diff options
-rw-r--r-- | components/style/gecko/conversions.rs | 13 | ||||
-rw-r--r-- | components/style/gecko/media_queries.rs | 21 | ||||
-rw-r--r-- | components/style/properties/gecko.mako.rs | 74 | ||||
-rw-r--r-- | components/style/properties/longhand/counters.mako.rs | 2 |
4 files changed, 94 insertions, 16 deletions
diff --git a/components/style/gecko/conversions.rs b/components/style/gecko/conversions.rs index 9d4b6f230b1..327b4b056ec 100644 --- a/components/style/gecko/conversions.rs +++ b/components/style/gecko/conversions.rs @@ -919,3 +919,16 @@ impl<T> Rect<T> where T: GeckoStyleCoordConvertible { ) } } + +/// Convert to String from given chars pointer. +pub unsafe fn string_from_chars_pointer(p: *const u16) -> String { + use std::slice; + let mut length = 0; + let mut iter = p; + while *iter != 0 { + length += 1; + iter = iter.offset(1); + } + let char_vec = slice::from_raw_parts(p, length as usize); + String::from_utf16_lossy(char_vec) +} diff --git a/components/style/gecko/media_queries.rs b/components/style/gecko/media_queries.rs index 3bd1a85f442..be2cafa77bc 100644 --- a/components/style/gecko/media_queries.rs +++ b/components/style/gecko/media_queries.rs @@ -14,7 +14,7 @@ use font_metrics::get_metrics_provider_for_product; use gecko::values::convert_nscolor_to_rgba; use gecko_bindings::bindings; use gecko_bindings::structs; -use gecko_bindings::structs::{nsCSSKeyword, nsCSSProps_KTableEntry, nsCSSValue, nsCSSUnit, nsStringBuffer}; +use gecko_bindings::structs::{nsCSSKeyword, nsCSSProps_KTableEntry, nsCSSValue, nsCSSUnit}; use gecko_bindings::structs::{nsMediaExpression_Range, nsMediaFeature}; use gecko_bindings::structs::{nsMediaFeature_ValueType, nsMediaFeature_RangeType, nsMediaFeature_RequirementFlags}; use gecko_bindings::structs::{nsPresContext, RawGeckoPresContextOwned}; @@ -294,19 +294,6 @@ impl ToCss for Resolution { } } -unsafe fn string_from_ns_string_buffer(buffer: *const nsStringBuffer) -> String { - use std::slice; - debug_assert!(!buffer.is_null()); - let data = buffer.offset(1) as *const u16; - let mut length = 0; - let mut iter = data; - while *iter != 0 { - length += 1; - iter = iter.offset(1); - } - String::from_utf16_lossy(slice::from_raw_parts(data, length)) -} - /// A value found or expected in a media expression. #[derive(PartialEq, Debug, Clone)] pub enum MediaExpressionValue { @@ -334,6 +321,8 @@ pub enum MediaExpressionValue { impl MediaExpressionValue { fn from_css_value(for_expr: &Expression, css_value: &nsCSSValue) -> Option<Self> { + use gecko::conversions::string_from_chars_pointer; + // NB: If there's a null value, that means that we don't support the // feature. if css_value.mUnit == nsCSSUnit::eCSSUnit_Null { @@ -372,7 +361,9 @@ impl MediaExpressionValue { nsMediaFeature_ValueType::eIdent => { debug_assert!(css_value.mUnit == nsCSSUnit::eCSSUnit_Ident); let string = unsafe { - string_from_ns_string_buffer(*css_value.mValue.mString.as_ref()) + let buffer = *css_value.mValue.mString.as_ref(); + debug_assert!(!buffer.is_null()); + string_from_chars_pointer(buffer.offset(1) as *const u16) }; Some(MediaExpressionValue::Ident(string)) } diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 45ffb371d8a..f3397ead5c4 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -5579,6 +5579,80 @@ clip-path self.copy_content_from(other) } + pub fn clone_content(&self) -> longhands::content::computed_value::T { + use gecko::conversions::string_from_chars_pointer; + use gecko_bindings::structs::nsStyleContentType::*; + use properties::longhands::content::computed_value::{T, ContentItem}; + use values::generics::CounterStyleOrNone; + use values::specified::url::SpecifiedUrl; + use values::specified::Attr; + + if self.gecko.mContents.is_empty() { + return T::Normal; + } + + if self.gecko.mContents.len() == 1 && + self.gecko.mContents[0].mType == eStyleContentType_AltContent { + return T::MozAltContent; + } + + T::Items( + self.gecko.mContents.iter().map(|gecko_content| { + match gecko_content.mType { + eStyleContentType_OpenQuote => ContentItem::OpenQuote, + eStyleContentType_CloseQuote => ContentItem::CloseQuote, + eStyleContentType_NoOpenQuote => ContentItem::NoOpenQuote, + eStyleContentType_NoCloseQuote => ContentItem::NoCloseQuote, + eStyleContentType_String => { + let gecko_chars = unsafe { gecko_content.mContent.mString.as_ref() }; + let string = unsafe { string_from_chars_pointer(*gecko_chars) }; + ContentItem::String(string) + }, + eStyleContentType_Attr => { + let gecko_chars = unsafe { gecko_content.mContent.mString.as_ref() }; + let string = unsafe { string_from_chars_pointer(*gecko_chars) }; + let (namespace, attribute) = + match string.find('|') { + None => (None, string), + Some(index) => { + let (_, val) = string.split_at(index); + // FIXME: We should give NamespaceId as well to make Attr + // struct. However, there is no field for it in Gecko. + debug_assert!(false, "Attr with namespace does not support yet"); + (None, val.to_string()) + } + }; + ContentItem::Attr(Attr { namespace, attribute }) + }, + eStyleContentType_Counter | eStyleContentType_Counters => { + let gecko_function = + unsafe { &**gecko_content.mContent.mCounters.as_ref() }; + let ident = gecko_function.mIdent.to_string(); + let style = + CounterStyleOrNone::from_gecko_value(&gecko_function.mCounterStyle); + if gecko_content.mType == eStyleContentType_Counter { + ContentItem::Counter(ident, style) + } else { + let separator = gecko_function.mSeparator.to_string(); + ContentItem::Counters(ident, separator, style) + } + }, + eStyleContentType_Image => { + unsafe { + let gecko_image_request = + unsafe { &**gecko_content.mContent.mImage.as_ref() }; + ContentItem::Url( + SpecifiedUrl::from_image_request(gecko_image_request) + .expect("mContent could not convert to SpecifiedUrl") + ) + } + }, + x => panic!("Found unexpected value in style struct for content property: {:?}", x), + } + }).collect() + ) + } + % for counter_property in ["Increment", "Reset"]: pub fn set_counter_${counter_property.lower()}(&mut self, v: longhands::counter_increment::computed_value::T) { unsafe { diff --git a/components/style/properties/longhand/counters.mako.rs b/components/style/properties/longhand/counters.mako.rs index 85e039b3f68..c10d06c8036 100644 --- a/components/style/properties/longhand/counters.mako.rs +++ b/components/style/properties/longhand/counters.mako.rs @@ -6,7 +6,7 @@ <% data.new_style_struct("Counters", inherited=False, gecko_name="Content") %> -<%helpers:longhand name="content" boxed="True" animation_value_type="none" +<%helpers:longhand name="content" boxed="True" animation_value_type="discrete" spec="https://drafts.csswg.org/css-content/#propdef-content"> use values::computed::ComputedValueAsSpecified; #[cfg(feature = "gecko")] |