Current-pixel-density tests passing

This commit is contained in:
paavininanda 2018-09-03 19:46:15 +05:30
parent 9a83ab6297
commit 25027e476c
9 changed files with 74 additions and 43 deletions

View file

@ -400,6 +400,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
Some(LayoutNodeType::Element(LayoutElementType::HTMLImageElement)) => { Some(LayoutNodeType::Element(LayoutElementType::HTMLImageElement)) => {
let image_info = Box::new(ImageFragmentInfo::new( let image_info = Box::new(ImageFragmentInfo::new(
node.image_url(), node.image_url(),
node.image_density(),
node, node,
&self.layout_context, &self.layout_context,
)); ));
@ -408,6 +409,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
Some(LayoutNodeType::Element(LayoutElementType::HTMLObjectElement)) => { Some(LayoutNodeType::Element(LayoutElementType::HTMLObjectElement)) => {
let image_info = Box::new(ImageFragmentInfo::new( let image_info = Box::new(ImageFragmentInfo::new(
node.object_data(), node.object_data(),
None,
node, node,
&self.layout_context, &self.layout_context,
)); ));
@ -1471,6 +1473,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
ImageUrlOrNone::Url(ref url_value) => { ImageUrlOrNone::Url(ref url_value) => {
let image_info = Box::new(ImageFragmentInfo::new( let image_info = Box::new(ImageFragmentInfo::new(
url_value.url().map(|u| u.clone()), url_value.url().map(|u| u.clone()),
None,
node, node,
&self.layout_context, &self.layout_context,
)); ));

View file

@ -393,6 +393,7 @@ impl ImageFragmentInfo {
/// sense to me. /// sense to me.
pub fn new<N: ThreadSafeLayoutNode>( pub fn new<N: ThreadSafeLayoutNode>(
url: Option<ServoUrl>, url: Option<ServoUrl>,
density: Option<f64>,
node: &N, node: &N,
layout_context: &LayoutContext, layout_context: &LayoutContext,
) -> ImageFragmentInfo { ) -> ImageFragmentInfo {
@ -400,15 +401,33 @@ impl ImageFragmentInfo {
layout_context.get_or_request_image_or_meta(node.opaque(), url, UsePlaceholder::Yes) layout_context.get_or_request_image_or_meta(node.opaque(), url, UsePlaceholder::Yes)
}); });
let current_pixel_density = density.unwrap_or(1f64);
let (image, metadata) = match image_or_metadata { let (image, metadata) = match image_or_metadata {
Some(ImageOrMetadataAvailable::ImageAvailable(i, _)) => ( Some(ImageOrMetadataAvailable::ImageAvailable(i, _)) => {
Some(i.clone()), let height = (i.height as f64 / current_pixel_density) as u32;
Some(ImageMetadata { let width = (i.width as f64 / current_pixel_density) as u32;
height: i.height, (
width: i.width, Some(Arc::new(Image {
}), height: height,
), width: width,
Some(ImageOrMetadataAvailable::MetadataAvailable(m)) => (None, Some(m)), ..(*i).clone()
})),
Some(ImageMetadata {
height: height,
width: width,
}),
)
},
Some(ImageOrMetadataAvailable::MetadataAvailable(m)) => {
(
None,
Some(ImageMetadata {
height: (m.height as f64 / current_pixel_density) as u32,
width: (m.width as f64 / current_pixel_density) as u32,
}),
)
},
None => (None, None), None => (None, None),
}; };

View file

@ -1041,6 +1041,11 @@ impl<'ln> ThreadSafeLayoutNode for ServoThreadSafeLayoutNode<'ln> {
this.image_url() this.image_url()
} }
fn image_density(&self) -> Option<f64> {
let this = unsafe { self.get_jsmanaged() };
this.image_density()
}
fn canvas_data(&self) -> Option<HTMLCanvasData> { fn canvas_data(&self) -> Option<HTMLCanvasData> {
let this = unsafe { self.get_jsmanaged() }; let this = unsafe { self.get_jsmanaged() };
this.canvas_data() this.canvas_data()

View file

@ -706,7 +706,7 @@ impl HTMLImageElement {
} }
/// Step 13-17 of html.spec.whatwg.org/multipage/#update-the-image-data /// Step 13-17 of html.spec.whatwg.org/multipage/#update-the-image-data
fn prepare_image_request(&self, url: &ServoUrl, src: &DOMString) { fn prepare_image_request(&self, url: &ServoUrl, src: &DOMString, selected_pixel_density: f64) {
match self.image_request.get() { match self.image_request.get() {
ImageRequestPhase::Pending => { ImageRequestPhase::Pending => {
if let Some(pending_url) = self.pending_request.borrow().parsed_url.clone() { if let Some(pending_url) = self.pending_request.borrow().parsed_url.clone() {
@ -731,15 +731,18 @@ impl HTMLImageElement {
// TODO: queue a task to restart animation, if restart-animation is set // TODO: queue a task to restart animation, if restart-animation is set
return return
} }
pending_request.current_pixel_density = Some(selected_pixel_density);
self.image_request.set(ImageRequestPhase::Pending); self.image_request.set(ImageRequestPhase::Pending);
self.init_image_request(&mut pending_request, &url, &src); self.init_image_request(&mut pending_request, &url, &src);
}, },
(_, State::Broken) | (_, State::Unavailable) => { (_, State::Broken) | (_, State::Unavailable) => {
// Step 17 // Step 17
current_request.current_pixel_density = Some(selected_pixel_density);
self.init_image_request(&mut current_request, &url, &src); self.init_image_request(&mut current_request, &url, &src);
}, },
(_, _) => { (_, _) => {
// step 17 // step 17
pending_request.current_pixel_density = Some(selected_pixel_density);
self.image_request.set(ImageRequestPhase::Pending); self.image_request.set(ImageRequestPhase::Pending);
self.init_image_request(&mut pending_request, &url, &src); self.init_image_request(&mut pending_request, &url, &src);
}, },
@ -755,12 +758,9 @@ impl HTMLImageElement {
let window = document.window(); let window = document.window();
let task_source = window.dom_manipulation_task_source(); let task_source = window.dom_manipulation_task_source();
let this = Trusted::new(self); let this = Trusted::new(self);
let src = match self.select_image_source() { let (src, pixel_density) = match self.select_image_source() {
Some(src) => { // Step 8
// Step 8 Some(data) => data,
// TODO: Handle pixel density.
src.0
},
None => { None => {
// Step 9. // Step 9.
// FIXME(nox): Why are errors silenced here? // FIXME(nox): Why are errors silenced here?
@ -816,7 +816,7 @@ impl HTMLImageElement {
match parsed_url { match parsed_url {
Ok(url) => { Ok(url) => {
// Step 13-17 // Step 13-17
self.prepare_image_request(&url, &src); self.prepare_image_request(&url, &src, pixel_density);
}, },
Err(_) => { Err(_) => {
// Step 12.1-12.5. // Step 12.1-12.5.
@ -1231,6 +1231,9 @@ pub trait LayoutHTMLImageElementHelpers {
#[allow(unsafe_code)] #[allow(unsafe_code)]
unsafe fn image_url(&self) -> Option<ServoUrl>; unsafe fn image_url(&self) -> Option<ServoUrl>;
#[allow(unsafe_code)]
unsafe fn image_density(&self) -> Option<f64>;
fn get_width(&self) -> LengthOrPercentageOrAuto; fn get_width(&self) -> LengthOrPercentageOrAuto;
fn get_height(&self) -> LengthOrPercentageOrAuto; fn get_height(&self) -> LengthOrPercentageOrAuto;
} }
@ -1246,6 +1249,11 @@ impl LayoutHTMLImageElementHelpers for LayoutDom<HTMLImageElement> {
(*self.unsafe_get()).current_request.borrow_for_layout().parsed_url.clone() (*self.unsafe_get()).current_request.borrow_for_layout().parsed_url.clone()
} }
#[allow(unsafe_code)]
unsafe fn image_density(&self) -> Option<f64> {
(*self.unsafe_get()).current_request.borrow_for_layout().current_pixel_density.clone()
}
#[allow(unsafe_code)] #[allow(unsafe_code)]
fn get_width(&self) -> LengthOrPercentageOrAuto { fn get_width(&self) -> LengthOrPercentageOrAuto {
unsafe { unsafe {
@ -1350,20 +1358,22 @@ impl HTMLImageElementMethods for HTMLImageElement {
// https://html.spec.whatwg.org/multipage/#dom-img-naturalwidth // https://html.spec.whatwg.org/multipage/#dom-img-naturalwidth
fn NaturalWidth(&self) -> u32 { fn NaturalWidth(&self) -> u32 {
let ref metadata = self.current_request.borrow().metadata; let request = self.current_request.borrow();
let pixel_density = request.current_pixel_density.unwrap_or(1f64);
match *metadata { match request.metadata {
Some(ref metadata) => metadata.width, Some(ref metadata) => (metadata.width as f64 / pixel_density) as u32,
None => 0, None => 0,
} }
} }
// https://html.spec.whatwg.org/multipage/#dom-img-naturalheight // https://html.spec.whatwg.org/multipage/#dom-img-naturalheight
fn NaturalHeight(&self) -> u32 { fn NaturalHeight(&self) -> u32 {
let ref metadata = self.current_request.borrow().metadata; let request = self.current_request.borrow();
let pixel_density = request.current_pixel_density.unwrap_or(1f64);
match *metadata { match request.metadata {
Some(ref metadata) => metadata.height, Some(ref metadata) => (metadata.height as f64 / pixel_density) as u32,
None => 0, None => 0,
} }
} }

View file

@ -1030,6 +1030,7 @@ pub trait LayoutNodeHelpers {
fn text_content(&self) -> String; fn text_content(&self) -> String;
fn selection(&self) -> Option<Range<usize>>; fn selection(&self) -> Option<Range<usize>>;
fn image_url(&self) -> Option<ServoUrl>; fn image_url(&self) -> Option<ServoUrl>;
fn image_density(&self) -> Option<f64>;
fn canvas_data(&self) -> Option<HTMLCanvasData>; fn canvas_data(&self) -> Option<HTMLCanvasData>;
fn svg_data(&self) -> Option<SVGSVGData>; fn svg_data(&self) -> Option<SVGSVGData>;
fn iframe_browsing_context_id(&self) -> Option<BrowsingContextId>; fn iframe_browsing_context_id(&self) -> Option<BrowsingContextId>;
@ -1173,6 +1174,15 @@ impl LayoutNodeHelpers for LayoutDom<Node> {
} }
} }
#[allow(unsafe_code)]
fn image_density(&self) -> Option<f64> {
unsafe {
self.downcast::<HTMLImageElement>()
.expect("not an image!")
.image_density()
}
}
fn canvas_data(&self) -> Option<HTMLCanvasData> { fn canvas_data(&self) -> Option<HTMLCanvasData> {
self.downcast::<HTMLCanvasElement>() self.downcast::<HTMLCanvasElement>()
.map(|canvas| canvas.data()) .map(|canvas| canvas.data())

View file

@ -249,6 +249,9 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + Debug + GetLayoutData + NodeInfo
/// If this is an image element, returns its URL. If this is not an image element, fails. /// If this is an image element, returns its URL. If this is not an image element, fails.
fn image_url(&self) -> Option<ServoUrl>; fn image_url(&self) -> Option<ServoUrl>;
/// If this is an image element, returns its current-pixel-density. If this is not an image element, fails.
fn image_density(&self) -> Option<f64>;
fn canvas_data(&self) -> Option<HTMLCanvasData>; fn canvas_data(&self) -> Option<HTMLCanvasData>;
fn svg_data(&self) -> Option<SVGSVGData>; fn svg_data(&self) -> Option<SVGSVGData>;

View file

@ -1,5 +1,6 @@
[adoption.html] [adoption.html]
type: testharness type: testharness
expected: TIMEOUT
[adoption is from appendChild] [adoption is from appendChild]
expected: FAIL expected: FAIL

View file

@ -1,20 +1,5 @@
[basic.html] [basic.html]
type: testharness type: testharness
[<img srcset="/images/green-256x256.png 1.6x" data-expect="160">]
expected: FAIL
[<img srcset="/images/green-256x256.png 2x" data-expect="128">]
expected: FAIL
[<img srcset="/images/green-256x256.png 512w" sizes="256px" data-expect="128">]
expected: FAIL
[<img srcset="/images/green-256x256.png 256w" sizes="512px" data-expect="512">]
expected: FAIL
[<img srcset="/images/green-256x256.png 256w" sizes="1px" data-expect="1">]
expected: FAIL
[<img srcset="data:image/svg+xml,<svg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='-1%20-1%202%202'%20width='20'%20height='20'><circle%20r='1'/></svg> 2x" data-expect="10">] [<img srcset="data:image/svg+xml,<svg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='-1%20-1%202%202'%20width='20'%20height='20'><circle%20r='1'/></svg> 2x" data-expect="10">]
expected: FAIL expected: FAIL
@ -24,9 +9,3 @@
[<img srcset="data:image/svg+xml,<svg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='-1%20-1%202%202'%20height='20'><circle%20r='1'/></svg> 2x" data-expect="10">] [<img srcset="data:image/svg+xml,<svg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='-1%20-1%202%202'%20height='20'><circle%20r='1'/></svg> 2x" data-expect="10">]
expected: FAIL expected: FAIL
[<img srcset="/images/green-256x256.png 10000x" data-expect="0">]
expected: FAIL
[<img srcset="/images/green-256x256.png 256w" sizes="0px" data-expect="0">]
expected: FAIL

View file

@ -1,5 +1,6 @@
[non-active-document.html] [non-active-document.html]
type: testharness type: testharness
expected: CRASH
[DOMParser] [DOMParser]
expected: FAIL expected: FAIL