mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Correctly paint the CSS canvas’ background
https://drafts.csswg.org/css-backgrounds/#special-backgrounds Fixes https://github.com/servo/servo/issues/25559 Closes https://github.com/servo/servo/pull/26121, as it is an alternative.
This commit is contained in:
parent
c7acfc37ed
commit
1f6efbf9e9
9 changed files with 312 additions and 37 deletions
|
@ -6,6 +6,7 @@ use crate::replaced::IntrinsicSizes;
|
|||
use euclid::{Size2D, Vector2D};
|
||||
use style::computed_values::background_clip::single_value::T as Clip;
|
||||
use style::computed_values::background_origin::single_value::T as Origin;
|
||||
use style::properties::ComputedValues;
|
||||
use style::values::computed::background::BackgroundSize as Size;
|
||||
use style::values::computed::{Length, LengthPercentage};
|
||||
use style::values::specified::background::BackgroundRepeat as RepeatXY;
|
||||
|
@ -31,17 +32,34 @@ fn get_cyclic<T>(values: &[T], layer_index: usize) -> &T {
|
|||
&values[layer_index % values.len()]
|
||||
}
|
||||
|
||||
pub(super) enum Source<'a> {
|
||||
Fragment,
|
||||
Canvas {
|
||||
style: &'a ComputedValues,
|
||||
|
||||
// Theoretically the painting area is the infinite 2D plane,
|
||||
// but WebRender doesn’t really do infinite so this is the part of it that can be visible.
|
||||
painting_area: units::LayoutRect,
|
||||
},
|
||||
}
|
||||
|
||||
pub(super) fn painting_area<'a>(
|
||||
fragment_builder: &'a super::BuilderForBoxFragment,
|
||||
source: &'a Source,
|
||||
builder: &mut super::DisplayListBuilder,
|
||||
layer_index: usize,
|
||||
) -> (&'a units::LayoutRect, wr::CommonItemProperties) {
|
||||
let fb = fragment_builder;
|
||||
let b = fb.fragment.style.get_background();
|
||||
let (painting_area, clip) = match get_cyclic(&b.background_clip.0, layer_index) {
|
||||
Clip::ContentBox => (fb.content_rect(), fb.content_edge_clip(builder)),
|
||||
Clip::PaddingBox => (fb.padding_rect(), fb.padding_edge_clip(builder)),
|
||||
Clip::BorderBox => (&fb.border_rect, fb.border_edge_clip(builder)),
|
||||
let (painting_area, clip) = match source {
|
||||
Source::Canvas { painting_area, .. } => (painting_area, None),
|
||||
Source::Fragment => {
|
||||
let fb = fragment_builder;
|
||||
let b = fb.fragment.style.get_background();
|
||||
match get_cyclic(&b.background_clip.0, layer_index) {
|
||||
Clip::ContentBox => (fb.content_rect(), fb.content_edge_clip(builder)),
|
||||
Clip::PaddingBox => (fb.padding_rect(), fb.padding_edge_clip(builder)),
|
||||
Clip::BorderBox => (&fb.border_rect, fb.border_edge_clip(builder)),
|
||||
}
|
||||
},
|
||||
};
|
||||
// The 'backgound-clip' property maps directly to `clip_rect` in `CommonItemProperties`:
|
||||
let mut common = builder.common_properties(*painting_area);
|
||||
|
@ -53,12 +71,17 @@ pub(super) fn painting_area<'a>(
|
|||
|
||||
pub(super) fn layout_layer(
|
||||
fragment_builder: &mut super::BuilderForBoxFragment,
|
||||
source: &Source,
|
||||
builder: &mut super::DisplayListBuilder,
|
||||
layer_index: usize,
|
||||
intrinsic: IntrinsicSizes,
|
||||
) -> Option<BackgroundLayer> {
|
||||
let b = fragment_builder.fragment.style.get_background();
|
||||
let (painting_area, common) = painting_area(fragment_builder, builder, layer_index);
|
||||
let style = match *source {
|
||||
Source::Canvas { style, .. } => style,
|
||||
Source::Fragment => &fragment_builder.fragment.style,
|
||||
};
|
||||
let b = style.get_background();
|
||||
let (painting_area, common) = painting_area(fragment_builder, source, builder, layer_index);
|
||||
|
||||
let positioning_area = match get_cyclic(&b.background_origin.0, layer_index) {
|
||||
Origin::ContentBox => fragment_builder.content_rect(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue