From 8500f3c8b8351a5888a79a008c5da65d63b21355 Mon Sep 17 00:00:00 2001 From: Jonathan Schuster Date: Wed, 21 Sep 2016 11:19:48 -0400 Subject: [PATCH] Style input-text pseudo with user-agent CSS --- components/layout/construct.rs | 4 +++- components/style/properties/properties.mako.rs | 14 -------------- components/style/servo_selector_impl.rs | 12 +++++++++++- resources/servo.css | 4 ++++ .../html/flex-vertical-align-effect.htm.ini | 3 --- 5 files changed, 18 insertions(+), 19 deletions(-) delete mode 100644 tests/wpt/metadata-css/css-flexbox-1_dev/html/flex-vertical-align-effect.htm.ini diff --git a/components/layout/construct.rs b/components/layout/construct.rs index c89d45c966c..d5a788778f2 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -48,6 +48,7 @@ use style::computed_values::content::ContentItem; use style::computed_values::position; use style::context::SharedStyleContext; use style::properties::{self, ServoComputedValues}; +use style::servo_selector_impl::PseudoElement; use table::TableFlow; use table_caption::TableCaptionFlow; use table_cell::TableCellFlow; @@ -693,7 +694,8 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> let mut style = node.style(self.style_context()).clone(); if node_is_input_or_text_area { - properties::modify_style_for_input_text(&mut style); + style = self.style_context().stylist. + precomputed_values_for_pseudo(&PseudoElement::ServoInputText, Some(&style)).unwrap(); } self.create_fragments_for_node_text_content(&mut initial_fragments, node, &style) diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index f2f8fbd2b66..e891b051ee3 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -2278,20 +2278,6 @@ pub fn modify_style_for_text(style: &mut Arc) { } } -/// Adjusts the `margin` property as necessary to account for the text of an `input` element. -/// -/// Margins apply to the `input` element itself, so including them in the text will cause them to -/// be double-counted. -#[cfg(feature = "servo")] -pub fn modify_style_for_input_text(style: &mut Arc) { - let mut style = Arc::make_mut(style); - let margin_style = Arc::make_mut(&mut style.margin); - margin_style.margin_top = computed::LengthOrPercentageOrAuto::Length(Au(0)); - margin_style.margin_right = computed::LengthOrPercentageOrAuto::Length(Au(0)); - margin_style.margin_bottom = computed::LengthOrPercentageOrAuto::Length(Au(0)); - margin_style.margin_left = computed::LengthOrPercentageOrAuto::Length(Au(0)); -} - /// Adjusts the `clip` property so that an inline absolute hypothetical fragment doesn't clip its /// children. #[cfg(feature = "servo")] diff --git a/components/style/servo_selector_impl.rs b/components/style/servo_selector_impl.rs index f54ef9f3870..70288c655f0 100644 --- a/components/style/servo_selector_impl.rs +++ b/components/style/servo_selector_impl.rs @@ -21,6 +21,7 @@ pub enum PseudoElement { Selection, DetailsSummary, DetailsContent, + ServoInputText, } impl ToCss for PseudoElement { @@ -32,6 +33,7 @@ impl ToCss for PseudoElement { Selection => "::selection", DetailsSummary => "::-servo-details-summary", DetailsContent => "::-servo-details-content", + ServoInputText => "::-servo-input-text", }) } } @@ -54,7 +56,8 @@ impl PseudoElement { PseudoElement::After | PseudoElement::Selection => PseudoElementCascadeType::Eager, PseudoElement::DetailsSummary => PseudoElementCascadeType::Lazy, - PseudoElement::DetailsContent => PseudoElementCascadeType::Precomputed, + PseudoElement::DetailsContent | + PseudoElement::ServoInputText => PseudoElementCascadeType::Precomputed, } } } @@ -201,6 +204,12 @@ impl SelectorImpl for ServoSelectorImpl { } DetailsContent }, + "-servo-input-text" => { + if !context.in_user_agent_stylesheet { + return Err(()) + } + ServoInputText + }, _ => return Err(()) }; @@ -222,6 +231,7 @@ impl ServoSelectorImpl { fun(PseudoElement::DetailsContent); fun(PseudoElement::DetailsSummary); fun(PseudoElement::Selection); + fun(PseudoElement::ServoInputText); } #[inline] diff --git a/resources/servo.css b/resources/servo.css index 858d59226c2..0c4bbeca12d 100644 --- a/resources/servo.css +++ b/resources/servo.css @@ -165,3 +165,7 @@ details[open]::-servo-details-summary { svg > * { display: none; } + +*|*::-servo-input-text { + margin: 0; +} diff --git a/tests/wpt/metadata-css/css-flexbox-1_dev/html/flex-vertical-align-effect.htm.ini b/tests/wpt/metadata-css/css-flexbox-1_dev/html/flex-vertical-align-effect.htm.ini deleted file mode 100644 index 0d1de654630..00000000000 --- a/tests/wpt/metadata-css/css-flexbox-1_dev/html/flex-vertical-align-effect.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[flex-vertical-align-effect.htm] - type: reftest - expected: FAIL