Skip to content

Commit

Permalink
Style input-text pseudo with user-agent CSS
Browse files Browse the repository at this point in the history
  • Loading branch information
schuster committed Sep 21, 2016
1 parent 83f687a commit bf7df32
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
4 changes: 3 additions & 1 deletion components/layout/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 0 additions & 14 deletions components/style/properties/properties.mako.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2278,20 +2278,6 @@ pub fn modify_style_for_text(style: &mut Arc<ComputedValues>) {
}
}

/// 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<ComputedValues>) {
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")]
Expand Down
12 changes: 11 additions & 1 deletion components/style/servo_selector_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub enum PseudoElement {
Selection,
DetailsSummary,
DetailsContent,
ServoInputText,
}

impl ToCss for PseudoElement {
Expand All @@ -32,6 +33,7 @@ impl ToCss for PseudoElement {
Selection => "::selection",
DetailsSummary => "::-servo-details-summary",
DetailsContent => "::-servo-details-content",
ServoInputText => "::-servo-input-text",
})
}
}
Expand All @@ -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,
}
}
}
Expand Down Expand Up @@ -201,6 +204,12 @@ impl SelectorImpl for ServoSelectorImpl {
}
DetailsContent
},
"-servo-input-text" => {
if !context.in_user_agent_stylesheet {
return Err(())
}
ServoInputText
},
_ => return Err(())
};

Expand All @@ -222,6 +231,7 @@ impl ServoSelectorImpl {
fun(PseudoElement::DetailsContent);
fun(PseudoElement::DetailsSummary);
fun(PseudoElement::Selection);
fun(PseudoElement::ServoInputText);
}

#[inline]
Expand Down
4 changes: 4 additions & 0 deletions resources/servo.css
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,7 @@ details[open]::-servo-details-summary {
svg > * {
display: none;
}

*|*::-servo-input-text {
margin: 0;
}

0 comments on commit bf7df32

Please sign in to comment.