aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <ecoal95@gmail.com>2016-02-08 02:53:22 +0100
committerEmilio Cobos Álvarez <ecoal95@gmail.com>2016-02-13 16:05:14 +0100
commitdd503dfacb46c63702e4a4b49b85ca30df62a8df (patch)
tree81021ae722350d30583c718cff1aab22fe456db5 /components/layout
parenta164176876bb6abccf729eb5d6334e3c22230103 (diff)
downloadservo-dd503dfacb46c63702e4a4b49b85ca30df62a8df.tar.gz
servo-dd503dfacb46c63702e4a4b49b85ca30df62a8df.zip
Refactor style to be completely backend-independent
This commit refactors the style crate to be completely independent of the actual implementation and pseudo-elements supported. This also adds a gecko backend which introduces parsing for the anonymous box pseudo-elements[1], although there's still no way of querying them. https://mxr.mozilla.org/mozilla-central/source/layout/style/nsCSSAnonBoxList.h
Diffstat (limited to 'components/layout')
-rw-r--r--components/layout/Cargo.toml2
-rw-r--r--components/layout/context.rs6
-rw-r--r--components/layout/data.rs2
-rw-r--r--components/layout/layout_thread.rs10
-rw-r--r--components/layout/traversal.rs4
-rw-r--r--components/layout/wrapper.rs45
6 files changed, 45 insertions, 24 deletions
diff --git a/components/layout/Cargo.toml b/components/layout/Cargo.toml
index c926475ae41..8ee2de344b7 100644
--- a/components/layout/Cargo.toml
+++ b/components/layout/Cargo.toml
@@ -64,7 +64,7 @@ heapsize_plugin = "0.1.2"
libc = "0.2"
log = "0.3"
rustc-serialize = "0.3"
-selectors = {version = "0.4.2", features = ["heap_size"]}
+selectors = {version = "0.5", features = ["heap_size"]}
serde = "0.6"
serde_json = "0.5"
serde_macros = "0.6"
diff --git a/components/layout/context.rs b/components/layout/context.rs
index 7eb01a68846..953c98797f5 100644
--- a/components/layout/context.rs
+++ b/components/layout/context.rs
@@ -25,8 +25,10 @@ use std::hash::BuildHasherDefault;
use std::rc::Rc;
use std::sync::mpsc::Sender;
use std::sync::{Arc, Mutex};
-use style::context::{LocalStyleContext, SharedStyleContext, StyleContext};
+use style::context::{LocalStyleContext, StyleContext};
use style::matching::{ApplicableDeclarationsCache, StyleSharingCandidateCache};
+use style::selector_impl::ServoSelectorImpl;
+use style::servo::SharedStyleContext;
use url::Url;
use util::opts;
@@ -104,7 +106,7 @@ pub struct LayoutContext<'a> {
cached_local_layout_context: Rc<LocalLayoutContext>,
}
-impl<'a> StyleContext<'a> for LayoutContext<'a> {
+impl<'a> StyleContext<'a, ServoSelectorImpl> for LayoutContext<'a> {
fn shared_context(&self) -> &'a SharedStyleContext {
&self.shared.style_context
}
diff --git a/components/layout/data.rs b/components/layout/data.rs
index 459743cd689..b11e4ebfd05 100644
--- a/components/layout/data.rs
+++ b/components/layout/data.rs
@@ -4,7 +4,7 @@
use construct::ConstructionResult;
use incremental::RestyleDamage;
-use style::data::PrivateStyleData;
+use style::servo::PrivateStyleData;
/// Data that layout associates with a node.
pub struct PrivateLayoutData {
diff --git a/components/layout/layout_thread.rs b/components/layout/layout_thread.rs
index aaa6a1e98c0..a540039c51b 100644
--- a/components/layout/layout_thread.rs
+++ b/components/layout/layout_thread.rs
@@ -62,13 +62,15 @@ use std::sync::mpsc::{channel, Sender, Receiver};
use std::sync::{Arc, Mutex, MutexGuard, RwLock};
use style::animation::Animation;
use style::computed_values::{filter, mix_blend_mode};
-use style::context::{SharedStyleContext, StylistWrapper, ReflowGoal};
+use style::context::{ReflowGoal, StylistWrapper};
use style::dom::{TDocument, TElement, TNode};
use style::error_reporting::ParseErrorReporter;
use style::media_queries::{Device, MediaType};
use style::parallel::WorkQueueData;
-use style::selector_matching::{Stylist, USER_OR_USER_AGENT_STYLESHEETS};
-use style::stylesheets::{CSSRuleIteratorExt, Stylesheet};
+use style::selector_impl::ServoSelectorImpl;
+use style::selector_matching::USER_OR_USER_AGENT_STYLESHEETS;
+use style::servo::{SharedStyleContext, Stylesheet, Stylist};
+use style::stylesheets::CSSRuleIteratorExt;
use traversal::RecalcStyleAndConstructFlows;
use url::Url;
use util::geometry::MAX_RECT;
@@ -477,7 +479,7 @@ impl LayoutThread {
style_context: SharedStyleContext {
viewport_size: self.viewport_size.clone(),
screen_size_changed: screen_size_changed,
- stylist: StylistWrapper(&*rw_data.stylist),
+ stylist: StylistWrapper::<ServoSelectorImpl>(&*rw_data.stylist),
generation: self.generation,
goal: goal,
new_animations_sender: Mutex::new(self.new_animations_sender.clone()),
diff --git a/components/layout/traversal.rs b/components/layout/traversal.rs
index 69e85c39303..d5febecc483 100644
--- a/components/layout/traversal.rs
+++ b/components/layout/traversal.rs
@@ -16,6 +16,7 @@ use incremental::{BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW, REPAINT, RestyleDam
use std::mem;
use style::context::{StyleContext, ReflowGoal};
use style::matching::MatchMethods;
+use style::selector_impl::ServoSelectorImpl;
use style::traversal::{DomTraversalContext, STYLE_BLOOM};
use style::traversal::{put_thread_local_bloom_filter, recalc_style_at};
use util::opts;
@@ -27,7 +28,8 @@ pub struct RecalcStyleAndConstructFlows<'lc> {
root: OpaqueNode,
}
-impl<'lc, 'ln, N: LayoutNode<'ln>> DomTraversalContext<'ln, N> for RecalcStyleAndConstructFlows<'lc> {
+impl<'lc, 'ln, N: LayoutNode<'ln>> DomTraversalContext<'ln, N> for RecalcStyleAndConstructFlows<'lc>
+ where N::ConcreteElement: ::selectors::Element<Impl=ServoSelectorImpl> {
type SharedContext = SharedLayoutContext;
#[allow(unsafe_code)]
fn new<'a>(shared: &'a Self::SharedContext, root: OpaqueNode) -> Self {
diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs
index 1c8f1ee1d8e..faacdbf44f0 100644
--- a/components/layout/wrapper.rs
+++ b/components/layout/wrapper.rs
@@ -64,13 +64,13 @@ use std::sync::Arc;
use string_cache::{Atom, Namespace};
use style::computed_values::content::ContentItem;
use style::computed_values::{content, display};
-use style::data::PrivateStyleData;
use style::dom::{TDocument, TElement, TNode, UnsafeNode};
use style::element_state::*;
use style::properties::ComputedValues;
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock};
use style::restyle_hints::ElementSnapshot;
-use style::selector_impl::{NonTSPseudoClass, ServoSelectorImpl};
+use style::selector_impl::{NonTSPseudoClass, PseudoElement, ServoSelectorImpl};
+use style::servo::PrivateStyleData;
use url::Url;
use util::str::{is_whitespace, search_index};
@@ -664,16 +664,20 @@ pub trait ThreadSafeLayoutNode<'ln> : Clone + Copy + Sized {
#[inline]
fn get_before_pseudo(&self) -> Option<Self> {
- self.borrow_layout_data().unwrap().style_data.before_style.as_ref().map(|style| {
- self.with_pseudo(PseudoElementType::Before(style.get_box().display))
- })
+ self.borrow_layout_data().unwrap()
+ .style_data.per_pseudo
+ .get(&PseudoElement::Before).unwrap_or(&None).as_ref().map(|style| {
+ self.with_pseudo(PseudoElementType::Before(style.get_box().display))
+ })
}
#[inline]
fn get_after_pseudo(&self) -> Option<Self> {
- self.borrow_layout_data().unwrap().style_data.after_style.as_ref().map(|style| {
- self.with_pseudo(PseudoElementType::After(style.get_box().display))
- })
+ self.borrow_layout_data().unwrap()
+ .style_data.per_pseudo
+ .get(&PseudoElement::After).unwrap_or(&None).as_ref().map(|style| {
+ self.with_pseudo(PseudoElementType::After(style.get_box().display))
+ })
}
/// Borrows the layout data immutably. Fails on a conflicting borrow.
@@ -696,8 +700,8 @@ pub trait ThreadSafeLayoutNode<'ln> : Clone + Copy + Sized {
fn style(&self) -> Ref<Arc<ComputedValues>> {
Ref::map(self.borrow_layout_data().unwrap(), |data| {
let style = match self.get_pseudo_element_type() {
- PseudoElementType::Before(_) => &data.style_data.before_style,
- PseudoElementType::After(_) => &data.style_data.after_style,
+ PseudoElementType::Before(_) => data.style_data.per_pseudo.get(&PseudoElement::Before).unwrap(),
+ PseudoElementType::After(_) => data.style_data.per_pseudo.get(&PseudoElement::After).unwrap(),
PseudoElementType::Normal => &data.style_data.style,
};
style.as_ref().unwrap()
@@ -711,9 +715,19 @@ pub trait ThreadSafeLayoutNode<'ln> : Clone + Copy + Sized {
let mut data = self.mutate_layout_data().unwrap();
let style =
match self.get_pseudo_element_type() {
- PseudoElementType::Before(_) => &mut data.style_data.before_style,
- PseudoElementType::After (_) => &mut data.style_data.after_style,
- PseudoElementType::Normal => &mut data.style_data.style,
+ PseudoElementType::Before(_) => {
+ match data.style_data.per_pseudo.get_mut(&PseudoElement::Before) {
+ None => return,
+ Some(style) => style,
+ }
+ }
+ PseudoElementType::After(_) => {
+ match data.style_data.per_pseudo.get_mut(&PseudoElement::After) {
+ None => return,
+ Some(style) => style,
+ }
+ }
+ PseudoElementType::Normal => &mut data.style_data.style,
};
*style = None;
@@ -934,10 +948,11 @@ impl<'ln> ThreadSafeLayoutNode<'ln> for ServoThreadSafeLayoutNode<'ln> {
let data = &self.borrow_layout_data().unwrap().style_data;
let style = if self.pseudo.is_before() {
- &data.before_style
+ data.per_pseudo.get(&PseudoElement::Before).unwrap()
} else {
- &data.after_style
+ data.per_pseudo.get(&PseudoElement::After).unwrap()
};
+
return match style.as_ref().unwrap().get_box().content {
content::T::Content(ref value) if !value.is_empty() => {
TextContent::GeneratedContent((*value).clone())