servo: Merge #19279 - style: Move -moz-force-broken-image-icon out of mako (from canaltinova:force-broken-image); r=emilio
authorNazım Can Altınova <canaltinova@gmail.com>
Sun, 19 Nov 2017 14:07:35 -0600
changeset 437163 da2dd46b2c2e6e37f3d41b2e731db8a04b87f84f
parent 437162 2e36423069468756547b41e0bf7550c2d7493fdf
child 437164 e1362d76d75600d1b36e839770821da74a857bac
push id117
push userfmarier@mozilla.com
push dateTue, 28 Nov 2017 20:17:16 +0000
reviewersemilio
milestone59.0a1
servo: Merge #19279 - style: Move -moz-force-broken-image-icon out of mako (from canaltinova:force-broken-image); r=emilio <!-- Please describe your changes on the following line: --> --- <!-- 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 - [X] These changes fix part of #19015. <!-- Either: --> - [X] These changes do not require tests because these are just refactoring. Source-Repo: https://github.com/servo/servo Source-Revision: 6361aed46d5246037d636669dc64664971e94279
servo/components/style/properties/longhand/ui.mako.rs
servo/components/style/values/computed/mod.rs
servo/components/style/values/computed/ui.rs
servo/components/style/values/specified/mod.rs
servo/components/style/values/specified/ui.rs
--- a/servo/components/style/properties/longhand/ui.mako.rs
+++ b/servo/components/style/properties/longhand/ui.mako.rs
@@ -58,62 +58,14 @@
                           "computed::TransformOrigin::initial_value()",
                           animation_value_type="ComputedValue",
                           gecko_ffi_name="mWindowTransformOrigin",
                           products="gecko",
                           boxed=True,
                           enabled_in="ua",
                           spec="None (Nonstandard internal property)")}
 
-<%helpers:longhand name="-moz-force-broken-image-icon"
-                   products="gecko"
-                   animation_value_type="discrete"
-                   spec="None (Nonstandard Firefox-only property)">
-    use std::fmt;
-    use style_traits::ToCss;
-
-    pub mod computed_value {
-        #[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
-        pub struct T(pub bool);
-    }
-
-    pub use self::computed_value::T as SpecifiedValue;
-
-    impl ToCss for computed_value::T {
-        fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
-            dest.write_str(if self.0 { "1" } else { "0" })
-        }
-    }
-
-    #[inline]
-    pub fn get_initial_value() -> computed_value::T {
-        computed_value::T(false)
-    }
-
-    #[inline]
-    pub fn get_initial_specified_value() -> SpecifiedValue {
-        computed_value::T(false)
-    }
-
-    pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
-                         -> Result<SpecifiedValue, ParseError<'i>> {
-        match input.expect_integer()? {
-            0 => Ok(computed_value::T(false)),
-            1 => Ok(computed_value::T(true)),
-            _ => Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)),
-        }
-    }
-
-    impl From<u8> for SpecifiedValue {
-        fn from(bits: u8) -> SpecifiedValue {
-            SpecifiedValue(bits == 1)
-        }
-    }
-
-    impl From<SpecifiedValue> for u8 {
-        fn from(v: SpecifiedValue) -> u8 {
-            match v.0 {
-                true => 1u8,
-                false => 0u8,
-            }
-        }
-    }
-</%helpers:longhand>
+${helpers.predefined_type("-moz-force-broken-image-icon",
+                          "MozForceBrokenImageIcon",
+                          "computed::MozForceBrokenImageIcon::false_value()",
+                          animation_value_type="discrete",
+                          products="gecko",
+                          spec="None (Nonstandard Firefox-only property)")}
--- a/servo/components/style/values/computed/mod.rs
+++ b/servo/components/style/values/computed/mod.rs
@@ -54,16 +54,17 @@ pub use self::length::{LengthOrPercentag
 pub use self::length::{CSSPixelLength, NonNegativeLength, NonNegativeLengthOrPercentage};
 pub use self::percentage::Percentage;
 pub use self::position::Position;
 pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind, SVGStrokeDashArray, SVGWidth};
 pub use self::table::XSpan;
 pub use self::text::{InitialLetter, LetterSpacing, LineHeight, TextOverflow, WordSpacing};
 pub use self::time::Time;
 pub use self::transform::{TimingFunction, Transform, TransformOperation, TransformOrigin};
+pub use self::ui::MozForceBrokenImageIcon;
 
 #[cfg(feature = "gecko")]
 pub mod align;
 pub mod angle;
 pub mod background;
 pub mod basic_shape;
 pub mod border;
 #[path = "box.rs"]
@@ -79,16 +80,17 @@ pub mod length;
 pub mod percentage;
 pub mod position;
 pub mod rect;
 pub mod svg;
 pub mod table;
 pub mod text;
 pub mod time;
 pub mod transform;
+pub mod ui;
 
 /// A `Context` is all the data a specified value could ever need to compute
 /// itself and be transformed to a computed value.
 pub struct Context<'a> {
     /// Whether the current element is the root element.
     pub is_root_element: bool,
 
     /// Values accessed through this need to be in the properties "computed
new file mode 100644
--- /dev/null
+++ b/servo/components/style/values/computed/ui.rs
@@ -0,0 +1,7 @@
+/* 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/. */
+
+//! Computed values for UI properties
+
+pub use values::specified::ui::MozForceBrokenImageIcon;
--- a/servo/components/style/values/specified/mod.rs
+++ b/servo/components/style/values/specified/mod.rs
@@ -50,16 +50,17 @@ pub use self::length::NonNegativeLengthO
 pub use self::rect::LengthOrNumberRect;
 pub use self::percentage::Percentage;
 pub use self::position::{Position, PositionComponent};
 pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind, SVGStrokeDashArray, SVGWidth};
 pub use self::table::XSpan;
 pub use self::text::{InitialLetter, LetterSpacing, LineHeight, TextDecorationLine, TextOverflow, WordSpacing};
 pub use self::time::Time;
 pub use self::transform::{TimingFunction, Transform, TransformOrigin};
+pub use self::ui::MozForceBrokenImageIcon;
 pub use super::generics::grid::GridTemplateComponent as GenericGridTemplateComponent;
 
 #[cfg(feature = "gecko")]
 pub mod align;
 pub mod angle;
 pub mod background;
 pub mod basic_shape;
 pub mod border;
@@ -79,16 +80,17 @@ pub mod percentage;
 pub mod position;
 pub mod rect;
 pub mod source_size_list;
 pub mod svg;
 pub mod table;
 pub mod text;
 pub mod time;
 pub mod transform;
+pub mod ui;
 
 /// Common handling for the specified value CSS url() values.
 pub mod url {
 use cssparser::Parser;
 use parser::{Parse, ParserContext};
 use style_traits::ParseError;
 
 #[cfg(feature = "servo")]
new file mode 100644
--- /dev/null
+++ b/servo/components/style/values/specified/ui.rs
@@ -0,0 +1,54 @@
+/* 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/. */
+
+//! Specified types for UI properties.
+
+use cssparser::Parser;
+use parser::{Parse, ParserContext};
+use std::fmt;
+use style_traits::{ParseError, StyleParseErrorKind, ToCss};
+
+/// Specified value of `-moz-force-broken-image-icon`
+#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
+pub struct MozForceBrokenImageIcon(pub bool);
+
+impl MozForceBrokenImageIcon {
+    /// Return initial value of -moz-force-broken-image-icon which is false.
+    #[inline]
+    pub fn false_value() -> MozForceBrokenImageIcon {
+        MozForceBrokenImageIcon(false)
+    }
+}
+
+impl Parse for MozForceBrokenImageIcon {
+    fn parse<'i, 't>(
+        _context: &ParserContext,
+        input: &mut Parser<'i, 't>
+    ) -> Result<MozForceBrokenImageIcon, ParseError<'i>> {
+        // We intentionally don't support calc values here.
+        match input.expect_integer()? {
+            0 => Ok(MozForceBrokenImageIcon(false)),
+            1 => Ok(MozForceBrokenImageIcon(true)),
+            _ => Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)),
+        }
+    }
+}
+
+impl ToCss for MozForceBrokenImageIcon {
+    fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
+        dest.write_str(if self.0 { "1" } else { "0" })
+    }
+}
+
+impl From<u8> for MozForceBrokenImageIcon {
+    fn from(bits: u8) -> MozForceBrokenImageIcon {
+        MozForceBrokenImageIcon(bits == 1)
+    }
+}
+
+impl From<MozForceBrokenImageIcon> for u8 {
+    fn from(v: MozForceBrokenImageIcon) -> u8 {
+        if v.0 { 1 } else { 0 }
+    }
+}