mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Use cbindgen for css-align types.
This provides stronger typing and removes a bunch of subtle constants matching. Differential Revision: https://phabricator.services.mozilla.com/D61058
This commit is contained in:
parent
41ae92e045
commit
2bdcd766bb
3 changed files with 39 additions and 100 deletions
|
@ -957,48 +957,16 @@ fn static_assert() {
|
||||||
|
|
||||||
<% skip_position_longhands = " ".join(x.ident for x in SIDES) %>
|
<% skip_position_longhands = " ".join(x.ident for x in SIDES) %>
|
||||||
<%self:impl_trait style_struct_name="Position"
|
<%self:impl_trait style_struct_name="Position"
|
||||||
skip_longhands="${skip_position_longhands}
|
skip_longhands="${skip_position_longhands} grid-auto-flow">
|
||||||
align-content justify-content align-self
|
|
||||||
justify-self align-items justify-items
|
|
||||||
grid-auto-flow">
|
|
||||||
% for side in SIDES:
|
% for side in SIDES:
|
||||||
<% impl_split_style_coord(side.ident, "mOffset", side.index) %>
|
<% impl_split_style_coord(side.ident, "mOffset", side.index) %>
|
||||||
% endfor
|
% endfor
|
||||||
|
${impl_simple_type_with_conversion("grid_auto_flow")}
|
||||||
% for kind in ["align", "justify"]:
|
|
||||||
${impl_simple_type_with_conversion(kind + "_content")}
|
|
||||||
${impl_simple_type_with_conversion(kind + "_self")}
|
|
||||||
% endfor
|
|
||||||
${impl_simple_type_with_conversion("align_items")}
|
|
||||||
|
|
||||||
pub fn set_justify_items(&mut self, v: longhands::justify_items::computed_value::T) {
|
|
||||||
self.gecko.mSpecifiedJustifyItems = v.specified.into();
|
|
||||||
self.set_computed_justify_items(v.computed);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_computed_justify_items(&mut self, v: values::specified::JustifyItems) {
|
pub fn set_computed_justify_items(&mut self, v: values::specified::JustifyItems) {
|
||||||
debug_assert_ne!(v.0, crate::values::specified::align::AlignFlags::LEGACY);
|
debug_assert_ne!(v.0, crate::values::specified::align::AlignFlags::LEGACY);
|
||||||
self.gecko.mJustifyItems = v.into();
|
self.gecko.mJustifyItems.computed = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reset_justify_items(&mut self, reset_style: &Self) {
|
|
||||||
self.gecko.mJustifyItems = reset_style.gecko.mJustifyItems;
|
|
||||||
self.gecko.mSpecifiedJustifyItems = reset_style.gecko.mSpecifiedJustifyItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn copy_justify_items_from(&mut self, other: &Self) {
|
|
||||||
self.gecko.mJustifyItems = other.gecko.mJustifyItems;
|
|
||||||
self.gecko.mSpecifiedJustifyItems = other.gecko.mJustifyItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn clone_justify_items(&self) -> longhands::justify_items::computed_value::T {
|
|
||||||
longhands::justify_items::computed_value::T {
|
|
||||||
computed: self.gecko.mJustifyItems.into(),
|
|
||||||
specified: self.gecko.mSpecifiedJustifyItems.into(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
${impl_simple_type_with_conversion("grid_auto_flow")}
|
|
||||||
</%self:impl_trait>
|
</%self:impl_trait>
|
||||||
|
|
||||||
<% skip_outline_longhands = " ".join("outline-style outline-width".split() +
|
<% skip_outline_longhands = " ".join("outline-style outline-width".split() +
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
use crate::values::computed::{Context, ToComputedValue};
|
use crate::values::computed::{Context, ToComputedValue};
|
||||||
use crate::values::specified;
|
use crate::values::specified;
|
||||||
|
|
||||||
pub use super::specified::{AlignContent, AlignItems, JustifyContent, SelfAlignment};
|
pub use super::specified::{AlignContent, AlignItems, ContentDistribution, JustifyContent, SelfAlignment};
|
||||||
pub use super::specified::{AlignSelf, JustifySelf};
|
pub use super::specified::{AlignSelf, JustifySelf};
|
||||||
|
|
||||||
/// The computed value for the `justify-items` property.
|
/// The computed value for the `justify-items` property.
|
||||||
|
@ -34,7 +34,8 @@ pub use super::specified::{AlignSelf, JustifySelf};
|
||||||
///
|
///
|
||||||
/// See the discussion in https://bugzil.la/1384542.
|
/// See the discussion in https://bugzil.la/1384542.
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, ToCss, ToResolvedValue)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq, ToCss, ToResolvedValue)]
|
||||||
pub struct JustifyItems {
|
#[repr(C)]
|
||||||
|
pub struct ComputedJustifyItems {
|
||||||
/// The specified value for the property. Can contain the bare `legacy`
|
/// The specified value for the property. Can contain the bare `legacy`
|
||||||
/// keyword.
|
/// keyword.
|
||||||
#[css(skip)]
|
#[css(skip)]
|
||||||
|
@ -45,6 +46,8 @@ pub struct JustifyItems {
|
||||||
pub computed: specified::JustifyItems,
|
pub computed: specified::JustifyItems,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub use self::ComputedJustifyItems as JustifyItems;
|
||||||
|
|
||||||
impl JustifyItems {
|
impl JustifyItems {
|
||||||
/// Returns the `legacy` value.
|
/// Returns the `legacy` value.
|
||||||
pub fn legacy() -> Self {
|
pub fn legacy() -> Self {
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
//!
|
//!
|
||||||
//! https://drafts.csswg.org/css-align/
|
//! https://drafts.csswg.org/css-align/
|
||||||
|
|
||||||
use crate::gecko_bindings::structs;
|
|
||||||
use crate::parser::{Parse, ParserContext};
|
use crate::parser::{Parse, ParserContext};
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
|
@ -14,56 +13,55 @@ use style_traits::{CssWriter, KeywordsCollectFn, ParseError, SpecifiedValueInfo,
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
/// Constants shared by multiple CSS Box Alignment properties
|
/// Constants shared by multiple CSS Box Alignment properties
|
||||||
///
|
|
||||||
/// These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
|
|
||||||
#[derive(MallocSizeOf, ToComputedValue, ToResolvedValue, ToShmem)]
|
#[derive(MallocSizeOf, ToComputedValue, ToResolvedValue, ToShmem)]
|
||||||
|
#[repr(C)]
|
||||||
pub struct AlignFlags: u8 {
|
pub struct AlignFlags: u8 {
|
||||||
// Enumeration stored in the lower 5 bits:
|
// Enumeration stored in the lower 5 bits:
|
||||||
/// 'auto'
|
/// {align,justify}-{content,items,self}: 'auto'
|
||||||
const AUTO = structs::NS_STYLE_ALIGN_AUTO as u8;
|
const AUTO = 0;
|
||||||
/// 'normal'
|
/// 'normal'
|
||||||
const NORMAL = structs::NS_STYLE_ALIGN_NORMAL as u8;
|
const NORMAL = 1;
|
||||||
/// 'start'
|
/// 'start'
|
||||||
const START = structs::NS_STYLE_ALIGN_START as u8;
|
const START = 2;
|
||||||
/// 'end'
|
/// 'end'
|
||||||
const END = structs::NS_STYLE_ALIGN_END as u8;
|
const END = 3;
|
||||||
/// 'flex-start'
|
/// 'flex-start'
|
||||||
const FLEX_START = structs::NS_STYLE_ALIGN_FLEX_START as u8;
|
const FLEX_START = 4;
|
||||||
/// 'flex-end'
|
/// 'flex-end'
|
||||||
const FLEX_END = structs::NS_STYLE_ALIGN_FLEX_END as u8;
|
const FLEX_END = 5;
|
||||||
/// 'center'
|
/// 'center'
|
||||||
const CENTER = structs::NS_STYLE_ALIGN_CENTER as u8;
|
const CENTER = 6;
|
||||||
/// 'left'
|
/// 'left'
|
||||||
const LEFT = structs::NS_STYLE_ALIGN_LEFT as u8;
|
const LEFT = 7;
|
||||||
/// 'right'
|
/// 'right'
|
||||||
const RIGHT = structs::NS_STYLE_ALIGN_RIGHT as u8;
|
const RIGHT = 8;
|
||||||
/// 'baseline'
|
/// 'baseline'
|
||||||
const BASELINE = structs::NS_STYLE_ALIGN_BASELINE as u8;
|
const BASELINE = 9;
|
||||||
/// 'last-baseline'
|
/// 'last-baseline'
|
||||||
const LAST_BASELINE = structs::NS_STYLE_ALIGN_LAST_BASELINE as u8;
|
const LAST_BASELINE = 10;
|
||||||
/// 'stretch'
|
/// 'stretch'
|
||||||
const STRETCH = structs::NS_STYLE_ALIGN_STRETCH as u8;
|
const STRETCH = 11;
|
||||||
/// 'self-start'
|
/// 'self-start'
|
||||||
const SELF_START = structs::NS_STYLE_ALIGN_SELF_START as u8;
|
const SELF_START = 12;
|
||||||
/// 'self-end'
|
/// 'self-end'
|
||||||
const SELF_END = structs::NS_STYLE_ALIGN_SELF_END as u8;
|
const SELF_END = 13;
|
||||||
/// 'space-between'
|
/// 'space-between'
|
||||||
const SPACE_BETWEEN = structs::NS_STYLE_ALIGN_SPACE_BETWEEN as u8;
|
const SPACE_BETWEEN = 14;
|
||||||
/// 'space-around'
|
/// 'space-around'
|
||||||
const SPACE_AROUND = structs::NS_STYLE_ALIGN_SPACE_AROUND as u8;
|
const SPACE_AROUND = 15;
|
||||||
/// 'space-evenly'
|
/// 'space-evenly'
|
||||||
const SPACE_EVENLY = structs::NS_STYLE_ALIGN_SPACE_EVENLY as u8;
|
const SPACE_EVENLY = 16;
|
||||||
|
|
||||||
// Additional flags stored in the upper bits:
|
// Additional flags stored in the upper bits:
|
||||||
/// 'legacy' (mutually exclusive w. SAFE & UNSAFE)
|
/// 'legacy' (mutually exclusive w. SAFE & UNSAFE)
|
||||||
const LEGACY = structs::NS_STYLE_ALIGN_LEGACY as u8;
|
const LEGACY = 1 << 5;
|
||||||
/// 'safe'
|
/// 'safe'
|
||||||
const SAFE = structs::NS_STYLE_ALIGN_SAFE as u8;
|
const SAFE = 1 << 6;
|
||||||
/// 'unsafe' (mutually exclusive w. SAFE)
|
/// 'unsafe' (mutually exclusive w. SAFE)
|
||||||
const UNSAFE = structs::NS_STYLE_ALIGN_UNSAFE as u8;
|
const UNSAFE = 1 << 7;
|
||||||
|
|
||||||
/// Mask for the additional flags above.
|
/// Mask for the additional flags above.
|
||||||
const FLAG_BITS = structs::NS_STYLE_ALIGN_FLAG_BITS as u8;
|
const FLAG_BITS = 0b11100000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,6 +144,7 @@ pub enum AxisDirection {
|
||||||
ToResolvedValue,
|
ToResolvedValue,
|
||||||
ToShmem,
|
ToShmem,
|
||||||
)]
|
)]
|
||||||
|
#[repr(C)]
|
||||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||||
pub struct ContentDistribution {
|
pub struct ContentDistribution {
|
||||||
primary: AlignFlags,
|
primary: AlignFlags,
|
||||||
|
@ -270,6 +269,7 @@ impl ContentDistribution {
|
||||||
ToResolvedValue,
|
ToResolvedValue,
|
||||||
ToShmem,
|
ToShmem,
|
||||||
)]
|
)]
|
||||||
|
#[repr(transparent)]
|
||||||
pub struct AlignContent(pub ContentDistribution);
|
pub struct AlignContent(pub ContentDistribution);
|
||||||
|
|
||||||
impl Parse for AlignContent {
|
impl Parse for AlignContent {
|
||||||
|
@ -292,20 +292,6 @@ impl SpecifiedValueInfo for AlignContent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
impl From<u16> for AlignContent {
|
|
||||||
fn from(bits: u16) -> Self {
|
|
||||||
AlignContent(ContentDistribution::from_bits(bits))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
impl From<AlignContent> for u16 {
|
|
||||||
fn from(v: AlignContent) -> u16 {
|
|
||||||
v.0.as_bits()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Value for the `justify-content` property.
|
/// Value for the `justify-content` property.
|
||||||
///
|
///
|
||||||
/// <https://drafts.csswg.org/css-align/#propdef-justify-content>
|
/// <https://drafts.csswg.org/css-align/#propdef-justify-content>
|
||||||
|
@ -321,6 +307,7 @@ impl From<AlignContent> for u16 {
|
||||||
ToResolvedValue,
|
ToResolvedValue,
|
||||||
ToShmem,
|
ToShmem,
|
||||||
)]
|
)]
|
||||||
|
#[repr(transparent)]
|
||||||
pub struct JustifyContent(pub ContentDistribution);
|
pub struct JustifyContent(pub ContentDistribution);
|
||||||
|
|
||||||
impl Parse for JustifyContent {
|
impl Parse for JustifyContent {
|
||||||
|
@ -370,6 +357,7 @@ impl From<JustifyContent> for u16 {
|
||||||
ToResolvedValue,
|
ToResolvedValue,
|
||||||
ToShmem,
|
ToShmem,
|
||||||
)]
|
)]
|
||||||
|
#[repr(transparent)]
|
||||||
pub struct SelfAlignment(pub AlignFlags);
|
pub struct SelfAlignment(pub AlignFlags);
|
||||||
|
|
||||||
impl SelfAlignment {
|
impl SelfAlignment {
|
||||||
|
@ -441,6 +429,7 @@ impl SelfAlignment {
|
||||||
ToResolvedValue,
|
ToResolvedValue,
|
||||||
ToShmem,
|
ToShmem,
|
||||||
)]
|
)]
|
||||||
|
#[repr(C)]
|
||||||
pub struct AlignSelf(pub SelfAlignment);
|
pub struct AlignSelf(pub SelfAlignment);
|
||||||
|
|
||||||
impl Parse for AlignSelf {
|
impl Parse for AlignSelf {
|
||||||
|
@ -463,18 +452,6 @@ impl SpecifiedValueInfo for AlignSelf {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<u8> for AlignSelf {
|
|
||||||
fn from(bits: u8) -> Self {
|
|
||||||
AlignSelf(SelfAlignment(AlignFlags::from_bits_truncate(bits)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<AlignSelf> for u8 {
|
|
||||||
fn from(align: AlignSelf) -> u8 {
|
|
||||||
(align.0).0.bits()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The specified value of the justify-self property.
|
/// The specified value of the justify-self property.
|
||||||
///
|
///
|
||||||
/// <https://drafts.csswg.org/css-align/#propdef-justify-self>
|
/// <https://drafts.csswg.org/css-align/#propdef-justify-self>
|
||||||
|
@ -490,6 +467,7 @@ impl From<AlignSelf> for u8 {
|
||||||
ToResolvedValue,
|
ToResolvedValue,
|
||||||
ToShmem,
|
ToShmem,
|
||||||
)]
|
)]
|
||||||
|
#[repr(C)]
|
||||||
pub struct JustifySelf(pub SelfAlignment);
|
pub struct JustifySelf(pub SelfAlignment);
|
||||||
|
|
||||||
impl Parse for JustifySelf {
|
impl Parse for JustifySelf {
|
||||||
|
@ -512,18 +490,6 @@ impl SpecifiedValueInfo for JustifySelf {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<u8> for JustifySelf {
|
|
||||||
fn from(bits: u8) -> Self {
|
|
||||||
JustifySelf(SelfAlignment(AlignFlags::from_bits_truncate(bits)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<JustifySelf> for u8 {
|
|
||||||
fn from(justify: JustifySelf) -> u8 {
|
|
||||||
(justify.0).0.bits()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Value of the `align-items` property
|
/// Value of the `align-items` property
|
||||||
///
|
///
|
||||||
/// <https://drafts.csswg.org/css-align/#propdef-align-items>
|
/// <https://drafts.csswg.org/css-align/#propdef-align-items>
|
||||||
|
@ -539,6 +505,7 @@ impl From<JustifySelf> for u8 {
|
||||||
ToResolvedValue,
|
ToResolvedValue,
|
||||||
ToShmem,
|
ToShmem,
|
||||||
)]
|
)]
|
||||||
|
#[repr(C)]
|
||||||
pub struct AlignItems(pub AlignFlags);
|
pub struct AlignItems(pub AlignFlags);
|
||||||
|
|
||||||
impl AlignItems {
|
impl AlignItems {
|
||||||
|
@ -590,6 +557,7 @@ impl SpecifiedValueInfo for AlignItems {
|
||||||
///
|
///
|
||||||
/// <https://drafts.csswg.org/css-align/#justify-items-property>
|
/// <https://drafts.csswg.org/css-align/#justify-items-property>
|
||||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToCss, ToShmem)]
|
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToCss, ToShmem)]
|
||||||
|
#[repr(C)]
|
||||||
pub struct JustifyItems(pub AlignFlags);
|
pub struct JustifyItems(pub AlignFlags);
|
||||||
|
|
||||||
impl JustifyItems {
|
impl JustifyItems {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue