mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +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
|
@ -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),
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue