aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpaavininanda <paavininanda@gmail.com>2018-09-03 19:46:15 +0530
committerpaavininanda <paavininanda@gmail.com>2018-09-13 00:23:09 +0530
commit25027e476c89ce438a85a631d66f5f4c261be895 (patch)
tree741c24f4e5e23d5b713fb72658d7d00da5374f90
parent9a83ab6297ddb62937fc54521b7fd4d19017e6b1 (diff)
downloadservo-25027e476c89ce438a85a631d66f5f4c261be895.tar.gz
servo-25027e476c89ce438a85a631d66f5f4c261be895.zip
Current-pixel-density tests passing
-rw-r--r--components/layout/construct.rs3
-rw-r--r--components/layout/fragment.rs35
-rw-r--r--components/layout_thread/dom_wrapper.rs5
-rw-r--r--components/script/dom/htmlimageelement.rs38
-rw-r--r--components/script/dom/node.rs10
-rw-r--r--components/script_layout_interface/wrapper_traits.rs3
-rw-r--r--tests/wpt/metadata/html/semantics/embedded-content/the-img-element/adoption.html.ini1
-rw-r--r--tests/wpt/metadata/html/semantics/embedded-content/the-img-element/current-pixel-density/basic.html.ini21
-rw-r--r--tests/wpt/metadata/html/semantics/embedded-content/the-img-element/non-active-document.html.ini1
9 files changed, 74 insertions, 43 deletions
diff --git a/components/layout/construct.rs b/components/layout/construct.rs
index dd4ef419bbd..36ab116d0ca 100644
--- a/components/layout/construct.rs
+++ b/components/layout/construct.rs
@@ -400,6 +400,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
Some(LayoutNodeType::Element(LayoutElementType::HTMLImageElement)) => {
let image_info = Box::new(ImageFragmentInfo::new(
node.image_url(),
+ node.image_density(),
node,
&self.layout_context,
));
@@ -408,6 +409,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
Some(LayoutNodeType::Element(LayoutElementType::HTMLObjectElement)) => {
let image_info = Box::new(ImageFragmentInfo::new(
node.object_data(),
+ None,
node,
&self.layout_context,
));
@@ -1471,6 +1473,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
ImageUrlOrNone::Url(ref url_value) => {
let image_info = Box::new(ImageFragmentInfo::new(
url_value.url().map(|u| u.clone()),
+ None,
node,
&self.layout_context,
));
diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs
index 2e952a501fb..65fd277fdde 100644
--- a/components/layout/fragment.rs
+++ b/components/layout/fragment.rs
@@ -393,6 +393,7 @@ impl ImageFragmentInfo {
/// sense to me.
pub fn new<N: ThreadSafeLayoutNode>(
url: Option<ServoUrl>,
+ density: Option<f64>,
node: &N,
layout_context: &LayoutContext,
) -> ImageFragmentInfo {
@@ -400,15 +401,33 @@ impl ImageFragmentInfo {
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 {
- Some(ImageOrMetadataAvailable::ImageAvailable(i, _)) => (
- Some(i.clone()),
- Some(ImageMetadata {
- height: i.height,
- width: i.width,
- }),
- ),
- Some(ImageOrMetadataAvailable::MetadataAvailable(m)) => (None, Some(m)),
+ Some(ImageOrMetadataAvailable::ImageAvailable(i, _)) => {
+ let height = (i.height as f64 / current_pixel_density) as u32;
+ let width = (i.width as f64 / current_pixel_density) as u32;
+ (
+ Some(Arc::new(Image {
+ height: height,
+ width: width,
+ ..(*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),
};
diff --git a/components/layout_thread/dom_wrapper.rs b/components/layout_thread/dom_wrapper.rs
index 204ff023c97..8fecbdbf53a 100644
--- a/components/layout_thread/dom_wrapper.rs
+++ b/components/layout_thread/dom_wrapper.rs
@@ -1041,6 +1041,11 @@ impl<'ln> ThreadSafeLayoutNode for ServoThreadSafeLayoutNode<'ln> {
this.image_url()
}
+ fn image_density(&self) -> Option<f64> {
+ let this = unsafe { self.get_jsmanaged() };
+ this.image_density()
+ }
+
fn canvas_data(&self) -> Option<HTMLCanvasData> {
let this = unsafe { self.get_jsmanaged() };
this.canvas_data()
diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs
index 81d328cc968..1c49185ad0d 100644
--- a/components/script/dom/htmlimageelement.rs
+++ b/components/script/dom/htmlimageelement.rs
@@ -706,7 +706,7 @@ impl HTMLImageElement {
}
/// 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() {
ImageRequestPhase::Pending => {
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
return
}
+ pending_request.current_pixel_density = Some(selected_pixel_density);
self.image_request.set(ImageRequestPhase::Pending);
self.init_image_request(&mut pending_request, &url, &src);
},
(_, State::Broken) | (_, State::Unavailable) => {
// Step 17
+ current_request.current_pixel_density = Some(selected_pixel_density);
self.init_image_request(&mut current_request, &url, &src);
},
(_, _) => {
// step 17
+ pending_request.current_pixel_density = Some(selected_pixel_density);
self.image_request.set(ImageRequestPhase::Pending);
self.init_image_request(&mut pending_request, &url, &src);
},
@@ -755,12 +758,9 @@ impl HTMLImageElement {
let window = document.window();
let task_source = window.dom_manipulation_task_source();
let this = Trusted::new(self);
- let src = match self.select_image_source() {
- Some(src) => {
- // Step 8
- // TODO: Handle pixel density.
- src.0
- },
+ let (src, pixel_density) = match self.select_image_source() {
+ // Step 8
+ Some(data) => data,
None => {
// Step 9.
// FIXME(nox): Why are errors silenced here?
@@ -816,7 +816,7 @@ impl HTMLImageElement {
match parsed_url {
Ok(url) => {
// Step 13-17
- self.prepare_image_request(&url, &src);
+ self.prepare_image_request(&url, &src, pixel_density);
},
Err(_) => {
// Step 12.1-12.5.
@@ -1231,6 +1231,9 @@ pub trait LayoutHTMLImageElementHelpers {
#[allow(unsafe_code)]
unsafe fn image_url(&self) -> Option<ServoUrl>;
+ #[allow(unsafe_code)]
+ unsafe fn image_density(&self) -> Option<f64>;
+
fn get_width(&self) -> LengthOrPercentageOrAuto;
fn get_height(&self) -> LengthOrPercentageOrAuto;
}
@@ -1247,6 +1250,11 @@ impl LayoutHTMLImageElementHelpers for LayoutDom<HTMLImageElement> {
}
#[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)]
fn get_width(&self) -> LengthOrPercentageOrAuto {
unsafe {
(*self.upcast::<Element>().unsafe_get())
@@ -1350,20 +1358,22 @@ impl HTMLImageElementMethods for HTMLImageElement {
// https://html.spec.whatwg.org/multipage/#dom-img-naturalwidth
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 {
- Some(ref metadata) => metadata.width,
+ match request.metadata {
+ Some(ref metadata) => (metadata.width as f64 / pixel_density) as u32,
None => 0,
}
}
// https://html.spec.whatwg.org/multipage/#dom-img-naturalheight
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 {
- Some(ref metadata) => metadata.height,
+ match request.metadata {
+ Some(ref metadata) => (metadata.height as f64 / pixel_density) as u32,
None => 0,
}
}
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs
index 09c4930ee29..c94f590c42b 100644
--- a/components/script/dom/node.rs
+++ b/components/script/dom/node.rs
@@ -1030,6 +1030,7 @@ pub trait LayoutNodeHelpers {
fn text_content(&self) -> String;
fn selection(&self) -> Option<Range<usize>>;
fn image_url(&self) -> Option<ServoUrl>;
+ fn image_density(&self) -> Option<f64>;
fn canvas_data(&self) -> Option<HTMLCanvasData>;
fn svg_data(&self) -> Option<SVGSVGData>;
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> {
self.downcast::<HTMLCanvasElement>()
.map(|canvas| canvas.data())
diff --git a/components/script_layout_interface/wrapper_traits.rs b/components/script_layout_interface/wrapper_traits.rs
index a23a417cb6d..23f9ff4a3b8 100644
--- a/components/script_layout_interface/wrapper_traits.rs
+++ b/components/script_layout_interface/wrapper_traits.rs
@@ -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.
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 svg_data(&self) -> Option<SVGSVGData>;
diff --git a/tests/wpt/metadata/html/semantics/embedded-content/the-img-element/adoption.html.ini b/tests/wpt/metadata/html/semantics/embedded-content/the-img-element/adoption.html.ini
index 0cc1f123d22..21672e83393 100644
--- a/tests/wpt/metadata/html/semantics/embedded-content/the-img-element/adoption.html.ini
+++ b/tests/wpt/metadata/html/semantics/embedded-content/the-img-element/adoption.html.ini
@@ -1,5 +1,6 @@
[adoption.html]
type: testharness
+ expected: TIMEOUT
[adoption is from appendChild]
expected: FAIL
diff --git a/tests/wpt/metadata/html/semantics/embedded-content/the-img-element/current-pixel-density/basic.html.ini b/tests/wpt/metadata/html/semantics/embedded-content/the-img-element/current-pixel-density/basic.html.ini
index 875fd3365f3..7304eeb41fb 100644
--- a/tests/wpt/metadata/html/semantics/embedded-content/the-img-element/current-pixel-density/basic.html.ini
+++ b/tests/wpt/metadata/html/semantics/embedded-content/the-img-element/current-pixel-density/basic.html.ini
@@ -1,20 +1,5 @@
[basic.html]
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">]
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">]
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
-
diff --git a/tests/wpt/metadata/html/semantics/embedded-content/the-img-element/non-active-document.html.ini b/tests/wpt/metadata/html/semantics/embedded-content/the-img-element/non-active-document.html.ini
index 6dc30b21283..d129c20cf72 100644
--- a/tests/wpt/metadata/html/semantics/embedded-content/the-img-element/non-active-document.html.ini
+++ b/tests/wpt/metadata/html/semantics/embedded-content/the-img-element/non-active-document.html.ini
@@ -1,5 +1,6 @@
[non-active-document.html]
type: testharness
+ expected: CRASH
[DOMParser]
expected: FAIL