diff options
author | Ms2ger <ms2ger@gmail.com> | 2015-07-27 16:40:23 +0200 |
---|---|---|
committer | Ms2ger <ms2ger@gmail.com> | 2015-07-27 19:57:33 +0200 |
commit | 3984e3901130a629293361c5eb8366e00b824a2f (patch) | |
tree | 9d488ca46e5331287a1ceb93e170a36d57931c8f | |
parent | 5cf662fb9759924e75d3bfe77f1b7607e9961bcb (diff) | |
download | servo-3984e3901130a629293361c5eb8366e00b824a2f.tar.gz servo-3984e3901130a629293361c5eb8366e00b824a2f.zip |
Replace the StyledNode trait with inherent methods.
-rw-r--r-- | components/layout/block.rs | 1 | ||||
-rw-r--r-- | components/layout/construct.rs | 1 | ||||
-rw-r--r-- | components/layout/css/matching.rs | 1 | ||||
-rw-r--r-- | components/layout/css/node_style.rs | 56 | ||||
-rw-r--r-- | components/layout/flow.rs | 1 | ||||
-rw-r--r-- | components/layout/fragment.rs | 1 | ||||
-rw-r--r-- | components/layout/inline.rs | 1 | ||||
-rw-r--r-- | components/layout/layout_task.rs | 1 | ||||
-rw-r--r-- | components/layout/lib.rs | 1 | ||||
-rw-r--r-- | components/layout/table_cell.rs | 1 | ||||
-rw-r--r-- | components/layout/table_colgroup.rs | 1 | ||||
-rw-r--r-- | components/layout/traversal.rs | 1 | ||||
-rw-r--r-- | components/layout/wrapper.rs | 37 |
13 files changed, 36 insertions, 68 deletions
diff --git a/components/layout/block.rs b/components/layout/block.rs index 0e8990702c3..91166c6cdc2 100644 --- a/components/layout/block.rs +++ b/components/layout/block.rs @@ -28,7 +28,6 @@ #![deny(unsafe_code)] use context::LayoutContext; -use css::node_style::StyledNode; use display_list_builder::{BlockFlowDisplayListBuilding, BorderPaintingMode}; use display_list_builder::{FragmentDisplayListBuilding}; use floats::{ClearType, FloatKind, Floats, PlacementInfo}; diff --git a/components/layout/construct.rs b/components/layout/construct.rs index aad12f4e770..8d6983d5e95 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -15,7 +15,6 @@ use block::BlockFlow; use context::LayoutContext; -use css::node_style::StyledNode; use data::{HAS_NEWLY_CONSTRUCTED_FLOW, LayoutDataWrapper}; use floats::FloatKind; use flow::{Descendants, AbsDescendants}; diff --git a/components/layout/css/matching.rs b/components/layout/css/matching.rs index 1cf48d3b9cc..1d147dcdbdd 100644 --- a/components/layout/css/matching.rs +++ b/components/layout/css/matching.rs @@ -8,7 +8,6 @@ use animation; use context::SharedLayoutContext; -use css::node_style::StyledNode; use data::LayoutDataWrapper; use incremental::{self, RestyleDamage}; use smallvec::SmallVec; diff --git a/components/layout/css/node_style.rs b/components/layout/css/node_style.rs deleted file mode 100644 index 72afd0c6193..00000000000 --- a/components/layout/css/node_style.rs +++ /dev/null @@ -1,56 +0,0 @@ -/* 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/. */ - -//! Style retrieval from DOM elements. - -use data::LayoutDataWrapper; -use wrapper::{PseudoElementType, ThreadSafeLayoutNode}; - -use style::properties::ComputedValues; - -use std::cell::Ref; -use std::sync::Arc; - -/// Node mixin providing `style` method that returns a `NodeStyle` -pub trait StyledNode { - fn get_style<'a>(&self, layout_data_ref: &'a LayoutDataWrapper) -> &'a Arc<ComputedValues>; - /// Returns the style results for the given node. If CSS selector matching has not yet been - /// performed, fails. - fn style<'a>(&'a self) -> Ref<'a, Arc<ComputedValues>>; - /// Removes the style from this node. - fn unstyle(self); -} - -impl<'ln> StyledNode for ThreadSafeLayoutNode<'ln> { - #[inline] - fn get_style<'a>(&self, layout_data_ref: &'a LayoutDataWrapper) -> &'a Arc<ComputedValues> { - match self.get_pseudo_element_type() { - PseudoElementType::Before(_) => layout_data_ref.data.before_style.as_ref().unwrap(), - PseudoElementType::After(_) => layout_data_ref.data.after_style.as_ref().unwrap(), - PseudoElementType::Normal => layout_data_ref.shared_data.style.as_ref().unwrap(), - } - } - - #[inline] - fn style<'a>(&'a self) -> Ref<'a, Arc<ComputedValues>> { - Ref::map(self.borrow_layout_data(), |layout_data_ref| { - let layout_data = layout_data_ref.as_ref().expect("no layout data"); - self.get_style(layout_data) - }) - } - - fn unstyle(self) { - let mut layout_data_ref = self.mutate_layout_data(); - let layout_data = layout_data_ref.as_mut().expect("no layout data"); - - let style = - match self.get_pseudo_element_type() { - PseudoElementType::Before(_) => &mut layout_data.data.before_style, - PseudoElementType::After (_) => &mut layout_data.data.after_style, - PseudoElementType::Normal => &mut layout_data.shared_data.style, - }; - - *style = None; - } -} diff --git a/components/layout/flow.rs b/components/layout/flow.rs index 5227f97dc43..90835cfac31 100644 --- a/components/layout/flow.rs +++ b/components/layout/flow.rs @@ -25,7 +25,6 @@ /// line breaks and mapping to CSS boxes, for the purpose of handling `getClientRects()` and /// similar methods. -use css::node_style::StyledNode; use block::BlockFlow; use context::LayoutContext; use display_list_builder::DisplayListBuildingResult; diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index 9b9aad64ee3..edc4e0fb66a 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -7,7 +7,6 @@ #![deny(unsafe_code)] use canvas_traits::CanvasMsg; -use css::node_style::StyledNode; use context::LayoutContext; use floats::ClearType; use flow; diff --git a/components/layout/inline.rs b/components/layout/inline.rs index e616ba02f9c..bc5e432a82e 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -5,7 +5,6 @@ #![deny(unsafe_code)] use block::{AbsoluteAssignBSizesTraversal, AbsoluteStoreOverflowTraversal}; -use css::node_style::StyledNode; use context::LayoutContext; use display_list_builder::{FragmentDisplayListBuilding, InlineFlowDisplayListBuilding}; use floats::{FloatKind, Floats, PlacementInfo}; diff --git a/components/layout/layout_task.rs b/components/layout/layout_task.rs index 7d0df0fc5e6..4a45cc4b22e 100644 --- a/components/layout/layout_task.rs +++ b/components/layout/layout_task.rs @@ -10,7 +10,6 @@ use animation; use construct::ConstructionResult; use context::{SharedLayoutContext, heap_size_of_local_context}; -use css::node_style::StyledNode; use data::LayoutDataWrapper; use display_list_builder::ToGfxColor; use flow::{self, Flow, ImmutableFlowUtils, MutableFlowUtils, MutableOwnedFlowUtils}; diff --git a/components/layout/lib.rs b/components/layout/lib.rs index 37ef193ef54..c12cb903d33 100644 --- a/components/layout/lib.rs +++ b/components/layout/lib.rs @@ -100,5 +100,4 @@ pub mod wrapper; pub mod css { pub mod matching; - pub mod node_style; } diff --git a/components/layout/table_cell.rs b/components/layout/table_cell.rs index f72f3f30e79..66f9ec72259 100644 --- a/components/layout/table_cell.rs +++ b/components/layout/table_cell.rs @@ -8,7 +8,6 @@ use block::{BlockFlow, ISizeAndMarginsComputer, MarginsMayCollapseFlag}; use context::LayoutContext; -use css::node_style::StyledNode; use display_list_builder::{BlockFlowDisplayListBuilding, BorderPaintingMode}; use flow::{Flow, FlowClass, OpaqueFlow}; use fragment::{Fragment, FragmentBorderBoxIterator}; diff --git a/components/layout/table_colgroup.rs b/components/layout/table_colgroup.rs index 90e7c329e68..d58c361da4d 100644 --- a/components/layout/table_colgroup.rs +++ b/components/layout/table_colgroup.rs @@ -7,7 +7,6 @@ #![deny(unsafe_code)] use context::LayoutContext; -use css::node_style::StyledNode; use flow::{BaseFlow, FlowClass, Flow, ForceNonfloatedFlag, OpaqueFlow}; use fragment::{Fragment, FragmentBorderBoxIterator, SpecificFragmentInfo}; use layout_debug; diff --git a/components/layout/traversal.rs b/components/layout/traversal.rs index d60729443cc..0fbf159d7c3 100644 --- a/components/layout/traversal.rs +++ b/components/layout/traversal.rs @@ -4,7 +4,6 @@ //! Traversals over the DOM and flow trees, running the layout computations. -use css::node_style::StyledNode; use css::matching::{ApplicableDeclarations, MatchMethods, StyleSharingResult}; use construct::FlowConstructor; use context::LayoutContext; diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 6bdc6d1f98e..8309c370e8a 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -32,7 +32,6 @@ use canvas_traits::CanvasMsg; use context::SharedLayoutContext; -use css::node_style::StyledNode; use incremental::RestyleDamage; use data::{LayoutDataFlags, LayoutDataWrapper, PrivateLayoutData}; use opaque_node::OpaqueNodeMethods; @@ -64,6 +63,7 @@ use std::borrow::ToOwned; use std::cell::{Ref, RefMut}; use std::marker::PhantomData; use std::mem; +use std::sync::Arc; use string_cache::{Atom, Namespace}; use style::computed_values::content::ContentItem; use style::computed_values::{content, display, white_space}; @@ -72,6 +72,7 @@ use selectors::parser::{NamespaceConstraint, AttrSelector}; use style::legacy::UnsignedIntegerAttribute; use style::node::TElementAttributes; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock}; +use style::properties::ComputedValues; use url::Url; /// A wrapper so that layout can access only the methods that it should have access to. Layout must @@ -742,6 +743,40 @@ impl<'ln> ThreadSafeLayoutNode<'ln> { self.node.mutate_layout_data() } + #[inline] + pub fn get_style<'a>(&self, layout_data_ref: &'a LayoutDataWrapper) -> &'a Arc<ComputedValues> { + match self.get_pseudo_element_type() { + PseudoElementType::Before(_) => layout_data_ref.data.before_style.as_ref().unwrap(), + PseudoElementType::After(_) => layout_data_ref.data.after_style.as_ref().unwrap(), + PseudoElementType::Normal => layout_data_ref.shared_data.style.as_ref().unwrap(), + } + } + + /// Returns the style results for the given node. If CSS selector matching + /// has not yet been performed, fails. + #[inline] + pub fn style<'a>(&'a self) -> Ref<'a, Arc<ComputedValues>> { + Ref::map(self.borrow_layout_data(), |layout_data_ref| { + let layout_data = layout_data_ref.as_ref().expect("no layout data"); + self.get_style(layout_data) + }) + } + + /// Removes the style from this node. + pub fn unstyle(self) { + let mut layout_data_ref = self.mutate_layout_data(); + let layout_data = layout_data_ref.as_mut().expect("no layout data"); + + let style = + match self.get_pseudo_element_type() { + PseudoElementType::Before(_) => &mut layout_data.data.before_style, + PseudoElementType::After (_) => &mut layout_data.data.after_style, + PseudoElementType::Normal => &mut layout_data.shared_data.style, + }; + + *style = None; + } + pub fn is_ignorable_whitespace(&self) -> bool { unsafe { let text: LayoutJS<Text> = match TextCast::to_layout_js(self.get_jsmanaged()) { |