diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-03-08 21:39:30 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-08 21:39:30 -0800 |
commit | dc3b32c853d51973cea98c235e7a9ab0bd00366e (patch) | |
tree | 118114f13703d6dc59160103113f31b9f2794ee1 | |
parent | 5fe921f2ab81726dc34b0c427580f355d503f56e (diff) | |
parent | b4c50de31e466ff0c0b82b3f5523384617c8fdc8 (diff) | |
download | servo-dc3b32c853d51973cea98c235e7a9ab0bd00366e.tar.gz servo-dc3b32c853d51973cea98c235e7a9ab0bd00366e.zip |
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 -->
-rw-r--r-- | components/layout/fragment.rs | 12 | ||||
-rw-r--r-- | components/script/dom/webidls/CSSStyleDeclaration.webidl | 2 | ||||
-rw-r--r-- | components/style/properties/longhand/text.mako.rs | 5 | ||||
-rw-r--r-- | components/style/properties/properties.mako.rs | 9 | ||||
-rw-r--r-- | components/style/properties/shorthand/text.mako.rs | 58 | ||||
-rw-r--r-- | components/style/servo/restyle_damage.rs | 2 | ||||
-rw-r--r-- | tests/unit/style/properties/serialization.rs | 41 |
7 files changed, 97 insertions, 32 deletions
diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index b8d6e12d75d..1008c4f1a0b 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -41,7 +41,7 @@ use std::collections::LinkedList; use std::sync::{Arc, Mutex}; use style::arc_ptr_eq; use style::computed_values::{border_collapse, box_sizing, clear, color, display, mix_blend_mode}; -use style::computed_values::{overflow_wrap, overflow_x, position, text_decoration, transform}; +use style::computed_values::{overflow_wrap, overflow_x, position, text_decoration_line, transform}; use style::computed_values::{transform_style, vertical_align, white_space, word_break, z_index}; use style::computed_values::content::ContentItem; use style::logical_geometry::{Direction, LogicalMargin, LogicalRect, LogicalSize, WritingMode}; @@ -1419,15 +1419,15 @@ impl Fragment { self.style().get_color().color } - /// Returns the text decoration of this fragment, according to the style of the nearest ancestor + /// Returns the text decoration line of this fragment, according to the style of the nearest ancestor /// element. /// - /// NB: This may not be the actual text decoration, because of the override rules specified in + /// NB: This may not be the actual text decoration line, because of the override rules specified in /// CSS 2.1 § 16.3.1. Unfortunately, computing this properly doesn't really fit into Servo's /// model. Therefore, this is a best lower bound approximation, but the end result may actually /// have the various decoration flags turned on afterward. - pub fn text_decoration(&self) -> text_decoration::T { - self.style().get_text().text_decoration + pub fn text_decoration_line(&self) -> text_decoration_line::T { + self.style().get_text().text_decoration_line } /// Returns the inline-start offset from margin edge to content edge. @@ -2297,7 +2297,7 @@ impl Fragment { &SpecificFragmentInfo::UnscannedText(_)) => { // FIXME: Should probably use a whitelist of styles that can safely differ (#3165) if self.style().get_font() != other.style().get_font() || - self.text_decoration() != other.text_decoration() || + self.text_decoration_line() != other.text_decoration_line() || self.white_space() != other.white_space() || self.color() != other.color() { return false diff --git a/components/script/dom/webidls/CSSStyleDeclaration.webidl b/components/script/dom/webidls/CSSStyleDeclaration.webidl index c0d851b196d..498d4a634d4 100644 --- a/components/script/dom/webidls/CSSStyleDeclaration.webidl +++ b/components/script/dom/webidls/CSSStyleDeclaration.webidl @@ -257,6 +257,8 @@ partial interface CSSStyleDeclaration { [SetterThrows, TreatNullAs=EmptyString] attribute DOMString text-align; [SetterThrows, TreatNullAs=EmptyString] attribute DOMString textDecoration; [SetterThrows, TreatNullAs=EmptyString] attribute DOMString text-decoration; + [SetterThrows, TreatNullAs=EmptyString] attribute DOMString textDecorationLine; + [SetterThrows, TreatNullAs=EmptyString] attribute DOMString text-decoration-line; [SetterThrows, TreatNullAs=EmptyString] attribute DOMString textIndent; [SetterThrows, TreatNullAs=EmptyString] attribute DOMString text-indent; [SetterThrows, TreatNullAs=EmptyString] attribute DOMString textJustify; diff --git a/components/style/properties/longhand/text.mako.rs b/components/style/properties/longhand/text.mako.rs index 654eac072ae..f5769fa26be 100644 --- a/components/style/properties/longhand/text.mako.rs +++ b/components/style/properties/longhand/text.mako.rs @@ -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(()) } } diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index af4943e8d33..3e7398ab15f 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -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': diff --git a/components/style/properties/shorthand/text.mako.rs b/components/style/properties/shorthand/text.mako.rs index b9bc7013a2c..00860c91887 100644 --- a/components/style/properties/shorthand/text.mako.rs +++ b/components/style/properties/shorthand/text.mako.rs @@ -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(()) } } diff --git a/components/style/servo/restyle_damage.rs b/components/style/servo/restyle_damage.rs index 68da9238afd..aad16730126 100644 --- a/components/style/servo/restyle_damage.rs +++ b/components/style/servo/restyle_damage.rs @@ -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 && diff --git a/tests/unit/style/properties/serialization.rs b/tests/unit/style/properties/serialization.rs index f69e75ed571..d197a52b9cd 100644 --- a/tests/unit/style/properties/serialization.rs +++ b/tests/unit/style/properties/serialization.rs @@ -112,6 +112,47 @@ mod shorthand_serialization { } } + mod text { + use style::properties::longhands::text_decoration_line as TextDecorationLine; + use style::properties::longhands::text_decoration_style::SpecifiedValue as TextDecorationStyle; + use super::*; + + #[test] + fn text_decoration_should_show_all_properties_when_set() { + let mut properties = Vec::new(); + + let line = DeclaredValue::Value(TextDecorationLine::OVERLINE); + let style = DeclaredValue::Value(TextDecorationStyle::dotted); + let color = DeclaredValue::Value(CSSColor { + parsed: ComputedColor::RGBA(RGBA::new(128, 0, 128, 255)), + authored: None + }); + + properties.push(PropertyDeclaration::TextDecorationLine(line)); + properties.push(PropertyDeclaration::TextDecorationStyle(style)); + properties.push(PropertyDeclaration::TextDecorationColor(color)); + + let serialization = shorthand_properties_to_string(properties); + assert_eq!(serialization, "text-decoration: overline dotted rgb(128, 0, 128);"); + } + + #[test] + fn text_decoration_should_not_serialize_initial_style_value() { + let mut properties = Vec::new(); + + let line = DeclaredValue::Value(TextDecorationLine::UNDERLINE); + let style = DeclaredValue::Value(TextDecorationStyle::solid); + let color = DeclaredValue::Value(CSSColor::currentcolor()); + + properties.push(PropertyDeclaration::TextDecorationLine(line)); + properties.push(PropertyDeclaration::TextDecorationStyle(style)); + properties.push(PropertyDeclaration::TextDecorationColor(color)); + + let serialization = shorthand_properties_to_string(properties); + assert_eq!(serialization, "text-decoration: underline;"); + } + } + mod four_sides_shorthands { pub use super::*; |