From 16e318d055e7820094a8584de86b27294dc2d697 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Wed, 8 Mar 2017 10:17:44 -0800 Subject: [PATCH] Add support for non-standard -moz color keyword values. Closes #15928 --- components/style/animation.rs | 2 +- components/style/gecko/media_queries.rs | 6 +- components/style/matching.rs | 2 +- .../style/properties/longhand/color.mako.rs | 10 +-- .../longhand/inherited_text.mako.rs | 2 +- .../style/properties/longhand/outline.mako.rs | 2 +- .../style/properties/longhand/text.mako.rs | 2 +- .../style/properties/properties.mako.rs | 12 +-- .../properties/shorthand/serialize.mako.rs | 3 +- .../style/properties/shorthand/text.mako.rs | 5 +- components/style/servo/media_queries.rs | 10 +-- components/style/stylist.rs | 4 +- components/style/values/computed/image.rs | 2 +- components/style/values/computed/length.rs | 1 - components/style/values/computed/mod.rs | 56 +++++++++++- components/style/values/specified/color.rs | 90 +++++++++++++++++++ components/style/values/specified/mod.rs | 18 ++-- components/style/viewport.rs | 2 +- ports/geckolib/glue.rs | 8 +- tests/unit/style/parsing/image.rs | 9 +- 20 files changed, 188 insertions(+), 58 deletions(-) create mode 100644 components/style/values/specified/color.rs diff --git a/components/style/animation.rs b/components/style/animation.rs index 048c1bfa521..aa167efe3e5 100644 --- a/components/style/animation.rs +++ b/components/style/animation.rs @@ -426,7 +426,7 @@ fn compute_style_for_animation_step(context: &SharedStyleContext, }; let computed = - properties::apply_declarations(context.viewport_size(), + properties::apply_declarations(&context.stylist.device, /* is_root = */ false, iter, previous_style, diff --git a/components/style/gecko/media_queries.rs b/components/style/gecko/media_queries.rs index 47c904cbe0e..0b52da21668 100644 --- a/components/style/gecko/media_queries.rs +++ b/components/style/gecko/media_queries.rs @@ -29,7 +29,7 @@ pub struct Device { /// NB: The pres context lifetime is tied to the styleset, who owns the /// stylist, and thus the `Device`, so having a raw pres context pointer /// here is fine. - pres_context: RawGeckoPresContextOwned, + pub pres_context: RawGeckoPresContextOwned, default_values: Arc, viewport_override: Option, } @@ -497,13 +497,13 @@ impl Expression { // em units are relative to the initial font-size. let context = computed::Context { is_root_element: false, - viewport_size: device.au_viewport_size(), + device: device, inherited_style: default_values, layout_parent_style: default_values, // This cloning business is kind of dumb.... It's because Context // insists on having an actual ComputedValues inside itself. style: default_values.clone(), - font_metrics_provider: None + font_metrics_provider: None, }; let required_value = match self.value { diff --git a/components/style/matching.rs b/components/style/matching.rs index 2fbf2760ce8..ceb021227b6 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -539,7 +539,7 @@ trait PrivateMatchMethods: TElement { // Invoke the cascade algorithm. let values = - Arc::new(cascade(shared_context.viewport_size(), + Arc::new(cascade(&shared_context.stylist.device, rule_node, inherited_values, layout_parent_style, diff --git a/components/style/properties/longhand/color.mako.rs b/components/style/properties/longhand/color.mako.rs index 136546e2e70..9fbdaac287a 100644 --- a/components/style/properties/longhand/color.mako.rs +++ b/components/style/properties/longhand/color.mako.rs @@ -8,28 +8,24 @@ <%helpers:longhand name="color" need_clone="True" animatable="True" spec="https://drafts.csswg.org/css-color/#color"> - use cssparser::Color as CSSParserColor; use cssparser::RGBA; use std::fmt; use style_traits::ToCss; use values::HasViewportPercentage; - use values::specified::{CSSColor, CSSRGBA}; + use values::specified::{Color, CSSColor, CSSRGBA}; impl ToComputedValue for SpecifiedValue { type ComputedValue = computed_value::T; #[inline] fn to_computed_value(&self, context: &Context) -> computed_value::T { - match self.0.parsed { - CSSParserColor::RGBA(rgba) => rgba, - CSSParserColor::CurrentColor => context.inherited_style.get_color().clone_color(), - } + self.0.parsed.to_computed_value(context) } #[inline] fn from_computed_value(computed: &computed_value::T) -> Self { SpecifiedValue(CSSColor { - parsed: CSSParserColor::RGBA(*computed), + parsed: Color::RGBA(*computed), authored: None, }) } diff --git a/components/style/properties/longhand/inherited_text.mako.rs b/components/style/properties/longhand/inherited_text.mako.rs index 516ff2855ad..145b0e61ab7 100644 --- a/components/style/properties/longhand/inherited_text.mako.rs +++ b/components/style/properties/longhand/inherited_text.mako.rs @@ -792,7 +792,7 @@ ${helpers.single_keyword("text-align-last", blur_radius: value.blur_radius.to_computed_value(context), color: value.color .as_ref() - .map(|color| color.parsed) + .map(|color| color.to_computed_value(context)) .unwrap_or(cssparser::Color::CurrentColor), } }).collect()) diff --git a/components/style/properties/longhand/outline.mako.rs b/components/style/properties/longhand/outline.mako.rs index 65be748c187..a599c436174 100644 --- a/components/style/properties/longhand/outline.mako.rs +++ b/components/style/properties/longhand/outline.mako.rs @@ -10,7 +10,7 @@ additional_methods=[Method("outline_has_nonzero_width", "bool")]) %> // TODO(pcwalton): `invert` -${helpers.predefined_type("outline-color", "CSSColor", "::cssparser::Color::CurrentColor", +${helpers.predefined_type("outline-color", "CSSColor", "computed::CSSColor::CurrentColor", initial_specified_value="specified::CSSColor::currentcolor()", animatable=True, complex_color=True, need_clone=True, spec="https://drafts.csswg.org/css-ui/#propdef-outline-color")} diff --git a/components/style/properties/longhand/text.mako.rs b/components/style/properties/longhand/text.mako.rs index f5769fa26be..8fed3b7acab 100644 --- a/components/style/properties/longhand/text.mako.rs +++ b/components/style/properties/longhand/text.mako.rs @@ -224,7 +224,7 @@ ${helpers.single_keyword("text-decoration-style", ${helpers.predefined_type( "text-decoration-color", "CSSColor", - "::cssparser::Color::CurrentColor", + "computed::CSSColor::CurrentColor", initial_specified_value="specified::CSSColor::currentcolor()", complex_color=True, products="gecko", diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 656b2b9294c..eb4628ce8be 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -21,13 +21,13 @@ use app_units::Au; use cssparser::{Parser, TokenSerializationType}; use error_reporting::ParseErrorReporter; #[cfg(feature = "servo")] use euclid::side_offsets::SideOffsets2D; -use euclid::size::Size2D; use computed_values; use font_metrics::FontMetricsProvider; #[cfg(feature = "gecko")] use gecko_bindings::bindings; #[cfg(feature = "gecko")] use gecko_bindings::structs::{self, nsCSSPropertyID}; #[cfg(feature = "servo")] use logical_geometry::{LogicalMargin, PhysicalSide}; use logical_geometry::WritingMode; +use media_queries::Device; use parser::{Parse, ParserContext, ParserContextExtraData}; use properties::animated_properties::TransitionProperty; #[cfg(feature = "servo")] use servo_config::prefs::PREFS; @@ -1793,7 +1793,7 @@ bitflags! { /// /// The arguments are: /// -/// * `viewport_size`: The size of the initial viewport. +/// * `device`: Used to get the initial viewport and other external state. /// /// * `rule_node`: The rule node in the tree that represent the CSS rules that /// matched. @@ -1803,7 +1803,7 @@ bitflags! { /// Returns the computed values. /// * `flags`: Various flags. /// -pub fn cascade(viewport_size: Size2D, +pub fn cascade(device: &Device, rule_node: &StrongRuleNode, parent_style: Option<<&ComputedValues>, layout_parent_style: Option<<&ComputedValues>, @@ -1836,7 +1836,7 @@ pub fn cascade(viewport_size: Size2D, }) }) }; - apply_declarations(viewport_size, + apply_declarations(device, is_root_element, iter_declarations, inherited_style, @@ -1850,7 +1850,7 @@ pub fn cascade(viewport_size: Size2D, /// NOTE: This function expects the declaration with more priority to appear /// first. -pub fn apply_declarations<'a, F, I>(viewport_size: Size2D, +pub fn apply_declarations<'a, F, I>(device: &Device, is_root_element: bool, iter_declarations: F, inherited_style: &ComputedValues, @@ -1905,7 +1905,7 @@ pub fn apply_declarations<'a, F, I>(viewport_size: Size2D, let mut context = computed::Context { is_root_element: is_root_element, - viewport_size: viewport_size, + device: device, inherited_style: inherited_style, layout_parent_style: layout_parent_style, style: starting_style, diff --git a/components/style/properties/shorthand/serialize.mako.rs b/components/style/properties/shorthand/serialize.mako.rs index 5c265f16c9e..f990ca81df3 100644 --- a/components/style/properties/shorthand/serialize.mako.rs +++ b/components/style/properties/shorthand/serialize.mako.rs @@ -2,9 +2,8 @@ * 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/. */ -use cssparser::Color; use style_traits::ToCss; -use values::specified::{BorderStyle, CSSColor}; +use values::specified::{BorderStyle, Color, CSSColor}; use std::fmt; #[allow(missing_docs)] diff --git a/components/style/properties/shorthand/text.mako.rs b/components/style/properties/shorthand/text.mako.rs index 00860c91887..c035158a511 100644 --- a/components/style/properties/shorthand/text.mako.rs +++ b/components/style/properties/shorthand/text.mako.rs @@ -10,13 +10,12 @@ spec="https://drafts.csswg.org/css-text-decor/#propdef-text-decoration"> % if product == "gecko" or data.testing: - use cssparser::Color as CSSParserColor; + use values::specified; 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 { % if product == "gecko" or data.testing: let (mut line, mut style, mut color, mut any) = (None, None, None, false); @@ -71,7 +70,7 @@ self.text_decoration_style.to_css(dest)?; } - if self.text_decoration_color.parsed != CSSParserColor::CurrentColor { + if self.text_decoration_color.parsed != specified::Color::CurrentColor { dest.write_str(" ")?; self.text_decoration_color.to_css(dest)?; } diff --git a/components/style/servo/media_queries.rs b/components/style/servo/media_queries.rs index 99b30494483..ffea9e5e1bc 100644 --- a/components/style/servo/media_queries.rs +++ b/components/style/servo/media_queries.rs @@ -128,7 +128,7 @@ impl Expression { let value = viewport_size.width; match self.0 { ExpressionKind::Width(ref range) => { - match range.to_computed_range(viewport_size, device.default_values()) { + match range.to_computed_range(device) { Range::Min(ref width) => { value >= *width }, Range::Max(ref width) => { value <= *width }, Range::Eq(ref width) => { value == *width }, @@ -170,15 +170,13 @@ pub enum Range { } impl Range { - fn to_computed_range(&self, - viewport_size: Size2D, - default_values: &ComputedValues) - -> Range { + fn to_computed_range(&self, device: &Device) -> Range { + let default_values = device.default_values(); // http://dev.w3.org/csswg/mediaqueries3/#units // em units are relative to the initial font-size. let context = computed::Context { is_root_element: false, - viewport_size: viewport_size, + device: device, inherited_style: default_values, layout_parent_style: default_values, // This cloning business is kind of dumb.... It's because Context diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 61b9826f8d0..069c8f21a26 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -325,7 +325,7 @@ impl Stylist { // the actual used value, and the computed value of it would need // blockification. let computed = - properties::cascade(self.device.au_viewport_size(), + properties::cascade(&self.device, &rule_node, parent.map(|p| &**p), parent.map(|p| &**p), @@ -410,7 +410,7 @@ impl Stylist { // (tl;dr: It doesn't apply for replaced elements and such, but the // computed value is still "contents"). let computed = - properties::cascade(self.device.au_viewport_size(), + properties::cascade(&self.device, &rule_node, Some(&**parent), Some(&**parent), diff --git a/components/style/values/computed/image.rs b/components/style/values/computed/image.rs index 9eb0bbc7f14..8441ab62c05 100644 --- a/components/style/values/computed/image.rs +++ b/components/style/values/computed/image.rs @@ -250,7 +250,7 @@ impl ToComputedValue for specified::ColorStop { #[inline] fn to_computed_value(&self, context: &Context) -> ColorStop { ColorStop { - color: self.color.parsed, + color: self.color.to_computed_value(context), position: match self.position { None => None, Some(ref value) => Some(value.to_computed_value(context)), diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index e512a623492..a65768ea2a1 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -12,7 +12,6 @@ use super::{Number, ToComputedValue, Context}; use values::{Auto, CSSFloat, Either, ExtremumLength, None_, Normal, specified}; use values::specified::length::{FontRelativeLength, ViewportPercentageLength}; -pub use cssparser::Color as CSSColor; pub use super::image::{EndingShape as GradientShape, Gradient, GradientKind, Image}; pub use super::image::{LengthOrKeyword, LengthOrPercentageOrKeyword}; pub use values::specified::{Angle, BorderStyle, Time, UrlOrNone}; diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 9f3c827b944..22f9e5e0996 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -7,6 +7,7 @@ use app_units::Au; use euclid::size::Size2D; use font_metrics::FontMetricsProvider; +use media_queries::Device; use properties::ComputedValues; use std::fmt; use style_traits::ToCss; @@ -37,8 +38,8 @@ pub struct Context<'a> { /// Whether the current element is the root element. pub is_root_element: bool, - /// The current viewport size. - pub viewport_size: Size2D, + /// The Device holds the viewport and other external state. + pub device: &'a Device, /// The style we're inheriting from. pub inherited_style: &'a ComputedValues, @@ -65,7 +66,7 @@ impl<'a> Context<'a> { /// Whether the current element is the root element. pub fn is_root_element(&self) -> bool { self.is_root_element } /// The current viewport size. - pub fn viewport_size(&self) -> Size2D { self.viewport_size } + pub fn viewport_size(&self) -> Size2D { self.device.au_viewport_size() } /// The style we're inheriting from. pub fn inherited_style(&self) -> &ComputedValues { &self.inherited_style } /// The current style. Note that only "eager" properties should be accessed @@ -113,18 +114,65 @@ impl ToComputedValue for T } } +impl ToComputedValue for specified::Color { + type ComputedValue = RGBA; + + #[cfg(not(feature = "gecko"))] + fn to_computed_value(&self, context: &Context) -> RGBA { + match *self { + specified::Color::RGBA(rgba) => rgba, + specified::Color::CurrentColor => context.inherited_style.get_color().clone_color(), + } + } + + #[cfg(feature = "gecko")] + fn to_computed_value(&self, context: &Context) -> RGBA { + use gecko::values::convert_nscolor_to_rgba as to_rgba; + // It's safe to access the nsPresContext immutably during style computation. + let pres_context = unsafe { &*context.device.pres_context }; + match *self { + specified::Color::RGBA(rgba) => rgba, + specified::Color::CurrentColor => context.inherited_style.get_color().clone_color(), + specified::Color::MozDefaultColor => to_rgba(pres_context.mDefaultColor), + specified::Color::MozDefaultBackgroundColor => to_rgba(pres_context.mBackgroundColor), + specified::Color::MozHyperlinktext => to_rgba(pres_context.mLinkColor), + specified::Color::MozActiveHyperlinktext => to_rgba(pres_context.mActiveLinkColor), + specified::Color::MozVisitedHyperlinktext => to_rgba(pres_context.mVisitedLinkColor), + } + } + + fn from_computed_value(computed: &RGBA) -> Self { + specified::Color::RGBA(*computed) + } +} + impl ToComputedValue for specified::CSSColor { type ComputedValue = CSSColor; + #[cfg(not(feature = "gecko"))] #[inline] fn to_computed_value(&self, _context: &Context) -> CSSColor { self.parsed } + #[cfg(feature = "gecko")] + #[inline] + fn to_computed_value(&self, context: &Context) -> CSSColor { + match self.parsed { + specified::Color::RGBA(rgba) => CSSColor::RGBA(rgba), + specified::Color::CurrentColor => CSSColor::CurrentColor, + // Resolve non-standard -moz keywords to RGBA: + non_standard => CSSColor::RGBA(non_standard.to_computed_value(context)), + } + } + #[inline] fn from_computed_value(computed: &CSSColor) -> Self { specified::CSSColor { - parsed: *computed, + parsed: match *computed { + CSSColor::RGBA(rgba) => specified::Color::RGBA(rgba), + CSSColor::CurrentColor => specified::Color::CurrentColor, + }, authored: None, } } diff --git a/components/style/values/specified/color.rs b/components/style/values/specified/color.rs new file mode 100644 index 00000000000..88063803d31 --- /dev/null +++ b/components/style/values/specified/color.rs @@ -0,0 +1,90 @@ +/* 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/. */ + +//! Non-standard CSS color values + +#[cfg(not(feature = "gecko"))] pub use self::servo::Color; +#[cfg(feature = "gecko")] pub use self::gecko::Color; + +#[cfg(not(feature = "gecko"))] +mod servo { + pub use cssparser::Color; + use cssparser::Parser; + use parser::{Parse, ParserContext}; + + impl Parse for Color { + fn parse(_: &ParserContext, input: &mut Parser) -> Result { + Color::parse(input) + } + } +} + +#[cfg(feature = "gecko")] +mod gecko { + use cssparser::{Color as CSSParserColor, Parser, RGBA}; + use parser::{Parse, ParserContext}; + use std::fmt; + use style_traits::ToCss; + use values::HasViewportPercentage; + + /// Color value including non-standard -moz prefixed values. + #[derive(Clone, Copy, PartialEq, Debug)] + pub enum Color { + /// The 'currentColor' keyword + CurrentColor, + /// A specific RGBA color + RGBA(RGBA), + + /// -moz-default-color + MozDefaultColor, + /// -moz-default-background-color + MozDefaultBackgroundColor, + /// -moz-hyperlinktext + MozHyperlinktext, + /// -moz-activehyperlinktext + MozActiveHyperlinktext, + /// -moz-visitedhyperlinktext + MozVisitedHyperlinktext, + } + + no_viewport_percentage!(Color); + + impl Parse for Color { + fn parse(_: &ParserContext, input: &mut Parser) -> Result { + if let Ok(value) = input.try(CSSParserColor::parse) { + match value { + CSSParserColor::CurrentColor => Ok(Color::CurrentColor), + CSSParserColor::RGBA(x) => Ok(Color::RGBA(x)), + } + } else { + let ident = input.expect_ident()?; + match_ignore_ascii_case! { &ident, + "-moz-default-color" => Ok(Color::MozDefaultColor), + "-moz-default-background-color" => Ok(Color::MozDefaultBackgroundColor), + "-moz-hyperlinktext" => Ok(Color::MozHyperlinktext), + "-moz-activehyperlinktext" => Ok(Color::MozActiveHyperlinktext), + "-moz-visitedhyperlinktext" => Ok(Color::MozVisitedHyperlinktext), + _ => Err(()) + } + } + } + } + + impl ToCss for Color { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + match *self { + // Standard values: + Color::CurrentColor => CSSParserColor::CurrentColor.to_css(dest), + Color::RGBA(rgba) => rgba.to_css(dest), + + // Non-standard values: + Color::MozDefaultColor => dest.write_str("-moz-default-color"), + Color::MozDefaultBackgroundColor => dest.write_str("-moz-default-background-color"), + Color::MozHyperlinktext => dest.write_str("-moz-hyperlinktext"), + Color::MozActiveHyperlinktext => dest.write_str("-moz-activehyperlinktext"), + Color::MozVisitedHyperlinktext => dest.write_str("-moz-visitedhyperlinktext"), + } + } + } +} diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 60c169c55be..0e7ec2eb34a 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -18,11 +18,12 @@ use std::fmt; use std::ops::Mul; use style_traits::ToCss; use super::{Auto, CSSFloat, HasViewportPercentage, Either, None_}; -use super::computed::{ComputedValueAsSpecified, Context, ToComputedValue}; -use super::computed::Shadow as ComputedShadow; +use super::computed::{ComputedValueAsSpecified, Context}; +use super::computed::{Shadow as ComputedShadow, ToComputedValue}; #[cfg(feature = "gecko")] pub use self::align::{AlignItems, AlignJustifyContent, AlignJustifySelf, JustifyItems}; +pub use self::color::Color; pub use self::grid::{GridLine, TrackKeyword}; pub use self::image::{AngleOrCorner, ColorStop, EndingShape as GradientEndingShape, Gradient}; pub use self::image::{GradientKind, HorizontalDirection, Image, LengthOrKeyword, LengthOrPercentageOrKeyword}; @@ -36,6 +37,7 @@ pub use self::position::{HorizontalPosition, Position, VerticalPosition}; #[cfg(feature = "gecko")] pub mod align; pub mod basic_shape; +pub mod color; pub mod grid; pub mod image; pub mod length; @@ -48,12 +50,12 @@ no_viewport_percentage!(i32); // For PropertyDeclaration::Order #[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[allow(missing_docs)] pub struct CSSColor { - pub parsed: cssparser::Color, + pub parsed: Color, pub authored: Option>, } impl Parse for CSSColor { - fn parse(_context: &ParserContext, input: &mut Parser) -> Result { + fn parse(context: &ParserContext, input: &mut Parser) -> Result { let start_position = input.position(); let authored = match input.next() { Ok(Token::Ident(s)) => Some(s.into_owned().into_boxed_str()), @@ -61,7 +63,7 @@ impl Parse for CSSColor { }; input.reset(start_position); Ok(CSSColor { - parsed: try!(cssparser::Color::parse(input)), + parsed: try!(Parse::parse(context, input)), authored: authored, }) } @@ -83,7 +85,7 @@ impl CSSColor { /// Returns currentcolor value. pub fn currentcolor() -> CSSColor { CSSColor { - parsed: cssparser::Color::CurrentColor, + parsed: Color::CurrentColor, authored: None, } } @@ -92,7 +94,7 @@ impl CSSColor { /// Returns transparent value. pub fn transparent() -> CSSColor { CSSColor { - parsed: cssparser::Color::RGBA(cssparser::RGBA::transparent()), + parsed: Color::RGBA(cssparser::RGBA::transparent()), // This should probably be "transparent", but maybe it doesn't matter. authored: None, } @@ -616,7 +618,7 @@ impl ToComputedValue for Shadow { spread_radius: self.spread_radius.to_computed_value(context), color: self.color .as_ref() - .map(|color| color.parsed) + .map(|color| color.to_computed_value(context)) .unwrap_or(cssparser::Color::CurrentColor), inset: self.inset, } diff --git a/components/style/viewport.rs b/components/style/viewport.rs index f15f4553c0e..d01d734a2d2 100644 --- a/components/style/viewport.rs +++ b/components/style/viewport.rs @@ -687,7 +687,7 @@ impl MaybeNew for ViewportConstraints { // TODO(emilio): Stop cloning `ComputedValues` around! let context = Context { is_root_element: false, - viewport_size: initial_viewport, + device: device, inherited_style: device.default_values(), layout_parent_style: device.default_values(), style: device.default_values().clone(), diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index eb51eb7ea09..2c36b5d1123 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -1173,9 +1173,8 @@ pub extern "C" fn Servo_DeclarationBlock_SetAutoValue(declarations: pub extern "C" fn Servo_DeclarationBlock_SetCurrentColor(declarations: RawServoDeclarationBlockBorrowed, property: nsCSSPropertyID) { - use cssparser::Color; use style::properties::{DeclaredValue, PropertyDeclaration, LonghandId}; - use style::values::specified::CSSColor; + use style::values::specified::{Color, CSSColor}; let declarations = RwLock::::as_arc(&declarations); let long = get_longhand_from_id!(property); @@ -1195,11 +1194,10 @@ pub extern "C" fn Servo_DeclarationBlock_SetColorValue(declarations: RawServoDeclarationBlockBorrowed, property: nsCSSPropertyID, value: structs::nscolor) { - use cssparser::Color; use style::gecko::values::convert_nscolor_to_rgba; use style::properties::{DeclaredValue, PropertyDeclaration, LonghandId}; use style::properties::longhands; - use style::values::specified::CSSColor; + use style::values::specified::{Color, CSSColor}; let declarations = RwLock::::as_arc(&declarations); let long = get_longhand_from_id!(property); @@ -1444,7 +1442,7 @@ pub extern "C" fn Servo_GetComputedKeyframeValues(keyframes: RawGeckoKeyframeLis let context = Context { is_root_element: false, - viewport_size: data.stylist.device.au_viewport_size(), + device: &data.stylist.device, inherited_style: parent_style.unwrap_or(default_values), layout_parent_style: parent_style.unwrap_or(default_values), style: (**style).clone(), diff --git a/tests/unit/style/parsing/image.rs b/tests/unit/style/parsing/image.rs index b68d61fb2ed..15e53e1007f 100644 --- a/tests/unit/style/parsing/image.rs +++ b/tests/unit/style/parsing/image.rs @@ -2,11 +2,11 @@ * 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/. */ -use app_units::Au; use cssparser::Parser; -use euclid::size::Size2D; +use euclid::size::TypedSize2D; use media_queries::CSSErrorReporterTest; use std::f32::consts::PI; +use style::media_queries::{Device, MediaType}; use style::parser::ParserContext; use style::properties::ComputedValues; use style::stylesheets::Origin; @@ -43,11 +43,12 @@ fn test_linear_gradient() { // AngleOrCorner::None should become AngleOrCorner::Angle(Angle(PI)) when parsed // Note that Angle(PI) is correct for top-to-bottom rendering, whereas Angle(0) would render bottom-to-top. // ref: https://developer.mozilla.org/en-US/docs/Web/CSS/angle - let container = Size2D::new(Au::default(), Au::default()); + let viewport_size = TypedSize2D::new(0., 0.); let initial_style = ComputedValues::initial_values(); + let device = Device::new(MediaType::Screen, viewport_size); let specified_context = Context { is_root_element: true, - viewport_size: container, + device: &device, inherited_style: initial_style, layout_parent_style: initial_style, style: initial_style.clone(),