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

Implement radial gradients #16385

Merged
merged 9 commits into from Apr 29, 2017

Use content_box instead of absoulte bounds in radial_gradient.

  • Loading branch information
pyfisch committed Apr 27, 2017
commit 6768614fdd9226314a2c208af4bbf2a38a0497be
@@ -393,7 +393,6 @@ pub trait FragmentDisplayListBuilding {
-> Option<display_list::Gradient>;

fn convert_radial_gradient(&self,
absolute_bounds: &Rect<Au>,
gradient: &Gradient,

This comment has been minimized.

@emilio

emilio Apr 16, 2017

Member

nit: Align to the paren.

style: &ServoComputedValues)
-> Option<display_list::RadialGradient>;
@@ -1111,34 +1110,38 @@ impl FragmentDisplayListBuilding for Fragment {
}

fn convert_radial_gradient(&self,
absolute_bounds: &Rect<Au>,
gradient: &Gradient,
style: &ServoComputedValues) -> Option<display_list::RadialGradient> {
// FIXME: Repeating gradients aren't implemented yet.
if gradient.repeating {
return None;

This comment has been minimized.

@emilio

emilio Apr 16, 2017

Member

nit: alignment is off here.

}
// FIXME(pcwalton, #2795): Get the real container size.
let container_size = Size2D::zero();
let content_box = self.content_box().to_physical(style.writing_mode, container_size);
let origin = content_box.origin;
let size = content_box.size;
if let GradientKind::Radial(ref shape, ref center) = gradient.gradient_kind {
let center = Point2D::new(specified(center.horizontal, absolute_bounds.size.width),
specified(center.vertical, absolute_bounds.size.height));
let center = Point2D::new(specified(center.horizontal, size.width),
specified(center.vertical, size.height));
let radius = match *shape {
EndingShape::Circle(LengthOrKeyword::Length(length))
=> Size2D::new(length, length),
EndingShape::Circle(LengthOrKeyword::Keyword(word))
=> convert_size_keyword(word, true, &absolute_bounds.size, &center),
=> convert_size_keyword(word, true, &size, &center),
EndingShape::Ellipse(LengthOrPercentageOrKeyword::LengthOrPercentage(horizontal,
vertical))
=> Size2D::new(specified(horizontal, absolute_bounds.size.width),
specified(vertical, absolute_bounds.size.height)),
=> Size2D::new(specified(horizontal, size.width),
specified(vertical, size.height)),
EndingShape::Ellipse(LengthOrPercentageOrKeyword::Keyword(word))
=> convert_size_keyword(word, false, &absolute_bounds.size, &center),
=> convert_size_keyword(word, false, &size, &center),
};
let length = Au::from_f32_px(radius.width.to_f32_px().hypot(radius.height.to_f32_px()));
let stops = convert_gradient_stops(&gradient.stops[..],
length,
style);
Some(display_list::RadialGradient {
center: absolute_bounds.origin + center,
center: origin + center,
radius: radius,
stops: stops,
})
@@ -1170,7 +1173,7 @@ impl FragmentDisplayListBuilding for Fragment {
});

state.add_display_item(gradient_display_item);
} else if let Some(x) = self.convert_radial_gradient(absolute_bounds, gradient, style) {
} else if let Some(x) = self.convert_radial_gradient(gradient, style) {
let base = state.create_base_display_item(absolute_bounds,
&clip,
self.node,
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.