diff --git a/Cargo.lock b/Cargo.lock index f827e4f9e5e0e..e7365b2d26a75 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -463,7 +463,7 @@ dependencies = [ name = "bluetooth" version = "0.0.1" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.3.1", "bluetooth_traits", "device", "embedder_traits", @@ -639,7 +639,7 @@ dependencies = [ name = "canvas" version = "0.0.1" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.3.1", "byteorder", "canvas_traits", "crossbeam-channel", @@ -1390,7 +1390,7 @@ dependencies = [ name = "devtools_traits" version = "0.0.1" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.3.1", "headers", "http", "ipc-channel", @@ -2077,7 +2077,7 @@ name = "gfx" version = "0.0.1" dependencies = [ "app_units", - "bitflags 1.3.2", + "bitflags 2.3.1", "byteorder", "core-foundation 0.9.3", "core-graphics", @@ -3068,7 +3068,7 @@ version = "0.0.1" dependencies = [ "app_units", "atomic_refcell", - "bitflags 1.3.2", + "bitflags 2.3.1", "canvas_traits", "embedder_traits", "euclid", @@ -3113,7 +3113,7 @@ version = "0.0.1" dependencies = [ "app_units", "atomic_refcell", - "bitflags 1.3.2", + "bitflags 2.3.1", "canvas_traits", "cssparser", "embedder_traits", @@ -4940,7 +4940,7 @@ dependencies = [ "atomic_refcell", "backtrace", "base64 0.21.3", - "bitflags 1.3.2", + "bitflags 2.3.1", "bluetooth_traits", "canvas_traits", "chrono", @@ -5086,7 +5086,7 @@ dependencies = [ name = "script_traits" version = "0.0.1" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.3.1", "bluetooth_traits", "canvas_traits", "cookie 0.12.0", diff --git a/Cargo.toml b/Cargo.toml index f6c513614478e..74ea4449a31ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ atomic_refcell = "0.1.11" arrayvec = "0.7" backtrace = "0.3" base64 = "0.21.3" -bitflags = "1.0" +bitflags = "2.3" byteorder = "1.0" encoding_rs = "0.8" euclid = "0.22" diff --git a/components/gfx/font.rs b/components/gfx/font.rs index 7feb66fcaa3d1..054b732b77972 100644 --- a/components/gfx/font.rs +++ b/components/gfx/font.rs @@ -177,16 +177,17 @@ impl Font { } bitflags! { + #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] pub struct ShapingFlags: u8 { - #[doc = "Set if the text is entirely whitespace."] + /// Set if the text is entirely whitespace. const IS_WHITESPACE_SHAPING_FLAG = 0x01; - #[doc = "Set if we are to ignore ligatures."] + /// Set if we are to ignore ligatures. const IGNORE_LIGATURES_SHAPING_FLAG = 0x02; - #[doc = "Set if we are to disable kerning."] + /// Set if we are to disable kerning. const DISABLE_KERNING_SHAPING_FLAG = 0x04; - #[doc = "Text direction is right-to-left."] + /// Text direction is right-to-left. const RTL_FLAG = 0x08; - #[doc = "Set if word-break is set to keep-all."] + /// Set if word-break is set to keep-all. const KEEP_ALL_FLAG = 0x10; } } diff --git a/components/gfx_traits/lib.rs b/components/gfx_traits/lib.rs index a20c5a0c34c9f..2c6c32ca9f27b 100644 --- a/components/gfx_traits/lib.rs +++ b/components/gfx_traits/lib.rs @@ -57,10 +57,9 @@ impl StackingContextId { } int_range_index! { - #[derive(Deserialize, Serialize)] - #[doc = "An index that refers to a byte offset in a text run. This could \ - point to the middle of a glyph."] - #[derive(MallocSizeOf)] + #[derive(Deserialize, MallocSizeOf, Serialize)] + /// An index that refers to a byte offset in a text run. This could + /// the middle of a glyph. struct ByteIndex(isize) } diff --git a/components/layout/block.rs b/components/layout/block.rs index df5dddaf50011..357504bcab941 100644 --- a/components/layout/block.rs +++ b/components/layout/block.rs @@ -603,10 +603,11 @@ pub struct BlockFlow { } bitflags! { + #[derive(Clone, Copy)] struct BlockFlowFlags: u8 { - #[doc = "If this is set, then this block flow is the root flow."] + /// If this is set, then this block flow is the root flow. const IS_ROOT = 0b0000_0001; - #[doc = "If this is set, then this block flow has overflow and it will scroll."] + /// If this is set, then this block flow has overflow and it will scroll. const HAS_SCROLLING_OVERFLOW = 0b0000_0010; } } diff --git a/components/layout/data.rs b/components/layout/data.rs index 7744b08a57316..96112a8523ac6 100644 --- a/components/layout/data.rs +++ b/components/layout/data.rs @@ -51,10 +51,11 @@ impl Default for LayoutData { } bitflags! { + #[derive(Clone, Copy)] pub struct LayoutDataFlags: u8 { - #[doc = "Whether a flow has been newly constructed."] + /// Whether a flow has been newly constructed. const HAS_NEWLY_CONSTRUCTED_FLOW = 0x01; - #[doc = "Whether this node has been traversed by layout."] + /// Whether this node has been traversed by layout. const HAS_BEEN_TRAVERSED = 0x02; } } diff --git a/components/layout/display_list/builder.rs b/components/layout/display_list/builder.rs index 93da81c3532f9..2614789668231 100644 --- a/components/layout/display_list/builder.rs +++ b/components/layout/display_list/builder.rs @@ -2223,6 +2223,7 @@ impl Fragment { } bitflags! { + #[derive(Clone, Copy)] pub struct StackingContextCollectionFlags: u8 { /// This flow never establishes a containing block. const POSITION_NEVER_CREATES_CONTAINING_BLOCK = 0b001; diff --git a/components/layout/flow.rs b/components/layout/flow.rs index ef7cfe3d5a7d0..48f6f17f2f4e5 100644 --- a/components/layout/flow.rs +++ b/components/layout/flow.rs @@ -613,43 +613,43 @@ impl FlowClass { } bitflags! { - #[doc = "Flags used in flows."] + /// Flags used in flows. + #[derive(Clone, Copy, Debug)] pub struct FlowFlags: u32 { - // text align flags - #[doc = "Whether this flow is absolutely positioned. This is checked all over layout, so a"] - #[doc = "virtual call is too expensive."] + /// Whether this flow is absolutely positioned. This is checked all over layout, so a + /// virtual call is too expensive. const IS_ABSOLUTELY_POSITIONED = 0b0000_0000_0000_0000_0100_0000; - #[doc = "Whether this flow clears to the left. This is checked all over layout, so a"] - #[doc = "virtual call is too expensive."] + /// Whether this flow clears to the left. This is checked all over layout, so a + /// virtual call is too expensive. const CLEARS_LEFT = 0b0000_0000_0000_0000_1000_0000; - #[doc = "Whether this flow clears to the right. This is checked all over layout, so a"] - #[doc = "virtual call is too expensive."] + /// Whether this flow clears to the right. This is checked all over layout, so a + /// virtual call is too expensive. const CLEARS_RIGHT = 0b0000_0000_0000_0001_0000_0000; - #[doc = "Whether this flow is left-floated. This is checked all over layout, so a"] - #[doc = "virtual call is too expensive."] + /// Whether this flow is left-floated. This is checked all over layout, so a + /// virtual call is too expensive. const FLOATS_LEFT = 0b0000_0000_0000_0010_0000_0000; - #[doc = "Whether this flow is right-floated. This is checked all over layout, so a"] - #[doc = "virtual call is too expensive."] + /// Whether this flow is right-floated. This is checked all over layout, so a + /// virtual call is too expensive. const FLOATS_RIGHT = 0b0000_0000_0000_0100_0000_0000; - #[doc = "Text alignment. \ - \ - NB: If you update this, update `TEXT_ALIGN_SHIFT` below."] + /// Text alignment. + /// + /// NB: If you update this, update `TEXT_ALIGN_SHIFT` below. const TEXT_ALIGN = 0b0000_0000_0111_1000_0000_0000; - #[doc = "Whether this flow has a fragment with `counter-reset` or `counter-increment` \ - styles."] + /// Whether this flow has a fragment with `counter-reset` or `counter-increment` + /// styles. const AFFECTS_COUNTERS = 0b0000_0000_1000_0000_0000_0000; - #[doc = "Whether this flow's descendants have fragments that affect `counter-reset` or \ - `counter-increment` styles."] + /// Whether this flow's descendants have fragments that affect `counter-reset` or + // `counter-increment` styles. const HAS_COUNTER_AFFECTING_CHILDREN = 0b0000_0001_0000_0000_0000_0000; - #[doc = "Whether this flow behaves as though it had `position: static` for the purposes \ - of positioning in the inline direction. This is set for flows with `position: \ - static` and `position: relative` as well as absolutely-positioned flows with \ - unconstrained positions in the inline direction."] + /// Whether this flow behaves as though it had `position: static` for the purposes + /// of positioning in the inline direction. This is set for flows with `position: + /// static` and `position: relative` as well as absolutely-positioned flows with + /// unconstrained positions in the inline direction."] const INLINE_POSITION_IS_STATIC = 0b0000_0010_0000_0000_0000_0000; - #[doc = "Whether this flow behaves as though it had `position: static` for the purposes \ - of positioning in the block direction. This is set for flows with `position: \ - static` and `position: relative` as well as absolutely-positioned flows with \ - unconstrained positions in the block direction."] + /// Whether this flow behaves as though it had `position: static` for the purposes + /// of positioning in the block direction. This is set for flows with `position: + /// static` and `position: relative` as well as absolutely-positioned flows with + /// unconstrained positions in the block direction. const BLOCK_POSITION_IS_STATIC = 0b0000_0100_0000_0000_0000_0000; /// Whether any ancestor is a fragmentation container diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index 7f36e1104996c..98e04fd3d3d6a 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -534,6 +534,7 @@ pub struct ScannedTextFragmentInfo { } bitflags! { + #[derive(Clone, Copy)] pub struct ScannedTextFlags: u8 { /// Whether a line break is required after this fragment if wrapping on newlines (e.g. if /// `white-space: pre` is in effect). @@ -3328,10 +3329,10 @@ bitflags! { // Various flags we can use when splitting fragments. See // `calculate_split_position_using_breaking_strategy()`. struct SplitOptions: u8 { - #[doc = "True if this is the first fragment on the line."] + /// True if this is the first fragment on the line."] const STARTS_LINE = 0x01; - #[doc = "True if we should attempt to split at character boundaries if this split fails. \ - This is used to implement `overflow-wrap: break-word`."] + /// True if we should attempt to split at character boundaries if this split fails. \ + /// This is used to implement `overflow-wrap: break-word`."] const RETRY_AT_CHARACTER_BOUNDARIES = 0x02; } } @@ -3446,6 +3447,7 @@ impl Overflow { } bitflags! { + #[derive(Clone, Debug)] pub struct FragmentFlags: u8 { // TODO(stshine): find a better name since these flags can also be used for grid item. /// Whether this fragment represents a child in a row flex container. diff --git a/components/layout/incremental.rs b/components/layout/incremental.rs index 4e313f088bba1..a119169520596 100644 --- a/components/layout/incremental.rs +++ b/components/layout/incremental.rs @@ -16,8 +16,8 @@ pub enum RelayoutMode { bitflags! { pub struct SpecialRestyleDamage: u8 { - #[doc = "If this flag is set, we need to reflow the entire document. This is more or less a \ - temporary hack to deal with cases that we don't handle incrementally yet."] + /// If this flag is set, we need to reflow the entire document. This is more or less a + /// temporary hack to deal with cases that we don't handle incrementally yet. const REFLOW_ENTIRE_DOCUMENT = 0x01; } } diff --git a/components/layout/inline.rs b/components/layout/inline.rs index ee9980c4f1a5e..e9ef5eeb39130 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -221,7 +221,7 @@ impl Line { int_range_index! { #[derive(Serialize)] - #[doc = "The index of a fragment in a flattened vector of DOM elements."] + /// The index of a fragment in a flattened vector of DOM elements. struct FragmentIndex(isize) } @@ -2053,6 +2053,7 @@ pub struct InlineFragmentNodeInfo { } bitflags! { + #[derive(Clone)] pub struct InlineFragmentNodeFlags: u8 { const FIRST_FRAGMENT_OF_ELEMENT = 0x01; const LAST_FRAGMENT_OF_ELEMENT = 0x02; diff --git a/components/layout_2020/fragment_tree/base_fragment.rs b/components/layout_2020/fragment_tree/base_fragment.rs index d9271a7a0f6b9..0935296c118f9 100644 --- a/components/layout_2020/fragment_tree/base_fragment.rs +++ b/components/layout_2020/fragment_tree/base_fragment.rs @@ -72,10 +72,10 @@ impl From for BaseFragment { } bitflags! { - #[doc = "Flags used to track various information about a DOM node during layout."] - #[derive(Serialize)] + /// Flags used to track various information about a DOM node during layout. + #[derive(Clone, Copy, Debug, Serialize)] pub(crate) struct FragmentFlags: u8 { - #[doc = "Whether or not this node is a body element on an HTML document."] + /// Whether or not this node is a body element on an HTML document. const IS_BODY_ELEMENT_OF_HTML_ELEMENT_ROOT = 0b00000001; } } diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 0c39ecf2f3e84..bc7f2ceb9a822 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -7964,7 +7964,7 @@ def InterfaceObjectMap(config): global_flags = CGWrapper(CGIndenter(CGList([ CGGeneric("const %s = %#x;" % args) for args in flags - ], "\n")), pre="pub struct Globals: u8 {\n", post="\n}") + ], "\n")), pre="#[derive(Clone, Copy)]\npub struct Globals: u8 {\n", post="\n}") globals_ = CGWrapper(CGIndenter(global_flags), pre="bitflags! {\n", post="\n}") phf = CGGeneric("include!(concat!(env!(\"OUT_DIR\"), \"/InterfaceObjectMapPhf.rs\"));") diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index 55c515d8c1da3..99a4fd15a1173 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -43,9 +43,11 @@ use servo_url::ServoUrl; use std::cell::Cell; use style::attr::{AttrValue, LengthOrPercentageOrAuto}; +#[derive(Clone, Copy, JSTraceable, MallocSizeOf)] +struct SandboxAllowance(u8); + bitflags! { - #[derive(JSTraceable, MallocSizeOf)] - struct SandboxAllowance: u8 { + impl SandboxAllowance: u8 { const ALLOW_NOTHING = 0x00; const ALLOW_SAME_ORIGIN = 0x01; const ALLOW_TOP_NAVIGATION = 0x02; diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 7e3367b9b2a5f..797d57dfa6e7b 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -157,28 +157,30 @@ pub struct Node { style_and_layout_data: DomRefCell>>, } +/// Flags for node items +#[derive(Clone, Copy, JSTraceable, MallocSizeOf)] +pub struct NodeFlags(u16); + bitflags! { - #[doc = "Flags for node items."] - #[derive(JSTraceable, MallocSizeOf)] - pub struct NodeFlags: u16 { - #[doc = "Specifies whether this node is in a document."] + impl NodeFlags: u16 { + /// Specifies whether this node is in a document. const IS_IN_DOC = 1 << 0; - #[doc = "Specifies whether this node needs style recalc on next reflow."] + /// Specifies whether this node needs style recalc on next reflow. const HAS_DIRTY_DESCENDANTS = 1 << 1; - #[doc = "Specifies whether or not there is an authentic click in progress on \ - this element."] + /// Specifies whether or not there is an authentic click in progress on + /// this element. const CLICK_IN_PROGRESS = 1 << 2; - #[doc = "Specifies whether this node is focusable and whether it is supposed \ - to be reachable with using sequential focus navigation."] + /// Specifies whether this node is focusable and whether it is supposed + /// to be reachable with using sequential focus navigation."] const SEQUENTIALLY_FOCUSABLE = 1 << 3; // There are two free bits here. - #[doc = "Specifies whether the parser has set an associated form owner for \ - this element. Only applicable for form-associatable elements."] + /// Specifies whether the parser has set an associated form owner for + /// this element. Only applicable for form-associatable elements. const PARSER_ASSOCIATED_FORM_OWNER = 1 << 6; /// Whether this element has a snapshot stored due to a style or diff --git a/components/script/dom/validitystate.rs b/components/script/dom/validitystate.rs index 2af3843c203b8..81f4c254e4339 100755 --- a/components/script/dom/validitystate.rs +++ b/components/script/dom/validitystate.rs @@ -20,9 +20,11 @@ use std::fmt; use style::element_state::ElementState; // https://html.spec.whatwg.org/multipage/#validity-states +#[derive(Clone, Copy, JSTraceable, MallocSizeOf)] +pub struct ValidationFlags(u32); + bitflags! { - #[derive(JSTraceable, MallocSizeOf)] - pub struct ValidationFlags: u32 { + impl ValidationFlags: u32 { const VALUE_MISSING = 0b0000000001; const TYPE_MISMATCH = 0b0000000010; const PATTERN_MISMATCH = 0b0000000100; diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 39807da9a817e..7aaceb98bae1c 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -136,10 +136,12 @@ where ObjectValue(rval.get()) } +/// Set of bitflags for texture unpacking (texImage2d, etc...) +#[derive(Clone, Copy, JSTraceable, MallocSizeOf)] +struct TextureUnpacking(u8); + bitflags! { - /// Set of bitflags for texture unpacking (texImage2d, etc...) - #[derive(JSTraceable, MallocSizeOf)] - struct TextureUnpacking: u8 { + impl TextureUnpacking: u8 { const FLIP_Y_AXIS = 0x01; const PREMULTIPLY_ALPHA = 0x02; const CONVERT_COLORSPACE = 0x04; @@ -4703,12 +4705,14 @@ macro_rules! capabilities { capabilities!($name, $next, $($rest,)* [$name = 1;]); }; ($prev:ident, $name:ident, $($rest:ident,)* [$($tt:tt)*]) => { - capabilities!($name, $($rest,)* [$($tt)* $name = Self::$prev.bits << 1;]); + capabilities!($name, $($rest,)* [$($tt)* $name = Self::$prev.bits() << 1;]); }; ($prev:ident, [$($name:ident = $value:expr;)*]) => { + #[derive(Copy, Clone, JSTraceable, MallocSizeOf)] + pub struct CapFlags(u16); + bitflags! { - #[derive(JSTraceable, MallocSizeOf)] - struct CapFlags: u16 { + impl CapFlags: u16 { $(const $name = $value;)* } }