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
Background follow ups #25594
Merged
+6,003
−292
Merged
Background follow ups #25594
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
68edef1
Layout 2020: enable web-platform-tests/css/css-background
SimonSapin 42bec01
Expected results for newly-enabled tests
SimonSapin 6901bf9
Make `layout_2020::display_list` a directory-module
SimonSapin c8c198a
Add a `display_list::background` module
SimonSapin 9fedade
Rename `clipping_area` to `painting_area`
SimonSapin ea4882a
Fix combinations of `border-radius` and `background-clip`
SimonSapin f39c3ff
Apply `background-clip` to `background-color`
SimonSapin 632e731
Render gradients
SimonSapin 923cddf
Update WPT expectations
SimonSapin 37ccefb
Adress review comments
SimonSapin File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
Loading status checks…
Adress review comments
- Loading branch information
commit 37ccefbe19e01edcaa8257b821c5e823b85ecd21
| @@ -12,7 +12,7 @@ use style::values::specified::background::BackgroundRepeat as RepeatXY; | ||
| use style::values::specified::background::BackgroundRepeatKeyword as Repeat; | ||
| use webrender_api::{self as wr, units}; | ||
|
|
||
| pub(super) struct Layer { | ||
| pub(super) struct BackgroundLayer { | ||
| pub common: wr::CommonItemProperties, | ||
| pub bounds: units::LayoutRect, | ||
| pub tile_size: units::LayoutSize, | ||
| @@ -24,6 +24,7 @@ struct Layout1DResult { | ||
| repeat: bool, | ||
| bounds_origin: f32, | ||
| bounds_size: f32, | ||
| tile_spacing: f32, | ||
| } | ||
|
|
||
| fn get_cyclic<T>(values: &[T], layer_index: usize) -> &T { | ||
| @@ -55,7 +56,7 @@ pub(super) fn layout_layer( | ||
| builder: &mut super::DisplayListBuilder, | ||
| layer_index: usize, | ||
| intrinsic: IntrinsicSizes, | ||
| ) -> Option<Layer> { | ||
| ) -> Option<BackgroundLayer> { | ||
| let b = fragment_builder.fragment.style.get_background(); | ||
| let (painting_area, common) = painting_area(fragment_builder, builder, layer_index); | ||
|
|
||
| @@ -141,11 +142,9 @@ pub(super) fn layout_layer( | ||
| return None; | ||
| } | ||
|
|
||
| let mut tile_spacing = units::LayoutSize::zero(); | ||
| let RepeatXY(repeat_x, repeat_y) = *get_cyclic(&b.background_repeat.0, layer_index); | ||
| let result_x = layout_1d( | ||
| &mut tile_size.width, | ||
| &mut tile_spacing.width, | ||
| repeat_x, | ||
| get_cyclic(&b.background_position_x.0, layer_index), | ||
| painting_area.origin.x - positioning_area.origin.x, | ||
| @@ -154,7 +153,6 @@ pub(super) fn layout_layer( | ||
| ); | ||
| let result_y = layout_1d( | ||
| &mut tile_size.height, | ||
| &mut tile_spacing.height, | ||
| repeat_y, | ||
| get_cyclic(&b.background_position_y.0, layer_index), | ||
| 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), | ||
| 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, | ||
| bounds, | ||
| 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. | ||
| fn layout_1d( | ||
SimonSapin
Author
Member
|
||
| tile_size: &mut f32, | ||
| tile_spacing: &mut f32, | ||
| mut repeat: Repeat, | ||
| position: &LengthPercentage, | ||
| painting_area_origin: f32, | ||
| @@ -194,6 +192,7 @@ fn layout_1d( | ||
| let mut position = position | ||
| .percentage_relative_to(Length::new(positioning_area_size - *tile_size)) | ||
| .px(); | ||
| let mut tile_spacing = 0.0; | ||
| // https://drafts.csswg.org/css-backgrounds/#background-repeat | ||
| if let Repeat::Space = repeat { | ||
| // The most entire tiles we can fit | ||
| @@ -204,7 +203,7 @@ fn layout_1d( | ||
| // touch the edges of the positioning area: | ||
| let total_space = positioning_area_size - *tile_size * tile_count; | ||
| let spaces_count = tile_count - 1.0; | ||
| *tile_spacing = total_space / spaces_count; | ||
| tile_spacing = total_space / spaces_count; | ||
| } else { | ||
| repeat = Repeat::NoRepeat | ||
| } | ||
| @@ -225,14 +224,15 @@ fn layout_1d( | ||
| // | ||
| // * Its bottom-right is the bottom-right of `clip_rect` | ||
| // * 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 bounds_origin = position - tile_stride * (offset / tile_stride).ceil(); | ||
| let bounds_size = painting_area_size - bounds_origin - painting_area_origin; | ||
| Layout1DResult { | ||
| repeat: true, | ||
| bounds_origin, | ||
| bounds_size, | ||
| tile_spacing, | ||
| } | ||
| }, | ||
| Repeat::NoRepeat => { | ||
| @@ -244,6 +244,7 @@ fn layout_1d( | ||
| repeat: false, | ||
| bounds_origin: position, | ||
| bounds_size: *tile_size, | ||
| tile_spacing: 0.0, | ||
| } | ||
| }, | ||
| } | ||
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Perhaps it makes sense to make this a factory method for
Layout1DResult?