mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Generate ::before and ::after content from url() for layout2020
This commit is contained in:
parent
756cf66cd2
commit
dc9a33f3a9
5 changed files with 46 additions and 6 deletions
|
@ -2,6 +2,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crate::context::LayoutContext;
|
||||
use crate::dom_traversal::NodeExt;
|
||||
use crate::fragments::{DebugId, Fragment, ImageFragment};
|
||||
use crate::geom::flow_relative::{Rect, Vec2};
|
||||
|
@ -10,9 +11,11 @@ use crate::sizing::ContentSizes;
|
|||
use crate::style_ext::ComputedValuesExt;
|
||||
use crate::ContainingBlock;
|
||||
use net_traits::image::base::Image;
|
||||
use net_traits::image_cache::{ImageOrMetadataAvailable, UsePlaceholder};
|
||||
use servo_arc::Arc as ServoArc;
|
||||
use std::sync::Arc;
|
||||
use style::properties::ComputedValues;
|
||||
use style::servo::url::ComputedUrl;
|
||||
use style::values::computed::{Length, LengthOrAuto};
|
||||
use style::values::CSSFloat;
|
||||
use style::Zero;
|
||||
|
@ -70,6 +73,39 @@ impl ReplacedContent {
|
|||
None
|
||||
}
|
||||
|
||||
pub fn from_image_url<'dom>(
|
||||
element: impl NodeExt<'dom>,
|
||||
context: &LayoutContext,
|
||||
image_url: &ComputedUrl,
|
||||
) -> Option<Self> {
|
||||
if let ComputedUrl::Valid(image_url) = image_url {
|
||||
let (image, width, height) = match context.get_or_request_image_or_meta(
|
||||
element.as_opaque(),
|
||||
image_url.clone(),
|
||||
UsePlaceholder::No,
|
||||
) {
|
||||
Some(ImageOrMetadataAvailable::ImageAvailable(image, _)) => {
|
||||
(Some(image.clone()), image.width as f32, image.height as f32)
|
||||
},
|
||||
Some(ImageOrMetadataAvailable::MetadataAvailable(metadata)) => {
|
||||
(None, metadata.width as f32, metadata.height as f32)
|
||||
},
|
||||
None => return None,
|
||||
};
|
||||
|
||||
return Some(Self {
|
||||
kind: ReplacedContentKind::Image(image),
|
||||
intrinsic: IntrinsicSizes {
|
||||
width: Some(Length::new(width)),
|
||||
height: Some(Length::new(height)),
|
||||
// FIXME https://github.com/w3c/csswg-drafts/issues/4572
|
||||
ratio: Some(width / height),
|
||||
},
|
||||
});
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn flow_relative_intrinsic_size(&self, style: &ComputedValues) -> Vec2<Option<Length>> {
|
||||
let intrinsic_size = PhysicalSize::new(self.intrinsic.width, self.intrinsic.height);
|
||||
Vec2::from_physical_size(&intrinsic_size, style.writing_mode)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue