diff options
author | Bastien Orivel <eijebong@bananium.fr> | 2017-10-09 17:03:40 +0200 |
---|---|---|
committer | Bastien Orivel <eijebong@bananium.fr> | 2017-10-19 15:01:17 +0200 |
commit | e8e2d0a4b24475b018dbc7e59ea46fdceaf20815 (patch) | |
tree | bd56b4a2fc203150ee5c3b5e163937fb3b4e1989 /components | |
parent | 4cf2ce66fc4f970a47ab1fb4b9aa1a55282640f7 (diff) | |
download | servo-e8e2d0a4b24475b018dbc7e59ea46fdceaf20815.tar.gz servo-e8e2d0a4b24475b018dbc7e59ea46fdceaf20815.zip |
Update bitflags to 1.0 in every servo crate
It still needs dependencies update to remove all the other bitflags
versions.
Diffstat (limited to 'components')
128 files changed, 1544 insertions, 1488 deletions
diff --git a/components/bluetooth/Cargo.toml b/components/bluetooth/Cargo.toml index 5683c7b8150..cdb304e785c 100644 --- a/components/bluetooth/Cargo.toml +++ b/components/bluetooth/Cargo.toml @@ -10,7 +10,7 @@ name = "bluetooth" path = "lib.rs" [dependencies] -bitflags = "0.7" +bitflags = "1.0" bluetooth_traits = {path = "../bluetooth_traits"} device = {git = "https://github.com/servo/devices", features = ["bluetooth-test"]} ipc-channel = "0.9" diff --git a/components/bluetooth/lib.rs b/components/bluetooth/lib.rs index ac41040feff..4da52efc445 100644 --- a/components/bluetooth/lib.rs +++ b/components/bluetooth/lib.rs @@ -47,16 +47,16 @@ const DIALOG_COLUMN_ID: &'static str = "Id"; const DIALOG_COLUMN_NAME: &'static str = "Name"; bitflags! { - flags Flags: u32 { - const BROADCAST = 0b000000001, - const READ = 0b000000010, - const WRITE_WITHOUT_RESPONSE = 0b000000100, - const WRITE = 0b000001000, - const NOTIFY = 0b000010000, - const INDICATE = 0b000100000, - const AUTHENTICATED_SIGNED_WRITES = 0b001000000, - const RELIABLE_WRITE = 0b010000000, - const WRITABLE_AUXILIARIES = 0b100000000, + struct Flags: u32 { + const BROADCAST = 0b000000001; + const READ = 0b000000010; + const WRITE_WITHOUT_RESPONSE = 0b000000100; + const WRITE = 0b000001000; + const NOTIFY = 0b000010000; + const INDICATE = 0b000100000; + const AUTHENTICATED_SIGNED_WRITES = 0b001000000; + const RELIABLE_WRITE = 0b010000000; + const WRITABLE_AUXILIARIES = 0b100000000; } } @@ -522,15 +522,15 @@ impl BluetoothManager { let flags = characteristic.get_flags().unwrap_or(vec!()); for flag in flags { match flag.as_ref() { - "broadcast" => props.insert(BROADCAST), - "read" => props.insert(READ), - "write-without-response" => props.insert(WRITE_WITHOUT_RESPONSE), - "write" => props.insert(WRITE), - "notify" => props.insert(NOTIFY), - "indicate" => props.insert(INDICATE), - "authenticated-signed-writes" => props.insert(AUTHENTICATED_SIGNED_WRITES), - "reliable-write" => props.insert(RELIABLE_WRITE), - "writable-auxiliaries" => props.insert(WRITABLE_AUXILIARIES), + "broadcast" => props.insert(Flags::BROADCAST), + "read" => props.insert(Flags::READ), + "write-without-response" => props.insert(Flags::WRITE_WITHOUT_RESPONSE), + "write" => props.insert(Flags::WRITE), + "notify" => props.insert(Flags::NOTIFY), + "indicate" => props.insert(Flags::INDICATE), + "authenticated-signed-writes" => props.insert(Flags::AUTHENTICATED_SIGNED_WRITES), + "reliable-write" => props.insert(Flags::RELIABLE_WRITE), + "writable-auxiliaries" => props.insert(Flags::WRITABLE_AUXILIARIES), _ => (), } } @@ -747,15 +747,15 @@ impl BluetoothManager { BluetoothCharacteristicMsg { uuid: uuid, instance_id: characteristic.get_id(), - broadcast: properties.contains(BROADCAST), - read: properties.contains(READ), - write_without_response: properties.contains(WRITE_WITHOUT_RESPONSE), - write: properties.contains(WRITE), - notify: properties.contains(NOTIFY), - indicate: properties.contains(INDICATE), - authenticated_signed_writes: properties.contains(AUTHENTICATED_SIGNED_WRITES), - reliable_write: properties.contains(RELIABLE_WRITE), - writable_auxiliaries: properties.contains(WRITABLE_AUXILIARIES), + broadcast: properties.contains(Flags::BROADCAST), + read: properties.contains(Flags::READ), + write_without_response: properties.contains(Flags::WRITE_WITHOUT_RESPONSE), + write: properties.contains(Flags::WRITE), + notify: properties.contains(Flags::NOTIFY), + indicate: properties.contains(Flags::INDICATE), + authenticated_signed_writes: properties.contains(Flags::AUTHENTICATED_SIGNED_WRITES), + reliable_write: properties.contains(Flags::RELIABLE_WRITE), + writable_auxiliaries: properties.contains(Flags::WRITABLE_AUXILIARIES), } ); } diff --git a/components/devtools/actors/console.rs b/components/devtools/actors/console.rs index c94c9860156..295ebca489b 100644 --- a/components/devtools/actors/console.rs +++ b/components/devtools/actors/console.rs @@ -9,7 +9,7 @@ use actor::{Actor, ActorMessageStatus, ActorRegistry}; use actors::object::ObjectActor; -use devtools_traits::{CONSOLE_API, CachedConsoleMessageTypes, DevtoolScriptControlMsg, PAGE_ERROR}; +use devtools_traits::{CachedConsoleMessageTypes, DevtoolScriptControlMsg}; use devtools_traits::CachedConsoleMessage; use devtools_traits::EvaluateJSReply::{ActorValue, BooleanValue, StringValue}; use devtools_traits::EvaluateJSReply::{NullValue, NumberValue, VoidValue}; @@ -107,8 +107,8 @@ impl Actor for ConsoleActor { let mut message_types = CachedConsoleMessageTypes::empty(); for str_type in str_types { match str_type { - "PageError" => message_types.insert(PAGE_ERROR), - "ConsoleAPI" => message_types.insert(CONSOLE_API), + "PageError" => message_types.insert(CachedConsoleMessageTypes::PAGE_ERROR), + "ConsoleAPI" => message_types.insert(CachedConsoleMessageTypes::CONSOLE_API), s => debug!("unrecognized message type requested: \"{}\"", s), }; }; diff --git a/components/devtools_traits/Cargo.toml b/components/devtools_traits/Cargo.toml index f722002daa8..eda5c8725c0 100644 --- a/components/devtools_traits/Cargo.toml +++ b/components/devtools_traits/Cargo.toml @@ -10,7 +10,7 @@ name = "devtools_traits" path = "lib.rs" [dependencies] -bitflags = "0.7" +bitflags = "1.0" hyper = "0.10" hyper_serde = "0.7" ipc-channel = "0.9" diff --git a/components/devtools_traits/lib.rs b/components/devtools_traits/lib.rs index 1195ef8a987..fe0f91c7e52 100644 --- a/components/devtools_traits/lib.rs +++ b/components/devtools_traits/lib.rs @@ -243,9 +243,9 @@ pub struct ConsoleMessage { bitflags! { #[derive(Deserialize, Serialize)] - pub flags CachedConsoleMessageTypes: u8 { - const PAGE_ERROR = 1 << 0, - const CONSOLE_API = 1 << 1, + pub struct CachedConsoleMessageTypes: u8 { + const PAGE_ERROR = 1 << 0; + const CONSOLE_API = 1 << 1; } } diff --git a/components/gfx/Cargo.toml b/components/gfx/Cargo.toml index 606d17c2908..3e3560870cb 100644 --- a/components/gfx/Cargo.toml +++ b/components/gfx/Cargo.toml @@ -15,7 +15,7 @@ unstable = ["simd"] [dependencies] app_units = "0.5" -bitflags = "0.7" +bitflags = "1.0" euclid = "0.15" fnv = "1.0" fontsan = {git = "https://github.com/servo/fontsan"} diff --git a/components/gfx/font.rs b/components/gfx/font.rs index 9c59f71fb0a..4623784c53d 100644 --- a/components/gfx/font.rs +++ b/components/gfx/font.rs @@ -139,17 +139,17 @@ impl Font { } bitflags! { - pub flags ShapingFlags: u8 { + pub struct ShapingFlags: u8 { #[doc = "Set if the text is entirely whitespace."] - const IS_WHITESPACE_SHAPING_FLAG = 0x01, + const IS_WHITESPACE_SHAPING_FLAG = 0x01; #[doc = "Set if we are to ignore ligatures."] - const IGNORE_LIGATURES_SHAPING_FLAG = 0x02, + const IGNORE_LIGATURES_SHAPING_FLAG = 0x02; #[doc = "Set if we are to disable kerning."] - const DISABLE_KERNING_SHAPING_FLAG = 0x04, + const DISABLE_KERNING_SHAPING_FLAG = 0x04; #[doc = "Text direction is right-to-left."] - const RTL_FLAG = 0x08, + const RTL_FLAG = 0x08; #[doc = "Set if word-break is set to keep-all."] - const KEEP_ALL_FLAG = 0x10, + const KEEP_ALL_FLAG = 0x10; } } @@ -186,8 +186,8 @@ impl Font { let result = self.shape_cache.borrow_mut().entry(lookup_key).or_insert_with(|| { let start_time = time::precise_time_ns(); let mut glyphs = GlyphStore::new(text.len(), - options.flags.contains(IS_WHITESPACE_SHAPING_FLAG), - options.flags.contains(RTL_FLAG)); + options.flags.contains(ShapingFlags::IS_WHITESPACE_SHAPING_FLAG), + options.flags.contains(ShapingFlags::RTL_FLAG)); if self.can_do_fast_shaping(text, options) { debug!("shape_text: Using ASCII fast path."); @@ -211,7 +211,7 @@ impl Font { fn can_do_fast_shaping(&self, text: &str, options: &ShapingOptions) -> bool { options.script == Script::Latin && - !options.flags.contains(RTL_FLAG) && + !options.flags.contains(ShapingFlags::RTL_FLAG) && self.handle.can_do_fast_shaping() && text.is_ascii() } diff --git a/components/gfx/text/shaping/harfbuzz.rs b/components/gfx/text/shaping/harfbuzz.rs index 27e614af158..36e35150ad1 100644 --- a/components/gfx/text/shaping/harfbuzz.rs +++ b/components/gfx/text/shaping/harfbuzz.rs @@ -6,8 +6,7 @@ use app_units::Au; use euclid::Point2D; -use font::{DISABLE_KERNING_SHAPING_FLAG, Font, FontTableMethods, FontTableTag}; -use font::{IGNORE_LIGATURES_SHAPING_FLAG, KERN, RTL_FLAG, ShapingOptions}; +use font::{ShapingFlags, Font, FontTableMethods, FontTableTag, ShapingOptions, KERN}; use harfbuzz::{HB_DIRECTION_LTR, HB_DIRECTION_RTL, HB_MEMORY_MODE_READONLY}; use harfbuzz::{hb_blob_create, hb_face_create_for_tables}; use harfbuzz::{hb_buffer_create, hb_font_destroy}; @@ -189,7 +188,7 @@ impl ShaperMethods for Shaper { fn shape_text(&self, text: &str, options: &ShapingOptions, glyphs: &mut GlyphStore) { unsafe { let hb_buffer: *mut hb_buffer_t = hb_buffer_create(); - hb_buffer_set_direction(hb_buffer, if options.flags.contains(RTL_FLAG) { + hb_buffer_set_direction(hb_buffer, if options.flags.contains(ShapingFlags::RTL_FLAG) { HB_DIRECTION_RTL } else { HB_DIRECTION_LTR @@ -204,7 +203,7 @@ impl ShaperMethods for Shaper { text.len() as c_int); let mut features = Vec::new(); - if options.flags.contains(IGNORE_LIGATURES_SHAPING_FLAG) { + if options.flags.contains(ShapingFlags::IGNORE_LIGATURES_SHAPING_FLAG) { features.push(hb_feature_t { tag: LIGA, value: 0, @@ -212,7 +211,7 @@ impl ShaperMethods for Shaper { end: hb_buffer_get_length(hb_buffer), }) } - if options.flags.contains(DISABLE_KERNING_SHAPING_FLAG) { + if options.flags.contains(ShapingFlags::DISABLE_KERNING_SHAPING_FLAG) { features.push(hb_feature_t { tag: KERN, value: 0, diff --git a/components/gfx/text/text_run.rs b/components/gfx/text/text_run.rs index d34e4788cac..e66b6550dc3 100644 --- a/components/gfx/text/text_run.rs +++ b/components/gfx/text/text_run.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use app_units::Au; -use font::{Font, FontHandleMethods, FontMetrics, IS_WHITESPACE_SHAPING_FLAG, KEEP_ALL_FLAG}; +use font::{Font, FontHandleMethods, FontMetrics, ShapingFlags}; use font::{RunMetrics, ShapingOptions}; use platform::font_template::FontTemplateData; use range::Range; @@ -210,7 +210,7 @@ impl<'a> TextRun { .take_while(|&(_, c)| char_is_whitespace(c)).last() { whitespace.start = slice.start + i; slice.end = whitespace.start; - } else if idx != text.len() && options.flags.contains(KEEP_ALL_FLAG) { + } else if idx != text.len() && options.flags.contains(ShapingFlags::KEEP_ALL_FLAG) { // If there's no whitespace and word-break is set to // keep-all, try increasing the slice. continue; @@ -224,7 +224,7 @@ impl<'a> TextRun { } if whitespace.len() > 0 { let mut options = options.clone(); - options.flags.insert(IS_WHITESPACE_SHAPING_FLAG); + options.flags.insert(ShapingFlags::IS_WHITESPACE_SHAPING_FLAG); glyphs.push(GlyphRun { glyph_store: font.shape_text(&text[whitespace.clone()], &options), range: Range::new(ByteIndex(whitespace.start as isize), diff --git a/components/layout/Cargo.toml b/components/layout/Cargo.toml index 70903da2dbf..ad6bfa86efb 100644 --- a/components/layout/Cargo.toml +++ b/components/layout/Cargo.toml @@ -12,7 +12,7 @@ path = "lib.rs" [dependencies] app_units = "0.5" atomic_refcell = "0.1" -bitflags = "0.8" +bitflags = "1.0" canvas_traits = {path = "../canvas_traits"} euclid = "0.15" fnv = "1.0" diff --git a/components/layout/block.rs b/components/layout/block.rs index aaad1d51937..57ebe275502 100644 --- a/components/layout/block.rs +++ b/components/layout/block.rs @@ -35,13 +35,9 @@ use display_list_builder::StackingContextCollectionState; use euclid::{Point2D, Rect, SideOffsets2D, Size2D}; use floats::{ClearType, FloatKind, Floats, PlacementInfo}; use flow::{self, BaseFlow, EarlyAbsolutePositionInfo, Flow, FlowClass, ForceNonfloatedFlag}; -use flow::{BLOCK_POSITION_IS_STATIC, CLEARS_LEFT, CLEARS_RIGHT}; -use flow::{CONTAINS_TEXT_OR_REPLACED_FRAGMENTS, INLINE_POSITION_IS_STATIC}; -use flow::{IS_ABSOLUTELY_POSITIONED, FragmentationContext, MARGINS_CANNOT_COLLAPSE}; -use flow::{ImmutableFlowUtils, LateAbsolutePositionInfo, OpaqueFlow}; +use flow::{ImmutableFlowUtils, LateAbsolutePositionInfo, OpaqueFlow, FragmentationContext, FlowFlags}; use flow_list::FlowList; -use fragment::{CoordinateSystem, Fragment, FragmentBorderBoxIterator, Overflow}; -use fragment::{IS_INLINE_FLEX_ITEM, IS_BLOCK_FLEX_ITEM}; +use fragment::{CoordinateSystem, Fragment, FragmentBorderBoxIterator, Overflow, FragmentFlags}; use gfx_traits::print_tree::PrintTree; use incremental::RelayoutMode; use layout_debug; @@ -57,7 +53,7 @@ use style::computed_values::{position, text_align}; use style::context::SharedStyleContext; use style::logical_geometry::{LogicalMargin, LogicalPoint, LogicalRect, LogicalSize, WritingMode}; use style::properties::ComputedValues; -use style::servo::restyle_damage::{BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW}; +use style::servo::restyle_damage::ServoRestyleDamage; use style::values::computed::{LengthOrPercentageOrNone, LengthOrPercentage}; use style::values::computed::LengthOrPercentageOrAuto; use traversal::PreorderFlowTraversal; @@ -455,11 +451,11 @@ impl<'a> PreorderFlowTraversal for AbsoluteAssignBSizesTraversal<'a> { // This flow might not be an absolutely positioned flow if it is the root of the tree. let block = flow.as_mut_block(); - if !block.base.flags.contains(IS_ABSOLUTELY_POSITIONED) { + if !block.base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { return; } - if !block.base.restyle_damage.intersects(REFLOW_OUT_OF_FLOW | REFLOW) { + if !block.base.restyle_damage.intersects(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW) { return } @@ -513,11 +509,11 @@ pub struct BlockFlow { } bitflags! { - flags BlockFlowFlags: u8 { + struct BlockFlowFlags: u8 { #[doc = "If this is set, then this block flow is the root flow."] - const IS_ROOT = 0b0000_0001, + const IS_ROOT = 0b0000_0001; #[doc = "If this is set, then this block flow has overflow and it will scroll."] - const HAS_SCROLLING_OVERFLOW = 0b0000_0010, + const HAS_SCROLLING_OVERFLOW = 0b0000_0010; } } @@ -551,7 +547,7 @@ impl BlockFlow { /// This determines the algorithm used to calculate inline-size, block-size, and the /// relevant margins for this Block. pub fn block_type(&self) -> BlockType { - if self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) { + if self.base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { if self.fragment.is_replaced() { BlockType::AbsoluteReplaced } else { @@ -664,7 +660,7 @@ impl BlockFlow { #[inline] pub fn containing_block_size(&self, viewport_size: &Size2D<Au>, descendant: OpaqueFlow) -> LogicalSize<Au> { - debug_assert!(self.base.flags.contains(IS_ABSOLUTELY_POSITIONED)); + debug_assert!(self.base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED)); if self.is_fixed() || self.is_root() { // Initial containing block is the CB for the root LogicalSize::from_physical(self.base.writing_mode, *viewport_size) @@ -783,13 +779,13 @@ impl BlockFlow { let mut break_at = None; let content_box = self.fragment.content_box(); - if self.base.restyle_damage.contains(REFLOW) { + if self.base.restyle_damage.contains(ServoRestyleDamage::REFLOW) { // Our current border-box position. let mut cur_b = Au(0); // Absolute positioning establishes a block formatting context. Don't propagate floats // in or out. (But do propagate them between kids.) - if self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) || + if self.base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) || margins_may_collapse != MarginsMayCollapseFlag::MarginsMayCollapse { self.base.floats = Floats::new(self.fragment.style.writing_mode); } @@ -805,7 +801,7 @@ impl BlockFlow { let can_collapse_block_start_margin_with_kids = margins_may_collapse == MarginsMayCollapseFlag::MarginsMayCollapse && - !self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) && + !self.base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) && self.fragment.border_padding.block_start == Au(0); margin_collapse_info.initialize_block_start_margin( &self.fragment, @@ -816,10 +812,10 @@ impl BlockFlow { let thread_id = self.base.thread_id; let (mut had_floated_children, mut had_children_with_clearance) = (false, false); for (child_index, kid) in self.base.child_iter_mut().enumerate() { - if flow::base(kid).flags.contains(IS_ABSOLUTELY_POSITIONED) { + if flow::base(kid).flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { // Assume that the *hypothetical box* for an absolute flow starts immediately // after the margin-end border edge of the previous flow. - if flow::base(kid).flags.contains(BLOCK_POSITION_IS_STATIC) { + if flow::base(kid).flags.contains(FlowFlags::BLOCK_POSITION_IS_STATIC) { let previous_bottom_margin = margin_collapse_info.current_float_ceiling(); flow::mut_base(kid).position.start.b = cur_b + @@ -887,8 +883,8 @@ impl BlockFlow { if !had_children_with_clearance && floats.is_present() && - (flow::base(kid).flags.contains(CLEARS_LEFT) || - flow::base(kid).flags.contains(CLEARS_RIGHT)) { + (flow::base(kid).flags.contains(FlowFlags::CLEARS_LEFT) || + flow::base(kid).flags.contains(FlowFlags::CLEARS_RIGHT)) { had_children_with_clearance = true } @@ -905,8 +901,8 @@ impl BlockFlow { } // Clear past the floats that came in, if necessary. - let clearance = match (flow::base(kid).flags.contains(CLEARS_LEFT), - flow::base(kid).flags.contains(CLEARS_RIGHT)) { + let clearance = match (flow::base(kid).flags.contains(FlowFlags::CLEARS_LEFT), + flow::base(kid).flags.contains(FlowFlags::CLEARS_RIGHT)) { (false, false) => Au(0), (true, false) => floats.clearance(ClearType::Left), (false, true) => floats.clearance(ClearType::Right), @@ -967,7 +963,7 @@ impl BlockFlow { // Add in our block-end margin and compute our collapsible margins. let can_collapse_block_end_margin_with_kids = margins_may_collapse == MarginsMayCollapseFlag::MarginsMayCollapse && - !self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) && + !self.base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) && self.fragment.border_padding.block_end == Au(0); let (collapsible_margins, delta) = margin_collapse_info.finish_and_compute_collapsible_margins( @@ -982,13 +978,13 @@ impl BlockFlow { let is_root = self.is_root(); if is_root || self.formatting_context_type() != FormattingContextType::None || - self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) { + self.base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { // The content block-size includes all the floats per CSS 2.1 § 10.6.7. The easiest // way to handle this is to just treat it as clearance. block_size = block_size + floats.clearance(ClearType::Both); } - if self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) { + if self.base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { // FIXME(#2003, pcwalton): The max is taken here so that you can scroll the page, // but this is not correct behavior according to CSS 2.1 § 10.5. Instead I think we // should treat the root element as having `overflow: scroll` and use the layers- @@ -1008,7 +1004,7 @@ impl BlockFlow { } - if self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) { + if self.base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { self.propagate_early_absolute_position_info_to_children(); return None } @@ -1076,9 +1072,9 @@ impl BlockFlow { // size has not yet been computed. (See `assign_inline_position_for_formatting_context()`.) if (self.base.flags.is_float() || self.formatting_context_type() == FormattingContextType::None) && - !self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) { - self.base.restyle_damage.remove(REFLOW_OUT_OF_FLOW | REFLOW); - self.fragment.restyle_damage.remove(REFLOW_OUT_OF_FLOW | REFLOW); + !self.base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { + self.base.restyle_damage.remove(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW); + self.fragment.restyle_damage.remove(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW); } break_at.and_then(|(i, child_remaining)| { @@ -1162,7 +1158,7 @@ impl BlockFlow { let viewport_size = LogicalSize::from_physical(self.fragment.style.writing_mode, shared_context.viewport_size()); Some(viewport_size.block) - } else if self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) && + } else if self.base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) && self.base.block_container_explicit_block_size.is_none() { self.base.absolute_cb.explicit_block_containing_size(shared_context) } else { @@ -1300,7 +1296,7 @@ impl BlockFlow { self.fragment.margin.block_end = solution.margin_block_end; self.fragment.border_box.start.b = Au(0); - if !self.base.flags.contains(BLOCK_POSITION_IS_STATIC) { + if !self.base.flags.contains(FlowFlags::BLOCK_POSITION_IS_STATIC) { self.base.position.start.b = solution.block_start + self.fragment.margin.block_start } @@ -1308,8 +1304,8 @@ impl BlockFlow { self.fragment.border_box.size.block = block_size; self.base.position.size.block = block_size; - self.base.restyle_damage.remove(REFLOW_OUT_OF_FLOW | REFLOW); - self.fragment.restyle_damage.remove(REFLOW_OUT_OF_FLOW | REFLOW); + self.base.restyle_damage.remove(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW); + self.fragment.restyle_damage.remove(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW); } /// Compute inline size based using the `block_container_inline_size` set by the parent flow. @@ -1358,7 +1354,7 @@ impl BlockFlow { .map(|x| if x < box_border { Au(0) } else { x - box_border }); if self.is_root() { explicit_content_size = max(parent_container_size, explicit_content_size); } // Calculate containing block inline size. - let containing_block_size = if flags.contains(IS_ABSOLUTELY_POSITIONED) { + let containing_block_size = if flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { self.containing_block_size(&shared_context.viewport_size(), opaque_self).inline } else { content_inline_size @@ -1386,12 +1382,12 @@ impl BlockFlow { // float child does not have `REFLOW` set, we must be careful to avoid touching its // inline position, as no logic will run afterward to set its true value. let kid_base = flow::mut_base(kid); - let reflow_damage = if kid_base.flags.contains(IS_ABSOLUTELY_POSITIONED) { - REFLOW_OUT_OF_FLOW + let reflow_damage = if kid_base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { + ServoRestyleDamage::REFLOW_OUT_OF_FLOW } else { - REFLOW + ServoRestyleDamage::REFLOW }; - if kid_base.flags.contains(INLINE_POSITION_IS_STATIC) && + if kid_base.flags.contains(FlowFlags::INLINE_POSITION_IS_STATIC) && kid_base.restyle_damage.contains(reflow_damage) { kid_base.position.start.i = if kid_mode.is_bidi_ltr() == containing_block_mode.is_bidi_ltr() { @@ -1475,13 +1471,13 @@ impl BlockFlow { content_box: LogicalRect<Au>) { debug_assert!(self.formatting_context_type() != FormattingContextType::None); - if !self.base.restyle_damage.intersects(REFLOW_OUT_OF_FLOW | REFLOW) { + if !self.base.restyle_damage.intersects(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW) { return } // We do this first to avoid recomputing our inline size when we propagate it. - self.base.restyle_damage.remove(REFLOW_OUT_OF_FLOW | REFLOW); - self.fragment.restyle_damage.remove(REFLOW_OUT_OF_FLOW | REFLOW); + self.base.restyle_damage.remove(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW); + self.fragment.restyle_damage.remove(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW); // The code below would completely wreck the layout if run on a flex item, however: // * Flex items are always the children of flex containers. @@ -1591,14 +1587,14 @@ impl BlockFlow { // This is kind of a hack for Acid2. But it's a harmless one, because (a) this behavior // is unspecified; (b) it matches the behavior one would intuitively expect, since // floats don't flow around blocks that take up no space in the block direction. - flags.remove(CONTAINS_TEXT_OR_REPLACED_FRAGMENTS); + flags.remove(FlowFlags::CONTAINS_TEXT_OR_REPLACED_FRAGMENTS); } else if self.fragment.is_text_or_replaced() { - flags.insert(CONTAINS_TEXT_OR_REPLACED_FRAGMENTS); + flags.insert(FlowFlags::CONTAINS_TEXT_OR_REPLACED_FRAGMENTS); } else { - flags.remove(CONTAINS_TEXT_OR_REPLACED_FRAGMENTS); + flags.remove(FlowFlags::CONTAINS_TEXT_OR_REPLACED_FRAGMENTS); for kid in self.base.children.iter() { - if flow::base(kid).flags.contains(CONTAINS_TEXT_OR_REPLACED_FRAGMENTS) { - flags.insert(CONTAINS_TEXT_OR_REPLACED_FRAGMENTS); + if flow::base(kid).flags.contains(FlowFlags::CONTAINS_TEXT_OR_REPLACED_FRAGMENTS) { + flags.insert(FlowFlags::CONTAINS_TEXT_OR_REPLACED_FRAGMENTS); break } } @@ -1615,7 +1611,7 @@ impl BlockFlow { let (mut left_float_width_accumulator, mut right_float_width_accumulator) = (Au(0), Au(0)); let mut preferred_inline_size_of_children_without_text_or_replaced_fragments = Au(0); for kid in self.base.child_iter_mut() { - if flow::base(kid).flags.contains(IS_ABSOLUTELY_POSITIONED) || !consult_children { + if flow::base(kid).flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) || !consult_children { continue } @@ -1625,16 +1621,16 @@ impl BlockFlow { max(computation.content_intrinsic_sizes.minimum_inline_size, child_base.intrinsic_inline_sizes.minimum_inline_size); - if child_base.flags.contains(CLEARS_LEFT) { + if child_base.flags.contains(FlowFlags::CLEARS_LEFT) { left_float_width = max(left_float_width, left_float_width_accumulator); left_float_width_accumulator = Au(0) } - if child_base.flags.contains(CLEARS_RIGHT) { + if child_base.flags.contains(FlowFlags::CLEARS_RIGHT) { right_float_width = max(right_float_width, right_float_width_accumulator); right_float_width_accumulator = Au(0) } - match (float_kind, child_base.flags.contains(CONTAINS_TEXT_OR_REPLACED_FRAGMENTS)) { + match (float_kind, child_base.flags.contains(FlowFlags::CONTAINS_TEXT_OR_REPLACED_FRAGMENTS)) { (float::T::none, true) => { computation.content_intrinsic_sizes.preferred_inline_size = max(computation.content_intrinsic_sizes.preferred_inline_size, @@ -1681,7 +1677,7 @@ impl BlockFlow { } pub fn compute_inline_sizes(&mut self, shared_context: &SharedStyleContext) { - if !self.base.restyle_damage.intersects(REFLOW_OUT_OF_FLOW | REFLOW) { + if !self.base.restyle_damage.intersects(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW) { return } @@ -1762,23 +1758,23 @@ impl BlockFlow { } pub fn is_inline_flex_item(&self) -> bool { - self.fragment.flags.contains(IS_INLINE_FLEX_ITEM) + self.fragment.flags.contains(FragmentFlags::IS_INLINE_FLEX_ITEM) } pub fn is_block_flex_item(&self) -> bool { - self.fragment.flags.contains(IS_BLOCK_FLEX_ITEM) + self.fragment.flags.contains(FragmentFlags::IS_BLOCK_FLEX_ITEM) } pub fn mark_scrolling_overflow(&mut self, has_scrolling_overflow: bool) { if has_scrolling_overflow { - self.flags.insert(HAS_SCROLLING_OVERFLOW); + self.flags.insert(BlockFlowFlags::HAS_SCROLLING_OVERFLOW); } else { - self.flags.remove(HAS_SCROLLING_OVERFLOW); + self.flags.remove(BlockFlowFlags::HAS_SCROLLING_OVERFLOW); } } pub fn has_scrolling_overflow(&mut self) -> bool { - self.flags.contains(HAS_SCROLLING_OVERFLOW) + self.flags.contains(BlockFlowFlags::HAS_SCROLLING_OVERFLOW) } // Return offset from original position because of `position: sticky`. @@ -1824,7 +1820,7 @@ impl Flow for BlockFlow { _ => true, }; self.bubble_inline_sizes_for_block(consult_children); - self.fragment.restyle_damage.remove(BUBBLE_ISIZES); + self.fragment.restyle_damage.remove(ServoRestyleDamage::BUBBLE_ISIZES); } /// Recursively (top-down) determines the actual inline-size of child contexts and fragments. @@ -1874,13 +1870,14 @@ impl Flow for BlockFlow { } let is_formatting_context = self.formatting_context_type() != FormattingContextType::None; - if !self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) && is_formatting_context { + if !self.base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) && is_formatting_context { self.assign_inline_position_for_formatting_context(layout_context, content_box); } if (self as &Flow).floats_might_flow_through() { self.base.thread_id = parent_thread_id; - if self.base.restyle_damage.intersects(REFLOW_OUT_OF_FLOW | REFLOW) { + if self.base.restyle_damage.intersects(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | + ServoRestyleDamage::REFLOW) { self.assign_block_size(layout_context); // Don't remove the restyle damage; `assign_block_size` decides whether that is // appropriate (which in the case of e.g. absolutely-positioned flows, it is not). @@ -1914,7 +1911,7 @@ impl Flow for BlockFlow { // Assign block-size for fragment if it is an image fragment. self.fragment.assign_replaced_block_size_if_necessary(); - if !self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) { + if !self.base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { self.base.position.size.block = self.fragment.border_box.size.block; let mut block_start = AdjoiningMargins::from_margin(self.fragment.margin.block_start); let block_end = AdjoiningMargins::from_margin(self.fragment.margin.block_end); @@ -1924,13 +1921,14 @@ impl Flow for BlockFlow { } else { self.base.collapsible_margins = CollapsibleMargins::Collapse(block_start, block_end); } - self.base.restyle_damage.remove(REFLOW_OUT_OF_FLOW | REFLOW); - self.fragment.restyle_damage.remove(REFLOW_OUT_OF_FLOW | REFLOW); + self.base.restyle_damage.remove(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW); + self.fragment.restyle_damage.remove(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | + ServoRestyleDamage::REFLOW); } None } else if self.is_root() || self.formatting_context_type() != FormattingContextType::None || - self.base.flags.contains(MARGINS_CANNOT_COLLAPSE) { + self.base.flags.contains(FlowFlags::MARGINS_CANNOT_COLLAPSE) { // Root element margins should never be collapsed according to CSS § 8.3.1. debug!("assign_block_size: assigning block_size for root flow {:?}", flow::base(self).debug_id()); @@ -1957,7 +1955,7 @@ impl Flow for BlockFlow { self.base.clip = max_rect(); } - if self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) { + if self.base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { let position_start = self.base.position.start.to_physical(self.base.writing_mode, container_size); @@ -1975,17 +1973,17 @@ impl Flow for BlockFlow { }; if !self.base.writing_mode.is_vertical() { - if !self.base.flags.contains(INLINE_POSITION_IS_STATIC) { + if !self.base.flags.contains(FlowFlags::INLINE_POSITION_IS_STATIC) { self.base.stacking_relative_position.x = absolute_stacking_relative_position.x } - if !self.base.flags.contains(BLOCK_POSITION_IS_STATIC) { + if !self.base.flags.contains(FlowFlags::BLOCK_POSITION_IS_STATIC) { self.base.stacking_relative_position.y = absolute_stacking_relative_position.y } } else { - if !self.base.flags.contains(INLINE_POSITION_IS_STATIC) { + if !self.base.flags.contains(FlowFlags::INLINE_POSITION_IS_STATIC) { self.base.stacking_relative_position.y = absolute_stacking_relative_position.y } - if !self.base.flags.contains(BLOCK_POSITION_IS_STATIC) { + if !self.base.flags.contains(FlowFlags::BLOCK_POSITION_IS_STATIC) { self.base.stacking_relative_position.x = absolute_stacking_relative_position.x } } @@ -2058,28 +2056,28 @@ impl Flow for BlockFlow { // Process children. for kid in self.base.child_iter_mut() { - if flow::base(kid).flags.contains(INLINE_POSITION_IS_STATIC) || - flow::base(kid).flags.contains(BLOCK_POSITION_IS_STATIC) { + if flow::base(kid).flags.contains(FlowFlags::INLINE_POSITION_IS_STATIC) || + flow::base(kid).flags.contains(FlowFlags::BLOCK_POSITION_IS_STATIC) { let kid_base = flow::mut_base(kid); let physical_position = kid_base.position.to_physical(kid_base.writing_mode, container_size_for_children); // Set the inline and block positions as necessary. if !kid_base.writing_mode.is_vertical() { - if kid_base.flags.contains(INLINE_POSITION_IS_STATIC) { + if kid_base.flags.contains(FlowFlags::INLINE_POSITION_IS_STATIC) { kid_base.stacking_relative_position.x = origin_for_children.x + physical_position.origin.x } - if kid_base.flags.contains(BLOCK_POSITION_IS_STATIC) { + if kid_base.flags.contains(FlowFlags::BLOCK_POSITION_IS_STATIC) { kid_base.stacking_relative_position.y = origin_for_children.y + physical_position.origin.y } } else { - if kid_base.flags.contains(INLINE_POSITION_IS_STATIC) { + if kid_base.flags.contains(FlowFlags::INLINE_POSITION_IS_STATIC) { kid_base.stacking_relative_position.y = origin_for_children.y + physical_position.origin.y } - if kid_base.flags.contains(BLOCK_POSITION_IS_STATIC) { + if kid_base.flags.contains(FlowFlags::BLOCK_POSITION_IS_STATIC) { kid_base.stacking_relative_position.x = origin_for_children.x + physical_position.origin.x } @@ -2092,11 +2090,11 @@ impl Flow for BlockFlow { } fn mark_as_root(&mut self) { - self.flags.insert(IS_ROOT) + self.flags.insert(BlockFlowFlags::IS_ROOT) } fn is_root(&self) -> bool { - self.flags.contains(IS_ROOT) + self.flags.contains(BlockFlowFlags::IS_ROOT) } /// The 'position' property of this flow. @@ -2122,7 +2120,7 @@ impl Flow for BlockFlow { } fn update_late_computed_inline_position_if_necessary(&mut self, inline_position: Au) { - if self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) && + if self.base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) && self.fragment.style().logical_position().inline_start == LengthOrPercentageOrAuto::Auto && self.fragment.style().logical_position().inline_end == @@ -2132,7 +2130,7 @@ impl Flow for BlockFlow { } fn update_late_computed_block_position_if_necessary(&mut self, block_position: Au) { - if self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) && + if self.base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) && self.fragment.style().logical_position().block_start == LengthOrPercentageOrAuto::Auto && self.fragment.style().logical_position().block_end == @@ -2748,7 +2746,7 @@ impl ISizeAndMarginsComputer for AbsoluteNonReplaced { block: &mut BlockFlow, solution: ISizeConstraintSolution) { // Set the inline position of the absolute flow wrt to its containing block. - if !block.base.flags.contains(INLINE_POSITION_IS_STATIC) { + if !block.base.flags.contains(FlowFlags::INLINE_POSITION_IS_STATIC) { block.base.position.start.i = solution.inline_start; } } diff --git a/components/layout/construct.rs b/components/layout/construct.rs index 3ad9ffcbe8a..888348e3688 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -16,22 +16,19 @@ use ServoArc; use block::BlockFlow; use context::{LayoutContext, with_thread_local_font_context}; -use data::{HAS_NEWLY_CONSTRUCTED_FLOW, LayoutData}; +use data::{LayoutDataFlags, LayoutData}; use flex::FlexFlow; use floats::FloatKind; use flow::{self, AbsoluteDescendants, Flow, FlowClass, ImmutableFlowUtils}; -use flow::{CAN_BE_FRAGMENTED, IS_ABSOLUTELY_POSITIONED, MARGINS_CANNOT_COLLAPSE}; -use flow::{MutableFlowUtils, MutableOwnedFlowUtils}; +use flow::{FlowFlags, MutableFlowUtils, MutableOwnedFlowUtils}; use flow_ref::FlowRef; use fragment::{CanvasFragmentInfo, ImageFragmentInfo, InlineAbsoluteFragmentInfo, SvgFragmentInfo}; -use fragment::{Fragment, GeneratedContentInfo, IframeFragmentInfo}; -use fragment::{IS_INLINE_FLEX_ITEM, IS_BLOCK_FLEX_ITEM}; +use fragment::{Fragment, GeneratedContentInfo, IframeFragmentInfo, FragmentFlags}; use fragment::{InlineAbsoluteHypotheticalFragmentInfo, TableColumnFragmentInfo}; use fragment::{InlineBlockFragmentInfo, SpecificFragmentInfo, UnscannedTextFragmentInfo}; use fragment::WhitespaceStrippingResult; use gfx::display_list::OpaqueNode; -use inline::{FIRST_FRAGMENT_OF_ELEMENT, InlineFlow}; -use inline::{InlineFragmentNodeInfo, LAST_FRAGMENT_OF_ELEMENT}; +use inline::{InlineFlow, InlineFragmentNodeInfo, InlineFragmentNodeFlags}; use linked_list::prepend_from; use list_item::{ListItemFlow, ListStyleTypeContent}; use multicol::{MulticolColumnFlow, MulticolFlow}; @@ -54,7 +51,7 @@ use style::logical_geometry::Direction; use style::properties::ComputedValues; use style::properties::longhands::list_style_image; use style::selector_parser::{PseudoElement, RestyleDamage}; -use style::servo::restyle_damage::{BUBBLE_ISIZES, RECONSTRUCT_FLOW}; +use style::servo::restyle_damage::ServoRestyleDamage; use style::values::Either; use table::TableFlow; use table_caption::TableCaptionFlow; @@ -173,7 +170,7 @@ impl InlineBlockSplit { -> InlineBlockSplit { fragment_accumulator.enclosing_node.as_mut().expect( "enclosing_node is None; Are {ib} splits being generated outside of an inline node?" - ).flags.remove(LAST_FRAGMENT_OF_ELEMENT); + ).flags.remove(InlineFragmentNodeFlags::LAST_FRAGMENT_OF_ELEMENT); let split = InlineBlockSplit { predecessors: mem::replace( @@ -183,7 +180,8 @@ impl InlineBlockSplit { flow: flow, }; - fragment_accumulator.enclosing_node.as_mut().unwrap().flags.remove(FIRST_FRAGMENT_OF_ELEMENT); + fragment_accumulator.enclosing_node.as_mut().unwrap().flags.remove( + InlineFragmentNodeFlags::FIRST_FRAGMENT_OF_ELEMENT); split } @@ -258,7 +256,8 @@ impl InlineFragmentsAccumulator { pseudo: node.get_pseudo_element_type().strip(), style: node.style(style_context), selected_style: node.selected_style(), - flags: FIRST_FRAGMENT_OF_ELEMENT | LAST_FRAGMENT_OF_ELEMENT, + flags: InlineFragmentNodeFlags::FIRST_FRAGMENT_OF_ELEMENT | + InlineFragmentNodeFlags::LAST_FRAGMENT_OF_ELEMENT, }), bidi_control_chars: None, restyle_damage: node.restyle_damage(), @@ -287,17 +286,18 @@ impl InlineFragmentsAccumulator { for (index, fragment) in fragments.fragments.iter_mut().enumerate() { let mut enclosing_node = enclosing_node.clone(); if index != 0 { - enclosing_node.flags.remove(FIRST_FRAGMENT_OF_ELEMENT) + enclosing_node.flags.remove(InlineFragmentNodeFlags::FIRST_FRAGMENT_OF_ELEMENT) } if index != fragment_count - 1 { - enclosing_node.flags.remove(LAST_FRAGMENT_OF_ELEMENT) + enclosing_node.flags.remove(InlineFragmentNodeFlags::LAST_FRAGMENT_OF_ELEMENT) } fragment.add_inline_context_style(enclosing_node); } // Control characters are later discarded in transform_text, so they don't affect the // is_first/is_last styles above. - enclosing_node.flags.remove(FIRST_FRAGMENT_OF_ELEMENT | LAST_FRAGMENT_OF_ELEMENT); + enclosing_node.flags.remove(InlineFragmentNodeFlags::FIRST_FRAGMENT_OF_ELEMENT | + InlineFragmentNodeFlags::LAST_FRAGMENT_OF_ELEMENT); if let Some((start, end)) = bidi_control_chars { fragments.fragments.push_front( @@ -493,7 +493,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> ConstructionResult::Flow(kid_flow, AbsoluteDescendants::new()); self.set_flow_construction_result(&kid, construction_result) } else { - if !flow::base(&*kid_flow).flags.contains(IS_ABSOLUTELY_POSITIONED) { + if !flow::base(&*kid_flow).flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { // Flush any inline fragments that we were gathering up. This allows us to // handle {ib} splits. let old_inline_fragment_accumulator = @@ -621,7 +621,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> flow.set_absolute_descendants(abs_descendants); abs_descendants = AbsoluteDescendants::new(); - if flow::base(&*flow).flags.contains(IS_ABSOLUTELY_POSITIONED) { + if flow::base(&*flow).flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { // This is now the only absolute flow in the subtree which hasn't yet // reached its CB. abs_descendants.push(flow.clone()); @@ -776,7 +776,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> match kid.get_construction_result() { ConstructionResult::None => {} ConstructionResult::Flow(flow, kid_abs_descendants) => { - if !flow::base(&*flow).flags.contains(IS_ABSOLUTELY_POSITIONED) { + if !flow::base(&*flow).flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { opt_inline_block_splits.push_back(InlineBlockSplit::new( &mut fragment_accumulator, node, self.style_context(), flow)); abs_descendants.push_descendants(kid_abs_descendants); @@ -1066,7 +1066,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> abs_descendants = AbsoluteDescendants::new(); - if flow::base(&*flow).flags.contains(IS_ABSOLUTELY_POSITIONED) { + if flow::base(&*flow).flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { // This is now the only absolute flow in the subtree which hasn't yet // reached its containing block. abs_descendants.push(flow.clone()); @@ -1137,7 +1137,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> abs_descendants = AbsoluteDescendants::new(); - if flow::base(&*wrapper_flow).flags.contains(IS_ABSOLUTELY_POSITIONED) { + if flow::base(&*wrapper_flow).flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { // This is now the only absolute flow in the subtree which hasn't yet // reached its containing block. abs_descendants.push(wrapper_flow.clone()); @@ -1332,8 +1332,8 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> } for kid in node.children() { - if kid.flags().contains(HAS_NEWLY_CONSTRUCTED_FLOW) { - kid.remove_flags(HAS_NEWLY_CONSTRUCTED_FLOW); + if kid.flags().contains(LayoutDataFlags::HAS_NEWLY_CONSTRUCTED_FLOW) { + kid.remove_flags(LayoutDataFlags::HAS_NEWLY_CONSTRUCTED_FLOW); need_to_reconstruct = true } } @@ -1342,7 +1342,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> return false } - if node.restyle_damage().contains(RECONSTRUCT_FLOW) { + if node.restyle_damage().contains(ServoRestyleDamage::RECONSTRUCT_FLOW) { return false } @@ -1436,7 +1436,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> } }; if set_has_newly_constructed_flow_flag { - node.insert_flags(HAS_NEWLY_CONSTRUCTED_FLOW); + node.insert_flags(LayoutDataFlags::HAS_NEWLY_CONSTRUCTED_FLOW); } return result; } @@ -1452,7 +1452,7 @@ impl<'a, ConcreteThreadSafeLayoutNode> PostorderNodeMutTraversal<ConcreteThreadS // TODO: This should actually consult the table in that section to get the // final computed value for 'display'. fn process(&mut self, node: &ConcreteThreadSafeLayoutNode) { - node.insert_flags(HAS_NEWLY_CONSTRUCTED_FLOW); + node.insert_flags(LayoutDataFlags::HAS_NEWLY_CONSTRUCTED_FLOW); // Bail out if this node has an ancestor with display: none. if node.style(self.style_context()).is_in_display_none_subtree() { @@ -1654,7 +1654,7 @@ impl<ConcreteThreadSafeLayoutNode> NodeUtils for ConcreteThreadSafeLayoutNode fn set_flow_construction_result(self, mut result: ConstructionResult) { if self.can_be_fragmented() { if let ConstructionResult::Flow(ref mut flow, _) = result { - flow::mut_base(FlowRef::deref_mut(flow)).flags.insert(CAN_BE_FRAGMENTED); + flow::mut_base(FlowRef::deref_mut(flow)).flags.insert(FlowFlags::CAN_BE_FRAGMENTED); } } @@ -1744,7 +1744,7 @@ impl FlowConstructionUtils for FlowRef { fn finish(&mut self) { if !opts::get().bubble_inline_sizes_separately { FlowRef::deref_mut(self).bubble_inline_sizes(); - flow::mut_base(FlowRef::deref_mut(self)).restyle_damage.remove(BUBBLE_ISIZES); + flow::mut_base(FlowRef::deref_mut(self)).restyle_damage.remove(ServoRestyleDamage::BUBBLE_ISIZES); } } } @@ -1945,7 +1945,7 @@ impl Legalizer { } (FlowClass::Flex, FlowClass::Inline) => { - flow::mut_base(FlowRef::deref_mut(child)).flags.insert(MARGINS_CANNOT_COLLAPSE); + flow::mut_base(FlowRef::deref_mut(child)).flags.insert(FlowFlags::MARGINS_CANNOT_COLLAPSE); let mut block_wrapper = Legalizer::create_anonymous_flow(context, parent, @@ -1954,12 +1954,12 @@ impl Legalizer { BlockFlow::from_fragment); { let flag = if parent.as_flex().main_mode() == Direction::Inline { - IS_INLINE_FLEX_ITEM + FragmentFlags::IS_INLINE_FLEX_ITEM } else { - IS_BLOCK_FLEX_ITEM + FragmentFlags::IS_BLOCK_FLEX_ITEM }; let block = FlowRef::deref_mut(&mut block_wrapper).as_mut_block(); - block.base.flags.insert(MARGINS_CANNOT_COLLAPSE); + block.base.flags.insert(FlowFlags::MARGINS_CANNOT_COLLAPSE); block.fragment.flags.insert(flag); } block_wrapper.add_new_child((*child).clone()); @@ -1971,12 +1971,12 @@ impl Legalizer { (FlowClass::Flex, _) => { { let flag = if parent.as_flex().main_mode() == Direction::Inline { - IS_INLINE_FLEX_ITEM + FragmentFlags::IS_INLINE_FLEX_ITEM } else { - IS_BLOCK_FLEX_ITEM + FragmentFlags::IS_BLOCK_FLEX_ITEM }; let block = FlowRef::deref_mut(child).as_mut_block(); - block.base.flags.insert(MARGINS_CANNOT_COLLAPSE); + block.base.flags.insert(FlowFlags::MARGINS_CANNOT_COLLAPSE); block.fragment.flags.insert(flag); } parent.add_new_child((*child).clone()); diff --git a/components/layout/data.rs b/components/layout/data.rs index ef2195a9f31..20ff5ef2b71 100644 --- a/components/layout/data.rs +++ b/components/layout/data.rs @@ -60,10 +60,10 @@ impl LayoutData { } bitflags! { - pub flags LayoutDataFlags: u8 { + pub struct LayoutDataFlags: u8 { #[doc = "Whether a flow has been newly constructed."] - const HAS_NEWLY_CONSTRUCTED_FLOW = 0x01, + const HAS_NEWLY_CONSTRUCTED_FLOW = 0x01; #[doc = "Whether this node has been traversed by layout."] - const HAS_BEEN_TRAVERSED = 0x02, + const HAS_BEEN_TRAVERSED = 0x02; } } diff --git a/components/layout/display_list_builder.rs b/components/layout/display_list_builder.rs index 170b662662c..6118bfaa8ce 100644 --- a/components/layout/display_list_builder.rs +++ b/components/layout/display_list_builder.rs @@ -17,7 +17,7 @@ use context::LayoutContext; use euclid::{Point2D, Rect, SideOffsets2D, Size2D, Transform3D, TypedSize2D}; use euclid::Vector2D; use flex::FlexFlow; -use flow::{BaseFlow, Flow, IS_ABSOLUTELY_POSITIONED}; +use flow::{BaseFlow, Flow, FlowFlags}; use flow_ref::FlowRef; use fnv::FnvHashMap; use fragment::{CanvasFragmentSource, CoordinateSystem, Fragment, ImageFragmentInfo, ScannedTextFragmentInfo}; @@ -32,7 +32,7 @@ use gfx::display_list::{PopAllTextShadowsDisplayItem, PushTextShadowDisplayItem} use gfx::display_list::{RadialGradientDisplayItem, SolidColorDisplayItem, StackingContext}; use gfx::display_list::{StackingContextType, TextDisplayItem, TextOrientation, WebRenderImageInfo}; use gfx_traits::{combine_id_with_fragment_type, FragmentType, StackingContextId}; -use inline::{FIRST_FRAGMENT_OF_ELEMENT, InlineFlow, LAST_FRAGMENT_OF_ELEMENT}; +use inline::{InlineFragmentNodeFlags, InlineFlow}; use ipc_channel::ipc; use list_item::ListItemFlow; use model::{self, MaybeAuto}; @@ -54,7 +54,7 @@ use style::logical_geometry::{LogicalMargin, LogicalPoint, LogicalRect, LogicalS use style::properties::ComputedValues; use style::properties::longhands::border_image_repeat::computed_value::RepeatKeyword; use style::properties::style_structs; -use style::servo::restyle_damage::REPAINT; +use style::servo::restyle_damage::ServoRestyleDamage; use style::values::{Either, RGBA}; use style::values::computed::{Angle, Gradient, GradientItem, LengthOrPercentage, Percentage}; use style::values::computed::{LengthOrPercentageOrAuto, NumberOrPercentage, Position}; @@ -105,7 +105,8 @@ fn convert_repeat_mode(from: RepeatKeyword) -> RepeatMode { fn establishes_containing_block_for_absolute(flags: StackingContextCollectionFlags, positioning: position::T) -> bool { - !flags.contains(NEVER_CREATES_CONTAINING_BLOCK) && position::T::static_ != positioning + !flags.contains(StackingContextCollectionFlags::NEVER_CREATES_CONTAINING_BLOCK) && + position::T::static_ != positioning } trait RgbColor { @@ -1868,7 +1869,7 @@ impl FragmentDisplayListBuilding for Fragment { border_painting_mode: BorderPaintingMode, display_list_section: DisplayListSection, clip: &Rect<Au>) { - self.restyle_damage.remove(REPAINT); + self.restyle_damage.remove(ServoRestyleDamage::REPAINT); if self.style().get_inheritedbox().visibility != visibility::T::visible { return } @@ -1914,8 +1915,10 @@ impl FragmentDisplayListBuilding for Fragment { state, &*node.style, Some(InlineNodeBorderInfo { - is_first_fragment_of_element: node.flags.contains(FIRST_FRAGMENT_OF_ELEMENT), - is_last_fragment_of_element: node.flags.contains(LAST_FRAGMENT_OF_ELEMENT), + is_first_fragment_of_element: + node.flags.contains(InlineFragmentNodeFlags::FIRST_FRAGMENT_OF_ELEMENT), + is_last_fragment_of_element: + node.flags.contains(InlineFragmentNodeFlags::LAST_FRAGMENT_OF_ELEMENT), }), border_painting_mode, &stacking_relative_border_box, @@ -2393,13 +2396,13 @@ impl FragmentDisplayListBuilding for Fragment { } bitflags! { - pub flags StackingContextCollectionFlags: u8 { + pub struct StackingContextCollectionFlags: u8 { /// This flow never establishes a containing block. - const NEVER_CREATES_CONTAINING_BLOCK = 0b001, + const NEVER_CREATES_CONTAINING_BLOCK = 0b001; /// This flow never creates a ClipScrollNode. - const NEVER_CREATES_CLIP_SCROLL_NODE = 0b010, + const NEVER_CREATES_CLIP_SCROLL_NODE = 0b010; /// This flow never creates a stacking context. - const NEVER_CREATES_STACKING_CONTEXT = 0b100, + const NEVER_CREATES_STACKING_CONTEXT = 0b100; } } @@ -2657,7 +2660,7 @@ impl BlockFlowDisplayListBuilding for BlockFlow { self.transform_clip_to_coordinate_space(state, preserved_state); } - if !flags.contains(NEVER_CREATES_CLIP_SCROLL_NODE) { + if !flags.contains(StackingContextCollectionFlags::NEVER_CREATES_CLIP_SCROLL_NODE) { self.setup_clip_scroll_node_for_position(state, &stacking_relative_border_box); self.setup_clip_scroll_node_for_overflow(state, &stacking_relative_border_box); self.setup_clip_scroll_node_for_css_clip(state, preserved_state, @@ -2667,7 +2670,7 @@ impl BlockFlowDisplayListBuilding for BlockFlow { // We keep track of our position so that any stickily positioned elements can // properly determine the extent of their movement relative to scrolling containers. - if !flags.contains(NEVER_CREATES_CONTAINING_BLOCK) { + if !flags.contains(StackingContextCollectionFlags::NEVER_CREATES_CONTAINING_BLOCK) { let border_box = if self.fragment.establishes_stacking_context() { stacking_relative_border_box } else { @@ -2884,7 +2887,7 @@ impl BlockFlowDisplayListBuilding for BlockFlow { parent_stacking_context_id: StackingContextId, parent_clip_and_scroll_info: ClipAndScrollInfo, state: &mut StackingContextCollectionState) { - let creation_mode = if self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) || + let creation_mode = if self.base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) || self.fragment.style.get_box().position != position::T::static_ { StackingContextType::PseudoPositioned } else { @@ -2940,7 +2943,7 @@ impl BlockFlowDisplayListBuilding for BlockFlow { border_painting_mode: BorderPaintingMode) { let background_border_section = if self.base.flags.is_float() { DisplayListSection::BackgroundAndBorders - } else if self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) { + } else if self.base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { if self.fragment.establishes_stacking_context() { DisplayListSection::BackgroundAndBorders } else { @@ -2976,7 +2979,7 @@ impl BlockFlowDisplayListBuilding for BlockFlow { &self, flags: StackingContextCollectionFlags, ) -> BlockStackingContextType { - if flags.contains(NEVER_CREATES_STACKING_CONTEXT) { + if flags.contains(StackingContextCollectionFlags::NEVER_CREATES_STACKING_CONTEXT) { return BlockStackingContextType::NonstackingContext; } @@ -2984,7 +2987,7 @@ impl BlockFlowDisplayListBuilding for BlockFlow { return BlockStackingContextType::StackingContext } - if self.base.flags.contains(IS_ABSOLUTELY_POSITIONED) { + if self.base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { return BlockStackingContextType::PseudoStackingContext } diff --git a/components/layout/flex.rs b/components/layout/flex.rs index 929b4cb1838..0e1d155f29b 100644 --- a/components/layout/flex.rs +++ b/components/layout/flex.rs @@ -14,8 +14,7 @@ use display_list_builder::StackingContextCollectionState; use euclid::Point2D; use floats::FloatKind; use flow; -use flow::{Flow, FlowClass, ImmutableFlowUtils, OpaqueFlow}; -use flow::{INLINE_POSITION_IS_STATIC, IS_ABSOLUTELY_POSITIONED}; +use flow::{Flow, FlowClass, ImmutableFlowUtils, OpaqueFlow, FlowFlags}; use fragment::{Fragment, FragmentBorderBoxIterator, Overflow}; use layout_debug; use model::{AdjoiningMargins, CollapsibleMargins}; @@ -25,7 +24,7 @@ use std::ops::Range; use style::computed_values::{align_content, align_self, flex_direction, flex_wrap, justify_content}; use style::logical_geometry::{Direction, LogicalSize}; use style::properties::ComputedValues; -use style::servo::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW}; +use style::servo::restyle_damage::ServoRestyleDamage; use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto, LengthOrPercentageOrNone}; use style::values::computed::flex::FlexBasis; use style::values::generics::flex::FlexBasis as GenericFlexBasis; @@ -449,7 +448,7 @@ impl FlexFlow { if !fixed_width { for kid in self.block_flow.base.children.iter_mut() { let base = flow::mut_base(kid); - let is_absolutely_positioned = base.flags.contains(IS_ABSOLUTELY_POSITIONED); + let is_absolutely_positioned = base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED); if !is_absolutely_positioned { let flex_item_inline_sizes = IntrinsicISizes { minimum_inline_size: base.intrinsic_inline_sizes.minimum_inline_size, @@ -475,7 +474,7 @@ impl FlexFlow { if !fixed_width { for kid in self.block_flow.base.children.iter_mut() { let base = flow::mut_base(kid); - let is_absolutely_positioned = base.flags.contains(IS_ABSOLUTELY_POSITIONED); + let is_absolutely_positioned = base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED); if !is_absolutely_positioned { computation.content_intrinsic_sizes.minimum_inline_size = max(computation.content_intrinsic_sizes.minimum_inline_size, @@ -518,7 +517,7 @@ impl FlexFlow { for kid in &mut self.items { let kid_base = flow::mut_base(children.get(kid.index)); kid_base.block_container_explicit_block_size = container_block_size; - if kid_base.flags.contains(INLINE_POSITION_IS_STATIC) { + if kid_base.flags.contains(FlowFlags::INLINE_POSITION_IS_STATIC) { // The inline-start margin edge of the child flow is at our inline-start content // edge, and its inline-size is our content inline-size. kid_base.position.start.i = @@ -855,7 +854,7 @@ impl Flow for FlexFlow { .iter() .enumerate() .filter(|&(_, flow)| { - !flow.as_block().base.flags.contains(IS_ABSOLUTELY_POSITIONED) + !flow.as_block().base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) }) .map(|(index, flow)| FlexItem::new(index, flow)) .collect(); @@ -873,7 +872,8 @@ impl Flow for FlexFlow { let _scope = layout_debug_scope!("flex::assign_inline_sizes {:x}", self.block_flow.base.debug_id()); debug!("assign_inline_sizes"); - if !self.block_flow.base.restyle_damage.intersects(REFLOW_OUT_OF_FLOW | REFLOW) { + if !self.block_flow.base.restyle_damage.intersects(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | + ServoRestyleDamage::REFLOW) { return } diff --git a/components/layout/floats.rs b/components/layout/floats.rs index 4996a9e49e6..1203a2187ae 100644 --- a/components/layout/floats.rs +++ b/components/layout/floats.rs @@ -4,7 +4,7 @@ use app_units::{Au, MAX_AU}; use block::FormattingContextType; -use flow::{self, CLEARS_LEFT, CLEARS_RIGHT, Flow, ImmutableFlowUtils}; +use flow::{self, Flow, FlowFlags, ImmutableFlowUtils}; use persistent_list::PersistentList; use std::cmp::{max, min}; use std::fmt; @@ -459,10 +459,10 @@ impl SpeculatedFloatPlacement { /// flow, computes the speculated inline size of the floats flowing in. pub fn compute_floats_in(&mut self, flow: &mut Flow) { let base_flow = flow::base(flow); - if base_flow.flags.contains(CLEARS_LEFT) { + if base_flow.flags.contains(FlowFlags::CLEARS_LEFT) { self.left = Au(0) } - if base_flow.flags.contains(CLEARS_RIGHT) { + if base_flow.flags.contains(FlowFlags::CLEARS_RIGHT) { self.right = Au(0) } } diff --git a/components/layout/flow.rs b/components/layout/flow.rs index 990e29e0238..2a91b329620 100644 --- a/components/layout/flow.rs +++ b/components/layout/flow.rs @@ -54,7 +54,7 @@ use style::context::SharedStyleContext; use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode}; use style::properties::ComputedValues; use style::selector_parser::RestyleDamage; -use style::servo::restyle_damage::{RECONSTRUCT_FLOW, REFLOW, REFLOW_OUT_OF_FLOW, REPAINT}; +use style::servo::restyle_damage::ServoRestyleDamage; use style::values::computed::LengthOrPercentageOrAuto; use table::TableFlow; use table_caption::TableCaptionFlow; @@ -253,7 +253,7 @@ pub trait Flow: HasBaseFlow + fmt::Debug + Sync + Send + 'static { if might_have_floats_in_or_out { mut_base(self).thread_id = parent_thread_id; self.assign_block_size(layout_context); - mut_base(self).restyle_damage.remove(REFLOW_OUT_OF_FLOW | REFLOW); + mut_base(self).restyle_damage.remove(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW); } might_have_floats_in_or_out } @@ -403,7 +403,7 @@ pub trait Flow: HasBaseFlow + fmt::Debug + Sync + Send + 'static { fn contains_positioned_fragments(&self) -> bool { self.contains_relatively_positioned_fragments() || - base(self).flags.contains(IS_ABSOLUTELY_POSITIONED) + base(self).flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) } fn contains_relatively_positioned_fragments(&self) -> bool { @@ -595,52 +595,52 @@ impl FlowClass { bitflags! { #[doc = "Flags used in flows."] - pub flags FlowFlags: u32 { + 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."] - const IS_ABSOLUTELY_POSITIONED = 0b0000_0000_0000_0000_0100_0000, + 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."] - const CLEARS_LEFT = 0b0000_0000_0000_0000_1000_0000, + 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."] - const CLEARS_RIGHT = 0b0000_0000_0000_0001_0000_0000, + 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."] - const FLOATS_LEFT = 0b0000_0000_0000_0010_0000_0000, + 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."] - const FLOATS_RIGHT = 0b0000_0000_0000_0100_0000_0000, + const FLOATS_RIGHT = 0b0000_0000_0000_0100_0000_0000; #[doc = "Text alignment. \ NB: If you update this, update `TEXT_ALIGN_SHIFT` below."] - const TEXT_ALIGN = 0b0000_0000_0111_1000_0000_0000, + const TEXT_ALIGN = 0b0000_0000_0111_1000_0000_0000; #[doc = "Whether this flow has a fragment with `counter-reset` or `counter-increment` \ styles."] - const AFFECTS_COUNTERS = 0b0000_0000_1000_0000_0000_0000, + 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."] - const HAS_COUNTER_AFFECTING_CHILDREN = 0b0000_0001_0000_0000_0000_0000, + 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."] - const INLINE_POSITION_IS_STATIC = 0b0000_0010_0000_0000_0000_0000, + 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."] - const BLOCK_POSITION_IS_STATIC = 0b0000_0100_0000_0000_0000_0000, + const BLOCK_POSITION_IS_STATIC = 0b0000_0100_0000_0000_0000_0000; /// Whether any ancestor is a fragmentation container - const CAN_BE_FRAGMENTED = 0b0000_1000_0000_0000_0000_0000, + const CAN_BE_FRAGMENTED = 0b0000_1000_0000_0000_0000_0000; /// Whether this flow contains any text and/or replaced fragments. - const CONTAINS_TEXT_OR_REPLACED_FRAGMENTS = 0b0001_0000_0000_0000_0000_0000, + const CONTAINS_TEXT_OR_REPLACED_FRAGMENTS = 0b0001_0000_0000_0000_0000_0000; /// Whether margins are prohibited from collapsing with this flow. - const MARGINS_CANNOT_COLLAPSE = 0b0010_0000_0000_0000_0000_0000, + const MARGINS_CANNOT_COLLAPSE = 0b0010_0000_0000_0000_0000_0000; } } @@ -652,20 +652,20 @@ static TEXT_ALIGN_SHIFT: usize = 11; impl FlowFlags { #[inline] pub fn text_align(self) -> text_align::T { - text_align::T::from_u32((self & TEXT_ALIGN).bits() >> TEXT_ALIGN_SHIFT).unwrap() + text_align::T::from_u32((self & FlowFlags::TEXT_ALIGN).bits() >> TEXT_ALIGN_SHIFT).unwrap() } #[inline] pub fn set_text_align(&mut self, value: text_align::T) { - *self = (*self & !TEXT_ALIGN) | + *self = (*self & !FlowFlags::TEXT_ALIGN) | FlowFlags::from_bits(value.to_u32() << TEXT_ALIGN_SHIFT).unwrap(); } #[inline] pub fn float_kind(&self) -> float::T { - if self.contains(FLOATS_LEFT) { + if self.contains(FlowFlags::FLOATS_LEFT) { float::T::left - } else if self.contains(FLOATS_RIGHT) { + } else if self.contains(FlowFlags::FLOATS_RIGHT) { float::T::right } else { float::T::none @@ -674,12 +674,12 @@ impl FlowFlags { #[inline] pub fn is_float(&self) -> bool { - self.contains(FLOATS_LEFT) || self.contains(FLOATS_RIGHT) + self.contains(FlowFlags::FLOATS_LEFT) || self.contains(FlowFlags::FLOATS_RIGHT) } #[inline] pub fn clears_floats(&self) -> bool { - self.contains(CLEARS_LEFT) || self.contains(CLEARS_RIGHT) + self.contains(FlowFlags::CLEARS_LEFT) || self.contains(FlowFlags::CLEARS_RIGHT) } } @@ -949,8 +949,8 @@ impl fmt::Debug for BaseFlow { overflow={:?}{}{}{}", self.stacking_context_id, self.position, - if self.flags.contains(FLOATS_LEFT) { "FL" } else { "" }, - if self.flags.contains(FLOATS_RIGHT) { "FR" } else { "" }, + if self.flags.contains(FlowFlags::FLOATS_LEFT) { "FL" } else { "" }, + if self.flags.contains(FlowFlags::FLOATS_RIGHT) { "FR" } else { "" }, self.speculated_float_placement_in, self.speculated_float_placement_out, self.overflow, @@ -993,50 +993,50 @@ impl BaseFlow { Some(style) => { match style.get_box().position { position::T::absolute | position::T::fixed => { - flags.insert(IS_ABSOLUTELY_POSITIONED); + flags.insert(FlowFlags::IS_ABSOLUTELY_POSITIONED); let logical_position = style.logical_position(); if logical_position.inline_start == LengthOrPercentageOrAuto::Auto && logical_position.inline_end == LengthOrPercentageOrAuto::Auto { - flags.insert(INLINE_POSITION_IS_STATIC); + flags.insert(FlowFlags::INLINE_POSITION_IS_STATIC); } if logical_position.block_start == LengthOrPercentageOrAuto::Auto && logical_position.block_end == LengthOrPercentageOrAuto::Auto { - flags.insert(BLOCK_POSITION_IS_STATIC); + flags.insert(FlowFlags::BLOCK_POSITION_IS_STATIC); } } - _ => flags.insert(BLOCK_POSITION_IS_STATIC | INLINE_POSITION_IS_STATIC), + _ => flags.insert(FlowFlags::BLOCK_POSITION_IS_STATIC | FlowFlags::INLINE_POSITION_IS_STATIC), } if force_nonfloated == ForceNonfloatedFlag::FloatIfNecessary { match style.get_box().float { float::T::none => {} - float::T::left => flags.insert(FLOATS_LEFT), - float::T::right => flags.insert(FLOATS_RIGHT), + float::T::left => flags.insert(FlowFlags::FLOATS_LEFT), + float::T::right => flags.insert(FlowFlags::FLOATS_RIGHT), } } match style.get_box().clear { clear::T::none => {} - clear::T::left => flags.insert(CLEARS_LEFT), - clear::T::right => flags.insert(CLEARS_RIGHT), + clear::T::left => flags.insert(FlowFlags::CLEARS_LEFT), + clear::T::right => flags.insert(FlowFlags::CLEARS_RIGHT), clear::T::both => { - flags.insert(CLEARS_LEFT); - flags.insert(CLEARS_RIGHT); + flags.insert(FlowFlags::CLEARS_LEFT); + flags.insert(FlowFlags::CLEARS_RIGHT); } } if !style.get_counters().counter_reset.0.is_empty() || !style.get_counters().counter_increment.0.is_empty() { - flags.insert(AFFECTS_COUNTERS) + flags.insert(FlowFlags::AFFECTS_COUNTERS) } } - None => flags.insert(BLOCK_POSITION_IS_STATIC | INLINE_POSITION_IS_STATIC), + None => flags.insert(FlowFlags::BLOCK_POSITION_IS_STATIC | FlowFlags::INLINE_POSITION_IS_STATIC), } // New flows start out as fully damaged. let mut damage = RestyleDamage::rebuild_and_reflow(); - damage.remove(RECONSTRUCT_FLOW); + damage.remove(ServoRestyleDamage::RECONSTRUCT_FLOW); BaseFlow { restyle_damage: damage, @@ -1073,15 +1073,15 @@ impl BaseFlow { pub fn update_flags_if_needed(&mut self, style: &ComputedValues) { // For absolutely-positioned flows, changes to top/bottom/left/right can cause these flags // to get out of date: - if self.restyle_damage.contains(REFLOW_OUT_OF_FLOW) { + if self.restyle_damage.contains(ServoRestyleDamage::REFLOW_OUT_OF_FLOW) { // Note: We don't need to check whether IS_ABSOLUTELY_POSITIONED has changed, because // changes to the 'position' property trigger flow reconstruction. - if self.flags.contains(IS_ABSOLUTELY_POSITIONED) { + if self.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { let logical_position = style.logical_position(); - self.flags.set(INLINE_POSITION_IS_STATIC, + self.flags.set(FlowFlags::INLINE_POSITION_IS_STATIC, logical_position.inline_start == LengthOrPercentageOrAuto::Auto && logical_position.inline_end == LengthOrPercentageOrAuto::Auto); - self.flags.set(BLOCK_POSITION_IS_STATIC, + self.flags.set(FlowFlags::BLOCK_POSITION_IS_STATIC, logical_position.block_start == LengthOrPercentageOrAuto::Auto && logical_position.block_end == LengthOrPercentageOrAuto::Auto); } @@ -1092,7 +1092,8 @@ impl BaseFlow { pub fn clone_with_children(&self, children: FlowList) -> BaseFlow { BaseFlow { children: children, - restyle_damage: self.restyle_damage | REPAINT | REFLOW_OUT_OF_FLOW | REFLOW, + restyle_damage: self.restyle_damage | ServoRestyleDamage::REPAINT | + ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW, parallel: FlowParallelInfo::new(), floats: self.floats.clone(), abs_descendants: self.abs_descendants.clone(), @@ -1290,7 +1291,7 @@ impl<'a> ImmutableFlowUtils for &'a Flow { return Some(base(kid).position.start.b + baseline_offset) } } - if kid.is_block_like() && !base(kid).flags.contains(IS_ABSOLUTELY_POSITIONED) { + if kid.is_block_like() && !base(kid).flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { if let Some(baseline_offset) = kid.baseline_offset_of_last_line_box_in_flow() { return Some(base(kid).position.start.b + baseline_offset) } diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index 153fe97992b..6e8cb41f9cd 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -19,8 +19,8 @@ use gfx::display_list::{BLUR_INFLATION_FACTOR, OpaqueNode}; use gfx::text::glyph::ByteIndex; use gfx::text::text_run::{TextRun, TextRunSlice}; use gfx_traits::StackingContextId; -use inline::{FIRST_FRAGMENT_OF_ELEMENT, InlineFragmentContext, InlineFragmentNodeInfo}; -use inline::{InlineMetrics, LAST_FRAGMENT_OF_ELEMENT, LineMetrics}; +use inline::{InlineFragmentNodeFlags, InlineFragmentContext, InlineFragmentNodeInfo}; +use inline::{InlineMetrics, LineMetrics}; use ipc_channel::ipc::IpcSender; #[cfg(debug_assertions)] use layout_debug; @@ -48,7 +48,7 @@ use style::logical_geometry::{Direction, LogicalMargin, LogicalRect, LogicalSize use style::properties::ComputedValues; use style::properties::longhands::transform::computed_value::T as TransformList; use style::selector_parser::RestyleDamage; -use style::servo::restyle_damage::RECONSTRUCT_FLOW; +use style::servo::restyle_damage::ServoRestyleDamage; use style::str::char_is_whitespace; use style::values::{self, Either, Auto}; use style::values::computed::{Length, LengthOrPercentage, LengthOrPercentageOrAuto}; @@ -533,13 +533,13 @@ pub struct ScannedTextFragmentInfo { } bitflags! { - pub flags ScannedTextFlags: u8 { + 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). - const REQUIRES_LINE_BREAK_AFTERWARD_IF_WRAPPING_ON_NEWLINES = 0x01, + const REQUIRES_LINE_BREAK_AFTERWARD_IF_WRAPPING_ON_NEWLINES = 0x01; /// Is this fragment selected? - const SELECTED = 0x02, + const SELECTED = 0x02; } } @@ -566,11 +566,11 @@ impl ScannedTextFragmentInfo { } pub fn requires_line_break_afterward_if_wrapping_on_newlines(&self) -> bool { - self.flags.contains(REQUIRES_LINE_BREAK_AFTERWARD_IF_WRAPPING_ON_NEWLINES) + self.flags.contains(ScannedTextFlags::REQUIRES_LINE_BREAK_AFTERWARD_IF_WRAPPING_ON_NEWLINES) } pub fn selected(&self) -> bool { - self.flags.contains(SELECTED) + self.flags.contains(ScannedTextFlags::SELECTED) } } @@ -671,7 +671,7 @@ impl Fragment { let writing_mode = style.writing_mode; let mut restyle_damage = node.restyle_damage(); - restyle_damage.remove(RECONSTRUCT_FLOW); + restyle_damage.remove(ServoRestyleDamage::RECONSTRUCT_FLOW); Fragment { node: node.opaque(), @@ -700,7 +700,7 @@ impl Fragment { -> Fragment { let writing_mode = style.writing_mode; - restyle_damage.remove(RECONSTRUCT_FLOW); + restyle_damage.remove(ServoRestyleDamage::RECONSTRUCT_FLOW); Fragment { node: node, @@ -753,7 +753,7 @@ impl Fragment { size); let mut restyle_damage = RestyleDamage::rebuild_and_reflow(); - restyle_damage.remove(RECONSTRUCT_FLOW); + restyle_damage.remove(ServoRestyleDamage::RECONSTRUCT_FLOW); Fragment { node: self.node, @@ -818,7 +818,7 @@ impl Fragment { }); debug_assert!(ellipsis_fragments.len() == 1); ellipsis_fragment = ellipsis_fragments.fragments.into_iter().next().unwrap(); - ellipsis_fragment.flags |= IS_ELLIPSIS; + ellipsis_fragment.flags |= FragmentFlags::IS_ELLIPSIS; ellipsis_fragment } @@ -858,35 +858,36 @@ impl Fragment { QuantitiesIncludedInIntrinsicInlineSizes::all() } SpecificFragmentInfo::Table => { - INTRINSIC_INLINE_SIZE_INCLUDES_SPECIFIED | - INTRINSIC_INLINE_SIZE_INCLUDES_PADDING | - INTRINSIC_INLINE_SIZE_INCLUDES_BORDER + QuantitiesIncludedInIntrinsicInlineSizes::INTRINSIC_INLINE_SIZE_INCLUDES_SPECIFIED | + QuantitiesIncludedInIntrinsicInlineSizes::INTRINSIC_INLINE_SIZE_INCLUDES_PADDING | + QuantitiesIncludedInIntrinsicInlineSizes::INTRINSIC_INLINE_SIZE_INCLUDES_BORDER } SpecificFragmentInfo::TableCell => { - let base_quantities = INTRINSIC_INLINE_SIZE_INCLUDES_PADDING | - INTRINSIC_INLINE_SIZE_INCLUDES_SPECIFIED; + let base_quantities = QuantitiesIncludedInIntrinsicInlineSizes::INTRINSIC_INLINE_SIZE_INCLUDES_PADDING | + QuantitiesIncludedInIntrinsicInlineSizes::INTRINSIC_INLINE_SIZE_INCLUDES_SPECIFIED; if self.style.get_inheritedtable().border_collapse == border_collapse::T::separate { - base_quantities | INTRINSIC_INLINE_SIZE_INCLUDES_BORDER + base_quantities | QuantitiesIncludedInIntrinsicInlineSizes::INTRINSIC_INLINE_SIZE_INCLUDES_BORDER } else { base_quantities } } SpecificFragmentInfo::TableWrapper => { - let base_quantities = INTRINSIC_INLINE_SIZE_INCLUDES_MARGINS | - INTRINSIC_INLINE_SIZE_INCLUDES_SPECIFIED; + let base_quantities = QuantitiesIncludedInIntrinsicInlineSizes::INTRINSIC_INLINE_SIZE_INCLUDES_MARGINS | + QuantitiesIncludedInIntrinsicInlineSizes::INTRINSIC_INLINE_SIZE_INCLUDES_SPECIFIED; if self.style.get_inheritedtable().border_collapse == border_collapse::T::separate { - base_quantities | INTRINSIC_INLINE_SIZE_INCLUDES_BORDER + base_quantities | QuantitiesIncludedInIntrinsicInlineSizes::INTRINSIC_INLINE_SIZE_INCLUDES_BORDER } else { base_quantities } } SpecificFragmentInfo::TableRow => { - let base_quantities = INTRINSIC_INLINE_SIZE_INCLUDES_SPECIFIED; + let base_quantities = + QuantitiesIncludedInIntrinsicInlineSizes::INTRINSIC_INLINE_SIZE_INCLUDES_SPECIFIED; if self.style.get_inheritedtable().border_collapse == border_collapse::T::separate { - base_quantities | INTRINSIC_INLINE_SIZE_INCLUDES_BORDER + base_quantities | QuantitiesIncludedInIntrinsicInlineSizes::INTRINSIC_INLINE_SIZE_INCLUDES_BORDER } else { base_quantities } @@ -914,7 +915,8 @@ impl Fragment { // FIXME(pcwalton): Percentages should be relative to any definite size per CSS-SIZING. // This will likely need to be done by pushing down definite sizes during selector // cascading. - let margin = if flags.contains(INTRINSIC_INLINE_SIZE_INCLUDES_MARGINS) { + let margin = if flags.contains( + QuantitiesIncludedInIntrinsicInlineSizes::INTRINSIC_INLINE_SIZE_INCLUDES_MARGINS) { let margin = style.logical_margin(); (MaybeAuto::from_style(margin.inline_start, Au(0)).specified_or_zero() + MaybeAuto::from_style(margin.inline_end, Au(0)).specified_or_zero()) @@ -925,7 +927,8 @@ impl Fragment { // FIXME(pcwalton): Percentages should be relative to any definite size per CSS-SIZING. // This will likely need to be done by pushing down definite sizes during selector // cascading. - let padding = if flags.contains(INTRINSIC_INLINE_SIZE_INCLUDES_PADDING) { + let padding = if flags.contains( + QuantitiesIncludedInIntrinsicInlineSizes::INTRINSIC_INLINE_SIZE_INCLUDES_PADDING) { let padding = style.logical_padding(); (padding.inline_start.to_used_value(Au(0)) + padding.inline_end.to_used_value(Au(0))) @@ -933,7 +936,8 @@ impl Fragment { Au(0) }; - let border = if flags.contains(INTRINSIC_INLINE_SIZE_INCLUDES_BORDER) { + let border = if flags.contains( + QuantitiesIncludedInIntrinsicInlineSizes::INTRINSIC_INLINE_SIZE_INCLUDES_BORDER) { self.border_width().inline_start_end() } else { Au(0) @@ -952,7 +956,7 @@ impl Fragment { let (border_padding, margin) = self.surrounding_intrinsic_inline_size(); let mut specified = Au(0); - if flags.contains(INTRINSIC_INLINE_SIZE_INCLUDES_SPECIFIED) { + if flags.contains(QuantitiesIncludedInIntrinsicInlineSizes::INTRINSIC_INLINE_SIZE_INCLUDES_SPECIFIED) { specified = MaybeAuto::from_style(style.content_inline_size(), Au(0)).specified_or_zero(); specified = max(style.min_inline_size().to_used_value(Au(0)), specified); @@ -1203,10 +1207,10 @@ impl Fragment { inline_fragment_context.nodes.iter().fold(style_border_width, |accumulator, node| { let mut this_border_width = node.style.border_width_for_writing_mode(writing_mode); - if !node.flags.contains(FIRST_FRAGMENT_OF_ELEMENT) { + if !node.flags.contains(InlineFragmentNodeFlags::FIRST_FRAGMENT_OF_ELEMENT) { this_border_width.inline_start = Au(0) } - if !node.flags.contains(LAST_FRAGMENT_OF_ELEMENT) { + if !node.flags.contains(InlineFragmentNodeFlags::LAST_FRAGMENT_OF_ELEMENT) { this_border_width.inline_end = Au(0) } accumulator + this_border_width @@ -1260,13 +1264,15 @@ impl Fragment { if let Some(ref inline_context) = self.inline_context { for node in &inline_context.nodes { let margin = node.style.logical_margin(); - let this_inline_start_margin = if !node.flags.contains(FIRST_FRAGMENT_OF_ELEMENT) { + let this_inline_start_margin = if !node.flags.contains( + InlineFragmentNodeFlags::FIRST_FRAGMENT_OF_ELEMENT) { Au(0) } else { MaybeAuto::from_style(margin.inline_start, containing_block_inline_size).specified_or_zero() }; - let this_inline_end_margin = if !node.flags.contains(LAST_FRAGMENT_OF_ELEMENT) { + let this_inline_end_margin = if!node.flags.contains( + InlineFragmentNodeFlags::LAST_FRAGMENT_OF_ELEMENT) { Au(0) } else { MaybeAuto::from_style(margin.inline_end, @@ -1339,10 +1345,10 @@ impl Fragment { let zero_padding = LogicalMargin::zero(writing_mode); inline_fragment_context.nodes.iter().fold(zero_padding, |accumulator, node| { let mut padding = model::padding_from_style(&*node.style, Au(0), writing_mode); - if !node.flags.contains(FIRST_FRAGMENT_OF_ELEMENT) { + if !node.flags.contains(InlineFragmentNodeFlags::FIRST_FRAGMENT_OF_ELEMENT) { padding.inline_start = Au(0) } - if !node.flags.contains(LAST_FRAGMENT_OF_ELEMENT) { + if !node.flags.contains(InlineFragmentNodeFlags::LAST_FRAGMENT_OF_ELEMENT) { padding.inline_end = Au(0) } accumulator + padding @@ -1584,12 +1590,12 @@ impl Fragment { let mut border_width = node.style.logical_border_width(); let mut padding = model::padding_from_style(&*node.style, Au(0), writing_mode); let mut margin = model::specified_margin_from_style(&*node.style, writing_mode); - if !node.flags.contains(FIRST_FRAGMENT_OF_ELEMENT) { + if !node.flags.contains(InlineFragmentNodeFlags::FIRST_FRAGMENT_OF_ELEMENT) { border_width.inline_start = Au(0); padding.inline_start = Au(0); margin.inline_start = Au(0); } - if !node.flags.contains(LAST_FRAGMENT_OF_ELEMENT) { + if !node.flags.contains(InlineFragmentNodeFlags::LAST_FRAGMENT_OF_ELEMENT) { border_width.inline_end = Au(0); padding.inline_end = Au(0); margin.inline_end = Au(0); @@ -1647,9 +1653,9 @@ impl Fragment { let mut flags = SplitOptions::empty(); if starts_line { - flags.insert(STARTS_LINE); + flags.insert(SplitOptions::STARTS_LINE); if self.style().get_inheritedtext().overflow_wrap == overflow_wrap::T::break_word { - flags.insert(RETRY_AT_CHARACTER_BOUNDARIES) + flags.insert(SplitOptions::RETRY_AT_CHARACTER_BOUNDARIES) } } @@ -1667,7 +1673,7 @@ impl Fragment { // Break at character boundaries. let character_breaking_strategy = text_fragment_info.run.character_slices_in_range(&text_fragment_info.range); - flags.remove(RETRY_AT_CHARACTER_BOUNDARIES); + flags.remove(SplitOptions::RETRY_AT_CHARACTER_BOUNDARIES); self.calculate_split_position_using_breaking_strategy( character_breaking_strategy, max_inline_size, @@ -1830,12 +1836,12 @@ impl Fragment { if split_is_empty || overflowing { // If we've been instructed to retry at character boundaries (probably via // `overflow-wrap: break-word`), do so. - if flags.contains(RETRY_AT_CHARACTER_BOUNDARIES) { + if flags.contains(SplitOptions::RETRY_AT_CHARACTER_BOUNDARIES) { let character_breaking_strategy = text_fragment_info.run .character_slices_in_range(&text_fragment_info.range); let mut flags = flags; - flags.remove(RETRY_AT_CHARACTER_BOUNDARIES); + flags.remove(SplitOptions::RETRY_AT_CHARACTER_BOUNDARIES); return self.calculate_split_position_using_breaking_strategy( character_breaking_strategy, max_inline_size, @@ -1844,7 +1850,7 @@ impl Fragment { // We aren't at the start of the line, so don't overflow. Let inline layout wrap to // the next line instead. - if !flags.contains(STARTS_LINE) { + if !flags.contains(SplitOptions::STARTS_LINE) { return None } } @@ -1880,7 +1886,7 @@ impl Fragment { this_info.range_end_including_stripped_whitespace = other_info.range_end_including_stripped_whitespace; if other_info.requires_line_break_afterward_if_wrapping_on_newlines() { - this_info.flags.insert(REQUIRES_LINE_BREAK_AFTERWARD_IF_WRAPPING_ON_NEWLINES); + this_info.flags.insert(ScannedTextFlags::REQUIRES_LINE_BREAK_AFTERWARD_IF_WRAPPING_ON_NEWLINES); } if other_info.insertion_point.is_some() { this_info.insertion_point = other_info.insertion_point; @@ -2340,7 +2346,7 @@ impl Fragment { // side, then we can't merge with the next fragment. if let Some(ref inline_context) = self.inline_context { for inline_context_node in inline_context.nodes.iter() { - if !inline_context_node.flags.contains(LAST_FRAGMENT_OF_ELEMENT) { + if !inline_context_node.flags.contains(InlineFragmentNodeFlags::LAST_FRAGMENT_OF_ELEMENT) { continue } if inline_context_node.style.logical_margin().inline_end != @@ -2361,7 +2367,7 @@ impl Fragment { // preceding side, then it can't merge with us. if let Some(ref inline_context) = other.inline_context { for inline_context_node in inline_context.nodes.iter() { - if !inline_context_node.flags.contains(FIRST_FRAGMENT_OF_ELEMENT) { + if !inline_context_node.flags.contains(InlineFragmentNodeFlags::FIRST_FRAGMENT_OF_ELEMENT) { continue } if inline_context_node.style.logical_margin().inline_start != @@ -2807,14 +2813,15 @@ impl Fragment { .zip(inline_context_of_next_fragment.nodes.iter().rev()) { if !inline_context_node_from_next_fragment.flags.contains( - LAST_FRAGMENT_OF_ELEMENT) { + InlineFragmentNodeFlags::LAST_FRAGMENT_OF_ELEMENT) { continue } if inline_context_node_from_next_fragment.address != inline_context_node_from_this_fragment.address { continue } - inline_context_node_from_this_fragment.flags.insert(LAST_FRAGMENT_OF_ELEMENT); + inline_context_node_from_this_fragment.flags.insert( + InlineFragmentNodeFlags::LAST_FRAGMENT_OF_ELEMENT); } } } @@ -2829,7 +2836,7 @@ impl Fragment { inline_context_of_this_fragment.nodes.iter_mut().rev()) { if !inline_context_node_from_prev_fragment.flags.contains( - FIRST_FRAGMENT_OF_ELEMENT) { + InlineFragmentNodeFlags::FIRST_FRAGMENT_OF_ELEMENT) { continue } if inline_context_node_from_prev_fragment.address != @@ -2837,7 +2844,7 @@ impl Fragment { continue } inline_context_node_from_this_fragment.flags.insert( - FIRST_FRAGMENT_OF_ELEMENT); + InlineFragmentNodeFlags::FIRST_FRAGMENT_OF_ELEMENT); } } } @@ -2978,23 +2985,23 @@ impl fmt::Debug for Fragment { } bitflags! { - flags QuantitiesIncludedInIntrinsicInlineSizes: u8 { - const INTRINSIC_INLINE_SIZE_INCLUDES_MARGINS = 0x01, - const INTRINSIC_INLINE_SIZE_INCLUDES_PADDING = 0x02, - const INTRINSIC_INLINE_SIZE_INCLUDES_BORDER = 0x04, - const INTRINSIC_INLINE_SIZE_INCLUDES_SPECIFIED = 0x08, + struct QuantitiesIncludedInIntrinsicInlineSizes: u8 { + const INTRINSIC_INLINE_SIZE_INCLUDES_MARGINS = 0x01; + const INTRINSIC_INLINE_SIZE_INCLUDES_PADDING = 0x02; + const INTRINSIC_INLINE_SIZE_INCLUDES_BORDER = 0x04; + const INTRINSIC_INLINE_SIZE_INCLUDES_SPECIFIED = 0x08; } } bitflags! { // Various flags we can use when splitting fragments. See // `calculate_split_position_using_breaking_strategy()`. - flags SplitOptions: u8 { + struct SplitOptions: u8 { #[doc = "True if this is the first fragment on the line."] - const STARTS_LINE = 0x01, + 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`."] - const RETRY_AT_CHARACTER_BOUNDARIES = 0x02, + const RETRY_AT_CHARACTER_BOUNDARIES = 0x02; } } @@ -3110,14 +3117,14 @@ impl Overflow { } bitflags! { - pub flags FragmentFlags: u8 { + 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. - const IS_INLINE_FLEX_ITEM = 0b0000_0001, + const IS_INLINE_FLEX_ITEM = 0b0000_0001; /// Whether this fragment represents a child in a column flex container. - const IS_BLOCK_FLEX_ITEM = 0b0000_0010, + const IS_BLOCK_FLEX_ITEM = 0b0000_0010; /// Whether this fragment represents the generated text from a text-overflow clip. - const IS_ELLIPSIS = 0b0000_0100, + const IS_ELLIPSIS = 0b0000_0100; } } diff --git a/components/layout/generated_content.rs b/components/layout/generated_content.rs index e8e94cb25a7..153a250caf1 100644 --- a/components/layout/generated_content.rs +++ b/components/layout/generated_content.rs @@ -9,7 +9,7 @@ //! as possible. use context::{LayoutContext, with_thread_local_font_context}; -use flow::{self, AFFECTS_COUNTERS, Flow, HAS_COUNTER_AFFECTING_CHILDREN, ImmutableFlowUtils}; +use flow::{self, Flow, FlowFlags, ImmutableFlowUtils}; use fragment::{Fragment, GeneratedContentInfo, SpecificFragmentInfo, UnscannedTextFragmentInfo}; use gfx::display_list::OpaqueNode; use script_layout_interface::wrapper_traits::PseudoElementType; @@ -19,7 +19,7 @@ use style::computed_values::{display, list_style_type}; use style::computed_values::content::ContentItem; use style::properties::ComputedValues; use style::selector_parser::RestyleDamage; -use style::servo::restyle_damage::RESOLVE_GENERATED_CONTENT; +use style::servo::restyle_damage::ServoRestyleDamage; use text::TextRunScanner; use traversal::InorderFlowTraversal; @@ -131,8 +131,8 @@ impl<'a> InorderFlowTraversal for ResolveGeneratedContent<'a> { #[inline] fn should_process_subtree(&mut self, flow: &mut Flow) -> bool { - flow::base(flow).restyle_damage.intersects(RESOLVE_GENERATED_CONTENT) || - flow::base(flow).flags.intersects(AFFECTS_COUNTERS | HAS_COUNTER_AFFECTING_CHILDREN) + flow::base(flow).restyle_damage.intersects(ServoRestyleDamage::RESOLVE_GENERATED_CONTENT) || + flow::base(flow).flags.intersects(FlowFlags::AFFECTS_COUNTERS | FlowFlags::HAS_COUNTER_AFFECTING_CHILDREN) } } diff --git a/components/layout/incremental.rs b/components/layout/incremental.rs index dd6b125938f..b3f8a58040b 100644 --- a/components/layout/incremental.rs +++ b/components/layout/incremental.rs @@ -2,10 +2,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use flow::{self, AFFECTS_COUNTERS, Flow, HAS_COUNTER_AFFECTING_CHILDREN, IS_ABSOLUTELY_POSITIONED}; +use flow::{self, FlowFlags, Flow}; use style::computed_values::float; use style::selector_parser::RestyleDamage; -use style::servo::restyle_damage::{REFLOW, RECONSTRUCT_FLOW}; +use style::servo::restyle_damage::ServoRestyleDamage; /// Used in a flow traversal to indicate whether this re-layout should be incremental or not. #[derive(Clone, Copy, PartialEq)] @@ -15,10 +15,10 @@ pub enum RelayoutMode { } bitflags! { - pub flags SpecialRestyleDamage: u8 { + 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."] - const REFLOW_ENTIRE_DOCUMENT = 0x01, + const REFLOW_ENTIRE_DOCUMENT = 0x01; } } @@ -30,7 +30,7 @@ pub trait LayoutDamageComputation { impl<'a> LayoutDamageComputation for &'a mut Flow { fn compute_layout_damage(self) -> SpecialRestyleDamage { let mut special_damage = SpecialRestyleDamage::empty(); - let is_absolutely_positioned = flow::base(self).flags.contains(IS_ABSOLUTELY_POSITIONED); + let is_absolutely_positioned = flow::base(self).flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED); // In addition to damage, we use this phase to compute whether nodes affect CSS counters. let mut has_counter_affecting_children = false; @@ -42,7 +42,7 @@ impl<'a> LayoutDamageComputation for &'a mut Flow { for kid in self_base.children.iter_mut() { let child_is_absolutely_positioned = - flow::base(kid).flags.contains(IS_ABSOLUTELY_POSITIONED); + flow::base(kid).flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED); flow::mut_base(kid).restyle_damage.insert( parent_damage.damage_for_child(is_absolutely_positioned, child_is_absolutely_positioned)); @@ -55,21 +55,21 @@ impl<'a> LayoutDamageComputation for &'a mut Flow { child_is_absolutely_positioned)); has_counter_affecting_children = has_counter_affecting_children || - flow::base(kid).flags.intersects(AFFECTS_COUNTERS | - HAS_COUNTER_AFFECTING_CHILDREN); + flow::base(kid).flags.intersects(FlowFlags::AFFECTS_COUNTERS | + FlowFlags::HAS_COUNTER_AFFECTING_CHILDREN); } } let self_base = flow::mut_base(self); if self_base.flags.float_kind() != float::T::none && - self_base.restyle_damage.intersects(REFLOW) { - special_damage.insert(REFLOW_ENTIRE_DOCUMENT); + self_base.restyle_damage.intersects(ServoRestyleDamage::REFLOW) { + special_damage.insert(SpecialRestyleDamage::REFLOW_ENTIRE_DOCUMENT); } if has_counter_affecting_children { - self_base.flags.insert(HAS_COUNTER_AFFECTING_CHILDREN) + self_base.flags.insert(FlowFlags::HAS_COUNTER_AFFECTING_CHILDREN) } else { - self_base.flags.remove(HAS_COUNTER_AFFECTING_CHILDREN) + self_base.flags.remove(FlowFlags::HAS_COUNTER_AFFECTING_CHILDREN) } special_damage @@ -78,7 +78,7 @@ impl<'a> LayoutDamageComputation for &'a mut Flow { fn reflow_entire_document(self) { let self_base = flow::mut_base(self); self_base.restyle_damage.insert(RestyleDamage::rebuild_and_reflow()); - self_base.restyle_damage.remove(RECONSTRUCT_FLOW); + self_base.restyle_damage.remove(ServoRestyleDamage::RECONSTRUCT_FLOW); for kid in self_base.children.iter_mut() { kid.reflow_entire_document(); } diff --git a/components/layout/inline.rs b/components/layout/inline.rs index e6f23afae8f..0cd75eae26e 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -13,10 +13,10 @@ use display_list_builder::StackingContextCollectionState; use euclid::{Point2D, Size2D}; use floats::{FloatKind, Floats, PlacementInfo}; use flow::{self, BaseFlow, Flow, FlowClass, ForceNonfloatedFlag}; -use flow::{CONTAINS_TEXT_OR_REPLACED_FRAGMENTS, EarlyAbsolutePositionInfo, OpaqueFlow}; +use flow::{FlowFlags, EarlyAbsolutePositionInfo, OpaqueFlow}; use flow_ref::FlowRef; use fragment::{CoordinateSystem, Fragment, FragmentBorderBoxIterator, Overflow}; -use fragment::IS_ELLIPSIS; +use fragment::FragmentFlags; use fragment::SpecificFragmentInfo; use gfx::display_list::OpaqueNode; use gfx::font::FontMetrics; @@ -34,7 +34,7 @@ use style::computed_values::{display, overflow_x, position, text_align, text_jus use style::computed_values::{vertical_align, white_space}; use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode}; use style::properties::{longhands, ComputedValues}; -use style::servo::restyle_damage::{BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW, RESOLVE_GENERATED_CONTENT}; +use style::servo::restyle_damage::ServoRestyleDamage; use style::values::generics::box_::VerticalAlign; use text; use traversal::PreorderFlowTraversal; @@ -344,7 +344,7 @@ impl LineBreaker { }; // Do not reflow truncated fragments. Reflow the original fragment only. - let fragment = if fragment.flags.contains(IS_ELLIPSIS) { + let fragment = if fragment.flags.contains(FragmentFlags::IS_ELLIPSIS) { continue } else if let SpecificFragmentInfo::TruncatedFragment(info) = fragment.specific { info.full @@ -667,7 +667,7 @@ impl LineBreaker { inline_start_fragment.border_padding.inline_end = Au(0); if let Some(ref mut inline_context) = inline_start_fragment.inline_context { for node in &mut inline_context.nodes { - node.flags.remove(LAST_FRAGMENT_OF_ELEMENT); + node.flags.remove(InlineFragmentNodeFlags::LAST_FRAGMENT_OF_ELEMENT); } } inline_start_fragment.border_box.size.inline += inline_start_fragment.border_padding.inline_start; @@ -675,7 +675,7 @@ impl LineBreaker { inline_end_fragment.border_padding.inline_start = Au(0); if let Some(ref mut inline_context) = inline_end_fragment.inline_context { for node in &mut inline_context.nodes { - node.flags.remove(FIRST_FRAGMENT_OF_ELEMENT); + node.flags.remove(InlineFragmentNodeFlags::FIRST_FRAGMENT_OF_ELEMENT); } } inline_end_fragment.border_box.size.inline += inline_end_fragment.border_padding.inline_end; @@ -899,7 +899,7 @@ impl InlineFlow { }; if flow.fragments.fragments.iter().any(Fragment::is_unscanned_generated_content) { - flow.base.restyle_damage.insert(RESOLVE_GENERATED_CONTENT); + flow.base.restyle_damage.insert(ServoRestyleDamage::RESOLVE_GENERATED_CONTENT); } flow @@ -1315,7 +1315,7 @@ impl Flow for InlineFlow { flow::mut_base(kid).floats = Floats::new(writing_mode); } - self.base.flags.remove(CONTAINS_TEXT_OR_REPLACED_FRAGMENTS); + self.base.flags.remove(FlowFlags::CONTAINS_TEXT_OR_REPLACED_FRAGMENTS); let mut intrinsic_sizes_for_flow = IntrinsicISizesContribution::new(); let mut intrinsic_sizes_for_inline_run = IntrinsicISizesContribution::new(); @@ -1374,10 +1374,10 @@ impl Flow for InlineFlow { } } - fragment.restyle_damage.remove(BUBBLE_ISIZES); + fragment.restyle_damage.remove(ServoRestyleDamage::BUBBLE_ISIZES); if fragment.is_text_or_replaced() { - self.base.flags.insert(CONTAINS_TEXT_OR_REPLACED_FRAGMENTS); + self.base.flags.insert(FlowFlags::CONTAINS_TEXT_OR_REPLACED_FRAGMENTS); } } @@ -1537,9 +1537,9 @@ impl Flow for InlineFlow { } }); - self.base.restyle_damage.remove(REFLOW_OUT_OF_FLOW | REFLOW); + self.base.restyle_damage.remove(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW); for fragment in &mut self.fragments.fragments { - fragment.restyle_damage.remove(REFLOW_OUT_OF_FLOW | REFLOW); + fragment.restyle_damage.remove(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW); } } @@ -1768,9 +1768,9 @@ pub struct InlineFragmentNodeInfo { } bitflags! { - pub flags InlineFragmentNodeFlags: u8 { - const FIRST_FRAGMENT_OF_ELEMENT = 0x01, - const LAST_FRAGMENT_OF_ELEMENT = 0x02, + pub struct InlineFragmentNodeFlags: u8 { + const FIRST_FRAGMENT_OF_ELEMENT = 0x01; + const LAST_FRAGMENT_OF_ELEMENT = 0x02; } } diff --git a/components/layout/list_item.rs b/components/layout/list_item.rs index 270d15b3771..1d5ca7884b3 100644 --- a/components/layout/list_item.rs +++ b/components/layout/list_item.rs @@ -22,7 +22,7 @@ use inline::InlineFlow; use style::computed_values::{list_style_type, position}; use style::logical_geometry::LogicalSize; use style::properties::ComputedValues; -use style::servo::restyle_damage::RESOLVE_GENERATED_CONTENT; +use style::servo::restyle_damage::ServoRestyleDamage; #[allow(unsafe_code)] unsafe impl ::flow::HasBaseFlow for ListItemFlow {} @@ -56,7 +56,7 @@ impl ListItemFlow { list_style_type::T::square | list_style_type::T::disclosure_open | list_style_type::T::disclosure_closed => {} - _ => this.block_flow.base.restyle_damage.insert(RESOLVE_GENERATED_CONTENT), + _ => this.block_flow.base.restyle_damage.insert(ServoRestyleDamage::RESOLVE_GENERATED_CONTENT), } } diff --git a/components/layout/query.rs b/components/layout/query.rs index e6d2e250468..7fac8d3b5b1 100644 --- a/components/layout/query.rs +++ b/components/layout/query.rs @@ -11,7 +11,7 @@ use euclid::{Point2D, Vector2D, Rect, Size2D}; use flow::{self, Flow}; use fragment::{Fragment, FragmentBorderBoxIterator, SpecificFragmentInfo}; use gfx::display_list::{DisplayList, OpaqueNode, ScrollOffsetMap}; -use inline::LAST_FRAGMENT_OF_ELEMENT; +use inline::InlineFragmentNodeFlags; use ipc_channel::ipc::IpcSender; use msg::constellation_msg::PipelineId; use opaque_node::OpaqueNodeMethods; @@ -562,7 +562,7 @@ impl FragmentBorderBoxIterator for ParentOffsetBorderBoxIterator { }, } - if node.flags.contains(LAST_FRAGMENT_OF_ELEMENT) { + if node.flags.contains(InlineFragmentNodeFlags::LAST_FRAGMENT_OF_ELEMENT) { self.has_processed_node = true; } } else if self.node_offset_box.is_none() { diff --git a/components/layout/sequential.rs b/components/layout/sequential.rs index 86a7d90142f..57785fceee7 100644 --- a/components/layout/sequential.rs +++ b/components/layout/sequential.rs @@ -9,12 +9,12 @@ use context::LayoutContext; use display_list_builder::{DisplayListBuildState, StackingContextCollectionState}; use euclid::{Point2D, Vector2D}; use floats::SpeculatedFloatPlacement; -use flow::{self, Flow, ImmutableFlowUtils, IS_ABSOLUTELY_POSITIONED}; +use flow::{self, Flow, ImmutableFlowUtils, FlowFlags}; use fragment::{FragmentBorderBoxIterator, CoordinateSystem}; use generated_content::ResolveGeneratedContent; use incremental::RelayoutMode; use servo_config::opts; -use style::servo::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW, STORE_OVERFLOW}; +use style::servo::restyle_damage::ServoRestyleDamage; use traversal::{AssignBSizes, AssignISizes, BubbleISizes, BuildDisplayList}; use traversal::{InorderFlowTraversal, PostorderFlowTraversal, PreorderFlowTraversal}; @@ -33,7 +33,7 @@ pub fn reflow(root: &mut Flow, layout_context: &LayoutContext, relayout_mode: Re if relayout_mode == RelayoutMode::Force { flow::mut_base(flow) .restyle_damage - .insert(REFLOW_OUT_OF_FLOW | REFLOW); + .insert(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW); } if assign_inline_sizes.should_process(flow) { @@ -112,7 +112,7 @@ pub fn iterate_through_flow_tree_fragment_border_boxes(root: &mut Flow, iterator } pub fn store_overflow(layout_context: &LayoutContext, flow: &mut Flow) { - if !flow::base(flow).restyle_damage.contains(STORE_OVERFLOW) { + if !flow::base(flow).restyle_damage.contains(ServoRestyleDamage::STORE_OVERFLOW) { return; } @@ -124,20 +124,20 @@ pub fn store_overflow(layout_context: &LayoutContext, flow: &mut Flow) { flow::mut_base(flow) .restyle_damage - .remove(STORE_OVERFLOW); + .remove(ServoRestyleDamage::STORE_OVERFLOW); } /// Guesses how much inline size will be taken up by floats on the left and right sides of the /// given flow. This is needed to speculatively calculate the inline sizes of block formatting /// contexts. The speculation typically succeeds, but if it doesn't we have to lay it out again. pub fn guess_float_placement(flow: &mut Flow) { - if !flow::base(flow).restyle_damage.intersects(REFLOW) { + if !flow::base(flow).restyle_damage.intersects(ServoRestyleDamage::REFLOW) { return; } let mut floats_in = SpeculatedFloatPlacement::compute_floats_in_for_first_child(flow); for kid in flow::mut_base(flow).child_iter_mut() { - if flow::base(kid).flags.contains(IS_ABSOLUTELY_POSITIONED) { + if flow::base(kid).flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { // Do not propagate floats in or out, but do propogate between kids. guess_float_placement(kid); } else { diff --git a/components/layout/table.rs b/components/layout/table.rs index 37fb246935f..6e67c5536c6 100644 --- a/components/layout/table.rs +++ b/components/layout/table.rs @@ -11,8 +11,7 @@ use block::{BlockFlow, CandidateBSizeIterator, ISizeAndMarginsComputer}; use block::{ISizeConstraintInput, ISizeConstraintSolution}; use context::LayoutContext; use display_list_builder::{BlockFlowDisplayListBuilding, BorderPaintingMode}; -use display_list_builder::{DisplayListBuildState, NEVER_CREATES_STACKING_CONTEXT}; -use display_list_builder::StackingContextCollectionState; +use display_list_builder::{DisplayListBuildState, StackingContextCollectionFlags, StackingContextCollectionState}; use euclid::Point2D; use flow; use flow::{BaseFlow, EarlyAbsolutePositionInfo, Flow, FlowClass, ImmutableFlowUtils, OpaqueFlow}; @@ -27,7 +26,7 @@ use style::computed_values::{border_collapse, border_spacing, table_layout}; use style::context::SharedStyleContext; use style::logical_geometry::LogicalSize; use style::properties::ComputedValues; -use style::servo::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW}; +use style::servo::restyle_damage::ServoRestyleDamage; use style::values::CSSFloat; use style::values::computed::LengthOrPercentageOrAuto; use table_row::{self, CellIntrinsicInlineSize, CollapsedBorder, CollapsedBorderProvenance}; @@ -505,7 +504,8 @@ impl Flow for TableFlow { fn collect_stacking_contexts(&mut self, state: &mut StackingContextCollectionState) { // Stacking contexts are collected by the table wrapper. - self.block_flow.collect_stacking_contexts_for_block(state, NEVER_CREATES_STACKING_CONTEXT); + self.block_flow.collect_stacking_contexts_for_block(state, + StackingContextCollectionFlags::NEVER_CREATES_STACKING_CONTEXT); } fn repair_style(&mut self, new_style: &::ServoArc<ComputedValues>) { @@ -735,7 +735,7 @@ impl TableLikeFlow for BlockFlow { debug_assert!(self.fragment.style.get_inheritedtable().border_collapse == border_collapse::T::separate || block_direction_spacing == Au(0)); - if self.base.restyle_damage.contains(REFLOW) { + if self.base.restyle_damage.contains(ServoRestyleDamage::REFLOW) { // Our current border-box position. let block_start_border_padding = self.fragment.border_padding.block_start; let mut current_block_offset = block_start_border_padding; @@ -809,7 +809,7 @@ impl TableLikeFlow for BlockFlow { } } - self.base.restyle_damage.remove(REFLOW_OUT_OF_FLOW | REFLOW); + self.base.restyle_damage.remove(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW); } } diff --git a/components/layout/table_cell.rs b/components/layout/table_cell.rs index c6c438204cf..40d0c73d2a8 100644 --- a/components/layout/table_cell.rs +++ b/components/layout/table_cell.rs @@ -13,7 +13,7 @@ use display_list_builder::{BlockFlowDisplayListBuilding, BorderPaintingMode}; use display_list_builder::{DisplayListBuildState, StackingContextCollectionFlags}; use display_list_builder::StackingContextCollectionState; use euclid::{Point2D, Rect, SideOffsets2D, Size2D}; -use flow::{self, Flow, FlowClass, IS_ABSOLUTELY_POSITIONED, OpaqueFlow}; +use flow::{self, Flow, FlowClass, FlowFlags, OpaqueFlow}; use fragment::{Fragment, FragmentBorderBoxIterator, Overflow}; use gfx_traits::print_tree::PrintTree; use layout_debug; @@ -102,7 +102,7 @@ impl TableCellFlow { let mut extents = None; for kid in flow::base(self).children.iter() { let kid_base = flow::base(kid); - if kid_base.flags.contains(IS_ABSOLUTELY_POSITIONED) { + if kid_base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { continue } let start = kid_base.position.start.b - @@ -144,7 +144,7 @@ impl TableCellFlow { for kid in flow::mut_base(self).children.iter_mut() { let kid_base = flow::mut_base(kid); - if !kid_base.flags.contains(IS_ABSOLUTELY_POSITIONED) { + if !kid_base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) { kid_base.position.start.b += offset } } diff --git a/components/layout/table_row.rs b/components/layout/table_row.rs index 761a363881a..354535a94a0 100644 --- a/components/layout/table_row.rs +++ b/components/layout/table_row.rs @@ -26,7 +26,7 @@ use std::iter::{Enumerate, IntoIterator, Peekable}; use style::computed_values::{border_collapse, border_spacing, border_top_style}; use style::logical_geometry::{LogicalSize, PhysicalSide, WritingMode}; use style::properties::ComputedValues; -use style::servo::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW}; +use style::servo::restyle_damage::ServoRestyleDamage; use style::values::computed::{Color, LengthOrPercentageOrAuto}; use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize, InternalTable, VecExt}; use table_cell::{CollapsedBordersForCell, TableCellFlow}; @@ -114,7 +114,7 @@ impl TableRowFlow { /// methods #[inline(always)] fn assign_block_size_table_row_base(&mut self, layout_context: &LayoutContext) { - if self.block_flow.base.restyle_damage.contains(REFLOW) { + if self.block_flow.base.restyle_damage.contains(ServoRestyleDamage::REFLOW) { // Per CSS 2.1 § 17.5.3, find max_y = max(computed `block-size`, minimum block-size of // all cells). let mut max_block_size = Au(0); @@ -195,7 +195,7 @@ impl TableRowFlow { } } - self.block_flow.base.restyle_damage.remove(REFLOW_OUT_OF_FLOW | REFLOW); + self.block_flow.base.restyle_damage.remove(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW); } pub fn populate_collapsed_border_spacing<'a, I>( diff --git a/components/layout/table_rowgroup.rs b/components/layout/table_rowgroup.rs index 0639f02dbf5..c70a99e16ac 100644 --- a/components/layout/table_rowgroup.rs +++ b/components/layout/table_rowgroup.rs @@ -10,7 +10,7 @@ use app_units::Au; use block::{BlockFlow, ISizeAndMarginsComputer}; use context::LayoutContext; use display_list_builder::{BlockFlowDisplayListBuilding, DisplayListBuildState}; -use display_list_builder::{NEVER_CREATES_CONTAINING_BLOCK, StackingContextCollectionState}; +use display_list_builder::{StackingContextCollectionFlags, StackingContextCollectionState}; use euclid::Point2D; use flow::{Flow, FlowClass, OpaqueFlow}; use fragment::{Fragment, FragmentBorderBoxIterator, Overflow}; @@ -184,7 +184,8 @@ impl Flow for TableRowGroupFlow { } fn collect_stacking_contexts(&mut self, state: &mut StackingContextCollectionState) { - self.block_flow.collect_stacking_contexts_for_block(state, NEVER_CREATES_CONTAINING_BLOCK); + self.block_flow.collect_stacking_contexts_for_block(state, + StackingContextCollectionFlags::NEVER_CREATES_CONTAINING_BLOCK); } fn repair_style(&mut self, new_style: &::ServoArc<ComputedValues>) { diff --git a/components/layout/table_wrapper.rs b/components/layout/table_wrapper.rs index 866916b9ad5..30e43eb23c3 100644 --- a/components/layout/table_wrapper.rs +++ b/components/layout/table_wrapper.rs @@ -17,12 +17,11 @@ use app_units::Au; use block::{AbsoluteNonReplaced, BlockFlow, FloatNonReplaced, ISizeAndMarginsComputer, ISizeConstraintInput}; use block::{ISizeConstraintSolution, MarginsMayCollapseFlag}; use context::LayoutContext; -use display_list_builder::{BlockFlowDisplayListBuilding, DisplayListBuildState}; -use display_list_builder::{NEVER_CREATES_CLIP_SCROLL_NODE, NEVER_CREATES_CONTAINING_BLOCK}; +use display_list_builder::{BlockFlowDisplayListBuilding, DisplayListBuildState, StackingContextCollectionFlags}; use display_list_builder::StackingContextCollectionState; use euclid::Point2D; use floats::FloatKind; -use flow::{Flow, FlowClass, ImmutableFlowUtils, INLINE_POSITION_IS_STATIC, OpaqueFlow}; +use flow::{Flow, FlowClass, ImmutableFlowUtils, FlowFlags, OpaqueFlow}; use fragment::{Fragment, FragmentBorderBoxIterator, Overflow}; use gfx_traits::print_tree::PrintTree; use model::MaybeAuto; @@ -256,7 +255,7 @@ impl TableWrapperFlow { return } - if !self.block_flow.base.flags.contains(INLINE_POSITION_IS_STATIC) { + if !self.block_flow.base.flags.contains(FlowFlags::INLINE_POSITION_IS_STATIC) { let inline_size_computer = AbsoluteTable { minimum_width_of_all_columns: minimum_width_of_all_columns, preferred_width_of_all_columns: preferred_width_of_all_columns, @@ -464,7 +463,9 @@ impl Flow for TableWrapperFlow { fn collect_stacking_contexts(&mut self, state: &mut StackingContextCollectionState) { self.block_flow.collect_stacking_contexts_for_block( - state, NEVER_CREATES_CONTAINING_BLOCK | NEVER_CREATES_CLIP_SCROLL_NODE); + state, + StackingContextCollectionFlags::NEVER_CREATES_CONTAINING_BLOCK | + StackingContextCollectionFlags::NEVER_CREATES_CLIP_SCROLL_NODE); } fn repair_style(&mut self, new_style: &::ServoArc<ComputedValues>) { diff --git a/components/layout/text.rs b/components/layout/text.rs index bdee1c52980..6da6d094998 100644 --- a/components/layout/text.rs +++ b/components/layout/text.rs @@ -7,15 +7,14 @@ #![deny(unsafe_code)] use app_units::Au; -use fragment::{Fragment, REQUIRES_LINE_BREAK_AFTERWARD_IF_WRAPPING_ON_NEWLINES, ScannedTextFlags}; -use fragment::{SELECTED, ScannedTextFragmentInfo, SpecificFragmentInfo, UnscannedTextFragmentInfo}; -use gfx::font::{DISABLE_KERNING_SHAPING_FLAG, FontMetrics, IGNORE_LIGATURES_SHAPING_FLAG}; -use gfx::font::{KEEP_ALL_FLAG, RTL_FLAG, RunMetrics, ShapingFlags, ShapingOptions}; +use fragment::{Fragment, ScannedTextFlags}; +use fragment::{ScannedTextFragmentInfo, SpecificFragmentInfo, UnscannedTextFragmentInfo}; +use gfx::font::{FontMetrics, RunMetrics, ShapingFlags, ShapingOptions}; use gfx::font_context::FontContext; use gfx::text::glyph::ByteIndex; use gfx::text::text_run::TextRun; use gfx::text::util::{self, CompressionMode}; -use inline::{FIRST_FRAGMENT_OF_ELEMENT, InlineFragments, LAST_FRAGMENT_OF_ELEMENT}; +use inline::{InlineFragmentNodeFlags, InlineFragments}; use linked_list::split_off_head; use ordered_float::NotNaN; use range::Range; @@ -291,15 +290,15 @@ impl TextRunScanner { let mut flags = ShapingFlags::empty(); if let Some(v) = letter_spacing.value() { if v.px() != 0. { - flags.insert(IGNORE_LIGATURES_SHAPING_FLAG); + flags.insert(ShapingFlags::IGNORE_LIGATURES_SHAPING_FLAG); } } if text_rendering == text_rendering::T::optimizespeed { - flags.insert(IGNORE_LIGATURES_SHAPING_FLAG); - flags.insert(DISABLE_KERNING_SHAPING_FLAG) + flags.insert(ShapingFlags::IGNORE_LIGATURES_SHAPING_FLAG); + flags.insert(ShapingFlags::DISABLE_KERNING_SHAPING_FLAG) } if word_break == word_break::T::keep_all { - flags.insert(KEEP_ALL_FLAG); + flags.insert(ShapingFlags::KEEP_ALL_FLAG); } let options = ShapingOptions { letter_spacing: letter_spacing.value().cloned().map(Au::from), @@ -313,7 +312,7 @@ impl TextRunScanner { let mut options = options; options.script = run_info.script; if run_info.bidi_level.is_rtl() { - options.flags.insert(RTL_FLAG); + options.flags.insert(ShapingFlags::RTL_FLAG); } let mut font = fontgroup.fonts.get(run_info.font_index).unwrap().borrow_mut(); ScannedTextRun { @@ -364,11 +363,11 @@ impl TextRunScanner { if requires_line_break_afterward_if_wrapping_on_newlines { byte_range.extend_by(ByteIndex(-1)); // Trim the '\n' - flags.insert(REQUIRES_LINE_BREAK_AFTERWARD_IF_WRAPPING_ON_NEWLINES); + flags.insert(ScannedTextFlags::REQUIRES_LINE_BREAK_AFTERWARD_IF_WRAPPING_ON_NEWLINES); } if mapping.selected { - flags.insert(SELECTED); + flags.insert(ScannedTextFlags::SELECTED); } let insertion_point = if mapping.contains_insertion_point(scanned_run.insertion_point) { @@ -402,10 +401,10 @@ impl TextRunScanner { if let Some(ref mut context) = new_fragment.inline_context { for node in &mut context.nodes { if !is_last_mapping_of_this_old_fragment { - node.flags.remove(LAST_FRAGMENT_OF_ELEMENT); + node.flags.remove(InlineFragmentNodeFlags::LAST_FRAGMENT_OF_ELEMENT); } if !is_first_mapping_of_this_old_fragment { - node.flags.remove(FIRST_FRAGMENT_OF_ELEMENT); + node.flags.remove(InlineFragmentNodeFlags::FIRST_FRAGMENT_OF_ELEMENT); } } } diff --git a/components/layout/traversal.rs b/components/layout/traversal.rs index 077e43fb45c..ee8232ff599 100644 --- a/components/layout/traversal.rs +++ b/components/layout/traversal.rs @@ -7,14 +7,14 @@ use construct::FlowConstructor; use context::LayoutContext; use display_list_builder::DisplayListBuildState; -use flow::{self, CAN_BE_FRAGMENTED, Flow, ImmutableFlowUtils}; +use flow::{self, FlowFlags, Flow, ImmutableFlowUtils}; use script_layout_interface::wrapper_traits::{LayoutNode, ThreadSafeLayoutNode}; use servo_config::opts; use style::context::{SharedStyleContext, StyleContext}; use style::data::ElementData; use style::dom::{NodeInfo, TElement, TNode}; use style::selector_parser::RestyleDamage; -use style::servo::restyle_damage::{BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW, REPAINT, REPOSITION}; +use style::servo::restyle_damage::ServoRestyleDamage; use style::traversal::{DomTraversal, recalc_style_at}; use style::traversal::PerLevelTraversalData; use wrapper::{GetRawData, LayoutNodeLayoutData}; @@ -209,7 +209,7 @@ fn construct_flows_at<N>(context: &LayoutContext, node: N) } } - tnode.mutate_layout_data().unwrap().flags.insert(::data::HAS_BEEN_TRAVERSED); + tnode.mutate_layout_data().unwrap().flags.insert(::data::LayoutDataFlags::HAS_BEEN_TRAVERSED); } if let Some(el) = node.as_element() { @@ -227,12 +227,12 @@ impl<'a> PostorderFlowTraversal for BubbleISizes<'a> { #[inline] fn process(&self, flow: &mut Flow) { flow.bubble_inline_sizes(); - flow::mut_base(flow).restyle_damage.remove(BUBBLE_ISIZES); + flow::mut_base(flow).restyle_damage.remove(ServoRestyleDamage::BUBBLE_ISIZES); } #[inline] fn should_process(&self, flow: &mut Flow) -> bool { - flow::base(flow).restyle_damage.contains(BUBBLE_ISIZES) + flow::base(flow).restyle_damage.contains(ServoRestyleDamage::BUBBLE_ISIZES) } } @@ -250,7 +250,7 @@ impl<'a> PreorderFlowTraversal for AssignISizes<'a> { #[inline] fn should_process(&self, flow: &mut Flow) -> bool { - flow::base(flow).restyle_damage.intersects(REFLOW_OUT_OF_FLOW | REFLOW) + flow::base(flow).restyle_damage.intersects(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW) } } @@ -280,9 +280,9 @@ impl<'a> PostorderFlowTraversal for AssignBSizes<'a> { #[inline] fn should_process(&self, flow: &mut Flow) -> bool { let base = flow::base(flow); - base.restyle_damage.intersects(REFLOW_OUT_OF_FLOW | REFLOW) && + base.restyle_damage.intersects(ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW) && // The fragmentation countainer is responsible for calling Flow::fragment recursively - !base.flags.contains(CAN_BE_FRAGMENTED) + !base.flags.contains(FlowFlags::CAN_BE_FRAGMENTED) } } @@ -293,13 +293,13 @@ pub struct ComputeStackingRelativePositions<'a> { impl<'a> PreorderFlowTraversal for ComputeStackingRelativePositions<'a> { #[inline] fn should_process_subtree(&self, flow: &mut Flow) -> bool { - flow::base(flow).restyle_damage.contains(REPOSITION) + flow::base(flow).restyle_damage.contains(ServoRestyleDamage::REPOSITION) } #[inline] fn process(&self, flow: &mut Flow) { flow.compute_stacking_relative_position(self.layout_context); - flow::mut_base(flow).restyle_damage.remove(REPOSITION) + flow::mut_base(flow).restyle_damage.remove(ServoRestyleDamage::REPOSITION) } } @@ -318,7 +318,7 @@ impl<'a> BuildDisplayList<'a> { flow.clip_and_scroll_info(self.state.layout_context.id); flow.build_display_list(&mut self.state); - flow::mut_base(flow).restyle_damage.remove(REPAINT); + flow::mut_base(flow).restyle_damage.remove(ServoRestyleDamage::REPAINT); for kid in flow::child_iter_mut(flow) { self.traverse(kid); diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 27c9475a8b2..de1eafe26fc 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -140,7 +140,7 @@ impl<T: ThreadSafeLayoutNode> ThreadSafeLayoutNodeHelpers for T { let damage = { let data = node.get_raw_data().unwrap(); - if !data.layout_data.borrow().flags.contains(::data::HAS_BEEN_TRAVERSED) { + if !data.layout_data.borrow().flags.contains(::data::LayoutDataFlags::HAS_BEEN_TRAVERSED) { // We're reflowing a node that was styled for the first time and // has never been visited by layout. Return rebuild_and_reflow, // because that's what the code expects. diff --git a/components/layout_thread/dom_wrapper.rs b/components/layout_thread/dom_wrapper.rs index f19e5e13b78..6729f50afe4 100644 --- a/components/layout_thread/dom_wrapper.rs +++ b/components/layout_thread/dom_wrapper.rs @@ -38,13 +38,11 @@ use layout::wrapper::GetRawData; use msg::constellation_msg::{BrowsingContextId, PipelineId}; use nonzero::NonZero; use range::Range; -use script::layout_exports::{CAN_BE_FRAGMENTED, HAS_DIRTY_DESCENDANTS, IS_IN_DOC}; use script::layout_exports::{CharacterDataTypeId, ElementTypeId, HTMLElementTypeId, NodeTypeId}; use script::layout_exports::{Document, Element, Node, Text}; -use script::layout_exports::{HANDLED_SNAPSHOT, HAS_SNAPSHOT}; use script::layout_exports::{LayoutCharacterDataHelpers, LayoutDocumentHelpers}; -use script::layout_exports::{LayoutElementHelpers, LayoutNodeHelpers, RawLayoutElementHelpers}; -use script::layout_exports::LayoutDom; +use script::layout_exports::{LayoutElementHelpers, LayoutNodeHelpers, LayoutDom, RawLayoutElementHelpers}; +use script::layout_exports::NodeFlags; use script::layout_exports::PendingRestyle; use script_layout_interface::{HTMLCanvasData, LayoutNodeType, SVGSVGData, TrustedNodeAddress}; use script_layout_interface::{OpaqueStyleAndLayoutData, StyleData}; @@ -207,11 +205,11 @@ impl<'ln> TNode for ServoLayoutNode<'ln> { } fn can_be_fragmented(&self) -> bool { - unsafe { self.node.get_flag(CAN_BE_FRAGMENTED) } + unsafe { self.node.get_flag(NodeFlags::CAN_BE_FRAGMENTED) } } unsafe fn set_can_be_fragmented(&self, value: bool) { - self.node.set_flag(CAN_BE_FRAGMENTED, value) + self.node.set_flag(NodeFlags::CAN_BE_FRAGMENTED, value) } } @@ -398,28 +396,28 @@ impl<'le> TElement for ServoLayoutElement<'le> { } fn has_dirty_descendants(&self) -> bool { - unsafe { self.as_node().node.get_flag(HAS_DIRTY_DESCENDANTS) } + unsafe { self.as_node().node.get_flag(NodeFlags::HAS_DIRTY_DESCENDANTS) } } fn has_snapshot(&self) -> bool { - unsafe { self.as_node().node.get_flag(HAS_SNAPSHOT) } + unsafe { self.as_node().node.get_flag(NodeFlags::HAS_SNAPSHOT) } } fn handled_snapshot(&self) -> bool { - unsafe { self.as_node().node.get_flag(HANDLED_SNAPSHOT) } + unsafe { self.as_node().node.get_flag(NodeFlags::HANDLED_SNAPSHOT) } } unsafe fn set_handled_snapshot(&self) { - self.as_node().node.set_flag(HANDLED_SNAPSHOT, true); + self.as_node().node.set_flag(NodeFlags::HANDLED_SNAPSHOT, true); } unsafe fn set_dirty_descendants(&self) { - debug_assert!(self.as_node().node.get_flag(IS_IN_DOC)); - self.as_node().node.set_flag(HAS_DIRTY_DESCENDANTS, true) + debug_assert!(self.as_node().node.get_flag(NodeFlags::IS_IN_DOC)); + self.as_node().node.set_flag(NodeFlags::HAS_DIRTY_DESCENDANTS, true) } unsafe fn unset_dirty_descendants(&self) { - self.as_node().node.set_flag(HAS_DIRTY_DESCENDANTS, false) + self.as_node().node.set_flag(NodeFlags::HAS_DIRTY_DESCENDANTS, false) } fn store_children_to_process(&self, n: isize) { @@ -565,11 +563,11 @@ impl<'le> ServoLayoutElement<'le> { } pub unsafe fn unset_snapshot_flags(&self) { - self.as_node().node.set_flag(HAS_SNAPSHOT | HANDLED_SNAPSHOT, false); + self.as_node().node.set_flag(NodeFlags::HAS_SNAPSHOT | NodeFlags::HANDLED_SNAPSHOT, false); } pub unsafe fn set_has_snapshot(&self) { - self.as_node().node.set_flag(HAS_SNAPSHOT, true); + self.as_node().node.set_flag(NodeFlags::HAS_SNAPSHOT, true); } pub unsafe fn note_dirty_descendant(&self) { diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index e7ce75db5c1..91da11e3257 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -71,7 +71,7 @@ use layout::context::malloc_size_of_persistent_local_context; use layout::display_list_builder::ToGfxColor; use layout::flow::{self, Flow, ImmutableFlowUtils, MutableOwnedFlowUtils}; use layout::flow_ref::FlowRef; -use layout::incremental::{LayoutDamageComputation, REFLOW_ENTIRE_DOCUMENT, RelayoutMode}; +use layout::incremental::{LayoutDamageComputation, RelayoutMode, SpecialRestyleDamage}; use layout::layout_debug; use layout::parallel; use layout::query::{LayoutRPCImpl, LayoutThreadData, process_content_box_request, process_content_boxes_request}; @@ -131,11 +131,11 @@ use style::logical_geometry::LogicalPoint; use style::media_queries::{Device, MediaList, MediaType}; use style::properties::PropertyId; use style::selector_parser::SnapshotMap; -use style::servo::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW, REPAINT, REPOSITION, STORE_OVERFLOW}; +use style::servo::restyle_damage::ServoRestyleDamage; use style::shared_lock::{SharedRwLock, SharedRwLockReadGuard, StylesheetGuards}; use style::stylesheets::{Origin, Stylesheet, DocumentStyleSheet, StylesheetInDocument, UserAgentStylesheets}; use style::stylist::Stylist; -use style::thread_state; +use style::thread_state::{self, ThreadState}; use style::timer::Timer; use style::traversal::DomTraversal; use style::traversal_flags::TraversalFlags; @@ -284,7 +284,7 @@ impl LayoutThreadFactory for LayoutThread { layout_threads: usize, paint_time_metrics: PaintTimeMetrics) { thread::Builder::new().name(format!("LayoutThread {:?}", id)).spawn(move || { - thread_state::initialize(thread_state::LAYOUT); + thread_state::initialize(ThreadState::LAYOUT); // In order to get accurate crash reports, we install the top-level bc id. TopLevelBrowsingContextId::install(top_level_browsing_context_id); @@ -974,7 +974,7 @@ impl LayoutThread { let traversal = ComputeStackingRelativePositions { layout_context: layout_context }; traversal.traverse(layout_root); - if flow::base(layout_root).restyle_damage.contains(REPAINT) || + if flow::base(layout_root).restyle_damage.contains(ServoRestyleDamage::REPAINT) || rw_data.display_list.is_none() { if reflow_goal.needs_display_list() { let mut build_state = @@ -1544,7 +1544,7 @@ impl LayoutThread { // that are needed in both incremental and non-incremental traversals. let damage = FlowRef::deref_mut(root_flow).compute_layout_damage(); - if opts::get().nonincremental_layout || damage.contains(REFLOW_ENTIRE_DOCUMENT) { + if opts::get().nonincremental_layout || damage.contains(SpecialRestyleDamage::REFLOW_ENTIRE_DOCUMENT) { FlowRef::deref_mut(root_flow).reflow_entire_document() } }); @@ -1567,7 +1567,8 @@ impl LayoutThread { // Perform the primary layout passes over the flow tree to compute the locations of all // the boxes. - if flow::base(&**root_flow).restyle_damage.intersects(REFLOW | REFLOW_OUT_OF_FLOW) { + if flow::base(&**root_flow).restyle_damage.intersects(ServoRestyleDamage::REFLOW | + ServoRestyleDamage::REFLOW_OUT_OF_FLOW) { profile(time::ProfilerCategory::LayoutMain, self.profiler_metadata(), self.time_profiler_chan.clone(), @@ -1634,7 +1635,8 @@ impl LayoutThread { debug!("reflowing all nodes!"); flow::mut_base(flow) .restyle_damage - .insert(REPAINT | STORE_OVERFLOW | REFLOW | REPOSITION); + .insert(ServoRestyleDamage::REPAINT | ServoRestyleDamage::STORE_OVERFLOW | + ServoRestyleDamage::REFLOW | ServoRestyleDamage::REPOSITION); for child in flow::child_iter_mut(flow) { LayoutThread::reflow_all_nodes(child); diff --git a/components/msg/Cargo.toml b/components/msg/Cargo.toml index d39620fdacf..a13fa591db6 100644 --- a/components/msg/Cargo.toml +++ b/components/msg/Cargo.toml @@ -13,7 +13,7 @@ path = "lib.rs" unstable = ["nonzero/unstable"] [dependencies] -bitflags = "0.7" +bitflags = "1.0" malloc_size_of = { path = "../malloc_size_of" } malloc_size_of_derive = { path = "../malloc_size_of_derive" } nonzero = {path = "../nonzero"} diff --git a/components/msg/constellation_msg.rs b/components/msg/constellation_msg.rs index 10d21917c79..eb2c1b74f19 100644 --- a/components/msg/constellation_msg.rs +++ b/components/msg/constellation_msg.rs @@ -148,12 +148,12 @@ pub enum Key { bitflags! { #[derive(Deserialize, Serialize)] - pub flags KeyModifiers: u8 { - const NONE = 0x00, - const SHIFT = 0x01, - const CONTROL = 0x02, - const ALT = 0x04, - const SUPER = 0x08, + pub struct KeyModifiers: u8 { + const NONE = 0x00; + const SHIFT = 0x01; + const CONTROL = 0x02; + const ALT = 0x04; + const SUPER = 0x08; } } diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index 8c9e9613ede..3c14fe9ad9e 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -28,7 +28,7 @@ tinyfiledialogs = "2.5.9" app_units = "0.5" audio-video-metadata = "0.1.4" base64 = "0.6" -bitflags = "0.7" +bitflags = "1.0" bluetooth_traits = {path = "../bluetooth_traits"} byteorder = "1.0" canvas_traits = {path = "../canvas_traits"} diff --git a/components/script/devtools.rs b/components/script/devtools.rs index 9bcd2376167..585ecd47a15 100644 --- a/components/script/devtools.rs +++ b/components/script/devtools.rs @@ -2,9 +2,9 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use devtools_traits::{AutoMargins, CONSOLE_API, CachedConsoleMessage, CachedConsoleMessageTypes}; +use devtools_traits::{AutoMargins, CachedConsoleMessage, CachedConsoleMessageTypes}; use devtools_traits::{ComputedNodeLayout, ConsoleAPI, PageError}; -use devtools_traits::{EvaluateJSReply, Modification, NodeInfo, PAGE_ERROR, TimelineMarker}; +use devtools_traits::{EvaluateJSReply, Modification, NodeInfo, TimelineMarker}; use devtools_traits::TimelineMarkerType; use dom::bindings::codegen::Bindings::CSSStyleDeclarationBinding::CSSStyleDeclarationMethods; use dom::bindings::codegen::Bindings::DOMRectBinding::DOMRectMethods; @@ -168,7 +168,7 @@ pub fn handle_get_cached_messages(_pipeline_id: PipelineId, reply: IpcSender<Vec<CachedConsoleMessage>>) { // TODO: check the messageTypes against a global Cache for console messages and page exceptions let mut messages = Vec::new(); - if message_types.contains(PAGE_ERROR) { + if message_types.contains(CachedConsoleMessageTypes::PAGE_ERROR) { // TODO: make script error reporter pass all reported errors // to devtools and cache them for returning here. let msg = PageError { @@ -188,7 +188,7 @@ pub fn handle_get_cached_messages(_pipeline_id: PipelineId, }; messages.push(CachedConsoleMessage::PageError(msg)); } - if message_types.contains(CONSOLE_API) { + if message_types.contains(CachedConsoleMessageTypes::CONSOLE_API) { // TODO: do for real let msg = ConsoleAPI { type_: "ConsoleAPI".to_owned(), diff --git a/components/script/dom/bindings/cell.rs b/components/script/dom/bindings/cell.rs index 3ba4fad6c66..c5a76bb4ee2 100644 --- a/components/script/dom/bindings/cell.rs +++ b/components/script/dom/bindings/cell.rs @@ -5,7 +5,7 @@ //! A shareable mutable container for the DOM. use std::cell::{BorrowError, BorrowMutError, Ref, RefCell, RefMut}; -use style::thread_state; +use style::thread_state::{self, ThreadState}; /// A mutable field in the DOM. /// @@ -45,7 +45,7 @@ impl<T> DomRefCell<T> { /// #[allow(unsafe_code)] pub unsafe fn borrow_for_script_deallocation(&self) -> &mut T { - debug_assert!(thread_state::get().contains(thread_state::SCRIPT)); + debug_assert!(thread_state::get().contains(ThreadState::SCRIPT)); &mut *self.value.as_ptr() } diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 3251290f398..859e98931a5 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -2039,7 +2039,7 @@ DOMClass { interface_chain: [ %s ], type_id: %s, malloc_size_of: %s as unsafe fn(&mut _, _) -> _, - global: InterfaceObjectMap::%s, + global: InterfaceObjectMap::Globals::%s, }""" % (prototypeChainString, DOMClassTypeId(descriptor), mallocSizeOf, globals_) @@ -2445,7 +2445,7 @@ class CGConstructorEnabled(CGAbstractMethod): iface = self.descriptor.interface bits = " | ".join(sorted( - "InterfaceObjectMap::" + camel_to_upper_snake(i) for i in iface.exposureSet + "InterfaceObjectMap::Globals::" + camel_to_upper_snake(i) for i in iface.exposureSet )) conditions.append("is_exposed_in(aObj, %s)" % bits) @@ -7092,9 +7092,9 @@ class GlobalGenRoots(): for (idx, d) in enumerate(global_descriptors) ) global_flags = CGWrapper(CGIndenter(CGList([ - CGGeneric("const %s = %#x," % args) + CGGeneric("const %s = %#x;" % args) for args in flags - ], "\n")), pre="pub flags Globals: u8 {\n", post="\n}") + ], "\n")), pre="pub 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/css.rs b/components/script/dom/css.rs index b1bc978c5fa..c78627b2e64 100644 --- a/components/script/dom/css.rs +++ b/components/script/dom/css.rs @@ -13,7 +13,7 @@ use style::context::QuirksMode; use style::parser::ParserContext; use style::stylesheets::CssRuleType; use style::stylesheets::supports_rule::{Declaration, parse_condition_or_declaration}; -use style_traits::PARSING_MODE_DEFAULT; +use style_traits::ParsingMode; #[dom_struct] pub struct CSS { @@ -39,7 +39,7 @@ impl CSS { let context = ParserContext::new_for_cssom( &url, Some(CssRuleType::Style), - PARSING_MODE_DEFAULT, + ParsingMode::DEFAULT, QuirksMode::NoQuirks ); decl.eval(&context) @@ -55,7 +55,7 @@ impl CSS { let context = ParserContext::new_for_cssom( &url, Some(CssRuleType::Style), - PARSING_MODE_DEFAULT, + ParsingMode::DEFAULT, QuirksMode::NoQuirks ); cond.eval(&context) diff --git a/components/script/dom/cssmediarule.rs b/components/script/dom/cssmediarule.rs index dc4a4c411a5..11f05d125a8 100644 --- a/components/script/dom/cssmediarule.rs +++ b/components/script/dom/cssmediarule.rs @@ -20,7 +20,7 @@ use style::media_queries::parse_media_query_list; use style::parser::ParserContext; use style::shared_lock::{Locked, ToCssWithGuard}; use style::stylesheets::{CssRuleType, MediaRule}; -use style_traits::{PARSING_MODE_DEFAULT, ToCss}; +use style_traits::{ParsingMode, ToCss}; #[dom_struct] pub struct CSSMediaRule { @@ -76,7 +76,7 @@ impl CSSMediaRule { let url = window.get_url(); let quirks_mode = window.Document().quirks_mode(); let context = ParserContext::new_for_cssom(&url, Some(CssRuleType::Media), - PARSING_MODE_DEFAULT, + ParsingMode::DEFAULT, quirks_mode); let new_medialist = parse_media_query_list(&context, &mut input, diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs index e20d4e82e3f..d1d5aa505bf 100644 --- a/components/script/dom/cssstyledeclaration.rs +++ b/components/script/dom/cssstyledeclaration.rs @@ -22,7 +22,7 @@ use style::properties::{DeclarationSource, Importance, PropertyDeclarationBlock, use style::properties::{parse_one_declaration_into, parse_style_attribute, SourcePropertyDeclaration}; use style::selector_parser::PseudoElement; use style::shared_lock::Locked; -use style_traits::{PARSING_MODE_DEFAULT, ToCss}; +use style_traits::{ParsingMode, ToCss}; // http://dev.w3.org/csswg/cssom/#the-cssstyledeclaration-interface #[dom_struct] @@ -261,7 +261,7 @@ impl CSSStyleDeclaration { let mut declarations = SourcePropertyDeclaration::new(); let result = parse_one_declaration_into( &mut declarations, id, &value, &self.owner.base_url(), - window.css_error_reporter(), PARSING_MODE_DEFAULT, quirks_mode); + window.css_error_reporter(), ParsingMode::DEFAULT, quirks_mode); // Step 6 match result { diff --git a/components/script/dom/csssupportsrule.rs b/components/script/dom/csssupportsrule.rs index d9e3f8ac8a0..68d02aa241a 100644 --- a/components/script/dom/csssupportsrule.rs +++ b/components/script/dom/csssupportsrule.rs @@ -18,7 +18,7 @@ use style::parser::ParserContext; use style::shared_lock::{Locked, ToCssWithGuard}; use style::stylesheets::{CssRuleType, SupportsRule}; use style::stylesheets::supports_rule::SupportsCondition; -use style_traits::{PARSING_MODE_DEFAULT, ToCss}; +use style_traits::{ParsingMode, ToCss}; #[dom_struct] pub struct CSSSupportsRule { @@ -64,7 +64,7 @@ impl CSSSupportsRule { let url = win.Document().url(); let quirks_mode = win.Document().quirks_mode(); let context = ParserContext::new_for_cssom(&url, Some(CssRuleType::Supports), - PARSING_MODE_DEFAULT, + ParsingMode::DEFAULT, quirks_mode); let enabled = cond.eval(&context); let mut guard = self.cssconditionrule.shared_lock().write(); diff --git a/components/script/dom/dedicatedworkerglobalscope.rs b/components/script/dom/dedicatedworkerglobalscope.rs index a754bbc4c6a..84b390ea1cf 100644 --- a/components/script/dom/dedicatedworkerglobalscope.rs +++ b/components/script/dom/dedicatedworkerglobalscope.rs @@ -42,7 +42,7 @@ use std::sync::{Arc, Mutex}; use std::sync::atomic::AtomicBool; use std::sync::mpsc::{Receiver, RecvError, Select, Sender, channel}; use std::thread; -use style::thread_state; +use style::thread_state::{self, ThreadState}; /// Set the `worker` field of a related DedicatedWorkerGlobalScope object to a particular /// value for the duration of this object's lifetime. This ensures that the related Worker @@ -167,7 +167,7 @@ impl DedicatedWorkerGlobalScope { let origin = GlobalScope::current().expect("No current global object").origin().immutable().clone(); thread::Builder::new().name(name).spawn(move || { - thread_state::initialize(thread_state::SCRIPT | thread_state::IN_WORKER); + thread_state::initialize(ThreadState::SCRIPT | ThreadState::IN_WORKER); if let Some(top_level_browsing_context_id) = top_level_browsing_context_id { TopLevelBrowsingContextId::install(top_level_browsing_context_id); diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 2e018bd62f5..731b89a26cb 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -66,7 +66,7 @@ use dom::keyboardevent::KeyboardEvent; use dom::location::Location; use dom::messageevent::MessageEvent; use dom::mouseevent::MouseEvent; -use dom::node::{self, CloneChildrenFlag, Node, NodeDamage, window_from_node, IS_IN_DOC, LayoutNodeHelpers}; +use dom::node::{self, CloneChildrenFlag, Node, NodeDamage, window_from_node, NodeFlags, LayoutNodeHelpers}; use dom::node::VecPreOrderInsertionHelper; use dom::nodeiterator::NodeIterator; use dom::nodelist::NodeList; @@ -99,7 +99,6 @@ use hyper_serde::Serde; use ipc_channel::ipc::{self, IpcSender}; use js::jsapi::{JSContext, JSRuntime}; use js::jsapi::JS_GetRuntime; -use msg::constellation_msg::{ALT, CONTROL, SHIFT, SUPER}; use msg::constellation_msg::{BrowsingContextId, Key, KeyModifiers, KeyState, TopLevelBrowsingContextId}; use net_traits::{FetchResponseMsg, IpcSend, ReferrerPolicy}; use net_traits::CookieSource::NonHTTP; @@ -130,7 +129,7 @@ use std::rc::Rc; use std::time::{Duration, Instant}; use style::attr::AttrValue; use style::context::QuirksMode; -use style::invalidation::element::restyle_hints::{RestyleHint, RESTYLE_SELF, RESTYLE_STYLE_ATTRIBUTE}; +use style::invalidation::element::restyle_hints::RestyleHint; use style::media_queries::{Device, MediaList, MediaType}; use style::selector_parser::{RestyleDamage, Snapshot}; use style::shared_lock::{SharedRwLock as StyleSharedRwLock, SharedRwLockReadGuard}; @@ -1276,10 +1275,10 @@ impl Document { (&None, &None) => self.window.upcast(), }; - let ctrl = modifiers.contains(CONTROL); - let alt = modifiers.contains(ALT); - let shift = modifiers.contains(SHIFT); - let meta = modifiers.contains(SUPER); + let ctrl = modifiers.contains(KeyModifiers::CONTROL); + let alt = modifiers.contains(KeyModifiers::ALT); + let shift = modifiers.contains(KeyModifiers::SHIFT); + let meta = modifiers.contains(KeyModifiers::SUPER); let is_composing = false; let is_repeating = state == KeyState::Repeated; @@ -2019,7 +2018,7 @@ impl LayoutDocumentHelpers for LayoutDom<Document> { // may no longer be true when the next layout occurs. let result = elements.drain() .map(|(k, v)| (k.to_layout(), v)) - .filter(|&(ref k, _)| k.upcast::<Node>().get_flag(IS_IN_DOC)) + .filter(|&(ref k, _)| k.upcast::<Node>().get_flag(NodeFlags::IS_IN_DOC)) .collect(); result } @@ -2466,11 +2465,11 @@ impl Document { entry.snapshot = Some(Snapshot::new(el.html_element_in_html_document())); } if attr.local_name() == &local_name!("style") { - entry.hint.insert(RESTYLE_STYLE_ATTRIBUTE); + entry.hint.insert(RestyleHint::RESTYLE_STYLE_ATTRIBUTE); } if vtable_for(el.upcast()).attribute_affects_presentational_hints(attr) { - entry.hint.insert(RESTYLE_SELF); + entry.hint.insert(RestyleHint::RESTYLE_SELF); } let snapshot = entry.snapshot.as_mut().unwrap(); diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 9045918d2f8..3f1245c1aaa 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -65,8 +65,8 @@ use dom::htmltemplateelement::HTMLTemplateElement; use dom::htmltextareaelement::{HTMLTextAreaElement, LayoutHTMLTextAreaElementHelpers}; use dom::mutationobserver::{Mutation, MutationObserver}; use dom::namednodemap::NamedNodeMap; -use dom::node::{CLICK_IN_PROGRESS, ChildrenMutation, LayoutNodeHelpers, Node}; -use dom::node::{NodeDamage, SEQUENTIALLY_FOCUSABLE, UnbindContext}; +use dom::node::{ChildrenMutation, LayoutNodeHelpers, Node}; +use dom::node::{NodeDamage, NodeFlags, UnbindContext}; use dom::node::{document_from_node, window_from_node}; use dom::nodelist::NodeList; use dom::promise::Promise; @@ -90,7 +90,6 @@ use script_thread::ScriptThread; use selectors::Element as SelectorsElement; use selectors::attr::{AttrSelectorOperation, NamespaceConstraint, CaseSensitivity}; use selectors::matching::{ElementSelectorFlags, MatchingContext, RelevantLinkStatus}; -use selectors::matching::{HAS_EDGE_CHILD_SELECTOR, HAS_SLOW_SELECTOR, HAS_SLOW_SELECTOR_LATER_SIBLINGS}; use selectors::sink::Push; use servo_arc::Arc; use servo_atoms::Atom; @@ -107,8 +106,8 @@ use style::applicable_declarations::ApplicableDeclarationBlock; use style::attr::{AttrValue, LengthOrPercentageOrAuto}; use style::context::QuirksMode; use style::dom_apis; -use style::element_state::*; -use style::invalidation::element::restyle_hints::RESTYLE_SELF; +use style::element_state::ElementState; +use style::invalidation::element::restyle_hints::RestyleHint; use style::properties::{Importance, PropertyDeclaration, PropertyDeclarationBlock, parse_style_attribute}; use style::properties::longhands::{self, background_image, border_spacing, font_family, font_size, overflow_x}; use style::rule_tree::CascadeLevel; @@ -292,7 +291,7 @@ impl Element { // FIXME(bholley): I think we should probably only do this for // NodeStyleDamaged, but I'm preserving existing behavior. - restyle.hint.insert(RESTYLE_SELF); + restyle.hint.insert(RestyleHint::RESTYLE_SELF); if damage == NodeDamage::OtherNodeDamage { restyle.damage = RestyleDamage::rebuild_and_reflow(); @@ -1069,7 +1068,7 @@ impl Element { } // TODO: Check whether the element is being rendered (i.e. not hidden). let node = self.upcast::<Node>(); - if node.get_flag(SEQUENTIALLY_FOCUSABLE) { + if node.get_flag(NodeFlags::SEQUENTIALLY_FOCUSABLE) { return true; } // https://html.spec.whatwg.org/multipage/#specially-focusable @@ -2487,11 +2486,11 @@ impl VirtualMethods for Element { } let flags = self.selector_flags.get(); - if flags.intersects(HAS_SLOW_SELECTOR) { + if flags.intersects(ElementSelectorFlags::HAS_SLOW_SELECTOR) { // All children of this node need to be restyled when any child changes. self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage); } else { - if flags.intersects(HAS_SLOW_SELECTOR_LATER_SIBLINGS) { + if flags.intersects(ElementSelectorFlags::HAS_SLOW_SELECTOR_LATER_SIBLINGS) { if let Some(next_child) = mutation.next_child() { for child in next_child.inclusively_following_siblings() { if child.is::<Element>() { @@ -2500,7 +2499,7 @@ impl VirtualMethods for Element { } } } - if flags.intersects(HAS_EDGE_CHILD_SELECTOR) { + if flags.intersects(ElementSelectorFlags::HAS_EDGE_CHILD_SELECTOR) { if let Some(child) = mutation.modified_edge_element() { child.dirty(NodeDamage::OtherNodeDamage); } @@ -2752,11 +2751,11 @@ impl Element { } pub fn click_in_progress(&self) -> bool { - self.upcast::<Node>().get_flag(CLICK_IN_PROGRESS) + self.upcast::<Node>().get_flag(NodeFlags::CLICK_IN_PROGRESS) } pub fn set_click_in_progress(&self, click: bool) { - self.upcast::<Node>().set_flag(CLICK_IN_PROGRESS, click) + self.upcast::<Node>().set_flag(NodeFlags::CLICK_IN_PROGRESS, click) } // https://html.spec.whatwg.org/multipage/#nearest-activatable-element @@ -2856,12 +2855,12 @@ impl Element { } pub fn active_state(&self) -> bool { - self.state.get().contains(IN_ACTIVE_STATE) + self.state.get().contains(ElementState::IN_ACTIVE_STATE) } /// <https://html.spec.whatwg.org/multipage/#concept-selector-active> pub fn set_active_state(&self, value: bool) { - self.set_state(IN_ACTIVE_STATE, value); + self.set_state(ElementState::IN_ACTIVE_STATE, value); if let Some(parent) = self.upcast::<Node>().GetParentElement() { parent.set_active_state(value); @@ -2869,71 +2868,71 @@ impl Element { } pub fn focus_state(&self) -> bool { - self.state.get().contains(IN_FOCUS_STATE) + self.state.get().contains(ElementState::IN_FOCUS_STATE) } pub fn set_focus_state(&self, value: bool) { - self.set_state(IN_FOCUS_STATE, value); + self.set_state(ElementState::IN_FOCUS_STATE, value); self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage); } pub fn hover_state(&self) -> bool { - self.state.get().contains(IN_HOVER_STATE) + self.state.get().contains(ElementState::IN_HOVER_STATE) } pub fn set_hover_state(&self, value: bool) { - self.set_state(IN_HOVER_STATE, value) + self.set_state(ElementState::IN_HOVER_STATE, value) } pub fn enabled_state(&self) -> bool { - self.state.get().contains(IN_ENABLED_STATE) + self.state.get().contains(ElementState::IN_ENABLED_STATE) } pub fn set_enabled_state(&self, value: bool) { - self.set_state(IN_ENABLED_STATE, value) + self.set_state(ElementState::IN_ENABLED_STATE, value) } pub fn disabled_state(&self) -> bool { - self.state.get().contains(IN_DISABLED_STATE) + self.state.get().contains(ElementState::IN_DISABLED_STATE) } pub fn set_disabled_state(&self, value: bool) { - self.set_state(IN_DISABLED_STATE, value) + self.set_state(ElementState::IN_DISABLED_STATE, value) } pub fn read_write_state(&self) -> bool { - self.state.get().contains(IN_READ_WRITE_STATE) + self.state.get().contains(ElementState::IN_READ_WRITE_STATE) } pub fn set_read_write_state(&self, value: bool) { - self.set_state(IN_READ_WRITE_STATE, value) + self.set_state(ElementState::IN_READ_WRITE_STATE, value) } pub fn placeholder_shown_state(&self) -> bool { - self.state.get().contains(IN_PLACEHOLDER_SHOWN_STATE) + self.state.get().contains(ElementState::IN_PLACEHOLDER_SHOWN_STATE) } pub fn set_placeholder_shown_state(&self, value: bool) { if self.placeholder_shown_state() != value { - self.set_state(IN_PLACEHOLDER_SHOWN_STATE, value); + self.set_state(ElementState::IN_PLACEHOLDER_SHOWN_STATE, value); self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage); } } pub fn target_state(&self) -> bool { - self.state.get().contains(IN_TARGET_STATE) + self.state.get().contains(ElementState::IN_TARGET_STATE) } pub fn set_target_state(&self, value: bool) { - self.set_state(IN_TARGET_STATE, value) + self.set_state(ElementState::IN_TARGET_STATE, value) } pub fn fullscreen_state(&self) -> bool { - self.state.get().contains(IN_FULLSCREEN_STATE) + self.state.get().contains(ElementState::IN_FULLSCREEN_STATE) } pub fn set_fullscreen_state(&self, value: bool) { - self.set_state(IN_FULLSCREEN_STATE, value) + self.set_state(ElementState::IN_FULLSCREEN_STATE, value) } /// <https://dom.spec.whatwg.org/#connected> diff --git a/components/script/dom/htmlbuttonelement.rs b/components/script/dom/htmlbuttonelement.rs index feb9a3f1805..be2b26d2085 100755 --- a/components/script/dom/htmlbuttonelement.rs +++ b/components/script/dom/htmlbuttonelement.rs @@ -27,7 +27,7 @@ use dom_struct::dom_struct; use html5ever::{LocalName, Prefix}; use std::cell::Cell; use std::default::Default; -use style::element_state::*; +use style::element_state::ElementState; #[derive(Clone, Copy, JSTraceable, PartialEq)] #[derive(MallocSizeOf)] @@ -51,7 +51,7 @@ impl HTMLButtonElement { document: &Document) -> HTMLButtonElement { HTMLButtonElement { htmlelement: - HTMLElement::new_inherited_with_state(IN_ENABLED_STATE, + HTMLElement::new_inherited_with_state(ElementState::IN_ENABLED_STATE, local_name, prefix, document), button_type: Cell::new(ButtonType::Submit), form_owner: Default::default(), diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs index f88e26a22e5..616b69ebb95 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -24,7 +24,7 @@ use dom::htmlframesetelement::HTMLFrameSetElement; use dom::htmlhtmlelement::HTMLHtmlElement; use dom::htmlinputelement::HTMLInputElement; use dom::htmllabelelement::HTMLLabelElement; -use dom::node::{Node, SEQUENTIALLY_FOCUSABLE}; +use dom::node::{Node, NodeFlags}; use dom::node::{document_from_node, window_from_node}; use dom::nodelist::NodeList; use dom::virtualmethods::VirtualMethods; @@ -76,18 +76,18 @@ impl HTMLElement { let element = self.upcast::<Element>(); let node = self.upcast::<Node>(); if element.has_attribute(&local_name!("tabindex")) { - node.set_flag(SEQUENTIALLY_FOCUSABLE, true); + node.set_flag(NodeFlags::SEQUENTIALLY_FOCUSABLE, true); } else { match node.type_id() { NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLButtonElement)) | NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLSelectElement)) | NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLIFrameElement)) | NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTextAreaElement)) - => node.set_flag(SEQUENTIALLY_FOCUSABLE, true), + => node.set_flag(NodeFlags::SEQUENTIALLY_FOCUSABLE, true), NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) | NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) => { if element.has_attribute(&local_name!("href")) { - node.set_flag(SEQUENTIALLY_FOCUSABLE, true); + node.set_flag(NodeFlags::SEQUENTIALLY_FOCUSABLE, true); } }, _ => { @@ -97,9 +97,9 @@ impl HTMLElement { AttrValue::String(ref string) => string == "true", _ => false, }; - node.set_flag(SEQUENTIALLY_FOCUSABLE, is_true); + node.set_flag(NodeFlags::SEQUENTIALLY_FOCUSABLE, is_true); } else { - node.set_flag(SEQUENTIALLY_FOCUSABLE, false); + node.set_flag(NodeFlags::SEQUENTIALLY_FOCUSABLE, false); } //TODO set SEQUENTIALLY_FOCUSABLE flag if editing host //TODO set SEQUENTIALLY_FOCUSABLE flag if "sorting interface th elements" diff --git a/components/script/dom/htmlfieldsetelement.rs b/components/script/dom/htmlfieldsetelement.rs index 81fc57dbce3..cae9aa49ee5 100644 --- a/components/script/dom/htmlfieldsetelement.rs +++ b/components/script/dom/htmlfieldsetelement.rs @@ -19,7 +19,7 @@ use dom::virtualmethods::VirtualMethods; use dom_struct::dom_struct; use html5ever::{LocalName, Prefix}; use std::default::Default; -use style::element_state::*; +use style::element_state::ElementState; #[dom_struct] pub struct HTMLFieldSetElement { @@ -33,7 +33,7 @@ impl HTMLFieldSetElement { document: &Document) -> HTMLFieldSetElement { HTMLFieldSetElement { htmlelement: - HTMLElement::new_inherited_with_state(IN_ENABLED_STATE, + HTMLElement::new_inherited_with_state(ElementState::IN_ENABLED_STATE, local_name, prefix, document), form_owner: Default::default(), } diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index d99b101dd4a..9e0c32aa057 100755 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -37,7 +37,7 @@ use dom::htmlobjectelement::HTMLObjectElement; use dom::htmloutputelement::HTMLOutputElement; use dom::htmlselectelement::HTMLSelectElement; use dom::htmltextareaelement::HTMLTextAreaElement; -use dom::node::{Node, PARSER_ASSOCIATED_FORM_OWNER, UnbindContext, VecPreOrderInsertionHelper}; +use dom::node::{Node, NodeFlags, UnbindContext, VecPreOrderInsertionHelper}; use dom::node::{document_from_node, window_from_node}; use dom::validitystate::ValidationFlags; use dom::virtualmethods::VirtualMethods; @@ -879,7 +879,7 @@ pub trait FormControl: DomObject { fn set_form_owner_from_parser(&self, form: &HTMLFormElement) { let elem = self.to_element(); let node = elem.upcast::<Node>(); - node.set_flag(PARSER_ASSOCIATED_FORM_OWNER, true); + node.set_flag(NodeFlags::PARSER_ASSOCIATED_FORM_OWNER, true); form.add_control(self); self.set_form_owner(Some(form)); } @@ -968,8 +968,8 @@ pub trait FormControl: DomObject { // Part of step 12. // '..suppress the running of the reset the form owner algorithm // when the parser subsequently attempts to insert the element..' - let must_skip_reset = node.get_flag(PARSER_ASSOCIATED_FORM_OWNER); - node.set_flag(PARSER_ASSOCIATED_FORM_OWNER, false); + let must_skip_reset = node.get_flag(NodeFlags::PARSER_ASSOCIATED_FORM_OWNER); + node.set_flag(NodeFlags::PARSER_ASSOCIATED_FORM_OWNER, false); if !must_skip_reset { self.form_attribute_mutated(AttributeMutation::Set(None)); diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index 697e32636b1..64bd9926ca3 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -57,14 +57,14 @@ use task_source::TaskSource; bitflags! { #[derive(JSTraceable, MallocSizeOf)] - flags SandboxAllowance: u8 { - const ALLOW_NOTHING = 0x00, - const ALLOW_SAME_ORIGIN = 0x01, - const ALLOW_TOP_NAVIGATION = 0x02, - const ALLOW_FORMS = 0x04, - const ALLOW_SCRIPTS = 0x08, - const ALLOW_POINTER_LOCK = 0x10, - const ALLOW_POPUPS = 0x20 + struct SandboxAllowance: u8 { + const ALLOW_NOTHING = 0x00; + const ALLOW_SAME_ORIGIN = 0x01; + const ALLOW_TOP_NAVIGATION = 0x02; + const ALLOW_FORMS = 0x04; + const ALLOW_SCRIPTS = 0x08; + const ALLOW_POINTER_LOCK = 0x10; + const ALLOW_POPUPS = 0x20; } } @@ -726,16 +726,16 @@ impl VirtualMethods for HTMLIFrameElement { match attr.local_name() { &local_name!("sandbox") => { self.sandbox_allowance.set(mutation.new_value(attr).map(|value| { - let mut modes = ALLOW_NOTHING; + let mut modes = SandboxAllowance::ALLOW_NOTHING; for token in value.as_tokens() { modes |= match &*token.to_ascii_lowercase() { - "allow-same-origin" => ALLOW_SAME_ORIGIN, - "allow-forms" => ALLOW_FORMS, - "allow-pointer-lock" => ALLOW_POINTER_LOCK, - "allow-popups" => ALLOW_POPUPS, - "allow-scripts" => ALLOW_SCRIPTS, - "allow-top-navigation" => ALLOW_TOP_NAVIGATION, - _ => ALLOW_NOTHING + "allow-same-origin" => SandboxAllowance::ALLOW_SAME_ORIGIN, + "allow-forms" => SandboxAllowance::ALLOW_FORMS, + "allow-pointer-lock" => SandboxAllowance::ALLOW_POINTER_LOCK, + "allow-popups" => SandboxAllowance::ALLOW_POPUPS, + "allow-scripts" => SandboxAllowance::ALLOW_SCRIPTS, + "allow-top-navigation" => SandboxAllowance::ALLOW_TOP_NAVIGATION, + _ => SandboxAllowance::ALLOW_NOTHING }; } modes diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 459633836d3..4fd99b289a1 100755 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -48,7 +48,7 @@ use std::borrow::ToOwned; use std::cell::Cell; use std::ops::Range; use style::attr::AttrValue; -use style::element_state::*; +use style::element_state::ElementState; use style::str::split_commas; use textinput::{SelectionDirection, TextInput}; use textinput::KeyReaction::{DispatchInput, Nothing, RedrawSelection, TriggerDefaultAction}; @@ -137,7 +137,8 @@ impl HTMLInputElement { let chan = document.window().upcast::<GlobalScope>().script_to_constellation_chan().clone(); HTMLInputElement { htmlelement: - HTMLElement::new_inherited_with_state(IN_ENABLED_STATE | IN_READ_WRITE_STATE, + HTMLElement::new_inherited_with_state(ElementState::IN_ENABLED_STATE | + ElementState::IN_READ_WRITE_STATE, local_name, prefix, document), input_type: Cell::new(InputType::InputText), placeholder: DomRefCell::new(DOMString::new()), @@ -280,13 +281,13 @@ impl LayoutHTMLInputElementHelpers for LayoutDom<HTMLInputElement> { #[allow(unrooted_must_root)] #[allow(unsafe_code)] unsafe fn checked_state_for_layout(self) -> bool { - self.upcast::<Element>().get_state_for_layout().contains(IN_CHECKED_STATE) + self.upcast::<Element>().get_state_for_layout().contains(ElementState::IN_CHECKED_STATE) } #[allow(unrooted_must_root)] #[allow(unsafe_code)] unsafe fn indeterminate_state_for_layout(self) -> bool { - self.upcast::<Element>().get_state_for_layout().contains(IN_INDETERMINATE_STATE) + self.upcast::<Element>().get_state_for_layout().contains(ElementState::IN_INDETERMINATE_STATE) } } @@ -336,7 +337,7 @@ impl HTMLInputElementMethods for HTMLInputElement { // https://html.spec.whatwg.org/multipage/#dom-input-checked fn Checked(&self) -> bool { - self.upcast::<Element>().state().contains(IN_CHECKED_STATE) + self.upcast::<Element>().state().contains(ElementState::IN_CHECKED_STATE) } // https://html.spec.whatwg.org/multipage/#dom-input-checked @@ -538,12 +539,12 @@ impl HTMLInputElementMethods for HTMLInputElement { // https://html.spec.whatwg.org/multipage/#dom-input-indeterminate fn Indeterminate(&self) -> bool { - self.upcast::<Element>().state().contains(IN_INDETERMINATE_STATE) + self.upcast::<Element>().state().contains(ElementState::IN_INDETERMINATE_STATE) } // https://html.spec.whatwg.org/multipage/#dom-input-indeterminate fn SetIndeterminate(&self, val: bool) { - self.upcast::<Element>().set_state(IN_INDETERMINATE_STATE, val) + self.upcast::<Element>().set_state(ElementState::IN_INDETERMINATE_STATE, val) } // https://html.spec.whatwg.org/multipage/#dom-lfe-labels @@ -745,7 +746,7 @@ impl HTMLInputElement { } fn update_checked_state(&self, checked: bool, dirty: bool) { - self.upcast::<Element>().set_state(IN_CHECKED_STATE, checked); + self.upcast::<Element>().set_state(ElementState::IN_CHECKED_STATE, checked); if dirty { self.checked_changed.set(true); diff --git a/components/script/dom/htmllinkelement.rs b/components/script/dom/htmllinkelement.rs index 03353d70bc4..3843bb034a7 100644 --- a/components/script/dom/htmllinkelement.rs +++ b/components/script/dom/htmllinkelement.rs @@ -35,7 +35,7 @@ use style::media_queries::parse_media_query_list; use style::parser::ParserContext as CssParserContext; use style::str::HTML_SPACE_CHARACTERS; use style::stylesheets::{CssRuleType, Stylesheet}; -use style_traits::PARSING_MODE_DEFAULT; +use style_traits::ParsingMode; use stylesheet_loader::{StylesheetLoader, StylesheetContextSource, StylesheetOwner}; #[derive(Clone, Copy, JSTraceable, MallocSizeOf, PartialEq)] @@ -287,7 +287,7 @@ impl HTMLLinkElement { let mut css_parser = CssParser::new(&mut input); let doc_url = document.url(); let context = CssParserContext::new_for_cssom(&doc_url, Some(CssRuleType::Media), - PARSING_MODE_DEFAULT, + ParsingMode::DEFAULT, document.quirks_mode()); let window = document.window(); let media = parse_media_query_list(&context, &mut css_parser, diff --git a/components/script/dom/htmloptgroupelement.rs b/components/script/dom/htmloptgroupelement.rs index 88e2d3012df..8413b464407 100644 --- a/components/script/dom/htmloptgroupelement.rs +++ b/components/script/dom/htmloptgroupelement.rs @@ -15,7 +15,7 @@ use dom::node::Node; use dom::virtualmethods::VirtualMethods; use dom_struct::dom_struct; use html5ever::{LocalName, Prefix}; -use style::element_state::*; +use style::element_state::ElementState; #[dom_struct] pub struct HTMLOptGroupElement { @@ -28,7 +28,7 @@ impl HTMLOptGroupElement { document: &Document) -> HTMLOptGroupElement { HTMLOptGroupElement { htmlelement: - HTMLElement::new_inherited_with_state(IN_ENABLED_STATE, + HTMLElement::new_inherited_with_state(ElementState::IN_ENABLED_STATE, local_name, prefix, document) } } diff --git a/components/script/dom/htmloptionelement.rs b/components/script/dom/htmloptionelement.rs index 27e86e630f7..ff59c4b0e24 100644 --- a/components/script/dom/htmloptionelement.rs +++ b/components/script/dom/htmloptionelement.rs @@ -25,7 +25,7 @@ use dom::virtualmethods::VirtualMethods; use dom_struct::dom_struct; use html5ever::{LocalName, Prefix}; use std::cell::Cell; -use style::element_state::*; +use style::element_state::ElementState; use style::str::{split_html_space_chars, str_join}; #[dom_struct] @@ -45,7 +45,7 @@ impl HTMLOptionElement { document: &Document) -> HTMLOptionElement { HTMLOptionElement { htmlelement: - HTMLElement::new_inherited_with_state(IN_ENABLED_STATE, + HTMLElement::new_inherited_with_state(ElementState::IN_ENABLED_STATE, local_name, prefix, document), selectedness: Cell::new(false), dirtiness: Cell::new(false), diff --git a/components/script/dom/htmlselectelement.rs b/components/script/dom/htmlselectelement.rs index 3423db303e4..401d29c6cb8 100755 --- a/components/script/dom/htmlselectelement.rs +++ b/components/script/dom/htmlselectelement.rs @@ -35,7 +35,7 @@ use html5ever::{LocalName, Prefix}; use std::default::Default; use std::iter; use style::attr::AttrValue; -use style::element_state::*; +use style::element_state::ElementState; #[derive(JSTraceable, MallocSizeOf)] struct OptionsFilter; @@ -73,7 +73,7 @@ impl HTMLSelectElement { document: &Document) -> HTMLSelectElement { HTMLSelectElement { htmlelement: - HTMLElement::new_inherited_with_state(IN_ENABLED_STATE, + HTMLElement::new_inherited_with_state(ElementState::IN_ENABLED_STATE, local_name, prefix, document), options: Default::default(), form_owner: Default::default(), diff --git a/components/script/dom/htmlstyleelement.rs b/components/script/dom/htmlstyleelement.rs index ef25b52dbb3..f6d2caaccf8 100644 --- a/components/script/dom/htmlstyleelement.rs +++ b/components/script/dom/htmlstyleelement.rs @@ -25,7 +25,7 @@ use std::cell::Cell; use style::media_queries::parse_media_query_list; use style::parser::ParserContext as CssParserContext; use style::stylesheets::{CssRuleType, Stylesheet, Origin}; -use style_traits::PARSING_MODE_DEFAULT; +use style_traits::ParsingMode; use stylesheet_loader::{StylesheetLoader, StylesheetOwner}; #[dom_struct] @@ -87,7 +87,7 @@ impl HTMLStyleElement { let url = window.get_url(); let context = CssParserContext::new_for_cssom(&url, Some(CssRuleType::Media), - PARSING_MODE_DEFAULT, + ParsingMode::DEFAULT, doc.quirks_mode()); let shared_lock = node.owner_doc().style_shared_lock().clone(); let mut input = ParserInput::new(&mq_str); diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs index c15553faa75..ce9c879d664 100755 --- a/components/script/dom/htmltextareaelement.rs +++ b/components/script/dom/htmltextareaelement.rs @@ -32,7 +32,7 @@ use std::cell::Cell; use std::default::Default; use std::ops::Range; use style::attr::AttrValue; -use style::element_state::*; +use style::element_state::ElementState; use textinput::{KeyReaction, Lines, SelectionDirection, TextInput}; #[dom_struct] @@ -111,7 +111,8 @@ impl HTMLTextAreaElement { let chan = document.window().upcast::<GlobalScope>().script_to_constellation_chan().clone(); HTMLTextAreaElement { htmlelement: - HTMLElement::new_inherited_with_state(IN_ENABLED_STATE | IN_READ_WRITE_STATE, + HTMLElement::new_inherited_with_state(ElementState::IN_ENABLED_STATE | + ElementState::IN_READ_WRITE_STATE, local_name, prefix, document), placeholder: DomRefCell::new(DOMString::new()), textinput: DomRefCell::new(TextInput::new( diff --git a/components/script/dom/keyboardevent.rs b/components/script/dom/keyboardevent.rs index 2d2a2391372..707c6b64afe 100644 --- a/components/script/dom/keyboardevent.rs +++ b/components/script/dom/keyboardevent.rs @@ -15,7 +15,6 @@ use dom::event::Event; use dom::uievent::UIEvent; use dom::window::Window; use dom_struct::dom_struct; -use msg::constellation_msg; use msg::constellation_msg::{Key, KeyModifiers}; use std::borrow::Cow; use std::cell::Cell; @@ -144,16 +143,16 @@ impl KeyboardEvent { pub fn get_key_modifiers(&self) -> KeyModifiers { let mut result = KeyModifiers::empty(); if self.shift.get() { - result = result | constellation_msg::SHIFT; + result = result | KeyModifiers::SHIFT; } if self.ctrl.get() { - result = result | constellation_msg::CONTROL; + result = result | KeyModifiers::CONTROL; } if self.alt.get() { - result = result | constellation_msg::ALT; + result = result | KeyModifiers::ALT; } if self.meta.get() { - result = result | constellation_msg::SUPER; + result = result | KeyModifiers::SUPER; } result } @@ -165,7 +164,7 @@ pub fn key_value(ch: Option<char>, key: Key, mods: KeyModifiers) -> Cow<'static, return Cow::from(format!("{}", ch)); } - let shift = mods.contains(constellation_msg::SHIFT); + let shift = mods.contains(KeyModifiers::SHIFT); Cow::from(match key { Key::Space => " ", Key::Apostrophe if shift => "\"", diff --git a/components/script/dom/medialist.rs b/components/script/dom/medialist.rs index 30d6ad9ed34..6ae318da582 100644 --- a/components/script/dom/medialist.rs +++ b/components/script/dom/medialist.rs @@ -18,7 +18,7 @@ use style::media_queries::MediaList as StyleMediaList; use style::parser::ParserContext; use style::shared_lock::{SharedRwLock, Locked}; use style::stylesheets::CssRuleType; -use style_traits::{PARSING_MODE_DEFAULT, ToCss}; +use style_traits::{ParsingMode, ToCss}; #[dom_struct] pub struct MediaList { @@ -78,7 +78,7 @@ impl MediaListMethods for MediaList { let url = window.get_url(); let quirks_mode = window.Document().quirks_mode(); let context = ParserContext::new_for_cssom(&url, Some(CssRuleType::Media), - PARSING_MODE_DEFAULT, + ParsingMode::DEFAULT, quirks_mode); *media_queries = parse_media_query_list(&context, &mut parser, window.css_error_reporter()); @@ -116,7 +116,7 @@ impl MediaListMethods for MediaList { let url = win.get_url(); let quirks_mode = win.Document().quirks_mode(); let context = ParserContext::new_for_cssom(&url, Some(CssRuleType::Media), - PARSING_MODE_DEFAULT, + ParsingMode::DEFAULT, quirks_mode); let m = MediaQuery::parse(&context, &mut parser); // Step 2 @@ -145,7 +145,7 @@ impl MediaListMethods for MediaList { let url = win.get_url(); let quirks_mode = win.Document().quirks_mode(); let context = ParserContext::new_for_cssom(&url, Some(CssRuleType::Media), - PARSING_MODE_DEFAULT, + ParsingMode::DEFAULT, quirks_mode); let m = MediaQuery::parse(&context, &mut parser); // Step 2 diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 0186d9e6a67..2e05eb30971 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -148,39 +148,39 @@ pub struct Node { bitflags! { #[doc = "Flags for node items."] #[derive(JSTraceable, MallocSizeOf)] - pub flags NodeFlags: u16 { + pub struct NodeFlags: u16 { #[doc = "Specifies whether this node is in a document."] - const IS_IN_DOC = 1 << 0, + const IS_IN_DOC = 1 << 0; #[doc = "Specifies whether this node needs style recalc on next reflow."] - const HAS_DIRTY_DESCENDANTS = 1 << 1, + const HAS_DIRTY_DESCENDANTS = 1 << 1; // TODO: find a better place to keep this (#4105) // https://critic.hoppipolla.co.uk/showcomment?chain=8873 // Perhaps using a Set in Document? #[doc = "Specifies whether or not there is an authentic click in progress on \ this element."] - const CLICK_IN_PROGRESS = 1 << 2, + 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."] - const SEQUENTIALLY_FOCUSABLE = 1 << 3, + const SEQUENTIALLY_FOCUSABLE = 1 << 3; /// Whether any ancestor is a fragmentation container - const CAN_BE_FRAGMENTED = 1 << 4, + const CAN_BE_FRAGMENTED = 1 << 4; // There's a free bit here. #[doc = "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, + const PARSER_ASSOCIATED_FORM_OWNER = 1 << 6; /// Whether this element has a snapshot stored due to a style or /// attribute change. /// /// See the `style::restyle_hints` module. - const HAS_SNAPSHOT = 1 << 7, + const HAS_SNAPSHOT = 1 << 7; /// Whether this element has already handled the stored snapshot. - const HANDLED_SNAPSHOT = 1 << 8, + const HANDLED_SNAPSHOT = 1 << 8; } } @@ -261,9 +261,9 @@ impl Node { let parent_in_doc = self.is_in_doc(); for node in new_child.traverse_preorder() { - node.set_flag(IS_IN_DOC, parent_in_doc); + node.set_flag(NodeFlags::IS_IN_DOC, parent_in_doc); // Out-of-document elements never have the descendants flag set. - debug_assert!(!node.get_flag(HAS_DIRTY_DESCENDANTS)); + debug_assert!(!node.get_flag(NodeFlags::HAS_DIRTY_DESCENDANTS)); vtable_for(&&*node).bind_to_tree(parent_in_doc); } let document = new_child.owner_doc(); @@ -303,8 +303,8 @@ impl Node { for node in child.traverse_preorder() { // Out-of-document elements never have the descendants flag set. - node.set_flag(IS_IN_DOC | HAS_DIRTY_DESCENDANTS | - HAS_SNAPSHOT | HANDLED_SNAPSHOT, + node.set_flag(NodeFlags::IS_IN_DOC | NodeFlags::HAS_DIRTY_DESCENDANTS | + NodeFlags::HAS_SNAPSHOT | NodeFlags::HANDLED_SNAPSHOT, false); } for node in child.traverse_preorder() { @@ -427,7 +427,7 @@ impl Node { } pub fn is_in_doc(&self) -> bool { - self.flags.get().contains(IS_IN_DOC) + self.flags.get().contains(NodeFlags::IS_IN_DOC) } /// Returns the type ID of this node. @@ -489,7 +489,7 @@ impl Node { } pub fn has_dirty_descendants(&self) -> bool { - self.get_flag(HAS_DIRTY_DESCENDANTS) + self.get_flag(NodeFlags::HAS_DIRTY_DESCENDANTS) } pub fn rev_version(&self) { @@ -1394,7 +1394,7 @@ impl Node { #[allow(unrooted_must_root)] pub fn new_document_node() -> Node { - Node::new_(NodeFlags::new() | IS_IN_DOC, None) + Node::new_(NodeFlags::new() | NodeFlags::IS_IN_DOC, None) } #[allow(unrooted_must_root)] diff --git a/components/script/dom/serviceworkerglobalscope.rs b/components/script/dom/serviceworkerglobalscope.rs index 9cffa2c341d..a0799fa0625 100644 --- a/components/script/dom/serviceworkerglobalscope.rs +++ b/components/script/dom/serviceworkerglobalscope.rs @@ -33,7 +33,7 @@ use servo_url::ServoUrl; use std::sync::mpsc::{Receiver, RecvError, Select, Sender, channel}; use std::thread; use std::time::Duration; -use style::thread_state::{self, IN_WORKER, SCRIPT}; +use style::thread_state::{self, ThreadState}; /// Messages used to control service worker event loop pub enum ServiceWorkerScriptMsg { @@ -154,7 +154,7 @@ impl ServiceWorkerGlobalScope { let serialized_worker_url = script_url.to_string(); let origin = GlobalScope::current().expect("No current global object").origin().immutable().clone(); thread::Builder::new().name(format!("ServiceWorker for {}", serialized_worker_url)).spawn(move || { - thread_state::initialize(SCRIPT | IN_WORKER); + thread_state::initialize(ThreadState::SCRIPT | ThreadState::IN_WORKER); let roots = RootCollection::new(); let _stack_roots = ThreadLocalStackRoots::new(&roots); diff --git a/components/script/dom/validitystate.rs b/components/script/dom/validitystate.rs index 0178764c3d0..58c05356204 100755 --- a/components/script/dom/validitystate.rs +++ b/components/script/dom/validitystate.rs @@ -28,17 +28,17 @@ pub enum ValidityStatus { } bitflags!{ - pub flags ValidationFlags: u32 { - const VALUE_MISSING = 0b0000000001, - const TYPE_MISMATCH = 0b0000000010, - const PATTERN_MISMATCH = 0b0000000100, - const TOO_LONG = 0b0000001000, - const TOO_SHORT = 0b0000010000, - const RANGE_UNDERFLOW = 0b0000100000, - const RANGE_OVERFLOW = 0b0001000000, - const STEP_MISMATCH = 0b0010000000, - const BAD_INPUT = 0b0100000000, - const CUSTOM_ERROR = 0b1000000000, + pub struct ValidationFlags: u32 { + const VALUE_MISSING = 0b0000000001; + const TYPE_MISMATCH = 0b0000000010; + const PATTERN_MISMATCH = 0b0000000100; + const TOO_LONG = 0b0000001000; + const TOO_SHORT = 0b0000010000; + const RANGE_UNDERFLOW = 0b0000100000; + const RANGE_OVERFLOW = 0b0001000000; + const STEP_MISMATCH = 0b0010000000; + const BAD_INPUT = 0b0100000000; + const CUSTOM_ERROR = 0b1000000000; } } diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 514fac1e492..b58481d9526 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -136,10 +136,10 @@ fn has_invalid_blend_constants(arg1: u32, arg2: u32) -> bool { /// Set of bitflags for texture unpacking (texImage2d, etc...) bitflags! { #[derive(JSTraceable, MallocSizeOf)] - flags TextureUnpacking: u8 { - const FLIP_Y_AXIS = 0x01, - const PREMULTIPLY_ALPHA = 0x02, - const CONVERT_COLORSPACE = 0x04, + struct TextureUnpacking: u8 { + const FLIP_Y_AXIS = 0x01; + const PREMULTIPLY_ALPHA = 0x02; + const CONVERT_COLORSPACE = 0x04; } } @@ -235,7 +235,7 @@ impl WebGLRenderingContext { limits: ctx_data.limits, canvas: Dom::from_ref(canvas), last_error: Cell::new(None), - texture_unpacking_settings: Cell::new(CONVERT_COLORSPACE), + texture_unpacking_settings: Cell::new(TextureUnpacking::CONVERT_COLORSPACE), texture_unpacking_alignment: Cell::new(4), bound_framebuffer: MutNullableDom::new(None), bound_textures: DomRefCell::new(Default::default()), @@ -878,7 +878,7 @@ impl WebGLRenderingContext { width: usize, height: usize, unpacking_alignment: usize) -> Vec<u8> { - if !self.texture_unpacking_settings.get().contains(FLIP_Y_AXIS) { + if !self.texture_unpacking_settings.get().contains(TextureUnpacking::FLIP_Y_AXIS) { return pixels; } @@ -906,7 +906,7 @@ impl WebGLRenderingContext { format: TexFormat, data_type: TexDataType, pixels: Vec<u8>) -> Vec<u8> { - if !self.texture_unpacking_settings.get().contains(PREMULTIPLY_ALPHA) { + if !self.texture_unpacking_settings.get().contains(TextureUnpacking::PREMULTIPLY_ALPHA) { return pixels; } @@ -990,7 +990,7 @@ impl WebGLRenderingContext { source_premultiplied: bool, source_from_image_or_canvas: bool, mut pixels: Vec<u8>) -> Vec<u8> { - let dest_premultiply = self.texture_unpacking_settings.get().contains(PREMULTIPLY_ALPHA); + let dest_premultiply = self.texture_unpacking_settings.get().contains(TextureUnpacking::PREMULTIPLY_ALPHA); if !source_premultiplied && dest_premultiply { if source_from_image_or_canvas { // When the pixels come from image or canvas or imagedata, use RGBA8 format @@ -2450,9 +2450,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { match param_name { constants::UNPACK_FLIP_Y_WEBGL => { if param_value != 0 { - texture_settings.insert(FLIP_Y_AXIS) + texture_settings.insert(TextureUnpacking::FLIP_Y_AXIS) } else { - texture_settings.remove(FLIP_Y_AXIS) + texture_settings.remove(TextureUnpacking::FLIP_Y_AXIS) } self.texture_unpacking_settings.set(texture_settings); @@ -2460,9 +2460,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { }, constants::UNPACK_PREMULTIPLY_ALPHA_WEBGL => { if param_value != 0 { - texture_settings.insert(PREMULTIPLY_ALPHA) + texture_settings.insert(TextureUnpacking::PREMULTIPLY_ALPHA) } else { - texture_settings.remove(PREMULTIPLY_ALPHA) + texture_settings.remove(TextureUnpacking::PREMULTIPLY_ALPHA) } self.texture_unpacking_settings.set(texture_settings); @@ -2471,9 +2471,9 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { constants::UNPACK_COLORSPACE_CONVERSION_WEBGL => { match param_value as u32 { constants::BROWSER_DEFAULT_WEBGL - => texture_settings.insert(CONVERT_COLORSPACE), + => texture_settings.insert(TextureUnpacking::CONVERT_COLORSPACE), constants::NONE - => texture_settings.remove(CONVERT_COLORSPACE), + => texture_settings.remove(TextureUnpacking::CONVERT_COLORSPACE), _ => return self.webgl_error(InvalidEnum), } diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 7746e637758..422abd7079e 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -109,7 +109,7 @@ use style::properties::longhands::overflow_x; use style::selector_parser::PseudoElement; use style::str::HTML_SPACE_CHARACTERS; use style::stylesheets::CssRuleType; -use style_traits::PARSING_MODE_DEFAULT; +use style_traits::ParsingMode; use task::TaskCanceller; use task_source::dom_manipulation::DOMManipulationTaskSource; use task_source::file_reading::FileReadingTaskSource; @@ -1016,7 +1016,7 @@ impl WindowMethods for Window { let url = self.get_url(); let quirks_mode = self.Document().quirks_mode(); let context = CssParserContext::new_for_cssom(&url, Some(CssRuleType::Media), - PARSING_MODE_DEFAULT, + ParsingMode::DEFAULT, quirks_mode); let media_query_list = media_queries::parse_media_query_list(&context, &mut parser, self.css_error_reporter()); diff --git a/components/script/dom/worklet.rs b/components/script/dom/worklet.rs index 7a608a189e1..39e1bdba930 100644 --- a/components/script/dom/worklet.rs +++ b/components/script/dom/worklet.rs @@ -63,7 +63,7 @@ use std::sync::mpsc; use std::sync::mpsc::Receiver; use std::sync::mpsc::Sender; use std::thread; -use style::thread_state; +use style::thread_state::{self, ThreadState}; use swapper::Swapper; use swapper::swapper; use task::TaskBox; @@ -426,7 +426,7 @@ impl WorkletThread { // TODO: set interrupt handler? // TODO: configure the JS runtime (e.g. discourage GC, encourage agressive JIT) debug!("Initializing worklet thread."); - thread_state::initialize(thread_state::SCRIPT | thread_state::IN_WORKER); + thread_state::initialize(ThreadState::SCRIPT | ThreadState::IN_WORKER); let roots = RootCollection::new(); let _stack_roots = ThreadLocalStackRoots::new(&roots); let mut thread = RootedTraceableBox::new(WorkletThread { diff --git a/components/script/lib.rs b/components/script/lib.rs index edf954d4c96..d4baa2d43e0 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -139,8 +139,7 @@ pub mod layout_exports { pub use dom::characterdata::LayoutCharacterDataHelpers; pub use dom::document::{Document, LayoutDocumentHelpers, PendingRestyle}; pub use dom::element::{Element, LayoutElementHelpers, RawLayoutElementHelpers}; - pub use dom::node::{CAN_BE_FRAGMENTED, HAS_DIRTY_DESCENDANTS, IS_IN_DOC}; - pub use dom::node::{HANDLED_SNAPSHOT, HAS_SNAPSHOT}; + pub use dom::node::NodeFlags; pub use dom::node::{LayoutNodeHelpers, Node}; pub use dom::text::Text; } diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 7985f562cbe..9416e0d11ae 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -33,7 +33,7 @@ use std::os; use std::os::raw::c_void; use std::panic::AssertUnwindSafe; use std::ptr; -use style::thread_state; +use style::thread_state::{self, ThreadState}; use task::TaskBox; use time::{Tm, now}; @@ -394,8 +394,8 @@ unsafe extern "C" fn gc_slice_callback(_rt: *mut JSRuntime, progress: GCProgress #[allow(unsafe_code)] unsafe extern "C" fn debug_gc_callback(_rt: *mut JSRuntime, status: JSGCStatus, _data: *mut os::raw::c_void) { match status { - JSGCStatus::JSGC_BEGIN => thread_state::enter(thread_state::IN_GC), - JSGCStatus::JSGC_END => thread_state::exit(thread_state::IN_GC), + JSGCStatus::JSGC_BEGIN => thread_state::enter(ThreadState::IN_GC), + JSGCStatus::JSGC_END => thread_state::exit(ThreadState::IN_GC), } } diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 354cc1928f7..72893e1e89a 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -114,7 +114,7 @@ use std::result::Result; use std::sync::Arc; use std::sync::mpsc::{Receiver, Select, Sender, channel}; use std::thread; -use style::thread_state; +use style::thread_state::{self, ThreadState}; use task_source::dom_manipulation::DOMManipulationTaskSource; use task_source::file_reading::FileReadingTaskSource; use task_source::history_traversal::HistoryTraversalTaskSource; @@ -544,7 +544,7 @@ impl ScriptThreadFactory for ScriptThread { let (sender, receiver) = channel(); let layout_chan = sender.clone(); thread::Builder::new().name(format!("ScriptThread {:?}", state.id)).spawn(move || { - thread_state::initialize(thread_state::SCRIPT); + thread_state::initialize(ThreadState::SCRIPT); PipelineNamespace::install(state.pipeline_namespace_id); TopLevelBrowsingContextId::install(state.top_level_browsing_context_id); let roots = RootCollection::new(); diff --git a/components/script/textinput.rs b/components/script/textinput.rs index 3c533964b7d..bfc34c9d5a6 100644 --- a/components/script/textinput.rs +++ b/components/script/textinput.rs @@ -7,7 +7,6 @@ use clipboard_provider::ClipboardProvider; use dom::bindings::str::DOMString; use dom::keyboardevent::KeyboardEvent; -use msg::constellation_msg::{ALT, CONTROL, SHIFT, SUPER}; use msg::constellation_msg::{Key, KeyModifiers}; use std::borrow::ToOwned; use std::cmp::{max, min}; @@ -114,12 +113,12 @@ pub enum Direction { /// i.e. cmd on Mac OS or ctrl on other platforms. #[cfg(target_os = "macos")] fn is_control_key(mods: KeyModifiers) -> bool { - mods.contains(SUPER) && !mods.contains(CONTROL | ALT) + mods.contains(KeyModifiers::SUPER) && !mods.contains(KeyModifiers::CONTROL | KeyModifiers::ALT) } #[cfg(not(target_os = "macos"))] fn is_control_key(mods: KeyModifiers) -> bool { - mods.contains(CONTROL) && !mods.contains(SUPER | ALT) + mods.contains(KeyModifiers::CONTROL) && !mods.contains(KeyModifiers::SUPER | KeyModifiers::ALT) } /// The length in bytes of the first n characters in a UTF-8 string. @@ -585,31 +584,36 @@ impl<T: ClipboardProvider> TextInput<T> { printable: Option<char>, key: Key, mods: KeyModifiers) -> KeyReaction { - let maybe_select = if mods.contains(SHIFT) { Selection::Selected } else { Selection::NotSelected }; + let maybe_select = if mods.contains(KeyModifiers::SHIFT) { + Selection::Selected + } else { + Selection::NotSelected + }; + match (printable, key) { - (_, Key::B) if mods.contains(CONTROL | ALT) => { + (_, Key::B) if mods.contains(KeyModifiers::CONTROL | KeyModifiers::ALT) => { self.adjust_horizontal_by_word(Direction::Backward, maybe_select); KeyReaction::RedrawSelection }, - (_, Key::F) if mods.contains(CONTROL | ALT) => { + (_, Key::F) if mods.contains(KeyModifiers::CONTROL | KeyModifiers::ALT) => { self.adjust_horizontal_by_word(Direction::Forward, maybe_select); KeyReaction::RedrawSelection }, - (_, Key::A) if mods.contains(CONTROL | ALT) => { + (_, Key::A) if mods.contains(KeyModifiers::CONTROL | KeyModifiers::ALT) => { self.adjust_horizontal_to_line_end(Direction::Backward, maybe_select); KeyReaction::RedrawSelection }, - (_, Key::E) if mods.contains(CONTROL | ALT) => { + (_, Key::E) if mods.contains(KeyModifiers::CONTROL | KeyModifiers::ALT) => { self.adjust_horizontal_to_line_end(Direction::Forward, maybe_select); KeyReaction::RedrawSelection }, #[cfg(target_os = "macos")] - (None, Key::A) if mods == CONTROL => { + (None, Key::A) if mods == KeyModifiers::CONTROL => { self.adjust_horizontal_to_line_end(Direction::Backward, maybe_select); KeyReaction::RedrawSelection }, #[cfg(target_os = "macos")] - (None, Key::E) if mods == CONTROL => { + (None, Key::E) if mods == KeyModifiers::CONTROL => { self.adjust_horizontal_to_line_end(Direction::Forward, maybe_select); KeyReaction::RedrawSelection }, @@ -641,30 +645,30 @@ impl<T: ClipboardProvider> TextInput<T> { KeyReaction::DispatchInput }, #[cfg(target_os = "macos")] - (None, Key::Left) if mods.contains(SUPER) => { + (None, Key::Left) if mods.contains(KeyModifiers::SUPER) => { self.adjust_horizontal_to_line_end(Direction::Backward, maybe_select); KeyReaction::RedrawSelection }, #[cfg(target_os = "macos")] - (None, Key::Right) if mods.contains(SUPER) => { + (None, Key::Right) if mods.contains(KeyModifiers::SUPER) => { self.adjust_horizontal_to_line_end(Direction::Forward, maybe_select); KeyReaction::RedrawSelection }, #[cfg(target_os = "macos")] - (None, Key::Up) if mods.contains(SUPER) => { + (None, Key::Up) if mods.contains(KeyModifiers::SUPER) => { self.adjust_horizontal_to_limit(Direction::Backward, maybe_select); KeyReaction::RedrawSelection }, #[cfg(target_os = "macos")] - (None, Key::Down) if mods.contains(SUPER) => { + (None, Key::Down) if mods.contains(KeyModifiers::SUPER) => { self.adjust_horizontal_to_limit(Direction::Forward, maybe_select); KeyReaction::RedrawSelection }, - (None, Key::Left) if mods.contains(ALT) => { + (None, Key::Left) if mods.contains(KeyModifiers::ALT) => { self.adjust_horizontal_by_word(Direction::Backward, maybe_select); KeyReaction::RedrawSelection }, - (None, Key::Right) if mods.contains(ALT) => { + (None, Key::Right) if mods.contains(KeyModifiers::ALT) => { self.adjust_horizontal_by_word(Direction::Forward, maybe_select); KeyReaction::RedrawSelection }, diff --git a/components/selectors/Cargo.toml b/components/selectors/Cargo.toml index 68681c5dbc5..d38d39689ac 100644 --- a/components/selectors/Cargo.toml +++ b/components/selectors/Cargo.toml @@ -23,7 +23,7 @@ gecko_like_types = [] bench = [] [dependencies] -bitflags = "0.7" +bitflags = "1.0" matches = "0.1" cssparser = "0.22.0" log = "0.3" diff --git a/components/selectors/matching.rs b/components/selectors/matching.rs index 596fa8afe9f..8efbd35caa9 100644 --- a/components/selectors/matching.rs +++ b/components/selectors/matching.rs @@ -20,37 +20,39 @@ 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. - pub flags ElementSelectorFlags: usize { + 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, /// :last-of-type, :nth-last-of-type, or :only-of-type. - const HAS_SLOW_SELECTOR = 1 << 0, + const HAS_SLOW_SELECTOR = 1 << 0; /// When a child is added or removed from the parent, any later /// children must be restyled, because they may match :nth-child, /// :first-of-type, or :nth-of-type. - const HAS_SLOW_SELECTOR_LATER_SIBLINGS = 1 << 1, + const HAS_SLOW_SELECTOR_LATER_SIBLINGS = 1 << 1; /// When a child is added or removed from the parent, the first and /// last children must be restyled, because they may match :first-child, /// :last-child, or :only-child. - const HAS_EDGE_CHILD_SELECTOR = 1 << 2, + const HAS_EDGE_CHILD_SELECTOR = 1 << 2; /// The element has an empty selector, so when a child is appended we /// might need to restyle the parent completely. - const HAS_EMPTY_SELECTOR = 1 << 3, + const HAS_EMPTY_SELECTOR = 1 << 3; } } impl ElementSelectorFlags { /// Returns the subset of flags that apply to the element. pub fn for_self(self) -> ElementSelectorFlags { - self & (HAS_EMPTY_SELECTOR) + self & (ElementSelectorFlags::HAS_EMPTY_SELECTOR) } /// Returns the subset of flags that apply to the parent. pub fn for_parent(self) -> ElementSelectorFlags { - self & (HAS_SLOW_SELECTOR | HAS_SLOW_SELECTOR_LATER_SIBLINGS | HAS_EDGE_CHILD_SELECTOR) + self & (ElementSelectorFlags::HAS_SLOW_SELECTOR | + ElementSelectorFlags::HAS_SLOW_SELECTOR_LATER_SIBLINGS | + ElementSelectorFlags::HAS_EDGE_CHILD_SELECTOR) } } @@ -502,7 +504,7 @@ where let combinator = selector_iter.next_sequence(); let siblings = combinator.map_or(false, |c| c.is_sibling()); if siblings { - flags_setter(element, HAS_SLOW_SELECTOR_LATER_SIBLINGS); + flags_setter(element, ElementSelectorFlags::HAS_SLOW_SELECTOR_LATER_SIBLINGS); } if !matches_all_simple_selectors { @@ -702,7 +704,7 @@ where element.is_root() } Component::Empty => { - flags_setter(element, HAS_EMPTY_SELECTOR); + flags_setter(element, ElementSelectorFlags::HAS_EMPTY_SELECTOR); element.is_empty() } Component::Scope => { @@ -777,9 +779,9 @@ where } flags_setter(element, if is_from_end { - HAS_SLOW_SELECTOR + ElementSelectorFlags::HAS_SLOW_SELECTOR } else { - HAS_SLOW_SELECTOR_LATER_SIBLINGS + ElementSelectorFlags::HAS_SLOW_SELECTOR_LATER_SIBLINGS }); // Grab a reference to the appropriate cache. @@ -872,7 +874,7 @@ where E: Element, F: FnMut(&E, ElementSelectorFlags), { - flags_setter(element, HAS_EDGE_CHILD_SELECTOR); + flags_setter(element, ElementSelectorFlags::HAS_EDGE_CHILD_SELECTOR); element.prev_sibling_element().is_none() } @@ -882,6 +884,6 @@ where E: Element, F: FnMut(&E, ElementSelectorFlags), { - flags_setter(element, HAS_EDGE_CHILD_SELECTOR); + flags_setter(element, ElementSelectorFlags::HAS_EDGE_CHILD_SELECTOR); element.next_sibling_element().is_none() } diff --git a/components/style/Cargo.toml b/components/style/Cargo.toml index eb79cdbe40f..50f3e9ba4fa 100644 --- a/components/style/Cargo.toml +++ b/components/style/Cargo.toml @@ -32,7 +32,7 @@ gecko_debug = ["nsstring_vendor/gecko_debug"] app_units = "0.5.5" arrayvec = "0.3.20" atomic_refcell = "0.1" -bitflags = "0.7" +bitflags = "1.0" byteorder = "1.0" cfg-if = "0.1.0" cssparser = "0.22.0" diff --git a/components/style/context.rs b/components/style/context.rs index a7fe03ad70c..d5110eaeb65 100644 --- a/components/style/context.rs +++ b/components/style/context.rs @@ -37,7 +37,7 @@ use style_traits::CSSPixel; use style_traits::DevicePixel; #[cfg(feature = "servo")] use style_traits::SpeculativePainter; use stylist::Stylist; -use thread_state; +use thread_state::{self, ThreadState}; use time; use timer::Timer; use traversal::DomTraversal; @@ -415,15 +415,15 @@ impl TraversalStatistics { bitflags! { /// Represents which tasks are performed in a SequentialTask of /// UpdateAnimations which is a result of normal restyle. - pub flags UpdateAnimationsTasks: u8 { + pub struct UpdateAnimationsTasks: u8 { /// Update CSS Animations. - const CSS_ANIMATIONS = structs::UpdateAnimationsTasks_CSSAnimations, + const CSS_ANIMATIONS = structs::UpdateAnimationsTasks_CSSAnimations; /// Update CSS Transitions. - const CSS_TRANSITIONS = structs::UpdateAnimationsTasks_CSSTransitions, + const CSS_TRANSITIONS = structs::UpdateAnimationsTasks_CSSTransitions; /// Update effect properties. - const EFFECT_PROPERTIES = structs::UpdateAnimationsTasks_EffectProperties, + const EFFECT_PROPERTIES = structs::UpdateAnimationsTasks_EffectProperties; /// Update animation cacade results for animations running on the compositor. - const CASCADE_RESULTS = structs::UpdateAnimationsTasks_CascadeResults, + const CASCADE_RESULTS = structs::UpdateAnimationsTasks_CascadeResults; } } @@ -431,11 +431,11 @@ bitflags! { bitflags! { /// Represents which tasks are performed in a SequentialTask as a result of /// animation-only restyle. - pub flags PostAnimationTasks: u8 { + pub struct PostAnimationTasks: u8 { /// Display property was changed from none in animation-only restyle so /// that we need to resolve styles for descendants in a subsequent /// normal restyle. - const DISPLAY_CHANGED_FROM_NONE_FOR_SMIL = 0x01, + const DISPLAY_CHANGED_FROM_NONE_FOR_SMIL = 0x01; } } @@ -477,7 +477,7 @@ impl<E: TElement> SequentialTask<E> { /// Executes this task. pub fn execute(self) { use self::SequentialTask::*; - debug_assert!(thread_state::get() == thread_state::LAYOUT); + debug_assert!(thread_state::get() == ThreadState::LAYOUT); match self { Unused(_) => unreachable!(), #[cfg(feature = "gecko")] @@ -565,7 +565,7 @@ impl<E: TElement> SelectorFlagsMap<E> { /// Applies the flags. Must be called on the main thread. pub fn apply_flags(&mut self) { - debug_assert!(thread_state::get() == thread_state::LAYOUT); + debug_assert!(thread_state::get() == ThreadState::LAYOUT); for (el, flags) in self.map.drain() { unsafe { el.set_selector_flags(flags); } } @@ -602,7 +602,7 @@ where E: TElement, { fn drop(&mut self) { - debug_assert!(thread_state::get() == thread_state::LAYOUT); + debug_assert!(thread_state::get() == ThreadState::LAYOUT); for task in self.0.drain(..) { task.execute() } @@ -797,7 +797,7 @@ impl<E: TElement> ThreadLocalStyleContext<E> { impl<E: TElement> Drop for ThreadLocalStyleContext<E> { fn drop(&mut self) { debug_assert!(self.current_element_info.is_none()); - debug_assert!(thread_state::get() == thread_state::LAYOUT); + debug_assert!(thread_state::get() == ThreadState::LAYOUT); // Apply any slow selector flags that need to be set on parents. self.selector_flags.apply_flags(); diff --git a/components/style/data.rs b/components/style/data.rs index b9aed397f23..073a62d6bed 100644 --- a/components/style/data.rs +++ b/components/style/data.rs @@ -25,9 +25,9 @@ use style_resolver::{PrimaryStyle, ResolvedElementStyles, ResolvedStyle}; bitflags! { /// Various flags stored on ElementData. #[derive(Default)] - pub flags ElementDataFlags: u8 { + pub struct ElementDataFlags: u8 { /// Whether the styles changed for this restyle. - const WAS_RESTYLED = 1 << 0, + const WAS_RESTYLED = 1 << 0; /// Whether the last traversal of this element did not do /// any style computation. This is not true during the initial /// styling pass, nor is it true when we restyle (in which case @@ -36,16 +36,16 @@ bitflags! { /// This bit always corresponds to the last time the element was /// traversed, so each traversal simply updates it with the appropriate /// value. - const TRAVERSED_WITHOUT_STYLING = 1 << 1, + const TRAVERSED_WITHOUT_STYLING = 1 << 1; /// Whether we reframed/reconstructed any ancestor or self. - const ANCESTOR_WAS_RECONSTRUCTED = 1 << 2, + const ANCESTOR_WAS_RECONSTRUCTED = 1 << 2; /// Whether the primary style of this element data was reused from another /// element via a rule node comparison. This allows us to differentiate /// between elements that shared styles because they met all the criteria /// of the style sharing cache, compared to elements that reused style /// structs via rule node identity. The former gives us stronger transitive /// guarantees that allows us to apply the style sharing cache to cousins. - const PRIMARY_STYLE_REUSED_VIA_RULE_NODE = 1 << 3, + const PRIMARY_STYLE_REUSED_VIA_RULE_NODE = 1 << 3; } } @@ -298,7 +298,7 @@ impl ElementData { /// Returns this element's primary style as a resolved style to use for sharing. pub fn share_primary_style(&self) -> PrimaryStyle { let reused_via_rule_node = - self.flags.contains(PRIMARY_STYLE_REUSED_VIA_RULE_NODE); + self.flags.contains(ElementDataFlags::PRIMARY_STYLE_REUSED_VIA_RULE_NODE); PrimaryStyle { style: ResolvedStyle(self.styles.primary().clone()), @@ -309,9 +309,9 @@ impl ElementData { /// Sets a new set of styles, returning the old ones. pub fn set_styles(&mut self, new_styles: ResolvedElementStyles) -> ElementStyles { if new_styles.primary.reused_via_rule_node { - self.flags.insert(PRIMARY_STYLE_REUSED_VIA_RULE_NODE); + self.flags.insert(ElementDataFlags::PRIMARY_STYLE_REUSED_VIA_RULE_NODE); } else { - self.flags.remove(PRIMARY_STYLE_REUSED_VIA_RULE_NODE); + self.flags.remove(ElementDataFlags::PRIMARY_STYLE_REUSED_VIA_RULE_NODE); } mem::replace(&mut self.styles, new_styles.into()) } @@ -399,7 +399,7 @@ impl ElementData { #[inline] pub fn clear_restyle_flags_and_damage(&mut self) { self.damage = RestyleDamage::empty(); - self.flags.remove(WAS_RESTYLED | ANCESTOR_WAS_RECONSTRUCTED) + self.flags.remove(ElementDataFlags::WAS_RESTYLED | ElementDataFlags::ANCESTOR_WAS_RECONSTRUCTED) } /// Returns whether this element or any ancestor is going to be @@ -416,7 +416,7 @@ impl ElementData { /// Returns whether any ancestor of this element is going to be /// reconstructed. fn reconstructed_ancestor(&self) -> bool { - self.flags.contains(ANCESTOR_WAS_RECONSTRUCTED) + self.flags.contains(ElementDataFlags::ANCESTOR_WAS_RECONSTRUCTED) } /// Sets the flag that tells us whether we've reconstructed an ancestor. @@ -424,34 +424,34 @@ impl ElementData { if reconstructed { // If it weren't for animation-only traversals, we could assert // `!self.reconstructed_ancestor()` here. - self.flags.insert(ANCESTOR_WAS_RECONSTRUCTED); + self.flags.insert(ElementDataFlags::ANCESTOR_WAS_RECONSTRUCTED); } else { - self.flags.remove(ANCESTOR_WAS_RECONSTRUCTED); + self.flags.remove(ElementDataFlags::ANCESTOR_WAS_RECONSTRUCTED); } } /// Mark this element as restyled, which is useful to know whether we need /// to do a post-traversal. pub fn set_restyled(&mut self) { - self.flags.insert(WAS_RESTYLED); - self.flags.remove(TRAVERSED_WITHOUT_STYLING); + self.flags.insert(ElementDataFlags::WAS_RESTYLED); + self.flags.remove(ElementDataFlags::TRAVERSED_WITHOUT_STYLING); } /// Returns true if this element was restyled. #[inline] pub fn is_restyle(&self) -> bool { - self.flags.contains(WAS_RESTYLED) + self.flags.contains(ElementDataFlags::WAS_RESTYLED) } /// Mark that we traversed this element without computing any style for it. pub fn set_traversed_without_styling(&mut self) { - self.flags.insert(TRAVERSED_WITHOUT_STYLING); + self.flags.insert(ElementDataFlags::TRAVERSED_WITHOUT_STYLING); } /// Returns whether the element was traversed without computing any style for /// it. pub fn traversed_without_styling(&self) -> bool { - self.flags.contains(TRAVERSED_WITHOUT_STYLING) + self.flags.contains(ElementDataFlags::TRAVERSED_WITHOUT_STYLING) } /// Returns whether this element has been part of a restyle. @@ -493,7 +493,8 @@ impl ElementData { /// happens later in the styling pipeline. The former gives us the stronger guarantees /// we need for style sharing, the latter does not. pub fn safe_for_cousin_sharing(&self) -> bool { - !self.flags.intersects(TRAVERSED_WITHOUT_STYLING | PRIMARY_STYLE_REUSED_VIA_RULE_NODE) + !self.flags.intersects(ElementDataFlags::TRAVERSED_WITHOUT_STYLING | + ElementDataFlags::PRIMARY_STYLE_REUSED_VIA_RULE_NODE) } /// Measures memory usage. diff --git a/components/style/dom.rs b/components/style/dom.rs index e9405fdc767..b8164a8c41a 100644 --- a/components/style/dom.rs +++ b/components/style/dom.rs @@ -32,7 +32,7 @@ use std::fmt::Debug; use std::hash::Hash; use std::ops::Deref; use stylist::Stylist; -use traversal_flags::{TraversalFlags, self}; +use traversal_flags::TraversalFlags; /// An opaque handle to a node, which, unlike UnsafeNode, cannot be transformed /// back into a non-opaque representation. The only safe operation that can be @@ -476,7 +476,7 @@ pub trait TElement !data.hint.has_animation_hint_or_recascade(); } - if traversal_flags.contains(traversal_flags::UnstyledOnly) { + if traversal_flags.contains(TraversalFlags::UnstyledOnly) { // We don't process invalidations in UnstyledOnly mode. return data.has_styles(); } diff --git a/components/style/element_state.rs b/components/style/element_state.rs index d6ecc3bf5a9..2958fc277b5 100644 --- a/components/style/element_state.rs +++ b/components/style/element_state.rs @@ -15,127 +15,128 @@ bitflags! { /// TODO(emilio): We really really want to use the NS_EVENT_STATE bindings /// for this. #[derive(MallocSizeOf)] - pub flags ElementState: u64 { + pub struct ElementState: u64 { /// The mouse is down on this element. /// <https://html.spec.whatwg.org/multipage/#selector-active> /// FIXME(#7333): set/unset this when appropriate - const IN_ACTIVE_STATE = 1 << 0, + const IN_ACTIVE_STATE = 1 << 0; /// This element has focus. /// <https://html.spec.whatwg.org/multipage/#selector-focus> - const IN_FOCUS_STATE = 1 << 1, + const IN_FOCUS_STATE = 1 << 1; /// The mouse is hovering over this element. /// <https://html.spec.whatwg.org/multipage/#selector-hover> - const IN_HOVER_STATE = 1 << 2, + const IN_HOVER_STATE = 1 << 2; /// Content is enabled (and can be disabled). /// <http://www.whatwg.org/html/#selector-enabled> - const IN_ENABLED_STATE = 1 << 3, + const IN_ENABLED_STATE = 1 << 3; /// Content is disabled. /// <http://www.whatwg.org/html/#selector-disabled> - const IN_DISABLED_STATE = 1 << 4, + const IN_DISABLED_STATE = 1 << 4; /// Content is checked. /// <https://html.spec.whatwg.org/multipage/#selector-checked> - const IN_CHECKED_STATE = 1 << 5, + const IN_CHECKED_STATE = 1 << 5; /// <https://html.spec.whatwg.org/multipage/#selector-indeterminate> - const IN_INDETERMINATE_STATE = 1 << 6, + const IN_INDETERMINATE_STATE = 1 << 6; /// <https://html.spec.whatwg.org/multipage/#selector-placeholder-shown> - const IN_PLACEHOLDER_SHOWN_STATE = 1 << 7, + const IN_PLACEHOLDER_SHOWN_STATE = 1 << 7; /// <https://html.spec.whatwg.org/multipage/#selector-target> - const IN_TARGET_STATE = 1 << 8, + const IN_TARGET_STATE = 1 << 8; /// <https://fullscreen.spec.whatwg.org/#%3Afullscreen-pseudo-class> - const IN_FULLSCREEN_STATE = 1 << 9, + const IN_FULLSCREEN_STATE = 1 << 9; /// <https://html.spec.whatwg.org/multipage/#selector-valid> - const IN_VALID_STATE = 1 << 10, + const IN_VALID_STATE = 1 << 10; /// <https://html.spec.whatwg.org/multipage/#selector-invalid> - const IN_INVALID_STATE = 1 << 11, + const IN_INVALID_STATE = 1 << 11; /// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-ui-valid - const IN_MOZ_UI_VALID_STATE = 1 << 12, + const IN_MOZ_UI_VALID_STATE = 1 << 12; /// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-ui-invalid - const IN_MOZ_UI_INVALID_STATE = 1 << 13, + const IN_MOZ_UI_INVALID_STATE = 1 << 13; /// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-broken - const IN_BROKEN_STATE = 1 << 14, + const IN_BROKEN_STATE = 1 << 14; /// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-user-disabled - const IN_USER_DISABLED_STATE = 1 << 15, + const IN_USER_DISABLED_STATE = 1 << 15; /// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-suppressed - const IN_SUPPRESSED_STATE = 1 << 16, + const IN_SUPPRESSED_STATE = 1 << 16; /// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-loading - const IN_LOADING_STATE = 1 << 17, + const IN_LOADING_STATE = 1 << 17; /// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-handler-blocked - const IN_HANDLER_BLOCKED_STATE = 1 << 18, + const IN_HANDLER_BLOCKED_STATE = 1 << 18; /// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-handler-disabled - const IN_HANDLER_DISABLED_STATE = 1 << 19, + const IN_HANDLER_DISABLED_STATE = 1 << 19; /// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-handler-crashed - const IN_HANDLER_CRASHED_STATE = 1 << 20, + const IN_HANDLER_CRASHED_STATE = 1 << 20; /// <https://html.spec.whatwg.org/multipage/#selector-required> - const IN_REQUIRED_STATE = 1 << 21, + const IN_REQUIRED_STATE = 1 << 21; /// <https://html.spec.whatwg.org/multipage/#selector-optional> - const IN_OPTIONAL_STATE = 1 << 22, + const IN_OPTIONAL_STATE = 1 << 22; /// <https://html.spec.whatwg.org/multipage/#selector-read-write> - const IN_READ_WRITE_STATE = 1 << 22, + const IN_READ_WRITE_STATE = 1 << 22; /// Non-standard: Older custom-elements spec. - const IN_UNRESOLVED_STATE = 1 << 23, + const IN_UNRESOLVED_STATE = 1 << 23; /// <https://html.spec.whatwg.org/multipage/#selector-visited> - const IN_VISITED_STATE = 1 << 24, + const IN_VISITED_STATE = 1 << 24; /// <https://html.spec.whatwg.org/multipage/#selector-link> - const IN_UNVISITED_STATE = 1 << 25, + const IN_UNVISITED_STATE = 1 << 25; /// <https://drafts.csswg.org/selectors-4/#the-any-link-pseudo> - const IN_VISITED_OR_UNVISITED_STATE = IN_VISITED_STATE.bits | IN_UNVISITED_STATE.bits, + const IN_VISITED_OR_UNVISITED_STATE = ElementState::IN_VISITED_STATE.bits | + ElementState::IN_UNVISITED_STATE.bits; /// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-drag-over - const IN_DRAGOVER_STATE = 1 << 26, + const IN_DRAGOVER_STATE = 1 << 26; /// <https://html.spec.whatwg.org/multipage/#selector-in-range> - const IN_INRANGE_STATE = 1 << 27, + const IN_INRANGE_STATE = 1 << 27; /// <https://html.spec.whatwg.org/multipage/#selector-out-of-range> - const IN_OUTOFRANGE_STATE = 1 << 28, + const IN_OUTOFRANGE_STATE = 1 << 28; /// <https://html.spec.whatwg.org/multipage/#selector-read-only> - const IN_MOZ_READONLY_STATE = 1 << 29, + const IN_MOZ_READONLY_STATE = 1 << 29; /// <https://html.spec.whatwg.org/multipage/#selector-read-write> - const IN_MOZ_READWRITE_STATE = 1 << 30, + const IN_MOZ_READWRITE_STATE = 1 << 30; /// <https://html.spec.whatwg.org/multipage/#selector-default> - const IN_DEFAULT_STATE = 1 << 31, + const IN_DEFAULT_STATE = 1 << 31; /// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-submit-invalid - const IN_MOZ_SUBMITINVALID_STATE = 1 << 32, + const IN_MOZ_SUBMITINVALID_STATE = 1 << 32; /// Non-standard & undocumented. - const IN_OPTIMUM_STATE = 1 << 33, + const IN_OPTIMUM_STATE = 1 << 33; /// Non-standard & undocumented. - const IN_SUB_OPTIMUM_STATE = 1 << 34, + const IN_SUB_OPTIMUM_STATE = 1 << 34; /// Non-standard & undocumented. - const IN_SUB_SUB_OPTIMUM_STATE = 1 << 35, + const IN_SUB_SUB_OPTIMUM_STATE = 1 << 35; /// Non-standard & undocumented. - const IN_DEVTOOLS_HIGHLIGHTED_STATE = 1 << 36, + const IN_DEVTOOLS_HIGHLIGHTED_STATE = 1 << 36; /// Non-standard & undocumented. - const IN_STYLEEDITOR_TRANSITIONING_STATE = 1 << 37, + const IN_STYLEEDITOR_TRANSITIONING_STATE = 1 << 37; /// Non-standard & undocumented. - const IN_INCREMENT_SCRIPT_LEVEL_STATE = 1 << 38, + const IN_INCREMENT_SCRIPT_LEVEL_STATE = 1 << 38; /// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-focusring - const IN_FOCUSRING_STATE = 1 << 39, + const IN_FOCUSRING_STATE = 1 << 39; /// Non-standard & undocumented. - const IN_HANDLER_CLICK_TO_PLAY_STATE = 1 << 40, + const IN_HANDLER_CLICK_TO_PLAY_STATE = 1 << 40; /// Non-standard & undocumented. - const IN_HANDLER_VULNERABLE_UPDATABLE_STATE = 1 << 41, + const IN_HANDLER_VULNERABLE_UPDATABLE_STATE = 1 << 41; /// Non-standard & undocumented. - const IN_HANDLER_VULNERABLE_NO_UPDATE_STATE = 1 << 42, + const IN_HANDLER_VULNERABLE_NO_UPDATE_STATE = 1 << 42; /// <https://drafts.csswg.org/selectors-4/#the-focus-within-pseudo> - const IN_FOCUS_WITHIN_STATE = 1 << 43, + const IN_FOCUS_WITHIN_STATE = 1 << 43; /// :dir matching; the states are used for dynamic change detection. /// State that elements that match :dir(ltr) are in. - const IN_LTR_STATE = 1 << 44, + const IN_LTR_STATE = 1 << 44; /// State that elements that match :dir(rtl) are in. - const IN_RTL_STATE = 1 << 45, + const IN_RTL_STATE = 1 << 45; /// State that HTML elements that have a "dir" attr are in. - const IN_HAS_DIR_ATTR_STATE = 1 << 46, + const IN_HAS_DIR_ATTR_STATE = 1 << 46; /// State that HTML elements with dir="ltr" (or something /// case-insensitively equal to "ltr") are in. - const IN_HAS_DIR_ATTR_LTR_STATE = 1 << 47, + const IN_HAS_DIR_ATTR_LTR_STATE = 1 << 47; /// State that HTML elements with dir="rtl" (or something /// case-insensitively equal to "rtl") are in. - const IN_HAS_DIR_ATTR_RTL_STATE = 1 << 48, + const IN_HAS_DIR_ATTR_RTL_STATE = 1 << 48; /// State that HTML <bdi> elements without a valid-valued "dir" attr or /// any HTML elements (including <bdi>) with dir="auto" (or something /// case-insensitively equal to "auto") are in. - const IN_HAS_DIR_ATTR_LIKE_AUTO_STATE = 1 << 49, + const IN_HAS_DIR_ATTR_LIKE_AUTO_STATE = 1 << 49; /// Non-standard & undocumented. - const IN_AUTOFILL_STATE = 1 << 50, + const IN_AUTOFILL_STATE = 1 << 50; /// Non-standard & undocumented. - const IN_AUTOFILL_PREVIEW_STATE = 1 << 51, + const IN_AUTOFILL_PREVIEW_STATE = 1 << 51; } } @@ -144,10 +145,10 @@ bitflags! { /// /// NB: Is important for this to remain in sync with Gecko's /// dom/base/nsIDocument.h. - pub flags DocumentState: u64 { + pub struct DocumentState: u64 { /// RTL locale: specific to the XUL localedir attribute - const NS_DOCUMENT_STATE_RTL_LOCALE = 1 << 0, + const NS_DOCUMENT_STATE_RTL_LOCALE = 1 << 0; /// Window activation status - const NS_DOCUMENT_STATE_WINDOW_INACTIVE = 1 << 1, + const NS_DOCUMENT_STATE_WINDOW_INACTIVE = 1 << 1; } } diff --git a/components/style/gecko/pseudo_element.rs b/components/style/gecko/pseudo_element.rs index fba462171f7..8013e91dd38 100644 --- a/components/style/gecko/pseudo_element.rs +++ b/components/style/gecko/pseudo_element.rs @@ -10,9 +10,7 @@ use cssparser::{ToCss, serialize_identifier}; use gecko_bindings::structs::{self, CSSPseudoElementType}; -use properties::{PropertyFlags, APPLIES_TO_FIRST_LETTER, APPLIES_TO_FIRST_LINE}; -use properties::APPLIES_TO_PLACEHOLDER; -use properties::ComputedValues; +use properties::{ComputedValues, PropertyFlags}; use properties::longhands::display::computed_value as display; use selector_parser::{NonTSPseudoClass, PseudoElementCascadeType, SelectorImpl}; use std::fmt; @@ -153,9 +151,9 @@ impl PseudoElement { #[inline] pub fn property_restriction(&self) -> Option<PropertyFlags> { match *self { - PseudoElement::FirstLetter => Some(APPLIES_TO_FIRST_LETTER), - PseudoElement::FirstLine => Some(APPLIES_TO_FIRST_LINE), - PseudoElement::Placeholder => Some(APPLIES_TO_PLACEHOLDER), + PseudoElement::FirstLetter => Some(PropertyFlags::APPLIES_TO_FIRST_LETTER), + PseudoElement::FirstLine => Some(PropertyFlags::APPLIES_TO_FIRST_LINE), + PseudoElement::Placeholder => Some(PropertyFlags::APPLIES_TO_PLACEHOLDER), _ => None, } } diff --git a/components/style/gecko/selector_parser.rs b/components/style/gecko/selector_parser.rs index cbc2806ef83..6305cde370c 100644 --- a/components/style/gecko/selector_parser.rs +++ b/components/style/gecko/selector_parser.rs @@ -22,11 +22,12 @@ pub use gecko::snapshot::SnapshotMap; bitflags! { // See NonTSPseudoClass::is_enabled_in() - flags NonTSPseudoClassFlag: u8 { - const PSEUDO_CLASS_ENABLED_IN_UA_SHEETS = 1 << 0, - const PSEUDO_CLASS_ENABLED_IN_CHROME = 1 << 1, + struct NonTSPseudoClassFlag: u8 { + const PSEUDO_CLASS_ENABLED_IN_UA_SHEETS = 1 << 0; + const PSEUDO_CLASS_ENABLED_IN_CHROME = 1 << 1; const PSEUDO_CLASS_ENABLED_IN_UA_SHEETS_AND_CHROME = - PSEUDO_CLASS_ENABLED_IN_UA_SHEETS.bits | PSEUDO_CLASS_ENABLED_IN_CHROME.bits, + NonTSPseudoClassFlag::PSEUDO_CLASS_ENABLED_IN_UA_SHEETS.bits | + NonTSPseudoClassFlag::PSEUDO_CLASS_ENABLED_IN_CHROME.bits; } } @@ -134,7 +135,7 @@ impl NonTSPseudoClass { fn has_any_flag(&self, flags: NonTSPseudoClassFlag) -> bool { macro_rules! check_flag { (_) => (false); - ($flags:expr) => ($flags.intersects(flags)); + ($flags:ident) => (NonTSPseudoClassFlag::$flags.intersects(flags)); } macro_rules! pseudo_class_check_is_enabled_in { (bare: [$(($css:expr, $name:ident, $gecko_type:tt, $state:tt, $flags:tt),)*], @@ -161,7 +162,7 @@ impl NonTSPseudoClass { unsafe { mozilla::StylePrefs_sUnprefixedFullscreenApiEnabled }, // Otherwise, a pseudo-class is enabled in content when it // doesn't have any enabled flag. - _ => !self.has_any_flag(PSEUDO_CLASS_ENABLED_IN_UA_SHEETS_AND_CHROME), + _ => !self.has_any_flag(NonTSPseudoClassFlag::PSEUDO_CLASS_ENABLED_IN_UA_SHEETS_AND_CHROME), } } @@ -178,7 +179,7 @@ impl NonTSPseudoClass { pub fn state_flag(&self) -> ElementState { macro_rules! flag { (_) => (ElementState::empty()); - ($state:ident) => (::element_state::$state); + ($state:ident) => (ElementState::$state); } macro_rules! pseudo_class_state { (bare: [$(($css:expr, $name:ident, $gecko_type:tt, $state:tt, $flags:tt),)*], @@ -290,9 +291,9 @@ impl<'a> SelectorParser<'a> { -> bool { pseudo_class.is_enabled_in_content() || (self.in_user_agent_stylesheet() && - pseudo_class.has_any_flag(PSEUDO_CLASS_ENABLED_IN_UA_SHEETS)) || + pseudo_class.has_any_flag(NonTSPseudoClassFlag::PSEUDO_CLASS_ENABLED_IN_UA_SHEETS)) || (self.in_chrome_stylesheet() && - pseudo_class.has_any_flag(PSEUDO_CLASS_ENABLED_IN_CHROME)) + pseudo_class.has_any_flag(NonTSPseudoClassFlag::PSEUDO_CLASS_ENABLED_IN_CHROME)) } } diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index 908af2b6bd3..c7c6fc09709 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -22,7 +22,7 @@ use context::{QuirksMode, SharedStyleContext, PostAnimationTasks, UpdateAnimatio use data::ElementData; use dom::{LayoutIterator, NodeInfo, TElement, TNode}; use dom::{OpaqueNode, PresentationalHintsSynthesizer}; -use element_state::{ElementState, DocumentState, NS_DOCUMENT_STATE_WINDOW_INACTIVE}; +use element_state::{ElementState, DocumentState}; use error_reporting::ParseErrorReporter; use font_metrics::{FontMetrics, FontMetricsProvider, FontMetricsQueryResult}; use gecko::data::PerDocumentStyleData; @@ -729,18 +729,17 @@ impl<'le> GeckoElement<'le> { /// it's probably not worth the trouble. fn selector_flags_to_node_flags(flags: ElementSelectorFlags) -> u32 { use gecko_bindings::structs::*; - use selectors::matching::*; let mut gecko_flags = 0u32; - if flags.contains(HAS_SLOW_SELECTOR) { + if flags.contains(ElementSelectorFlags::HAS_SLOW_SELECTOR) { gecko_flags |= NODE_HAS_SLOW_SELECTOR as u32; } - if flags.contains(HAS_SLOW_SELECTOR_LATER_SIBLINGS) { + if flags.contains(ElementSelectorFlags::HAS_SLOW_SELECTOR_LATER_SIBLINGS) { gecko_flags |= NODE_HAS_SLOW_SELECTOR_LATER_SIBLINGS as u32; } - if flags.contains(HAS_EDGE_CHILD_SELECTOR) { + if flags.contains(ElementSelectorFlags::HAS_EDGE_CHILD_SELECTOR) { gecko_flags |= NODE_HAS_EDGE_CHILD_SELECTOR as u32; } - if flags.contains(HAS_EMPTY_SELECTOR) { + if flags.contains(ElementSelectorFlags::HAS_EMPTY_SELECTOR) { gecko_flags |= NODE_HAS_EMPTY_SELECTOR as u32; } @@ -1080,8 +1079,7 @@ impl<'le> TElement for GeckoElement<'le> { } fn is_visited_link(&self) -> bool { - use element_state::IN_VISITED_STATE; - self.get_state().intersects(IN_VISITED_STATE) + self.get_state().intersects(ElementState::IN_VISITED_STATE) } #[inline] @@ -1192,7 +1190,6 @@ impl<'le> TElement for GeckoElement<'le> { /// Process various tasks that are a result of animation-only restyle. fn process_post_animation(&self, tasks: PostAnimationTasks) { - use context::DISPLAY_CHANGED_FROM_NONE_FOR_SMIL; use gecko_bindings::structs::nsChangeHint_nsChangeHint_Empty; use gecko_bindings::structs::nsRestyleHint_eRestyle_Subtree; @@ -1202,7 +1199,7 @@ impl<'le> TElement for GeckoElement<'le> { // the descendants in the display:none subtree. Instead of resolving // those styles in animation-only restyle, we defer it to a subsequent // normal restyle. - if tasks.intersects(DISPLAY_CHANGED_FROM_NONE_FOR_SMIL) { + if tasks.intersects(PostAnimationTasks::DISPLAY_CHANGED_FROM_NONE_FOR_SMIL) { debug_assert!(self.implemented_pseudo_element() .map_or(true, |p| !p.is_before_or_after()), "display property animation shouldn't run on pseudo elements \ @@ -1898,7 +1895,7 @@ impl<'le> ::selectors::Element for GeckoElement<'le> { NonTSPseudoClass::Link => relevant_link.is_unvisited(self, context), NonTSPseudoClass::Visited => relevant_link.is_visited(self, context), NonTSPseudoClass::MozFirstNode => { - flags_setter(self, HAS_EDGE_CHILD_SELECTOR); + flags_setter(self, ElementSelectorFlags::HAS_EDGE_CHILD_SELECTOR); let mut elem = self.as_node(); while let Some(prev) = elem.prev_sibling() { if prev.contains_non_whitespace_content() { @@ -1909,7 +1906,7 @@ impl<'le> ::selectors::Element for GeckoElement<'le> { true } NonTSPseudoClass::MozLastNode => { - flags_setter(self, HAS_EDGE_CHILD_SELECTOR); + flags_setter(self, ElementSelectorFlags::HAS_EDGE_CHILD_SELECTOR); let mut elem = self.as_node(); while let Some(next) = elem.next_sibling() { if next.contains_non_whitespace_content() { @@ -1920,7 +1917,7 @@ impl<'le> ::selectors::Element for GeckoElement<'le> { true } NonTSPseudoClass::MozOnlyWhitespace => { - flags_setter(self, HAS_EMPTY_SELECTOR); + flags_setter(self, ElementSelectorFlags::HAS_EMPTY_SELECTOR); if self.as_node().dom_children().any(|c| c.contains_non_whitespace_content()) { return false } @@ -1945,7 +1942,7 @@ impl<'le> ::selectors::Element for GeckoElement<'le> { self.get_document_theme() == DocumentTheme::Doc_Theme_Dark } NonTSPseudoClass::MozWindowInactive => { - self.document_state().contains(NS_DOCUMENT_STATE_WINDOW_INACTIVE) + self.document_state().contains(DocumentState::NS_DOCUMENT_STATE_WINDOW_INACTIVE) } NonTSPseudoClass::MozPlaceholder => false, NonTSPseudoClass::MozAny(ref sels) => { diff --git a/components/style/gecko_bindings/nsstring_vendor/Cargo.toml b/components/style/gecko_bindings/nsstring_vendor/Cargo.toml index 5aca14f7c2e..e330a0b651c 100644 --- a/components/style/gecko_bindings/nsstring_vendor/Cargo.toml +++ b/components/style/gecko_bindings/nsstring_vendor/Cargo.toml @@ -9,7 +9,7 @@ description = "Rust bindings to xpcom string types" # Revendoring nsstring from m-c into Servo [dependencies] -bitflags = "0.8" +bitflags = "1.0" [features] gecko_debug = [] diff --git a/components/style/gecko_bindings/nsstring_vendor/src/lib.rs b/components/style/gecko_bindings/nsstring_vendor/src/lib.rs index 5f287b236de..18aa9931d8a 100644 --- a/components/style/gecko_bindings/nsstring_vendor/src/lib.rs +++ b/components/style/gecko_bindings/nsstring_vendor/src/lib.rs @@ -138,13 +138,13 @@ mod data_flags { // While this has the same layout as u16, it cannot be passed // over FFI safely as a u16. #[repr(C)] - pub flags DataFlags : u16 { - const TERMINATED = 1 << 0, // IsTerminated returns true - const VOIDED = 1 << 1, // IsVoid returns true - const SHARED = 1 << 2, // mData points to a heap-allocated, shared buffer - const OWNED = 1 << 3, // mData points to a heap-allocated, raw buffer - const INLINE = 1 << 4, // mData points to a writable, inline buffer - const LITERAL = 1 << 5, // mData points to a string literal; TERMINATED will also be set + pub struct DataFlags : u16 { + const TERMINATED = 1 << 0; // IsTerminated returns true + const VOIDED = 1 << 1; // IsVoid returns true + const SHARED = 1 << 2; // mData points to a heap-allocated, shared buffer + const OWNED = 1 << 3; // mData points to a heap-allocated, raw buffer + const INLINE = 1 << 4; // mData points to a writable, inline buffer + const LITERAL = 1 << 5; // mData points to a string literal; TERMINATED will also be set } } } @@ -154,9 +154,9 @@ mod class_flags { // While this has the same layout as u16, it cannot be passed // over FFI safely as a u16. #[repr(C)] - pub flags ClassFlags : u16 { - const INLINE = 1 << 0, // |this|'s buffer is inline - const NULL_TERMINATED = 1 << 1, // |this| requires its buffer is null-terminated + pub struct ClassFlags : u16 { + const INLINE = 1 << 0; // |this|'s buffer is inline + const NULL_TERMINATED = 1 << 1; // |this| requires its buffer is null-terminated } } } @@ -212,7 +212,7 @@ macro_rules! define_string_types { $StringRepr { data: &NUL, length: 0, - dataflags: data_flags::TERMINATED | data_flags::LITERAL, + dataflags: DataFlags::TERMINATED | DataFlags::LITERAL, classflags: classflags, } } @@ -536,7 +536,7 @@ macro_rules! define_string_types { impl $String { pub fn new() -> $String { $String { - hdr: $StringRepr::new(class_flags::NULL_TERMINATED), + hdr: $StringRepr::new(ClassFlags::NULL_TERMINATED), } } } @@ -618,8 +618,8 @@ macro_rules! define_string_types { hdr: $StringRepr { data: ptr, length: length, - dataflags: data_flags::OWNED | data_flags::TERMINATED, - classflags: class_flags::NULL_TERMINATED, + dataflags: DataFlags::OWNED | DataFlags::TERMINATED, + classflags: ClassFlags::NULL_TERMINATED, } } } diff --git a/components/style/gecko_bindings/sugar/origin_flags.rs b/components/style/gecko_bindings/sugar/origin_flags.rs index 60cc9084459..ae31a34e222 100644 --- a/components/style/gecko_bindings/sugar/origin_flags.rs +++ b/components/style/gecko_bindings/sugar/origin_flags.rs @@ -13,9 +13,9 @@ use stylesheets::OriginSet; /// Checks that the values for OriginFlags are the ones we expect. pub fn assert_flags_match() { use stylesheets::origin::*; - debug_assert_eq!(OriginFlags_UserAgent.0, ORIGIN_USER_AGENT.bits()); - debug_assert_eq!(OriginFlags_Author.0, ORIGIN_AUTHOR.bits()); - debug_assert_eq!(OriginFlags_User.0, ORIGIN_USER.bits()); + debug_assert_eq!(OriginFlags_UserAgent.0, OriginSet::ORIGIN_USER_AGENT.bits()); + debug_assert_eq!(OriginFlags_Author.0, OriginSet::ORIGIN_AUTHOR.bits()); + debug_assert_eq!(OriginFlags_User.0, OriginSet::ORIGIN_USER.bits()); } impl From<OriginFlags> for OriginSet { diff --git a/components/style/invalidation/element/collector.rs b/components/style/invalidation/element/collector.rs index ff74ad9f3a2..e6583db9e14 100644 --- a/components/style/invalidation/element/collector.rs +++ b/components/style/invalidation/element/collector.rs @@ -9,11 +9,11 @@ use Atom; use context::{QuirksMode, SharedStyleContext}; use data::ElementData; use dom::TElement; -use element_state::{ElementState, IN_VISITED_OR_UNVISITED_STATE}; +use element_state::ElementState; use invalidation::element::element_wrapper::{ElementSnapshot, ElementWrapper}; use invalidation::element::invalidation_map::*; use invalidation::element::invalidator::{InvalidationVector, Invalidation, InvalidationProcessor}; -use invalidation::element::restyle_hints::*; +use invalidation::element::restyle_hints::RestyleHint; use selector_map::SelectorMap; use selector_parser::Snapshot; use selectors::NthIndexCache; @@ -102,7 +102,7 @@ where // force a restyle here. Matching doesn't depend on the actual visited // state at all, so we can't look at matching results to decide what to // do for this case. - if state_changes.intersects(IN_VISITED_OR_UNVISITED_STATE) { + if state_changes.intersects(ElementState::IN_VISITED_OR_UNVISITED_STATE) { trace!(" > visitedness change, force subtree restyle"); // We can't just return here because there may also be attribute // changes as well that imply additional hints. @@ -186,7 +186,7 @@ where }; if invalidated_self { - self.data.hint.insert(RESTYLE_SELF); + self.data.hint.insert(RestyleHint::RESTYLE_SELF); } invalidated_self @@ -195,7 +195,7 @@ where fn should_process_descendants(&mut self, element: E) -> bool { if element == self.element { return !self.data.styles.is_display_none() && - !self.data.hint.contains(RESTYLE_DESCENDANTS) + !self.data.hint.contains(RestyleHint::RESTYLE_DESCENDANTS) } let data = match element.borrow_data() { @@ -204,17 +204,17 @@ where }; !data.styles.is_display_none() && - !data.hint.contains(RESTYLE_DESCENDANTS) + !data.hint.contains(RestyleHint::RESTYLE_DESCENDANTS) } fn recursion_limit_exceeded(&mut self, element: E) { if element == self.element { - self.data.hint.insert(RESTYLE_DESCENDANTS); + self.data.hint.insert(RestyleHint::RESTYLE_DESCENDANTS); return; } if let Some(mut data) = element.mutate_data() { - data.hint.insert(RESTYLE_DESCENDANTS); + data.hint.insert(RestyleHint::RESTYLE_DESCENDANTS); } } @@ -242,7 +242,7 @@ where fn invalidated_self(&mut self, element: E) { debug_assert_ne!(element, self.element); if let Some(mut data) = element.mutate_data() { - data.hint.insert(RESTYLE_SELF); + data.hint.insert(RestyleHint::RESTYLE_SELF); } } } @@ -333,7 +333,7 @@ where return true; } let visited_dependent = - if dependency.state.intersects(IN_VISITED_OR_UNVISITED_STATE) { + if dependency.state.intersects(ElementState::IN_VISITED_OR_UNVISITED_STATE) { VisitedDependent::Yes } else { VisitedDependent::No diff --git a/components/style/invalidation/element/invalidation_map.rs b/components/style/invalidation/element/invalidation_map.rs index 1ee1358a91a..b21db89163b 100644 --- a/components/style/invalidation/element/invalidation_map.rs +++ b/components/style/invalidation/element/invalidation_map.rs @@ -20,16 +20,16 @@ use smallvec::SmallVec; #[cfg(feature = "gecko")] /// Gets the element state relevant to the given `:dir` pseudo-class selector. pub fn dir_selector_to_state(s: &[u16]) -> ElementState { - use element_state::{IN_LTR_STATE, IN_RTL_STATE}; + use element_state::ElementState; // Jump through some hoops to deal with our Box<[u16]> thing. const LTR: [u16; 4] = [b'l' as u16, b't' as u16, b'r' as u16, 0]; const RTL: [u16; 4] = [b'r' as u16, b't' as u16, b'l' as u16, 0]; if LTR == *s { - IN_LTR_STATE + ElementState::IN_LTR_STATE } else if RTL == *s { - IN_RTL_STATE + ElementState::IN_RTL_STATE } else { // :dir(something-random) is a valid selector, but shouldn't // match anything. diff --git a/components/style/invalidation/element/restyle_hints.rs b/components/style/invalidation/element/restyle_hints.rs index 06549e4fb0f..5fb95702845 100644 --- a/components/style/invalidation/element/restyle_hints.rs +++ b/components/style/invalidation/element/restyle_hints.rs @@ -10,38 +10,38 @@ use traversal_flags::TraversalFlags; bitflags! { /// The kind of restyle we need to do for a given element. - pub flags RestyleHint: u8 { + pub struct RestyleHint: u8 { /// Do a selector match of the element. - const RESTYLE_SELF = 1 << 0, + const RESTYLE_SELF = 1 << 0; /// Do a selector match of the element's descendants. - const RESTYLE_DESCENDANTS = 1 << 1, + const RESTYLE_DESCENDANTS = 1 << 1; /// Recascade the current element. - const RECASCADE_SELF = 1 << 2, + const RECASCADE_SELF = 1 << 2; /// Recascade all descendant elements. - const RECASCADE_DESCENDANTS = 1 << 3, + const RECASCADE_DESCENDANTS = 1 << 3; /// Replace the style data coming from CSS transitions without updating /// any other style data. This hint is only processed in animation-only /// traversal which is prior to normal traversal. - const RESTYLE_CSS_TRANSITIONS = 1 << 4, + const RESTYLE_CSS_TRANSITIONS = 1 << 4; /// Replace the style data coming from CSS animations without updating /// any other style data. This hint is only processed in animation-only /// traversal which is prior to normal traversal. - const RESTYLE_CSS_ANIMATIONS = 1 << 5, + const RESTYLE_CSS_ANIMATIONS = 1 << 5; /// Don't re-run selector-matching on the element, only the style /// attribute has changed, and this change didn't have any other /// dependencies. - const RESTYLE_STYLE_ATTRIBUTE = 1 << 6, + const RESTYLE_STYLE_ATTRIBUTE = 1 << 6; /// Replace the style data coming from SMIL animations without updating /// any other style data. This hint is only processed in animation-only /// traversal which is prior to normal traversal. - const RESTYLE_SMIL = 1 << 7, + const RESTYLE_SMIL = 1 << 7; } } @@ -49,26 +49,26 @@ impl RestyleHint { /// Creates a new `RestyleHint` indicating that the current element and all /// its descendants must be fully restyled. pub fn restyle_subtree() -> Self { - RESTYLE_SELF | RESTYLE_DESCENDANTS + RestyleHint::RESTYLE_SELF | RestyleHint::RESTYLE_DESCENDANTS } /// Creates a new `RestyleHint` indicating that the current element and all /// its descendants must be recascaded. pub fn recascade_subtree() -> Self { - RECASCADE_SELF | RECASCADE_DESCENDANTS + RestyleHint::RECASCADE_SELF | RestyleHint::RECASCADE_DESCENDANTS } /// Returns whether this hint invalidates the element and all its /// descendants. pub fn contains_subtree(&self) -> bool { - self.contains(RESTYLE_SELF | RESTYLE_DESCENDANTS) + self.contains(RestyleHint::RESTYLE_SELF | RestyleHint::RESTYLE_DESCENDANTS) } /// Returns whether we need to restyle this element. pub fn has_non_animation_invalidations(&self) -> bool { self.intersects( - RESTYLE_SELF | - RECASCADE_SELF | + RestyleHint::RESTYLE_SELF | + RestyleHint::RECASCADE_SELF | (Self::replacements() & !Self::for_animations()) ) } @@ -96,10 +96,10 @@ impl RestyleHint { /// Returns a new `CascadeHint` appropriate for children of the current /// element. fn propagate_for_non_animation_restyle(&self) -> Self { - if self.contains(RESTYLE_DESCENDANTS) { + if self.contains(RestyleHint::RESTYLE_DESCENDANTS) { return Self::restyle_subtree() } - if self.contains(RECASCADE_DESCENDANTS) { + if self.contains(RestyleHint::RECASCADE_DESCENDANTS) { return Self::recascade_subtree() } Self::empty() @@ -108,24 +108,24 @@ impl RestyleHint { /// Creates a new `RestyleHint` that indicates the element must be /// recascaded. pub fn recascade_self() -> Self { - RECASCADE_SELF + RestyleHint::RECASCADE_SELF } /// Returns a hint that contains all the replacement hints. pub fn replacements() -> Self { - RESTYLE_STYLE_ATTRIBUTE | Self::for_animations() + RestyleHint::RESTYLE_STYLE_ATTRIBUTE | Self::for_animations() } /// The replacements for the animation cascade levels. #[inline] pub fn for_animations() -> Self { - RESTYLE_SMIL | RESTYLE_CSS_ANIMATIONS | RESTYLE_CSS_TRANSITIONS + RestyleHint::RESTYLE_SMIL | RestyleHint::RESTYLE_CSS_ANIMATIONS | RestyleHint::RESTYLE_CSS_TRANSITIONS } /// Returns whether the hint specifies that the currently element must be /// recascaded. pub fn has_recascade_self(&self) -> bool { - self.contains(RECASCADE_SELF) + self.contains(RestyleHint::RECASCADE_SELF) } /// Returns whether the hint specifies that an animation cascade level must @@ -139,7 +139,7 @@ impl RestyleHint { /// be replaced. #[inline] pub fn has_animation_hint_or_recascade(&self) -> bool { - self.intersects(Self::for_animations() | RECASCADE_SELF) + self.intersects(Self::for_animations() | RestyleHint::RECASCADE_SELF) } /// Returns whether the hint specifies some restyle work other than an @@ -153,7 +153,7 @@ impl RestyleHint { /// for the element. #[inline] pub fn match_self(&self) -> bool { - self.intersects(RESTYLE_SELF) + self.intersects(RestyleHint::RESTYLE_SELF) } /// Returns whether the hint specifies that some cascade levels must be @@ -177,7 +177,7 @@ impl RestyleHint { // normal restyle. (We could have separate RECASCADE_SELF_NORMAL and // RECASCADE_SELF_ANIMATIONS flags to make it clear, but this isn't // currently necessary.) - self.remove(RECASCADE_SELF); + self.remove(RestyleHint::RECASCADE_SELF); } } @@ -204,23 +204,23 @@ impl From<nsRestyleHint> for RestyleHint { if (raw.0 & (eRestyle_Self.0 | eRestyle_Subtree.0)) != 0 { raw.0 &= !eRestyle_Self.0; - hint.insert(RESTYLE_SELF); + hint.insert(RestyleHint::RESTYLE_SELF); } if (raw.0 & (eRestyle_Subtree.0 | eRestyle_SomeDescendants.0)) != 0 { raw.0 &= !eRestyle_Subtree.0; raw.0 &= !eRestyle_SomeDescendants.0; - hint.insert(RESTYLE_DESCENDANTS); + hint.insert(RestyleHint::RESTYLE_DESCENDANTS); } if (raw.0 & (eRestyle_ForceDescendants.0 | eRestyle_Force.0)) != 0 { raw.0 &= !eRestyle_Force.0; - hint.insert(RECASCADE_SELF); + hint.insert(RestyleHint::RECASCADE_SELF); } if (raw.0 & eRestyle_ForceDescendants.0) != 0 { raw.0 &= !eRestyle_ForceDescendants.0; - hint.insert(RECASCADE_DESCENDANTS); + hint.insert(RestyleHint::RECASCADE_DESCENDANTS); } hint.insert(RestyleHint::from_bits_truncate(raw.0 as u8)); @@ -239,7 +239,7 @@ pub fn assert_restyle_hints_match() { use gecko_bindings::structs; macro_rules! check_restyle_hints { - ( $( $a:ident => $b:ident ),*, ) => { + ( $( $a:ident => $b:path),*, ) => { if cfg!(debug_assertions) { let mut replacements = RestyleHint::replacements(); $( @@ -254,9 +254,9 @@ pub fn assert_restyle_hints_match() { } check_restyle_hints! { - nsRestyleHint_eRestyle_CSSTransitions => RESTYLE_CSS_TRANSITIONS, - nsRestyleHint_eRestyle_CSSAnimations => RESTYLE_CSS_ANIMATIONS, - nsRestyleHint_eRestyle_StyleAttribute => RESTYLE_STYLE_ATTRIBUTE, - nsRestyleHint_eRestyle_StyleAttribute_Animations => RESTYLE_SMIL, + nsRestyleHint_eRestyle_CSSTransitions => RestyleHint::RESTYLE_CSS_TRANSITIONS, + nsRestyleHint_eRestyle_CSSAnimations => RestyleHint::RESTYLE_CSS_ANIMATIONS, + nsRestyleHint_eRestyle_StyleAttribute => RestyleHint::RESTYLE_STYLE_ATTRIBUTE, + nsRestyleHint_eRestyle_StyleAttribute_Animations => RestyleHint::RESTYLE_SMIL, } } diff --git a/components/style/invalidation/stylesheets.rs b/components/style/invalidation/stylesheets.rs index 17c9d9ce920..01cff601560 100644 --- a/components/style/invalidation/stylesheets.rs +++ b/components/style/invalidation/stylesheets.rs @@ -11,7 +11,7 @@ use Atom; use LocalName as SelectorLocalName; use dom::{TElement, TNode}; use fnv::FnvHashSet; -use invalidation::element::restyle_hints::{RESTYLE_SELF, RestyleHint}; +use invalidation::element::restyle_hints::RestyleHint; use media_queries::Device; use selector_parser::SelectorImpl; use selectors::attr::CaseSensitivity; @@ -223,12 +223,12 @@ impl StylesheetInvalidationSet { let mut self_invalid = false; - if !data.hint.contains(RESTYLE_SELF) { + if !data.hint.contains(RestyleHint::RESTYLE_SELF) { for invalidation in &self.invalid_elements { if invalidation.matches(element) { debug!("process_invalidations_in_subtree: {:?} matched self {:?}", element, invalidation); - data.hint.insert(RESTYLE_SELF); + data.hint.insert(RestyleHint::RESTYLE_SELF); self_invalid = true; break; } diff --git a/components/style/logical_geometry.rs b/components/style/logical_geometry.rs index 1e56fa8fa18..3b029ba6a2a 100644 --- a/components/style/logical_geometry.rs +++ b/components/style/logical_geometry.rs @@ -25,51 +25,51 @@ pub enum InlineBaseDirection { // TODO: improve the readability of the WritingMode serialization, refer to the Debug:fmt() bitflags!( #[cfg_attr(feature = "servo", derive(MallocSizeOf, Serialize))] - pub flags WritingMode: u8 { - const FLAG_RTL = 1 << 0, - const FLAG_VERTICAL = 1 << 1, - const FLAG_VERTICAL_LR = 1 << 2, + pub struct WritingMode: u8 { + const RTL = 1 << 0; + const VERTICAL = 1 << 1; + const VERTICAL_LR = 1 << 2; /// For vertical writing modes only. When set, line-over/line-under /// sides are inverted from block-start/block-end. This flag is /// set when sideways-lr is used. - const FLAG_LINE_INVERTED = 1 << 3, - const FLAG_SIDEWAYS = 1 << 4, - const FLAG_UPRIGHT = 1 << 5, + const LINE_INVERTED = 1 << 3; + const SIDEWAYS = 1 << 4; + const UPRIGHT = 1 << 5; } ); impl WritingMode { #[inline] pub fn is_vertical(&self) -> bool { - self.intersects(FLAG_VERTICAL) + self.intersects(WritingMode::VERTICAL) } /// Assuming .is_vertical(), does the block direction go left to right? #[inline] pub fn is_vertical_lr(&self) -> bool { - self.intersects(FLAG_VERTICAL_LR) + self.intersects(WritingMode::VERTICAL_LR) } /// Assuming .is_vertical(), does the inline direction go top to bottom? #[inline] pub fn is_inline_tb(&self) -> bool { // https://drafts.csswg.org/css-writing-modes-3/#logical-to-physical - self.intersects(FLAG_RTL) == self.intersects(FLAG_LINE_INVERTED) + self.intersects(WritingMode::RTL) == self.intersects(WritingMode::LINE_INVERTED) } #[inline] pub fn is_bidi_ltr(&self) -> bool { - !self.intersects(FLAG_RTL) + !self.intersects(WritingMode::RTL) } #[inline] pub fn is_sideways(&self) -> bool { - self.intersects(FLAG_SIDEWAYS) + self.intersects(WritingMode::SIDEWAYS) } #[inline] pub fn is_upright(&self) -> bool { - self.intersects(FLAG_UPRIGHT) + self.intersects(WritingMode::UPRIGHT) } #[inline] @@ -121,7 +121,7 @@ impl WritingMode { #[inline] pub fn inline_base_direction(&self) -> InlineBaseDirection { - if self.intersects(FLAG_RTL) { + if self.intersects(WritingMode::RTL) { InlineBaseDirection::RightToLeft } else { InlineBaseDirection::LeftToRight @@ -150,10 +150,10 @@ impl fmt::Display for WritingMode { } else { write!(formatter, " RL")?; } - if self.intersects(FLAG_SIDEWAYS) { + if self.intersects(WritingMode::SIDEWAYS) { write!(formatter, " Sideways")?; } - if self.intersects(FLAG_LINE_INVERTED) { + if self.intersects(WritingMode::LINE_INVERTED) { write!(formatter, " Inverted")?; } } else { diff --git a/components/style/matching.rs b/components/style/matching.rs index 3b3ee3e0196..5f140b54ca0 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -11,8 +11,6 @@ use context::{ElementCascadeInputs, QuirksMode, SelectorFlagsMap}; use context::{SharedStyleContext, StyleContext}; use data::ElementData; use dom::TElement; -use invalidation::element::restyle_hints::{RESTYLE_CSS_ANIMATIONS, RESTYLE_CSS_TRANSITIONS}; -use invalidation::element::restyle_hints::{RESTYLE_SMIL, RESTYLE_STYLE_ATTRIBUTE}; use invalidation::element::restyle_hints::RestyleHint; use properties::ComputedValues; use rule_tree::{CascadeLevel, StrongRuleNode}; @@ -20,7 +18,7 @@ use selector_parser::{PseudoElement, RestyleDamage}; use selectors::matching::ElementSelectorFlags; use servo_arc::{Arc, ArcBorrow}; use style_resolver::ResolvedElementStyles; -use traversal_flags; +use traversal_flags::TraversalFlags; /// Represents the result of comparing an element's old and new style. #[derive(Debug)] @@ -161,7 +159,7 @@ trait PrivateMatchMethods: TElement { // animation is running or not. // TODO: We should check which @keyframes changed/added/deleted // and update only animations corresponding to those @keyframes. - (context.shared.traversal_flags.contains(traversal_flags::ForCSSRuleChanges) && + (context.shared.traversal_flags.contains(TraversalFlags::ForCSSRuleChanges) && (has_new_animation_style || has_animations)) || !old_box_style.animations_equals(new_box_style) || (old_display_style == display::T::none && @@ -183,10 +181,10 @@ trait PrivateMatchMethods: TElement { new_values: &ComputedValues, restyle_hints: RestyleHint ) { - use context::DISPLAY_CHANGED_FROM_NONE_FOR_SMIL; + use context::PostAnimationTasks; use properties::longhands::display::computed_value as display; - if !restyle_hints.intersects(RESTYLE_SMIL) { + if !restyle_hints.intersects(RestyleHint::RESTYLE_SMIL) { return; } @@ -206,7 +204,7 @@ trait PrivateMatchMethods: TElement { // restyle). let task = ::context::SequentialTask::process_post_animation( *self, - DISPLAY_CHANGED_FROM_NONE_FOR_SMIL, + PostAnimationTasks::DISPLAY_CHANGED_FROM_NONE_FOR_SMIL, ); context.thread_local.tasks.push(task); } @@ -219,7 +217,6 @@ trait PrivateMatchMethods: TElement { new_values: &mut Arc<ComputedValues>, restyle_hint: RestyleHint, important_rules_changed: bool) { - use context::{CASCADE_RESULTS, CSS_ANIMATIONS, CSS_TRANSITIONS, EFFECT_PROPERTIES}; use context::UpdateAnimationsTasks; if context.shared.traversal_flags.for_animation_only() { @@ -237,7 +234,7 @@ trait PrivateMatchMethods: TElement { let mut tasks = UpdateAnimationsTasks::empty(); if self.needs_animations_update(context, old_values.as_ref(), new_values) { - tasks.insert(CSS_ANIMATIONS); + tasks.insert(UpdateAnimationsTasks::CSS_ANIMATIONS); } let before_change_style = if self.might_need_transitions_update(old_values.as_ref().map(|s| &**s), @@ -265,7 +262,7 @@ trait PrivateMatchMethods: TElement { if let Some(values_without_transitions) = after_change_style { *new_values = values_without_transitions; } - tasks.insert(CSS_TRANSITIONS); + tasks.insert(UpdateAnimationsTasks::CSS_TRANSITIONS); // We need to clone old_values into SequentialTask, so we can use it later. old_values.clone() @@ -277,9 +274,9 @@ trait PrivateMatchMethods: TElement { }; if self.has_animations() { - tasks.insert(EFFECT_PROPERTIES); + tasks.insert(UpdateAnimationsTasks::EFFECT_PROPERTIES); if important_rules_changed { - tasks.insert(CASCADE_RESULTS); + tasks.insert(UpdateAnimationsTasks::CASCADE_RESULTS); } } @@ -345,7 +342,7 @@ trait PrivateMatchMethods: TElement { debug!("accumulate_damage_for: {:?}", self); // Don't accumulate damage if we're in a forgetful traversal. - if shared_context.traversal_flags.contains(traversal_flags::Forgetful) { + if shared_context.traversal_flags.contains(TraversalFlags::Forgetful) { debug!(" > forgetful traversal"); return ChildCascadeRequirement::MustCascadeChildren; } @@ -401,7 +398,7 @@ trait PrivateMatchMethods: TElement { // seems not common enough to care about. #[cfg(feature = "gecko")] { - use values::specified::align; + use values::specified::align::AlignFlags; let old_justify_items = old_values.get_position().clone_justify_items(); @@ -409,10 +406,10 @@ trait PrivateMatchMethods: TElement { new_values.get_position().clone_justify_items(); let was_legacy_justify_items = - old_justify_items.computed.0.contains(align::ALIGN_LEGACY); + old_justify_items.computed.0.contains(AlignFlags::LEGACY); let is_legacy_justify_items = - new_justify_items.computed.0.contains(align::ALIGN_LEGACY); + new_justify_items.computed.0.contains(AlignFlags::LEGACY); if is_legacy_justify_items != was_legacy_justify_items { return ChildCascadeRequirement::MustCascadeChildren; @@ -584,7 +581,7 @@ pub trait MatchMethods : TElement { } // Don't accumulate damage if we're in a forgetful traversal. - if context.shared.traversal_flags.contains(traversal_flags::Forgetful) { + if context.shared.traversal_flags.contains(TraversalFlags::Forgetful) { return ChildCascadeRequirement::MustCascadeChildren; } @@ -768,7 +765,7 @@ pub trait MatchMethods : TElement { if !context.shared.traversal_flags.for_animation_only() { let mut result = false; - if replacements.contains(RESTYLE_STYLE_ATTRIBUTE) { + if replacements.contains(RestyleHint::RESTYLE_STYLE_ATTRIBUTE) { let style_attribute = self.style_attribute(); result |= replace_rule_node(CascadeLevel::StyleAttributeNormal, style_attribute, @@ -790,7 +787,7 @@ pub trait MatchMethods : TElement { if replacements.intersects(RestyleHint::for_animations()) { debug_assert!(context.shared.traversal_flags.for_animation_only()); - if replacements.contains(RESTYLE_SMIL) { + if replacements.contains(RestyleHint::RESTYLE_SMIL) { replace_rule_node(CascadeLevel::SMILOverride, self.get_smil_override(), primary_rules); @@ -806,12 +803,12 @@ pub trait MatchMethods : TElement { // Apply Transition rules and Animation rules if the corresponding restyle hint // is contained. - if replacements.contains(RESTYLE_CSS_TRANSITIONS) { + if replacements.contains(RestyleHint::RESTYLE_CSS_TRANSITIONS) { replace_rule_node_for_animation(CascadeLevel::Transitions, primary_rules); } - if replacements.contains(RESTYLE_CSS_ANIMATIONS) { + if replacements.contains(RestyleHint::RESTYLE_CSS_ANIMATIONS) { replace_rule_node_for_animation(CascadeLevel::Animations, primary_rules); } diff --git a/components/style/parser.rs b/components/style/parser.rs index 6e08d937b76..4237b3bf041 100644 --- a/components/style/parser.rs +++ b/components/style/parser.rs @@ -8,8 +8,6 @@ use context::QuirksMode; use cssparser::{Parser, SourceLocation, UnicodeRange}; use error_reporting::{ParseErrorReporter, ContextualParseError}; use style_traits::{OneOrMoreSeparated, ParseError, ParsingMode, Separator}; -#[cfg(feature = "gecko")] -use style_traits::{PARSING_MODE_DEFAULT, PARSING_MODE_ALLOW_UNITLESS_LENGTH, PARSING_MODE_ALLOW_ALL_NUMERIC_VALUES}; use stylesheets::{CssRuleType, Origin, UrlExtraData, Namespaces}; /// Asserts that all ParsingMode flags have a matching ParsingMode value in gecko. @@ -19,7 +17,7 @@ pub fn assert_parsing_mode_match() { use gecko_bindings::structs; macro_rules! check_parsing_modes { - ( $( $a:ident => $b:ident ),*, ) => { + ( $( $a:ident => $b:path ),*, ) => { if cfg!(debug_assertions) { let mut modes = ParsingMode::all(); $( @@ -32,9 +30,9 @@ pub fn assert_parsing_mode_match() { } check_parsing_modes! { - ParsingMode_Default => PARSING_MODE_DEFAULT, - ParsingMode_AllowUnitlessLength => PARSING_MODE_ALLOW_UNITLESS_LENGTH, - ParsingMode_AllowAllNumericValues => PARSING_MODE_ALLOW_ALL_NUMERIC_VALUES, + ParsingMode_Default => ParsingMode::DEFAULT, + ParsingMode_AllowUnitlessLength => ParsingMode::ALLOW_UNITLESS_LENGTH, + ParsingMode_AllowAllNumericValues => ParsingMode::ALLOW_ALL_NUMERIC_VALUES, } } diff --git a/components/style/properties/computed_value_flags.rs b/components/style/properties/computed_value_flags.rs index 3c1b15474cd..ca045946201 100644 --- a/components/style/properties/computed_value_flags.rs +++ b/components/style/properties/computed_value_flags.rs @@ -11,13 +11,13 @@ bitflags! { /// anonymous boxes, see StyleBuilder::for_inheritance and its callsites. /// If we ever want to add some flags that shouldn't inherit for them, /// we might want to add a function to handle this. - pub flags ComputedValueFlags: u16 { + pub struct ComputedValueFlags: u16 { /// Whether the style or any of the ancestors has a text-decoration-line /// property that should get propagated to descendants. /// /// text-decoration-line is a reset property, but gets propagated in the /// frame/box tree. - const HAS_TEXT_DECORATION_LINES = 1 << 0, + const HAS_TEXT_DECORATION_LINES = 1 << 0; /// Whether line break inside should be suppressed. /// @@ -27,41 +27,41 @@ bitflags! { /// /// This bit is propagated to all children of line participants. /// It is currently used by ruby to make its content unbreakable. - const SHOULD_SUPPRESS_LINEBREAK = 1 << 1, + const SHOULD_SUPPRESS_LINEBREAK = 1 << 1; /// A flag used to mark text that that has text-combine-upright. /// /// This is used from Gecko's layout engine. - const IS_TEXT_COMBINED = 1 << 2, + const IS_TEXT_COMBINED = 1 << 2; /// A flag used to mark styles under a relevant link that is also /// visited. - const IS_RELEVANT_LINK_VISITED = 1 << 3, + const IS_RELEVANT_LINK_VISITED = 1 << 3; /// A flag used to mark styles which are a pseudo-element or under one. - const IS_IN_PSEUDO_ELEMENT_SUBTREE = 1 << 4, + const IS_IN_PSEUDO_ELEMENT_SUBTREE = 1 << 4; /// A flag used to mark styles which are in a display: none subtree, or /// under one. - const IS_IN_DISPLAY_NONE_SUBTREE = 1 << 5, + const IS_IN_DISPLAY_NONE_SUBTREE = 1 << 5; /// Whether this style inherits the `display` property. /// /// This is important because it may affect our optimizations to avoid /// computing the style of pseudo-elements, given whether the /// pseudo-element is generated depends on the `display` value. - const INHERITS_DISPLAY = 1 << 6, + const INHERITS_DISPLAY = 1 << 6; /// Whether this style inherits the `content` property. /// /// Important because of the same reason. - const INHERITS_CONTENT = 1 << 7, + const INHERITS_CONTENT = 1 << 7; /// Whether the child explicitly inherits any reset property. - const INHERITS_RESET_STYLE = 1 << 8, + const INHERITS_RESET_STYLE = 1 << 8; /// A flag to mark a style which is a visited style. - const IS_STYLE_IF_VISITED = 1 << 9, + const IS_STYLE_IF_VISITED = 1 << 9; } } @@ -69,6 +69,8 @@ impl ComputedValueFlags { /// Returns the flags that are inherited. #[inline] pub fn inherited(self) -> Self { - self & !(INHERITS_DISPLAY | INHERITS_CONTENT | INHERITS_RESET_STYLE) + self & !(ComputedValueFlags::INHERITS_DISPLAY | + ComputedValueFlags::INHERITS_CONTENT | + ComputedValueFlags::INHERITS_RESET_STYLE) } } diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index 7053433f9d5..4e074be6a4b 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -19,7 +19,7 @@ use smallvec::SmallVec; use std::fmt; use std::iter::{DoubleEndedIterator, Zip}; use std::slice::Iter; -use style_traits::{PARSING_MODE_DEFAULT, ToCss, ParseError, ParsingMode, StyleParseErrorKind}; +use style_traits::{ToCss, ParseError, ParsingMode, StyleParseErrorKind}; use stylesheets::{CssRuleType, Origin, UrlExtraData}; use super::*; use values::computed::Context; @@ -853,7 +853,7 @@ impl ToCss for PropertyDeclarationBlock { // Substeps 7 and 8 // We need to check the shorthand whether it's an alias property or not. // If it's an alias property, it should be serialized like its longhand. - if shorthand.flags().contains(SHORTHAND_ALIAS_PROPERTY) { + if shorthand.flags().contains(PropertyFlags::SHORTHAND_ALIAS_PROPERTY) { append_serialization::<_, Cloned<slice::Iter< _>>, _>( dest, &property, @@ -1023,7 +1023,7 @@ pub fn parse_style_attribute<R>(input: &str, let context = ParserContext::new(Origin::Author, url_data, Some(CssRuleType::Style), - PARSING_MODE_DEFAULT, + ParsingMode::DEFAULT, quirks_mode); let error_context = ParserErrorContext { error_reporter: error_reporter }; let mut input = ParserInput::new(input); diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 7831f76aabd..2a50234d301 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -1538,7 +1538,7 @@ fn static_assert() { } pub fn set_computed_justify_items(&mut self, v: values::specified::JustifyItems) { - debug_assert!(v.0 != ::values::specified::align::ALIGN_AUTO); + debug_assert!(v.0 != ::values::specified::align::AlignFlags::AUTO); self.gecko.mJustifyItems = v.into(); } @@ -3364,20 +3364,20 @@ fn static_assert() { use properties::longhands::will_change::computed_value::T; fn will_change_bitfield_from_prop_flags(prop: &LonghandId) -> u8 { - use properties::{ABSPOS_CB, CREATES_STACKING_CONTEXT, FIXPOS_CB}; + use properties::PropertyFlags; use gecko_bindings::structs::NS_STYLE_WILL_CHANGE_ABSPOS_CB; use gecko_bindings::structs::NS_STYLE_WILL_CHANGE_FIXPOS_CB; use gecko_bindings::structs::NS_STYLE_WILL_CHANGE_STACKING_CONTEXT; let servo_flags = prop.flags(); let mut bitfield = 0; - if servo_flags.contains(CREATES_STACKING_CONTEXT) { + if servo_flags.contains(PropertyFlags::CREATES_STACKING_CONTEXT) { bitfield |= NS_STYLE_WILL_CHANGE_STACKING_CONTEXT; } - if servo_flags.contains(FIXPOS_CB) { + if servo_flags.contains(PropertyFlags::FIXPOS_CB) { bitfield |= NS_STYLE_WILL_CHANGE_FIXPOS_CB; } - if servo_flags.contains(ABSPOS_CB) { + if servo_flags.contains(PropertyFlags::ABSPOS_CB) { bitfield |= NS_STYLE_WILL_CHANGE_ABSPOS_CB; } @@ -3470,26 +3470,26 @@ fn static_assert() { use gecko_bindings::structs::NS_STYLE_CONTAIN_STYLE; use gecko_bindings::structs::NS_STYLE_CONTAIN_PAINT; use gecko_bindings::structs::NS_STYLE_CONTAIN_ALL_BITS; - use properties::longhands::contain; + use properties::longhands::contain::SpecifiedValue; if v.is_empty() { self.gecko.mContain = NS_STYLE_CONTAIN_NONE as u8; return; } - if v.contains(contain::STRICT) { + if v.contains(SpecifiedValue::STRICT) { self.gecko.mContain = (NS_STYLE_CONTAIN_STRICT | NS_STYLE_CONTAIN_ALL_BITS) as u8; return; } let mut bitfield = 0; - if v.contains(contain::LAYOUT) { + if v.contains(SpecifiedValue::LAYOUT) { bitfield |= NS_STYLE_CONTAIN_LAYOUT; } - if v.contains(contain::STYLE) { + if v.contains(SpecifiedValue::STYLE) { bitfield |= NS_STYLE_CONTAIN_STYLE; } - if v.contains(contain::PAINT) { + if v.contains(SpecifiedValue::PAINT) { bitfield |= NS_STYLE_CONTAIN_PAINT; } @@ -3502,25 +3502,25 @@ fn static_assert() { use gecko_bindings::structs::NS_STYLE_CONTAIN_STYLE; use gecko_bindings::structs::NS_STYLE_CONTAIN_PAINT; use gecko_bindings::structs::NS_STYLE_CONTAIN_ALL_BITS; - use properties::longhands::contain; + use properties::longhands::contain::{self, SpecifiedValue}; let mut servo_flags = contain::computed_value::T::empty(); let gecko_flags = self.gecko.mContain; if gecko_flags & (NS_STYLE_CONTAIN_STRICT as u8) != 0 && gecko_flags & (NS_STYLE_CONTAIN_ALL_BITS as u8) != 0 { - servo_flags.insert(contain::STRICT | contain::STRICT_BITS); + servo_flags.insert(SpecifiedValue::STRICT | SpecifiedValue::STRICT_BITS); return servo_flags; } if gecko_flags & (NS_STYLE_CONTAIN_LAYOUT as u8) != 0 { - servo_flags.insert(contain::LAYOUT); + servo_flags.insert(SpecifiedValue::LAYOUT); } if gecko_flags & (NS_STYLE_CONTAIN_STYLE as u8) != 0{ - servo_flags.insert(contain::STYLE); + servo_flags.insert(SpecifiedValue::STYLE); } if gecko_flags & (NS_STYLE_CONTAIN_PAINT as u8) != 0 { - servo_flags.insert(contain::PAINT); + servo_flags.insert(SpecifiedValue::PAINT); } return servo_flags; diff --git a/components/style/properties/longhand/background.mako.rs b/components/style/properties/longhand/background.mako.rs index 069f272e4c1..a0a6e680863 100644 --- a/components/style/properties/longhand/background.mako.rs +++ b/components/style/properties/longhand/background.mako.rs @@ -15,7 +15,8 @@ ${helpers.predefined_type( animation_value_type="AnimatedColor", ignored_when_colors_disabled=True, allow_quirks=True, - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""", )} ${helpers.predefined_type("background-image", "ImageLayer", @@ -25,7 +26,8 @@ ${helpers.predefined_type("background-image", "ImageLayer", vector="True", animation_value_type="discrete", ignored_when_colors_disabled="True", - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER")} + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""")} % for (axis, direction, initial) in [("x", "Horizontal", "left"), ("y", "Vertical", "top")]: ${helpers.predefined_type( @@ -36,13 +38,15 @@ ${helpers.predefined_type("background-image", "ImageLayer", spec="https://drafts.csswg.org/css-backgrounds-4/#propdef-background-position-" + axis, animation_value_type="ComputedValue", vector=True, - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""", )} % endfor <%helpers:vector_longhand name="background-repeat" animation_value_type="discrete" spec="https://drafts.csswg.org/css-backgrounds/#the-background-repeat" - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER"> + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER"""> use std::fmt; use style_traits::ToCss; @@ -142,7 +146,8 @@ ${helpers.single_keyword("background-attachment", gecko_constant_prefix="NS_STYLE_IMAGELAYER_ATTACHMENT", spec="https://drafts.csswg.org/css-backgrounds/#the-background-attachment", animation_value_type="discrete", - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER")} + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""")} ${helpers.single_keyword("background-clip", "border-box padding-box content-box", @@ -151,7 +156,8 @@ ${helpers.single_keyword("background-clip", gecko_enum_prefix="StyleGeometryBox", spec="https://drafts.csswg.org/css-backgrounds/#the-background-clip", animation_value_type="discrete", - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER")} + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""")} ${helpers.single_keyword("background-origin", "padding-box border-box content-box", @@ -159,7 +165,8 @@ ${helpers.single_keyword("background-origin", gecko_enum_prefix="StyleGeometryBox", spec="https://drafts.csswg.org/css-backgrounds/#the-background-origin", animation_value_type="discrete", - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER")} + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""")} ${helpers.predefined_type("background-size", "BackgroundSize", initial_value="computed::BackgroundSize::auto()", @@ -168,7 +175,8 @@ ${helpers.predefined_type("background-size", "BackgroundSize", vector=True, animation_value_type="BackgroundSizeList", need_animatable=True, - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""", extra_prefixes="webkit")} // https://drafts.fxtf.org/compositing/#background-blend-mode @@ -179,4 +187,5 @@ ${helpers.single_keyword("background-blend-mode", gecko_constant_prefix="NS_STYLE_BLEND", vector=True, products="gecko", animation_value_type="discrete", spec="https://drafts.fxtf.org/compositing/#background-blend-mode", - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER")} + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""")} diff --git a/components/style/properties/longhand/border.mako.rs b/components/style/properties/longhand/border.mako.rs index 7e33bb886f1..01fdb52ab5e 100644 --- a/components/style/properties/longhand/border.mako.rs +++ b/components/style/properties/longhand/border.mako.rs @@ -28,7 +28,7 @@ animation_value_type="AnimatedColor", logical=is_logical, allow_quirks=not is_logical, - flags="APPLIES_TO_FIRST_LETTER", + flags="PropertyFlags::APPLIES_TO_FIRST_LETTER", ignored_when_colors_disabled=True, )} @@ -36,7 +36,7 @@ "specified::BorderStyle::none", alias=maybe_moz_logical_alias(product, side, "-moz-border-%s-style"), spec=maybe_logical_spec(side, "style"), - flags="APPLIES_TO_FIRST_LETTER", + flags="PropertyFlags::APPLIES_TO_FIRST_LETTER", animation_value_type="discrete" if not is_logical else "none", logical=is_logical)} @@ -48,7 +48,7 @@ spec=maybe_logical_spec(side, "width"), animation_value_type="NonNegativeLength", logical=is_logical, - flags="APPLIES_TO_FIRST_LETTER", + flags="PropertyFlags::APPLIES_TO_FIRST_LETTER", allow_quirks=not is_logical)} % endfor @@ -63,7 +63,7 @@ ${helpers.gecko_keyword_conversion(Keyword('border-style', "parse", extra_prefixes="webkit", spec="https://drafts.csswg.org/css-backgrounds/#border-%s-radius" % corner, boxed=True, - flags="APPLIES_TO_FIRST_LETTER", + flags="PropertyFlags::APPLIES_TO_FIRST_LETTER", animation_value_type="BorderCornerRadius")} % endfor @@ -73,7 +73,7 @@ ${helpers.gecko_keyword_conversion(Keyword('border-style', <%helpers:longhand name="-moz-border-${side}-colors" animation_value_type="discrete" spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-border-*-colors)" products="gecko" - flags="APPLIES_TO_FIRST_LETTER" + flags="PropertyFlags::APPLIES_TO_FIRST_LETTER" ignored_when_colors_disabled="True"> use std::fmt; use style_traits::ToCss; @@ -207,7 +207,7 @@ ${helpers.predefined_type("border-image-source", "ImageLayer", spec="https://drafts.csswg.org/css-backgrounds/#the-background-image", vector=False, animation_value_type="discrete", - flags="APPLIES_TO_FIRST_LETTER", + flags="PropertyFlags::APPLIES_TO_FIRST_LETTER", boxed="True")} ${helpers.predefined_type("border-image-outset", "LengthOrNumberRect", @@ -216,11 +216,11 @@ ${helpers.predefined_type("border-image-outset", "LengthOrNumberRect", initial_specified_value="specified::LengthOrNumberRect::all(specified::LengthOrNumber::zero())", spec="https://drafts.csswg.org/css-backgrounds/#border-image-outset", animation_value_type="discrete", - flags="APPLIES_TO_FIRST_LETTER", + flags="PropertyFlags::APPLIES_TO_FIRST_LETTER", boxed=True)} <%helpers:longhand name="border-image-repeat" animation_value_type="discrete" - flags="APPLIES_TO_FIRST_LETTER" + flags="PropertyFlags::APPLIES_TO_FIRST_LETTER" spec="https://drafts.csswg.org/css-backgrounds/#border-image-repeat"> use style_traits::ToCss; @@ -279,7 +279,7 @@ ${helpers.predefined_type("border-image-width", "BorderImageWidth", initial_specified_value="specified::BorderImageWidth::all(specified::BorderImageSideWidth::one())", spec="https://drafts.csswg.org/css-backgrounds/#border-image-width", animation_value_type="discrete", - flags="APPLIES_TO_FIRST_LETTER", + flags="PropertyFlags::APPLIES_TO_FIRST_LETTER", boxed=True)} ${helpers.predefined_type("border-image-slice", "BorderImageSlice", @@ -287,7 +287,7 @@ ${helpers.predefined_type("border-image-slice", "BorderImageSlice", initial_specified_value="specified::NumberOrPercentage::Percentage(specified::Percentage::new(1.)).into()", spec="https://drafts.csswg.org/css-backgrounds/#border-image-slice", animation_value_type="discrete", - flags="APPLIES_TO_FIRST_LETTER", + flags="PropertyFlags::APPLIES_TO_FIRST_LETTER", boxed=True)} #[cfg(feature = "gecko")] diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index a6d23949d75..5800d5a91f4 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -16,7 +16,7 @@ <%helpers:longhand name="display" animation_value_type="discrete" custom_cascade="${product == 'servo'}" - flags="APPLIES_TO_PLACEHOLDER" + flags="PropertyFlags::APPLIES_TO_PLACEHOLDER" spec="https://drafts.csswg.org/css-display/#propdef-display"> <% values = """inline block inline-block @@ -227,7 +227,7 @@ ${helpers.single_keyword("-moz-top-layer", "none top", ${helpers.single_keyword("position", "static absolute relative fixed sticky", animation_value_type="discrete", - flags="CREATES_STACKING_CONTEXT ABSPOS_CB", + flags="PropertyFlags::CREATES_STACKING_CONTEXT PropertyFlags::ABSPOS_CB", spec="https://drafts.csswg.org/css-position/#position-property")} <%helpers:single_keyword_computed name="float" @@ -240,7 +240,7 @@ ${helpers.single_keyword("position", "static absolute relative fixed sticky", gecko_inexhaustive="True" gecko_ffi_name="mFloat" gecko_pref_ident="float_" - flags="APPLIES_TO_FIRST_LETTER" + flags="PropertyFlags::APPLIES_TO_FIRST_LETTER" spec="https://drafts.csswg.org/css-box/#propdef-float"> impl ToComputedValue for SpecifiedValue { type ComputedValue = computed_value::T; @@ -362,7 +362,8 @@ ${helpers.predefined_type( "VerticalAlign", "computed::VerticalAlign::baseline()", animation_value_type="ComputedValue", - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""", spec="https://www.w3.org/TR/CSS2/visudet.html#propdef-vertical-align", )} @@ -375,7 +376,7 @@ ${helpers.single_keyword("-servo-overflow-clip-box", "padding-box content-box", ${helpers.single_keyword("overflow-clip-box", "padding-box content-box", products="gecko", animation_value_type="discrete", internal=True, - flags="APPLIES_TO_PLACEHOLDER", + flags="PropertyFlags::APPLIES_TO_PLACEHOLDER", spec="Internal, not web-exposed, \ may be standardized in the future (https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-clip-box)")} @@ -389,12 +390,12 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", extra_gecko_values="-moz-hidden-unscrollable", custom_consts=overflow_custom_consts, gecko_constant_prefix="NS_STYLE_OVERFLOW", - flags="APPLIES_TO_PLACEHOLDER", + flags="PropertyFlags::APPLIES_TO_PLACEHOLDER", spec="https://drafts.csswg.org/css-overflow/#propdef-overflow-x")} // FIXME(pcwalton, #2742): Implement scrolling for `scroll` and `auto`. <%helpers:longhand name="overflow-y" animation_value_type="discrete" - flags="APPLIES_TO_PLACEHOLDER", + flags="PropertyFlags::APPLIES_TO_PLACEHOLDER", spec="https://drafts.csswg.org/css-overflow/#propdef-overflow-y"> pub use super::overflow_x::{SpecifiedValue, parse, get_initial_value, computed_value}; </%helpers:longhand> @@ -668,7 +669,7 @@ ${helpers.predefined_type( <%helpers:longhand name="transform" extra_prefixes="webkit" animation_value_type="ComputedValue" - flags="CREATES_STACKING_CONTEXT FIXPOS_CB" + flags="PropertyFlags::CREATES_STACKING_CONTEXT PropertyFlags::FIXPOS_CB" spec="https://drafts.csswg.org/css-transforms/#propdef-transform"> use values::computed::{LengthOrPercentageOrNumber as ComputedLoPoNumber, LengthOrNumber as ComputedLoN}; use values::computed::{LengthOrPercentage as ComputedLoP, Length as ComputedLength}; @@ -1571,7 +1572,7 @@ ${helpers.single_keyword("isolation", "auto isolate", products="gecko", spec="https://drafts.fxtf.org/compositing/#isolation", - flags="CREATES_STACKING_CONTEXT", + flags="PropertyFlags::CREATES_STACKING_CONTEXT", animation_value_type="discrete")} // TODO add support for logical values recto and verso @@ -1604,7 +1605,7 @@ ${helpers.single_keyword("resize", "none both horizontal vertical", products="gecko", spec="https://drafts.csswg.org/css-ui/#propdef-resize", - flags="APPLIES_TO_PLACEHOLDER", + flags="PropertyFlags::APPLIES_TO_PLACEHOLDER", animation_value_type="discrete")} @@ -1615,7 +1616,7 @@ ${helpers.predefined_type("perspective", gecko_ffi_name="mChildPerspective", spec="https://drafts.csswg.org/css-transforms/#perspective", extra_prefixes="moz webkit", - flags="CREATES_STACKING_CONTEXT FIXPOS_CB", + flags="PropertyFlags::CREATES_STACKING_CONTEXT PropertyFlags::FIXPOS_CB", animation_value_type="ComputedValue")} ${helpers.predefined_type("perspective-origin", @@ -1646,7 +1647,7 @@ ${helpers.single_keyword("transform-style", "flat preserve-3d", spec="https://drafts.csswg.org/css-transforms/#transform-style-property", extra_prefixes="moz webkit", - flags="CREATES_STACKING_CONTEXT FIXPOS_CB", + flags="PropertyFlags::CREATES_STACKING_CONTEXT PropertyFlags::FIXPOS_CB", animation_value_type="discrete")} ${helpers.predefined_type("transform-origin", @@ -1661,7 +1662,7 @@ ${helpers.predefined_type("transform-origin", // like `content`(layout style paint) in gecko. We should implement `size` and `content`, // also update the glue once they are implemented in gecko. <%helpers:longhand name="contain" animation_value_type="discrete" products="gecko" - flags="FIXPOS_CB" + flags="PropertyFlags::FIXPOS_CB" spec="https://drafts.csswg.org/css-contain/#contain-property"> use std::fmt; use style_traits::ToCss; @@ -1672,12 +1673,12 @@ ${helpers.predefined_type("transform-origin", bitflags! { #[derive(MallocSizeOf, ToComputedValue)] - pub flags SpecifiedValue: u8 { - const LAYOUT = 0x01, - const STYLE = 0x02, - const PAINT = 0x04, - const STRICT = 0x8, - const STRICT_BITS = LAYOUT.bits | STYLE.bits | PAINT.bits, + pub struct SpecifiedValue: u8 { + const LAYOUT = 0x01; + const STYLE = 0x02; + const PAINT = 0x04; + const STRICT = 0x8; + const STRICT_BITS = SpecifiedValue::LAYOUT.bits | SpecifiedValue::STYLE.bits | SpecifiedValue::PAINT.bits; } } @@ -1686,13 +1687,13 @@ ${helpers.predefined_type("transform-origin", if self.is_empty() { return dest.write_str("none") } - if self.contains(STRICT) { + if self.contains(SpecifiedValue::STRICT) { return dest.write_str("strict") } let mut has_any = false; macro_rules! maybe_write_value { - ($ident:ident => $str:expr) => { + ($ident:path => $str:expr) => { if self.contains($ident) { if has_any { dest.write_str(" ")?; @@ -1702,9 +1703,9 @@ ${helpers.predefined_type("transform-origin", } } } - maybe_write_value!(LAYOUT => "layout"); - maybe_write_value!(STYLE => "style"); - maybe_write_value!(PAINT => "paint"); + maybe_write_value!(SpecifiedValue::LAYOUT => "layout"); + maybe_write_value!(SpecifiedValue::STYLE => "style"); + maybe_write_value!(SpecifiedValue::PAINT => "paint"); debug_assert!(has_any); Ok(()) @@ -1725,15 +1726,15 @@ ${helpers.predefined_type("transform-origin", return Ok(result) } if input.try(|input| input.expect_ident_matching("strict")).is_ok() { - result.insert(STRICT | STRICT_BITS); + result.insert(SpecifiedValue::STRICT | SpecifiedValue::STRICT_BITS); return Ok(result) } while let Ok(name) = input.try(|i| i.expect_ident_cloned()) { let flag = match_ignore_ascii_case! { &name, - "layout" => Some(LAYOUT), - "style" => Some(STYLE), - "paint" => Some(PAINT), + "layout" => Some(SpecifiedValue::LAYOUT), + "style" => Some(SpecifiedValue::STYLE), + "paint" => Some(SpecifiedValue::PAINT), _ => None }; let flag = match flag { @@ -1864,7 +1865,7 @@ ${helpers.predefined_type( products="gecko", boxed=True, animation_value_type="ComputedValue", - flags="APPLIES_TO_FIRST_LETTER", + flags="PropertyFlags::APPLIES_TO_FIRST_LETTER", spec="https://drafts.csswg.org/css-shapes/#shape-outside-property", )} @@ -1884,28 +1885,28 @@ ${helpers.predefined_type( /// These constants match Gecko's `NS_STYLE_TOUCH_ACTION_*` constants. #[cfg_attr(feature = "gecko", derive(MallocSizeOf))] #[derive(ToComputedValue)] - pub flags SpecifiedValue: u8 { - const TOUCH_ACTION_NONE = structs::NS_STYLE_TOUCH_ACTION_NONE as u8, - const TOUCH_ACTION_AUTO = structs::NS_STYLE_TOUCH_ACTION_AUTO as u8, - const TOUCH_ACTION_PAN_X = structs::NS_STYLE_TOUCH_ACTION_PAN_X as u8, - const TOUCH_ACTION_PAN_Y = structs::NS_STYLE_TOUCH_ACTION_PAN_Y as u8, - const TOUCH_ACTION_MANIPULATION = structs::NS_STYLE_TOUCH_ACTION_MANIPULATION as u8, + pub struct SpecifiedValue: u8 { + const TOUCH_ACTION_NONE = structs::NS_STYLE_TOUCH_ACTION_NONE as u8; + const TOUCH_ACTION_AUTO = structs::NS_STYLE_TOUCH_ACTION_AUTO as u8; + const TOUCH_ACTION_PAN_X = structs::NS_STYLE_TOUCH_ACTION_PAN_X as u8; + const TOUCH_ACTION_PAN_Y = structs::NS_STYLE_TOUCH_ACTION_PAN_Y as u8; + const TOUCH_ACTION_MANIPULATION = structs::NS_STYLE_TOUCH_ACTION_MANIPULATION as u8; } } impl ToCss for SpecifiedValue { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { - TOUCH_ACTION_NONE => dest.write_str("none"), - TOUCH_ACTION_AUTO => dest.write_str("auto"), - TOUCH_ACTION_MANIPULATION => dest.write_str("manipulation"), - _ if self.contains(TOUCH_ACTION_PAN_X | TOUCH_ACTION_PAN_Y) => { + SpecifiedValue::TOUCH_ACTION_NONE => dest.write_str("none"), + SpecifiedValue::TOUCH_ACTION_AUTO => dest.write_str("auto"), + SpecifiedValue::TOUCH_ACTION_MANIPULATION => dest.write_str("manipulation"), + _ if self.contains(SpecifiedValue::TOUCH_ACTION_PAN_X | SpecifiedValue::TOUCH_ACTION_PAN_Y) => { dest.write_str("pan-x pan-y") }, - _ if self.contains(TOUCH_ACTION_PAN_X) => { + _ if self.contains(SpecifiedValue::TOUCH_ACTION_PAN_X) => { dest.write_str("pan-x") }, - _ if self.contains(TOUCH_ACTION_PAN_Y) => { + _ if self.contains(SpecifiedValue::TOUCH_ACTION_PAN_Y) => { dest.write_str("pan-y") }, _ => panic!("invalid touch-action value"), @@ -1915,28 +1916,28 @@ ${helpers.predefined_type( #[inline] pub fn get_initial_value() -> computed_value::T { - TOUCH_ACTION_AUTO + SpecifiedValue::TOUCH_ACTION_AUTO } pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<SpecifiedValue, ParseError<'i>> { // FIXME: remove clone() when lifetimes are non-lexical try_match_ident_ignore_ascii_case! { input, - "auto" => Ok(TOUCH_ACTION_AUTO), - "none" => Ok(TOUCH_ACTION_NONE), - "manipulation" => Ok(TOUCH_ACTION_MANIPULATION), + "auto" => Ok(SpecifiedValue::TOUCH_ACTION_AUTO), + "none" => Ok(SpecifiedValue::TOUCH_ACTION_NONE), + "manipulation" => Ok(SpecifiedValue::TOUCH_ACTION_MANIPULATION), "pan-x" => { if input.try(|i| i.expect_ident_matching("pan-y")).is_ok() { - Ok(TOUCH_ACTION_PAN_X | TOUCH_ACTION_PAN_Y) + Ok(SpecifiedValue::TOUCH_ACTION_PAN_X | SpecifiedValue::TOUCH_ACTION_PAN_Y) } else { - Ok(TOUCH_ACTION_PAN_X) + Ok(SpecifiedValue::TOUCH_ACTION_PAN_X) } }, "pan-y" => { if input.try(|i| i.expect_ident_matching("pan-x")).is_ok() { - Ok(TOUCH_ACTION_PAN_X | TOUCH_ACTION_PAN_Y) + Ok(SpecifiedValue::TOUCH_ACTION_PAN_X | SpecifiedValue::TOUCH_ACTION_PAN_Y) } else { - Ok(TOUCH_ACTION_PAN_Y) + Ok(SpecifiedValue::TOUCH_ACTION_PAN_Y) } }, } diff --git a/components/style/properties/longhand/color.mako.rs b/components/style/properties/longhand/color.mako.rs index bb39dbf27cd..f535cbf1ea1 100644 --- a/components/style/properties/longhand/color.mako.rs +++ b/components/style/properties/longhand/color.mako.rs @@ -13,7 +13,8 @@ ${helpers.predefined_type( "ColorPropertyValue", "::cssparser::RGBA::new(0, 0, 0, 255)", animation_value_type="AnimatedRGBA", - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""", ignored_when_colors_disabled="True", spec="https://drafts.csswg.org/css-color/#color" )} diff --git a/components/style/properties/longhand/effects.mako.rs b/components/style/properties/longhand/effects.mako.rs index bec6cae249b..e06f59771aa 100644 --- a/components/style/properties/longhand/effects.mako.rs +++ b/components/style/properties/longhand/effects.mako.rs @@ -11,7 +11,7 @@ ${helpers.predefined_type("opacity", "Opacity", "1.0", animation_value_type="ComputedValue", - flags="CREATES_STACKING_CONTEXT APPLIES_TO_PLACEHOLDER", + flags="PropertyFlags::CREATES_STACKING_CONTEXT PropertyFlags::APPLIES_TO_PLACEHOLDER", spec="https://drafts.csswg.org/css-color/#opacity")} ${helpers.predefined_type( @@ -22,7 +22,7 @@ ${helpers.predefined_type( animation_value_type="AnimatedBoxShadowList", extra_prefixes="webkit", ignored_when_colors_disabled=True, - flags="APPLIES_TO_FIRST_LETTER", + flags="PropertyFlags::APPLIES_TO_FIRST_LETTER", spec="https://drafts.csswg.org/css-backgrounds/#box-shadow", )} @@ -42,7 +42,7 @@ ${helpers.predefined_type( separator="Space", animation_value_type="AnimatedFilterList", extra_prefixes="webkit", - flags="CREATES_STACKING_CONTEXT FIXPOS_CB", + flags="PropertyFlags::CREATES_STACKING_CONTEXT PropertyFlags::FIXPOS_CB", spec="https://drafts.fxtf.org/filters/#propdef-filter", )} @@ -51,5 +51,5 @@ ${helpers.single_keyword("mix-blend-mode", color-burn hard-light soft-light difference exclusion hue saturation color luminosity""", gecko_constant_prefix="NS_STYLE_BLEND", animation_value_type="discrete", - flags="CREATES_STACKING_CONTEXT", + flags="PropertyFlags::CREATES_STACKING_CONTEXT", spec="https://drafts.fxtf.org/compositing/#propdef-mix-blend-mode")} diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs index 9cf3fd1b4fd..e71cebccb77 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -69,7 +69,8 @@ macro_rules! impl_gecko_keyword_conversions { </%def> <%helpers:longhand name="font-family" animation_value_type="discrete" - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER" + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""" spec="https://drafts.csswg.org/css-fonts/#propdef-font-family"> #[cfg(feature = "gecko")] use gecko_bindings::bindings; #[cfg(feature = "gecko")] use malloc_size_of::{MallocSizeOf, MallocSizeOfOps}; @@ -596,7 +597,8 @@ ${helpers.single_keyword_system("font-style", gecko_constant_prefix="NS_FONT_STYLE", gecko_ffi_name="mFont.style", spec="https://drafts.csswg.org/css-fonts/#propdef-font-style", - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""", animation_value_type="discrete")} @@ -613,11 +615,13 @@ ${helpers.single_keyword_system("font-variant-caps", gecko_ffi_name="mFont.variantCaps", spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-caps", custom_consts=font_variant_caps_custom_consts, - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""", animation_value_type="discrete")} <%helpers:longhand name="font-weight" animation_value_type="ComputedValue" - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER" + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""" spec="https://drafts.csswg.org/css-fonts/#propdef-font-weight"> use properties::longhands::system_font::SystemFont; @@ -782,7 +786,8 @@ ${helpers.single_keyword_system("font-variant-caps", </%helpers:longhand> <%helpers:longhand name="font-size" animation_value_type="NonNegativeLength" - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER" + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""" allow_quirks="True" spec="https://drafts.csswg.org/css-fonts/#propdef-font-size"> use app_units::Au; use values::specified::AllowQuirks; @@ -917,7 +922,8 @@ ${helpers.single_keyword_system("font-variant-caps", <%helpers:longhand products="gecko" name="font-size-adjust" animation_value_type="longhands::font_size_adjust::computed_value::T" - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER" + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""" spec="https://drafts.csswg.org/css-fonts/#propdef-font-size-adjust"> use properties::longhands::system_font::SystemFont; @@ -1034,7 +1040,8 @@ ${helpers.single_keyword_system("font-variant-caps", </%helpers:longhand> <%helpers:longhand products="gecko" name="font-synthesis" animation_value_type="discrete" - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER" + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""" spec="https://drafts.csswg.org/css-fonts/#propdef-font-synthesis"> use std::fmt; use style_traits::ToCss; @@ -1128,7 +1135,8 @@ ${helpers.single_keyword_system("font-stretch", gecko_constant_prefix="NS_FONT_STRETCH", cast_type='i16', spec="https://drafts.csswg.org/css-fonts/#propdef-font-stretch", - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""", animation_value_type="ComputedValue")} ${helpers.single_keyword_system("font-kerning", @@ -1137,11 +1145,13 @@ ${helpers.single_keyword_system("font-kerning", gecko_ffi_name="mFont.kerning", gecko_constant_prefix="NS_FONT_KERNING", spec="https://drafts.csswg.org/css-fonts/#propdef-font-kerning", - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""", animation_value_type="discrete")} <%helpers:longhand name="font-variant-alternates" products="gecko" animation_value_type="discrete" - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER" + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""", spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-alternates"> use properties::longhands::system_font::SystemFont; use std::fmt; @@ -1253,15 +1263,15 @@ ${helpers.single_keyword_system("font-kerning", bitflags! { #[cfg_attr(feature = "servo", derive(MallocSizeOf))] - pub flags ParsingFlags: u8 { - const NORMAL = 0, - const HISTORICAL_FORMS = 0x01, - const STYLISTIC = 0x02, - const STYLESET = 0x04, - const CHARACTER_VARIANT = 0x08, - const SWASH = 0x10, - const ORNAMENTS = 0x20, - const ANNOTATION = 0x40, + pub struct ParsingFlags: u8 { + const NORMAL = 0; + const HISTORICAL_FORMS = 0x01; + const STYLISTIC = 0x02; + const STYLESET = 0x04; + const CHARACTER_VARIANT = 0x08; + const SWASH = 0x10; + const ORNAMENTS = 0x20; + const ANNOTATION = 0x40; } } @@ -1282,7 +1292,7 @@ ${helpers.single_keyword_system("font-kerning", let mut parsed_alternates = ParsingFlags::empty(); macro_rules! check_if_parsed( - ($input:expr, $flag:ident) => ( + ($input:expr, $flag:path) => ( if parsed_alternates.contains($flag) { return Err($input.new_custom_error(StyleParseErrorKind::UnspecifiedError)) } @@ -1294,7 +1304,7 @@ ${helpers.single_keyword_system("font-kerning", match input.next()?.clone() { Token::Ident(ref ident) => { if *ident == "historical-forms" { - check_if_parsed!(input, HISTORICAL_FORMS); + check_if_parsed!(input, ParsingFlags::HISTORICAL_FORMS); alternates.push(VariantAlternates::HistoricalForms); Ok(()) } else { @@ -1306,7 +1316,7 @@ ${helpers.single_keyword_system("font-kerning", match_ignore_ascii_case! { &name, % for value in "swash stylistic ornaments annotation".split(): "${value}" => { - check_if_parsed!(i, ${value.upper()}); + check_if_parsed!(i, ParsingFlags::${value.upper()}); let location = i.current_source_location(); let ident = CustomIdent::from_ident(location, i.expect_ident()?, &[])?; alternates.push(VariantAlternates::${to_camel_case(value)}(ident)); @@ -1315,7 +1325,7 @@ ${helpers.single_keyword_system("font-kerning", % endfor % for value in "styleset character-variant".split(): "${value}" => { - check_if_parsed!(i, ${to_rust_ident(value).upper()}); + check_if_parsed!(i, ParsingFlags:: ${to_rust_ident(value).upper()}); let idents = i.parse_comma_separated(|i| { let location = i.current_source_location(); CustomIdent::from_ident(location, i.expect_ident()?, &[]) @@ -1341,7 +1351,7 @@ ${helpers.single_keyword_system("font-kerning", #[cfg(feature = "gecko")] macro_rules! exclusive_value { - (($value:ident, $set:expr) => $ident:ident) => { + (($value:ident, $set:expr) => $ident:path) => { if $value.intersects($set) { return Err(()) } else { @@ -1351,7 +1361,8 @@ macro_rules! exclusive_value { } <%helpers:longhand name="font-variant-east-asian" products="gecko" animation_value_type="discrete" - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER" + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""" spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-east-asian"> use properties::longhands::system_font::SystemFont; use std::fmt; @@ -1360,17 +1371,17 @@ macro_rules! exclusive_value { bitflags! { #[derive(MallocSizeOf)] - pub flags VariantEastAsian: u16 { - const NORMAL = 0, - const JIS78 = 0x01, - const JIS83 = 0x02, - const JIS90 = 0x04, - const JIS04 = 0x08, - const SIMPLIFIED = 0x10, - const TRADITIONAL = 0x20, - const FULL_WIDTH = 0x40, - const PROPORTIONAL_WIDTH = 0x80, - const RUBY = 0x100, + pub struct VariantEastAsian: u16 { + const NORMAL = 0; + const JIS78 = 0x01; + const JIS83 = 0x02; + const JIS90 = 0x04; + const JIS04 = 0x08; + const SIMPLIFIED = 0x10; + const TRADITIONAL = 0x20; + const FULL_WIDTH = 0x40; + const PROPORTIONAL_WIDTH = 0x80; + const RUBY = 0x100; } } @@ -1384,15 +1395,15 @@ macro_rules! exclusive_value { <%self:simple_system_boilerplate name="font_variant_east_asian"></%self:simple_system_boilerplate> // servo_bit: gecko_bit - <% font_variant_east_asian_map = { "JIS78": "JIS78", - "JIS83": "JIS83", - "JIS90": "JIS90", - "JIS04": "JIS04", - "SIMPLIFIED": "SIMPLIFIED", - "TRADITIONAL": "TRADITIONAL", - "FULL_WIDTH": "FULL_WIDTH", - "PROPORTIONAL_WIDTH": "PROP_WIDTH", - "RUBY": "RUBY" } %> + <% font_variant_east_asian_map = { "VariantEastAsian::JIS78": "JIS78", + "VariantEastAsian::JIS83": "JIS83", + "VariantEastAsian::JIS90": "JIS90", + "VariantEastAsian::JIS04": "JIS04", + "VariantEastAsian::SIMPLIFIED": "SIMPLIFIED", + "VariantEastAsian::TRADITIONAL": "TRADITIONAL", + "VariantEastAsian::FULL_WIDTH": "FULL_WIDTH", + "VariantEastAsian::PROPORTIONAL_WIDTH": "PROP_WIDTH", + "VariantEastAsian::RUBY": "RUBY" } %> ${helpers.gecko_bitflags_conversion(font_variant_east_asian_map, 'NS_FONT_VARIANT_EAST_ASIAN_', 'VariantEastAsian', kw_type='u16')} @@ -1407,7 +1418,7 @@ macro_rules! exclusive_value { let mut has_any = false; macro_rules! write_value { - ($ident:ident => $str:expr) => { + ($ident:path => $str:expr) => { if self.intersects($ident) { if has_any { dest.write_str(" ")?; @@ -1418,15 +1429,15 @@ macro_rules! exclusive_value { } } - write_value!(JIS78 => "jis78"); - write_value!(JIS83 => "jis83"); - write_value!(JIS90 => "jis90"); - write_value!(JIS04 => "jis04"); - write_value!(SIMPLIFIED => "simplified"); - write_value!(TRADITIONAL => "traditional"); - write_value!(FULL_WIDTH => "full-width"); - write_value!(PROPORTIONAL_WIDTH => "proportional-width"); - write_value!(RUBY => "ruby"); + write_value!(VariantEastAsian::JIS78 => "jis78"); + write_value!(VariantEastAsian::JIS83 => "jis83"); + write_value!(VariantEastAsian::JIS90 => "jis90"); + write_value!(VariantEastAsian::JIS04 => "jis04"); + write_value!(VariantEastAsian::SIMPLIFIED => "simplified"); + write_value!(VariantEastAsian::TRADITIONAL => "traditional"); + write_value!(VariantEastAsian::FULL_WIDTH => "full-width"); + write_value!(VariantEastAsian::PROPORTIONAL_WIDTH => "proportional-width"); + write_value!(VariantEastAsian::RUBY => "ruby"); debug_assert!(has_any); Ok(()) @@ -1448,8 +1459,10 @@ macro_rules! exclusive_value { /// normal | [ <east-asian-variant-values> || <east-asian-width-values> || ruby ] /// <east-asian-variant-values> = [ jis78 | jis83 | jis90 | jis04 | simplified | traditional ] /// <east-asian-width-values> = [ full-width | proportional-width ] - <% east_asian_variant_values = "JIS78 | JIS83 | JIS90 | JIS04 | SIMPLIFIED | TRADITIONAL" %> - <% east_asian_width_values = "FULL_WIDTH | PROPORTIONAL_WIDTH" %> + <% east_asian_variant_values = """VariantEastAsian::JIS78 | VariantEastAsian::JIS83 | + VariantEastAsian::JIS90 | VariantEastAsian::JIS04 | + VariantEastAsian::SIMPLIFIED | VariantEastAsian::TRADITIONAL""" %> + <% east_asian_width_values = "VariantEastAsian::FULL_WIDTH | VariantEastAsian::PROPORTIONAL_WIDTH" %> pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<SpecifiedValue, ParseError<'i>> { let mut result = VariantEastAsian::empty(); @@ -1461,23 +1474,23 @@ macro_rules! exclusive_value { while let Ok(flag) = input.try(|input| { Ok(match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?, "jis78" => - exclusive_value!((result, ${east_asian_variant_values}) => JIS78), + exclusive_value!((result, ${east_asian_variant_values}) => VariantEastAsian::JIS78), "jis83" => - exclusive_value!((result, ${east_asian_variant_values}) => JIS83), + exclusive_value!((result, ${east_asian_variant_values}) => VariantEastAsian::JIS83), "jis90" => - exclusive_value!((result, ${east_asian_variant_values}) => JIS90), + exclusive_value!((result, ${east_asian_variant_values}) => VariantEastAsian::JIS90), "jis04" => - exclusive_value!((result, ${east_asian_variant_values}) => JIS04), + exclusive_value!((result, ${east_asian_variant_values}) => VariantEastAsian::JIS04), "simplified" => - exclusive_value!((result, ${east_asian_variant_values}) => SIMPLIFIED), + exclusive_value!((result, ${east_asian_variant_values}) => VariantEastAsian::SIMPLIFIED), "traditional" => - exclusive_value!((result, ${east_asian_variant_values}) => TRADITIONAL), + exclusive_value!((result, ${east_asian_variant_values}) => VariantEastAsian::TRADITIONAL), "full-width" => - exclusive_value!((result, ${east_asian_width_values}) => FULL_WIDTH), + exclusive_value!((result, ${east_asian_width_values}) => VariantEastAsian::FULL_WIDTH), "proportional-width" => - exclusive_value!((result, ${east_asian_width_values}) => PROPORTIONAL_WIDTH), + exclusive_value!((result, ${east_asian_width_values}) => VariantEastAsian::PROPORTIONAL_WIDTH), "ruby" => - exclusive_value!((result, RUBY) => RUBY), + exclusive_value!((result, VariantEastAsian::RUBY) => VariantEastAsian::RUBY), _ => return Err(()), }) }) { @@ -1496,7 +1509,8 @@ macro_rules! exclusive_value { </%helpers:longhand> <%helpers:longhand name="font-variant-ligatures" products="gecko" animation_value_type="discrete" - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER" + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""" spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-ligatures"> use properties::longhands::system_font::SystemFont; use std::fmt; @@ -1504,18 +1518,18 @@ macro_rules! exclusive_value { bitflags! { - #[derive(MallocSizeOf)] - pub flags VariantLigatures: u16 { - const NORMAL = 0, - const NONE = 0x01, - const COMMON_LIGATURES = 0x02, - const NO_COMMON_LIGATURES = 0x04, - const DISCRETIONARY_LIGATURES = 0x08, - const NO_DISCRETIONARY_LIGATURES = 0x10, - const HISTORICAL_LIGATURES = 0x20, - const NO_HISTORICAL_LIGATURES = 0x40, - const CONTEXTUAL = 0x80, - const NO_CONTEXTUAL = 0x100, + #[derive(MallocSizeOf)] + pub struct VariantLigatures: u16 { + const NORMAL = 0; + const NONE = 0x01; + const COMMON_LIGATURES = 0x02; + const NO_COMMON_LIGATURES = 0x04; + const DISCRETIONARY_LIGATURES = 0x08; + const NO_DISCRETIONARY_LIGATURES = 0x10; + const HISTORICAL_LIGATURES = 0x20; + const NO_HISTORICAL_LIGATURES = 0x40; + const CONTEXTUAL = 0x80; + const NO_CONTEXTUAL = 0x100; } } @@ -1529,15 +1543,15 @@ macro_rules! exclusive_value { <%self:simple_system_boilerplate name="font_variant_ligatures"></%self:simple_system_boilerplate> // servo_bit: gecko_bit - <% font_variant_ligatures_map = { "NONE": "NONE", - "COMMON_LIGATURES": "COMMON", - "NO_COMMON_LIGATURES": "NO_COMMON", - "DISCRETIONARY_LIGATURES": "DISCRETIONARY", - "NO_DISCRETIONARY_LIGATURES": "NO_DISCRETIONARY", - "HISTORICAL_LIGATURES": "HISTORICAL", - "NO_HISTORICAL_LIGATURES": "NO_HISTORICAL", - "CONTEXTUAL": "CONTEXTUAL", - "NO_CONTEXTUAL": "NO_CONTEXTUAL" } %> + <% font_variant_ligatures_map = { "VariantLigatures::NONE": "NONE", + "VariantLigatures::COMMON_LIGATURES": "COMMON", + "VariantLigatures::NO_COMMON_LIGATURES": "NO_COMMON", + "VariantLigatures::DISCRETIONARY_LIGATURES": "DISCRETIONARY", + "VariantLigatures::NO_DISCRETIONARY_LIGATURES": "NO_DISCRETIONARY", + "VariantLigatures::HISTORICAL_LIGATURES": "HISTORICAL", + "VariantLigatures::NO_HISTORICAL_LIGATURES": "NO_HISTORICAL", + "VariantLigatures::CONTEXTUAL": "CONTEXTUAL", + "VariantLigatures::NO_CONTEXTUAL": "NO_CONTEXTUAL" } %> ${helpers.gecko_bitflags_conversion(font_variant_ligatures_map, 'NS_FONT_VARIANT_LIGATURES_', 'VariantLigatures', kw_type='u16')} @@ -1547,14 +1561,14 @@ macro_rules! exclusive_value { if self.is_empty() { return dest.write_str("normal") } - if self.contains(NONE) { + if self.contains(VariantLigatures::NONE) { return dest.write_str("none") } let mut has_any = false; macro_rules! write_value { - ($ident:ident => $str:expr) => { + ($ident:path => $str:expr) => { if self.intersects($ident) { if has_any { dest.write_str(" ")?; @@ -1565,14 +1579,14 @@ macro_rules! exclusive_value { } } - write_value!(COMMON_LIGATURES => "common-ligatures"); - write_value!(NO_COMMON_LIGATURES => "no-common-ligatures"); - write_value!(DISCRETIONARY_LIGATURES => "discretionary-ligatures"); - write_value!(NO_DISCRETIONARY_LIGATURES => "no-discretionary-ligatures"); - write_value!(HISTORICAL_LIGATURES => "historical-ligatures"); - write_value!(NO_HISTORICAL_LIGATURES => "no-historical-ligatures"); - write_value!(CONTEXTUAL => "contextual"); - write_value!(NO_CONTEXTUAL => "no-contextual"); + write_value!(VariantLigatures::COMMON_LIGATURES => "common-ligatures"); + write_value!(VariantLigatures::NO_COMMON_LIGATURES => "no-common-ligatures"); + write_value!(VariantLigatures::DISCRETIONARY_LIGATURES => "discretionary-ligatures"); + write_value!(VariantLigatures::NO_DISCRETIONARY_LIGATURES => "no-discretionary-ligatures"); + write_value!(VariantLigatures::HISTORICAL_LIGATURES => "historical-ligatures"); + write_value!(VariantLigatures::NO_HISTORICAL_LIGATURES => "no-historical-ligatures"); + write_value!(VariantLigatures::CONTEXTUAL => "contextual"); + write_value!(VariantLigatures::NO_CONTEXTUAL => "no-contextual"); debug_assert!(has_any); Ok(()) @@ -1592,7 +1606,7 @@ macro_rules! exclusive_value { } #[inline] pub fn get_none_specified_value() -> SpecifiedValue { - SpecifiedValue::Value(NONE) + SpecifiedValue::Value(VariantLigatures::NONE) } /// normal | none | @@ -1604,10 +1618,11 @@ macro_rules! exclusive_value { /// <discretionary-lig-values> = [ discretionary-ligatures | no-discretionary-ligatures ] /// <historical-lig-values> = [ historical-ligatures | no-historical-ligatures ] /// <contextual-alt-values> = [ contextual | no-contextual ] - <% common_lig_values = "COMMON_LIGATURES | NO_COMMON_LIGATURES" %> - <% discretionary_lig_values = "DISCRETIONARY_LIGATURES | NO_DISCRETIONARY_LIGATURES" %> - <% historical_lig_values = "HISTORICAL_LIGATURES | NO_HISTORICAL_LIGATURES" %> - <% contextual_alt_values = "CONTEXTUAL | NO_CONTEXTUAL" %> + <% common_lig_values = "VariantLigatures::COMMON_LIGATURES | VariantLigatures::NO_COMMON_LIGATURES" %> + <% discretionary_lig_values = """VariantLigatures::DISCRETIONARY_LIGATURES | + VariantLigatures::NO_DISCRETIONARY_LIGATURES""" %> + <% historical_lig_values = "VariantLigatures::HISTORICAL_LIGATURES | VariantLigatures::NO_HISTORICAL_LIGATURES" %> + <% contextual_alt_values = "VariantLigatures::CONTEXTUAL | VariantLigatures::NO_CONTEXTUAL" %> pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<SpecifiedValue, ParseError<'i>> { let mut result = VariantLigatures::empty(); @@ -1616,27 +1631,29 @@ macro_rules! exclusive_value { return Ok(SpecifiedValue::Value(result)) } if input.try(|input| input.expect_ident_matching("none")).is_ok() { - return Ok(SpecifiedValue::Value(NONE)) + return Ok(SpecifiedValue::Value(VariantLigatures::NONE)) } while let Ok(flag) = input.try(|input| { Ok(match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?, "common-ligatures" => - exclusive_value!((result, ${common_lig_values}) => COMMON_LIGATURES), + exclusive_value!((result, ${common_lig_values}) => VariantLigatures::COMMON_LIGATURES), "no-common-ligatures" => - exclusive_value!((result, ${common_lig_values}) => NO_COMMON_LIGATURES), + exclusive_value!((result, ${common_lig_values}) => VariantLigatures::NO_COMMON_LIGATURES), "discretionary-ligatures" => - exclusive_value!((result, ${discretionary_lig_values}) => DISCRETIONARY_LIGATURES), + exclusive_value!((result, ${discretionary_lig_values}) => + VariantLigatures::DISCRETIONARY_LIGATURES), "no-discretionary-ligatures" => - exclusive_value!((result, ${discretionary_lig_values}) => NO_DISCRETIONARY_LIGATURES), + exclusive_value!((result, ${discretionary_lig_values}) => + VariantLigatures::NO_DISCRETIONARY_LIGATURES), "historical-ligatures" => - exclusive_value!((result, ${historical_lig_values}) => HISTORICAL_LIGATURES), + exclusive_value!((result, ${historical_lig_values}) => VariantLigatures::HISTORICAL_LIGATURES), "no-historical-ligatures" => - exclusive_value!((result, ${historical_lig_values}) => NO_HISTORICAL_LIGATURES), + exclusive_value!((result, ${historical_lig_values}) => VariantLigatures::NO_HISTORICAL_LIGATURES), "contextual" => - exclusive_value!((result, ${contextual_alt_values}) => CONTEXTUAL), + exclusive_value!((result, ${contextual_alt_values}) => VariantLigatures::CONTEXTUAL), "no-contextual" => - exclusive_value!((result, ${contextual_alt_values}) => NO_CONTEXTUAL), + exclusive_value!((result, ${contextual_alt_values}) => VariantLigatures::NO_CONTEXTUAL), _ => return Err(()), }) }) { @@ -1655,7 +1672,8 @@ macro_rules! exclusive_value { </%helpers:longhand> <%helpers:longhand name="font-variant-numeric" products="gecko" animation_value_type="discrete" - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER" + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""" spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-numeric"> use properties::longhands::system_font::SystemFont; use std::fmt; @@ -1664,16 +1682,16 @@ macro_rules! exclusive_value { bitflags! { #[derive(MallocSizeOf)] - pub flags VariantNumeric: u8 { - const NORMAL = 0, - const LINING_NUMS = 0x01, - const OLDSTYLE_NUMS = 0x02, - const PROPORTIONAL_NUMS = 0x04, - const TABULAR_NUMS = 0x08, - const DIAGONAL_FRACTIONS = 0x10, - const STACKED_FRACTIONS = 0x20, - const SLASHED_ZERO = 0x40, - const ORDINAL = 0x80, + pub struct VariantNumeric: u8 { + const NORMAL = 0; + const LINING_NUMS = 0x01; + const OLDSTYLE_NUMS = 0x02; + const PROPORTIONAL_NUMS = 0x04; + const TABULAR_NUMS = 0x08; + const DIAGONAL_FRACTIONS = 0x10; + const STACKED_FRACTIONS = 0x20; + const SLASHED_ZERO = 0x40; + const ORDINAL = 0x80; } } @@ -1688,14 +1706,14 @@ macro_rules! exclusive_value { // servo_bit: gecko_bit - <% font_variant_numeric_map = { "LINING_NUMS": "LINING", - "OLDSTYLE_NUMS": "OLDSTYLE", - "PROPORTIONAL_NUMS": "PROPORTIONAL", - "TABULAR_NUMS": "TABULAR", - "DIAGONAL_FRACTIONS": "DIAGONAL_FRACTIONS", - "STACKED_FRACTIONS": "STACKED_FRACTIONS", - "SLASHED_ZERO": "SLASHZERO", - "ORDINAL": "ORDINAL" } %> + <% font_variant_numeric_map = { "VariantNumeric::LINING_NUMS": "LINING", + "VariantNumeric::OLDSTYLE_NUMS": "OLDSTYLE", + "VariantNumeric::PROPORTIONAL_NUMS": "PROPORTIONAL", + "VariantNumeric::TABULAR_NUMS": "TABULAR", + "VariantNumeric::DIAGONAL_FRACTIONS": "DIAGONAL_FRACTIONS", + "VariantNumeric::STACKED_FRACTIONS": "STACKED_FRACTIONS", + "VariantNumeric::SLASHED_ZERO": "SLASHZERO", + "VariantNumeric::ORDINAL": "ORDINAL" } %> ${helpers.gecko_bitflags_conversion(font_variant_numeric_map, 'NS_FONT_VARIANT_NUMERIC_', 'VariantNumeric')} @@ -1709,7 +1727,7 @@ macro_rules! exclusive_value { let mut has_any = false; macro_rules! write_value { - ($ident:ident => $str:expr) => { + ($ident:path => $str:expr) => { if self.intersects($ident) { if has_any { dest.write_str(" ")?; @@ -1720,14 +1738,14 @@ macro_rules! exclusive_value { } } - write_value!(LINING_NUMS => "lining-nums"); - write_value!(OLDSTYLE_NUMS => "oldstyle-nums"); - write_value!(PROPORTIONAL_NUMS => "proportional-nums"); - write_value!(TABULAR_NUMS => "tabular-nums"); - write_value!(DIAGONAL_FRACTIONS => "diagonal-fractions"); - write_value!(STACKED_FRACTIONS => "stacked-fractions"); - write_value!(SLASHED_ZERO => "slashed-zero"); - write_value!(ORDINAL => "ordinal"); + write_value!(VariantNumeric::LINING_NUMS => "lining-nums"); + write_value!(VariantNumeric::OLDSTYLE_NUMS => "oldstyle-nums"); + write_value!(VariantNumeric::PROPORTIONAL_NUMS => "proportional-nums"); + write_value!(VariantNumeric::TABULAR_NUMS => "tabular-nums"); + write_value!(VariantNumeric::DIAGONAL_FRACTIONS => "diagonal-fractions"); + write_value!(VariantNumeric::STACKED_FRACTIONS => "stacked-fractions"); + write_value!(VariantNumeric::SLASHED_ZERO => "slashed-zero"); + write_value!(VariantNumeric::ORDINAL => "ordinal"); debug_assert!(has_any); Ok(()) @@ -1755,9 +1773,9 @@ macro_rules! exclusive_value { /// <numeric-figure-values> = [ lining-nums | oldstyle-nums ] /// <numeric-spacing-values> = [ proportional-nums | tabular-nums ] /// <numeric-fraction-values> = [ diagonal-fractions | stacked-fractions ] - <% numeric_figure_values = "LINING_NUMS | OLDSTYLE_NUMS" %> - <% numeric_spacing_values = "PROPORTIONAL_NUMS | TABULAR_NUMS" %> - <% numeric_fraction_values = "DIAGONAL_FRACTIONS | STACKED_FRACTIONS" %> + <% numeric_figure_values = "VariantNumeric::LINING_NUMS | VariantNumeric::OLDSTYLE_NUMS" %> + <% numeric_spacing_values = "VariantNumeric::PROPORTIONAL_NUMS | VariantNumeric::TABULAR_NUMS" %> + <% numeric_fraction_values = "VariantNumeric::DIAGONAL_FRACTIONS | VariantNumeric::STACKED_FRACTIONS" %> pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<SpecifiedValue, ParseError<'i>> { let mut result = VariantNumeric::empty(); @@ -1769,21 +1787,21 @@ macro_rules! exclusive_value { while let Ok(flag) = input.try(|input| { Ok(match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?, "ordinal" => - exclusive_value!((result, ORDINAL) => ORDINAL), + exclusive_value!((result, VariantNumeric::ORDINAL) => VariantNumeric::ORDINAL), "slashed-zero" => - exclusive_value!((result, SLASHED_ZERO) => SLASHED_ZERO), + exclusive_value!((result, VariantNumeric::SLASHED_ZERO) => VariantNumeric::SLASHED_ZERO), "lining-nums" => - exclusive_value!((result, ${numeric_figure_values}) => LINING_NUMS), + exclusive_value!((result, ${numeric_figure_values}) => VariantNumeric::LINING_NUMS), "oldstyle-nums" => - exclusive_value!((result, ${numeric_figure_values}) => OLDSTYLE_NUMS), + exclusive_value!((result, ${numeric_figure_values}) => VariantNumeric::OLDSTYLE_NUMS), "proportional-nums" => - exclusive_value!((result, ${numeric_spacing_values}) => PROPORTIONAL_NUMS), + exclusive_value!((result, ${numeric_spacing_values}) => VariantNumeric::PROPORTIONAL_NUMS), "tabular-nums" => - exclusive_value!((result, ${numeric_spacing_values}) => TABULAR_NUMS), + exclusive_value!((result, ${numeric_spacing_values}) => VariantNumeric::TABULAR_NUMS), "diagonal-fractions" => - exclusive_value!((result, ${numeric_fraction_values}) => DIAGONAL_FRACTIONS), + exclusive_value!((result, ${numeric_fraction_values}) => VariantNumeric::DIAGONAL_FRACTIONS), "stacked-fractions" => - exclusive_value!((result, ${numeric_fraction_values}) => STACKED_FRACTIONS), + exclusive_value!((result, ${numeric_fraction_values}) => VariantNumeric::STACKED_FRACTIONS), _ => return Err(()), }) }) { @@ -1807,12 +1825,14 @@ ${helpers.single_keyword_system("font-variant-position", gecko_ffi_name="mFont.variantPosition", gecko_constant_prefix="NS_FONT_VARIANT_POSITION", spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-position", - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""", animation_value_type="discrete")} <%helpers:longhand name="font-feature-settings" products="gecko" animation_value_type="discrete" extra_prefixes="moz" boxed="True" - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER" + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""" spec="https://drafts.csswg.org/css-fonts/#propdef-font-feature-settings"> use properties::longhands::system_font::SystemFont; use values::generics::FontSettings; @@ -1856,7 +1876,8 @@ https://drafts.csswg.org/css-fonts-4/#low-level-font-variation-settings-control- %> <%helpers:longhand name="font-variation-settings" products="gecko" animation_value_type="ComputedValue" - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER" + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""" spec="${variation_spec}"> use values::generics::FontSettings; @@ -1881,7 +1902,8 @@ https://drafts.csswg.org/css-fonts-4/#low-level-font-variation-settings-control- <%helpers:longhand name="font-language-override" products="gecko" animation_value_type="discrete" extra_prefixes="moz" boxed="True" - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER" + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""" spec="https://drafts.csswg.org/css-fonts-3/#propdef-font-language-override"> use properties::longhands::system_font::SystemFont; use std::fmt; @@ -2463,7 +2485,8 @@ ${helpers.single_keyword("-moz-osx-font-smoothing", gecko_ffi_name="mFont.smoothing", products="gecko", spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/font-smooth)", - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""", animation_value_type="discrete")} ${helpers.predefined_type("-moz-min-font-size-ratio", diff --git a/components/style/properties/longhand/inherited_text.mako.rs b/components/style/properties/longhand/inherited_text.mako.rs index 5416433bedd..55ebf8d496c 100644 --- a/components/style/properties/longhand/inherited_text.mako.rs +++ b/components/style/properties/longhand/inherited_text.mako.rs @@ -10,7 +10,8 @@ ${helpers.predefined_type("line-height", "LineHeight", "computed::LineHeight::normal()", animation_value_type="LineHeight", - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""", spec="https://drafts.csswg.org/css2/visudet.html#propdef-line-height")} // CSS Text Module Level 3 @@ -20,7 +21,8 @@ ${helpers.single_keyword("text-transform", "none capitalize uppercase lowercase", extra_gecko_values="full-width", animation_value_type="discrete", - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""", spec="https://drafts.csswg.org/css-text/#propdef-text-transform")} ${helpers.single_keyword("hyphens", "manual none auto", @@ -66,7 +68,7 @@ ${helpers.single_keyword("word-break", extra_specified="${'distribute' if product == 'gecko' else ''}" gecko_enum_prefix="StyleTextJustify" animation_value_type="discrete" - flags="APPLIES_TO_PLACEHOLDER", + flags="PropertyFlags::APPLIES_TO_PLACEHOLDER", spec="https://drafts.csswg.org/css-text/#propdef-text-justify"> impl ToComputedValue for SpecifiedValue { @@ -109,7 +111,7 @@ ${helpers.single_keyword("text-align-last", // TODO make this a shorthand and implement text-align-last/text-align-all <%helpers:longhand name="text-align" animation_value_type="discrete" - flags="APPLIES_TO_PLACEHOLDER" + flags="PropertyFlags::APPLIES_TO_PLACEHOLDER" spec="https://drafts.csswg.org/css-text/#propdef-text-align"> pub mod computed_value { use style_traits::ToCss; @@ -267,14 +269,16 @@ ${helpers.predefined_type("letter-spacing", "LetterSpacing", "computed::LetterSpacing::normal()", animation_value_type="ComputedValue", - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""", spec="https://drafts.csswg.org/css-text/#propdef-letter-spacing")} ${helpers.predefined_type("word-spacing", "WordSpacing", "computed::WordSpacing::normal()", animation_value_type="ComputedValue", - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""", spec="https://drafts.csswg.org/css-text/#propdef-word-spacing")} <%helpers:longhand name="-servo-text-decorations-in-effect" @@ -347,7 +351,7 @@ ${helpers.predefined_type("word-spacing", animation_value_type="discrete" // Only allowed for UA sheets, which set it // !important. - flags="APPLIES_TO_PLACEHOLDER" + flags="PropertyFlags::APPLIES_TO_PLACEHOLDER" spec="https://drafts.csswg.org/css-text/#propdef-white-space"> trivial_to_computed_value!(SpecifiedValue); % if product != "gecko": @@ -392,7 +396,8 @@ ${helpers.predefined_type( vector=True, animation_value_type="AnimatedTextShadowList", ignored_when_colors_disabled=True, - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""", spec="https://drafts.csswg.org/css-text-decor-3/#text-shadow-property", )} @@ -694,7 +699,8 @@ ${helpers.predefined_type( products="gecko", animation_value_type="AnimatedColor", ignored_when_colors_disabled=True, - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""", spec="https://compat.spec.whatwg.org/#the-webkit-text-fill-color", )} @@ -706,7 +712,8 @@ ${helpers.predefined_type( products="gecko", animation_value_type="AnimatedColor", ignored_when_colors_disabled=True, - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""", spec="https://compat.spec.whatwg.org/#the-webkit-text-stroke-color", )} @@ -716,7 +723,8 @@ ${helpers.predefined_type("-webkit-text-stroke-width", initial_specified_value="specified::BorderSideWidth::Length(specified::Length::zero())", computed_type="::values::computed::NonNegativeLength", products="gecko", - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""", spec="https://compat.spec.whatwg.org/#the-webkit-text-stroke-width", animation_value_type="discrete")} diff --git a/components/style/properties/longhand/margin.mako.rs b/components/style/properties/longhand/margin.mako.rs index 948faeed06f..ab86fde54e8 100644 --- a/components/style/properties/longhand/margin.mako.rs +++ b/components/style/properties/longhand/margin.mako.rs @@ -17,6 +17,6 @@ alias=maybe_moz_logical_alias(product, side, "-moz-margin-%s"), allow_quirks=not side[1], animation_value_type="ComputedValue", logical = side[1], spec = spec, - flags="APPLIES_TO_FIRST_LETTER", + flags="PropertyFlags::APPLIES_TO_FIRST_LETTER", allowed_in_page_rule=True)} % endfor diff --git a/components/style/properties/longhand/padding.mako.rs b/components/style/properties/longhand/padding.mako.rs index 49d9b1bd722..a0c797b0a6b 100644 --- a/components/style/properties/longhand/padding.mako.rs +++ b/components/style/properties/longhand/padding.mako.rs @@ -20,6 +20,6 @@ animation_value_type="NonNegativeLengthOrPercentage", logical = side[1], spec = spec, - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_PLACEHOLDER", + flags="PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_PLACEHOLDER", allow_quirks=not side[1])} % endfor diff --git a/components/style/properties/longhand/pointing.mako.rs b/components/style/properties/longhand/pointing.mako.rs index 3c7d693f302..e8daff9b1f3 100644 --- a/components/style/properties/longhand/pointing.mako.rs +++ b/components/style/properties/longhand/pointing.mako.rs @@ -148,7 +148,7 @@ // TODO(pcwalton): SVG-only values. ${helpers.single_keyword("pointer-events", "auto none", animation_value_type="discrete", extra_gecko_values="visiblepainted visiblefill visiblestroke visible painted fill stroke all", - flags="APPLIES_TO_PLACEHOLDER", + flags="PropertyFlags::APPLIES_TO_PLACEHOLDER", spec="https://www.w3.org/TR/SVG11/interact.html#PointerEventsProperty")} ${helpers.single_keyword("-moz-user-input", "auto none enabled disabled", diff --git a/components/style/properties/longhand/position.mako.rs b/components/style/properties/longhand/position.mako.rs index 9a4ec5c4b3f..2a2997153e1 100644 --- a/components/style/properties/longhand/position.mako.rs +++ b/components/style/properties/longhand/position.mako.rs @@ -45,7 +45,7 @@ macro_rules! impl_align_conversions { ${helpers.predefined_type("z-index", "IntegerOrAuto", "Either::Second(Auto)", spec="https://www.w3.org/TR/CSS2/visuren.html#z-index", - flags="CREATES_STACKING_CONTEXT", + flags="PropertyFlags::CREATES_STACKING_CONTEXT", animation_value_type="ComputedValue")} diff --git a/components/style/properties/longhand/svg.mako.rs b/components/style/properties/longhand/svg.mako.rs index 5fe3f1f96a0..a456790119e 100644 --- a/components/style/properties/longhand/svg.mako.rs +++ b/components/style/properties/longhand/svg.mako.rs @@ -70,7 +70,7 @@ ${helpers.predefined_type( products="gecko", boxed=True, animation_value_type="ComputedValue", - flags="CREATES_STACKING_CONTEXT", + flags="PropertyFlags::CREATES_STACKING_CONTEXT", spec="https://drafts.fxtf.org/css-masking/#propdef-clip-path", )} @@ -167,4 +167,4 @@ ${helpers.predefined_type("mask-image", "ImageLayer", products="gecko", extra_prefixes="webkit", animation_value_type="discrete", - flags="CREATES_STACKING_CONTEXT")} + flags="PropertyFlags::CREATES_STACKING_CONTEXT")} diff --git a/components/style/properties/longhand/text.mako.rs b/components/style/properties/longhand/text.mako.rs index a88d5199797..8c0a0deceb6 100644 --- a/components/style/properties/longhand/text.mako.rs +++ b/components/style/properties/longhand/text.mako.rs @@ -13,7 +13,7 @@ Method("has_line_through", "bool")]) %> <%helpers:longhand name="text-overflow" animation_value_type="discrete" boxed="True" - flags="APPLIES_TO_PLACEHOLDER" + flags="PropertyFlags::APPLIES_TO_PLACEHOLDER" spec="https://drafts.csswg.org/css-ui/#propdef-text-overflow"> use std::fmt; use style_traits::ToCss; @@ -141,19 +141,20 @@ ${helpers.single_keyword("unicode-bidi", <%helpers:longhand name="text-decoration-line" custom_cascade="${product == 'servo'}" animation_value_type="discrete" - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""", spec="https://drafts.csswg.org/css-text-decor/#propdef-text-decoration-line"> use std::fmt; use style_traits::ToCss; bitflags! { #[derive(MallocSizeOf, ToComputedValue)] - pub flags SpecifiedValue: u8 { - const NONE = 0, - const UNDERLINE = 0x01, - const OVERLINE = 0x02, - const LINE_THROUGH = 0x04, - const BLINK = 0x08, + pub struct SpecifiedValue: u8 { + const NONE = 0; + const UNDERLINE = 0x01; + const OVERLINE = 0x02; + const LINE_THROUGH = 0x04; + const BLINK = 0x08; % if product == "gecko": /// Only set by presentation attributes /// @@ -162,7 +163,7 @@ ${helpers.single_keyword("unicode-bidi", /// /// For example, this gives <a href=foo><font color="red">text</font></a> /// a red text decoration - const COLOR_OVERRIDE = 0x10, + const COLOR_OVERRIDE = 0x10; % endif } } @@ -172,7 +173,7 @@ ${helpers.single_keyword("unicode-bidi", let mut has_any = false; macro_rules! write_value { - ($line:ident => $css:expr) => { + ($line:path => $css:expr) => { if self.contains($line) { if has_any { dest.write_str(" ")?; @@ -182,10 +183,10 @@ ${helpers.single_keyword("unicode-bidi", } } } - write_value!(UNDERLINE => "underline"); - write_value!(OVERLINE => "overline"); - write_value!(LINE_THROUGH => "line-through"); - write_value!(BLINK => "blink"); + write_value!(SpecifiedValue::UNDERLINE => "underline"); + write_value!(SpecifiedValue::OVERLINE => "overline"); + write_value!(SpecifiedValue::LINE_THROUGH => "line-through"); + write_value!(SpecifiedValue::BLINK => "blink"); if !has_any { dest.write_str("none")?; } @@ -222,14 +223,17 @@ ${helpers.single_keyword("unicode-bidi", match input.expect_ident() { Ok(ident) => { (match_ignore_ascii_case! { &ident, - "underline" => if result.contains(UNDERLINE) { Err(()) } - else { empty = false; result.insert(UNDERLINE); Ok(()) }, - "overline" => if result.contains(OVERLINE) { Err(()) } - else { empty = false; result.insert(OVERLINE); Ok(()) }, - "line-through" => if result.contains(LINE_THROUGH) { Err(()) } - else { empty = false; result.insert(LINE_THROUGH); Ok(()) }, - "blink" => if result.contains(BLINK) { Err(()) } - else { empty = false; result.insert(BLINK); Ok(()) }, + "underline" => if result.contains(SpecifiedValue::UNDERLINE) { Err(()) } + else { empty = false; result.insert(SpecifiedValue::UNDERLINE); Ok(()) }, + "overline" => if result.contains(SpecifiedValue::OVERLINE) { Err(()) } + else { empty = false; result.insert(SpecifiedValue::OVERLINE); Ok(()) }, + "line-through" => if result.contains(SpecifiedValue::LINE_THROUGH) { Err(()) } + else { + empty = false; + result.insert(SpecifiedValue::LINE_THROUGH); Ok(()) + }, + "blink" => if result.contains(SpecifiedValue::BLINK) { Err(()) } + else { empty = false; result.insert(SpecifiedValue::BLINK); Ok(()) }, _ => Err(()) }).map_err(|()| { location.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone())) @@ -261,7 +265,8 @@ ${helpers.single_keyword("text-decoration-style", "solid double dotted dashed wavy -moz-none", products="gecko", animation_value_type="discrete", - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""", spec="https://drafts.csswg.org/css-text-decor/#propdef-text-decoration-style")} ${helpers.predefined_type( @@ -272,7 +277,8 @@ ${helpers.predefined_type( products="gecko", animation_value_type="AnimatedColor", ignored_when_colors_disabled=True, - flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER", + flags="""PropertyFlags::APPLIES_TO_FIRST_LETTER PropertyFlags::APPLIES_TO_FIRST_LINE + PropertyFlags::APPLIES_TO_PLACEHOLDER""", spec="https://drafts.csswg.org/css-text-decor/#propdef-text-decoration-color", )} @@ -283,5 +289,5 @@ ${helpers.predefined_type( initial_specified_value="specified::InitialLetter::normal()", animation_value_type="discrete", products="gecko", - flags="APPLIES_TO_FIRST_LETTER", + flags="PropertyFlags::APPLIES_TO_FIRST_LETTER", spec="https://drafts.csswg.org/css-inline/#sizing-drop-initials")} diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 517b0a4e9ab..c8083129016 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -38,7 +38,7 @@ use selector_parser::PseudoElement; use selectors::parser::SelectorParseErrorKind; #[cfg(feature = "servo")] use servo_config::prefs::PREFS; use shared_lock::StylesheetGuards; -use style_traits::{PARSING_MODE_DEFAULT, ToCss, ParseError, StyleParseErrorKind}; +use style_traits::{ParsingMode, ToCss, ParseError, StyleParseErrorKind}; use stylesheets::{CssRuleType, Origin, UrlExtraData}; #[cfg(feature = "servo")] use values::Either; use values::generics::text::LineHeight; @@ -440,23 +440,23 @@ impl CSSWideKeyword { bitflags! { /// A set of flags for properties. - pub flags PropertyFlags: u8 { + pub struct PropertyFlags: u8 { /// This property requires a stacking context. - const CREATES_STACKING_CONTEXT = 1 << 0, + const CREATES_STACKING_CONTEXT = 1 << 0; /// This property has values that can establish a containing block for /// fixed positioned and absolutely positioned elements. - const FIXPOS_CB = 1 << 1, + const FIXPOS_CB = 1 << 1; /// This property has values that can establish a containing block for /// absolutely positioned elements. - const ABSPOS_CB = 1 << 2, + const ABSPOS_CB = 1 << 2; /// This shorthand property is an alias of another property. - const SHORTHAND_ALIAS_PROPERTY = 1 << 3, + const SHORTHAND_ALIAS_PROPERTY = 1 << 3; /// This longhand property applies to ::first-letter. - const APPLIES_TO_FIRST_LETTER = 1 << 4, + const APPLIES_TO_FIRST_LETTER = 1 << 4; /// This longhand property applies to ::first-line. - const APPLIES_TO_FIRST_LINE = 1 << 5, + const APPLIES_TO_FIRST_LINE = 1 << 5; /// This longhand property applies to ::placeholder. - const APPLIES_TO_PLACEHOLDER = 1 << 6, + const APPLIES_TO_PLACEHOLDER = 1 << 6; } } @@ -948,7 +948,7 @@ impl UnparsedValue { Origin::Author, &self.url_data, None, - PARSING_MODE_DEFAULT, + ParsingMode::DEFAULT, quirks_mode, ); let mut input = ParserInput::new(&css); @@ -1428,7 +1428,7 @@ impl ToCss for PropertyDeclaration { // Normally, we shouldn't be printing variables here if they came from // shorthands. But we should allow properties that came from shorthand // aliases. That also matches with the Gecko behavior. - Some(shorthand) if shorthand.flags().contains(SHORTHAND_ALIAS_PROPERTY) => + Some(shorthand) if shorthand.flags().contains(PropertyFlags::SHORTHAND_ALIAS_PROPERTY) => dest.write_str(&*with_variables.css)?, None => dest.write_str(&*with_variables.css)?, _ => {}, @@ -1487,7 +1487,7 @@ impl PropertyDeclaration { // should return None here. But we return Some to longhands if they // came from a shorthand alias. Because for example, we should be able to // get -moz-transform's value from transform. - if shorthand.flags().contains(SHORTHAND_ALIAS_PROPERTY) { + if shorthand.flags().contains(PropertyFlags::SHORTHAND_ALIAS_PROPERTY) { return Some(&*with_variables.css); } None @@ -1940,19 +1940,19 @@ pub mod style_structs { /// Whether the text decoration has an underline. #[inline] pub fn has_underline(&self) -> bool { - self.text_decoration_line.contains(longhands::text_decoration_line::UNDERLINE) + self.text_decoration_line.contains(longhands::text_decoration_line::SpecifiedValue::UNDERLINE) } /// Whether the text decoration has an overline. #[inline] pub fn has_overline(&self) -> bool { - self.text_decoration_line.contains(longhands::text_decoration_line::OVERLINE) + self.text_decoration_line.contains(longhands::text_decoration_line::SpecifiedValue::OVERLINE) } /// Whether the text decoration has a line through. #[inline] pub fn has_line_through(&self) -> bool { - self.text_decoration_line.contains(longhands::text_decoration_line::LINE_THROUGH) + self.text_decoration_line.contains(longhands::text_decoration_line::SpecifiedValue::LINE_THROUGH) } % elif style_struct.name == "Box": /// Sets the display property, but without touching @@ -2089,7 +2089,7 @@ pub struct ComputedValues { impl ComputedValues { /// Whether we're a visited style. pub fn is_style_if_visited(&self) -> bool { - self.flags.contains(IS_STYLE_IF_VISITED) + self.flags.contains(ComputedValueFlags::IS_STYLE_IF_VISITED) } /// Gets a reference to the rule node. Panic if no rule node exists. @@ -2109,9 +2109,9 @@ impl ComputedValues { /// Returns whether we're in a display: none subtree. pub fn is_in_display_none_subtree(&self) -> bool { - use properties::computed_value_flags::IS_IN_DISPLAY_NONE_SUBTREE; + use properties::computed_value_flags::ComputedValueFlags; - self.flags.contains(IS_IN_DISPLAY_NONE_SUBTREE) + self.flags.contains(ComputedValueFlags::IS_IN_DISPLAY_NONE_SUBTREE) } /// Gets a reference to the custom properties map (if one exists). @@ -2443,28 +2443,28 @@ pub fn get_writing_mode(inheritedbox_style: &style_structs::InheritedBox) -> Wri match inheritedbox_style.clone_direction() { computed_values::direction::T::ltr => {}, computed_values::direction::T::rtl => { - flags.insert(logical_geometry::FLAG_RTL); + flags.insert(logical_geometry::WritingMode::RTL); }, } match inheritedbox_style.clone_writing_mode() { computed_values::writing_mode::T::horizontal_tb => {}, computed_values::writing_mode::T::vertical_rl => { - flags.insert(logical_geometry::FLAG_VERTICAL); + flags.insert(logical_geometry::WritingMode::VERTICAL); }, computed_values::writing_mode::T::vertical_lr => { - flags.insert(logical_geometry::FLAG_VERTICAL); - flags.insert(logical_geometry::FLAG_VERTICAL_LR); + flags.insert(logical_geometry::WritingMode::VERTICAL); + flags.insert(logical_geometry::WritingMode::VERTICAL_LR); }, % if product == "gecko": computed_values::writing_mode::T::sideways_rl => { - flags.insert(logical_geometry::FLAG_VERTICAL); - flags.insert(logical_geometry::FLAG_SIDEWAYS); + flags.insert(logical_geometry::WritingMode::VERTICAL); + flags.insert(logical_geometry::WritingMode::SIDEWAYS); }, computed_values::writing_mode::T::sideways_lr => { - flags.insert(logical_geometry::FLAG_VERTICAL); - flags.insert(logical_geometry::FLAG_VERTICAL_LR); - flags.insert(logical_geometry::FLAG_LINE_INVERTED); - flags.insert(logical_geometry::FLAG_SIDEWAYS); + flags.insert(logical_geometry::WritingMode::VERTICAL); + flags.insert(logical_geometry::WritingMode::VERTICAL_LR); + flags.insert(logical_geometry::WritingMode::LINE_INVERTED); + flags.insert(logical_geometry::WritingMode::SIDEWAYS); }, % endif } @@ -2472,14 +2472,14 @@ pub fn get_writing_mode(inheritedbox_style: &style_structs::InheritedBox) -> Wri // If FLAG_SIDEWAYS is already set, this means writing-mode is either // sideways-rl or sideways-lr, and for both of these values, // text-orientation has no effect. - if !flags.intersects(logical_geometry::FLAG_SIDEWAYS) { + if !flags.intersects(logical_geometry::WritingMode::SIDEWAYS) { match inheritedbox_style.clone_text_orientation() { computed_values::text_orientation::T::mixed => {}, computed_values::text_orientation::T::upright => { - flags.insert(logical_geometry::FLAG_UPRIGHT); + flags.insert(logical_geometry::WritingMode::UPRIGHT); }, computed_values::text_orientation::T::sideways => { - flags.insert(logical_geometry::FLAG_SIDEWAYS); + flags.insert(logical_geometry::WritingMode::SIDEWAYS); }, } } @@ -2668,14 +2668,14 @@ impl<'a> StyleBuilder<'a> { // 99% sure it should give incorrect behavior for table anonymous box // backgrounds, for example. This code doesn't attempt to make it play // nice with inherited_style_ignoring_first_line. - let reset_style = if cascade_flags.contains(INHERIT_ALL) { + let reset_style = if cascade_flags.contains(CascadeFlags::INHERIT_ALL) { inherited_style } else { reset_style }; - if cascade_flags.contains(VISITED_DEPENDENT_ONLY) { - flags.insert(IS_STYLE_IF_VISITED); + if cascade_flags.contains(CascadeFlags::VISITED_DEPENDENT_ONLY) { + flags.insert(ComputedValueFlags::IS_STYLE_IF_VISITED); } StyleBuilder { @@ -2703,7 +2703,7 @@ impl<'a> StyleBuilder<'a> { /// Whether we're a visited style. pub fn is_style_if_visited(&self) -> bool { - self.flags.contains(IS_STYLE_IF_VISITED) + self.flags.contains(ComputedValueFlags::IS_STYLE_IF_VISITED) } /// Creates a StyleBuilder holding only references to the structs of `s`, in @@ -2765,16 +2765,16 @@ impl<'a> StyleBuilder<'a> { % endif % if not property.style_struct.inherited: - self.flags.insert(::properties::computed_value_flags::INHERITS_RESET_STYLE); + self.flags.insert(::properties::computed_value_flags::ComputedValueFlags::INHERITS_RESET_STYLE); self.modified_reset = true; % endif % if property.ident == "content": - self.flags.insert(::properties::computed_value_flags::INHERITS_CONTENT); + self.flags.insert(::properties::computed_value_flags::ComputedValueFlags::INHERITS_CONTENT); % endif % if property.ident == "display": - self.flags.insert(::properties::computed_value_flags::INHERITS_DISPLAY); + self.flags.insert(::properties::computed_value_flags::ComputedValueFlags::INHERITS_DISPLAY); % endif self.${property.style_struct.ident}.mutate() @@ -3070,17 +3070,17 @@ static CASCADE_PROPERTY: [CascadePropertyFn; ${len(data.longhands)}] = [ bitflags! { /// A set of flags to tweak the behavior of the `cascade` function. - pub flags CascadeFlags: u8 { + pub struct CascadeFlags: u8 { /// Whether to inherit all styles from the parent. If this flag is not /// present, non-inherited styles are reset to their initial values. - const INHERIT_ALL = 1, + const INHERIT_ALL = 1; /// Whether to skip any display style fixup for root element, flex/grid /// item, and ruby descendants. - const SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP = 1 << 1, + const SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP = 1 << 1; /// Whether to only cascade properties that are visited dependent. - const VISITED_DEPENDENT_ONLY = 1 << 2, + const VISITED_DEPENDENT_ONLY = 1 << 2; /// Whether the given element we're styling is the document element, /// that is, matches :root. @@ -3090,23 +3090,23 @@ bitflags! { /// /// This affects some style adjustments, like blockification, and means /// that it may affect global state, like the Device's root font-size. - const IS_ROOT_ELEMENT = 1 << 3, + const IS_ROOT_ELEMENT = 1 << 3; /// Whether to convert display:contents into display:inline. This /// is used by Gecko to prevent display:contents on generated /// content. - const PROHIBIT_DISPLAY_CONTENTS = 1 << 4, + const PROHIBIT_DISPLAY_CONTENTS = 1 << 4; /// Whether we're styling the ::-moz-fieldset-content anonymous box. - const IS_FIELDSET_CONTENT = 1 << 5, + const IS_FIELDSET_CONTENT = 1 << 5; /// Whether we're computing the style of a link, either visited or /// unvisited. - const IS_LINK = 1 << 6, + const IS_LINK = 1 << 6; /// Whether we're computing the style of a link element that happens to /// be visited. - const IS_VISITED_LINK = 1 << 7, + const IS_VISITED_LINK = 1 << 7; } } @@ -3251,7 +3251,7 @@ where }; let mut context = computed::Context { - is_root_element: flags.contains(IS_ROOT_ELEMENT), + is_root_element: flags.contains(CascadeFlags::IS_ROOT_ELEMENT), // We'd really like to own the rules here to avoid refcount traffic, but // animation's usage of `apply_declarations` make this tricky. See bug // 1375525. @@ -3328,7 +3328,7 @@ where // Only a few properties are allowed to depend on the visited state // of links. When cascading visited styles, we can save time by // only processing these properties. - if flags.contains(VISITED_DEPENDENT_ONLY) && + if flags.contains(CascadeFlags::VISITED_DEPENDENT_ONLY) && !longhand_id.is_visited_dependent() { continue } diff --git a/components/style/properties/shorthand/box.mako.rs b/components/style/properties/shorthand/box.mako.rs index 94510e12c1f..6990f2cccbc 100644 --- a/components/style/properties/shorthand/box.mako.rs +++ b/components/style/properties/shorthand/box.mako.rs @@ -360,7 +360,7 @@ macro_rules! try_parse_one { <%helpers:shorthand name="-moz-transform" products="gecko" sub_properties="transform" - flags="SHORTHAND_ALIAS_PROPERTY" + flags="PropertyFlags::SHORTHAND_ALIAS_PROPERTY" derive_serialize="True" spec="Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/transform"> use properties::longhands::transform; diff --git a/components/style/servo/restyle_damage.rs b/components/style/servo/restyle_damage.rs index cec14dfb31f..def2a331cc7 100644 --- a/components/style/servo/restyle_damage.rs +++ b/components/style/servo/restyle_damage.rs @@ -14,41 +14,41 @@ use std::fmt; bitflags! { #[doc = "Individual layout actions that may be necessary after restyling."] - pub flags ServoRestyleDamage: u8 { + pub struct ServoRestyleDamage: u8 { #[doc = "Repaint the node itself."] #[doc = "Currently unused; need to decide how this propagates."] - const REPAINT = 0x01, + const REPAINT = 0x01; #[doc = "The stacking-context-relative position of this node or its descendants has \ changed."] #[doc = "Propagates both up and down the flow tree."] - const REPOSITION = 0x02, + const REPOSITION = 0x02; #[doc = "Recompute the overflow regions (bounding box of object and all descendants)."] #[doc = "Propagates down the flow tree because the computation is bottom-up."] - const STORE_OVERFLOW = 0x04, + const STORE_OVERFLOW = 0x04; #[doc = "Recompute intrinsic inline_sizes (minimum and preferred)."] #[doc = "Propagates down the flow tree because the computation is"] #[doc = "bottom-up."] - const BUBBLE_ISIZES = 0x08, + const BUBBLE_ISIZES = 0x08; #[doc = "Recompute actual inline-sizes and block-sizes, only taking out-of-flow children \ into account. \ Propagates up the flow tree because the computation is top-down."] - const REFLOW_OUT_OF_FLOW = 0x10, + const REFLOW_OUT_OF_FLOW = 0x10; #[doc = "Recompute actual inline_sizes and block_sizes."] #[doc = "Propagates up the flow tree because the computation is"] #[doc = "top-down."] - const REFLOW = 0x20, + const REFLOW = 0x20; #[doc = "Re-resolve generated content. \ Propagates up the flow tree because the computation is inorder."] - const RESOLVE_GENERATED_CONTENT = 0x40, + const RESOLVE_GENERATED_CONTENT = 0x40; #[doc = "The entire flow needs to be reconstructed."] - const RECONSTRUCT_FLOW = 0x80 + const RECONSTRUCT_FLOW = 0x80; } } @@ -79,24 +79,28 @@ impl ServoRestyleDamage { /// FIXME(bholley): Do we ever actually need this? Shouldn't /// RECONSTRUCT_FLOW imply everything else? pub fn rebuild_and_reflow() -> ServoRestyleDamage { - REPAINT | REPOSITION | STORE_OVERFLOW | BUBBLE_ISIZES | REFLOW_OUT_OF_FLOW | REFLOW | - RECONSTRUCT_FLOW + ServoRestyleDamage::REPAINT | ServoRestyleDamage::REPOSITION | + ServoRestyleDamage::STORE_OVERFLOW | ServoRestyleDamage::BUBBLE_ISIZES | + ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::REFLOW | + ServoRestyleDamage::RECONSTRUCT_FLOW } /// Returns a bitmask indicating that the frame needs to be reconstructed. pub fn reconstruct() -> ServoRestyleDamage { - RECONSTRUCT_FLOW + ServoRestyleDamage::RECONSTRUCT_FLOW } /// Supposing a flow has the given `position` property and this damage, /// returns the damage that we should add to the *parent* of this flow. pub fn damage_for_parent(self, child_is_absolutely_positioned: bool) -> ServoRestyleDamage { if child_is_absolutely_positioned { - self & (REPAINT | REPOSITION | STORE_OVERFLOW | REFLOW_OUT_OF_FLOW | - RESOLVE_GENERATED_CONTENT) + self & (ServoRestyleDamage::REPAINT | ServoRestyleDamage::REPOSITION | + ServoRestyleDamage::STORE_OVERFLOW | ServoRestyleDamage::REFLOW_OUT_OF_FLOW | + ServoRestyleDamage::RESOLVE_GENERATED_CONTENT) } else { - self & (REPAINT | REPOSITION | STORE_OVERFLOW | REFLOW | REFLOW_OUT_OF_FLOW | - RESOLVE_GENERATED_CONTENT) + self & (ServoRestyleDamage::REPAINT | ServoRestyleDamage::REPOSITION | + ServoRestyleDamage::STORE_OVERFLOW | ServoRestyleDamage::REFLOW | + ServoRestyleDamage::REFLOW_OUT_OF_FLOW | ServoRestyleDamage::RESOLVE_GENERATED_CONTENT) } } @@ -111,20 +115,20 @@ impl ServoRestyleDamage { // Absolute children are out-of-flow and therefore insulated from changes. // // FIXME(pcwalton): Au contraire, if the containing block dimensions change! - self & (REPAINT | REPOSITION) + self & (ServoRestyleDamage::REPAINT | ServoRestyleDamage::REPOSITION) } (true, false) => { // Changing the position of an absolutely-positioned block requires us to reflow // its kids. - if self.contains(REFLOW_OUT_OF_FLOW) { - self | REFLOW + if self.contains(ServoRestyleDamage::REFLOW_OUT_OF_FLOW) { + self | ServoRestyleDamage::REFLOW } else { self } } _ => { // TODO(pcwalton): Take floatedness into account. - self & (REPAINT | REPOSITION | REFLOW) + self & (ServoRestyleDamage::REPAINT | ServoRestyleDamage::REPOSITION | ServoRestyleDamage::REFLOW) } } } @@ -141,14 +145,14 @@ impl fmt::Display for ServoRestyleDamage { let mut first_elem = true; let to_iter = - [ (REPAINT, "Repaint") - , (REPOSITION, "Reposition") - , (STORE_OVERFLOW, "StoreOverflow") - , (BUBBLE_ISIZES, "BubbleISizes") - , (REFLOW_OUT_OF_FLOW, "ReflowOutOfFlow") - , (REFLOW, "Reflow") - , (RESOLVE_GENERATED_CONTENT, "ResolveGeneratedContent") - , (RECONSTRUCT_FLOW, "ReconstructFlow") + [ (ServoRestyleDamage::REPAINT, "Repaint") + , (ServoRestyleDamage::REPOSITION, "Reposition") + , (ServoRestyleDamage::STORE_OVERFLOW, "StoreOverflow") + , (ServoRestyleDamage::BUBBLE_ISIZES, "BubbleISizes") + , (ServoRestyleDamage::REFLOW_OUT_OF_FLOW, "ReflowOutOfFlow") + , (ServoRestyleDamage::REFLOW, "Reflow") + , (ServoRestyleDamage::RESOLVE_GENERATED_CONTENT, "ResolveGeneratedContent") + , (ServoRestyleDamage::RECONSTRUCT_FLOW, "ReconstructFlow") ]; for &(damage, damage_str) in &to_iter { @@ -172,7 +176,7 @@ impl fmt::Display for ServoRestyleDamage { // breakage on modifications. macro_rules! add_if_not_equal( ($old:ident, $new:ident, $damage:ident, - [ $($effect:ident),* ], [ $($style_struct_getter:ident.$name:ident),* ]) => ({ + [ $($effect:path),* ], [ $($style_struct_getter:ident.$name:ident),* ]) => ({ if $( ($old.$style_struct_getter().$name != $new.$style_struct_getter().$name) )||* { $damage.insert($($effect)|*); true @@ -191,8 +195,10 @@ fn compute_damage(old: &ComputedValues, new: &ComputedValues) -> ServoRestyleDam // FIXME: Test somehow that every property is included. add_if_not_equal!(old, new, damage, - [REPAINT, REPOSITION, STORE_OVERFLOW, BUBBLE_ISIZES, REFLOW_OUT_OF_FLOW, - REFLOW, RECONSTRUCT_FLOW], [ + [ServoRestyleDamage::REPAINT, ServoRestyleDamage::REPOSITION, + ServoRestyleDamage::STORE_OVERFLOW, ServoRestyleDamage::BUBBLE_ISIZES, + ServoRestyleDamage::REFLOW_OUT_OF_FLOW, ServoRestyleDamage::REFLOW, + ServoRestyleDamage::RECONSTRUCT_FLOW], [ get_box.clear, get_box.float, get_box.display, get_box.position, get_counters.content, get_counters.counter_reset, get_counters.counter_increment, get_list.quotes, get_list.list_style_type, @@ -211,8 +217,10 @@ fn compute_damage(old: &ComputedValues, new: &ComputedValues) -> ServoRestyleDam get_column.column_width, get_column.column_count ]) || (new.get_box().display == display::T::inline && add_if_not_equal!(old, new, damage, - [REPAINT, REPOSITION, STORE_OVERFLOW, BUBBLE_ISIZES, - REFLOW_OUT_OF_FLOW, REFLOW, RECONSTRUCT_FLOW], [ + [ServoRestyleDamage::REPAINT, ServoRestyleDamage::REPOSITION, + ServoRestyleDamage::STORE_OVERFLOW, ServoRestyleDamage::BUBBLE_ISIZES, + ServoRestyleDamage::REFLOW_OUT_OF_FLOW, ServoRestyleDamage::REFLOW, + ServoRestyleDamage::RECONSTRUCT_FLOW], [ // For inline boxes only, border/padding styles are used in flow construction (to decide // whether to create fragments for empty flows). get_border.border_top_width, get_border.border_right_width, @@ -220,8 +228,9 @@ fn compute_damage(old: &ComputedValues, new: &ComputedValues) -> ServoRestyleDam get_padding.padding_top, get_padding.padding_right, get_padding.padding_bottom, get_padding.padding_left ])) || add_if_not_equal!(old, new, damage, - [REPAINT, REPOSITION, STORE_OVERFLOW, BUBBLE_ISIZES, - REFLOW_OUT_OF_FLOW, REFLOW], + [ServoRestyleDamage::REPAINT, ServoRestyleDamage::REPOSITION, + ServoRestyleDamage::STORE_OVERFLOW, ServoRestyleDamage::BUBBLE_ISIZES, + ServoRestyleDamage::REFLOW_OUT_OF_FLOW, ServoRestyleDamage::REFLOW], [get_border.border_top_width, get_border.border_right_width, get_border.border_bottom_width, get_border.border_left_width, get_margin.margin_top, get_margin.margin_right, @@ -246,14 +255,15 @@ fn compute_damage(old: &ComputedValues, new: &ComputedValues) -> ServoRestyleDam get_position.flex_shrink, get_position.align_self ]) || add_if_not_equal!(old, new, damage, - [REPAINT, REPOSITION, STORE_OVERFLOW, REFLOW_OUT_OF_FLOW], [ - get_position.top, get_position.left, + [ServoRestyleDamage::REPAINT, ServoRestyleDamage::REPOSITION, + ServoRestyleDamage::STORE_OVERFLOW, ServoRestyleDamage::REFLOW_OUT_OF_FLOW], + [get_position.top, get_position.left, get_position.right, get_position.bottom, get_effects.opacity, get_box.transform, get_box.transform_style, get_box.transform_origin, get_box.perspective, get_box.perspective_origin ]) || add_if_not_equal!(old, new, damage, - [REPAINT], [ + [ServoRestyleDamage::REPAINT], [ get_color.color, get_background.background_color, get_background.background_image, get_background.background_position_x, get_background.background_position_y, get_background.background_repeat, @@ -279,7 +289,7 @@ fn compute_damage(old: &ComputedValues, new: &ComputedValues) -> ServoRestyleDam // Paint worklets may depend on custom properties, // so if they have changed we should repaint. if old.custom_properties() != new.custom_properties() { - damage.insert(REPAINT); + damage.insert(ServoRestyleDamage::REPAINT); } // If the layer requirements of this flow have changed due to the value diff --git a/components/style/servo/selector_parser.rs b/components/style/servo/selector_parser.rs index bffb436cf1c..931506b6cf3 100644 --- a/components/style/servo/selector_parser.rs +++ b/components/style/servo/selector_parser.rs @@ -329,20 +329,20 @@ impl NonTSPseudoClass { /// Gets a given state flag for this pseudo-class. This is used to do /// selector matching, and it's set from the DOM. pub fn state_flag(&self) -> ElementState { - use element_state::*; + use element_state::ElementState; use self::NonTSPseudoClass::*; match *self { - Active => IN_ACTIVE_STATE, - Focus => IN_FOCUS_STATE, - Fullscreen => IN_FULLSCREEN_STATE, - Hover => IN_HOVER_STATE, - Enabled => IN_ENABLED_STATE, - Disabled => IN_DISABLED_STATE, - Checked => IN_CHECKED_STATE, - Indeterminate => IN_INDETERMINATE_STATE, - ReadOnly | ReadWrite => IN_READ_WRITE_STATE, - PlaceholderShown => IN_PLACEHOLDER_SHOWN_STATE, - Target => IN_TARGET_STATE, + Active => ElementState::IN_ACTIVE_STATE, + Focus => ElementState::IN_FOCUS_STATE, + Fullscreen => ElementState::IN_FULLSCREEN_STATE, + Hover => ElementState::IN_HOVER_STATE, + Enabled => ElementState::IN_ENABLED_STATE, + Disabled => ElementState::IN_DISABLED_STATE, + Checked => ElementState::IN_CHECKED_STATE, + Indeterminate => ElementState::IN_INDETERMINATE_STATE, + ReadOnly | ReadWrite => ElementState::IN_READ_WRITE_STATE, + PlaceholderShown => ElementState::IN_PLACEHOLDER_SHOWN_STATE, + Target => ElementState::IN_TARGET_STATE, AnyLink | Lang(_) | diff --git a/components/style/style_adjuster.rs b/components/style/style_adjuster.rs index 4d41dd50559..884fa98acea 100644 --- a/components/style/style_adjuster.rs +++ b/components/style/style_adjuster.rs @@ -6,8 +6,7 @@ //! a computed style needs in order for it to adhere to the CSS spec. use app_units::Au; -use properties::{self, CascadeFlags, ComputedValues}; -use properties::{IS_ROOT_ELEMENT, SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP, StyleBuilder}; +use properties::{self, CascadeFlags, ComputedValues, StyleBuilder}; use properties::longhands::display::computed_value::T as display; use properties::longhands::float::computed_value::T as float; use properties::longhands::overflow_x::computed_value::T as overflow; @@ -68,8 +67,8 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { } } - if !flags.contains(SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP) { - blockify_if!(flags.contains(IS_ROOT_ELEMENT)); + if !flags.contains(CascadeFlags::SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP) { + blockify_if!(flags.contains(CascadeFlags::IS_ROOT_ELEMENT)); blockify_if!(layout_parent_style.get_box().clone_display().is_item_container()); } @@ -84,7 +83,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { let display = self.style.get_box().clone_display(); let blockified_display = - display.equivalent_block_display(flags.contains(IS_ROOT_ELEMENT)); + display.equivalent_block_display(flags.contains(CascadeFlags::IS_ROOT_ELEMENT)); if display != blockified_display { self.style.mutate_box().set_adjusted_display( blockified_display, @@ -95,17 +94,16 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { /// Compute a few common flags for both text and element's style. pub fn set_bits(&mut self) { - use properties::computed_value_flags::IS_IN_DISPLAY_NONE_SUBTREE; - use properties::computed_value_flags::IS_IN_PSEUDO_ELEMENT_SUBTREE; + use properties::computed_value_flags::ComputedValueFlags; - if self.style.inherited_flags().contains(IS_IN_DISPLAY_NONE_SUBTREE) || + if self.style.inherited_flags().contains(ComputedValueFlags::IS_IN_DISPLAY_NONE_SUBTREE) || self.style.get_box().clone_display() == display::none { - self.style.flags.insert(IS_IN_DISPLAY_NONE_SUBTREE); + self.style.flags.insert(ComputedValueFlags::IS_IN_DISPLAY_NONE_SUBTREE); } - if self.style.inherited_flags().contains(IS_IN_PSEUDO_ELEMENT_SUBTREE) || + if self.style.inherited_flags().contains(ComputedValueFlags::IS_IN_PSEUDO_ELEMENT_SUBTREE) || self.style.is_pseudo_element() { - self.style.flags.insert(IS_IN_PSEUDO_ELEMENT_SUBTREE); + self.style.flags.insert(ComputedValueFlags::IS_IN_PSEUDO_ELEMENT_SUBTREE); } } @@ -133,7 +131,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { fn adjust_for_text_combine_upright(&mut self) { use computed_values::text_combine_upright::T as text_combine_upright; use computed_values::writing_mode::T as writing_mode; - use properties::computed_value_flags::IS_TEXT_COMBINED; + use properties::computed_value_flags::ComputedValueFlags; let writing_mode = self.style.get_inheritedbox().clone_writing_mode(); @@ -142,7 +140,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { if writing_mode != writing_mode::horizontal_tb && text_combine_upright == text_combine_upright::all { - self.style.flags.insert(IS_TEXT_COMBINED); + self.style.flags.insert(ComputedValueFlags::IS_TEXT_COMBINED); self.style.mutate_inheritedbox().set_writing_mode(writing_mode::horizontal_tb); } } @@ -153,10 +151,10 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { /// from them. #[cfg(feature = "gecko")] fn adjust_for_text_in_ruby(&mut self) { - use properties::computed_value_flags::SHOULD_SUPPRESS_LINEBREAK; + use properties::computed_value_flags::ComputedValueFlags; let parent_display = self.style.get_parent_box().clone_display(); if parent_display.is_ruby_type() { - self.style.flags.insert(SHOULD_SUPPRESS_LINEBREAK); + self.style.flags.insert(ComputedValueFlags::SHOULD_SUPPRESS_LINEBREAK); } } @@ -190,14 +188,14 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { #[cfg(feature = "gecko")] fn adjust_for_contain(&mut self) { - use properties::longhands::contain; + use properties::longhands::contain::SpecifiedValue; // An element with contain: paint needs to be a formatting context, and // also implies overflow: clip. // // TODO(emilio): This mimics Gecko, but spec links are missing! let contain = self.style.get_box().clone_contain(); - if !contain.contains(contain::PAINT) { + if !contain.contains(SpecifiedValue::PAINT) { return; } @@ -208,7 +206,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { // When 'contain: paint', update overflow from 'visible' to 'clip'. - if self.style.get_box().clone_contain().contains(contain::PAINT) { + if self.style.get_box().clone_contain().contains(SpecifiedValue::PAINT) { if self.style.get_box().clone_overflow_x() == overflow::visible { let box_style = self.style.mutate_box(); box_style.set_overflow_x(overflow::_moz_hidden_unscrollable); @@ -321,11 +319,11 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { /// Native anonymous content converts display:contents into display:inline. #[cfg(feature = "gecko")] fn adjust_for_prohibited_display_contents(&mut self, flags: CascadeFlags) { - use properties::PROHIBIT_DISPLAY_CONTENTS; + use properties::CascadeFlags; // TODO: We should probably convert display:contents into display:none // in some cases too: https://drafts.csswg.org/css-display/#unbox - if !flags.contains(PROHIBIT_DISPLAY_CONTENTS) || + if !flags.contains(CascadeFlags::PROHIBIT_DISPLAY_CONTENTS) || self.style.get_box().clone_display() != display::contents { return; } @@ -345,8 +343,8 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { layout_parent_style: &ComputedValues, flags: CascadeFlags, ) { - use properties::IS_FIELDSET_CONTENT; - if !flags.contains(IS_FIELDSET_CONTENT) { + use properties::CascadeFlags; + if !flags.contains(CascadeFlags::IS_FIELDSET_CONTENT) { return; } debug_assert_eq!(self.style.get_box().clone_display(), display::block); @@ -394,10 +392,10 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { &mut self, layout_parent_style: &ComputedValues, ) { - use properties::computed_value_flags::HAS_TEXT_DECORATION_LINES; - if layout_parent_style.flags.contains(HAS_TEXT_DECORATION_LINES) || + use properties::computed_value_flags::ComputedValueFlags; + if layout_parent_style.flags.contains(ComputedValueFlags::HAS_TEXT_DECORATION_LINES) || !self.style.get_text().clone_text_decoration_line().is_empty() { - self.style.flags.insert(HAS_TEXT_DECORATION_LINES); + self.style.flags.insert(ComputedValueFlags::HAS_TEXT_DECORATION_LINES); } } @@ -406,13 +404,13 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { &self, layout_parent_style: &ComputedValues, ) -> bool { - use properties::computed_value_flags::SHOULD_SUPPRESS_LINEBREAK; + use properties::computed_value_flags::ComputedValueFlags; // Line break suppression should only be propagated to in-flow children. if self.style.floated() || self.style.out_of_flow_positioned() { return false; } let parent_display = layout_parent_style.get_box().clone_display(); - if layout_parent_style.flags.contains(SHOULD_SUPPRESS_LINEBREAK) { + if layout_parent_style.flags.contains(ComputedValueFlags::SHOULD_SUPPRESS_LINEBREAK) { // Line break suppression is propagated to any children of // line participants. if parent_display.is_line_participant() { @@ -448,16 +446,16 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { layout_parent_style: &ComputedValues, flags: CascadeFlags, ) { - use properties::SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP; - use properties::computed_value_flags::SHOULD_SUPPRESS_LINEBREAK; + use properties::CascadeFlags; + use properties::computed_value_flags::ComputedValueFlags; use properties::longhands::unicode_bidi::computed_value::T as unicode_bidi; let self_display = self.style.get_box().clone_display(); // Check whether line break should be suppressed for this element. if self.should_suppress_linebreak(layout_parent_style) { - self.style.flags.insert(SHOULD_SUPPRESS_LINEBREAK); + self.style.flags.insert(ComputedValueFlags::SHOULD_SUPPRESS_LINEBREAK); // Inlinify the display type if allowed. - if !flags.contains(SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP) { + if !flags.contains(CascadeFlags::SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP) { let inline_display = self_display.inlinify(); if self_display != inline_display { self.style.mutate_box().set_display(inline_display); @@ -498,21 +496,21 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { /// FIXME(emilio): This isn't technically a style adjustment thingie, could /// it move somewhere else? fn adjust_for_visited(&mut self, flags: CascadeFlags) { - use properties::{IS_LINK, IS_VISITED_LINK}; - use properties::computed_value_flags::IS_RELEVANT_LINK_VISITED; + use properties::CascadeFlags; + use properties::computed_value_flags::ComputedValueFlags; if !self.style.has_visited_style() { return; } - let relevant_link_visited = if flags.contains(IS_LINK) { - flags.contains(IS_VISITED_LINK) + let relevant_link_visited = if flags.contains(CascadeFlags::IS_LINK) { + flags.contains(CascadeFlags::IS_VISITED_LINK) } else { - self.style.inherited_flags().contains(IS_RELEVANT_LINK_VISITED) + self.style.inherited_flags().contains(ComputedValueFlags::IS_RELEVANT_LINK_VISITED) }; if relevant_link_visited { - self.style.flags.insert(IS_RELEVANT_LINK_VISITED); + self.style.flags.insert(ComputedValueFlags::IS_RELEVANT_LINK_VISITED); } } @@ -526,14 +524,14 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { fn adjust_for_justify_items(&mut self) { use values::specified::align; let justify_items = self.style.get_position().clone_justify_items(); - if justify_items.specified.0 != align::ALIGN_AUTO { + if justify_items.specified.0 != align::AlignFlags::AUTO { return; } let parent_justify_items = self.style.get_parent_position().clone_justify_items(); - if !parent_justify_items.computed.0.contains(align::ALIGN_LEGACY) { + if !parent_justify_items.computed.0.contains(align::AlignFlags::LEGACY) { return; } diff --git a/components/style/style_resolver.rs b/components/style/style_resolver.rs index 30d97f5f240..8c7a12c4e30 100644 --- a/components/style/style_resolver.rs +++ b/components/style/style_resolver.rs @@ -11,9 +11,7 @@ use dom::TElement; use log::LogLevel::Trace; use matching::{CascadeVisitedMode, MatchMethods}; use properties::{AnimationRules, CascadeFlags, ComputedValues}; -use properties::{IS_LINK, IS_ROOT_ELEMENT, IS_VISITED_LINK}; -use properties::{PROHIBIT_DISPLAY_CONTENTS, SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP}; -use properties::{VISITED_DEPENDENT_ONLY, cascade}; +use properties::cascade; use properties::longhands::display::computed_value::T as display; use rule_tree::StrongRuleNode; use selector_parser::{PseudoElement, SelectorImpl}; @@ -110,18 +108,18 @@ fn eager_pseudo_is_definitely_not_generated( pseudo: &PseudoElement, style: &ComputedValues, ) -> bool { - use properties::computed_value_flags::{INHERITS_CONTENT, INHERITS_DISPLAY}; + use properties::computed_value_flags::ComputedValueFlags; if !pseudo.is_before_or_after() { return false; } - if !style.flags.intersects(INHERITS_DISPLAY) && + if !style.flags.intersects(ComputedValueFlags::INHERITS_DISPLAY) && style.get_box().clone_display() == display::none { return true; } - if !style.flags.intersects(INHERITS_CONTENT) && + if !style.flags.intersects(ComputedValueFlags::INHERITS_CONTENT) && style.ineffective_content_property() { return true; } @@ -550,14 +548,14 @@ where if self.element.skip_root_and_item_based_display_fixup() || pseudo.map_or(false, |p| p.skip_item_based_display_fixup()) { - cascade_flags.insert(SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP); + cascade_flags.insert(CascadeFlags::SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP); } if pseudo.is_none() && self.element.is_link() { - cascade_flags.insert(IS_LINK); + cascade_flags.insert(CascadeFlags::IS_LINK); if self.element.is_visited_link() && self.context.shared.visited_styles_enabled { - cascade_flags.insert(IS_VISITED_LINK); + cascade_flags.insert(CascadeFlags::IS_VISITED_LINK); } } @@ -570,12 +568,12 @@ where s.visited_style().unwrap_or(s) }); } - cascade_flags.insert(VISITED_DEPENDENT_ONLY); + cascade_flags.insert(CascadeFlags::VISITED_DEPENDENT_ONLY); } if self.element.is_native_anonymous() || pseudo.is_some() { - cascade_flags.insert(PROHIBIT_DISPLAY_CONTENTS); + cascade_flags.insert(CascadeFlags::PROHIBIT_DISPLAY_CONTENTS); } else if self.element.is_root() { - cascade_flags.insert(IS_ROOT_ELEMENT); + cascade_flags.insert(CascadeFlags::IS_ROOT_ELEMENT); } let implemented_pseudo = self.element.implemented_pseudo_element(); diff --git a/components/style/stylesheets/keyframes_rule.rs b/components/style/stylesheets/keyframes_rule.rs index d85b0e06ea6..d0372c7d240 100644 --- a/components/style/stylesheets/keyframes_rule.rs +++ b/components/style/stylesheets/keyframes_rule.rs @@ -15,7 +15,7 @@ use properties::longhands::transition_timing_function::single_value::SpecifiedVa use servo_arc::Arc; use shared_lock::{DeepCloneParams, DeepCloneWithLock, SharedRwLock, SharedRwLockReadGuard, Locked, ToCssWithGuard}; use std::fmt; -use style_traits::{PARSING_MODE_DEFAULT, ToCss, ParseError, StyleParseErrorKind}; +use style_traits::{ParsingMode, ToCss, ParseError, StyleParseErrorKind}; use stylesheets::{CssRuleType, StylesheetContents}; use stylesheets::rule_parser::VendorPrefix; use values::{KeyframesName, serialize_percentage}; @@ -218,7 +218,7 @@ impl Keyframe { parent_stylesheet_contents.origin, &url_data, Some(CssRuleType::Keyframe), - PARSING_MODE_DEFAULT, + ParsingMode::DEFAULT, parent_stylesheet_contents.quirks_mode ); let error_context = ParserErrorContext { error_reporter: &error_reporter }; diff --git a/components/style/stylesheets/mod.rs b/components/style/stylesheets/mod.rs index dff69880418..f419b9602ed 100644 --- a/components/style/stylesheets/mod.rs +++ b/components/style/stylesheets/mod.rs @@ -31,7 +31,7 @@ use parser::{ParserContext, ParserErrorContext}; use servo_arc::Arc; use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard}; use std::fmt; -use style_traits::PARSING_MODE_DEFAULT; +use style_traits::ParsingMode; pub use self::counter_style_rule::CounterStyleRule; pub use self::document_rule::DocumentRule; @@ -241,7 +241,7 @@ impl CssRule { parent_stylesheet_contents.origin, &url_data, None, - PARSING_MODE_DEFAULT, + ParsingMode::DEFAULT, parent_stylesheet_contents.quirks_mode, ); diff --git a/components/style/stylesheets/origin.rs b/components/style/stylesheets/origin.rs index a64214691c0..5defc2a3db2 100644 --- a/components/style/stylesheets/origin.rs +++ b/components/style/stylesheets/origin.rs @@ -41,13 +41,13 @@ impl Origin { bitflags! { /// A set of origins. This is equivalent to Gecko's OriginFlags. #[cfg_attr(feature = "servo", derive(MallocSizeOf))] - pub flags OriginSet: u8 { + pub struct OriginSet: u8 { /// <https://drafts.csswg.org/css-cascade/#cascade-origin-user-agent> - const ORIGIN_USER_AGENT = Origin::UserAgent as u8, + const ORIGIN_USER_AGENT = Origin::UserAgent as u8; /// <https://drafts.csswg.org/css-cascade/#cascade-origin-user> - const ORIGIN_USER = Origin::User as u8, + const ORIGIN_USER = Origin::User as u8; /// <https://drafts.csswg.org/css-cascade/#cascade-origin-author> - const ORIGIN_AUTHOR = Origin::Author as u8, + const ORIGIN_AUTHOR = Origin::Author as u8; } } diff --git a/components/style/stylesheets/stylesheet.rs b/components/style/stylesheets/stylesheet.rs index 29ffbf1fa98..02d87f1ceea 100644 --- a/components/style/stylesheets/stylesheet.rs +++ b/components/style/stylesheets/stylesheet.rs @@ -18,7 +18,7 @@ use servo_arc::Arc; use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard}; use std::mem; use std::sync::atomic::{AtomicBool, Ordering}; -use style_traits::PARSING_MODE_DEFAULT; +use style_traits::ParsingMode; use stylesheets::{CssRule, CssRules, Origin, UrlExtraData}; use stylesheets::loader::StylesheetLoader; use stylesheets::rule_parser::{State, TopLevelRuleParser}; @@ -364,7 +364,7 @@ impl Stylesheet { origin, url_data, None, - PARSING_MODE_DEFAULT, + ParsingMode::DEFAULT, quirks_mode ); let error_context = ParserErrorContext { error_reporter }; diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 72445369d7c..924cbde3d9f 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -22,10 +22,6 @@ use malloc_size_of::MallocUnconditionalShallowSizeOf; use media_queries::Device; use properties::{self, CascadeFlags, ComputedValues}; use properties::{AnimationRules, PropertyDeclarationBlock}; -#[cfg(feature = "servo")] -use properties::INHERIT_ALL; -use properties::IS_LINK; -use properties::VISITED_DEPENDENT_ONLY; use rule_tree::{CascadeLevel, RuleTree, StrongRuleNode, StyleSource}; use selector_map::{PrecomputedHashMap, SelectorMap, SelectorMapEntry}; use selector_parser::{SelectorImpl, PerPseudoElementMap, PseudoElement}; @@ -54,7 +50,7 @@ use stylesheets::StyleRule; use stylesheets::StylesheetInDocument; use stylesheets::keyframes_rule::KeyframesAnimation; use stylesheets::viewport_rule::{self, MaybeNew, ViewportRule}; -use thread_state; +use thread_state::{self, ThreadState}; /// The type of the stylesheets that the stylist contains. #[cfg(feature = "servo")] @@ -791,7 +787,7 @@ impl Stylist { }; let mut cascade_flags = CascadeFlags::empty(); if inherit_all { - cascade_flags.insert(INHERIT_ALL); + cascade_flags.insert(CascadeFlags::INHERIT_ALL); } self.precomputed_values_for_pseudo( guards, @@ -907,7 +903,7 @@ impl Stylist { let inherited_style; let inherited_style_ignoring_first_line; let layout_parent_style_for_visited; - if cascade_flags.contains(IS_LINK) { + if cascade_flags.contains(CascadeFlags::IS_LINK) { // We just want to use our parent style as our parent. inherited_style = parent_style; inherited_style_ignoring_first_line = parent_style_ignoring_first_line; @@ -933,7 +929,7 @@ impl Stylist { Some(layout_parent_style_for_visited), None, font_metrics, - cascade_flags | VISITED_DEPENDENT_ONLY, + cascade_flags | CascadeFlags::VISITED_DEPENDENT_ONLY, self.quirks_mode, /* rule_cache = */ None, &mut Default::default(), @@ -1002,7 +998,7 @@ impl Stylist { // Gecko calls this from sequential mode, so we can directly apply // the flags. - debug_assert!(thread_state::get() == thread_state::LAYOUT); + debug_assert!(thread_state::get() == ThreadState::LAYOUT); let self_flags = flags.for_self(); if !self_flags.is_empty() { unsafe { element.set_selector_flags(self_flags); } diff --git a/components/style/thread_state.rs b/components/style/thread_state.rs index d06f47aabe4..7bcefc564fa 100644 --- a/components/style/thread_state.rs +++ b/components/style/thread_state.rs @@ -11,26 +11,26 @@ use std::cell::RefCell; bitflags! { /// A thread state flag, used for multiple assertions. - pub flags ThreadState: u32 { + pub struct ThreadState: u32 { /// Whether we're in a script thread. - const SCRIPT = 0x01, + const SCRIPT = 0x01; /// Whether we're in a layout thread. - const LAYOUT = 0x02, + const LAYOUT = 0x02; /// Whether we're in a script worker thread (actual web workers), or in /// a layout worker thread. - const IN_WORKER = 0x0100, + const IN_WORKER = 0x0100; /// Whether the current thread is going through a GC. - const IN_GC = 0x0200, + const IN_GC = 0x0200; } } -macro_rules! thread_types ( ( $( $fun:ident = $flag:ident ; )* ) => ( +macro_rules! thread_types ( ( $( $fun:ident = $flag:path ; )* ) => ( impl ThreadState { /// Whether the current thread is a worker thread. pub fn is_worker(self) -> bool { - self.contains(IN_WORKER) + self.contains(ThreadState::IN_WORKER) } $( @@ -43,8 +43,8 @@ macro_rules! thread_types ( ( $( $fun:ident = $flag:ident ; )* ) => ( )); thread_types! { - is_script = SCRIPT; - is_layout = LAYOUT; + is_script = ThreadState::SCRIPT; + is_layout = ThreadState::LAYOUT; } thread_local!(static STATE: RefCell<Option<ThreadState>> = RefCell::new(None)); @@ -63,7 +63,7 @@ pub fn initialize(x: ThreadState) { /// Initializes the current thread as a layout worker thread. pub fn initialize_layout_worker_thread() { - initialize(LAYOUT | IN_WORKER); + initialize(ThreadState::LAYOUT | ThreadState::IN_WORKER); } /// Gets the current thread state. diff --git a/components/style/traversal.rs b/components/style/traversal.rs index 7737ce044f0..8b52c3bd4b9 100644 --- a/components/style/traversal.rs +++ b/components/style/traversal.rs @@ -7,14 +7,14 @@ use context::{ElementCascadeInputs, StyleContext, SharedStyleContext}; use data::{ElementData, ElementStyles}; use dom::{NodeInfo, OpaqueNode, TElement, TNode}; -use invalidation::element::restyle_hints::{RECASCADE_SELF, RECASCADE_DESCENDANTS, RestyleHint}; +use invalidation::element::restyle_hints::RestyleHint; use matching::{ChildCascadeRequirement, MatchMethods}; use selector_parser::PseudoElement; use sharing::StyleSharingTarget; use smallvec::SmallVec; use style_resolver::{PseudoElementResolution, StyleResolverForElement}; use stylist::RuleInclusion; -use traversal_flags::{TraversalFlags, self}; +use traversal_flags::TraversalFlags; /// A per-traversal-level chunk of data. This is sent down by the traversal, and /// currently only holds the dom depth for the bloom filter. @@ -149,7 +149,7 @@ pub trait DomTraversal<E: TElement> : Sync { // If this is an unstyled-only traversal, the caller has already verified // that there's something to traverse, and we don't need to do any // invalidation since we're not doing any restyling. - if traversal_flags.contains(traversal_flags::UnstyledOnly) { + if traversal_flags.contains(TraversalFlags::UnstyledOnly) { return PreTraverseToken(Some(root)) } @@ -222,7 +222,7 @@ pub trait DomTraversal<E: TElement> : Sync { debug!("element_needs_traversal({:?}, {:?}, {:?}, {:?})", el, traversal_flags, data, parent_data); - if traversal_flags.contains(traversal_flags::UnstyledOnly) { + if traversal_flags.contains(TraversalFlags::UnstyledOnly) { return data.map_or(true, |d| !d.has_styles()) || el.has_dirty_descendants(); } @@ -473,12 +473,12 @@ where F: FnMut(E::ConcreteNode), { use std::cmp; - use traversal_flags::*; + use traversal_flags::TraversalFlags; let flags = context.shared.traversal_flags; context.thread_local.begin_element(element, data); context.thread_local.statistics.elements_traversed += 1; - debug_assert!(flags.intersects(AnimationOnly | UnstyledOnly) || + debug_assert!(flags.intersects(TraversalFlags::AnimationOnly | TraversalFlags::UnstyledOnly) || !element.has_snapshot() || element.handled_snapshot(), "Should've handled snapshots here already"); @@ -525,7 +525,7 @@ where // those operations and compute the propagated restyle hint (unless we're // not processing invalidations, in which case don't need to propagate it // and must avoid clearing it). - let propagated_hint = if flags.contains(UnstyledOnly) { + let propagated_hint = if flags.contains(TraversalFlags::UnstyledOnly) { RestyleHint::empty() } else { debug_assert!(flags.for_animation_only() || @@ -596,7 +596,7 @@ where } debug_assert!(flags.for_animation_only() || - !flags.contains(ClearDirtyBits) || + !flags.contains(TraversalFlags::ClearDirtyBits) || !element.has_animation_only_dirty_descendants(), "Should have cleared animation bits already"); clear_state_after_traversing(element, data, flags); @@ -612,21 +612,19 @@ fn clear_state_after_traversing<E>( where E: TElement, { - use traversal_flags::*; - // If we are in a forgetful traversal, drop the existing restyle // data here, since we won't need to perform a post-traversal to pick up // any change hints. - if flags.contains(Forgetful) { + if flags.contains(TraversalFlags::Forgetful) { data.clear_restyle_flags_and_damage(); } // Clear dirty bits as appropriate. if flags.for_animation_only() { - if flags.intersects(ClearDirtyBits | ClearAnimationOnlyDirtyDescendants) { + if flags.intersects(TraversalFlags::ClearDirtyBits | TraversalFlags::ClearAnimationOnlyDirtyDescendants) { unsafe { element.unset_animation_only_dirty_descendants(); } } - } else if flags.contains(ClearDirtyBits) { + } else if flags.contains(TraversalFlags::ClearDirtyBits) { // The animation traversal happens first, so we don't need to guard against // clearing the animation bit on the regular traversal. unsafe { element.clear_dirty_bits(); } @@ -863,7 +861,7 @@ where // Make sure to not run style invalidation of styled elements in an // unstyled-children-only traversal. - if child_data.is_some() && flags.intersects(traversal_flags::UnstyledOnly) { + if child_data.is_some() && flags.intersects(TraversalFlags::UnstyledOnly) { continue; } @@ -876,16 +874,16 @@ where match cascade_requirement { ChildCascadeRequirement::CanSkipCascade => {} ChildCascadeRequirement::MustCascadeDescendants => { - child_hint |= RECASCADE_SELF | RECASCADE_DESCENDANTS; + child_hint |= RestyleHint::RECASCADE_SELF | RestyleHint::RECASCADE_DESCENDANTS; } ChildCascadeRequirement::MustCascadeChildrenIfInheritResetStyle => { - use properties::computed_value_flags::INHERITS_RESET_STYLE; - if child_data.styles.primary().flags.contains(INHERITS_RESET_STYLE) { - child_hint |= RECASCADE_SELF; + use properties::computed_value_flags::ComputedValueFlags; + if child_data.styles.primary().flags.contains(ComputedValueFlags::INHERITS_RESET_STYLE) { + child_hint |= RestyleHint::RECASCADE_SELF; } } ChildCascadeRequirement::MustCascadeChildren => { - child_hint |= RECASCADE_SELF; + child_hint |= RestyleHint::RECASCADE_SELF; } } diff --git a/components/style/traversal_flags.rs b/components/style/traversal_flags.rs index ba623b5451d..5664aeeb31a 100644 --- a/components/style/traversal_flags.rs +++ b/components/style/traversal_flags.rs @@ -10,31 +10,31 @@ bitflags! { /// Flags that control the traversal process. - pub flags TraversalFlags: u32 { + pub struct TraversalFlags: u32 { /// Traverse only elements for animation restyles. - const AnimationOnly = 1 << 0, + const AnimationOnly = 1 << 0; /// Traverse and update all elements with CSS animations since /// @keyframes rules may have changed. Triggered by CSS rule changes. - const ForCSSRuleChanges = 1 << 1, + const ForCSSRuleChanges = 1 << 1; /// Styles unstyled elements, but does not handle invalidations on /// already-styled elements. - const UnstyledOnly = 1 << 2, + const UnstyledOnly = 1 << 2; /// A forgetful traversal ignores the previous state of the frame tree, and /// thus does not compute damage or maintain other state describing the styles /// pre-traversal. A forgetful traversal is usually the right thing if you /// aren't going to do a post-traversal. - const Forgetful = 1 << 3, + const Forgetful = 1 << 3; /// Clears all the dirty bits on the elements traversed. - const ClearDirtyBits = 1 << 5, + const ClearDirtyBits = 1 << 5; /// Clears the animation-only dirty descendants bit in the subtree. - const ClearAnimationOnlyDirtyDescendants = 1 << 6, + const ClearAnimationOnlyDirtyDescendants = 1 << 6; /// Allows the traversal to run in parallel if there are sufficient cores on /// the machine. - const ParallelTraversal = 1 << 7, + const ParallelTraversal = 1 << 7; /// Flush throttled animations. By default, we only update throttled animations /// when we have other non-throttled work to do. With this flag, we /// unconditionally tick and process them. - const FlushThrottledAnimations = 1 << 8, + const FlushThrottledAnimations = 1 << 8; } } @@ -46,7 +46,7 @@ pub fn assert_traversal_flags_match() { use gecko_bindings::structs; macro_rules! check_traversal_flags { - ( $( $a:ident => $b:ident ),*, ) => { + ( $( $a:ident => $b:path ),*, ) => { if cfg!(debug_assertions) { let mut modes = TraversalFlags::all(); $( @@ -59,15 +59,15 @@ pub fn assert_traversal_flags_match() { } check_traversal_flags! { - ServoTraversalFlags_AnimationOnly => AnimationOnly, - ServoTraversalFlags_ForCSSRuleChanges => ForCSSRuleChanges, - ServoTraversalFlags_UnstyledOnly => UnstyledOnly, - ServoTraversalFlags_Forgetful => Forgetful, - ServoTraversalFlags_ClearDirtyBits => ClearDirtyBits, + ServoTraversalFlags_AnimationOnly => TraversalFlags::AnimationOnly, + ServoTraversalFlags_ForCSSRuleChanges => TraversalFlags::ForCSSRuleChanges, + ServoTraversalFlags_UnstyledOnly => TraversalFlags::UnstyledOnly, + ServoTraversalFlags_Forgetful => TraversalFlags::Forgetful, + ServoTraversalFlags_ClearDirtyBits => TraversalFlags::ClearDirtyBits, ServoTraversalFlags_ClearAnimationOnlyDirtyDescendants => - ClearAnimationOnlyDirtyDescendants, - ServoTraversalFlags_ParallelTraversal => ParallelTraversal, - ServoTraversalFlags_FlushThrottledAnimations => FlushThrottledAnimations, + TraversalFlags::ClearAnimationOnlyDirtyDescendants, + ServoTraversalFlags_ParallelTraversal => TraversalFlags::ParallelTraversal, + ServoTraversalFlags_FlushThrottledAnimations => TraversalFlags::FlushThrottledAnimations, } } @@ -75,6 +75,6 @@ impl TraversalFlags { /// Returns true if the traversal is for animation-only restyles. #[inline] pub fn for_animation_only(&self) -> bool { - self.contains(AnimationOnly) + self.contains(TraversalFlags::AnimationOnly) } } diff --git a/components/style/values/computed/align.rs b/components/style/values/computed/align.rs index ab306a179ed..f3caade67a5 100644 --- a/components/style/values/computed/align.rs +++ b/components/style/values/computed/align.rs @@ -51,7 +51,7 @@ impl ToComputedValue for specified::JustifyItems { use values::specified::align; let specified = *self; let computed = - if self.0 != align::ALIGN_AUTO { + if self.0 != align::AlignFlags::AUTO { *self } else { // If the inherited value of `justify-items` includes the diff --git a/components/style/values/specified/align.rs b/components/style/values/specified/align.rs index 54fece9d340..66ba2116a62 100644 --- a/components/style/values/specified/align.rs +++ b/components/style/values/specified/align.rs @@ -20,84 +20,84 @@ bitflags! { /// These constants match Gecko's `NS_STYLE_ALIGN_*` constants. #[cfg_attr(feature = "gecko", derive(MallocSizeOf))] #[derive(ToComputedValue)] - pub flags AlignFlags: u8 { + pub struct AlignFlags: u8 { // Enumeration stored in the lower 5 bits: /// 'auto' - const ALIGN_AUTO = structs::NS_STYLE_ALIGN_AUTO as u8, + const AUTO = structs::NS_STYLE_ALIGN_AUTO as u8; /// 'normal' - const ALIGN_NORMAL = structs::NS_STYLE_ALIGN_NORMAL as u8, + const NORMAL = structs::NS_STYLE_ALIGN_NORMAL as u8; /// 'start' - const ALIGN_START = structs::NS_STYLE_ALIGN_START as u8, + const START = structs::NS_STYLE_ALIGN_START as u8; /// 'end' - const ALIGN_END = structs::NS_STYLE_ALIGN_END as u8, + const END = structs::NS_STYLE_ALIGN_END as u8; /// 'flex-start' - const ALIGN_FLEX_START = structs::NS_STYLE_ALIGN_FLEX_START as u8, + const FLEX_START = structs::NS_STYLE_ALIGN_FLEX_START as u8; /// 'flex-end' - const ALIGN_FLEX_END = structs::NS_STYLE_ALIGN_FLEX_END as u8, + const FLEX_END = structs::NS_STYLE_ALIGN_FLEX_END as u8; /// 'center' - const ALIGN_CENTER = structs::NS_STYLE_ALIGN_CENTER as u8, + const CENTER = structs::NS_STYLE_ALIGN_CENTER as u8; /// 'left' - const ALIGN_LEFT = structs::NS_STYLE_ALIGN_LEFT as u8, + const LEFT = structs::NS_STYLE_ALIGN_LEFT as u8; /// 'right' - const ALIGN_RIGHT = structs::NS_STYLE_ALIGN_RIGHT as u8, + const RIGHT = structs::NS_STYLE_ALIGN_RIGHT as u8; /// 'baseline' - const ALIGN_BASELINE = structs::NS_STYLE_ALIGN_BASELINE as u8, + const BASELINE = structs::NS_STYLE_ALIGN_BASELINE as u8; /// 'last-baseline' - const ALIGN_LAST_BASELINE = structs::NS_STYLE_ALIGN_LAST_BASELINE as u8, + const LAST_BASELINE = structs::NS_STYLE_ALIGN_LAST_BASELINE as u8; /// 'stretch' - const ALIGN_STRETCH = structs::NS_STYLE_ALIGN_STRETCH as u8, + const STRETCH = structs::NS_STYLE_ALIGN_STRETCH as u8; /// 'self-start' - const ALIGN_SELF_START = structs::NS_STYLE_ALIGN_SELF_START as u8, + const SELF_START = structs::NS_STYLE_ALIGN_SELF_START as u8; /// 'self-end' - const ALIGN_SELF_END = structs::NS_STYLE_ALIGN_SELF_END as u8, + const SELF_END = structs::NS_STYLE_ALIGN_SELF_END as u8; /// 'space-between' - const ALIGN_SPACE_BETWEEN = structs::NS_STYLE_ALIGN_SPACE_BETWEEN as u8, + const SPACE_BETWEEN = structs::NS_STYLE_ALIGN_SPACE_BETWEEN as u8; /// 'space-around' - const ALIGN_SPACE_AROUND = structs::NS_STYLE_ALIGN_SPACE_AROUND as u8, + const SPACE_AROUND = structs::NS_STYLE_ALIGN_SPACE_AROUND as u8; /// 'space-evenly' - const ALIGN_SPACE_EVENLY = structs::NS_STYLE_ALIGN_SPACE_EVENLY as u8, + const SPACE_EVENLY = structs::NS_STYLE_ALIGN_SPACE_EVENLY as u8; // Additional flags stored in the upper bits: /// 'legacy' (mutually exclusive w. SAFE & UNSAFE) - const ALIGN_LEGACY = structs::NS_STYLE_ALIGN_LEGACY as u8, + const LEGACY = structs::NS_STYLE_ALIGN_LEGACY as u8; /// 'safe' - const ALIGN_SAFE = structs::NS_STYLE_ALIGN_SAFE as u8, + const SAFE = structs::NS_STYLE_ALIGN_SAFE as u8; /// 'unsafe' (mutually exclusive w. SAFE) - const ALIGN_UNSAFE = structs::NS_STYLE_ALIGN_UNSAFE as u8, + const UNSAFE = structs::NS_STYLE_ALIGN_UNSAFE as u8; /// Mask for the additional flags above. - const ALIGN_FLAG_BITS = structs::NS_STYLE_ALIGN_FLAG_BITS as u8, + const FLAG_BITS = structs::NS_STYLE_ALIGN_FLAG_BITS as u8; } } impl ToCss for AlignFlags { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - let s = match *self & !ALIGN_FLAG_BITS { - ALIGN_AUTO => "auto", - ALIGN_NORMAL => "normal", - ALIGN_START => "start", - ALIGN_END => "end", - ALIGN_FLEX_START => "flex-start", - ALIGN_FLEX_END => "flex-end", - ALIGN_CENTER => "center", - ALIGN_LEFT => "left", - ALIGN_RIGHT => "right", - ALIGN_BASELINE => "baseline", - ALIGN_LAST_BASELINE => "last baseline", - ALIGN_STRETCH => "stretch", - ALIGN_SELF_START => "self-start", - ALIGN_SELF_END => "self-end", - ALIGN_SPACE_BETWEEN => "space-between", - ALIGN_SPACE_AROUND => "space-around", - ALIGN_SPACE_EVENLY => "space-evenly", + let s = match *self & !AlignFlags::FLAG_BITS { + AlignFlags::AUTO => "auto", + AlignFlags::NORMAL => "normal", + AlignFlags::START => "start", + AlignFlags::END => "end", + AlignFlags::FLEX_START => "flex-start", + AlignFlags::FLEX_END => "flex-end", + AlignFlags::CENTER => "center", + AlignFlags::LEFT => "left", + AlignFlags::RIGHT => "right", + AlignFlags::BASELINE => "baseline", + AlignFlags::LAST_BASELINE => "last baseline", + AlignFlags::STRETCH => "stretch", + AlignFlags::SELF_START => "self-start", + AlignFlags::SELF_END => "self-end", + AlignFlags::SPACE_BETWEEN => "space-between", + AlignFlags::SPACE_AROUND => "space-around", + AlignFlags::SPACE_EVENLY => "space-evenly", _ => unreachable!() }; dest.write_str(s)?; - match *self & ALIGN_FLAG_BITS { - ALIGN_LEGACY => { dest.write_str(" legacy")?; } - ALIGN_SAFE => { dest.write_str(" safe")?; } - ALIGN_UNSAFE => { dest.write_str(" unsafe")?; } + match *self & AlignFlags::FLAG_BITS { + AlignFlags::LEGACY => { dest.write_str(" legacy")?; } + AlignFlags::SAFE => { dest.write_str(" safe")?; } + AlignFlags::UNSAFE => { dest.write_str(" unsafe")?; } _ => {} } Ok(()) @@ -123,7 +123,7 @@ impl AlignJustifyContent { /// The initial value 'normal' #[inline] pub fn normal() -> Self { - Self::new(ALIGN_NORMAL) + Self::new(AlignFlags::NORMAL) } /// Construct a value with no fallback. @@ -157,7 +157,7 @@ impl AlignJustifyContent { /// Whether this value has extra flags. #[inline] pub fn has_extra_flags(self) -> bool { - self.primary().intersects(ALIGN_FLAG_BITS) || self.fallback().intersects(ALIGN_FLAG_BITS) + self.primary().intersects(AlignFlags::FLAG_BITS) || self.fallback().intersects(AlignFlags::FLAG_BITS) } } @@ -165,7 +165,7 @@ impl ToCss for AlignJustifyContent { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { self.primary().to_css(dest)?; match self.fallback() { - ALIGN_AUTO => {} + AlignFlags::AUTO => {} fallback => { dest.write_str(" ")?; fallback.to_css(dest)?; @@ -215,13 +215,13 @@ impl AlignJustifySelf { /// The initial value 'auto' #[inline] pub fn auto() -> Self { - AlignJustifySelf(ALIGN_AUTO) + AlignJustifySelf(AlignFlags::AUTO) } /// Whether this value has extra flags. #[inline] pub fn has_extra_flags(self) -> bool { - self.0.intersects(ALIGN_FLAG_BITS) + self.0.intersects(AlignFlags::FLAG_BITS) } } @@ -253,13 +253,13 @@ impl AlignItems { /// The initial value 'normal' #[inline] pub fn normal() -> Self { - AlignItems(ALIGN_NORMAL) + AlignItems(AlignFlags::NORMAL) } /// Whether this value has extra flags. #[inline] pub fn has_extra_flags(self) -> bool { - self.0.intersects(ALIGN_FLAG_BITS) + self.0.intersects(AlignFlags::FLAG_BITS) } } @@ -291,19 +291,19 @@ impl JustifyItems { /// The initial value 'auto' #[inline] pub fn auto() -> Self { - JustifyItems(ALIGN_AUTO) + JustifyItems(AlignFlags::AUTO) } /// The value 'normal' #[inline] pub fn normal() -> Self { - JustifyItems(ALIGN_NORMAL) + JustifyItems(AlignFlags::NORMAL) } /// Whether this value has extra flags. #[inline] pub fn has_extra_flags(self) -> bool { - self.0.intersects(ALIGN_FLAG_BITS) + self.0.intersects(AlignFlags::FLAG_BITS) } } @@ -351,9 +351,9 @@ fn parse_auto_normal_stretch_baseline<'i, 't>(input: &mut Parser<'i, 't>) } try_match_ident_ignore_ascii_case! { input, - "auto" => Ok(ALIGN_AUTO), - "normal" => Ok(ALIGN_NORMAL), - "stretch" => Ok(ALIGN_STRETCH), + "auto" => Ok(AlignFlags::AUTO), + "normal" => Ok(AlignFlags::NORMAL), + "stretch" => Ok(AlignFlags::STRETCH), } } @@ -364,8 +364,8 @@ fn parse_normal_stretch_baseline<'i, 't>(input: &mut Parser<'i, 't>) -> Result<A } try_match_ident_ignore_ascii_case! { input, - "normal" => Ok(ALIGN_NORMAL), - "stretch" => Ok(ALIGN_STRETCH), + "normal" => Ok(AlignFlags::NORMAL), + "stretch" => Ok(AlignFlags::STRETCH), } } @@ -376,21 +376,21 @@ fn parse_normal_or_baseline<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignF } input.expect_ident_matching("normal")?; - Ok(ALIGN_NORMAL) + Ok(AlignFlags::NORMAL) } // <baseline-position> fn parse_baseline<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> { // FIXME: remove clone() when lifetimes are non-lexical try_match_ident_ignore_ascii_case! { input, - "baseline" => Ok(ALIGN_BASELINE), + "baseline" => Ok(AlignFlags::BASELINE), "first" => { input.expect_ident_matching("baseline")?; - Ok(ALIGN_BASELINE) + Ok(AlignFlags::BASELINE) } "last" => { input.expect_ident_matching("baseline")?; - Ok(ALIGN_LAST_BASELINE) + Ok(AlignFlags::LAST_BASELINE) } } } @@ -398,10 +398,10 @@ fn parse_baseline<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, Pars // <content-distribution> fn parse_content_distribution<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> { try_match_ident_ignore_ascii_case! { input, - "stretch" => Ok(ALIGN_STRETCH), - "space-between" => Ok(ALIGN_SPACE_BETWEEN), - "space-around" => Ok(ALIGN_SPACE_AROUND), - "space-evenly" => Ok(ALIGN_SPACE_EVENLY), + "stretch" => Ok(AlignFlags::STRETCH), + "space-between" => Ok(AlignFlags::SPACE_BETWEEN), + "space-around" => Ok(AlignFlags::SPACE_AROUND), + "space-evenly" => Ok(AlignFlags::SPACE_EVENLY), } } @@ -426,21 +426,21 @@ fn parse_overflow_content_position<'i, 't>(input: &mut Parser<'i, 't>) -> Result // <content-position> fn parse_content_position<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> { try_match_ident_ignore_ascii_case! { input, - "start" => Ok(ALIGN_START), - "end" => Ok(ALIGN_END), - "flex-start" => Ok(ALIGN_FLEX_START), - "flex-end" => Ok(ALIGN_FLEX_END), - "center" => Ok(ALIGN_CENTER), - "left" => Ok(ALIGN_LEFT), - "right" => Ok(ALIGN_RIGHT), + "start" => Ok(AlignFlags::START), + "end" => Ok(AlignFlags::END), + "flex-start" => Ok(AlignFlags::FLEX_START), + "flex-end" => Ok(AlignFlags::FLEX_END), + "center" => Ok(AlignFlags::CENTER), + "left" => Ok(AlignFlags::LEFT), + "right" => Ok(AlignFlags::RIGHT), } } // <overflow-position> fn parse_overflow_position<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> { try_match_ident_ignore_ascii_case! { input, - "safe" => Ok(ALIGN_SAFE), - "unsafe" => Ok(ALIGN_UNSAFE), + "safe" => Ok(AlignFlags::SAFE), + "unsafe" => Ok(AlignFlags::UNSAFE), } } @@ -465,15 +465,15 @@ fn parse_overflow_self_position<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Al // <self-position> fn parse_self_position<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> { try_match_ident_ignore_ascii_case! { input, - "start" => Ok(ALIGN_START), - "end" => Ok(ALIGN_END), - "flex-start" => Ok(ALIGN_FLEX_START), - "flex-end" => Ok(ALIGN_FLEX_END), - "center" => Ok(ALIGN_CENTER), - "left" => Ok(ALIGN_LEFT), - "right" => Ok(ALIGN_RIGHT), - "self-start" => Ok(ALIGN_SELF_START), - "self-end" => Ok(ALIGN_SELF_END), + "start" => Ok(AlignFlags::START), + "end" => Ok(AlignFlags::END), + "flex-start" => Ok(AlignFlags::FLEX_START), + "flex-end" => Ok(AlignFlags::FLEX_END), + "center" => Ok(AlignFlags::CENTER), + "left" => Ok(AlignFlags::LEFT), + "right" => Ok(AlignFlags::RIGHT), + "self-start" => Ok(AlignFlags::SELF_START), + "self-end" => Ok(AlignFlags::SELF_END), } } @@ -485,16 +485,16 @@ fn parse_legacy<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseE let b = input.expect_ident()?; if a.eq_ignore_ascii_case("legacy") { (match_ignore_ascii_case! { &b, - "left" => Ok(ALIGN_LEGACY | ALIGN_LEFT), - "right" => Ok(ALIGN_LEGACY | ALIGN_RIGHT), - "center" => Ok(ALIGN_LEGACY | ALIGN_CENTER), + "left" => Ok(AlignFlags::LEGACY | AlignFlags::LEFT), + "right" => Ok(AlignFlags::LEGACY | AlignFlags::RIGHT), + "center" => Ok(AlignFlags::LEGACY | AlignFlags::CENTER), _ => Err(()) }).map_err(|()| b_location.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(b.clone()))) } else if b.eq_ignore_ascii_case("legacy") { (match_ignore_ascii_case! { &a, - "left" => Ok(ALIGN_LEGACY | ALIGN_LEFT), - "right" => Ok(ALIGN_LEGACY | ALIGN_RIGHT), - "center" => Ok(ALIGN_LEGACY | ALIGN_CENTER), + "left" => Ok(AlignFlags::LEGACY | AlignFlags::LEFT), + "right" => Ok(AlignFlags::LEGACY | AlignFlags::RIGHT), + "center" => Ok(AlignFlags::LEGACY | AlignFlags::CENTER), _ => Err(()) }).map_err(|()| a_location.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(a))) } else { diff --git a/components/style/values/specified/time.rs b/components/style/values/specified/time.rs index 075207a7906..3143160abaa 100644 --- a/components/style/values/specified/time.rs +++ b/components/style/values/specified/time.rs @@ -77,7 +77,7 @@ impl Time { input: &mut Parser<'i, 't>, clamping_mode: AllowedNumericType ) -> Result<Self, ParseError<'i>> { - use style_traits::PARSING_MODE_DEFAULT; + use style_traits::ParsingMode; let location = input.current_source_location(); // FIXME: remove early returns when lifetimes are non-lexical @@ -86,8 +86,8 @@ impl Time { // that the ParserMode of the ParserContext allows all numeric // values for SMIL regardless of clamping_mode, but in this Time // value case, the value does not animate for SMIL at all, so we use - // PARSING_MODE_DEFAULT directly. - Ok(&Token::Dimension { value, ref unit, .. }) if clamping_mode.is_ok(PARSING_MODE_DEFAULT, value) => { + // ParsingMode::DEFAULT directly. + Ok(&Token::Dimension { value, ref unit, .. }) if clamping_mode.is_ok(ParsingMode::DEFAULT, value) => { return Time::parse_dimension(value, unit, /* from_calc = */ false) .map_err(|()| location.new_custom_error(StyleParseErrorKind::UnspecifiedError)) } @@ -96,7 +96,7 @@ impl Time { Err(e) => return Err(e.into()) } match input.parse_nested_block(|i| CalcNode::parse_time(context, i)) { - Ok(time) if clamping_mode.is_ok(PARSING_MODE_DEFAULT, time.seconds) => Ok(time), + Ok(time) if clamping_mode.is_ok(ParsingMode::DEFAULT, time.seconds) => Ok(time), _ => Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)), } } diff --git a/components/style_traits/Cargo.toml b/components/style_traits/Cargo.toml index 36677df3a43..99c80c1aa58 100644 --- a/components/style_traits/Cargo.toml +++ b/components/style_traits/Cargo.toml @@ -15,8 +15,8 @@ gecko = [] [dependencies] app_units = "0.5" -bitflags = "0.7" cssparser = "0.22.0" +bitflags = "1.0" euclid = "0.15" malloc_size_of = { path = "../malloc_size_of" } malloc_size_of_derive = { path = "../malloc_size_of_derive" } diff --git a/components/style_traits/lib.rs b/components/style_traits/lib.rs index 98940a5411c..e0f1993c5a8 100644 --- a/components/style_traits/lib.rs +++ b/components/style_traits/lib.rs @@ -197,29 +197,29 @@ impl<'i> StyleParseErrorKind<'i> { bitflags! { /// The mode to use when parsing values. - pub flags ParsingMode: u8 { - /// In CSS, lengths must have units, except for zero values, where the unit can be omitted. + pub struct ParsingMode: u8 { + /// In CSS; lengths must have units, except for zero values, where the unit can be omitted. /// <https://www.w3.org/TR/css3-values/#lengths> - const PARSING_MODE_DEFAULT = 0x00, - /// In SVG, a coordinate or length value without a unit identifier (e.g., "25") is assumed + const DEFAULT = 0x00; + /// In SVG; a coordinate or length value without a unit identifier (e.g., "25") is assumed /// to be in user units (px). /// <https://www.w3.org/TR/SVG/coords.html#Units> - const PARSING_MODE_ALLOW_UNITLESS_LENGTH = 0x01, - /// In SVG, out-of-range values are not treated as an error in parsing. + const ALLOW_UNITLESS_LENGTH = 0x01; + /// In SVG; out-of-range values are not treated as an error in parsing. /// <https://www.w3.org/TR/SVG/implnote.html#RangeClamping> - const PARSING_MODE_ALLOW_ALL_NUMERIC_VALUES = 0x02, + const ALLOW_ALL_NUMERIC_VALUES = 0x02; } } impl ParsingMode { /// Whether the parsing mode allows unitless lengths for non-zero values to be intpreted as px. pub fn allows_unitless_lengths(&self) -> bool { - self.intersects(PARSING_MODE_ALLOW_UNITLESS_LENGTH) + self.intersects(ParsingMode::ALLOW_UNITLESS_LENGTH) } /// Whether the parsing mode allows all numeric values. pub fn allows_all_numeric_values(&self) -> bool { - self.intersects(PARSING_MODE_ALLOW_ALL_NUMERIC_VALUES) + self.intersects(ParsingMode::ALLOW_ALL_NUMERIC_VALUES) } } diff --git a/components/style_traits/viewport.rs b/components/style_traits/viewport.rs index 352616d941e..3d422aaef1f 100644 --- a/components/style_traits/viewport.rs +++ b/components/style_traits/viewport.rs @@ -105,7 +105,7 @@ impl Zoom { /// /// <https://drafts.csswg.org/css-device-adapt/#descdef-viewport-zoom> pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Zoom, ParseError<'i>> { - use PARSING_MODE_DEFAULT; + use ParsingMode; use cssparser::Token; use values::specified::AllowedNumericType::NonNegative; @@ -113,12 +113,12 @@ impl Zoom { match *input.next()? { // TODO: This parse() method should take ParserContext as an // argument, and pass ParsingMode owned by the ParserContext to - // is_ok() instead of using PARSING_MODE_DEFAULT directly. + // is_ok() instead of using ParsingMode::DEFAULT directly. // In order to do so, we might want to move these stuff into style::stylesheets::viewport_rule. - Token::Percentage { unit_value, .. } if NonNegative.is_ok(PARSING_MODE_DEFAULT, unit_value) => { + Token::Percentage { unit_value, .. } if NonNegative.is_ok(ParsingMode::DEFAULT, unit_value) => { Ok(Zoom::Percentage(unit_value)) } - Token::Number { value, .. } if NonNegative.is_ok(PARSING_MODE_DEFAULT, value) => { + Token::Number { value, .. } if NonNegative.is_ok(ParsingMode::DEFAULT, value) => { Ok(Zoom::Number(value)) } Token::Ident(ref value) if value.eq_ignore_ascii_case("auto") => { diff --git a/components/webdriver_server/keys.rs b/components/webdriver_server/keys.rs index ce516411c75..b52febc2b5e 100644 --- a/components/webdriver_server/keys.rs +++ b/components/webdriver_server/keys.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use msg::constellation_msg::{Key, KeyState, KeyModifiers, SHIFT}; +use msg::constellation_msg::{Key, KeyState, KeyModifiers}; /// Takes a character and returns an Option containing a tuple of the @@ -174,7 +174,7 @@ pub fn keycodes_to_keys(key_codes: &[char]) -> Result<Vec<(Key, KeyModifiers, Ke for char_code in key_codes.iter() { let (key, with_shift) = key_from_char(char_code).ok_or(format!("Unsupported character code {}", char_code))?; let modifiers = if with_shift { - SHIFT + KeyModifiers::SHIFT } else { KeyModifiers::empty() }; |