Auto merge of #13354 - schuster:input-text-style, r=pcwalton

Style input-text pseudo with user-agent CSS

This changes the input-text pseudo-element to be styled with user-agent CSS rather than having a hard-coded style, as part of #8570

---
<!-- 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
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because they're a refactoring of existing functionality

<!-- 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/13354)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-09-23 21:08:19 -05:00 committed by GitHub
commit 28ebab4398
5 changed files with 18 additions and 19 deletions

View file

@ -48,6 +48,7 @@ use style::computed_values::content::ContentItem;
use style::computed_values::position; use style::computed_values::position;
use style::context::SharedStyleContext; use style::context::SharedStyleContext;
use style::properties::{self, ServoComputedValues}; use style::properties::{self, ServoComputedValues};
use style::servo_selector_impl::PseudoElement;
use table::TableFlow; use table::TableFlow;
use table_caption::TableCaptionFlow; use table_caption::TableCaptionFlow;
use table_cell::TableCellFlow; use table_cell::TableCellFlow;
@ -693,7 +694,8 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
let mut style = node.style(self.style_context()).clone(); let mut style = node.style(self.style_context()).clone();
if node_is_input_or_text_area { 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) self.create_fragments_for_node_text_content(&mut initial_fragments, node, &style)

View file

@ -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 /// Adjusts the `clip` property so that an inline absolute hypothetical fragment doesn't clip its
/// children. /// children.
#[cfg(feature = "servo")] #[cfg(feature = "servo")]

View file

@ -21,6 +21,7 @@ pub enum PseudoElement {
Selection, Selection,
DetailsSummary, DetailsSummary,
DetailsContent, DetailsContent,
ServoInputText,
} }
impl ToCss for PseudoElement { impl ToCss for PseudoElement {
@ -32,6 +33,7 @@ impl ToCss for PseudoElement {
Selection => "::selection", Selection => "::selection",
DetailsSummary => "::-servo-details-summary", DetailsSummary => "::-servo-details-summary",
DetailsContent => "::-servo-details-content", DetailsContent => "::-servo-details-content",
ServoInputText => "::-servo-input-text",
}) })
} }
} }
@ -54,7 +56,8 @@ impl PseudoElement {
PseudoElement::After | PseudoElement::After |
PseudoElement::Selection => PseudoElementCascadeType::Eager, PseudoElement::Selection => PseudoElementCascadeType::Eager,
PseudoElement::DetailsSummary => PseudoElementCascadeType::Lazy, PseudoElement::DetailsSummary => PseudoElementCascadeType::Lazy,
PseudoElement::DetailsContent => PseudoElementCascadeType::Precomputed, PseudoElement::DetailsContent |
PseudoElement::ServoInputText => PseudoElementCascadeType::Precomputed,
} }
} }
} }
@ -201,6 +204,12 @@ impl SelectorImpl for ServoSelectorImpl {
} }
DetailsContent DetailsContent
}, },
"-servo-input-text" => {
if !context.in_user_agent_stylesheet {
return Err(())
}
ServoInputText
},
_ => return Err(()) _ => return Err(())
}; };
@ -222,6 +231,7 @@ impl ServoSelectorImpl {
fun(PseudoElement::DetailsContent); fun(PseudoElement::DetailsContent);
fun(PseudoElement::DetailsSummary); fun(PseudoElement::DetailsSummary);
fun(PseudoElement::Selection); fun(PseudoElement::Selection);
fun(PseudoElement::ServoInputText);
} }
#[inline] #[inline]

View file

@ -165,3 +165,7 @@ details[open]::-servo-details-summary {
svg > * { svg > * {
display: none; display: none;
} }
*|*::-servo-input-text {
margin: 0;
}

View file

@ -1,3 +0,0 @@
[flex-vertical-align-effect.htm]
type: reftest
expected: FAIL