mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
layout: Port border-image
support for legacy layout (#32874)
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
29a4cca42d
commit
e23dc0bf6f
48 changed files with 295 additions and 338 deletions
|
@ -2,6 +2,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use euclid::Size2D;
|
||||
use style::color::mix::ColorInterpolationMethod;
|
||||
use style::properties::ComputedValues;
|
||||
use style::values::computed::image::{EndingShape, Gradient, LineDirection};
|
||||
|
@ -11,15 +12,25 @@ use style::values::computed::{
|
|||
use style::values::generics::image::{
|
||||
Circle, ColorStop, Ellipse, GradientFlags, GradientItem, ShapeExtent,
|
||||
};
|
||||
use webrender_api::{self as wr, units};
|
||||
use webrender_api::units::LayoutPixel;
|
||||
use webrender_api::{
|
||||
self as wr, units, ConicGradient as WebRenderConicGradient,
|
||||
Gradient as WebRenderLinearGradient, RadialGradient as WebRenderRadialGradient,
|
||||
};
|
||||
use wr::ColorF;
|
||||
|
||||
pub(super) enum WebRenderGradient {
|
||||
Linear(WebRenderLinearGradient),
|
||||
Radial(WebRenderRadialGradient),
|
||||
Conic(WebRenderConicGradient),
|
||||
}
|
||||
|
||||
pub(super) fn build(
|
||||
style: &ComputedValues,
|
||||
gradient: &Gradient,
|
||||
layer: &super::background::BackgroundLayer,
|
||||
size: Size2D<f32, LayoutPixel>,
|
||||
builder: &mut super::DisplayListBuilder,
|
||||
) {
|
||||
) -> WebRenderGradient {
|
||||
match gradient {
|
||||
Gradient::Linear {
|
||||
ref items,
|
||||
|
@ -33,7 +44,7 @@ pub(super) fn build(
|
|||
direction,
|
||||
color_interpolation_method,
|
||||
*flags,
|
||||
layer,
|
||||
size,
|
||||
builder,
|
||||
),
|
||||
Gradient::Radial {
|
||||
|
@ -50,7 +61,7 @@ pub(super) fn build(
|
|||
position,
|
||||
color_interpolation_method,
|
||||
*flags,
|
||||
layer,
|
||||
size,
|
||||
builder,
|
||||
),
|
||||
Gradient::Conic {
|
||||
|
@ -66,7 +77,7 @@ pub(super) fn build(
|
|||
*color_interpolation_method,
|
||||
items,
|
||||
*flags,
|
||||
layer,
|
||||
size,
|
||||
builder,
|
||||
),
|
||||
}
|
||||
|
@ -79,13 +90,12 @@ pub(super) fn build_linear(
|
|||
line_direction: &LineDirection,
|
||||
_color_interpolation_method: &ColorInterpolationMethod,
|
||||
flags: GradientFlags,
|
||||
layer: &super::background::BackgroundLayer,
|
||||
gradient_box: Size2D<f32, LayoutPixel>,
|
||||
builder: &mut super::DisplayListBuilder,
|
||||
) {
|
||||
) -> WebRenderGradient {
|
||||
use style::values::specified::position::HorizontalPositionKeyword::*;
|
||||
use style::values::specified::position::VerticalPositionKeyword::*;
|
||||
use units::LayoutVector2D as Vec2;
|
||||
let gradient_box = layer.tile_size;
|
||||
|
||||
// A vector of length 1.0 in the direction of the gradient line
|
||||
let direction = match line_direction {
|
||||
|
@ -168,16 +178,12 @@ pub(super) fn build_linear(
|
|||
} else {
|
||||
wr::ExtendMode::Clamp
|
||||
};
|
||||
let linear_gradient = builder
|
||||
.wr()
|
||||
.create_gradient(start_point, end_point, stops, extend_mode);
|
||||
builder.wr().push_gradient(
|
||||
&layer.common,
|
||||
layer.bounds,
|
||||
linear_gradient,
|
||||
layer.tile_size,
|
||||
layer.tile_spacing,
|
||||
)
|
||||
WebRenderGradient::Linear(builder.wr().create_gradient(
|
||||
start_point,
|
||||
end_point,
|
||||
stops,
|
||||
extend_mode,
|
||||
))
|
||||
}
|
||||
|
||||
/// <https://drafts.csswg.org/css-images-3/#radial-gradients>
|
||||
|
@ -189,10 +195,9 @@ pub(super) fn build_radial(
|
|||
center: &Position,
|
||||
_color_interpolation_method: &ColorInterpolationMethod,
|
||||
flags: GradientFlags,
|
||||
layer: &super::background::BackgroundLayer,
|
||||
gradient_box: Size2D<f32, LayoutPixel>,
|
||||
builder: &mut super::DisplayListBuilder,
|
||||
) {
|
||||
let gradient_box = layer.tile_size;
|
||||
) -> WebRenderGradient {
|
||||
let center = units::LayoutPoint::new(
|
||||
center
|
||||
.horizontal
|
||||
|
@ -277,16 +282,12 @@ pub(super) fn build_radial(
|
|||
} else {
|
||||
wr::ExtendMode::Clamp
|
||||
};
|
||||
let radial_gradient = builder
|
||||
.wr()
|
||||
.create_radial_gradient(center, radii, stops, extend_mode);
|
||||
builder.wr().push_radial_gradient(
|
||||
&layer.common,
|
||||
layer.bounds,
|
||||
radial_gradient,
|
||||
layer.tile_size,
|
||||
layer.tile_spacing,
|
||||
)
|
||||
WebRenderGradient::Radial(builder.wr().create_radial_gradient(
|
||||
center,
|
||||
radii,
|
||||
stops,
|
||||
extend_mode,
|
||||
))
|
||||
}
|
||||
|
||||
/// <https://drafts.csswg.org/css-images-4/#conic-gradients>
|
||||
|
@ -298,10 +299,9 @@ fn build_conic(
|
|||
_color_interpolation_method: ColorInterpolationMethod,
|
||||
items: &[GradientItem<Color, AngleOrPercentage>],
|
||||
flags: GradientFlags,
|
||||
layer: &super::background::BackgroundLayer,
|
||||
gradient_box: Size2D<f32, LayoutPixel>,
|
||||
builder: &mut super::DisplayListBuilder<'_>,
|
||||
) {
|
||||
let gradient_box = layer.tile_size;
|
||||
) -> WebRenderGradient {
|
||||
let center = units::LayoutPoint::new(
|
||||
center
|
||||
.horizontal
|
||||
|
@ -319,17 +319,12 @@ fn build_conic(
|
|||
} else {
|
||||
wr::ExtendMode::Clamp
|
||||
};
|
||||
let conic_gradient =
|
||||
builder
|
||||
.wr()
|
||||
.create_conic_gradient(center, angle.radians(), stops, extend_mode);
|
||||
builder.wr().push_conic_gradient(
|
||||
&layer.common,
|
||||
layer.bounds,
|
||||
conic_gradient,
|
||||
layer.tile_size,
|
||||
layer.tile_spacing,
|
||||
)
|
||||
WebRenderGradient::Conic(builder.wr().create_conic_gradient(
|
||||
center,
|
||||
angle.radians(),
|
||||
stops,
|
||||
extend_mode,
|
||||
))
|
||||
}
|
||||
|
||||
fn conic_gradient_items_to_color_stops(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue