Skip to content
Permalink
Browse files

style: Use cbindgen for counters.

  • Loading branch information...
emilio committed Sep 2, 2019
1 parent 3fcd23d commit 987a1eeb62c218fddd6d5ddfdfcaba016db8c150
@@ -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">
@@ -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;
@@ -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;

0 comments on commit 987a1ee

Please sign in to comment.
You can’t perform that action at this time.