From 61fd5e79f738c3d0526d8fe2d93caca54fcf3d9c Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Wed, 25 May 2016 16:06:02 +1000 Subject: [PATCH 1/3] Make text-decoration-style initial value 'solid'. --- components/style/properties/longhand/text.mako.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/style/properties/longhand/text.mako.rs b/components/style/properties/longhand/text.mako.rs index e56cf93597c..cd8606ab2ad 100644 --- a/components/style/properties/longhand/text.mako.rs +++ b/components/style/properties/longhand/text.mako.rs @@ -105,7 +105,7 @@ ${helpers.single_keyword("unicode-bidi", "normal embed isolate bidi-override iso ${helpers.single_keyword("text-decoration-style", - "-moz-none solid double dotted dashed wavy", + "solid double dotted dashed wavy -moz-none", products="gecko")} ${helpers.predefined_type( From 53a9defa9f2823f17ab5ea6522ef05601a2452d7 Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Wed, 25 May 2016 20:23:51 +1000 Subject: [PATCH 2/3] Don't consume invalid idents when parsing text-decoration. --- .../style/properties/longhand/text.mako.rs | 32 ++++++++++++------- .../html4/c71-fwd-parsing-003.htm.ini | 3 -- 2 files changed, 20 insertions(+), 15 deletions(-) delete mode 100644 tests/wpt/metadata-css/css21_dev/html4/c71-fwd-parsing-003.htm.ini diff --git a/components/style/properties/longhand/text.mako.rs b/components/style/properties/longhand/text.mako.rs index cd8606ab2ad..26a29a49f39 100644 --- a/components/style/properties/longhand/text.mako.rs +++ b/components/style/properties/longhand/text.mako.rs @@ -75,19 +75,27 @@ ${helpers.single_keyword("unicode-bidi", "normal embed isolate bidi-override iso } let mut blink = false; let mut empty = true; - while let Ok(ident) = input.expect_ident() { - match_ignore_ascii_case! { ident, - "underline" => if result.underline { return Err(()) } - else { empty = false; result.underline = true }, - "overline" => if result.overline { return Err(()) } - else { empty = false; result.overline = true }, - "line-through" => if result.line_through { return Err(()) } - else { empty = false; result.line_through = true }, - "blink" => if blink { return Err(()) } - else { empty = false; blink = true }, - _ => break - } + + while input.try(|input| { + if let Ok(ident) = input.expect_ident() { + match_ignore_ascii_case! { ident, + "underline" => if result.underline { return Err(()) } + else { empty = false; result.underline = true }, + "overline" => if result.overline { return Err(()) } + else { empty = false; result.overline = true }, + "line-through" => if result.line_through { return Err(()) } + else { empty = false; result.line_through = true }, + "blink" => if blink { return Err(()) } + else { empty = false; blink = true }, + _ => return Err(()) + } + } else { + return Err(()); + } + Ok(()) + }).is_ok() { } + if !empty { Ok(result) } else { Err(()) } } diff --git a/tests/wpt/metadata-css/css21_dev/html4/c71-fwd-parsing-003.htm.ini b/tests/wpt/metadata-css/css21_dev/html4/c71-fwd-parsing-003.htm.ini deleted file mode 100644 index f8f06a021a1..00000000000 --- a/tests/wpt/metadata-css/css21_dev/html4/c71-fwd-parsing-003.htm.ini +++ /dev/null @@ -1,3 +0,0 @@ -[c71-fwd-parsing-003.htm] - type: reftest - expected: FAIL From 0580e1854e3f757b1dc7724be362a16b426b5d64 Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Wed, 25 May 2016 18:21:54 +1000 Subject: [PATCH 3/3] Support text-decoration-line and the text-decoration shorthand in geckolib. --- .../style/properties/longhand/text.mako.rs | 3 +- .../style/properties/properties.mako.rs | 10 ++-- .../style/properties/shorthand/text.mako.rs | 46 +++++++++++++++++++ ports/geckolib/properties.mako.rs | 24 ++++++++-- 4 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 components/style/properties/shorthand/text.mako.rs diff --git a/components/style/properties/longhand/text.mako.rs b/components/style/properties/longhand/text.mako.rs index 26a29a49f39..9bf491a4546 100644 --- a/components/style/properties/longhand/text.mako.rs +++ b/components/style/properties/longhand/text.mako.rs @@ -16,7 +16,8 @@ ${helpers.single_keyword("text-overflow", "clip ellipsis")} ${helpers.single_keyword("unicode-bidi", "normal embed isolate bidi-override isolate-override plaintext")} -<%helpers:longhand name="text-decoration" custom_cascade="${product == 'servo'}"> +<%helpers:longhand name="${'text-decoration' if product == 'servo' else 'text-decoration-line'}" + custom_cascade="${product == 'servo'}"> use cssparser::ToCss; use std::fmt; use values::computed::ComputedValueAsSpecified; diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index ec6fe6562e0..9a1b2546efa 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -130,6 +130,7 @@ pub mod shorthands { <%include file="/shorthand/margin.mako.rs" /> <%include file="/shorthand/outline.mako.rs" /> <%include file="/shorthand/padding.mako.rs" /> + <%include file="/shorthand/text.mako.rs" /> } @@ -815,14 +816,15 @@ pub mod style_structs { self.outline_width != ::app_units::Au(0) } % elif style_struct.trait_name == "Text": + <% text_decoration_field = 'text_decoration' if product == 'servo' else 'text_decoration_line' %> fn has_underline(&self) -> bool { - self.text_decoration.underline + self.${text_decoration_field}.underline } fn has_overline(&self) -> bool { - self.text_decoration.overline + self.${text_decoration_field}.overline } fn has_line_through(&self) -> bool { - self.text_decoration.line_through + self.${text_decoration_field}.line_through } % endif } @@ -1463,7 +1465,7 @@ pub fn cascade( PropertyDeclaration::Color(_) | PropertyDeclaration::Position(_) | PropertyDeclaration::Float(_) | - PropertyDeclaration::TextDecoration(_) + PropertyDeclaration::TextDecoration${'' if product == 'servo' else 'Line'}(_) ); if % if category_to_cascade_now == "early": diff --git a/components/style/properties/shorthand/text.mako.rs b/components/style/properties/shorthand/text.mako.rs new file mode 100644 index 00000000000..becdb111231 --- /dev/null +++ b/components/style/properties/shorthand/text.mako.rs @@ -0,0 +1,46 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +<%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"> + use cssparser::Color as CSSParserColor; + use properties::longhands::{text_decoration_color, text_decoration_line, text_decoration_style}; + use values::specified::CSSColor; + + let (mut color, mut line, mut style, mut any) = (None, None, None, false); + loop { + macro_rules! parse_component { + ($value:ident, $module:ident) => ( + if $value.is_none() { + if let Ok(value) = input.try(|input| $module::parse(context, input)) { + $value = Some(value); + any = true; + continue; + } + } + ) + } + + parse_component!(color, text_decoration_color); + parse_component!(line, text_decoration_line); + parse_component!(style, text_decoration_style); + break; + } + + if !any { + return Err(()); + } + + Ok(Longhands { + text_decoration_color: color.or(Some(CSSColor { parsed: CSSParserColor::CurrentColor, + authored: None })), + text_decoration_line: line.or(Some(text_decoration_line::computed_value::none)), + text_decoration_style: style.or(Some(text_decoration_style::computed_value::T::solid)), + }) + diff --git a/ports/geckolib/properties.mako.rs b/ports/geckolib/properties.mako.rs index 387f5e02edb..bff52878d70 100644 --- a/ports/geckolib/properties.mako.rs +++ b/ports/geckolib/properties.mako.rs @@ -727,20 +727,36 @@ fn static_assert() { <%self:impl_trait style_struct_name="Text" - skip_longhands="text-decoration-color" + skip_longhands="text-decoration-color text-decoration-line" skip_additionals="*"> <% impl_color("text_decoration_color", "mTextDecorationColor", color_flags_ffi_name="mTextDecorationStyle") %> + fn set_text_decoration_line(&mut self, v: longhands::text_decoration_line::computed_value::T) { + let mut bits: u8 = 0; + if v.underline { + bits |= structs::NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE as u8; + } + if v.overline { + bits |= structs::NS_STYLE_TEXT_DECORATION_LINE_OVERLINE as u8; + } + if v.line_through { + bits |= structs::NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH as u8; + } + self.gecko.mTextDecorationLine = bits; + } + + <%call expr="impl_simple_copy('text_decoration_line', 'mTextDecorationLine')"> + fn has_underline(&self) -> bool { - (self.gecko.mTextDecorationStyle & (structs::NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE as u8)) != 0 + (self.gecko.mTextDecorationLine & (structs::NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE as u8)) != 0 } fn has_overline(&self) -> bool { - (self.gecko.mTextDecorationStyle & (structs::NS_STYLE_TEXT_DECORATION_LINE_OVERLINE as u8)) != 0 + (self.gecko.mTextDecorationLine & (structs::NS_STYLE_TEXT_DECORATION_LINE_OVERLINE as u8)) != 0 } fn has_line_through(&self) -> bool { - (self.gecko.mTextDecorationStyle & (structs::NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH as u8)) != 0 + (self.gecko.mTextDecorationLine & (structs::NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH as u8)) != 0 }