Bug 1378076 - Part 4: make content property animatable. r?hiro
In this patch, make following properties animatable.
* content
MozReview-Commit-ID: E7lNR8bK2C6
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -4813,16 +4813,106 @@ clip-path
pub fn copy_content_from(&mut self, other: &Self) {
use gecko_bindings::bindings::Gecko_CopyStyleContentsFrom;
unsafe {
Gecko_CopyStyleContentsFrom(&mut self.gecko, &other.gecko)
}
}
+ pub fn clone_content(&self) -> longhands::content::computed_value::T {
+ 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;
+ }
+
+ unsafe fn string_from_char_array(chars: &*mut u16) -> String {
+ let data = *chars as *const u16;
+ let mut length = 0;
+ let mut iter = data;
+ while *iter != 0 {
+ length += 1;
+ iter = iter.offset(1);
+ }
+ let char_vec = ::std::slice::from_raw_parts(data, length as usize);
+ String::from_utf16(char_vec).unwrap()
+ }
+
+ 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_char_array(gecko_chars) };
+ ContentItem::String(string)
+ },
+ eStyleContentType_Attr => {
+ let gecko_chars = unsafe { gecko_content.mContent.mString.as_ref() };
+ let string = unsafe { string_from_char_array(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.
+ // We should somehow keep namespaces which could be taken
+ // during parsing?
+ debug_assert!(false, "Attr with namespace don't support yet");
+ (None, val.to_string())
+ }
+ };
+ ContentItem::Attr(Attr { namespace, attribute })
+ },
+ eStyleContentType_Counter => {
+ 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);
+ ContentItem::Counter(ident, style)
+ },
+ 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);
+ let sep = gecko_function.mSeparator.to_string();
+ ContentItem::Counters(ident, sep, 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 {
bindings::Gecko_ClearAndResizeCounter${counter_property}s(&mut self.gecko,
v.0.len() as u32);
for (i, (name, value)) in v.0.into_iter().enumerate() {
self.gecko.m${counter_property}s[i].mCounter.assign(name.0.as_slice());
self.gecko.m${counter_property}s[i].mValue = value;
--- a/servo/components/style/properties/longhand/counters.mako.rs
+++ b/servo/components/style/properties/longhand/counters.mako.rs
@@ -1,17 +1,17 @@
/* 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/. */
<%namespace name="helpers" file="/helpers.mako.rs" />
<% 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")]
use values::generics::CounterStyleOrNone;
#[cfg(feature = "gecko")]
use values::specified::url::SpecifiedUrl;
#[cfg(feature = "gecko")]
use values::specified::Attr;