aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2019-09-02 23:11:26 +0000
committerEmilio Cobos Álvarez <emilio@crisal.io>2019-09-12 22:34:16 +0200
commit987a1eeb62c218fddd6d5ddfdfcaba016db8c150 (patch)
tree17f04efb90f51df68b01f4bee5e8b0c5310024a6
parent3fcd23dcdf0c8f8e32a1ae0b0eafd7640f63b10b (diff)
downloadservo-987a1eeb62c218fddd6d5ddfdfcaba016db8c150.tar.gz
servo-987a1eeb62c218fddd6d5ddfdfcaba016db8c150.zip
style: Use cbindgen for counters.
Differential Revision: https://phabricator.services.mozilla.com/D44403
-rw-r--r--components/style/properties/gecko.mako.rs48
-rw-r--r--components/style/values/generics/counters.rs30
-rw-r--r--components/style/values/specified/counters.rs4
3 files changed, 17 insertions, 65 deletions
diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs
index 526304d87ef..97321fcbd38 100644
--- a/components/style/properties/gecko.mako.rs
+++ b/components/style/properties/gecko.mako.rs
@@ -2579,8 +2579,7 @@ clip-path
${impl_simple('column_rule_style', 'mColumnRuleStyle')}
</%self:impl_trait>
-<%self:impl_trait style_struct_name="Counters"
- skip_longhands="content counter-increment counter-reset counter-set">
+<%self:impl_trait style_struct_name="Counters" skip_longhands="content">
pub fn ineffective_content_property(&self) -> bool {
self.gecko.mContents.is_empty()
}
@@ -2811,51 +2810,6 @@ clip-path
}).collect::<Vec<_>>().into_boxed_slice()
)
}
-
- % for counter_property in ["Increment", "Reset", "Set"]:
- pub fn set_counter_${counter_property.lower()}(
- &mut self,
- v: longhands::counter_${counter_property.lower()}::computed_value::T
- ) {
- unsafe {
- bindings::Gecko_ClearAndResizeCounter${counter_property}s(&mut *self.gecko, v.len() as u32);
- for (i, pair) in v.0.into_vec().into_iter().enumerate() {
- self.gecko.m${counter_property}s[i].mCounter.set_move(
- RefPtr::from_addrefed(pair.name.0.into_addrefed())
- );
- self.gecko.m${counter_property}s[i].mValue = pair.value;
- }
- }
- }
-
- pub fn copy_counter_${counter_property.lower()}_from(&mut self, other: &Self) {
- unsafe {
- bindings::Gecko_CopyCounter${counter_property}sFrom(&mut *self.gecko, &*other.gecko)
- }
- }
-
- pub fn reset_counter_${counter_property.lower()}(&mut self, other: &Self) {
- self.copy_counter_${counter_property.lower()}_from(other)
- }
-
- pub fn clone_counter_${counter_property.lower()}(
- &self
- ) -> longhands::counter_${counter_property.lower()}::computed_value::T {
- use crate::values::generics::counters::CounterPair;
- use crate::values::CustomIdent;
-
- longhands::counter_${counter_property.lower()}::computed_value::T::new(
- self.gecko.m${counter_property}s.iter().map(|ref gecko_counter| {
- CounterPair {
- name: CustomIdent(unsafe {
- Atom::from_raw(gecko_counter.mCounter.mRawPtr)
- }),
- value: gecko_counter.mValue,
- }
- }).collect()
- )
- }
- % endfor
</%self:impl_trait>
<%self:impl_trait style_struct_name="UI" skip_longhands="-moz-force-broken-image-icon">
diff --git a/components/style/values/generics/counters.rs b/components/style/values/generics/counters.rs
index 9f3135d867d..391da7e33cc 100644
--- a/components/style/values/generics/counters.rs
+++ b/components/style/values/generics/counters.rs
@@ -25,12 +25,14 @@ use std::ops::Deref;
ToResolvedValue,
ToShmem,
)]
-pub struct CounterPair<Integer> {
+#[repr(C)]
+pub struct GenericCounterPair<Integer> {
/// The name of the counter.
pub name: CustomIdent,
/// The value of the counter / increment / etc.
pub value: Integer,
}
+pub use self::GenericCounterPair as CounterPair;
/// A generic value for the `counter-increment` property.
#[derive(
@@ -45,13 +47,15 @@ pub struct CounterPair<Integer> {
ToResolvedValue,
ToShmem,
)]
-pub struct CounterIncrement<I>(pub Counters<I>);
+#[repr(transparent)]
+pub struct GenericCounterIncrement<I>(pub GenericCounters<I>);
+pub use self::GenericCounterIncrement as CounterIncrement;
impl<I> CounterIncrement<I> {
/// Returns a new value for `counter-increment`.
#[inline]
pub fn new(counters: Vec<CounterPair<I>>) -> Self {
- CounterIncrement(Counters(counters.into_boxed_slice()))
+ CounterIncrement(Counters(counters.into()))
}
}
@@ -77,13 +81,15 @@ impl<I> Deref for CounterIncrement<I> {
ToResolvedValue,
ToShmem,
)]
-pub struct CounterSetOrReset<I>(pub Counters<I>);
+#[repr(transparent)]
+pub struct GenericCounterSetOrReset<I>(pub GenericCounters<I>);
+pub use self::GenericCounterSetOrReset as CounterSetOrReset;
impl<I> CounterSetOrReset<I> {
/// Returns a new value for `counter-set` / `counter-reset`.
#[inline]
pub fn new(counters: Vec<CounterPair<I>>) -> Self {
- CounterSetOrReset(Counters(counters.into_boxed_slice()))
+ CounterSetOrReset(Counters(counters.into()))
}
}
@@ -111,17 +117,9 @@ impl<I> Deref for CounterSetOrReset<I> {
ToResolvedValue,
ToShmem,
)]
-pub struct Counters<I>(#[css(iterable, if_empty = "none")] Box<[CounterPair<I>]>);
-
-impl<I> Counters<I> {
- /// Move out the Box into a vector. This could just return the Box<>, but
- /// Vec<> is a bit more convenient because Box<[T]> doesn't implement
- /// IntoIter: https://github.com/rust-lang/rust/issues/59878
- #[inline]
- pub fn into_vec(self) -> Vec<CounterPair<I>> {
- self.0.into_vec()
- }
-}
+#[repr(transparent)]
+pub struct GenericCounters<I>(#[css(iterable, if_empty = "none")] crate::OwnedSlice<GenericCounterPair<I>>);
+pub use self::GenericCounters as Counters;
#[cfg(feature = "servo")]
type CounterStyleType = ListStyleType;
diff --git a/components/style/values/specified/counters.rs b/components/style/values/specified/counters.rs
index 98e9a27752c..39ca07e3563 100644
--- a/components/style/values/specified/counters.rs
+++ b/components/style/values/specified/counters.rs
@@ -8,9 +8,9 @@
use crate::computed_values::list_style_type::T as ListStyleType;
use crate::parser::{Parse, ParserContext};
use crate::values::generics::counters as generics;
-use crate::values::generics::counters::CounterIncrement as GenericCounterIncrement;
+use crate::values::generics::counters::GenericCounterIncrement;
use crate::values::generics::counters::CounterPair;
-use crate::values::generics::counters::CounterSetOrReset as GenericCounterSetOrReset;
+use crate::values::generics::counters::GenericCounterSetOrReset;
#[cfg(feature = "gecko")]
use crate::values::generics::CounterStyle;
use crate::values::specified::url::SpecifiedImageUrl;