Skip to content

Commit

Permalink
Auto merge of #16766 - emilio:border-radius, r=glennw
Browse files Browse the repository at this point in the history
layout: Fix radius percentage resolution.

Fixes #16764

<!-- 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/16766)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed May 8, 2017
2 parents f6bd158 + c9ab75b commit 34d3357
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
16 changes: 8 additions & 8 deletions components/layout/display_list_builder.rs
Expand Up @@ -564,20 +564,20 @@ fn build_border_radius(abs_bounds: &Rect<Au>,

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),
})
}

/// 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<Au>,
style: ::StyleArc<ServoComputedValues>)
style: &ServoComputedValues)
-> BorderRadii<Au> {
let mut radii = build_border_radius(&outer_rect, style.get_border());
if radii.is_square() {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
18 changes: 15 additions & 3 deletions components/layout/model.rs
Expand Up @@ -478,10 +478,22 @@ pub fn specified(length: LengthOrPercentage, containing_length: Au) -> Au {
}
}

pub fn specified_border_radius(radius: BorderRadiusSize, containing_length: Au) -> Size2D<Au> {
/// 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<Au>)
-> Size2D<Au>
{
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)
}

Expand Down

0 comments on commit 34d3357

Please sign in to comment.