mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Current-pixel-density tests passing
This commit is contained in:
parent
9a83ab6297
commit
25027e476c
9 changed files with 74 additions and 43 deletions
|
@ -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,
|
||||
));
|
||||
|
|
|
@ -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),
|
||||
};
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
@ -1246,6 +1249,11 @@ impl LayoutHTMLImageElementHelpers for LayoutDom<HTMLImageElement> {
|
|||
(*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)]
|
||||
fn get_width(&self) -> LengthOrPercentageOrAuto {
|
||||
unsafe {
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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>;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
[adoption.html]
|
||||
type: testharness
|
||||
expected: TIMEOUT
|
||||
[adoption is from appendChild]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
[non-active-document.html]
|
||||
type: testharness
|
||||
expected: CRASH
|
||||
[DOMParser]
|
||||
expected: FAIL
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue