From 3ea2f3a16c03683dd39250caae8597620600da04 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Tue, 16 May 2017 09:47:14 +1000 Subject: [PATCH] Add support for auto value in nsCSSValue sugar. --- components/style/gecko/rules.rs | 6 +++--- .../style/gecko_bindings/sugar/ns_css_value.rs | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/components/style/gecko/rules.rs b/components/style/gecko/rules.rs index 49e33ab16cc..4bb3ed85041 100644 --- a/components/style/gecko/rules.rs +++ b/components/style/gecko/rules.rs @@ -217,9 +217,9 @@ impl ToNsCssValue for counter_style::Symbol { } impl ToNsCssValue for counter_style::Ranges { - fn convert(&self, _nscssvalue: &mut nsCSSValue) { + fn convert(&self, nscssvalue: &mut nsCSSValue) { if self.0.is_empty() { - //nscssvalue.set_auto(); // FIXME: add bindings for nsCSSValue::SetAutoValue + nscssvalue.set_auto(); } else { for range in &self.0 { fn set_bound(bound: Option, nscssvalue: &mut nsCSSValue) { @@ -274,7 +274,7 @@ impl ToNsCssValue for counter_style::SpeakAs { fn convert(&self, nscssvalue: &mut nsCSSValue) { use counter_style::SpeakAs::*; match *self { - Auto => {} //nscssvalue.set_auto(), // FIXME: add bindings for nsCSSValue::SetAutoValue + Auto => nscssvalue.set_auto(), Bullets => nscssvalue.set_enum(structs::NS_STYLE_COUNTER_SPEAKAS_BULLETS as i32), Numbers => nscssvalue.set_enum(structs::NS_STYLE_COUNTER_SPEAKAS_NUMBERS as i32), Words => nscssvalue.set_enum(structs::NS_STYLE_COUNTER_SPEAKAS_WORDS as i32), diff --git a/components/style/gecko_bindings/sugar/ns_css_value.rs b/components/style/gecko_bindings/sugar/ns_css_value.rs index e2ff4ceab30..3cc6ae1df00 100644 --- a/components/style/gecko_bindings/sugar/ns_css_value.rs +++ b/components/style/gecko_bindings/sugar/ns_css_value.rs @@ -101,9 +101,24 @@ impl nsCSSValue { } } + fn set_valueless_unit(&mut self, unit: nsCSSUnit) { + debug_assert_eq!(self.mUnit, nsCSSUnit::eCSSUnit_Null); + debug_assert!(unit as u32 <= nsCSSUnit::eCSSUnit_DummyInherit as u32, "Not a valueless unit"); + self.mUnit = unit; + } + + /// Set to an auto value + /// + /// This method requires the current value to be null. + pub fn set_auto(&mut self) { + self.set_valueless_unit(nsCSSUnit::eCSSUnit_Auto); + } + /// Set to a normal value + /// + /// This method requires the current value to be null. pub fn set_normal(&mut self) { - unsafe { bindings::Gecko_CSSValue_SetNormal(self) } + self.set_valueless_unit(nsCSSUnit::eCSSUnit_Normal); } fn set_string_internal(&mut self, s: &str, unit: nsCSSUnit) {