Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply border-radius to img, canvas, iframe #17589

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -830,18 +830,25 @@ fn convert_ellipse_size_keyword(keyword: ShapeExtent,
}
}

fn clip_for_border_radius(style: &ServoComputedValues,
clip: &Rect<Au>) -> ClippingRegion {
let border_radii = build_border_radius(clip, style.get_border());
let mut adjusted_clip = ClippingRegion::max();
if !border_radii.is_square() {
adjusted_clip.intersect_with_rounded_rect(clip, &border_radii);
}

adjusted_clip
}

impl FragmentDisplayListBuilding for Fragment {
fn build_display_list_for_background_if_applicable(&self,
state: &mut DisplayListBuildState,
style: &ServoComputedValues,
display_list_section: DisplayListSection,
absolute_bounds: &Rect<Au>) {
// Adjust the clipping region as necessary to account for `border-radius`.
let border_radii = build_border_radius(absolute_bounds, style.get_border());
let mut clip = ClippingRegion::max();
if !border_radii.is_square() {
clip.intersect_with_rounded_rect(absolute_bounds, &border_radii);
};
let clip = clip_for_border_radius(style, absolute_bounds);

let background = style.get_background();

// FIXME: This causes a lot of background colors to be displayed when they are clearly not
@@ -1834,6 +1841,8 @@ impl FragmentDisplayListBuilding for Fragment {
let stacking_relative_content_box =
self.stacking_relative_content_box(stacking_relative_border_box);

let clipping_region = clip_for_border_radius(&self.style, &stacking_relative_content_box);

This comment has been minimized.

@emilio

emilio Jul 2, 2017

Member

Why stacking_relative_border_box? I'd have expected this to use clip.

Also, what about the other uses for the clip rect? Should they account for border-radius too?

This comment has been minimized.

@streichgeorg

streichgeorg Jul 2, 2017

Author Contributor

I tried clip and it doesn't work, but it works with stacking_relative_content_box so I just used that. I don't really have any oversight over this code so I don't know why that is.


match self.specific {
SpecificFragmentInfo::TruncatedFragment(box TruncatedFragmentInfo {
text_info: Some(ref text_fragment),
@@ -1892,7 +1901,7 @@ impl FragmentDisplayListBuilding for Fragment {
if !stacking_relative_content_box.is_empty() {
let base = state.create_base_display_item(
&stacking_relative_content_box,
&ClippingRegion::from_rect(clip),
&clipping_region,
self.node,
self.style.get_cursor(Cursor::Default),
DisplayListSection::Content);
@@ -1913,7 +1922,7 @@ impl FragmentDisplayListBuilding for Fragment {
if let Some(ref image) = image_fragment.image {
let base = state.create_base_display_item(
&stacking_relative_content_box,
&ClippingRegion::from_rect(clip),
&clipping_region,
self.node,
self.style.get_cursor(Cursor::Default),
DisplayListSection::Content);
@@ -1944,7 +1953,7 @@ impl FragmentDisplayListBuilding for Fragment {

let base = state.create_base_display_item(
&stacking_relative_content_box,
&ClippingRegion::from_rect(clip),
&clipping_region,
self.node,
self.style.get_cursor(Cursor::Default),
DisplayListSection::Content);
{}
]
],
"css/css-backgrounds-3/image-with-border-radius.html": [
[
"/css/css-backgrounds-3/image-with-border-radius.html",
[
[
"/css/css-backgrounds-3/reference/image-with-border-radius.ref.html",
"=="
]
],
{}
]
],
"css/css-backgrounds-3/scroll-positioned-multiple-background-images.html": [
[
"/css/css-backgrounds-3/scroll-positioned-multiple-background-images.html",
{}
]
],
"css/css-backgrounds-3/reference/image-with-border-radius.ref.html": [
[
{}
]
],
"css/css-backgrounds-3/reference/ref-filled-black-96px-square.xht": [
[
{}
"f8b27b21849c4bda9171a82f463a661610c05a65",
"reftest"
],
"css/css-backgrounds-3/image-with-border-radius.html": [
"907c85b623c744bf2a8afc7f734d516970d3eb6f",
"reftest"
],
"css/css-backgrounds-3/justfortest.html": [
"da39a3ee5e6b4b0d3255bfef95601890afd80709",
"support"
"b41f9a457b15ffac1102e421ccdd7c606b9d3c48",
"support"
],
"css/css-backgrounds-3/reference/image-with-border-radius.ref.html": [
"d4cce1edd8a18653e9b0b144929001bcc6004c83",
"support"
],
"css/css-backgrounds-3/reference/ref-filled-black-96px-square.xht": [
"c4e874f13c7533a3f4357ba22522b609c4b7267a",
"support"
@@ -0,0 +1,13 @@
<!doctype html>
<meta charset="utf-8">
<title>Image with border-radius</title>
<link rel="match" href="reference/image-with-border-radius.ref.html">
<link rel="help" href="http://www.w3.org/TR/css3-background/#the-border-radius">

<style>
#image {
border-radius: 15px;
}
</style>

<img src="support/60x60-green.png" id="image"/>
@@ -0,0 +1,12 @@
<!doctype html>
<meta charset="utf-8">

<style>
#green {
width: 60px;
height: 60px;
border-radius: 15px;
}
</style>

<div id="green"><div/>
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.