From a2c7a9d0fb7174f9188640ba2fb5a3df7821c1a8 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Wed, 2 Nov 2016 18:46:04 -0700 Subject: [PATCH] Stop using associated types for the concrete TRestyleDamage implementation. MozReview-Commit-ID: LfaZFCVlIb1 --- components/layout/animation.rs | 2 +- components/layout/block.rs | 3 +- components/layout/construct.rs | 4 +- components/layout/display_list_builder.rs | 2 +- components/layout/flex.rs | 2 +- components/layout/flow.rs | 4 +- components/layout/fragment.rs | 3 +- components/layout/generated_content.rs | 3 +- components/layout/incremental.rs | 3 +- components/layout/inline.rs | 3 +- components/layout/list_item.rs | 2 +- components/layout/sequential.rs | 2 +- components/layout/table.rs | 2 +- components/layout/table_row.rs | 2 +- components/layout/traversal.rs | 3 +- components/layout_thread/lib.rs | 3 +- components/script/layout_wrapper.rs | 4 +- components/script_layout_interface/lib.rs | 3 +- .../script_layout_interface/wrapper_traits.rs | 3 +- components/style/dom.rs | 7 ++- components/style/gecko/mod.rs | 1 + components/style/gecko/restyle_damage.rs | 53 +++++++++++++++++++ components/style/gecko/wrapper.rs | 45 ++-------------- components/style/lib.rs | 2 +- components/style/matching.rs | 34 +++++------- components/style/selector_impl.rs | 12 +++-- components/style/servo/mod.rs | 6 +++ .../servo}/restyle_damage.rs | 34 ++++++------ .../selector_impl.rs} | 0 29 files changed, 133 insertions(+), 114 deletions(-) create mode 100644 components/style/gecko/restyle_damage.rs create mode 100644 components/style/servo/mod.rs rename components/{script_layout_interface => style/servo}/restyle_damage.rs (93%) rename components/style/{servo_selector_impl.rs => servo/selector_impl.rs} (100%) diff --git a/components/layout/animation.rs b/components/layout/animation.rs index 22387dff5621..9147970f8cf5 100644 --- a/components/layout/animation.rs +++ b/components/layout/animation.rs @@ -9,12 +9,12 @@ use flow::{self, Flow}; use gfx::display_list::OpaqueNode; use ipc_channel::ipc::IpcSender; use msg::constellation_msg::PipelineId; -use script_layout_interface::restyle_damage::RestyleDamage; use script_traits::{AnimationState, ConstellationControlMsg, LayoutMsg as ConstellationMsg}; use std::collections::HashMap; use std::sync::mpsc::Receiver; use style::animation::{Animation, update_style_for_animation}; use style::dom::TRestyleDamage; +use style::selector_impl::RestyleDamage; use style::timer::Timer; /// Processes any new animations that were discovered after style recalculation. diff --git a/components/layout/block.rs b/components/layout/block.rs index 71db966d69c3..1d6ad5a08d9a 100644 --- a/components/layout/block.rs +++ b/components/layout/block.rs @@ -48,8 +48,6 @@ use gfx_traits::print_tree::PrintTree; use layout_debug; use model::{CollapsibleMargins, IntrinsicISizes, MarginCollapseInfo, MaybeAuto}; use model::{specified, specified_or_none}; -use script_layout_interface::restyle_damage::{BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW}; -use script_layout_interface::restyle_damage::REPOSITION; use sequential; use serde::{Serialize, Serializer}; use std::cmp::{max, min}; @@ -60,6 +58,7 @@ use style::computed_values::{position, text_align}; use style::context::{SharedStyleContext, StyleContext}; use style::logical_geometry::{LogicalPoint, LogicalRect, LogicalSize, WritingMode}; use style::properties::ServoComputedValues; +use style::servo::restyle_damage::{BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW, REPOSITION}; use style::values::computed::{LengthOrPercentageOrNone, LengthOrPercentage}; use style::values::computed::LengthOrPercentageOrAuto; use util::clamp; diff --git a/components/layout/construct.rs b/components/layout/construct.rs index 69e3a2d20d26..0b489459352a 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -36,7 +36,6 @@ use list_item::{ListItemFlow, ListStyleTypeContent}; use multicol::{MulticolColumnFlow, MulticolFlow}; use parallel; use script_layout_interface::{LayoutElementType, LayoutNodeType, is_image_data}; -use script_layout_interface::restyle_damage::{BUBBLE_ISIZES, RECONSTRUCT_FLOW, RestyleDamage}; use script_layout_interface::wrapper_traits::{PseudoElementType, ThreadSafeLayoutElement, ThreadSafeLayoutNode}; use std::borrow::ToOwned; use std::collections::LinkedList; @@ -49,8 +48,9 @@ use style::computed_values::content::ContentItem; use style::computed_values::position; use style::context::SharedStyleContext; use style::properties::{self, ServoComputedValues}; +use style::selector_impl::{PseudoElement, RestyleDamage}; use style::selector_matching::Stylist; -use style::servo_selector_impl::PseudoElement; +use style::servo::restyle_damage::{BUBBLE_ISIZES, RECONSTRUCT_FLOW}; use table::TableFlow; use table_caption::TableCaptionFlow; use table_cell::TableCellFlow; diff --git a/components/layout/display_list_builder.rs b/components/layout/display_list_builder.rs index cbecdba41877..e6501e64050a 100644 --- a/components/layout/display_list_builder.rs +++ b/components/layout/display_list_builder.rs @@ -35,7 +35,6 @@ use model::{self, MaybeAuto, ToGfxMatrix}; use net_traits::image::base::PixelFormat; use net_traits::image_cache_thread::UsePlaceholder; use range::Range; -use script_layout_interface::restyle_damage::REPAINT; use std::{cmp, f32}; use std::collections::HashMap; use std::default::Default; @@ -51,6 +50,7 @@ use style::computed_values::text_shadow::TextShadow; use style::logical_geometry::{LogicalPoint, LogicalRect, LogicalSize, WritingMode}; use style::properties::{self, ServoComputedValues}; use style::properties::style_structs; +use style::servo::restyle_damage::REPAINT; use style::values::RGBA; use style::values::computed; use style::values::computed::{Gradient, GradientKind, LengthOrNone, LengthOrPercentage, LengthOrPercentageOrAuto}; diff --git a/components/layout/flex.rs b/components/layout/flex.rs index 0fca93fb5f3f..337abc3227a6 100644 --- a/components/layout/flex.rs +++ b/components/layout/flex.rs @@ -21,7 +21,6 @@ use gfx_traits::ScrollRootId; use layout_debug; use model::{Direction, IntrinsicISizes, MaybeAuto, MinMaxConstraint}; use model::{specified, specified_or_none}; -use script_layout_interface::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW}; use std::cmp::{max, min}; use std::ops::Range; use std::sync::Arc; @@ -30,6 +29,7 @@ use style::computed_values::border_collapse; use style::context::{SharedStyleContext, StyleContext}; use style::logical_geometry::LogicalSize; use style::properties::ServoComputedValues; +use style::servo::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW}; use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto}; use style::values::computed::{LengthOrPercentageOrAutoOrContent, LengthOrPercentageOrNone}; diff --git a/components/layout/flow.rs b/components/layout/flow.rs index 22f64438f918..3da277d924df 100644 --- a/components/layout/flow.rs +++ b/components/layout/flow.rs @@ -41,8 +41,6 @@ use inline::InlineFlow; use model::{CollapsibleMargins, IntrinsicISizes, MarginCollapseInfo}; use multicol::MulticolFlow; use parallel::FlowParallelInfo; -use script_layout_interface::restyle_damage::{RECONSTRUCT_FLOW, REFLOW, REFLOW_OUT_OF_FLOW}; -use script_layout_interface::restyle_damage::{REPAINT, REPOSITION, RestyleDamage}; use serde::{Serialize, Serializer}; use std::{fmt, mem, raw}; use std::iter::Zip; @@ -54,6 +52,8 @@ use style::context::SharedStyleContext; use style::dom::TRestyleDamage; use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode}; use style::properties::ServoComputedValues; +use style::selector_impl::RestyleDamage; +use style::servo::restyle_damage::{RECONSTRUCT_FLOW, REFLOW, REFLOW_OUT_OF_FLOW, REPAINT, REPOSITION}; use style::values::computed::LengthOrPercentageOrAuto; use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize, TableFlow}; use table_caption::TableCaptionFlow; diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index e624ad6013c2..932067829836 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -30,7 +30,6 @@ use net_traits::image_cache_thread::{ImageOrMetadataAvailable, UsePlaceholder}; use range::*; use script_layout_interface::HTMLCanvasData; use script_layout_interface::SVGSVGData; -use script_layout_interface::restyle_damage::{RECONSTRUCT_FLOW, RestyleDamage}; use script_layout_interface::wrapper_traits::{PseudoElementType, ThreadSafeLayoutElement, ThreadSafeLayoutNode}; use serde::{Serialize, Serializer}; use std::borrow::ToOwned; @@ -47,6 +46,8 @@ use style::context::SharedStyleContext; use style::dom::TRestyleDamage; use style::logical_geometry::{LogicalMargin, LogicalRect, LogicalSize, WritingMode}; use style::properties::ServoComputedValues; +use style::selector_impl::RestyleDamage; +use style::servo::restyle_damage::RECONSTRUCT_FLOW; use style::str::char_is_whitespace; use style::values::computed::{LengthOrNone, LengthOrPercentage, LengthOrPercentageOrAuto}; use style::values::computed::LengthOrPercentageOrNone; diff --git a/components/layout/generated_content.rs b/components/layout/generated_content.rs index a4c7f4e06fa5..0d8038a03487 100644 --- a/components/layout/generated_content.rs +++ b/components/layout/generated_content.rs @@ -13,7 +13,6 @@ use flow::{self, AFFECTS_COUNTERS, Flow, HAS_COUNTER_AFFECTING_CHILDREN, Immutab use flow::InorderFlowTraversal; use fragment::{Fragment, GeneratedContentInfo, SpecificFragmentInfo, UnscannedTextFragmentInfo}; use gfx::display_list::OpaqueNode; -use script_layout_interface::restyle_damage::{RESOLVE_GENERATED_CONTENT, RestyleDamage}; use script_layout_interface::wrapper_traits::PseudoElementType; use smallvec::SmallVec; use std::collections::{HashMap, LinkedList}; @@ -22,6 +21,8 @@ use style::computed_values::{display, list_style_type}; use style::computed_values::content::ContentItem; use style::dom::TRestyleDamage; use style::properties::ServoComputedValues; +use style::selector_impl::RestyleDamage; +use style::servo::restyle_damage::RESOLVE_GENERATED_CONTENT; use text::TextRunScanner; // Decimal styles per CSS-COUNTER-STYLES ยง 6.1: diff --git a/components/layout/incremental.rs b/components/layout/incremental.rs index 14644be6ddc4..83c9a5f4ddb2 100644 --- a/components/layout/incremental.rs +++ b/components/layout/incremental.rs @@ -3,9 +3,10 @@ * 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 script_layout_interface::restyle_damage::{RestyleDamage, REFLOW, RECONSTRUCT_FLOW}; use style::computed_values::float; use style::dom::TRestyleDamage; +use style::selector_impl::RestyleDamage; +use style::servo::restyle_damage::{REFLOW, RECONSTRUCT_FLOW}; bitflags! { pub flags SpecialRestyleDamage: u8 { diff --git a/components/layout/inline.rs b/components/layout/inline.rs index 80b8c29eae60..735ee0acf90a 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -24,8 +24,6 @@ use gfx_traits::print_tree::PrintTree; use layout_debug; use model::IntrinsicISizesContribution; use range::{Range, RangeIndex}; -use script_layout_interface::restyle_damage::{BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW}; -use script_layout_interface::restyle_damage::{REPOSITION, RESOLVE_GENERATED_CONTENT}; use script_layout_interface::wrapper_traits::PseudoElementType; use std::{fmt, i32, isize, mem}; use std::cmp::max; @@ -37,6 +35,7 @@ use style::computed_values::{text_overflow, vertical_align, white_space}; use style::context::{SharedStyleContext, StyleContext}; use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode}; use style::properties::ServoComputedValues; +use style::servo::restyle_damage::{BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW, REPOSITION, RESOLVE_GENERATED_CONTENT}; use text; use unicode_bidi; diff --git a/components/layout/list_item.rs b/components/layout/list_item.rs index 2a925acd8837..b3f8df9752dc 100644 --- a/components/layout/list_item.rs +++ b/components/layout/list_item.rs @@ -20,12 +20,12 @@ use generated_content; use gfx::display_list::StackingContext; use gfx_traits::ScrollRootId; use inline::InlineFlow; -use script_layout_interface::restyle_damage::RESOLVE_GENERATED_CONTENT; use std::sync::Arc; use style::computed_values::{list_style_type, position}; use style::context::SharedStyleContext; use style::logical_geometry::LogicalSize; use style::properties::ServoComputedValues; +use style::servo::restyle_damage::RESOLVE_GENERATED_CONTENT; /// A block with the CSS `display` property equal to `list-item`. #[derive(Debug)] diff --git a/components/layout/sequential.rs b/components/layout/sequential.rs index 59819efe4146..716262432065 100644 --- a/components/layout/sequential.rs +++ b/components/layout/sequential.rs @@ -15,8 +15,8 @@ use flow::IS_ABSOLUTELY_POSITIONED; use fragment::FragmentBorderBoxIterator; use generated_content::ResolveGeneratedContent; use gfx_traits::ScrollRootId; -use script_layout_interface::restyle_damage::{REFLOW, STORE_OVERFLOW}; use style::context::StyleContext; +use style::servo::restyle_damage::{REFLOW, STORE_OVERFLOW}; use traversal::{AssignBSizes, AssignISizes, BubbleISizes, BuildDisplayList}; use util::opts; diff --git a/components/layout/table.rs b/components/layout/table.rs index 3ffc5231f5ae..b1f3a01fc229 100644 --- a/components/layout/table.rs +++ b/components/layout/table.rs @@ -21,7 +21,6 @@ use gfx_traits::ScrollRootId; use gfx_traits::print_tree::PrintTree; use layout_debug; use model::{IntrinsicISizes, IntrinsicISizesContribution, MaybeAuto}; -use script_layout_interface::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW}; use std::cmp; use std::fmt; use std::sync::Arc; @@ -29,6 +28,7 @@ use style::computed_values::{border_collapse, border_spacing, table_layout}; use style::context::SharedStyleContext; use style::logical_geometry::LogicalSize; use style::properties::ServoComputedValues; +use style::servo::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW}; use style::values::CSSFloat; use style::values::computed::LengthOrPercentageOrAuto; use table_row::{self, CellIntrinsicInlineSize, CollapsedBorder, CollapsedBorderProvenance}; diff --git a/components/layout/table_row.rs b/components/layout/table_row.rs index 1b4df7b7bfc4..3a39b4c1ce1c 100644 --- a/components/layout/table_row.rs +++ b/components/layout/table_row.rs @@ -20,7 +20,6 @@ use gfx_traits::ScrollRootId; use gfx_traits::print_tree::PrintTree; use layout_debug; use model::MaybeAuto; -use script_layout_interface::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW}; use serde::{Serialize, Serializer}; use std::cmp::max; use std::fmt; @@ -30,6 +29,7 @@ use style::computed_values::{border_collapse, border_spacing, border_top_style}; use style::context::SharedStyleContext; use style::logical_geometry::{LogicalSize, PhysicalSide, WritingMode}; use style::properties::ServoComputedValues; +use style::servo::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW}; use style::values::computed::LengthOrPercentageOrAuto; use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize, InternalTable, VecExt}; use table_cell::{CollapsedBordersForCell, TableCellFlow}; diff --git a/components/layout/traversal.rs b/components/layout/traversal.rs index c897838875a8..3124bca1dfcc 100644 --- a/components/layout/traversal.rs +++ b/components/layout/traversal.rs @@ -10,13 +10,14 @@ use display_list_builder::DisplayListBuildState; use flow::{self, PreorderFlowTraversal}; use flow::{CAN_BE_FRAGMENTED, Flow, ImmutableFlowUtils, PostorderFlowTraversal}; use gfx::display_list::OpaqueNode; -use script_layout_interface::restyle_damage::{BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW, REPAINT, RestyleDamage}; use script_layout_interface::wrapper_traits::{LayoutElement, LayoutNode, ThreadSafeLayoutNode}; use std::mem; use style::atomic_refcell::AtomicRefCell; use style::context::{LocalStyleContext, SharedStyleContext, StyleContext}; use style::data::ElementData; use style::dom::{StylingMode, TElement, TNode}; +use style::selector_impl::RestyleDamage; +use style::servo::restyle_damage::{BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW, REPAINT}; use style::traversal::{DomTraversalContext, put_thread_local_bloom_filter}; use style::traversal::{recalc_style_at, remove_from_bloom_filter}; use style::traversal::take_thread_local_bloom_filter; diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index 60956b00150f..6d4f45ef99ef 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -87,8 +87,6 @@ use profile_traits::time::{TimerMetadataFrameType, TimerMetadataReflowType}; use script::layout_wrapper::{ServoLayoutDocument, ServoLayoutNode}; use script_layout_interface::message::{Msg, NewLayoutThreadInfo, Reflow, ReflowQueryType, ScriptReflow}; use script_layout_interface::reporter::CSSErrorReporter; -use script_layout_interface::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW, REPAINT, REPOSITION}; -use script_layout_interface::restyle_damage::STORE_OVERFLOW; use script_layout_interface::rpc::{LayoutRPC, MarginStyleResponse, NodeOverflowResponse, OffsetParentResponse}; use script_layout_interface::wrapper_traits::LayoutNode; use script_traits::{ConstellationControlMsg, LayoutControlMsg, LayoutMsg as ConstellationMsg}; @@ -111,6 +109,7 @@ use style::media_queries::{Device, MediaType}; use style::parallel::WorkQueueData; use style::parser::ParserContextExtraData; use style::selector_matching::Stylist; +use style::servo::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW, REPAINT, REPOSITION, STORE_OVERFLOW}; use style::stylesheets::{Origin, Stylesheet, UserAgentStylesheets}; use style::thread_state; use style::timer::Timer; diff --git a/components/script/layout_wrapper.rs b/components/script/layout_wrapper.rs index 9c4d72537821..00c7ce1413c5 100644 --- a/components/script/layout_wrapper.rs +++ b/components/script/layout_wrapper.rs @@ -46,7 +46,6 @@ use parking_lot::RwLock; use range::Range; use script_layout_interface::{HTMLCanvasData, LayoutNodeType, SVGSVGData, TrustedNodeAddress}; use script_layout_interface::{OpaqueStyleAndLayoutData, PartialPersistentLayoutData}; -use script_layout_interface::restyle_damage::RestyleDamage; use script_layout_interface::wrapper_traits::{DangerousThreadSafeLayoutNode, GetLayoutData, LayoutElement, LayoutNode}; use script_layout_interface::wrapper_traits::{PseudoElementType, ThreadSafeLayoutElement, ThreadSafeLayoutNode}; use selectors::matching::ElementFlags; @@ -66,7 +65,7 @@ use style::dom::{LayoutIterator, NodeInfo, OpaqueNode, PresentationalHintsSynthe use style::dom::{TRestyleDamage, UnsafeNode}; use style::element_state::*; use style::properties::{ComputedValues, PropertyDeclarationBlock}; -use style::selector_impl::{NonTSPseudoClass, PseudoElement, ServoSelectorImpl, Snapshot}; +use style::selector_impl::{NonTSPseudoClass, PseudoElement, RestyleDamage, ServoSelectorImpl, Snapshot}; use style::selector_matching::ApplicableDeclarationBlock; use style::sink::Push; use style::str::is_whitespace; @@ -435,7 +434,6 @@ impl<'le> PresentationalHintsSynthetizer for ServoLayoutElement<'le> { impl<'le> TElement for ServoLayoutElement<'le> { type ConcreteNode = ServoLayoutNode<'le>; type ConcreteDocument = ServoLayoutDocument<'le>; - type ConcreteRestyleDamage = RestyleDamage; fn as_node(&self) -> ServoLayoutNode<'le> { ServoLayoutNode::from_layout_js(self.element.upcast()) diff --git a/components/script_layout_interface/lib.rs b/components/script_layout_interface/lib.rs index b442e502b2b9..284f6f33498e 100644 --- a/components/script_layout_interface/lib.rs +++ b/components/script_layout_interface/lib.rs @@ -41,7 +41,6 @@ extern crate url; pub mod message; pub mod reporter; -pub mod restyle_damage; pub mod rpc; pub mod wrapper_traits; @@ -49,10 +48,10 @@ use canvas_traits::CanvasMsg; use core::nonzero::NonZero; use ipc_channel::ipc::IpcSender; use libc::c_void; -use restyle_damage::RestyleDamage; use std::sync::atomic::AtomicIsize; use style::atomic_refcell::AtomicRefCell; use style::data::ElementData; +use style::selector_impl::RestyleDamage; pub struct PartialPersistentLayoutData { /// Data that the style system associates with a node. When the diff --git a/components/script_layout_interface/wrapper_traits.rs b/components/script_layout_interface/wrapper_traits.rs index 7bd91bdb0d04..9123c0c1f452 100644 --- a/components/script_layout_interface/wrapper_traits.rs +++ b/components/script_layout_interface/wrapper_traits.rs @@ -12,7 +12,6 @@ use gfx_traits::ByteIndex; use html5ever_atoms::{Namespace, LocalName}; use msg::constellation_msg::PipelineId; use range::Range; -use restyle_damage::RestyleDamage; use std::fmt::Debug; use std::sync::Arc; use style::atomic_refcell::AtomicRefCell; @@ -22,7 +21,7 @@ use style::data::ElementData; use style::dom::{LayoutIterator, NodeInfo, PresentationalHintsSynthetizer, TElement, TNode}; use style::dom::OpaqueNode; use style::properties::ServoComputedValues; -use style::selector_impl::{PseudoElement, PseudoElementCascadeType, ServoSelectorImpl}; +use style::selector_impl::{PseudoElement, PseudoElementCascadeType, RestyleDamage, ServoSelectorImpl}; use url::Url; #[derive(Copy, PartialEq, Clone, Debug)] diff --git a/components/style/dom.rs b/components/style/dom.rs index 493a38bdc591..388a7310ab06 100644 --- a/components/style/dom.rs +++ b/components/style/dom.rs @@ -14,7 +14,7 @@ use parking_lot::RwLock; use properties::{ComputedValues, PropertyDeclarationBlock}; use properties::longhands::display::computed_value as display; use restyle_hints::{RESTYLE_DESCENDANTS, RESTYLE_LATER_SIBLINGS, RESTYLE_SELF, RestyleHint}; -use selector_impl::{ElementExt, PseudoElement, Snapshot}; +use selector_impl::{ElementExt, PseudoElement, RestyleDamage, Snapshot}; use selector_matching::ApplicableDeclarationBlock; use sink::Push; use std::fmt::Debug; @@ -173,7 +173,6 @@ pub trait PresentationalHintsSynthetizer { pub trait TElement : PartialEq + Debug + Sized + Copy + Clone + ElementExt + PresentationalHintsSynthetizer { type ConcreteNode: TNode; type ConcreteDocument: TDocument; - type ConcreteRestyleDamage: TRestyleDamage; fn as_node(&self) -> Self::ConcreteNode; @@ -185,7 +184,7 @@ pub trait TElement : PartialEq + Debug + Sized + Copy + Clone + ElementExt + Pre fn attr_equals(&self, namespace: &Namespace, attr: &LocalName, value: &Atom) -> bool; /// Set the restyle damage field. - fn set_restyle_damage(self, damage: Self::ConcreteRestyleDamage); + fn set_restyle_damage(self, damage: RestyleDamage); /// XXX: It's a bit unfortunate we need to pass the current computed values /// as an argument here, but otherwise Servo would crash due to double @@ -193,7 +192,7 @@ pub trait TElement : PartialEq + Debug + Sized + Copy + Clone + ElementExt + Pre fn existing_style_for_restyle_damage<'a>(&'a self, current_computed_values: Option<&'a Arc>, pseudo: Option<&PseudoElement>) - -> Option<&'a ::PreExistingComputedValues>; + -> Option<&'a ::PreExistingComputedValues>; /// The concept of a dirty bit doesn't exist in our new restyle algorithm. /// Instead, we associate restyle and change hints with nodes. However, we diff --git a/components/style/gecko/mod.rs b/components/style/gecko/mod.rs index 7153a7e3da27..ee462ef4b81e 100644 --- a/components/style/gecko/mod.rs +++ b/components/style/gecko/mod.rs @@ -5,6 +5,7 @@ pub mod context; pub mod data; +pub mod restyle_damage; pub mod snapshot; pub mod snapshot_helpers; pub mod traversal; diff --git a/components/style/gecko/restyle_damage.rs b/components/style/gecko/restyle_damage.rs new file mode 100644 index 000000000000..ed23bb150623 --- /dev/null +++ b/components/style/gecko/restyle_damage.rs @@ -0,0 +1,53 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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 dom::TRestyleDamage; +use gecko_bindings::bindings; +use gecko_bindings::structs::{nsChangeHint, nsStyleContext}; +use gecko_bindings::sugar::ownership::FFIArcHelpers; +use properties::ComputedValues; +use std::ops::BitOr; +use std::sync::Arc; + +#[derive(Clone, Copy, Debug, PartialEq)] +pub struct GeckoRestyleDamage(nsChangeHint); + +impl GeckoRestyleDamage { + pub fn as_change_hint(&self) -> nsChangeHint { + self.0 + } +} + +impl TRestyleDamage for GeckoRestyleDamage { + type PreExistingComputedValues = nsStyleContext; + + fn empty() -> Self { + use std::mem; + GeckoRestyleDamage(unsafe { mem::transmute(0u32) }) + } + + fn compute(source: &nsStyleContext, + new_style: &Arc) -> Self { + let context = source as *const nsStyleContext as *mut nsStyleContext; + let hint = unsafe { + bindings::Gecko_CalcStyleDifference(context, + new_style.as_borrowed_opt().unwrap()) + }; + GeckoRestyleDamage(hint) + } + + fn rebuild_and_reflow() -> Self { + GeckoRestyleDamage(nsChangeHint::nsChangeHint_ReconstructFrame) + } +} + +impl BitOr for GeckoRestyleDamage { + type Output = Self; + + fn bitor(self, other: Self) -> Self { + use std::mem; + GeckoRestyleDamage(unsafe { mem::transmute(self.0 as u32 | other.0 as u32) }) + } +} + diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index 4da1e1af4f94..9adac5f269fd 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -7,15 +7,15 @@ use atomic_refcell::{AtomicRef, AtomicRefCell}; use data::ElementData; -use dom::{LayoutIterator, NodeInfo, TDocument, TElement, TNode, TRestyleDamage, UnsafeNode}; +use dom::{LayoutIterator, NodeInfo, TDocument, TElement, TNode, UnsafeNode}; use dom::{OpaqueNode, PresentationalHintsSynthetizer}; use element_state::ElementState; use error_reporting::StdoutErrorReporter; +use gecko::restyle_damage::GeckoRestyleDamage; use gecko::selector_impl::{GeckoSelectorImpl, NonTSPseudoClass, PseudoElement}; use gecko::snapshot::GeckoElementSnapshot; use gecko::snapshot_helpers; use gecko_bindings::bindings; -use gecko_bindings::bindings::{Gecko_CalcStyleDifference, Gecko_StoreStyleDifference}; use gecko_bindings::bindings::{Gecko_DropStyleChildrenIterator, Gecko_MaybeCreateStyleChildrenIterator}; use gecko_bindings::bindings::{Gecko_ElementState, Gecko_GetDocumentElement}; use gecko_bindings::bindings::{Gecko_GetLastChild, Gecko_GetNextStyleChild}; @@ -26,10 +26,10 @@ use gecko_bindings::bindings::{RawGeckoDocument, RawGeckoElement, RawGeckoNode}; use gecko_bindings::bindings::Gecko_ClassOrClassList; use gecko_bindings::bindings::Gecko_GetStyleContext; use gecko_bindings::bindings::Gecko_SetNodeFlags; +use gecko_bindings::bindings::Gecko_StoreStyleDifference; use gecko_bindings::structs; use gecko_bindings::structs::{NODE_HAS_DIRTY_DESCENDANTS_FOR_SERVO, NODE_IS_DIRTY_FOR_SERVO}; -use gecko_bindings::structs::{nsChangeHint, nsIAtom, nsIContent, nsStyleContext}; -use gecko_bindings::sugar::ownership::FFIArcHelpers; +use gecko_bindings::structs::{nsIAtom, nsIContent, nsStyleContext}; use libc::uintptr_t; use parking_lot::RwLock; use parser::ParserContextExtraData; @@ -41,7 +41,6 @@ use selectors::Element; use selectors::parser::{AttrSelector, NamespaceConstraint}; use sink::Push; use std::fmt; -use std::ops::BitOr; use std::ptr; use std::sync::Arc; use string_cache::{Atom, Namespace, WeakAtom, WeakNamespace}; @@ -66,39 +65,6 @@ impl<'ln> GeckoNode<'ln> { } } -#[derive(Clone, Copy, Debug, PartialEq)] -pub struct GeckoRestyleDamage(nsChangeHint); - -impl TRestyleDamage for GeckoRestyleDamage { - type PreExistingComputedValues = nsStyleContext; - - fn empty() -> Self { - use std::mem; - GeckoRestyleDamage(unsafe { mem::transmute(0u32) }) - } - - fn compute(source: &nsStyleContext, - new_style: &Arc) -> Self { - let context = source as *const nsStyleContext as *mut nsStyleContext; - let hint = unsafe { Gecko_CalcStyleDifference(context, new_style.as_borrowed_opt().unwrap()) }; - GeckoRestyleDamage(hint) - } - - fn rebuild_and_reflow() -> Self { - GeckoRestyleDamage(nsChangeHint::nsChangeHint_ReconstructFrame) - } -} - -impl BitOr for GeckoRestyleDamage { - type Output = Self; - - fn bitor(self, other: Self) -> Self { - use std::mem; - GeckoRestyleDamage(unsafe { mem::transmute(self.0 as u32 | other.0 as u32) }) - } -} - - impl<'ln> NodeInfo for GeckoNode<'ln> { fn is_element(&self) -> bool { use gecko_bindings::structs::nsINode_BooleanFlag; @@ -358,7 +324,6 @@ lazy_static! { impl<'le> TElement for GeckoElement<'le> { type ConcreteNode = GeckoNode<'le>; type ConcreteDocument = GeckoDocument<'le>; - type ConcreteRestyleDamage = GeckoRestyleDamage; fn as_node(&self) -> Self::ConcreteNode { unsafe { GeckoNode(&*(self.0 as *const _ as *const RawGeckoNode)) } @@ -400,7 +365,7 @@ impl<'le> TElement for GeckoElement<'le> { // drive the post-traversal. This will go away soon. unsafe { self.set_flags(NODE_IS_DIRTY_FOR_SERVO as u32) } - unsafe { Gecko_StoreStyleDifference(self.as_node().0, damage.0) } + unsafe { Gecko_StoreStyleDifference(self.as_node().0, damage.as_change_hint()) } } fn existing_style_for_restyle_damage<'a>(&'a self, diff --git a/components/style/lib.rs b/components/style/lib.rs index c6010def3743..d7312bbb904d 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -117,8 +117,8 @@ pub mod restyle_hints; pub mod rule_tree; pub mod selector_impl; pub mod selector_matching; +#[cfg(feature = "servo")] #[allow(unsafe_code)] pub mod servo; pub mod sequential; -#[cfg(feature = "servo")] pub mod servo_selector_impl; pub mod sink; pub mod str; pub mod stylesheets; diff --git a/components/style/matching.rs b/components/style/matching.rs index ac4bdb0b59a8..97faf4d0a6aa 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -17,7 +17,7 @@ use dom::{TElement, TNode, TRestyleDamage, UnsafeNode}; use properties::{CascadeFlags, ComputedValues, SHAREABLE, cascade}; use properties::longhands::display::computed_value as display; use rule_tree::StrongRuleNode; -use selector_impl::{TheSelectorImpl, PseudoElement}; +use selector_impl::{PseudoElement, RestyleDamage, TheSelectorImpl}; use selector_matching::{ApplicableDeclarationBlock, Stylist}; use selectors::MatchAttr; use selectors::bloom::BloomFilter; @@ -373,14 +373,14 @@ impl StyleSharingCandidateCache { } /// The results of attempting to share a style. -pub enum StyleSharingResult { +pub enum StyleSharingResult { /// We didn't find anybody to share the style with. CannotShare, /// The node's style can be shared. The integer specifies the index in the /// LRU cache that was hit and the damage that was done, and the restyle /// result the original result of the candidate's styling, that is, whether /// it should stop the traversal or not. - StyleWasShared(usize, ConcreteRestyleDamage), + StyleWasShared(usize, RestyleDamage), } // Callers need to pass several boolean flags to cascade_node_pseudo_element. @@ -565,7 +565,7 @@ pub trait MatchMethods : TElement { &mut StyleSharingCandidateCache, shared_context: &SharedStyleContext, data: &mut AtomicRefMut) - -> StyleSharingResult { + -> StyleSharingResult { if opts::get().disable_share_style_cache { return StyleSharingResult::CannotShare } @@ -591,12 +591,8 @@ pub trait MatchMethods : TElement { // replaced content, or similar stuff! let damage = match self.existing_style_for_restyle_damage(data.previous_styles().map(|x| &x.primary), None) { - Some(ref source) => { - Self::ConcreteRestyleDamage::compute(source, &shared_style) - } - None => { - Self::ConcreteRestyleDamage::rebuild_and_reflow() - } + Some(ref source) => RestyleDamage::compute(source, &shared_style), + None => RestyleDamage::rebuild_and_reflow(), }; data.finish_styling(ElementStyles::new(shared_style, rule_node)); @@ -678,13 +674,10 @@ pub trait MatchMethods : TElement { old_style: Option<&Arc>, new_style: &Arc, pseudo: Option<&PseudoElement>) - -> Self::ConcreteRestyleDamage + -> RestyleDamage { match self.existing_style_for_restyle_damage(old_style, pseudo) { - Some(ref source) => { - Self::ConcreteRestyleDamage::compute(source, - new_style) - } + Some(ref source) => RestyleDamage::compute(source, new_style), None => { // If there's no style source, two things can happen: // @@ -710,7 +703,7 @@ pub trait MatchMethods : TElement { // stick without the assertions. debug_assert!(pseudo.is_none() || new_style.get_box().clone_display() != display::T::none); - Self::ConcreteRestyleDamage::rebuild_and_reflow() + RestyleDamage::rebuild_and_reflow() } } } @@ -783,7 +776,7 @@ pub trait MatchMethods : TElement { new_pseudos: &mut PseudoStyles, context: &Ctx, applicable_declarations: &mut ApplicableDeclarations) - -> Self::ConcreteRestyleDamage + -> RestyleDamage where Ctx: StyleContext<'a> { // Here we optimise the case of the style changing but both the @@ -800,9 +793,9 @@ pub trait MatchMethods : TElement { // otherwise, we don't do anything. let damage = match old_display { Some(display) if display == this_display => { - Self::ConcreteRestyleDamage::empty() + RestyleDamage::empty() } - _ => Self::ConcreteRestyleDamage::rebuild_and_reflow() + _ => RestyleDamage::rebuild_and_reflow() }; debug!("Short-circuiting traversal: {:?} {:?} {:?}", @@ -820,8 +813,7 @@ pub trait MatchMethods : TElement { return damage; } - let rebuild_and_reflow = - Self::ConcreteRestyleDamage::rebuild_and_reflow(); + let rebuild_and_reflow = RestyleDamage::rebuild_and_reflow(); debug_assert!(new_pseudos.is_empty()); ::Impl::each_eagerly_cascaded_pseudo_element(|pseudo| { diff --git a/components/style/selector_impl.rs b/components/style/selector_impl.rs index d4a7f2645b47..85734d513873 100644 --- a/components/style/selector_impl.rs +++ b/components/style/selector_impl.rs @@ -11,23 +11,29 @@ use selectors::parser::{AttrSelector, SelectorImpl}; pub type AttrValue = ::AttrValue; #[cfg(feature = "servo")] -pub use servo_selector_impl::*; +pub use servo::selector_impl::*; #[cfg(feature = "gecko")] pub use gecko::selector_impl::*; #[cfg(feature = "servo")] -pub use servo_selector_impl::ServoSelectorImpl as TheSelectorImpl; +pub use servo::selector_impl::ServoSelectorImpl as TheSelectorImpl; #[cfg(feature = "gecko")] pub use gecko::selector_impl::GeckoSelectorImpl as TheSelectorImpl; #[cfg(feature = "servo")] -pub use servo_selector_impl::ServoElementSnapshot as Snapshot; +pub use servo::selector_impl::ServoElementSnapshot as Snapshot; #[cfg(feature = "gecko")] pub use gecko::snapshot::GeckoElementSnapshot as Snapshot; +#[cfg(feature = "servo")] +pub use servo::restyle_damage::ServoRestyleDamage as RestyleDamage; + +#[cfg(feature = "gecko")] +pub use gecko::restyle_damage::GeckoRestyleDamage as RestyleDamage; + /// This function determines if a pseudo-element is eagerly cascaded or not. /// /// Eagerly cascaded pseudo-elements are "normal" pseudo-elements (i.e. diff --git a/components/style/servo/mod.rs b/components/style/servo/mod.rs new file mode 100644 index 000000000000..bd3db996effe --- /dev/null +++ b/components/style/servo/mod.rs @@ -0,0 +1,6 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + +pub mod restyle_damage; +pub mod selector_impl; diff --git a/components/script_layout_interface/restyle_damage.rs b/components/style/servo/restyle_damage.rs similarity index 93% rename from components/script_layout_interface/restyle_damage.rs rename to components/style/servo/restyle_damage.rs index ff0e26af03f4..08dd549b288f 100644 --- a/components/script_layout_interface/restyle_damage.rs +++ b/components/style/servo/restyle_damage.rs @@ -2,15 +2,15 @@ * 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 computed_values::display; +use dom::TRestyleDamage; +use properties::ServoComputedValues; use std::fmt; use std::sync::Arc; -use style::computed_values::display; -use style::dom::TRestyleDamage; -use style::properties::ServoComputedValues; bitflags! { #[doc = "Individual layout actions that may be necessary after restyling."] - pub flags RestyleDamage: u8 { + pub flags ServoRestyleDamage: u8 { #[doc = "Repaint the node itself."] #[doc = "Currently unused; need to decide how this propagates."] const REPAINT = 0x01, @@ -48,35 +48,35 @@ bitflags! { } } -impl TRestyleDamage for RestyleDamage { +impl TRestyleDamage for ServoRestyleDamage { /// For Servo the style source is always the computed values. type PreExistingComputedValues = Arc; fn empty() -> Self { - RestyleDamage::empty() + ServoRestyleDamage::empty() } fn compute(old: &Arc, - new: &Arc) -> RestyleDamage { + new: &Arc) -> ServoRestyleDamage { compute_damage(old, new) } /// Returns a bitmask that represents a flow that needs to be rebuilt and /// reflowed. /// - /// Use this instead of `RestyleDamage::all()` because - /// `RestyleDamage::all()` will result in unnecessary sequential resolution + /// Use this instead of `ServoRestyleDamage::all()` because + /// `ServoRestyleDamage::all()` will result in unnecessary sequential resolution /// of generated content. - fn rebuild_and_reflow() -> RestyleDamage { + fn rebuild_and_reflow() -> ServoRestyleDamage { REPAINT | REPOSITION | STORE_OVERFLOW | BUBBLE_ISIZES | REFLOW_OUT_OF_FLOW | REFLOW | RECONSTRUCT_FLOW } } -impl RestyleDamage { +impl ServoRestyleDamage { /// 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) -> RestyleDamage { + 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) @@ -91,7 +91,7 @@ impl RestyleDamage { pub fn damage_for_child(self, parent_is_absolutely_positioned: bool, child_is_absolutely_positioned: bool) - -> RestyleDamage { + -> ServoRestyleDamage { match (parent_is_absolutely_positioned, child_is_absolutely_positioned) { (false, true) => { // Absolute children are out-of-flow and therefore insulated from changes. @@ -116,7 +116,7 @@ impl RestyleDamage { } } -impl fmt::Display for RestyleDamage { +impl fmt::Display for ServoRestyleDamage { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { let mut first_elem = true; @@ -162,8 +162,8 @@ macro_rules! add_if_not_equal( }) ); -fn compute_damage(old: &ServoComputedValues, new: &ServoComputedValues) -> RestyleDamage { - let mut damage = RestyleDamage::empty(); +fn compute_damage(old: &ServoComputedValues, new: &ServoComputedValues) -> ServoRestyleDamage { + let mut damage = ServoRestyleDamage::empty(); // This should check every CSS property, as enumerated in the fields of // http://doc.servo.org/style/properties/struct.ServoComputedValues.html @@ -260,7 +260,7 @@ fn compute_damage(old: &ServoComputedValues, new: &ServoComputedValues) -> Resty // If the layer requirements of this flow have changed due to the value // of the transform, then reflow is required to rebuild the layers. if old.transform_requires_layer() != new.transform_requires_layer() { - damage.insert(RestyleDamage::rebuild_and_reflow()); + damage.insert(ServoRestyleDamage::rebuild_and_reflow()); } damage diff --git a/components/style/servo_selector_impl.rs b/components/style/servo/selector_impl.rs similarity index 100% rename from components/style/servo_selector_impl.rs rename to components/style/servo/selector_impl.rs