Bug 1855617 - Upgrade stylo to bitflags 2. r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D189451
This commit is contained in:
Mike Hommey 2023-09-28 08:01:16 +00:00
parent 61c6eccd2a
commit ad5c3990ad
47 changed files with 202 additions and 159 deletions

8
Cargo.lock generated
View File

@ -1417,7 +1417,7 @@ dependencies = [
name = "dom"
version = "0.1.0"
dependencies = [
"bitflags 1.999.999",
"bitflags 2.4.0",
]
[[package]]
@ -4820,7 +4820,7 @@ dependencies = [
name = "selectors"
version = "0.22.0"
dependencies = [
"bitflags 1.999.999",
"bitflags 2.4.0",
"cssparser",
"derive_more 0.99.999",
"fxhash",
@ -5187,7 +5187,7 @@ dependencies = [
"arrayvec",
"atomic_refcell",
"bindgen 0.66.1",
"bitflags 1.999.999",
"bitflags 2.4.0",
"byteorder",
"cssparser",
"derive_more 0.99.999",
@ -5254,7 +5254,7 @@ name = "style_traits"
version = "0.0.1"
dependencies = [
"app_units",
"bitflags 1.999.999",
"bitflags 2.4.0",
"cssparser",
"euclid",
"lazy_static",

View File

@ -11,4 +11,4 @@ license = "MPL-2.0"
path = "lib.rs"
[dependencies]
bitflags = "1.0"
bitflags = "2"

View File

@ -9,6 +9,7 @@ use bitflags::bitflags;
bitflags! {
/// Event-based element states.
#[repr(C)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ElementState: u64 {
/// The mouse is down on this element.
/// <https://html.spec.whatwg.org/multipage/#selector-active>
@ -147,6 +148,7 @@ bitflags! {
bitflags! {
/// Event-based document states.
#[repr(C)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct DocumentState: u64 {
/// Window activation status
const WINDOW_INACTIVE = 1 << 0;

View File

@ -1256,13 +1256,13 @@ static inline void MapLangAttributeInto(MappedDeclarationsBuilder& aBuilder) {
const nsAtom* lang = langValue->GetAtomValue();
if (nsStyleUtil::MatchesLanguagePrefix(lang, u"zh")) {
aBuilder.SetKeywordValue(eCSSProperty_text_emphasis_position,
StyleTextEmphasisPosition::UNDER.bits);
StyleTextEmphasisPosition::UNDER._0);
} else if (nsStyleUtil::MatchesLanguagePrefix(lang, u"ja") ||
nsStyleUtil::MatchesLanguagePrefix(lang, u"mn")) {
// This branch is currently no part of the spec.
// See bug 1040668 comment 69 and comment 75.
aBuilder.SetKeywordValue(eCSSProperty_text_emphasis_position,
StyleTextEmphasisPosition::OVER.bits);
StyleTextEmphasisPosition::OVER._0);
}
}
}

View File

@ -179,21 +179,21 @@ class WritingMode {
* Return the absolute inline flow direction as an InlineDir
*/
InlineDir GetInlineDir() const {
return InlineDir(mWritingMode.bits & eInlineMask);
return InlineDir(mWritingMode._0 & eInlineMask);
}
/**
* Return the absolute block flow direction as a BlockDir
*/
BlockDir GetBlockDir() const {
return BlockDir(mWritingMode.bits & eBlockMask);
return BlockDir(mWritingMode._0 & eBlockMask);
}
/**
* Return the line-relative inline flow direction as a BidiDir
*/
BidiDir GetBidiDir() const {
return BidiDir((mWritingMode & StyleWritingMode::RTL).bits);
return BidiDir((mWritingMode & StyleWritingMode::RTL)._0);
}
/**
@ -303,10 +303,9 @@ class WritingMode {
// StyleWritingMode::VERTICAL_SIDEWAYS or StyleWritingMode::TEXT_SIDEWAYS
// flags.
WritingMode IgnoreSideways() const {
return WritingMode(
mWritingMode.bits &
~(StyleWritingMode::VERTICAL_SIDEWAYS | StyleWritingMode::TEXT_SIDEWAYS)
.bits);
return WritingMode(mWritingMode._0 & ~(StyleWritingMode::VERTICAL_SIDEWAYS |
StyleWritingMode::TEXT_SIDEWAYS)
._0);
}
#endif
@ -343,7 +342,7 @@ class WritingMode {
// and hypothetical) values. But this is fine; we only need to
// distinguish between vertical and horizontal in
// PhysicalAxisForLogicalAxis.
const auto wm = (mWritingMode & StyleWritingMode::VERTICAL).bits;
const auto wm = (mWritingMode & StyleWritingMode::VERTICAL)._0;
return PhysicalAxisForLogicalAxis(wm, aAxis);
}
@ -404,12 +403,12 @@ class WritingMode {
// StyleWritingMode::INLINE_REVERSED, StyleWritingMode::VERTICAL_LR and
// StyleWritingMode::LINE_INVERTED bits. Use these four bits to index into
// kLogicalInlineSides.
MOZ_ASSERT(StyleWritingMode::VERTICAL.bits == 0x01 &&
StyleWritingMode::INLINE_REVERSED.bits == 0x02 &&
StyleWritingMode::VERTICAL_LR.bits == 0x04 &&
StyleWritingMode::LINE_INVERTED.bits == 0x08,
MOZ_ASSERT(StyleWritingMode::VERTICAL._0 == 0x01 &&
StyleWritingMode::INLINE_REVERSED._0 == 0x02 &&
StyleWritingMode::VERTICAL_LR._0 == 0x04 &&
StyleWritingMode::LINE_INVERTED._0 == 0x08,
"unexpected mask values");
int index = mWritingMode.bits & 0x0F;
int index = mWritingMode._0 & 0x0F;
return kLogicalInlineSides[index][aEdge];
}
@ -419,12 +418,12 @@ class WritingMode {
*/
mozilla::Side PhysicalSide(LogicalSide aSide) const {
if (IsBlock(aSide)) {
MOZ_ASSERT(StyleWritingMode::VERTICAL.bits == 0x01 &&
StyleWritingMode::VERTICAL_LR.bits == 0x04,
MOZ_ASSERT(StyleWritingMode::VERTICAL._0 == 0x01 &&
StyleWritingMode::VERTICAL_LR._0 == 0x04,
"unexpected mask values");
const uint8_t wm =
((mWritingMode & StyleWritingMode::VERTICAL_LR).bits >> 1) |
(mWritingMode & StyleWritingMode::VERTICAL).bits;
((mWritingMode & StyleWritingMode::VERTICAL_LR)._0 >> 1) |
(mWritingMode & StyleWritingMode::VERTICAL)._0;
return PhysicalSideForBlockAxis(wm, GetEdge(aSide));
}
@ -481,12 +480,12 @@ class WritingMode {
};
// clang-format on
MOZ_ASSERT(StyleWritingMode::VERTICAL.bits == 0x01 &&
StyleWritingMode::INLINE_REVERSED.bits == 0x02 &&
StyleWritingMode::VERTICAL_LR.bits == 0x04 &&
StyleWritingMode::LINE_INVERTED.bits == 0x08,
MOZ_ASSERT(StyleWritingMode::VERTICAL._0 == 0x01 &&
StyleWritingMode::INLINE_REVERSED._0 == 0x02 &&
StyleWritingMode::VERTICAL_LR._0 == 0x04 &&
StyleWritingMode::LINE_INVERTED._0 == 0x08,
"unexpected mask values");
int index = mWritingMode.bits & 0x0F;
int index = mWritingMode._0 & 0x0F;
return kPhysicalToLogicalSides[index][aSide];
}
@ -586,7 +585,7 @@ class WritingMode {
return myStartSide == otherWMStartSide;
}
uint8_t GetBits() const { return mWritingMode.bits; }
uint8_t GetBits() const { return mWritingMode._0; }
private:
friend class LogicalPoint;

View File

@ -18,7 +18,7 @@ path = "lib.rs"
bench = []
[dependencies]
bitflags = "1.0"
bitflags = "2"
cssparser = "0.33"
derive_more = { version = "0.99", default-features = false, features = ["add", "add_assign"] }
fxhash = "0.2"

View File

@ -166,10 +166,12 @@ fn split_from_end<T>(s: &[T], at: usize) -> (&[T], &[T]) {
s.split_at(s.len() - at)
}
/// Flags that indicate at which point of parsing a selector are we.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, ToShmem)]
pub (crate) struct SelectorFlags(u8);
bitflags! {
/// Flags that indicate at which point of parsing a selector are we.
#[derive(Default, ToShmem)]
pub (crate) struct SelectorFlags : u8 {
impl SelectorFlags: u8 {
const HAS_PSEUDO = 1 << 0;
const HAS_SLOTTED = 1 << 1;
const HAS_PART = 1 << 2;

View File

@ -28,6 +28,7 @@ pub static RECOMMENDED_SELECTOR_BLOOM_FILTER_SIZE: usize = 4096;
bitflags! {
/// Set of flags that are set on either the element or its parent (depending
/// on the flag) if the element could potentially match a selector.
#[derive(Clone, Copy)]
pub struct ElementSelectorFlags: usize {
/// When a child is added or removed from the parent, all the children
/// must be restyled, because they may match :nth-last-child,

View File

@ -77,6 +77,7 @@ fn to_ascii_lowercase(s: &str) -> Cow<str> {
bitflags! {
/// Flags that indicate at which point of parsing a selector are we.
#[derive(Copy, Clone)]
struct SelectorParsingState: u8 {
/// Whether we should avoid adding default namespaces to selectors that
/// aren't type or universal selectors.
@ -1667,6 +1668,7 @@ pub struct RelativeSelector<Impl: SelectorImpl> {
bitflags! {
/// Composition of combinators in a given selector, not traversing selectors of pseudoclasses.
#[derive(Clone, Debug, Eq, PartialEq)]
struct CombinatorComposition: u8 {
const DESCENDANTS = 1 << 0;
const SIBLINGS = 1 << 1;

View File

@ -70,7 +70,7 @@ pub trait SelectorVisitor: Sized {
bitflags! {
/// The kinds of components the visitor is visiting the selector list of, if any
#[derive(Default)]
#[derive(Clone, Copy, Default)]
pub struct SelectorListKind: u8 {
/// The visitor is inside :not(..)
const NEGATION = 1 << 0;

View File

@ -30,7 +30,7 @@ gecko_refcount_logging = []
app_units = "0.7"
arrayvec = "0.7"
atomic_refcell = "0.1"
bitflags = "1.0"
bitflags = "2"
byteorder = "1.0"
cssparser = "0.33"
derive_more = { version = "0.99", default-features = false, features = ["add", "add_assign", "deref", "deref_mut", "from"] }

View File

@ -165,11 +165,12 @@ impl ColorSpace {
}
}
/// Flags used when serializing colors.
#[derive(Clone, Copy, Debug, Default, MallocSizeOf, PartialEq, ToShmem)]
#[repr(C)]
pub struct ColorFlags(u8);
bitflags! {
/// Flags used when serializing colors.
#[derive(Default, MallocSizeOf, ToShmem)]
#[repr(C)]
pub struct ColorFlags : u8 {
impl ColorFlags : u8 {
/// Marks that this color is in the legacy color format. This flag is
/// only valid for the `Srgb` color space.
const IS_LEGACY_SRGB = 1 << 0;

View File

@ -22,7 +22,7 @@ use std::ops::{Deref, DerefMut};
bitflags! {
/// Various flags stored on ElementData.
#[derive(Default)]
#[derive(Debug, Default)]
pub struct ElementDataFlags: u8 {
/// Whether the styles changed for this restyle.
const WAS_RESTYLED = 1 << 0;

View File

@ -94,12 +94,13 @@ pub enum FontFaceSourceFormatKeyword {
Unknown,
}
/// Flags for the @font-face tech() function, indicating font technologies
/// required by the resource.
#[derive(Clone, Copy, Debug, Eq, PartialEq, ToShmem)]
#[repr(C)]
pub struct FontFaceSourceTechFlags(u16);
bitflags! {
/// Flags for the @font-face tech() function, indicating font technologies
/// required by the resource.
#[derive(ToShmem)]
#[repr(C)]
pub struct FontFaceSourceTechFlags: u16 {
impl FontFaceSourceTechFlags: u16 {
/// Font requires OpenType feature support.
const FEATURES_OPENTYPE = 1 << 0;
/// Font requires Apple Advanced Typography support.

View File

@ -26,6 +26,7 @@ pub use crate::gecko::snapshot::SnapshotMap;
bitflags! {
// See NonTSPseudoClass::is_enabled_in()
#[derive(Copy, Clone)]
struct NonTSPseudoClassFlag: u8 {
const PSEUDO_CLASS_ENABLED_IN_UA_SHEETS = 1 << 0;
const PSEUDO_CLASS_ENABLED_IN_CHROME = 1 << 1;

View File

@ -106,7 +106,7 @@ impl ElementSnapshot for GeckoElementSnapshot {
fn state(&self) -> Option<ElementState> {
if self.has_any(Flags::State) {
Some(ElementState::from_bits_truncate(self.mState))
Some(ElementState::from_bits_retain(self.mState))
} else {
None
}

View File

@ -154,6 +154,7 @@ unsafe impl Send for LoadDataKey {}
bitflags! {
/// Various bits of mutable state that are kept for image loads.
#[derive(Debug)]
#[repr(C)]
pub struct LoadDataFlags: u8 {
/// Whether we tried to resolve the uri at least once.

View File

@ -714,7 +714,7 @@ impl<'le> GeckoElement<'le> {
#[inline]
fn document_state(&self) -> DocumentState {
DocumentState::from_bits_truncate(self.as_node().owner_doc().0.mDocumentState.bits)
DocumentState::from_bits_retain(self.as_node().owner_doc().0.mDocumentState.bits)
}
#[inline]
@ -1205,7 +1205,7 @@ impl<'le> TElement for GeckoElement<'le> {
#[inline]
fn state(&self) -> ElementState {
ElementState::from_bits_truncate(self.state_internal())
ElementState::from_bits_retain(self.state_internal())
}
#[inline]

View File

@ -20,7 +20,7 @@ pub fn assert_flags_match() {
impl From<OriginFlags> for OriginSet {
fn from(flags: OriginFlags) -> Self {
Self::from_bits_truncate(flags.0)
Self::from_bits_retain(flags.0)
}
}

View File

@ -277,11 +277,13 @@ pub struct InvalidationMap {
pub other_attribute_affecting_selectors: LocalNameDependencyMap,
}
/// Tree-structural pseudoclasses that we care about for (Relative selector) invalidation.
/// Specifically, we need to store information on ones that don't generate the inner selector.
#[derive(Clone, Copy, Debug, MallocSizeOf)]
pub struct TSStateForInvalidation(u8);
bitflags! {
/// Tree-structural pseudoclasses that we care about for (Relative selector) invalidation.
/// Specifically, we need to store information on ones that don't generate the inner selector.
#[derive(MallocSizeOf)]
pub struct TSStateForInvalidation : u8 {
impl TSStateForInvalidation : u8 {
/// :empty
const EMPTY = 1 << 0;
/// :nth, :first-child, etc, without of.

View File

@ -9,6 +9,7 @@ use crate::traversal_flags::TraversalFlags;
bitflags! {
/// The kind of restyle we need to do for a given element.
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct RestyleHint: u16 {
/// Do a selector match of the element.
const RESTYLE_SELF = 1 << 0;

View File

@ -24,10 +24,11 @@ pub enum InlineBaseDirection {
}
// TODO: improve the readability of the WritingMode serialization, refer to the Debug:fmt()
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, Serialize)]
#[repr(C)]
pub struct WritingMode(u8);
bitflags!(
#[derive(MallocSizeOf, Serialize)]
#[repr(C)]
pub struct WritingMode: u8 {
impl WritingMode: u8 {
/// A vertical writing mode; writing-mode is vertical-rl,
/// vertical-lr, sideways-lr, or sideways-rl.
const VERTICAL = 1 << 0;

View File

@ -12,6 +12,7 @@ bitflags! {
/// If we ever want to add some flags that shouldn't inherit for them,
/// we might want to add a function to handle this.
#[repr(C)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ComputedValueFlags: u32 {
/// Whether the style or any of the ancestors has a text-decoration-line
/// property that should get propagated to descendants.

View File

@ -1193,6 +1193,7 @@ impl CSSWideKeyword {
bitflags! {
/// A set of flags for properties.
#[derive(Clone, Copy)]
pub struct PropertyFlags: u16 {
/// This longhand property applies to ::first-letter.
const APPLIES_TO_FIRST_LETTER = 1 << 1;
@ -1429,7 +1430,7 @@ impl LonghandId {
0,
% endfor
];
PropertyFlags::from_bits_truncate(FLAGS[self as usize])
PropertyFlags::from_bits_retain(FLAGS[self as usize])
}
/// Returns true if the property is one that is ignored when document
@ -1604,7 +1605,7 @@ impl ShorthandId {
0,
% endfor
];
PropertyFlags::from_bits_truncate(FLAGS[self as usize])
PropertyFlags::from_bits_retain(FLAGS[self as usize])
}
/// Returns whether this property is a legacy shorthand.

View File

@ -101,11 +101,12 @@ macro_rules! keyword_evaluator {
}};
}
/// Different flags or toggles that change how a expression is parsed or
/// evaluated.
#[derive(Clone, Copy, Debug, ToShmem)]
pub struct FeatureFlags(u8);
bitflags! {
/// Different flags or toggles that change how a expression is parsed or
/// evaluated.
#[derive(ToShmem)]
pub struct FeatureFlags : u8 {
impl FeatureFlags : u8 {
/// The feature should only be parsed in chrome and ua sheets.
const CHROME_AND_UA_ONLY = 1 << 0;
/// The feature requires a -webkit- prefix.

View File

@ -40,7 +40,7 @@ impl Default for PrecomputedHasher {
///
/// We can avoid selector-matching those global rules for all elements without
/// these pseudo-class states.
const RARE_PSEUDO_CLASS_STATES: ElementState = ElementState::from_bits_truncate(
const RARE_PSEUDO_CLASS_STATES: ElementState = ElementState::from_bits_retain(
ElementState::FULLSCREEN.bits() |
ElementState::VISITED_OR_UNVISITED.bits() |
ElementState::URLTARGET.bits() |

View File

@ -56,10 +56,11 @@ impl Origin {
}
}
/// A set of origins. This is equivalent to Gecko's OriginFlags.
#[derive(Clone, Copy, PartialEq, MallocSizeOf)]
pub struct OriginSet(u8);
bitflags! {
/// A set of origins. This is equivalent to Gecko's OriginFlags.
#[derive(MallocSizeOf)]
pub struct OriginSet: u8 {
impl OriginSet: u8 {
/// <https://drafts.csswg.org/css-cascade/#cascade-origin-user-agent>
const ORIGIN_USER_AGENT = Origin::UserAgent as u8;
/// <https://drafts.csswg.org/css-cascade/#cascade-origin-user>
@ -85,7 +86,7 @@ impl OriginSet {
impl From<Origin> for OriginSet {
fn from(origin: Origin) -> Self {
Self::from_bits_truncate(origin as u8)
Self::from_bits_retain(origin as u8)
}
}

View File

@ -83,6 +83,7 @@ bitflags! {
/// page-rule applies.
///
/// https://drafts.csswg.org/css-page-3/#page-selectors
#[derive(Clone, Copy)]
#[repr(C)]
pub struct PagePseudoClassFlags : u8 {
/// No pseudo-classes

View File

@ -11,6 +11,7 @@ use std::cell::RefCell;
bitflags! {
/// A thread state flag, used for multiple assertions.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ThreadState: u32 {
/// Whether we're in a script thread.
const SCRIPT = 0x01;

View File

@ -10,6 +10,7 @@
bitflags! {
/// Flags that control the traversal process.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct TraversalFlags: u32 {
/// Traverse only elements for animation restyles.
const AnimationOnly = 1 << 0;

View File

@ -217,6 +217,7 @@ bitflags! {
/// This is used as a hint for the parser to fast-reject invalid
/// expressions. Numbers are always allowed because they multiply other
/// units.
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct CalcUnits: u8 {
/// <length>
const LENGTH = 1 << 0;

View File

@ -23,11 +23,12 @@ pub enum GenericColor<Percentage> {
ColorMix(Box<GenericColorMix<Self, Percentage>>),
}
/// Flags used to modify the calculation of a color mix result.
#[derive(Clone, Copy, Debug, Default, MallocSizeOf, PartialEq, ToShmem)]
#[repr(C)]
pub struct ColorMixFlags(u8);
bitflags! {
/// Flags used to modify the calculation of a color mix result.
#[derive(MallocSizeOf, ToShmem)]
#[repr(C)]
pub struct ColorMixFlags : u8 {
impl ColorMixFlags : u8 {
/// Normalize the weights of the mix.
const NORMALIZE_WEIGHTS = 1 << 0;
/// The result should always be converted to the modern color syntax.

View File

@ -155,11 +155,12 @@ impl<I: style_traits::ToCss, R: style_traits::ToCss> ToCss for GenericImageSetIt
pub use self::GenericImageSet as ImageSet;
pub use self::GenericImageSetItem as ImageSetItem;
/// State flags stored on each variant of a Gradient.
#[derive(Clone, Copy, Debug, Default, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem)]
#[repr(C)]
pub struct GradientFlags(u8);
bitflags! {
/// State flags stored on each variant of a Gradient.
#[derive(MallocSizeOf, ToComputedValue, ToResolvedValue, ToShmem)]
#[repr(C)]
pub struct GradientFlags: u8 {
impl GradientFlags: u8 {
/// Set if this is a repeating gradient.
const REPEATING = 1 << 0;
/// Set if the color interpolation method matches the default for the items.

View File

@ -11,11 +11,12 @@ use cssparser::Parser;
use std::fmt::{self, Write};
use style_traits::{CssWriter, KeywordsCollectFn, ParseError, SpecifiedValueInfo, ToCss};
/// Constants shared by multiple CSS Box Alignment properties
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem)]
#[repr(C)]
pub struct AlignFlags(u8);
bitflags! {
/// Constants shared by multiple CSS Box Alignment properties
#[derive(MallocSizeOf, ToComputedValue, ToResolvedValue, ToShmem)]
#[repr(C)]
pub struct AlignFlags: u8 {
impl AlignFlags: u8 {
// Enumeration stored in the lower 5 bits:
/// {align,justify}-{content,items,self}: 'auto'
const AUTO = 0;

View File

@ -146,6 +146,7 @@ bitflags! {
/// we use the bitflags to choose the supported basic shapes for each property at the parse
/// time.
/// https://github.com/w3c/csswg-drafts/issues/7390
#[derive(Clone, Copy)]
#[repr(C)]
pub struct AllowedBasicShapes: u8 {
/// inset().

View File

@ -1020,11 +1020,12 @@ impl WillChange {
}
}
/// The change bits that we care about.
#[derive(Clone, Copy, Debug, Default, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToResolvedValue, ToShmem)]
#[repr(C)]
pub struct WillChangeBits(u16);
bitflags! {
/// The change bits that we care about.
#[derive(Default, MallocSizeOf, SpecifiedValueInfo, ToComputedValue, ToResolvedValue, ToShmem)]
#[repr(C)]
pub struct WillChangeBits: u16 {
impl WillChangeBits: u16 {
/// Whether a property which can create a stacking context **on any
/// box** will change.
const STACKING_CONTEXT_UNCONDITIONAL = 1 << 0;
@ -1131,12 +1132,13 @@ impl Parse for WillChange {
}
}
/// Values for the `touch-action` property.
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss, ToResolvedValue, ToShmem)]
#[css(bitflags(single = "none,auto,manipulation", mixed = "pan-x,pan-y,pinch-zoom"))]
#[repr(C)]
pub struct TouchAction(u8);
bitflags! {
/// Values for the `touch-action` property.
#[derive(MallocSizeOf, Parse, SpecifiedValueInfo, ToComputedValue, ToCss, ToResolvedValue, ToShmem)]
#[css(bitflags(single = "none,auto,manipulation", mixed = "pan-x,pan-y,pinch-zoom"))]
#[repr(C)]
pub struct TouchAction: u8 {
impl TouchAction: u8 {
/// `none` variant
const NONE = 1 << 0;
/// `auto` variant
@ -1160,12 +1162,13 @@ impl TouchAction {
}
}
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss, ToResolvedValue, ToShmem)]
#[css(bitflags(single = "none,strict,content", mixed="size,layout,style,paint,inline-size", overlapping_bits))]
#[repr(C)]
/// Constants for contain: https://drafts.csswg.org/css-contain/#contain-property
pub struct Contain(u8);
bitflags! {
#[derive(MallocSizeOf, Parse, SpecifiedValueInfo, ToComputedValue, ToCss, ToResolvedValue, ToShmem)]
#[css(bitflags(single = "none,strict,content", mixed="size,layout,style,paint,inline-size", overlapping_bits))]
#[repr(C)]
/// Constants for contain: https://drafts.csswg.org/css-contain/#contain-property
pub struct Contain: u8 {
impl Contain: u8 {
/// `none` variant, just for convenience.
const NONE = 0;
/// `inline-size` variant, turns on single-axis inline size containment
@ -1854,13 +1857,14 @@ impl Overflow {
}
}
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss, ToResolvedValue, ToShmem)]
#[repr(C)]
#[css(bitflags(single = "auto", mixed = "stable,both-edges", validate_mixed="Self::has_stable"))]
/// Values for scrollbar-gutter:
/// <https://drafts.csswg.org/css-overflow-3/#scrollbar-gutter-property>
pub struct ScrollbarGutter(u8);
bitflags! {
#[derive(MallocSizeOf, Parse, SpecifiedValueInfo, ToComputedValue, ToCss, ToResolvedValue, ToShmem)]
#[repr(C)]
#[css(bitflags(single = "auto", mixed = "stable,both-edges", validate_mixed="Self::has_stable"))]
/// Values for scrollbar-gutter:
/// <https://drafts.csswg.org/css-overflow-3/#scrollbar-gutter-property>
pub struct ScrollbarGutter: u8 {
impl ScrollbarGutter: u8 {
/// `auto` variant. Just for convenience if there is no flag set.
const AUTO = 0;
/// `stable` variant.

View File

@ -1033,13 +1033,14 @@ impl Parse for CaretColor {
}
}
/// Various flags to represent the color-scheme property in an efficient
/// way.
#[derive(Clone, Copy, Debug, Default, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToResolvedValue, ToShmem)]
#[repr(C)]
#[value_info(other_values = "light,dark,only")]
pub struct ColorSchemeFlags(u8);
bitflags! {
/// Various flags to represent the color-scheme property in an efficient
/// way.
#[derive(Default, MallocSizeOf, SpecifiedValueInfo, ToComputedValue, ToResolvedValue, ToShmem)]
#[repr(C)]
#[value_info(other_values = "light,dark,only")]
pub struct ColorSchemeFlags: u8 {
impl ColorSchemeFlags: u8 {
/// Whether the author specified `light`.
const LIGHT = 1 << 0;
/// Whether the author specified `dark`.

View File

@ -1020,6 +1020,7 @@ impl Parse for FontSize {
}
bitflags! {
#[derive(Clone, Copy)]
/// Flags of variant alternates in bit
struct VariantAlternatesParsingFlags: u8 {
/// None of variant alternates enabled
@ -1245,10 +1246,11 @@ macro_rules! impl_variant_east_asian {
$ident:ident / $css:expr => $gecko:ident = $value:expr,
)+
} => {
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem)]
/// Variants for east asian variant
pub struct FontVariantEastAsian(u16);
bitflags! {
#[derive(MallocSizeOf, ToComputedValue, ToResolvedValue, ToShmem)]
/// Variants for east asian variant
pub struct FontVariantEastAsian: u16 {
impl FontVariantEastAsian: u16 {
/// None of the features
const NORMAL = 0;
$(
@ -1416,10 +1418,11 @@ macro_rules! impl_variant_ligatures {
$ident:ident / $css:expr => $gecko:ident = $value:expr,
)+
} => {
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem)]
/// Variants of ligatures
pub struct FontVariantLigatures(u16);
bitflags! {
#[derive(MallocSizeOf, ToComputedValue, ToResolvedValue, ToShmem)]
/// Variants of ligatures
pub struct FontVariantLigatures: u16 {
impl FontVariantLigatures: u16 {
/// Specifies that common default features are enabled
const NORMAL = 0;
$(
@ -1594,10 +1597,11 @@ macro_rules! impl_variant_numeric {
$ident:ident / $css:expr => $gecko:ident = $value:expr,
)+
} => {
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem)]
/// Variants of numeric values
pub struct FontVariantNumeric(u8);
bitflags! {
#[derive(MallocSizeOf, ToComputedValue, ToResolvedValue, ToShmem)]
/// Vairants of numeric values
pub struct FontVariantNumeric: u8 {
impl FontVariantNumeric: u8 {
/// None of other variants are enabled.
const NORMAL = 0;
$(

View File

@ -187,6 +187,7 @@ pub enum LineDirection {
pub type EndingShape = generic::EndingShape<NonNegativeLength, NonNegativeLengthPercentage>;
bitflags! {
#[derive(Clone, Copy)]
struct ParseImageFlags: u8 {
const FORBID_NONE = 1 << 0;
const FORBID_IMAGE_SET = 1 << 1;

View File

@ -369,13 +369,14 @@ impl Side for VerticalPositionKeyword {
}
}
/// Controls how the auto-placement algorithm works specifying exactly how auto-placed items
/// get flowed into the grid.
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToResolvedValue, ToShmem)]
#[value_info(other_values = "row,column,dense")]
#[repr(C)]
pub struct GridAutoFlow(u8);
bitflags! {
/// Controls how the auto-placement algorithm works specifying exactly how auto-placed items
/// get flowed into the grid.
#[derive(MallocSizeOf, SpecifiedValueInfo, ToComputedValue, ToResolvedValue, ToShmem)]
#[value_info(other_values = "row,column,dense")]
#[repr(C)]
pub struct GridAutoFlow: u8 {
impl GridAutoFlow: u8 {
/// 'row' - mutually exclusive with 'column'
const ROW = 1 << 0;
/// 'column' - mutually exclusive with 'row'

View File

@ -247,11 +247,12 @@ impl ToCss for SVGPaintOrder {
}
}
/// The context properties we understand.
#[derive(Clone, Copy, Eq, Debug, Default, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToResolvedValue, ToShmem)]
#[repr(C)]
pub struct ContextPropertyBits(u8);
bitflags! {
/// The context properties we understand.
#[derive(Default, MallocSizeOf, SpecifiedValueInfo, ToComputedValue, ToResolvedValue, ToShmem)]
#[repr(C)]
pub struct ContextPropertyBits: u8 {
impl ContextPropertyBits: u8 {
/// `fill`
const FILL = 1 << 0;
/// `stroke`

View File

@ -231,12 +231,13 @@ impl ToComputedValue for TextOverflow {
}
}
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, Parse, Serialize, SpecifiedValueInfo, ToCss, ToComputedValue, ToResolvedValue, ToShmem)]
#[css(bitflags(single = "none", mixed = "underline,overline,line-through,blink"))]
#[repr(C)]
/// Specified keyword values for the text-decoration-line property.
pub struct TextDecorationLine(u8);
bitflags! {
#[derive(MallocSizeOf, Parse, Serialize, SpecifiedValueInfo, ToCss, ToComputedValue, ToResolvedValue, ToShmem)]
#[css(bitflags(single = "none", mixed = "underline,overline,line-through,blink"))]
#[repr(C)]
/// Specified keyword values for the text-decoration-line property.
pub struct TextDecorationLine: u8 {
impl TextDecorationLine: u8 {
/// No text decoration line is specified.
const NONE = 0;
/// underline
@ -414,12 +415,13 @@ pub enum TextTransformCase {
MathAuto,
}
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, Parse, Serialize, SpecifiedValueInfo, ToCss, ToComputedValue, ToResolvedValue, ToShmem)]
#[css(bitflags(mixed = "full-width,full-size-kana"))]
#[repr(C)]
/// Specified keyword values for non-case transforms in the text-transform property. (Non-exclusive.)
pub struct TextTransformOther(u8);
bitflags! {
#[derive(MallocSizeOf, Parse, Serialize, SpecifiedValueInfo, ToCss, ToComputedValue, ToResolvedValue, ToShmem)]
#[css(bitflags(mixed = "full-width,full-size-kana"))]
#[repr(C)]
/// Specified keyword values for non-case transforms in the text-transform property. (Non-exclusive.)
pub struct TextTransformOther: u8 {
impl TextTransformOther: u8 {
/// full-width
const FULL_WIDTH = 1 << 0;
/// full-size-kana
@ -754,13 +756,14 @@ impl Parse for TextEmphasisStyle {
}
}
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, Parse, Serialize, SpecifiedValueInfo, ToCss, ToComputedValue, ToResolvedValue, ToShmem)]
#[repr(C)]
#[css(bitflags(mixed="over,under,left,right", validate_mixed="Self::validate_and_simplify"))]
/// Values for text-emphasis-position:
/// <https://drafts.csswg.org/css-text-decor/#text-emphasis-position-property>
pub struct TextEmphasisPosition(u8);
bitflags! {
#[derive(MallocSizeOf, Parse, Serialize, SpecifiedValueInfo, ToCss, ToComputedValue, ToResolvedValue, ToShmem)]
#[repr(C)]
#[css(bitflags(mixed="over,under,left,right", validate_mixed="Self::validate_and_simplify"))]
/// Values for text-emphasis-position:
/// <https://drafts.csswg.org/css-text-decor/#text-emphasis-position-property>
pub struct TextEmphasisPosition: u8 {
impl TextEmphasisPosition: u8 {
/// Draws marks to the right of the text in vertical writing mode.
const OVER = 1 << 0;
/// Draw marks under the text in horizontal writing mode.
@ -966,15 +969,16 @@ impl TextDecorationLength {
}
}
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToResolvedValue, ToShmem)]
#[value_info(other_values = "auto,from-font,under,left,right")]
#[repr(C)]
/// Specified keyword values for the text-underline-position property.
/// (Non-exclusive, but not all combinations are allowed: the spec grammar gives
/// `auto | [ from-font | under ] || [ left | right ]`.)
/// https://drafts.csswg.org/css-text-decor-4/#text-underline-position-property
pub struct TextUnderlinePosition(u8);
bitflags! {
#[derive(MallocSizeOf, SpecifiedValueInfo, ToComputedValue, ToResolvedValue, ToShmem)]
#[value_info(other_values = "auto,from-font,under,left,right")]
#[repr(C)]
/// Specified keyword values for the text-underline-position property.
/// (Non-exclusive, but not all combinations are allowed: the spec grammar gives
/// `auto | [ from-font | under ] || [ left | right ]`.)
/// https://drafts.csswg.org/css-text-decor-4/#text-underline-position-property
pub struct TextUnderlinePosition: u8 {
impl TextUnderlinePosition: u8 {
/// Use automatic positioning below the alphabetic baseline.
const AUTO = 0;
/// Use underline position from the first available font.

View File

@ -15,7 +15,7 @@ gecko = ["nsstring"]
[dependencies]
app_units = "0.7"
bitflags = "1.0"
bitflags = "2"
cssparser = "0.33"
euclid = "0.22"
lazy_static = "1"

View File

@ -243,6 +243,7 @@ pub enum PropertySyntaxParseError {
bitflags! {
/// The mode to use when parsing values.
#[derive(Clone, Copy, Eq, PartialEq)]
#[repr(C)]
pub struct ParsingMode: u8 {
/// In CSS; lengths must have units, except for zero values, where the unit can be omitted.

View File

@ -305,7 +305,7 @@ pub extern "C" fn Servo_TraverseSubtree(
snapshots: *const ServoElementSnapshotTable,
raw_flags: ServoTraversalFlags,
) -> bool {
let traversal_flags = TraversalFlags::from_bits_truncate(raw_flags);
let traversal_flags = TraversalFlags::from_bits_retain(raw_flags);
debug_assert!(!snapshots.is_null());
let element = GeckoElement(root);
@ -5172,7 +5172,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetKeywordValue(
Clear => get_from_computed::<Clear>(value),
VerticalAlign => VerticalAlign::Keyword(VerticalAlignKeyword::from_u32(value).unwrap()),
TextAlign => get_from_computed::<TextAlign>(value),
TextEmphasisPosition => TextEmphasisPosition::from_bits_truncate(value as u8),
TextEmphasisPosition => TextEmphasisPosition::from_bits_retain(value as u8),
FontSize => {
// We rely on Gecko passing in font-size values (0...7) here.
longhands::font_size::SpecifiedValue::from_html_size(value as u8)
@ -7296,7 +7296,7 @@ pub extern "C" fn Servo_StyleSet_HasStateDependency(
) -> bool {
let element = GeckoElement(element);
let state = ElementState::from_bits_truncate(state);
let state = ElementState::from_bits_retain(state);
let data = raw_data.borrow();
data.stylist
@ -7311,7 +7311,7 @@ pub extern "C" fn Servo_StyleSet_HasNthOfStateDependency(
) -> bool {
let element = GeckoElement(element);
let state = ElementState::from_bits_truncate(state);
let state = ElementState::from_bits_retain(state);
let data = raw_data.borrow();
data.stylist
@ -7330,7 +7330,7 @@ pub extern "C" fn Servo_StyleSet_HasDocumentStateDependency(
raw_data: &PerDocumentStyleData,
state: u64,
) -> bool {
let state = DocumentState::from_bits_truncate(state);
let state = DocumentState::from_bits_retain(state);
let data = raw_data.borrow();
data.stylist.has_document_state_dependency(state)
@ -8099,7 +8099,7 @@ pub unsafe extern "C" fn Servo_InvalidateStyleForDocStateChanges(
let root = GeckoElement(root);
let mut processor = DocumentStateInvalidationProcessor::new(
iter,
DocumentState::from_bits_truncate(states_changed),
DocumentState::from_bits_retain(states_changed),
&mut selector_caches,
root.as_node().owner_doc().quirks_mode(),
);

View File

@ -887,11 +887,11 @@ struct ParamTraits<mozilla::WritingMode> {
using paramType = mozilla::WritingMode;
static void Write(MessageWriter* aWriter, const paramType& aParam) {
WriteParam(aWriter, aParam.mWritingMode.bits);
WriteParam(aWriter, aParam.mWritingMode._0);
}
static bool Read(MessageReader* aReader, paramType* aResult) {
return ReadParam(aReader, &aResult->mWritingMode.bits);
return ReadParam(aReader, &aResult->mWritingMode._0);
}
};

View File

@ -1378,7 +1378,7 @@ ColorScheme LookAndFeel::ColorSchemeForStyle(
StyleColorSchemeFlags style(aFlags);
if (!style) {
style.bits = aDoc.GetColorSchemeBits();
style._0 = aDoc.GetColorSchemeBits();
}
const bool supportsDark = bool(style & StyleColorSchemeFlags::DARK);
const bool supportsLight = bool(style & StyleColorSchemeFlags::LIGHT);