From 28a71c48202bcd9c719751b623fcf3333a27c7ca Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 29 Feb 2016 14:31:08 -0800 Subject: [PATCH] Make border radii clip their contents. Needed for browser.html rounded corners. --- components/gfx/display_list/mod.rs | 8 ++----- components/layout/display_list_builder.rs | 8 ++++++- tests/wpt/mozilla/meta/MANIFEST.json | 24 +++++++++++++++++++ .../border_radius_clipping_contents_a.html | 21 ++++++++++++++++ .../border_radius_clipping_contents_ref.html | 16 +++++++++++++ 5 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 tests/wpt/mozilla/tests/css/border_radius_clipping_contents_a.html create mode 100644 tests/wpt/mozilla/tests/css/border_radius_clipping_contents_ref.html diff --git a/components/gfx/display_list/mod.rs b/components/gfx/display_list/mod.rs index 34c78080f1f..5ecde93bf81 100644 --- a/components/gfx/display_list/mod.rs +++ b/components/gfx/display_list/mod.rs @@ -762,9 +762,7 @@ pub struct BaseDisplayItem { impl BaseDisplayItem { #[inline(always)] - pub fn new(bounds: &Rect, - metadata: DisplayItemMetadata, - clip: &ClippingRegion) + pub fn new(bounds: &Rect, metadata: DisplayItemMetadata, clip: &ClippingRegion) -> BaseDisplayItem { // Detect useless clipping regions here and optimize them to `ClippingRegion::max()`. // The painting backend may want to optimize out clipping regions and this makes it easier @@ -887,13 +885,11 @@ impl ClippingRegion { /// Intersects this clipping region with the given rounded rectangle. #[inline] - pub fn intersect_with_rounded_rect(mut self, rect: &Rect, radii: &BorderRadii) - -> ClippingRegion { + pub fn intersect_with_rounded_rect(&mut self, rect: &Rect, radii: &BorderRadii) { self.complex.push(ComplexClippingRegion { rect: *rect, radii: *radii, }); - self } /// Translates this clipping region by the given vector. diff --git a/components/layout/display_list_builder.rs b/components/layout/display_list_builder.rs index 4589848a0f5..f498d83c389 100644 --- a/components/layout/display_list_builder.rs +++ b/components/layout/display_list_builder.rs @@ -335,7 +335,7 @@ impl FragmentDisplayListBuilding for Fragment { let border_radii = build_border_radius(absolute_bounds, style.get_border()); let mut clip = (*clip).clone(); if !border_radii.is_square() { - clip = clip.intersect_with_rounded_rect(absolute_bounds, &border_radii) + clip.intersect_with_rounded_rect(absolute_bounds, &border_radii) } // FIXME: This causes a lot of background colors to be displayed when they are clearly not @@ -1473,6 +1473,12 @@ impl FragmentDisplayListBuilding for Fragment { } _ => {} } + + let border_radii = build_border_radius(stacking_relative_border_box, + self.style.get_border()); + if !border_radii.is_square() { + current_clip.intersect_with_rounded_rect(stacking_relative_border_box, &border_radii) + } } fn build_display_list_for_text_fragment(&self, diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index 7ea42099e65..24c84798ed4 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -788,6 +788,18 @@ "url": "/_mozilla/css/border_radius_clip_a.html" } ], + "css/border_radius_clipping_contents_a.html": [ + { + "path": "css/border_radius_clipping_contents_a.html", + "references": [ + [ + "/_mozilla/css/border_radius_clipping_contents_ref.html", + "==" + ] + ], + "url": "/_mozilla/css/border_radius_clipping_contents_a.html" + } + ], "css/border_radius_dashed_a.html": [ { "path": "css/border_radius_dashed_a.html", @@ -6988,6 +7000,18 @@ "url": "/_mozilla/css/border_radius_clip_a.html" } ], + "css/border_radius_clipping_contents_a.html": [ + { + "path": "css/border_radius_clipping_contents_a.html", + "references": [ + [ + "/_mozilla/css/border_radius_clipping_contents_ref.html", + "==" + ] + ], + "url": "/_mozilla/css/border_radius_clipping_contents_a.html" + } + ], "css/border_radius_dashed_a.html": [ { "path": "css/border_radius_dashed_a.html", diff --git a/tests/wpt/mozilla/tests/css/border_radius_clipping_contents_a.html b/tests/wpt/mozilla/tests/css/border_radius_clipping_contents_a.html new file mode 100644 index 00000000000..fa9eb73d3e5 --- /dev/null +++ b/tests/wpt/mozilla/tests/css/border_radius_clipping_contents_a.html @@ -0,0 +1,21 @@ + + + + +
+ diff --git a/tests/wpt/mozilla/tests/css/border_radius_clipping_contents_ref.html b/tests/wpt/mozilla/tests/css/border_radius_clipping_contents_ref.html new file mode 100644 index 00000000000..08f65cace58 --- /dev/null +++ b/tests/wpt/mozilla/tests/css/border_radius_clipping_contents_ref.html @@ -0,0 +1,16 @@ + + +
+