aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout/wrapper.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/layout/wrapper.rs')
-rw-r--r--components/layout/wrapper.rs37
1 files changed, 36 insertions, 1 deletions
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()) {