From 0f2dc53b0ab58af135aa21d8eefed1f71cd4b60d Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Sun, 1 May 2016 17:33:43 +1000 Subject: [PATCH] Factor out opacity property to use an Opacity type. --- .../style/properties/longhand/effects.mako.rs | 43 ++----------------- components/style/values.rs | 31 +++++++++++++ ports/geckolib/properties.mako.rs | 2 +- 3 files changed, 35 insertions(+), 41 deletions(-) diff --git a/components/style/properties/longhand/effects.mako.rs b/components/style/properties/longhand/effects.mako.rs index 0852ef5dd4e..a927e487a6a 100644 --- a/components/style/properties/longhand/effects.mako.rs +++ b/components/style/properties/longhand/effects.mako.rs @@ -7,46 +7,9 @@ // Box-shadow, etc. <% data.new_style_struct("Effects", inherited=False) %> -<%helpers:longhand name="opacity"> - use cssparser::ToCss; - use std::fmt; - use values::CSSFloat; - - impl ToCss for SpecifiedValue { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - self.0.to_css(dest) - } - } - - #[derive(Debug, Clone, PartialEq, HeapSizeOf)] - pub struct SpecifiedValue(pub CSSFloat); - pub mod computed_value { - use values::CSSFloat; - pub type T = CSSFloat; - } - #[inline] - pub fn get_initial_value() -> computed_value::T { - 1.0 - } - - impl ToComputedValue for SpecifiedValue { - type ComputedValue = computed_value::T; - - #[inline] - fn to_computed_value(&self, _context: &Cx) -> computed_value::T { - if self.0 < 0.0 { - 0.0 - } else if self.0 > 1.0 { - 1.0 - } else { - self.0 - } - } - } - fn parse(_context: &ParserContext, input: &mut Parser) -> Result { - specified::parse_number(input).map(SpecifiedValue) - } - +${helpers.predefined_type("opacity", + "Opacity", + "1.0")} <%helpers:longhand name="box-shadow"> use cssparser::{self, ToCss}; diff --git a/components/style/values.rs b/components/style/values.rs index 23c933bc394..9b33b18fee7 100644 --- a/components/style/values.rs +++ b/components/style/values.rs @@ -1475,6 +1475,36 @@ pub mod specified { write!(dest, "{}s", self.0) } } + + #[derive(Clone, Copy, Debug, PartialEq, PartialOrd, HeapSizeOf)] + pub struct Opacity(pub CSSFloat); + + impl Opacity { + pub fn parse(input: &mut Parser) -> Result { + parse_number(input).map(Opacity) + } + } + + impl ToComputedValue for Opacity { + type ComputedValue = CSSFloat; + + #[inline] + fn to_computed_value(&self, _: &Cx) -> CSSFloat { + if self.0 < 0.0 { + 0.0 + } else if self.0 > 1.0 { + 1.0 + } else { + self.0 + } + } + } + + impl ToCss for Opacity { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + self.0.to_css(dest) + } + } } pub mod computed { @@ -2087,4 +2117,5 @@ pub mod computed { } } pub type Length = Au; + pub type Opacity = CSSFloat; } diff --git a/ports/geckolib/properties.mako.rs b/ports/geckolib/properties.mako.rs index ad2d3648176..839e072ee2c 100644 --- a/ports/geckolib/properties.mako.rs +++ b/ports/geckolib/properties.mako.rs @@ -295,7 +295,7 @@ impl Debug for ${style_struct.gecko_ffi_name} { # These are booleans. force_stub += ["page-break-after", "page-break-before"] - simple_types = [] + simple_types = ["Opacity"] keyword_longhands = [x for x in longhands if x.keyword and not x.name in force_stub] simple_longhands = [x for x in longhands