diff options
Diffstat (limited to 'components/layout/display_list/builder.rs')
-rw-r--r-- | components/layout/display_list/builder.rs | 128 |
1 files changed, 69 insertions, 59 deletions
diff --git a/components/layout/display_list/builder.rs b/components/layout/display_list/builder.rs index 8d32ec01520..e6ead2505ca 100644 --- a/components/layout/display_list/builder.rs +++ b/components/layout/display_list/builder.rs @@ -13,7 +13,7 @@ use crate::context::LayoutContext; use crate::display_list::background::{self, get_cyclic}; use crate::display_list::border; use crate::display_list::gradient; -use crate::display_list::items::{BaseDisplayItem, ClipScrollNode, BLUR_INFLATION_FACTOR}; +use crate::display_list::items::{self, BaseDisplayItem, ClipScrollNode}; use crate::display_list::items::{ClipScrollNodeIndex, ClipScrollNodeType, ClippingAndScrolling}; use crate::display_list::items::{ClippingRegion, DisplayItem, DisplayItemMetadata, DisplayList}; use crate::display_list::items::{CommonDisplayItem, DisplayListSection}; @@ -32,7 +32,7 @@ use crate::table_cell::CollapsedBordersForCell; use app_units::{Au, AU_PER_PX}; use canvas_traits::canvas::{CanvasMsg, FromLayoutMsg}; use embedder_traits::Cursor; -use euclid::{rect, Point2D, Rect, SideOffsets2D, Size2D, TypedRect, TypedSize2D, Vector2D}; +use euclid::{rect, Point2D, Rect, SideOffsets2D, Size2D, TypedRect, TypedSize2D}; use fnv::FnvHashMap; use gfx::text::glyph::ByteIndex; use gfx::text::TextRun; @@ -43,7 +43,7 @@ use net_traits::image_cache::UsePlaceholder; use range::Range; use script_traits::IFrameSize; use servo_config::opts; -use servo_geometry::MaxRect; +use servo_geometry::{self, MaxRect}; use std::default::Default; use std::f32; use std::mem; @@ -64,12 +64,11 @@ use style::values::generics::image::{GradientKind, PaintWorklet}; use style::values::specified::ui::CursorKind; use style::values::{Either, RGBA}; use style_traits::ToCss; -use webrender_api::{ - self, BorderDetails, BorderRadius, BorderSide, BoxShadowClipMode, ColorF, ColorU, - ExternalScrollId, FilterOp, GlyphInstance, ImageRendering, LayoutRect, LayoutSize, - LayoutTransform, LayoutVector2D, LineStyle, NinePatchBorder, NinePatchBorderSource, - NormalBorder, ScrollSensitivity, StickyOffsetBounds, -}; +use webrender_api::units::{LayoutRect, LayoutSize, LayoutTransform, LayoutVector2D}; +use webrender_api::{self, BorderDetails, BorderRadius, BorderSide, BoxShadowClipMode, ColorF}; +use webrender_api::{ColorU, ExternalScrollId, FilterOp, GlyphInstance, ImageRendering, LineStyle}; +use webrender_api::{NinePatchBorder, NinePatchBorderSource, NormalBorder}; +use webrender_api::{ScrollSensitivity, StickyOffsetBounds}; static THREAD_TINT_COLORS: [ColorF; 8] = [ ColorF { @@ -346,7 +345,7 @@ impl<'a> DisplayListBuildState<'a> { } } - fn add_display_item(&mut self, display_item: DisplayItem) { + pub fn add_display_item(&mut self, display_item: DisplayItem) { let items = self .items .entry(display_item.stacking_context_id()) @@ -375,9 +374,8 @@ impl<'a> DisplayListBuildState<'a> { self.processing_scrolling_overflow_element } - fn create_base_display_item( + pub fn create_base_display_item( &self, - bounds: Rect<Au>, clip_rect: Rect<Au>, node: OpaqueNode, cursor: Option<Cursor>, @@ -391,7 +389,6 @@ impl<'a> DisplayListBuildState<'a> { self.current_clipping_and_scrolling }; self.create_base_display_item_with_clipping_and_scrolling( - bounds, clip_rect, node, cursor, @@ -402,7 +399,6 @@ impl<'a> DisplayListBuildState<'a> { fn create_base_display_item_with_clipping_and_scrolling( &self, - bounds: Rect<Au>, clip_rect: Rect<Au>, node: OpaqueNode, cursor: Option<Cursor>, @@ -410,7 +406,6 @@ impl<'a> DisplayListBuildState<'a> { clipping_and_scrolling: ClippingAndScrolling, ) -> BaseDisplayItem { BaseDisplayItem::new( - bounds.to_layout(), DisplayItemMetadata { node, // Store cursor id in display list. @@ -708,7 +703,6 @@ impl Fragment { let base = state.create_base_display_item( bounds, - bounds, self.node, get_cursor(&style, Cursor::Default), display_list_section, @@ -717,6 +711,7 @@ impl Fragment { base, webrender_api::RectangleDisplayItem { color: background_color.to_layout(), + common: items::empty_common_item_properties(), }, ))); }); @@ -844,7 +839,6 @@ impl Fragment { // Create the image display item. let base = state.create_base_display_item( - placement.bounds, placement.clip_rect, self.node, get_cursor(&style, Cursor::Default), @@ -855,6 +849,8 @@ impl Fragment { state.add_image_item( base, webrender_api::ImageDisplayItem { + bounds: placement.bounds.to_f32_px(), + common: items::empty_common_item_properties(), image_key: webrender_image.key.unwrap(), stretch_size: placement.tile_size.to_layout(), tile_spacing: placement.tile_spacing.to_layout(), @@ -959,7 +955,6 @@ impl Fragment { } let base = state.create_base_display_item( - placement.bounds, placement.clip_rect, self.node, get_cursor(&style, Cursor::Default), @@ -977,6 +972,8 @@ impl Fragment { ); let item = webrender_api::GradientDisplayItem { gradient, + bounds: placement.bounds.to_f32_px(), + common: items::empty_common_item_properties(), tile_size: placement.tile_size.to_layout(), tile_spacing: placement.tile_spacing.to_layout(), }; @@ -993,6 +990,8 @@ impl Fragment { ); let item = webrender_api::RadialGradientDisplayItem { gradient, + bounds: placement.bounds.to_f32_px(), + common: items::empty_common_item_properties(), tile_size: placement.tile_size.to_layout(), tile_spacing: placement.tile_spacing.to_layout(), }; @@ -1015,17 +1014,7 @@ impl Fragment { ) { // NB: According to CSS-BACKGROUNDS, box shadows render in *reverse* order (front to back). for box_shadow in style.get_effects().box_shadow.0.iter().rev() { - let bounds = shadow_bounds( - absolute_bounds.translate(&Vector2D::new( - Au::from(box_shadow.base.horizontal), - Au::from(box_shadow.base.vertical), - )), - Au::from(box_shadow.base.blur), - Au::from(box_shadow.spread), - ); - let base = state.create_base_display_item( - bounds, clip, self.node, get_cursor(&style, Cursor::Default), @@ -1035,6 +1024,7 @@ impl Fragment { state.add_display_item(DisplayItem::BoxShadow(CommonDisplayItem::new( base, webrender_api::BoxShadowDisplayItem { + common: items::empty_common_item_properties(), box_bounds: absolute_bounds.to_layout(), color: style.resolve_color(box_shadow.base.color).to_layout(), offset: LayoutVector2D::new( @@ -1109,7 +1099,6 @@ impl Fragment { // Append the border to the display list. let base = state.create_base_display_item( - bounds, clip, self.node, get_cursor(&style, Cursor::Default), @@ -1161,6 +1150,8 @@ impl Fragment { state.add_display_item(DisplayItem::Border(CommonDisplayItem::with_data( base, webrender_api::BorderDisplayItem { + bounds: bounds.to_layout(), + common: items::empty_common_item_properties(), widths: border_widths.to_layout(), details, }, @@ -1265,6 +1256,8 @@ impl Fragment { state.add_display_item(DisplayItem::Border(CommonDisplayItem::with_data( base, webrender_api::BorderDisplayItem { + bounds: bounds.to_layout(), + common: items::empty_common_item_properties(), widths: border_image_width, details, }, @@ -1308,7 +1301,6 @@ impl Fragment { .resolve_color(style.get_outline().outline_color) .to_layout(); let base = state.create_base_display_item( - bounds, clip, self.node, get_cursor(&style, Cursor::Default), @@ -1317,6 +1309,8 @@ impl Fragment { state.add_display_item(DisplayItem::Border(CommonDisplayItem::with_data( base, webrender_api::BorderDisplayItem { + bounds: bounds.to_layout(), + common: items::empty_common_item_properties(), widths: SideOffsets2D::new_all_same(width).to_layout(), details: BorderDetails::Normal(border::simple(color, outline_style.to_layout())), }, @@ -1339,7 +1333,6 @@ impl Fragment { // Compute the text fragment bounds and draw a border surrounding them. let base = state.create_base_display_item( - stacking_relative_border_box, clip, self.node, get_cursor(&style, Cursor::Default), @@ -1348,6 +1341,8 @@ impl Fragment { state.add_display_item(DisplayItem::Border(CommonDisplayItem::with_data( base, webrender_api::BorderDisplayItem { + bounds: stacking_relative_border_box.to_layout(), + common: items::empty_common_item_properties(), widths: SideOffsets2D::new_all_same(Au::from_px(1)).to_layout(), details: BorderDetails::Normal(border::simple( ColorU::new(0, 0, 200, 1).into(), @@ -1368,17 +1363,19 @@ impl Fragment { let baseline = baseline.to_physical(self.style.writing_mode, container_size); let base = state.create_base_display_item( - baseline, clip, self.node, get_cursor(&style, Cursor::Default), DisplayListSection::Content, ); // TODO(gw): Use a better estimate for wavy line thickness. - let wavy_line_thickness = (0.33 * base.bounds.size.height).ceil(); + let area = baseline.to_layout(); + let wavy_line_thickness = (0.33 * area.size.height).ceil(); state.add_display_item(DisplayItem::Line(CommonDisplayItem::new( base, webrender_api::LineDisplayItem { + common: items::empty_common_item_properties(), + area, orientation: webrender_api::LineOrientation::Horizontal, wavy_line_thickness, color: ColorU::new(0, 200, 0, 1).into(), @@ -1396,7 +1393,6 @@ impl Fragment { ) { // This prints a debug border around the border of this fragment. let base = state.create_base_display_item( - stacking_relative_border_box, clip, self.node, get_cursor(&self.style, Cursor::Default), @@ -1405,6 +1401,8 @@ impl Fragment { state.add_display_item(DisplayItem::Border(CommonDisplayItem::with_data( base, webrender_api::BorderDisplayItem { + bounds: stacking_relative_border_box.to_layout(), + common: items::empty_common_item_properties(), widths: SideOffsets2D::new_all_same(Au::from_px(1)).to_layout(), details: BorderDetails::Normal(border::simple( ColorU::new(0, 0, 200, 1).into(), @@ -1422,7 +1420,6 @@ impl Fragment { state: &mut DisplayListBuildState, stacking_relative_border_box: Rect<Au>, display_list_section: DisplayListSection, - clip: Rect<Au>, ) { let scanned_text_fragment_info = match self.specific { SpecificFragmentInfo::ScannedText(ref scanned_text_fragment_info) => { @@ -1439,7 +1436,6 @@ impl Fragment { let background_color = style.resolve_color(style.get_background().background_color); let base = state.create_base_display_item( stacking_relative_border_box, - clip, self.node, get_cursor(&self.style, Cursor::Default), display_list_section, @@ -1447,6 +1443,7 @@ impl Fragment { state.add_display_item(DisplayItem::Rectangle(CommonDisplayItem::new( base, webrender_api::RectangleDisplayItem { + common: items::empty_common_item_properties(), color: background_color.to_layout(), }, ))); @@ -1485,7 +1482,6 @@ impl Fragment { let base = state.create_base_display_item( insertion_point_bounds, - clip, self.node, get_cursor(&self.style, cursor), display_list_section, @@ -1493,6 +1489,7 @@ impl Fragment { state.add_display_item(DisplayItem::Rectangle(CommonDisplayItem::new( base, webrender_api::RectangleDisplayItem { + common: items::empty_common_item_properties(), color: self.style().get_inherited_text().color.to_layout(), }, ))); @@ -1649,7 +1646,6 @@ impl Fragment { state, stacking_relative_border_box, display_list_section, - clip, ); } @@ -1667,7 +1663,6 @@ impl Fragment { let content_size = TypedRect::new(stacking_relative_border_box.origin, content_size); let base = state.create_base_display_item_with_clipping_and_scrolling( content_size, - content_size, self.node, // FIXME(emilio): Why does this ignore pointer-events? get_cursor(&self.style, Cursor::Default).or(Some(Cursor::Default)), @@ -1677,6 +1672,7 @@ impl Fragment { state.add_display_item(DisplayItem::Rectangle(CommonDisplayItem::new( base, webrender_api::RectangleDisplayItem { + common: items::empty_common_item_properties(), color: ColorF::TRANSPARENT, }, ))); @@ -1719,7 +1715,6 @@ impl Fragment { } state.create_base_display_item( - stacking_relative_content_box, stacking_relative_border_box, self.node, get_cursor(&self.style, Cursor::Default), @@ -1806,12 +1801,16 @@ impl Fragment { }; let base = create_base_display_item(state); + let bounds = stacking_relative_content_box.to_layout(); let item = DisplayItem::Iframe(Box::new(IframeDisplayItem { base, + bounds, iframe: pipeline_id, })); - let size = Size2D::new(item.bounds().size.width, item.bounds().size.height); + // XXXjdm: This sleight-of-hand to convert LayoutRect -> Size2D<CSSPixel> + // looks bogus. + let size = Size2D::new(bounds.size.width, bounds.size.height); state.iframe_sizes.push(IFrameSize { id: browsing_context_id, size: TypedSize2D::from_untyped(&size), @@ -1828,6 +1827,8 @@ impl Fragment { state.add_image_item( base, webrender_api::ImageDisplayItem { + bounds: stacking_relative_content_box.to_layout(), + common: items::empty_common_item_properties(), image_key: id, stretch_size: stacking_relative_content_box.size.to_layout(), tile_spacing: LayoutSize::zero(), @@ -1849,6 +1850,8 @@ impl Fragment { state.add_image_item( base, webrender_api::ImageDisplayItem { + bounds: stacking_relative_content_box.to_layout(), + common: items::empty_common_item_properties(), image_key: *image_key, stretch_size: stacking_relative_border_box.size.to_layout(), tile_spacing: LayoutSize::zero(), @@ -1880,6 +1883,8 @@ impl Fragment { let base = create_base_display_item(state); let display_item = webrender_api::ImageDisplayItem { + bounds: stacking_relative_border_box.to_layout(), + common: items::empty_common_item_properties(), image_key, stretch_size: stacking_relative_content_box.size.to_layout(), tile_spacing: LayoutSize::zero(), @@ -1997,7 +2002,6 @@ impl Fragment { // Base item for all text/shadows let base = state.create_base_display_item( - stacking_relative_content_box, clip, self.node, get_cursor(&self.style, cursor), @@ -2016,7 +2020,6 @@ impl Fragment { offset: LayoutVector2D::new(shadow.horizontal.px(), shadow.vertical.px()), color: self.style.resolve_color(shadow.color).to_layout(), blur_radius: shadow.blur.px(), - should_inflate: true, }, }, ))); @@ -2076,6 +2079,8 @@ impl Fragment { state.add_display_item(DisplayItem::Text(CommonDisplayItem::with_data( base.clone(), webrender_api::TextDisplayItem { + bounds: stacking_relative_content_box.to_layout(), + common: items::empty_common_item_properties(), font_key: text_fragment.run.font_key, color: text_color.to_layout(), glyph_options: None, @@ -2122,7 +2127,6 @@ impl Fragment { let stacking_relative_box = stacking_relative_box.to_physical(self.style.writing_mode, container_size); let base = state.create_base_display_item( - stacking_relative_box, clip, self.node, get_cursor(&self.style, Cursor::Default), @@ -2130,10 +2134,13 @@ impl Fragment { ); // TODO(gw): Use a better estimate for wavy line thickness. - let wavy_line_thickness = (0.33 * base.bounds.size.height).ceil(); + let area = stacking_relative_box.to_layout(); + let wavy_line_thickness = (0.33 * area.size.height).ceil(); state.add_display_item(DisplayItem::Line(CommonDisplayItem::new( base, webrender_api::LineDisplayItem { + common: items::empty_common_item_properties(), + area, orientation: webrender_api::LineOrientation::Horizontal, wavy_line_thickness, color: color.to_layout(), @@ -2837,16 +2844,14 @@ impl BaseFlow { let mut color = THREAD_TINT_COLORS[thread_id as usize % THREAD_TINT_COLORS.len()]; color.a = 1.0; - let base = state.create_base_display_item( - stacking_context_relative_bounds.inflate(Au::from_px(2), Au::from_px(2)), - self.clip, - node, - None, - DisplayListSection::Content, - ); + let base = + state.create_base_display_item(self.clip, node, None, DisplayListSection::Content); + let bounds = stacking_context_relative_bounds.inflate(Au::from_px(2), Au::from_px(2)); state.add_display_item(DisplayItem::Border(CommonDisplayItem::with_data( base, webrender_api::BorderDisplayItem { + bounds: bounds.to_layout(), + common: items::empty_common_item_properties(), widths: SideOffsets2D::new_all_same(Au::from_px(2)).to_layout(), details: BorderDetails::Normal(border::simple( color, @@ -2908,13 +2913,6 @@ fn get_cursor(values: &ComputedValues, default_cursor: Cursor) -> Option<Cursor> }) } -/// Adjusts `content_rect` as necessary for the given spread, and blur so that the resulting -/// bounding rect contains all of a shadow's ink. -fn shadow_bounds(content_rect: Rect<Au>, blur: Au, spread: Au) -> Rect<Au> { - let inflation = spread + blur * BLUR_INFLATION_FACTOR; - content_rect.inflate(inflation, inflation) -} - /// Adjusts borders as appropriate to account for a fragment's status as the /// first or last fragment within the range of an element. /// @@ -3012,3 +3010,15 @@ impl IndexableText { ) } } + +trait ToF32Px { + type Output; + fn to_f32_px(&self) -> Self::Output; +} + +impl ToF32Px for TypedRect<Au> { + type Output = LayoutRect; + fn to_f32_px(&self) -> LayoutRect { + LayoutRect::from_untyped(&servo_geometry::au_rect_to_f32_rect(*self)) + } +} |