From 39471cda1b54dc7cf079cf60c5239ee7cef44c44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 8 May 2017 11:04:14 +0200 Subject: [PATCH 1/2] layout: Avoid a few dumb refcount bumps. --- components/layout/display_list_builder.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/layout/display_list_builder.rs b/components/layout/display_list_builder.rs index 785025cc3e10..ac1735b7a161 100644 --- a/components/layout/display_list_builder.rs +++ b/components/layout/display_list_builder.rs @@ -577,7 +577,7 @@ fn build_border_radius(abs_bounds: &Rect, /// Get the border radius for the rectangle inside of a rounded border. This is useful /// for building the clip for the content inside the border. fn build_border_radius_for_inner_rect(outer_rect: &Rect, - style: ::StyleArc) + style: &ServoComputedValues) -> BorderRadii { let mut radii = build_border_radius(&outer_rect, style.get_border()); if radii.is_square() { @@ -2376,7 +2376,7 @@ impl BlockFlowDisplayListBuilding for BlockFlow { let mut clip = ClippingRegion::from_rect(&clip_rect); let border_radii = build_border_radius_for_inner_rect(&border_box, - self.fragment.style.clone()); + &self.fragment.style); if !border_radii.is_square() { clip.intersect_with_rounded_rect(&clip_rect, &border_radii) } @@ -2398,7 +2398,7 @@ impl BlockFlowDisplayListBuilding for BlockFlow { let clip_rect = Rect::new(Point2D::zero(), content_box.size); let mut clip = ClippingRegion::from_rect(&clip_rect); - let radii = build_border_radius_for_inner_rect(&border_box, self.fragment.style.clone()); + let radii = build_border_radius_for_inner_rect(&border_box, &self.fragment.style); if !radii.is_square() { clip.intersect_with_rounded_rect(&clip_rect, &radii) } From c9ab75b013b8a0e3679ce01cf4f0f7bd6a89cfc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 8 May 2017 11:04:44 +0200 Subject: [PATCH 2/2] layout: Fix radius percentage resolution. By resolving against the corresponding dimension of the border box, instead of against the width. Fixes #16764 --- components/layout/display_list_builder.rs | 10 +++++----- components/layout/model.rs | 18 +++++++++++++++--- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/components/layout/display_list_builder.rs b/components/layout/display_list_builder.rs index ac1735b7a161..b48bb607ac7a 100644 --- a/components/layout/display_list_builder.rs +++ b/components/layout/display_list_builder.rs @@ -564,13 +564,13 @@ fn build_border_radius(abs_bounds: &Rect, handle_overlapping_radii(&abs_bounds.size, &BorderRadii { top_left: model::specified_border_radius(border_style.border_top_left_radius, - abs_bounds.size.width), + abs_bounds.size), top_right: model::specified_border_radius(border_style.border_top_right_radius, - abs_bounds.size.width), + abs_bounds.size), bottom_right: model::specified_border_radius(border_style.border_bottom_right_radius, - abs_bounds.size.width), + abs_bounds.size), bottom_left: model::specified_border_radius(border_style.border_bottom_left_radius, - abs_bounds.size.width), + abs_bounds.size), }) } @@ -1278,7 +1278,7 @@ impl FragmentDisplayListBuilding for Fragment { spread_radius: box_shadow.spread_radius, border_radius: model::specified_border_radius(style.get_border() .border_top_left_radius, - absolute_bounds.size.width).width, + absolute_bounds.size).width, clip_mode: if box_shadow.inset { BoxShadowClipMode::Inset } else { diff --git a/components/layout/model.rs b/components/layout/model.rs index 27f0b2ce7a71..531d37038d7f 100644 --- a/components/layout/model.rs +++ b/components/layout/model.rs @@ -478,10 +478,22 @@ pub fn specified(length: LengthOrPercentage, containing_length: Au) -> Au { } } -pub fn specified_border_radius(radius: BorderRadiusSize, containing_length: Au) -> Size2D { +/// Computes a border radius size against the containing size. +/// +/// Note that percentages in `border-radius` are resolved against the relevant +/// box dimension instead of only against the width per [1]: +/// +/// > Percentages: Refer to corresponding dimension of the border box. +/// +/// [1]: https://drafts.csswg.org/css-backgrounds-3/#border-radius +pub fn specified_border_radius( + radius: BorderRadiusSize, + containing_size: Size2D) + -> Size2D +{ let generics::BorderRadiusSize(size) = radius; - let w = specified(size.width, containing_length); - let h = specified(size.height, containing_length); + let w = specified(size.width, containing_size.width); + let h = specified(size.height, containing_size.height); Size2D::new(w, h) }