mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #16096 - stshine:die-modify-style-die, r=emilio
Use Servo-specific pseudo elements for anonymous box and text <!-- Please describe your changes on the following line: --> Use some fake pseudo elements to style servo-specific boxes in servo. Also, Since for nested inline elements non-inheritable properties are properly stored in the inline context of an inline fragment, so get rid of them on the style using empty pseudo to do cascading. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #5625 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because refactoring <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16096) <!-- Reviewable:end -->
This commit is contained in:
commit
449758ef5d
9 changed files with 126 additions and 259 deletions
|
@ -2398,96 +2398,6 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
|
|||
style
|
||||
}
|
||||
|
||||
/// Modifies the style for an anonymous flow so it resets all its non-inherited
|
||||
/// style structs, and set their borders and outlines to zero.
|
||||
///
|
||||
/// Also, it gets a new display value, which is honored except when it's
|
||||
/// `inline`.
|
||||
#[cfg(feature = "servo")]
|
||||
pub fn modify_style_for_anonymous_flow(style: &mut Arc<ComputedValues>,
|
||||
new_display_value: longhands::display::computed_value::T) {
|
||||
// The 'align-self' property needs some special treatment since
|
||||
// its value depends on the 'align-items' value of its parent.
|
||||
% if "align-items" in data.longhands_by_name:
|
||||
use computed_values::align_self::T as align_self;
|
||||
use computed_values::align_items::T as align_items;
|
||||
let self_align =
|
||||
match style.position.align_items {
|
||||
align_items::stretch => align_self::stretch,
|
||||
align_items::baseline => align_self::baseline,
|
||||
align_items::flex_start => align_self::flex_start,
|
||||
align_items::flex_end => align_self::flex_end,
|
||||
align_items::center => align_self::center,
|
||||
};
|
||||
% endif
|
||||
let inital_values = &*INITIAL_SERVO_VALUES;
|
||||
let mut style = Arc::make_mut(style);
|
||||
% for style_struct in data.active_style_structs():
|
||||
% if not style_struct.inherited:
|
||||
style.${style_struct.ident} = inital_values.clone_${style_struct.name_lower}();
|
||||
% endif
|
||||
% endfor
|
||||
% if "align-items" in data.longhands_by_name:
|
||||
let position = Arc::make_mut(&mut style.position);
|
||||
position.align_self = self_align;
|
||||
% endif
|
||||
if new_display_value != longhands::display::computed_value::T::inline {
|
||||
let new_box = Arc::make_mut(&mut style.box_);
|
||||
new_box.display = new_display_value;
|
||||
}
|
||||
let border = Arc::make_mut(&mut style.border);
|
||||
% for side in ["top", "right", "bottom", "left"]:
|
||||
// Like calling to_computed_value, which wouldn't type check.
|
||||
border.border_${side}_width = Au(0);
|
||||
% endfor
|
||||
// Initial value of outline-style is always none for anonymous box.
|
||||
let outline = Arc::make_mut(&mut style.outline);
|
||||
outline.outline_width = Au(0);
|
||||
}
|
||||
|
||||
/// Alters the given style to accommodate replaced content. This is called in
|
||||
/// flow construction. It handles cases like:
|
||||
///
|
||||
/// <div style="position: absolute">foo bar baz</div>
|
||||
///
|
||||
/// (in which `foo`, `bar`, and `baz` must not be absolutely-positioned) and
|
||||
/// cases like `<sup>Foo</sup>` (in which the `vertical-align: top` style of
|
||||
/// `sup` must not propagate down into `Foo`).
|
||||
///
|
||||
/// FIXME(#5625, pcwalton): It would probably be cleaner and faster to do this
|
||||
/// in the cascade.
|
||||
#[cfg(feature = "servo")]
|
||||
#[inline]
|
||||
pub fn modify_style_for_replaced_content(style: &mut Arc<ComputedValues>) {
|
||||
// Reset `position` to handle cases like `<div style="position: absolute">foo bar baz</div>`.
|
||||
if style.box_.display != longhands::display::computed_value::T::inline {
|
||||
let mut style = Arc::make_mut(style);
|
||||
Arc::make_mut(&mut style.box_).display = longhands::display::computed_value::T::inline;
|
||||
Arc::make_mut(&mut style.box_).position =
|
||||
longhands::position::computed_value::T::static_;
|
||||
}
|
||||
|
||||
// Reset `vertical-align` to handle cases like `<sup>foo</sup>`.
|
||||
if style.box_.vertical_align != longhands::vertical_align::computed_value::T::baseline {
|
||||
let mut style = Arc::make_mut(style);
|
||||
Arc::make_mut(&mut style.box_).vertical_align =
|
||||
longhands::vertical_align::computed_value::T::baseline
|
||||
}
|
||||
|
||||
// Reset margins.
|
||||
if style.margin.margin_top != computed::LengthOrPercentageOrAuto::Length(Au(0)) ||
|
||||
style.margin.margin_left != computed::LengthOrPercentageOrAuto::Length(Au(0)) ||
|
||||
style.margin.margin_bottom != computed::LengthOrPercentageOrAuto::Length(Au(0)) ||
|
||||
style.margin.margin_right != computed::LengthOrPercentageOrAuto::Length(Au(0)) {
|
||||
let mut style = Arc::make_mut(style);
|
||||
let margin = Arc::make_mut(&mut style.margin);
|
||||
margin.margin_top = computed::LengthOrPercentageOrAuto::Length(Au(0));
|
||||
margin.margin_left = computed::LengthOrPercentageOrAuto::Length(Au(0));
|
||||
margin.margin_bottom = computed::LengthOrPercentageOrAuto::Length(Au(0));
|
||||
margin.margin_right = computed::LengthOrPercentageOrAuto::Length(Au(0));
|
||||
}
|
||||
}
|
||||
|
||||
/// Adjusts borders as appropriate to account for a fragment's status as the
|
||||
/// first or last fragment within the range of an element.
|
||||
///
|
||||
|
@ -2544,65 +2454,6 @@ pub fn modify_border_style_for_inline_sides(style: &mut Arc<ComputedValues>,
|
|||
}
|
||||
}
|
||||
|
||||
/// Adjusts the `position` property as necessary for the outer fragment wrapper
|
||||
/// of an inline-block.
|
||||
#[cfg(feature = "servo")]
|
||||
#[inline]
|
||||
pub fn modify_style_for_outer_inline_block_fragment(style: &mut Arc<ComputedValues>) {
|
||||
let mut style = Arc::make_mut(style);
|
||||
let box_style = Arc::make_mut(&mut style.box_);
|
||||
box_style.position = longhands::position::computed_value::T::static_
|
||||
}
|
||||
|
||||
/// Adjusts the `position` and `padding` properties as necessary to account for
|
||||
/// text.
|
||||
///
|
||||
/// Text is never directly relatively positioned; it's always contained within
|
||||
/// an element that is itself relatively positioned.
|
||||
#[cfg(feature = "servo")]
|
||||
#[inline]
|
||||
pub fn modify_style_for_text(style: &mut Arc<ComputedValues>) {
|
||||
if style.box_.position == longhands::position::computed_value::T::relative {
|
||||
// We leave the `position` property set to `relative` so that we'll still establish a
|
||||
// containing block if needed. But we reset all position offsets to `auto`.
|
||||
let mut style = Arc::make_mut(style);
|
||||
let mut position = Arc::make_mut(&mut style.position);
|
||||
position.top = computed::LengthOrPercentageOrAuto::Auto;
|
||||
position.right = computed::LengthOrPercentageOrAuto::Auto;
|
||||
position.bottom = computed::LengthOrPercentageOrAuto::Auto;
|
||||
position.left = computed::LengthOrPercentageOrAuto::Auto;
|
||||
}
|
||||
|
||||
if style.padding.padding_top != computed::LengthOrPercentage::Length(Au(0)) ||
|
||||
style.padding.padding_right != computed::LengthOrPercentage::Length(Au(0)) ||
|
||||
style.padding.padding_bottom != computed::LengthOrPercentage::Length(Au(0)) ||
|
||||
style.padding.padding_left != computed::LengthOrPercentage::Length(Au(0)) {
|
||||
let mut style = Arc::make_mut(style);
|
||||
let mut padding = Arc::make_mut(&mut style.padding);
|
||||
padding.padding_top = computed::LengthOrPercentage::Length(Au(0));
|
||||
padding.padding_right = computed::LengthOrPercentage::Length(Au(0));
|
||||
padding.padding_bottom = computed::LengthOrPercentage::Length(Au(0));
|
||||
padding.padding_left = computed::LengthOrPercentage::Length(Au(0));
|
||||
}
|
||||
|
||||
if style.effects.opacity != 1.0 {
|
||||
let mut style = Arc::make_mut(style);
|
||||
let mut effects = Arc::make_mut(&mut style.effects);
|
||||
effects.opacity = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
/// Adjusts the `clip` property so that an inline absolute hypothetical fragment
|
||||
/// doesn't clip its children.
|
||||
#[cfg(feature = "servo")]
|
||||
pub fn modify_style_for_inline_absolute_hypothetical_fragment(style: &mut Arc<ComputedValues>) {
|
||||
if !style.get_effects().clip.is_auto() {
|
||||
let mut style = Arc::make_mut(style);
|
||||
let effects_style = Arc::make_mut(&mut style.effects);
|
||||
effects_style.clip = Either::auto()
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! css_properties_accessors {
|
||||
($macro_name: ident) => {
|
||||
|
|
|
@ -32,6 +32,7 @@ pub enum PseudoElement {
|
|||
Selection,
|
||||
DetailsSummary,
|
||||
DetailsContent,
|
||||
ServoText,
|
||||
ServoInputText,
|
||||
ServoTableWrapper,
|
||||
ServoAnonymousTableWrapper,
|
||||
|
@ -39,6 +40,8 @@ pub enum PseudoElement {
|
|||
ServoAnonymousTableRow,
|
||||
ServoAnonymousTableCell,
|
||||
ServoAnonymousBlock,
|
||||
ServoInlineBlockWrapper,
|
||||
ServoInlineAbsolute,
|
||||
}
|
||||
|
||||
impl ToCss for PseudoElement {
|
||||
|
@ -50,6 +53,7 @@ impl ToCss for PseudoElement {
|
|||
Selection => "::selection",
|
||||
DetailsSummary => "::-servo-details-summary",
|
||||
DetailsContent => "::-servo-details-content",
|
||||
ServoText => "::-servo-text",
|
||||
ServoInputText => "::-servo-input-text",
|
||||
ServoTableWrapper => "::-servo-table-wrapper",
|
||||
ServoAnonymousTableWrapper => "::-servo-anonymous-table-wrapper",
|
||||
|
@ -57,6 +61,8 @@ impl ToCss for PseudoElement {
|
|||
ServoAnonymousTableRow => "::-servo-anonymous-table-row",
|
||||
ServoAnonymousTableCell => "::-servo-anonymous-table-cell",
|
||||
ServoAnonymousBlock => "::-servo-anonymous-block",
|
||||
ServoInlineBlockWrapper => "::-servo-inline-block-wrapper",
|
||||
ServoInlineAbsolute => "::-servo-inline-absolute",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -83,13 +89,16 @@ impl PseudoElement {
|
|||
PseudoElement::Selection => PseudoElementCascadeType::Eager,
|
||||
PseudoElement::DetailsSummary => PseudoElementCascadeType::Lazy,
|
||||
PseudoElement::DetailsContent |
|
||||
PseudoElement::ServoText |
|
||||
PseudoElement::ServoInputText |
|
||||
PseudoElement::ServoTableWrapper |
|
||||
PseudoElement::ServoAnonymousTableWrapper |
|
||||
PseudoElement::ServoAnonymousTable |
|
||||
PseudoElement::ServoAnonymousTableRow |
|
||||
PseudoElement::ServoAnonymousTableCell |
|
||||
PseudoElement::ServoAnonymousBlock => PseudoElementCascadeType::Precomputed,
|
||||
PseudoElement::ServoAnonymousBlock |
|
||||
PseudoElement::ServoInlineBlockWrapper |
|
||||
PseudoElement::ServoInlineAbsolute => PseudoElementCascadeType::Precomputed,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -278,6 +287,12 @@ impl<'a> ::selectors::Parser for SelectorParser<'a> {
|
|||
}
|
||||
DetailsContent
|
||||
},
|
||||
"-servo-text" => {
|
||||
if !self.in_user_agent_stylesheet() {
|
||||
return Err(())
|
||||
}
|
||||
ServoText
|
||||
},
|
||||
"-servo-input-text" => {
|
||||
if !self.in_user_agent_stylesheet() {
|
||||
return Err(())
|
||||
|
@ -320,6 +335,18 @@ impl<'a> ::selectors::Parser for SelectorParser<'a> {
|
|||
}
|
||||
ServoAnonymousBlock
|
||||
},
|
||||
"-servo-inline-block-wrapper" => {
|
||||
if !self.in_user_agent_stylesheet() {
|
||||
return Err(())
|
||||
}
|
||||
ServoInlineBlockWrapper
|
||||
},
|
||||
"-servo-input-absolute" => {
|
||||
if !self.in_user_agent_stylesheet() {
|
||||
return Err(())
|
||||
}
|
||||
ServoInlineAbsolute
|
||||
},
|
||||
_ => return Err(())
|
||||
};
|
||||
|
||||
|
@ -352,6 +379,7 @@ impl SelectorImpl {
|
|||
fun(PseudoElement::DetailsContent);
|
||||
fun(PseudoElement::DetailsSummary);
|
||||
fun(PseudoElement::Selection);
|
||||
fun(PseudoElement::ServoText);
|
||||
fun(PseudoElement::ServoInputText);
|
||||
fun(PseudoElement::ServoTableWrapper);
|
||||
fun(PseudoElement::ServoAnonymousTableWrapper);
|
||||
|
@ -359,6 +387,8 @@ impl SelectorImpl {
|
|||
fun(PseudoElement::ServoAnonymousTableRow);
|
||||
fun(PseudoElement::ServoAnonymousTableCell);
|
||||
fun(PseudoElement::ServoAnonymousBlock);
|
||||
fun(PseudoElement::ServoInlineBlockWrapper);
|
||||
fun(PseudoElement::ServoInlineAbsolute);
|
||||
}
|
||||
|
||||
/// Returns the pseudo-class state flag for selector matching.
|
||||
|
|
|
@ -385,20 +385,23 @@ impl Stylist {
|
|||
|
||||
/// Returns the style for an anonymous box of the given type.
|
||||
#[cfg(feature = "servo")]
|
||||
pub fn style_for_anonymous_box(&self,
|
||||
guards: &StylesheetGuards,
|
||||
pseudo: &PseudoElement,
|
||||
parent_style: &Arc<ComputedValues>)
|
||||
-> Arc<ComputedValues> {
|
||||
pub fn style_for_anonymous(&self,
|
||||
guards: &StylesheetGuards,
|
||||
pseudo: &PseudoElement,
|
||||
parent_style: &Arc<ComputedValues>)
|
||||
-> Arc<ComputedValues> {
|
||||
// For most (but not all) pseudo-elements, we inherit all values from the parent.
|
||||
let inherit_all = match *pseudo {
|
||||
PseudoElement::ServoText |
|
||||
PseudoElement::ServoInputText => false,
|
||||
PseudoElement::ServoAnonymousBlock |
|
||||
PseudoElement::ServoAnonymousTable |
|
||||
PseudoElement::ServoAnonymousTableCell |
|
||||
PseudoElement::ServoAnonymousTableRow |
|
||||
PseudoElement::ServoAnonymousTableWrapper |
|
||||
PseudoElement::ServoTableWrapper => true,
|
||||
PseudoElement::ServoTableWrapper |
|
||||
PseudoElement::ServoInlineBlockWrapper |
|
||||
PseudoElement::ServoInlineAbsolute => true,
|
||||
PseudoElement::Before |
|
||||
PseudoElement::After |
|
||||
PseudoElement::Selection |
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue