1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 use atomic_refcell::AtomicRefCell; 6 use construct::ConstructionResult; 7 use script_layout_interface::StyleData; 8 9 #[repr(C)] 10 pub struct StyleAndLayoutData { 11 /// Data accessed by script_layout_interface. This must be first to allow 12 /// casting between StyleAndLayoutData and StyleData. 13 pub style_data: StyleData, 14 /// The layout data associated with a node. 15 pub layout_data: AtomicRefCell<LayoutData>, 16 } 17 18 impl StyleAndLayoutData { new() -> Self19 pub fn new() -> Self { 20 Self { 21 style_data: StyleData::new(), 22 layout_data: AtomicRefCell::new(LayoutData::new()), 23 } 24 } 25 } 26 27 28 /// Data that layout associates with a node. 29 #[repr(C)] 30 pub struct LayoutData { 31 /// The current results of flow construction for this node. This is either a 32 /// flow or a `ConstructionItem`. See comments in `construct.rs` for more 33 /// details. 34 pub flow_construction_result: ConstructionResult, 35 36 pub before_flow_construction_result: ConstructionResult, 37 38 pub after_flow_construction_result: ConstructionResult, 39 40 pub details_summary_flow_construction_result: ConstructionResult, 41 42 pub details_content_flow_construction_result: ConstructionResult, 43 44 /// Various flags. 45 pub flags: LayoutDataFlags, 46 } 47 48 impl LayoutData { 49 /// Creates new layout data. new() -> LayoutData50 pub fn new() -> LayoutData { 51 Self { 52 flow_construction_result: ConstructionResult::None, 53 before_flow_construction_result: ConstructionResult::None, 54 after_flow_construction_result: ConstructionResult::None, 55 details_summary_flow_construction_result: ConstructionResult::None, 56 details_content_flow_construction_result: ConstructionResult::None, 57 flags: LayoutDataFlags::empty(), 58 } 59 } 60 } 61 62 bitflags! { 63 pub struct LayoutDataFlags: u8 { 64 #[doc = "Whether a flow has been newly constructed."] 65 const HAS_NEWLY_CONSTRUCTED_FLOW = 0x01; 66 #[doc = "Whether this node has been traversed by layout."] 67 const HAS_BEEN_TRAVERSED = 0x02; 68 } 69 } 70