Auto merge of #15861 - projektir:make-text-decoration-testable, r=Wafflespeanut

Make text decoration testable and do not serialize initial text-decoration-style

Servo now uses the same name for the text-decoration-line longhand property as Gecko. This was done to enable testing of the text-decoration shorthand.

The text-decoration shorthand has been fixed to not serialize initial text-decoration-style.

---

- [x ] `./mach build -d` does not report any errors
- [x ] `./mach test-tidy` does not report any errors
- [x ] These changes fix #15790

---

- [x ] There are tests for these changes

<!-- 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/15861)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-03-08 21:39:30 -08:00 committed by GitHub
commit dc3b32c853
7 changed files with 97 additions and 32 deletions

View file

@ -101,10 +101,9 @@ ${helpers.single_keyword("unicode-bidi",
spec="https://drafts.csswg.org/css-writing-modes/#propdef-unicode-bidi")}
// FIXME: This prop should be animatable.
<%helpers:longhand name="${'text-decoration' if product == 'servo' else 'text-decoration-line'}"
<%helpers:longhand name="text-decoration-line"
custom_cascade="${product == 'servo'}"
animatable="False"
disable_when_testing="True",
spec="https://drafts.csswg.org/css-text-decor/#propdef-text-decoration-line">
use std::fmt;
use style_traits::ToCss;
@ -138,6 +137,7 @@ ${helpers.single_keyword("unicode-bidi",
impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
let mut has_any = false;
macro_rules! write_value {
($line:ident => $css:expr) => {
if self.contains($line) {
@ -156,6 +156,7 @@ ${helpers.single_keyword("unicode-bidi",
if !has_any {
dest.write_str("none")?;
}
Ok(())
}
}

View file

@ -1306,23 +1306,22 @@ pub mod style_structs {
self.outline_width != ::app_units::Au(0)
}
% elif style_struct.name == "Text":
<% text_decoration_field = 'text_decoration' if product == 'servo' else 'text_decoration_line' %>
/// Whether the text decoration has an underline.
#[inline]
pub fn has_underline(&self) -> bool {
self.${text_decoration_field}.contains(longhands::${text_decoration_field}::UNDERLINE)
self.text_decoration_line.contains(longhands::text_decoration_line::UNDERLINE)
}
/// Whether the text decoration has an overline.
#[inline]
pub fn has_overline(&self) -> bool {
self.${text_decoration_field}.contains(longhands::${text_decoration_field}::OVERLINE)
self.text_decoration_line.contains(longhands::text_decoration_line::OVERLINE)
}
/// Whether the text decoration has a line through.
#[inline]
pub fn has_line_through(&self) -> bool {
self.${text_decoration_field}.contains(longhands::${text_decoration_field}::LINE_THROUGH)
self.text_decoration_line.contains(longhands::text_decoration_line::LINE_THROUGH)
}
% endif
}
@ -1953,7 +1952,7 @@ pub fn apply_declarations<'a, F, I>(viewport_size: Size2D<Au>,
PropertyDeclaration::Color(_) |
PropertyDeclaration::Position(_) |
PropertyDeclaration::Float(_) |
PropertyDeclaration::TextDecoration${'' if product == 'servo' else 'Line'}(_) |
PropertyDeclaration::TextDecorationLine(_) |
PropertyDeclaration::WritingMode(_) |
PropertyDeclaration::Direction(_)
% if product == 'gecko':

View file

@ -5,17 +5,25 @@
<%namespace name="helpers" file="/helpers.mako.rs" />
<%helpers:shorthand name="text-decoration"
sub_properties="text-decoration-color
text-decoration-line
text-decoration-style"
products="gecko"
disable_when_testing="True"
sub_properties="text-decoration-line
${' text-decoration-style text-decoration-color' if product == 'gecko' or data.testing else ''}"
spec="https://drafts.csswg.org/css-text-decor/#propdef-text-decoration">
use cssparser::Color as CSSParserColor;
use properties::longhands::{text_decoration_color, text_decoration_line, text_decoration_style};
% if product == "gecko" or data.testing:
use cssparser::Color as CSSParserColor;
use properties::longhands::{text_decoration_line, text_decoration_style, text_decoration_color};
% else:
use properties::longhands::text_decoration_line;
% endif
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
let (mut color, mut line, mut style, mut any) = (None, None, None, false);
% if product == "gecko" or data.testing:
let (mut line, mut style, mut color, mut any) = (None, None, None, false);
% else:
let (mut line, mut any) = (None, false);
% endif
loop {
macro_rules! parse_component {
($value:ident, $module:ident) => (
@ -29,9 +37,13 @@
)
}
parse_component!(color, text_decoration_color);
parse_component!(line, text_decoration_line);
parse_component!(style, text_decoration_style);
% if product == "gecko" or data.testing:
parse_component!(style, text_decoration_style);
parse_component!(color, text_decoration_color);
% endif
break;
}
@ -40,21 +52,31 @@
}
Ok(Longhands {
text_decoration_color: unwrap_or_initial!(text_decoration_color, color),
text_decoration_line: unwrap_or_initial!(text_decoration_line, line),
text_decoration_style: unwrap_or_initial!(text_decoration_style, style),
% if product == "gecko" or data.testing:
text_decoration_style: unwrap_or_initial!(text_decoration_style, style),
text_decoration_color: unwrap_or_initial!(text_decoration_color, color),
% endif
})
}
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
self.text_decoration_line.to_css(dest)?;
dest.write_str(" ")?;
self.text_decoration_style.to_css(dest)?;
if self.text_decoration_color.parsed != CSSParserColor::CurrentColor {
dest.write_str(" ")?;
self.text_decoration_color.to_css(dest)?;
}
% if product == "gecko" or data.testing:
if self.text_decoration_style != &text_decoration_style::SpecifiedValue::solid {
dest.write_str(" ")?;
self.text_decoration_style.to_css(dest)?;
}
if self.text_decoration_color.parsed != CSSParserColor::CurrentColor {
dest.write_str(" ")?;
self.text_decoration_color.to_css(dest)?;
}
% endif
Ok(())
}
}

View file

@ -204,7 +204,7 @@ fn compute_damage(old: &ServoComputedValues, new: &ServoComputedValues) -> Servo
get_font.font_family, get_font.font_style, get_font.font_variant, get_font.font_weight,
get_font.font_size, get_font.font_stretch,
get_inheritedbox.direction, get_inheritedbox.writing_mode,
get_text.text_decoration, get_text.unicode_bidi,
get_text.text_decoration_line, get_text.unicode_bidi,
get_inheritedtable.empty_cells, get_inheritedtable.caption_side,
get_column.column_width, get_column.column_count
]) || (new.get_box().display == display::T::inline &&