mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Replace the StyledNode trait with inherent methods.
This commit is contained in:
parent
5cf662fb97
commit
3984e39011
13 changed files with 36 additions and 68 deletions
|
@ -28,7 +28,6 @@
|
||||||
#![deny(unsafe_code)]
|
#![deny(unsafe_code)]
|
||||||
|
|
||||||
use context::LayoutContext;
|
use context::LayoutContext;
|
||||||
use css::node_style::StyledNode;
|
|
||||||
use display_list_builder::{BlockFlowDisplayListBuilding, BorderPaintingMode};
|
use display_list_builder::{BlockFlowDisplayListBuilding, BorderPaintingMode};
|
||||||
use display_list_builder::{FragmentDisplayListBuilding};
|
use display_list_builder::{FragmentDisplayListBuilding};
|
||||||
use floats::{ClearType, FloatKind, Floats, PlacementInfo};
|
use floats::{ClearType, FloatKind, Floats, PlacementInfo};
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
|
|
||||||
use block::BlockFlow;
|
use block::BlockFlow;
|
||||||
use context::LayoutContext;
|
use context::LayoutContext;
|
||||||
use css::node_style::StyledNode;
|
|
||||||
use data::{HAS_NEWLY_CONSTRUCTED_FLOW, LayoutDataWrapper};
|
use data::{HAS_NEWLY_CONSTRUCTED_FLOW, LayoutDataWrapper};
|
||||||
use floats::FloatKind;
|
use floats::FloatKind;
|
||||||
use flow::{Descendants, AbsDescendants};
|
use flow::{Descendants, AbsDescendants};
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
use animation;
|
use animation;
|
||||||
use context::SharedLayoutContext;
|
use context::SharedLayoutContext;
|
||||||
use css::node_style::StyledNode;
|
|
||||||
use data::LayoutDataWrapper;
|
use data::LayoutDataWrapper;
|
||||||
use incremental::{self, RestyleDamage};
|
use incremental::{self, RestyleDamage};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -25,7 +25,6 @@
|
||||||
/// line breaks and mapping to CSS boxes, for the purpose of handling `getClientRects()` and
|
/// line breaks and mapping to CSS boxes, for the purpose of handling `getClientRects()` and
|
||||||
/// similar methods.
|
/// similar methods.
|
||||||
|
|
||||||
use css::node_style::StyledNode;
|
|
||||||
use block::BlockFlow;
|
use block::BlockFlow;
|
||||||
use context::LayoutContext;
|
use context::LayoutContext;
|
||||||
use display_list_builder::DisplayListBuildingResult;
|
use display_list_builder::DisplayListBuildingResult;
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
#![deny(unsafe_code)]
|
#![deny(unsafe_code)]
|
||||||
|
|
||||||
use canvas_traits::CanvasMsg;
|
use canvas_traits::CanvasMsg;
|
||||||
use css::node_style::StyledNode;
|
|
||||||
use context::LayoutContext;
|
use context::LayoutContext;
|
||||||
use floats::ClearType;
|
use floats::ClearType;
|
||||||
use flow;
|
use flow;
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#![deny(unsafe_code)]
|
#![deny(unsafe_code)]
|
||||||
|
|
||||||
use block::{AbsoluteAssignBSizesTraversal, AbsoluteStoreOverflowTraversal};
|
use block::{AbsoluteAssignBSizesTraversal, AbsoluteStoreOverflowTraversal};
|
||||||
use css::node_style::StyledNode;
|
|
||||||
use context::LayoutContext;
|
use context::LayoutContext;
|
||||||
use display_list_builder::{FragmentDisplayListBuilding, InlineFlowDisplayListBuilding};
|
use display_list_builder::{FragmentDisplayListBuilding, InlineFlowDisplayListBuilding};
|
||||||
use floats::{FloatKind, Floats, PlacementInfo};
|
use floats::{FloatKind, Floats, PlacementInfo};
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
use animation;
|
use animation;
|
||||||
use construct::ConstructionResult;
|
use construct::ConstructionResult;
|
||||||
use context::{SharedLayoutContext, heap_size_of_local_context};
|
use context::{SharedLayoutContext, heap_size_of_local_context};
|
||||||
use css::node_style::StyledNode;
|
|
||||||
use data::LayoutDataWrapper;
|
use data::LayoutDataWrapper;
|
||||||
use display_list_builder::ToGfxColor;
|
use display_list_builder::ToGfxColor;
|
||||||
use flow::{self, Flow, ImmutableFlowUtils, MutableFlowUtils, MutableOwnedFlowUtils};
|
use flow::{self, Flow, ImmutableFlowUtils, MutableFlowUtils, MutableOwnedFlowUtils};
|
||||||
|
|
|
@ -100,5 +100,4 @@ pub mod wrapper;
|
||||||
|
|
||||||
pub mod css {
|
pub mod css {
|
||||||
pub mod matching;
|
pub mod matching;
|
||||||
pub mod node_style;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
use block::{BlockFlow, ISizeAndMarginsComputer, MarginsMayCollapseFlag};
|
use block::{BlockFlow, ISizeAndMarginsComputer, MarginsMayCollapseFlag};
|
||||||
use context::LayoutContext;
|
use context::LayoutContext;
|
||||||
use css::node_style::StyledNode;
|
|
||||||
use display_list_builder::{BlockFlowDisplayListBuilding, BorderPaintingMode};
|
use display_list_builder::{BlockFlowDisplayListBuilding, BorderPaintingMode};
|
||||||
use flow::{Flow, FlowClass, OpaqueFlow};
|
use flow::{Flow, FlowClass, OpaqueFlow};
|
||||||
use fragment::{Fragment, FragmentBorderBoxIterator};
|
use fragment::{Fragment, FragmentBorderBoxIterator};
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
#![deny(unsafe_code)]
|
#![deny(unsafe_code)]
|
||||||
|
|
||||||
use context::LayoutContext;
|
use context::LayoutContext;
|
||||||
use css::node_style::StyledNode;
|
|
||||||
use flow::{BaseFlow, FlowClass, Flow, ForceNonfloatedFlag, OpaqueFlow};
|
use flow::{BaseFlow, FlowClass, Flow, ForceNonfloatedFlag, OpaqueFlow};
|
||||||
use fragment::{Fragment, FragmentBorderBoxIterator, SpecificFragmentInfo};
|
use fragment::{Fragment, FragmentBorderBoxIterator, SpecificFragmentInfo};
|
||||||
use layout_debug;
|
use layout_debug;
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
//! Traversals over the DOM and flow trees, running the layout computations.
|
//! Traversals over the DOM and flow trees, running the layout computations.
|
||||||
|
|
||||||
use css::node_style::StyledNode;
|
|
||||||
use css::matching::{ApplicableDeclarations, MatchMethods, StyleSharingResult};
|
use css::matching::{ApplicableDeclarations, MatchMethods, StyleSharingResult};
|
||||||
use construct::FlowConstructor;
|
use construct::FlowConstructor;
|
||||||
use context::LayoutContext;
|
use context::LayoutContext;
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
|
|
||||||
use canvas_traits::CanvasMsg;
|
use canvas_traits::CanvasMsg;
|
||||||
use context::SharedLayoutContext;
|
use context::SharedLayoutContext;
|
||||||
use css::node_style::StyledNode;
|
|
||||||
use incremental::RestyleDamage;
|
use incremental::RestyleDamage;
|
||||||
use data::{LayoutDataFlags, LayoutDataWrapper, PrivateLayoutData};
|
use data::{LayoutDataFlags, LayoutDataWrapper, PrivateLayoutData};
|
||||||
use opaque_node::OpaqueNodeMethods;
|
use opaque_node::OpaqueNodeMethods;
|
||||||
|
@ -64,6 +63,7 @@ use std::borrow::ToOwned;
|
||||||
use std::cell::{Ref, RefMut};
|
use std::cell::{Ref, RefMut};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
use std::sync::Arc;
|
||||||
use string_cache::{Atom, Namespace};
|
use string_cache::{Atom, Namespace};
|
||||||
use style::computed_values::content::ContentItem;
|
use style::computed_values::content::ContentItem;
|
||||||
use style::computed_values::{content, display, white_space};
|
use style::computed_values::{content, display, white_space};
|
||||||
|
@ -72,6 +72,7 @@ use selectors::parser::{NamespaceConstraint, AttrSelector};
|
||||||
use style::legacy::UnsignedIntegerAttribute;
|
use style::legacy::UnsignedIntegerAttribute;
|
||||||
use style::node::TElementAttributes;
|
use style::node::TElementAttributes;
|
||||||
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock};
|
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock};
|
||||||
|
use style::properties::ComputedValues;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
/// A wrapper so that layout can access only the methods that it should have access to. Layout must
|
/// 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()
|
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 {
|
pub fn is_ignorable_whitespace(&self) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
let text: LayoutJS<Text> = match TextCast::to_layout_js(self.get_jsmanaged()) {
|
let text: LayoutJS<Text> = match TextCast::to_layout_js(self.get_jsmanaged()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue