mirror of
https://github.com/servo/servo.git
synced 2025-07-31 19:20:22 +01:00
Auto merge of #21628 - paavininanda:Current-pixel-density, r=jdm
Current pixel density <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix a subset of #11416. <!-- Either: --> - [x] There are tests for these changes OR <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21628) <!-- Reviewable:end -->
This commit is contained in:
commit
b0de9c5315
9 changed files with 74 additions and 43 deletions
|
@ -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())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue