mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Adress review comments
This commit is contained in:
parent
923cddf0b2
commit
37ccefbe19
2 changed files with 17 additions and 16 deletions
|
@ -12,7 +12,7 @@ use style::values::specified::background::BackgroundRepeat as RepeatXY;
|
||||||
use style::values::specified::background::BackgroundRepeatKeyword as Repeat;
|
use style::values::specified::background::BackgroundRepeatKeyword as Repeat;
|
||||||
use webrender_api::{self as wr, units};
|
use webrender_api::{self as wr, units};
|
||||||
|
|
||||||
pub(super) struct Layer {
|
pub(super) struct BackgroundLayer {
|
||||||
pub common: wr::CommonItemProperties,
|
pub common: wr::CommonItemProperties,
|
||||||
pub bounds: units::LayoutRect,
|
pub bounds: units::LayoutRect,
|
||||||
pub tile_size: units::LayoutSize,
|
pub tile_size: units::LayoutSize,
|
||||||
|
@ -24,6 +24,7 @@ struct Layout1DResult {
|
||||||
repeat: bool,
|
repeat: bool,
|
||||||
bounds_origin: f32,
|
bounds_origin: f32,
|
||||||
bounds_size: f32,
|
bounds_size: f32,
|
||||||
|
tile_spacing: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_cyclic<T>(values: &[T], layer_index: usize) -> &T {
|
fn get_cyclic<T>(values: &[T], layer_index: usize) -> &T {
|
||||||
|
@ -55,7 +56,7 @@ pub(super) fn layout_layer(
|
||||||
builder: &mut super::DisplayListBuilder,
|
builder: &mut super::DisplayListBuilder,
|
||||||
layer_index: usize,
|
layer_index: usize,
|
||||||
intrinsic: IntrinsicSizes,
|
intrinsic: IntrinsicSizes,
|
||||||
) -> Option<Layer> {
|
) -> Option<BackgroundLayer> {
|
||||||
let b = fragment_builder.fragment.style.get_background();
|
let b = fragment_builder.fragment.style.get_background();
|
||||||
let (painting_area, common) = painting_area(fragment_builder, builder, layer_index);
|
let (painting_area, common) = painting_area(fragment_builder, builder, layer_index);
|
||||||
|
|
||||||
|
@ -141,11 +142,9 @@ pub(super) fn layout_layer(
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut tile_spacing = units::LayoutSize::zero();
|
|
||||||
let RepeatXY(repeat_x, repeat_y) = *get_cyclic(&b.background_repeat.0, layer_index);
|
let RepeatXY(repeat_x, repeat_y) = *get_cyclic(&b.background_repeat.0, layer_index);
|
||||||
let result_x = layout_1d(
|
let result_x = layout_1d(
|
||||||
&mut tile_size.width,
|
&mut tile_size.width,
|
||||||
&mut tile_spacing.width,
|
|
||||||
repeat_x,
|
repeat_x,
|
||||||
get_cyclic(&b.background_position_x.0, layer_index),
|
get_cyclic(&b.background_position_x.0, layer_index),
|
||||||
painting_area.origin.x - positioning_area.origin.x,
|
painting_area.origin.x - positioning_area.origin.x,
|
||||||
|
@ -154,7 +153,6 @@ pub(super) fn layout_layer(
|
||||||
);
|
);
|
||||||
let result_y = layout_1d(
|
let result_y = layout_1d(
|
||||||
&mut tile_size.height,
|
&mut tile_size.height,
|
||||||
&mut tile_spacing.height,
|
|
||||||
repeat_y,
|
repeat_y,
|
||||||
get_cyclic(&b.background_position_y.0, layer_index),
|
get_cyclic(&b.background_position_y.0, layer_index),
|
||||||
painting_area.origin.y - positioning_area.origin.y,
|
painting_area.origin.y - positioning_area.origin.y,
|
||||||
|
@ -165,8 +163,9 @@ pub(super) fn layout_layer(
|
||||||
positioning_area.origin + Vector2D::new(result_x.bounds_origin, result_y.bounds_origin),
|
positioning_area.origin + Vector2D::new(result_x.bounds_origin, result_y.bounds_origin),
|
||||||
Size2D::new(result_x.bounds_size, result_y.bounds_size),
|
Size2D::new(result_x.bounds_size, result_y.bounds_size),
|
||||||
);
|
);
|
||||||
|
let tile_spacing = units::LayoutSize::new(result_x.tile_spacing, result_y.tile_spacing);
|
||||||
|
|
||||||
Some(Layer {
|
Some(BackgroundLayer {
|
||||||
common,
|
common,
|
||||||
bounds,
|
bounds,
|
||||||
tile_size,
|
tile_size,
|
||||||
|
@ -179,7 +178,6 @@ pub(super) fn layout_layer(
|
||||||
/// Coordinates (0, 0) for the purpose of this function are the positioning area’s origin.
|
/// Coordinates (0, 0) for the purpose of this function are the positioning area’s origin.
|
||||||
fn layout_1d(
|
fn layout_1d(
|
||||||
tile_size: &mut f32,
|
tile_size: &mut f32,
|
||||||
tile_spacing: &mut f32,
|
|
||||||
mut repeat: Repeat,
|
mut repeat: Repeat,
|
||||||
position: &LengthPercentage,
|
position: &LengthPercentage,
|
||||||
painting_area_origin: f32,
|
painting_area_origin: f32,
|
||||||
|
@ -194,6 +192,7 @@ fn layout_1d(
|
||||||
let mut position = position
|
let mut position = position
|
||||||
.percentage_relative_to(Length::new(positioning_area_size - *tile_size))
|
.percentage_relative_to(Length::new(positioning_area_size - *tile_size))
|
||||||
.px();
|
.px();
|
||||||
|
let mut tile_spacing = 0.0;
|
||||||
// https://drafts.csswg.org/css-backgrounds/#background-repeat
|
// https://drafts.csswg.org/css-backgrounds/#background-repeat
|
||||||
if let Repeat::Space = repeat {
|
if let Repeat::Space = repeat {
|
||||||
// The most entire tiles we can fit
|
// The most entire tiles we can fit
|
||||||
|
@ -204,7 +203,7 @@ fn layout_1d(
|
||||||
// touch the edges of the positioning area:
|
// touch the edges of the positioning area:
|
||||||
let total_space = positioning_area_size - *tile_size * tile_count;
|
let total_space = positioning_area_size - *tile_size * tile_count;
|
||||||
let spaces_count = tile_count - 1.0;
|
let spaces_count = tile_count - 1.0;
|
||||||
*tile_spacing = total_space / spaces_count;
|
tile_spacing = total_space / spaces_count;
|
||||||
} else {
|
} else {
|
||||||
repeat = Repeat::NoRepeat
|
repeat = Repeat::NoRepeat
|
||||||
}
|
}
|
||||||
|
@ -225,7 +224,7 @@ fn layout_1d(
|
||||||
//
|
//
|
||||||
// * Its bottom-right is the bottom-right of `clip_rect`
|
// * Its bottom-right is the bottom-right of `clip_rect`
|
||||||
// * Its top-left is the top-left of first tile.
|
// * Its top-left is the top-left of first tile.
|
||||||
let tile_stride = *tile_size + *tile_spacing;
|
let tile_stride = *tile_size + tile_spacing;
|
||||||
let offset = position - painting_area_origin;
|
let offset = position - painting_area_origin;
|
||||||
let bounds_origin = position - tile_stride * (offset / tile_stride).ceil();
|
let bounds_origin = position - tile_stride * (offset / tile_stride).ceil();
|
||||||
let bounds_size = painting_area_size - bounds_origin - painting_area_origin;
|
let bounds_size = painting_area_size - bounds_origin - painting_area_origin;
|
||||||
|
@ -233,6 +232,7 @@ fn layout_1d(
|
||||||
repeat: true,
|
repeat: true,
|
||||||
bounds_origin,
|
bounds_origin,
|
||||||
bounds_size,
|
bounds_size,
|
||||||
|
tile_spacing,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Repeat::NoRepeat => {
|
Repeat::NoRepeat => {
|
||||||
|
@ -244,6 +244,7 @@ fn layout_1d(
|
||||||
repeat: false,
|
repeat: false,
|
||||||
bounds_origin: position,
|
bounds_origin: position,
|
||||||
bounds_size: *tile_size,
|
bounds_size: *tile_size,
|
||||||
|
tile_spacing: 0.0,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ use webrender_api::{self as wr, units};
|
||||||
pub(super) fn build(
|
pub(super) fn build(
|
||||||
style: &ComputedValues,
|
style: &ComputedValues,
|
||||||
gradient: &Gradient,
|
gradient: &Gradient,
|
||||||
layer: &super::background::Layer,
|
layer: &super::background::BackgroundLayer,
|
||||||
builder: &mut super::DisplayListBuilder,
|
builder: &mut super::DisplayListBuilder,
|
||||||
) {
|
) {
|
||||||
let extend_mode = if gradient.repeating {
|
let extend_mode = if gradient.repeating {
|
||||||
|
@ -47,7 +47,7 @@ pub(super) fn build_linear(
|
||||||
items: &[GradientItem],
|
items: &[GradientItem],
|
||||||
line_direction: &LineDirection,
|
line_direction: &LineDirection,
|
||||||
extend_mode: wr::ExtendMode,
|
extend_mode: wr::ExtendMode,
|
||||||
layer: &super::background::Layer,
|
layer: &super::background::BackgroundLayer,
|
||||||
builder: &mut super::DisplayListBuilder,
|
builder: &mut super::DisplayListBuilder,
|
||||||
) {
|
) {
|
||||||
use style::values::specified::position::HorizontalPositionKeyword::*;
|
use style::values::specified::position::HorizontalPositionKeyword::*;
|
||||||
|
@ -102,7 +102,7 @@ pub(super) fn build_linear(
|
||||||
|
|
||||||
// `{ x, y }` is now a vector of arbitrary length
|
// `{ x, y }` is now a vector of arbitrary length
|
||||||
// with the same direction as the gradient line.
|
// with the same direction as the gradient line.
|
||||||
|
// This normalizes the length to 1.0:
|
||||||
Vec2::new(x, y).normalize()
|
Vec2::new(x, y).normalize()
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -128,7 +128,7 @@ pub(super) fn build_linear(
|
||||||
let start_point = center - half_gradient_line;
|
let start_point = center - half_gradient_line;
|
||||||
let end_point = center + half_gradient_line;
|
let end_point = center + half_gradient_line;
|
||||||
|
|
||||||
let stops = stops_fixup(style, items, Length::new(gradient_line_length));
|
let stops = fixup_stops(style, items, Length::new(gradient_line_length));
|
||||||
let linear_gradient = builder
|
let linear_gradient = builder
|
||||||
.wr
|
.wr
|
||||||
.create_gradient(start_point, end_point, stops, extend_mode);
|
.create_gradient(start_point, end_point, stops, extend_mode);
|
||||||
|
@ -148,7 +148,7 @@ pub(super) fn build_radial(
|
||||||
shape: &EndingShape,
|
shape: &EndingShape,
|
||||||
center: &Position,
|
center: &Position,
|
||||||
extend_mode: wr::ExtendMode,
|
extend_mode: wr::ExtendMode,
|
||||||
layer: &super::background::Layer,
|
layer: &super::background::BackgroundLayer,
|
||||||
builder: &mut super::DisplayListBuilder,
|
builder: &mut super::DisplayListBuilder,
|
||||||
) {
|
) {
|
||||||
let gradient_box = layer.tile_size;
|
let gradient_box = layer.tile_size;
|
||||||
|
@ -228,7 +228,7 @@ pub(super) fn build_radial(
|
||||||
// where the gradient line intersects the ending shape.”
|
// where the gradient line intersects the ending shape.”
|
||||||
let gradient_line_length = radii.width;
|
let gradient_line_length = radii.width;
|
||||||
|
|
||||||
let stops = stops_fixup(style, items, Length::new(gradient_line_length));
|
let stops = fixup_stops(style, items, Length::new(gradient_line_length));
|
||||||
let radial_gradient = builder
|
let radial_gradient = builder
|
||||||
.wr
|
.wr
|
||||||
.create_radial_gradient(center, radii, stops, extend_mode);
|
.create_radial_gradient(center, radii, stops, extend_mode);
|
||||||
|
@ -242,7 +242,7 @@ pub(super) fn build_radial(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://drafts.csswg.org/css-images-4/#color-stop-fixup
|
/// https://drafts.csswg.org/css-images-4/#color-stop-fixup
|
||||||
fn stops_fixup(
|
fn fixup_stops(
|
||||||
style: &ComputedValues,
|
style: &ComputedValues,
|
||||||
items: &[GradientItem],
|
items: &[GradientItem],
|
||||||
gradient_line_length: Length,
|
gradient_line_length: Length,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue