aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout
diff options
context:
space:
mode:
Diffstat (limited to 'components/layout')
-rw-r--r--components/layout/css/matching.rs9
-rw-r--r--components/layout/css/node_style.rs58
-rw-r--r--components/layout/css/node_util.rs75
-rw-r--r--components/layout/lib.rs2
-rw-r--r--components/layout/wrapper.rs24
5 files changed, 83 insertions, 85 deletions
diff --git a/components/layout/css/matching.rs b/components/layout/css/matching.rs
index f1615aa005d..86968a6d9c2 100644
--- a/components/layout/css/matching.rs
+++ b/components/layout/css/matching.rs
@@ -268,6 +268,9 @@ impl StyleSharingCandidate {
return false
}
+ // FIXME(pcwalton): It's probably faster to iterate over all the element's attributes and
+ // use the {common, rare}-style-affecting-attributes tables as lookup tables.
+
for attribute_info in style::common_style_affecting_attributes().iter() {
match attribute_info.mode {
AttrIsPresentMode(flag) => {
@@ -295,6 +298,12 @@ impl StyleSharingCandidate {
}
}
+ for attribute_name in style::rare_style_affecting_attributes().iter() {
+ if element.get_attr(&ns!(""), attribute_name).is_some() {
+ return false
+ }
+ }
+
if element.get_link().is_some() != self.link {
return false
}
diff --git a/components/layout/css/node_style.rs b/components/layout/css/node_style.rs
index ecfb3383453..c3eaa04ddd2 100644
--- a/components/layout/css/node_style.rs
+++ b/components/layout/css/node_style.rs
@@ -2,27 +2,75 @@
* 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.
+//! Style retrieval from DOM elements.
-use css::node_util::NodeUtil;
-use wrapper::ThreadSafeLayoutNode;
+use wrapper::{After, Before, Normal, ThreadSafeLayoutNode};
+use std::mem;
use style::ComputedValues;
use sync::Arc;
/// Node mixin providing `style` method that returns a `NodeStyle`
pub trait StyledNode {
+ /// Returns the style results for the given node. If CSS selector matching has not yet been
+ /// performed, fails.
fn style<'a>(&'a self) -> &'a Arc<ComputedValues>;
+ /// Does this node have a computed style yet?
+ fn has_style(&self) -> bool;
+ /// Removes the style from this node.
fn unstyle(self);
}
impl<'ln> StyledNode for ThreadSafeLayoutNode<'ln> {
#[inline]
fn style<'a>(&'a self) -> &'a Arc<ComputedValues> {
- self.get_css_select_results()
+ unsafe {
+ let layout_data_ref = self.borrow_layout_data();
+ match self.get_pseudo_element_type() {
+ Before(_) => {
+ mem::transmute(layout_data_ref.as_ref()
+ .unwrap()
+ .data
+ .before_style
+ .as_ref()
+ .unwrap())
+ }
+ After(_) => {
+ mem::transmute(layout_data_ref.as_ref()
+ .unwrap()
+ .data
+ .after_style
+ .as_ref()
+ .unwrap())
+ }
+ Normal => {
+ mem::transmute(layout_data_ref.as_ref()
+ .unwrap()
+ .shared_data
+ .style
+ .as_ref()
+ .unwrap())
+ }
+ }
+ }
+ }
+
+ fn has_style(&self) -> bool {
+ let layout_data_ref = self.borrow_layout_data();
+ layout_data_ref.as_ref().unwrap().shared_data.style.is_some()
}
fn unstyle(self) {
- self.remove_css_select_results()
+ 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() {
+ Before(_) => &mut layout_data.data.before_style,
+ After (_) => &mut layout_data.data.after_style,
+ Normal => &mut layout_data.shared_data.style,
+ };
+
+ *style = None;
}
}
diff --git a/components/layout/css/node_util.rs b/components/layout/css/node_util.rs
deleted file mode 100644
index eb447b0cf6b..00000000000
--- a/components/layout/css/node_util.rs
+++ /dev/null
@@ -1,75 +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/. */
-
-use util::LayoutDataAccess;
-use wrapper::ThreadSafeLayoutNode;
-use wrapper::{After, Before, Normal};
-
-use std::mem;
-use style::ComputedValues;
-use sync::Arc;
-
-pub trait NodeUtil {
- fn get_css_select_results<'a>(&'a self) -> &'a Arc<ComputedValues>;
- fn have_css_select_results(&self) -> bool;
- fn remove_css_select_results(self);
-}
-
-impl<'ln> NodeUtil for ThreadSafeLayoutNode<'ln> {
- /// Returns the style results for the given node. If CSS selector
- /// matching has not yet been performed, fails.
- #[inline]
- fn get_css_select_results<'a>(&'a self) -> &'a Arc<ComputedValues> {
- unsafe {
- let layout_data_ref = self.borrow_layout_data();
- match self.get_pseudo_element_type() {
- Before(_) => {
- mem::transmute(layout_data_ref.as_ref()
- .unwrap()
- .data
- .before_style
- .as_ref()
- .unwrap())
- }
- After(_) => {
- mem::transmute(layout_data_ref.as_ref()
- .unwrap()
- .data
- .after_style
- .as_ref()
- .unwrap())
- }
- Normal => {
- mem::transmute(layout_data_ref.as_ref()
- .unwrap()
- .shared_data
- .style
- .as_ref()
- .unwrap())
- }
- }
- }
- }
-
- /// Does this node have a computed style yet?
- fn have_css_select_results(&self) -> bool {
- let layout_data_ref = self.borrow_layout_data();
- layout_data_ref.as_ref().unwrap().shared_data.style.is_some()
- }
-
- fn remove_css_select_results(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() {
- Before(_) => &mut layout_data.data.before_style,
- After (_) => &mut layout_data.data.after_style,
- Normal => &mut layout_data.shared_data.style,
- };
-
- *style = None;
- }
-}
-
diff --git a/components/layout/lib.rs b/components/layout/lib.rs
index 1fa21311373..af91126cc4a 100644
--- a/components/layout/lib.rs
+++ b/components/layout/lib.rs
@@ -70,8 +70,6 @@ pub mod incremental;
pub mod wrapper;
pub mod css {
- mod node_util;
-
pub mod matching;
pub mod node_style;
}
diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs
index 9a70539c78b..ba16eb885a9 100644
--- a/components/layout/wrapper.rs
+++ b/components/layout/wrapper.rs
@@ -56,11 +56,12 @@ use servo_msg::constellation_msg::{PipelineId, SubpageId};
use servo_util::str::{LengthOrPercentageOrAuto, is_whitespace};
use std::kinds::marker::ContravariantLifetime;
use std::mem;
+use string_cache::{Atom, Namespace};
use style::computed_values::{content, display, white_space};
-use style::{AnyNamespace, AttrSelector, IntegerAttribute, LengthAttribute};
-use style::{PropertyDeclarationBlock, SpecificNamespace, TElement, TElementAttributes, TNode};
+use style::{AnyNamespace, AttrSelector, BorderUnsignedIntegerAttribute, IntegerAttribute};
+use style::{LengthAttribute, PropertyDeclarationBlock, SpecificNamespace, TElement};
+use style::{TElementAttributes, TNode, UnsignedIntegerAttribute};
use url::Url;
-use string_cache::{Atom, Namespace};
use std::cell::{Ref, RefMut};
@@ -580,6 +581,17 @@ impl<'le> TElement<'le> for LayoutElement<'le> {
}
}
}
+
+ #[inline]
+ fn has_nonzero_border(self) -> bool {
+ unsafe {
+ match self.element
+ .get_unsigned_integer_attribute_for_layout(BorderUnsignedIntegerAttribute) {
+ None | Some(0) => false,
+ _ => true,
+ }
+ }
+ }
}
impl<'le> TElementAttributes for LayoutElement<'le> {
@@ -594,6 +606,12 @@ impl<'le> TElementAttributes for LayoutElement<'le> {
self.element.get_integer_attribute_for_layout(integer_attribute)
}
}
+
+ fn get_unsigned_integer_attribute(self, attribute: UnsignedIntegerAttribute) -> Option<u32> {
+ unsafe {
+ self.element.get_unsigned_integer_attribute_for_layout(attribute)
+ }
+ }
}
fn get_content(content_list: &content::T) -> String {