mirror of
https://github.com/servo/servo.git
synced 2025-08-07 22:45:34 +01:00
style: Use OwnedSlice for will-change.
We could use ArcSlice if wanted I guess, your call. Though will change is not supposed to be used very frequently. Differential Revision: https://phabricator.services.mozilla.com/D30548
This commit is contained in:
parent
5f6c8d9060
commit
85752fa479
2 changed files with 25 additions and 84 deletions
|
@ -2513,7 +2513,7 @@ fn static_assert() {
|
|||
transition-timing-function transition-property
|
||||
transform-style
|
||||
rotate scroll-snap-points-x scroll-snap-points-y
|
||||
scroll-snap-coordinate -moz-binding will-change
|
||||
scroll-snap-coordinate -moz-binding
|
||||
offset-path shape-outside
|
||||
translate scale -webkit-line-clamp""" %>
|
||||
<%self:impl_trait style_struct_name="Box" skip_longhands="${skip_box_longhands}">
|
||||
|
@ -2829,66 +2829,6 @@ fn static_assert() {
|
|||
${impl_individual_transform('translate', 'Translate', 'mSpecifiedTranslate')}
|
||||
${impl_individual_transform('scale', 'Scale', 'mSpecifiedScale')}
|
||||
|
||||
pub fn set_will_change(&mut self, v: longhands::will_change::computed_value::T) {
|
||||
use crate::gecko_bindings::bindings::{Gecko_AppendWillChange, Gecko_ClearWillChange};
|
||||
use crate::values::specified::box_::{WillChangeBits, WillChange};
|
||||
|
||||
match v {
|
||||
WillChange::AnimateableFeatures { features, bits } => {
|
||||
unsafe {
|
||||
Gecko_ClearWillChange(&mut *self.gecko, features.len());
|
||||
}
|
||||
|
||||
for feature in features.iter() {
|
||||
unsafe {
|
||||
Gecko_AppendWillChange(&mut *self.gecko, feature.0.as_ptr())
|
||||
}
|
||||
}
|
||||
|
||||
self.gecko.mWillChangeBitField = bits;
|
||||
},
|
||||
WillChange::Auto => {
|
||||
unsafe {
|
||||
Gecko_ClearWillChange(&mut *self.gecko, 0);
|
||||
}
|
||||
self.gecko.mWillChangeBitField = WillChangeBits::empty();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
pub fn copy_will_change_from(&mut self, other: &Self) {
|
||||
use crate::gecko_bindings::bindings::Gecko_CopyWillChangeFrom;
|
||||
|
||||
self.gecko.mWillChangeBitField = other.gecko.mWillChangeBitField;
|
||||
unsafe {
|
||||
Gecko_CopyWillChangeFrom(&mut *self.gecko, &*other.gecko);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reset_will_change(&mut self, other: &Self) {
|
||||
self.copy_will_change_from(other)
|
||||
}
|
||||
|
||||
pub fn clone_will_change(&self) -> longhands::will_change::computed_value::T {
|
||||
use crate::values::CustomIdent;
|
||||
use crate::values::specified::box_::WillChange;
|
||||
|
||||
if self.gecko.mWillChange.len() == 0 {
|
||||
return WillChange::Auto
|
||||
}
|
||||
|
||||
let custom_idents: Vec<CustomIdent> = self.gecko.mWillChange.iter().map(|gecko_atom| {
|
||||
unsafe {
|
||||
CustomIdent(Atom::from_raw(gecko_atom.mRawPtr))
|
||||
}
|
||||
}).collect();
|
||||
|
||||
WillChange::AnimateableFeatures {
|
||||
features: custom_idents.into_boxed_slice(),
|
||||
bits: self.gecko.mWillChangeBitField,
|
||||
}
|
||||
}
|
||||
|
||||
<% impl_shape_source("shape_outside", "mShapeOutside") %>
|
||||
|
||||
pub fn set_offset_path(&mut self, v: longhands::offset_path::computed_value::T) {
|
||||
|
|
|
@ -642,6 +642,7 @@ pub enum OverflowClipBox {
|
|||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
Default,
|
||||
MallocSizeOf,
|
||||
PartialEq,
|
||||
SpecifiedValueInfo,
|
||||
|
@ -650,38 +651,38 @@ pub enum OverflowClipBox {
|
|||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
/// Provides a rendering hint to the user agent,
|
||||
/// stating what kinds of changes the author expects
|
||||
/// to perform on the element
|
||||
#[css(comma)]
|
||||
#[repr(C)]
|
||||
/// Provides a rendering hint to the user agent, stating what kinds of changes
|
||||
/// the author expects to perform on the element.
|
||||
///
|
||||
/// `auto` is represented by an empty `features` list.
|
||||
///
|
||||
/// <https://drafts.csswg.org/css-will-change/#will-change>
|
||||
pub enum WillChange {
|
||||
/// Expresses no particular intent
|
||||
Auto,
|
||||
/// <custom-ident>
|
||||
#[css(comma)]
|
||||
AnimateableFeatures {
|
||||
pub struct WillChange {
|
||||
/// The features that are supposed to change.
|
||||
#[css(iterable)]
|
||||
features: Box<[CustomIdent]>,
|
||||
///
|
||||
/// TODO(emilio): Consider using ArcSlice since we just clone them from the
|
||||
/// specified value? That'd save an allocation, which could be worth it.
|
||||
#[css(iterable, if_empty = "auto")]
|
||||
features: crate::OwnedSlice<CustomIdent>,
|
||||
/// A bitfield with the kind of change that the value will create, based
|
||||
/// on the above field.
|
||||
#[css(skip)]
|
||||
bits: WillChangeBits,
|
||||
},
|
||||
}
|
||||
|
||||
impl WillChange {
|
||||
#[inline]
|
||||
/// Get default value of `will-change` as `auto`
|
||||
pub fn auto() -> WillChange {
|
||||
WillChange::Auto
|
||||
pub fn auto() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
/// The change bits that we care about.
|
||||
#[derive(MallocSizeOf, SpecifiedValueInfo, ToComputedValue, ToResolvedValue, ToShmem)]
|
||||
#[derive(Default, MallocSizeOf, SpecifiedValueInfo, ToComputedValue, ToResolvedValue, ToShmem)]
|
||||
#[repr(C)]
|
||||
pub struct WillChangeBits: u8 {
|
||||
/// Whether the stacking context will change.
|
||||
|
@ -746,7 +747,7 @@ impl Parse for WillChange {
|
|||
.try(|input| input.expect_ident_matching("auto"))
|
||||
.is_ok()
|
||||
{
|
||||
return Ok(WillChange::Auto);
|
||||
return Ok(Self::default());
|
||||
}
|
||||
|
||||
let mut bits = WillChangeBits::empty();
|
||||
|
@ -767,8 +768,8 @@ impl Parse for WillChange {
|
|||
Ok(ident)
|
||||
})?;
|
||||
|
||||
Ok(WillChange::AnimateableFeatures {
|
||||
features: custom_idents.into_boxed_slice(),
|
||||
Ok(Self {
|
||||
features: custom_idents.into(),
|
||||
bits,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue