Parameterize the rest of the style system on TNode.

This commit is contained in:
Bobby Holley 2016-03-10 16:17:52 -08:00
parent 5c749127cc
commit c2daea2c9c
37 changed files with 149 additions and 113 deletions

View file

@ -60,7 +60,7 @@ use style::computed_values::{border_collapse, box_sizing, display, float, overfl
use style::computed_values::{position, text_align, transform_style}; use style::computed_values::{position, text_align, transform_style};
use style::context::StyleContext; use style::context::StyleContext;
use style::logical_geometry::{LogicalPoint, LogicalRect, LogicalSize, WritingMode}; use style::logical_geometry::{LogicalPoint, LogicalRect, LogicalSize, WritingMode};
use style::properties::ComputedValues; use style::properties::{ComputedValues, TComputedValues};
use style::values::computed::{LengthOrNone, LengthOrPercentageOrNone}; use style::values::computed::{LengthOrNone, LengthOrPercentageOrNone};
use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto}; use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
use util::geometry::MAX_RECT; use util::geometry::MAX_RECT;

View file

@ -45,7 +45,7 @@ use std::sync::atomic::Ordering;
use style::computed_values::content::ContentItem; use style::computed_values::content::ContentItem;
use style::computed_values::{caption_side, display, empty_cells, float, list_style_position}; use style::computed_values::{caption_side, display, empty_cells, float, list_style_position};
use style::computed_values::{position}; use style::computed_values::{position};
use style::properties::{self, ComputedValues}; use style::properties::{self, ComputedValues, TComputedValues};
use table::TableFlow; use table::TableFlow;
use table_caption::TableCaptionFlow; use table_caption::TableCaptionFlow;
use table_cell::TableCellFlow; use table_cell::TableCellFlow;

View file

@ -28,13 +28,14 @@ use std::sync::mpsc::Sender;
use std::sync::{Arc, Mutex, RwLock}; use std::sync::{Arc, Mutex, RwLock};
use style::context::{LocalStyleContext, StyleContext}; use style::context::{LocalStyleContext, StyleContext};
use style::matching::{ApplicableDeclarationsCache, StyleSharingCandidateCache}; use style::matching::{ApplicableDeclarationsCache, StyleSharingCandidateCache};
use style::properties::ComputedValues;
use style::selector_impl::ServoSelectorImpl; use style::selector_impl::ServoSelectorImpl;
use style::servo::SharedStyleContext; use style::servo::SharedStyleContext;
use url::Url; use url::Url;
use util::opts; use util::opts;
struct LocalLayoutContext { struct LocalLayoutContext {
style_context: LocalStyleContext, style_context: LocalStyleContext<ComputedValues>,
font_context: RefCell<FontContext>, font_context: RefCell<FontContext>,
} }
@ -112,12 +113,12 @@ pub struct LayoutContext<'a> {
cached_local_layout_context: Rc<LocalLayoutContext>, cached_local_layout_context: Rc<LocalLayoutContext>,
} }
impl<'a> StyleContext<'a, ServoSelectorImpl> for LayoutContext<'a> { impl<'a> StyleContext<'a, ServoSelectorImpl, ComputedValues> for LayoutContext<'a> {
fn shared_context(&self) -> &'a SharedStyleContext { fn shared_context(&self) -> &'a SharedStyleContext {
&self.shared.style_context &self.shared.style_context
} }
fn local_context(&self) -> &LocalStyleContext { fn local_context(&self) -> &LocalStyleContext<ComputedValues> {
&self.cached_local_layout_context.style_context &self.cached_local_layout_context.style_context
} }
} }

View file

@ -51,7 +51,7 @@ use style::computed_values::{border_style, image_rendering, overflow_x, position
use style::computed_values::{transform, transform_style, visibility}; use style::computed_values::{transform, transform_style, visibility};
use style::logical_geometry::{LogicalPoint, LogicalRect, LogicalSize, WritingMode}; use style::logical_geometry::{LogicalPoint, LogicalRect, LogicalSize, WritingMode};
use style::properties::style_structs::Border; use style::properties::style_structs::Border;
use style::properties::{self, ComputedValues}; use style::properties::{self, ComputedValues, TComputedValues};
use style::values::RGBA; use style::values::RGBA;
use style::values::computed; use style::values::computed;
use style::values::computed::{LengthOrNone, LengthOrPercentage, LengthOrPercentageOrAuto, LinearGradient}; use style::values::computed::{LengthOrNone, LengthOrPercentage, LengthOrPercentageOrAuto, LinearGradient};

View file

@ -28,8 +28,8 @@ use std::cmp::max;
use std::sync::Arc; use std::sync::Arc;
use style::computed_values::{flex_direction, float}; use style::computed_values::{flex_direction, float};
use style::logical_geometry::LogicalSize; use style::logical_geometry::LogicalSize;
use style::properties::ComputedValues;
use style::properties::style_structs; use style::properties::style_structs;
use style::properties::{ComputedValues, TComputedValues};
use style::values::computed::LengthOrPercentageOrAuto; use style::values::computed::LengthOrPercentageOrAuto;
// A mode describes which logical axis a flex axis is parallel with. // A mode describes which logical axis a flex axis is parallel with.

View file

@ -50,7 +50,7 @@ use std::{fmt, mem, raw};
use style::computed_values::{clear, display, empty_cells, float, position, overflow_x, text_align}; use style::computed_values::{clear, display, empty_cells, float, position, overflow_x, text_align};
use style::dom::TRestyleDamage; use style::dom::TRestyleDamage;
use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode}; use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode};
use style::properties::{self, ComputedValues}; use style::properties::{self, ComputedValues, TComputedValues};
use style::values::computed::LengthOrPercentageOrAuto; use style::values::computed::LengthOrPercentageOrAuto;
use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize, TableFlow}; use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize, TableFlow};
use table_caption::TableCaptionFlow; use table_caption::TableCaptionFlow;

View file

@ -41,7 +41,7 @@ use style::computed_values::{overflow_x, position, text_decoration, transform_st
use style::computed_values::{white_space, word_break, z_index}; use style::computed_values::{white_space, word_break, z_index};
use style::dom::TRestyleDamage; use style::dom::TRestyleDamage;
use style::logical_geometry::{LogicalMargin, LogicalRect, LogicalSize, WritingMode}; use style::logical_geometry::{LogicalMargin, LogicalRect, LogicalSize, WritingMode};
use style::properties::ComputedValues; use style::properties::{ComputedValues, TComputedValues};
use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto}; use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
use style::values::computed::{LengthOrPercentageOrNone}; use style::values::computed::{LengthOrPercentageOrNone};
use text; use text;

View file

@ -20,7 +20,7 @@ use std::sync::Arc;
use style::computed_values::content::ContentItem; use style::computed_values::content::ContentItem;
use style::computed_values::{display, list_style_type}; use style::computed_values::{display, list_style_type};
use style::dom::TRestyleDamage; use style::dom::TRestyleDamage;
use style::properties::ComputedValues; use style::properties::{ComputedValues, TComputedValues};
use text::TextRunScanner; use text::TextRunScanner;
use wrapper::PseudoElementType; use wrapper::PseudoElementType;

View file

@ -7,7 +7,7 @@ use std::fmt;
use std::sync::Arc; use std::sync::Arc;
use style::computed_values::float; use style::computed_values::float;
use style::dom::TRestyleDamage; use style::dom::TRestyleDamage;
use style::properties::ComputedValues; use style::properties::{ComputedValues, TComputedValues};
bitflags! { bitflags! {
#[doc = "Individual layout actions that may be necessary after restyling."] #[doc = "Individual layout actions that may be necessary after restyling."]
@ -53,6 +53,7 @@ bitflags! {
} }
impl TRestyleDamage for RestyleDamage { impl TRestyleDamage for RestyleDamage {
type ConcreteComputedValues = ComputedValues;
fn compute(old: Option<&Arc<ComputedValues>>, new: &ComputedValues) -> RestyleDamage { compute_damage(old, new) } fn compute(old: Option<&Arc<ComputedValues>>, new: &ComputedValues) -> RestyleDamage { compute_damage(old, new) }
/// Returns a bitmask that represents a flow that needs to be rebuilt and reflowed. /// Returns a bitmask that represents a flow that needs to be rebuilt and reflowed.

View file

@ -30,7 +30,7 @@ use std::{fmt, isize, mem};
use style::computed_values::{display, overflow_x, position, text_align, text_justify}; use style::computed_values::{display, overflow_x, position, text_align, text_justify};
use style::computed_values::{text_overflow, vertical_align, white_space}; use style::computed_values::{text_overflow, vertical_align, white_space};
use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode}; use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode};
use style::properties::ComputedValues; use style::properties::{ComputedValues, TComputedValues};
use style::values::computed::LengthOrPercentage; use style::values::computed::LengthOrPercentage;
use text; use text;
use unicode_bidi; use unicode_bidi;

View file

@ -73,6 +73,7 @@ use style::error_reporting::ParseErrorReporter;
use style::logical_geometry::LogicalPoint; use style::logical_geometry::LogicalPoint;
use style::media_queries::{Device, MediaType}; use style::media_queries::{Device, MediaType};
use style::parallel::WorkQueueData; use style::parallel::WorkQueueData;
use style::properties::TComputedValues;
use style::selector_impl::ServoSelectorImpl; use style::selector_impl::ServoSelectorImpl;
use style::selector_matching::USER_OR_USER_AGENT_STYLESHEETS; use style::selector_matching::USER_OR_USER_AGENT_STYLESHEETS;
use style::servo::{SharedStyleContext, Stylesheet, Stylist}; use style::servo::{SharedStyleContext, Stylesheet, Stylist};

View file

@ -23,7 +23,7 @@ use inline::InlineMetrics;
use std::sync::Arc; use std::sync::Arc;
use style::computed_values::{list_style_type, position}; use style::computed_values::{list_style_type, position};
use style::logical_geometry::LogicalSize; use style::logical_geometry::LogicalSize;
use style::properties::ComputedValues; use style::properties::{ComputedValues, TComputedValues};
use text; use text;
/// A block with the CSS `display` property equal to `list-item`. /// A block with the CSS `display` property equal to `list-item`.

View file

@ -13,7 +13,7 @@ use std::cmp::{max, min};
use std::fmt; use std::fmt;
use style::computed_values::transform::ComputedMatrix; use style::computed_values::transform::ComputedMatrix;
use style::logical_geometry::LogicalMargin; use style::logical_geometry::LogicalMargin;
use style::properties::ComputedValues; use style::properties::{ComputedValues, TComputedValues};
use style::values::computed::{BorderRadiusSize, LengthOrPercentageOrAuto}; use style::values::computed::{BorderRadiusSize, LengthOrPercentageOrAuto};
use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrNone}; use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrNone};

View file

@ -21,7 +21,7 @@ use std::fmt;
use std::sync::Arc; use std::sync::Arc;
use style::context::StyleContext; use style::context::StyleContext;
use style::logical_geometry::LogicalSize; use style::logical_geometry::LogicalSize;
use style::properties::ComputedValues; use style::properties::{ComputedValues, TComputedValues};
use style::values::computed::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone}; use style::values::computed::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone};
use util::print_tree::PrintTree; use util::print_tree::PrintTree;

View file

@ -27,6 +27,7 @@ use std::sync::{Arc, Mutex};
use string_cache::Atom; use string_cache::Atom;
use style::computed_values; use style::computed_values;
use style::logical_geometry::{WritingMode, BlockFlowDirection, InlineBaseDirection}; use style::logical_geometry::{WritingMode, BlockFlowDirection, InlineBaseDirection};
use style::properties::TComputedValues;
use style::properties::longhands::{display, position}; use style::properties::longhands::{display, position};
use style::properties::style_structs; use style::properties::style_structs;
use style::selector_impl::PseudoElement; use style::selector_impl::PseudoElement;

View file

@ -25,7 +25,7 @@ use std::fmt;
use std::sync::Arc; use std::sync::Arc;
use style::computed_values::{border_collapse, border_spacing, table_layout}; use style::computed_values::{border_collapse, border_spacing, table_layout};
use style::logical_geometry::LogicalSize; use style::logical_geometry::LogicalSize;
use style::properties::ComputedValues; use style::properties::{ComputedValues, TComputedValues};
use style::values::CSSFloat; use style::values::CSSFloat;
use style::values::computed::LengthOrPercentageOrAuto; use style::values::computed::LengthOrPercentageOrAuto;
use table_row::{TableRowFlow}; use table_row::{TableRowFlow};

View file

@ -17,7 +17,7 @@ use gfx::display_list::{StackingContext, StackingContextId};
use std::fmt; use std::fmt;
use std::sync::Arc; use std::sync::Arc;
use style::logical_geometry::LogicalSize; use style::logical_geometry::LogicalSize;
use style::properties::ComputedValues; use style::properties::{ComputedValues, TComputedValues};
use util::print_tree::PrintTree; use util::print_tree::PrintTree;
/// A table formatting context. /// A table formatting context.

View file

@ -21,7 +21,7 @@ use std::fmt;
use std::sync::Arc; use std::sync::Arc;
use style::computed_values::{border_collapse, border_top_style}; use style::computed_values::{border_collapse, border_top_style};
use style::logical_geometry::{LogicalMargin, LogicalRect, LogicalSize, WritingMode}; use style::logical_geometry::{LogicalMargin, LogicalRect, LogicalSize, WritingMode};
use style::properties::ComputedValues; use style::properties::{ComputedValues, TComputedValues};
use table::InternalTable; use table::InternalTable;
use table_row::{CollapsedBorder, CollapsedBorderProvenance}; use table_row::{CollapsedBorder, CollapsedBorderProvenance};
use util::print_tree::PrintTree; use util::print_tree::PrintTree;

View file

@ -18,7 +18,7 @@ use std::cmp::max;
use std::fmt; use std::fmt;
use std::sync::Arc; use std::sync::Arc;
use style::logical_geometry::LogicalSize; use style::logical_geometry::LogicalSize;
use style::properties::ComputedValues; use style::properties::{ComputedValues, TComputedValues};
use style::values::computed::LengthOrPercentageOrAuto; use style::values::computed::LengthOrPercentageOrAuto;
/// A table formatting context. /// A table formatting context.

View file

@ -25,7 +25,7 @@ use std::iter::{Enumerate, IntoIterator, Peekable};
use std::sync::Arc; use std::sync::Arc;
use style::computed_values::{border_collapse, border_spacing, border_top_style}; use style::computed_values::{border_collapse, border_spacing, border_top_style};
use style::logical_geometry::{LogicalSize, PhysicalSide, WritingMode}; use style::logical_geometry::{LogicalSize, PhysicalSide, WritingMode};
use style::properties::ComputedValues; use style::properties::{ComputedValues, TComputedValues};
use style::values::computed::LengthOrPercentageOrAuto; use style::values::computed::LengthOrPercentageOrAuto;
use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize, InternalTable, VecExt}; use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize, InternalTable, VecExt};
use table_cell::{CollapsedBordersForCell, TableCellFlow}; use table_cell::{CollapsedBordersForCell, TableCellFlow};

View file

@ -21,7 +21,7 @@ use std::iter::{IntoIterator, Iterator, Peekable};
use std::sync::Arc; use std::sync::Arc;
use style::computed_values::{border_collapse, border_spacing}; use style::computed_values::{border_collapse, border_spacing};
use style::logical_geometry::{LogicalSize, WritingMode}; use style::logical_geometry::{LogicalSize, WritingMode};
use style::properties::ComputedValues; use style::properties::{ComputedValues, TComputedValues};
use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize, InternalTable, TableLikeFlow}; use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize, InternalTable, TableLikeFlow};
use table_row; use table_row;
use util::print_tree::PrintTree; use util::print_tree::PrintTree;

View file

@ -31,7 +31,7 @@ use std::ops::Add;
use std::sync::Arc; use std::sync::Arc;
use style::computed_values::{border_collapse, table_layout}; use style::computed_values::{border_collapse, table_layout};
use style::logical_geometry::LogicalSize; use style::logical_geometry::LogicalSize;
use style::properties::ComputedValues; use style::properties::{ComputedValues, TComputedValues};
use style::values::CSSFloat; use style::values::CSSFloat;
use style::values::computed::LengthOrPercentageOrAuto; use style::values::computed::LengthOrPercentageOrAuto;
use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize}; use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize};

View file

@ -23,8 +23,8 @@ use std::sync::Arc;
use style::computed_values::{line_height, text_orientation, text_rendering, text_transform}; use style::computed_values::{line_height, text_orientation, text_rendering, text_transform};
use style::computed_values::{white_space}; use style::computed_values::{white_space};
use style::logical_geometry::{LogicalSize, WritingMode}; use style::logical_geometry::{LogicalSize, WritingMode};
use style::properties::ComputedValues;
use style::properties::style_structs::Font as FontStyle; use style::properties::style_structs::Font as FontStyle;
use style::properties::{ComputedValues, TComputedValues};
use unicode_bidi::{is_rtl, process_text}; use unicode_bidi::{is_rtl, process_text};
use unicode_script::{get_script, Script}; use unicode_script::{get_script, Script};
use util::linked_list::split_off_head; use util::linked_list::split_off_head;

View file

@ -15,7 +15,7 @@ use flow::{self, Flow, CAN_BE_FRAGMENTED};
use gfx::display_list::OpaqueNode; use gfx::display_list::OpaqueNode;
use incremental::{BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW, REPAINT, RestyleDamage}; use incremental::{BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW, REPAINT, RestyleDamage};
use std::mem; use std::mem;
use style::context::{StyleContext, ReflowGoal}; use style::context::StyleContext;
use style::matching::MatchMethods; use style::matching::MatchMethods;
use style::traversal::{DomTraversalContext, STYLE_BLOOM}; use style::traversal::{DomTraversalContext, STYLE_BLOOM};
use style::traversal::{put_thread_local_bloom_filter, recalc_style_at}; use style::traversal::{put_thread_local_bloom_filter, recalc_style_at};

View file

@ -66,7 +66,7 @@ use style::computed_values::content::ContentItem;
use style::computed_values::{content, display}; use style::computed_values::{content, display};
use style::dom::{TDocument, TElement, TNode, UnsafeNode}; use style::dom::{TDocument, TElement, TNode, UnsafeNode};
use style::element_state::*; use style::element_state::*;
use style::properties::ComputedValues; use style::properties::{ComputedValues, TComputedValues};
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock}; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock};
use style::restyle_hints::ElementSnapshot; use style::restyle_hints::ElementSnapshot;
use style::selector_impl::{NonTSPseudoClass, PseudoElement, ServoSelectorImpl}; use style::selector_impl::{NonTSPseudoClass, PseudoElement, ServoSelectorImpl};
@ -131,6 +131,7 @@ impl<'ln> ServoLayoutNode<'ln> {
} }
impl<'ln> TNode for ServoLayoutNode<'ln> { impl<'ln> TNode for ServoLayoutNode<'ln> {
type ConcreteComputedValues = ComputedValues;
type ConcreteElement = ServoLayoutElement<'ln>; type ConcreteElement = ServoLayoutElement<'ln>;
type ConcreteDocument = ServoLayoutDocument<'ln>; type ConcreteDocument = ServoLayoutDocument<'ln>;
type ConcreteRestyleDamage = RestyleDamage; type ConcreteRestyleDamage = RestyleDamage;

View file

@ -24,6 +24,7 @@ use properties::longhands::transition_timing_function::computed_value::{Transiti
use properties::longhands::vertical_align::computed_value::T as VerticalAlign; use properties::longhands::vertical_align::computed_value::T as VerticalAlign;
use properties::longhands::visibility::computed_value::T as Visibility; use properties::longhands::visibility::computed_value::T as Visibility;
use properties::longhands::z_index::computed_value::T as ZIndex; use properties::longhands::z_index::computed_value::T as ZIndex;
use properties::style_struct_traits::TAnimation;
use properties::{ComputedValues, TComputedValues}; use properties::{ComputedValues, TComputedValues};
use std::cmp::Ordering; use std::cmp::Ordering;
use std::iter::repeat; use std::iter::repeat;
@ -73,7 +74,7 @@ impl PropertyAnimation {
-> Vec<PropertyAnimation> { -> Vec<PropertyAnimation> {
let mut result = Vec::new(); let mut result = Vec::new();
let transition_property = let transition_property =
new_style.get_animation().transition_property.0[transition_index]; new_style.as_servo().get_animation().transition_property.0[transition_index];
if transition_property != TransitionProperty::All { if transition_property != TransitionProperty::All {
if let Some(property_animation) = if let Some(property_animation) =
PropertyAnimation::from_transition_property(transition_property, PropertyAnimation::from_transition_property(transition_property,
@ -929,22 +930,22 @@ impl<T> GetMod for Vec<T> {
/// Inserts transitions into the queue of running animations as applicable for the given style /// Inserts transitions into the queue of running animations as applicable for the given style
/// difference. This is called from the layout worker threads. Returns true if any animations were /// difference. This is called from the layout worker threads. Returns true if any animations were
/// kicked off and false otherwise. /// kicked off and false otherwise.
pub fn start_transitions_if_applicable(new_animations_sender: &Mutex<Sender<Animation>>, pub fn start_transitions_if_applicable<C: TComputedValues>(new_animations_sender: &Mutex<Sender<Animation>>,
node: OpaqueNode, node: OpaqueNode,
old_style: &ComputedValues, old_style: &C,
new_style: &mut ComputedValues) new_style: &mut C)
-> bool { -> bool {
let mut had_animations = false; let mut had_animations = false;
for i in 0..new_style.get_animation().transition_property.0.len() { for i in 0..new_style.get_animation().transition_count() {
// Create any property animations, if applicable. // Create any property animations, if applicable.
let property_animations = PropertyAnimation::from_transition(i, old_style, new_style); let property_animations = PropertyAnimation::from_transition(i, old_style.as_servo(), new_style.as_servo_mut());
for property_animation in property_animations { for property_animation in property_animations {
// Set the property to the initial value. // Set the property to the initial value.
property_animation.update(new_style, 0.0); property_animation.update(new_style.as_servo_mut(), 0.0);
// Kick off the animation. // Kick off the animation.
let now = time::precise_time_s(); let now = time::precise_time_s();
let animation_style = new_style.get_animation(); let animation_style = new_style.as_servo().get_animation();
let start_time = let start_time =
now + (animation_style.transition_delay.0.get_mod(i).seconds() as f64); now + (animation_style.transition_delay.0.get_mod(i).seconds() as f64);
new_animations_sender.lock().unwrap().send(Animation { new_animations_sender.lock().unwrap().send(Animation {
@ -964,9 +965,10 @@ pub fn start_transitions_if_applicable(new_animations_sender: &Mutex<Sender<Anim
/// Updates a single animation and associated style based on the current time. If `damage` is /// Updates a single animation and associated style based on the current time. If `damage` is
/// provided, inserts the appropriate restyle damage. /// provided, inserts the appropriate restyle damage.
pub fn update_style_for_animation<ConcreteRestyleDamage: TRestyleDamage>(animation: &Animation, pub fn update_style_for_animation<C: TComputedValues,
style: &mut Arc<ComputedValues>, Damage: TRestyleDamage<ConcreteComputedValues=C>>(animation: &Animation,
damage: Option<&mut ConcreteRestyleDamage>) { style: &mut Arc<C>,
damage: Option<&mut Damage>) {
let now = time::precise_time_s(); let now = time::precise_time_s();
let mut progress = (now - animation.start_time) / animation.duration(); let mut progress = (now - animation.start_time) / animation.duration();
if progress > 1.0 { if progress > 1.0 {
@ -977,9 +979,9 @@ pub fn update_style_for_animation<ConcreteRestyleDamage: TRestyleDamage>(animati
} }
let mut new_style = (*style).clone(); let mut new_style = (*style).clone();
animation.property_animation.update(&mut *Arc::make_mut(&mut new_style), progress); animation.property_animation.update(Arc::make_mut(&mut new_style).as_servo_mut(), progress);
if let Some(damage) = damage { if let Some(damage) = damage {
*damage = *damage | ConcreteRestyleDamage::compute(Some(style), &new_style); *damage = *damage | Damage::compute(Some(style), &new_style);
} }
*style = new_style *style = new_style

View file

@ -8,6 +8,7 @@ use dom::OpaqueNode;
use error_reporting::ParseErrorReporter; use error_reporting::ParseErrorReporter;
use euclid::Size2D; use euclid::Size2D;
use matching::{ApplicableDeclarationsCache, StyleSharingCandidateCache}; use matching::{ApplicableDeclarationsCache, StyleSharingCandidateCache};
use properties::TComputedValues;
use selector_impl::SelectorImplExt; use selector_impl::SelectorImplExt;
use selector_matching::Stylist; use selector_matching::Stylist;
use std::cell::RefCell; use std::cell::RefCell;
@ -54,15 +55,15 @@ pub struct SharedStyleContext<Impl: SelectorImplExt> {
pub error_reporter: Box<ParseErrorReporter + Sync>, pub error_reporter: Box<ParseErrorReporter + Sync>,
} }
pub struct LocalStyleContext { pub struct LocalStyleContext<C: TComputedValues> {
pub applicable_declarations_cache: RefCell<ApplicableDeclarationsCache>, pub applicable_declarations_cache: RefCell<ApplicableDeclarationsCache<C>>,
pub style_sharing_candidate_cache: RefCell<StyleSharingCandidateCache>, pub style_sharing_candidate_cache: RefCell<StyleSharingCandidateCache<C>>,
} }
pub trait StyleContext<'a, Impl: SelectorImplExt> { pub trait StyleContext<'a, Impl: SelectorImplExt, C: TComputedValues> {
fn shared_context(&self) -> &'a SharedStyleContext<Impl>; fn shared_context(&self) -> &'a SharedStyleContext<Impl>;
fn local_context(&self) -> &LocalStyleContext; fn local_context(&self) -> &LocalStyleContext<C>;
} }
/// Why we're doing reflow. /// Why we're doing reflow.

View file

@ -2,26 +2,28 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use properties::ComputedValues; use properties::TComputedValues;
use selectors::parser::SelectorImpl; use selectors::parser::SelectorImpl;
use std::collections::HashMap; use std::collections::HashMap;
use std::hash::BuildHasherDefault; use std::hash::BuildHasherDefault;
use std::sync::Arc; use std::sync::Arc;
use std::sync::atomic::AtomicIsize; use std::sync::atomic::AtomicIsize;
pub struct PrivateStyleData<Impl: SelectorImpl> { pub struct PrivateStyleData<Impl: SelectorImpl, ConcreteComputedValues: TComputedValues> {
/// The results of CSS styling for this node. /// The results of CSS styling for this node.
pub style: Option<Arc<ComputedValues>>, pub style: Option<Arc<ConcreteComputedValues>>,
/// The results of CSS styling for each pseudo-element (if any). /// The results of CSS styling for each pseudo-element (if any).
pub per_pseudo: HashMap<Impl::PseudoElement, Arc<ComputedValues>, BuildHasherDefault<::fnv::FnvHasher>>, pub per_pseudo: HashMap<Impl::PseudoElement, Arc<ConcreteComputedValues>,
BuildHasherDefault<::fnv::FnvHasher>>,
/// Information needed during parallel traversals. /// Information needed during parallel traversals.
pub parallel: DomParallelInfo, pub parallel: DomParallelInfo,
} }
impl<Impl: SelectorImpl> PrivateStyleData<Impl> { impl<Impl, ConcreteComputedValues> PrivateStyleData<Impl, ConcreteComputedValues>
pub fn new() -> PrivateStyleData<Impl> { where Impl: SelectorImpl, ConcreteComputedValues: TComputedValues {
pub fn new() -> PrivateStyleData<Impl, ConcreteComputedValues> {
PrivateStyleData { PrivateStyleData {
style: None, style: None,
per_pseudo: HashMap::with_hasher(Default::default()), per_pseudo: HashMap::with_hasher(Default::default()),

View file

@ -6,7 +6,7 @@
use data::PrivateStyleData; use data::PrivateStyleData;
use element_state::ElementState; use element_state::ElementState;
use properties::{ComputedValues, PropertyDeclaration, PropertyDeclarationBlock}; use properties::{PropertyDeclaration, PropertyDeclarationBlock, TComputedValues};
use restyle_hints::{ElementSnapshot, RESTYLE_DESCENDANTS, RESTYLE_LATER_SIBLINGS, RESTYLE_SELF, RestyleHint}; use restyle_hints::{ElementSnapshot, RESTYLE_DESCENDANTS, RESTYLE_LATER_SIBLINGS, RESTYLE_SELF, RestyleHint};
use selector_impl::ElementExt; use selector_impl::ElementExt;
use selectors::Element; use selectors::Element;
@ -43,14 +43,16 @@ impl OpaqueNode {
} }
pub trait TRestyleDamage : BitOr<Output=Self> + Copy { pub trait TRestyleDamage : BitOr<Output=Self> + Copy {
fn compute(old: Option<&Arc<ComputedValues>>, new: &ComputedValues) -> Self; type ConcreteComputedValues: TComputedValues;
fn compute(old: Option<&Arc<Self::ConcreteComputedValues>>, new: &Self::ConcreteComputedValues) -> Self;
fn rebuild_and_reflow() -> Self; fn rebuild_and_reflow() -> Self;
} }
pub trait TNode : Sized + Copy + Clone { pub trait TNode : Sized + Copy + Clone {
type ConcreteElement: TElement<ConcreteNode = Self, ConcreteDocument = Self::ConcreteDocument>; type ConcreteElement: TElement<ConcreteNode = Self, ConcreteDocument = Self::ConcreteDocument>;
type ConcreteDocument: TDocument<ConcreteNode = Self, ConcreteElement = Self::ConcreteElement>; type ConcreteDocument: TDocument<ConcreteNode = Self, ConcreteElement = Self::ConcreteElement>;
type ConcreteRestyleDamage: TRestyleDamage; type ConcreteRestyleDamage: TRestyleDamage<ConcreteComputedValues = Self::ConcreteComputedValues>;
type ConcreteComputedValues: TComputedValues;
fn to_unsafe(&self) -> UnsafeNode; fn to_unsafe(&self) -> UnsafeNode;
unsafe fn from_unsafe(n: &UnsafeNode) -> Self; unsafe fn from_unsafe(n: &UnsafeNode) -> Self;
@ -135,17 +137,20 @@ pub trait TNode : Sized + Copy + Clone {
/// Borrows the PrivateStyleData without checks. /// Borrows the PrivateStyleData without checks.
#[inline(always)] #[inline(always)]
unsafe fn borrow_data_unchecked(&self) unsafe fn borrow_data_unchecked(&self)
-> Option<*const PrivateStyleData<<Self::ConcreteElement as Element>::Impl>>; -> Option<*const PrivateStyleData<<Self::ConcreteElement as Element>::Impl,
Self::ConcreteComputedValues>>;
/// Borrows the PrivateStyleData immutably. Fails on a conflicting borrow. /// Borrows the PrivateStyleData immutably. Fails on a conflicting borrow.
#[inline(always)] #[inline(always)]
fn borrow_data(&self) fn borrow_data(&self)
-> Option<Ref<PrivateStyleData<<Self::ConcreteElement as Element>::Impl>>>; -> Option<Ref<PrivateStyleData<<Self::ConcreteElement as Element>::Impl,
Self::ConcreteComputedValues>>>;
/// Borrows the PrivateStyleData mutably. Fails on a conflicting borrow. /// Borrows the PrivateStyleData mutably. Fails on a conflicting borrow.
#[inline(always)] #[inline(always)]
fn mutate_data(&self) fn mutate_data(&self)
-> Option<RefMut<PrivateStyleData<<Self::ConcreteElement as Element>::Impl>>>; -> Option<RefMut<PrivateStyleData<<Self::ConcreteElement as Element>::Impl,
Self::ConcreteComputedValues>>>;
/// Get the description of how to account for recent style changes. /// Get the description of how to account for recent style changes.
fn restyle_damage(self) -> Self::ConcreteRestyleDamage; fn restyle_damage(self) -> Self::ConcreteRestyleDamage;
@ -166,7 +171,7 @@ pub trait TNode : Sized + Copy + Clone {
/// Returns the style results for the given node. If CSS selector matching /// Returns the style results for the given node. If CSS selector matching
/// has not yet been performed, fails. /// has not yet been performed, fails.
fn style(&self) -> Ref<Arc<ComputedValues>> { fn style(&self) -> Ref<Arc<Self::ConcreteComputedValues>> {
Ref::map(self.borrow_data().unwrap(), |data| data.style.as_ref().unwrap()) Ref::map(self.borrow_data().unwrap(), |data| data.style.as_ref().unwrap())
} }

View file

@ -8,8 +8,8 @@ use animation::{self, Animation};
use context::SharedStyleContext; use context::SharedStyleContext;
use data::PrivateStyleData; use data::PrivateStyleData;
use dom::{TElement, TNode, TRestyleDamage}; use dom::{TElement, TNode, TRestyleDamage};
use properties::{ComputedValues, PropertyDeclaration, TComputedValues, cascade}; use properties::{PropertyDeclaration, TComputedValues, cascade};
use selector_impl::SelectorImplExt; use selector_impl::{ElementExt, SelectorImplExt};
use selector_matching::{DeclarationBlock, Stylist}; use selector_matching::{DeclarationBlock, Stylist};
use selectors::Element; use selectors::Element;
use selectors::bloom::BloomFilter; use selectors::bloom::BloomFilter;
@ -151,25 +151,25 @@ impl<'a> Hash for ApplicableDeclarationsCacheQuery<'a> {
static APPLICABLE_DECLARATIONS_CACHE_SIZE: usize = 32; static APPLICABLE_DECLARATIONS_CACHE_SIZE: usize = 32;
pub struct ApplicableDeclarationsCache { pub struct ApplicableDeclarationsCache<C: TComputedValues> {
cache: SimpleHashCache<ApplicableDeclarationsCacheEntry, Arc<ComputedValues>>, cache: SimpleHashCache<ApplicableDeclarationsCacheEntry, Arc<C>>,
} }
impl ApplicableDeclarationsCache { impl<C: TComputedValues> ApplicableDeclarationsCache<C> {
pub fn new() -> ApplicableDeclarationsCache { pub fn new() -> Self {
ApplicableDeclarationsCache { ApplicableDeclarationsCache {
cache: SimpleHashCache::new(APPLICABLE_DECLARATIONS_CACHE_SIZE), cache: SimpleHashCache::new(APPLICABLE_DECLARATIONS_CACHE_SIZE),
} }
} }
pub fn find(&self, declarations: &[DeclarationBlock]) -> Option<Arc<ComputedValues>> { pub fn find(&self, declarations: &[DeclarationBlock]) -> Option<Arc<C>> {
match self.cache.find(&ApplicableDeclarationsCacheQuery::new(declarations)) { match self.cache.find(&ApplicableDeclarationsCacheQuery::new(declarations)) {
None => None, None => None,
Some(ref values) => Some((*values).clone()), Some(ref values) => Some((*values).clone()),
} }
} }
pub fn insert(&mut self, declarations: Vec<DeclarationBlock>, style: Arc<ComputedValues>) { pub fn insert(&mut self, declarations: Vec<DeclarationBlock>, style: Arc<C>) {
self.cache.insert(ApplicableDeclarationsCacheEntry::new(declarations), style) self.cache.insert(ApplicableDeclarationsCacheEntry::new(declarations), style)
} }
@ -179,14 +179,14 @@ impl ApplicableDeclarationsCache {
} }
/// An LRU cache of the last few nodes seen, so that we can aggressively try to reuse their styles. /// An LRU cache of the last few nodes seen, so that we can aggressively try to reuse their styles.
pub struct StyleSharingCandidateCache { pub struct StyleSharingCandidateCache<C: TComputedValues> {
cache: LRUCache<StyleSharingCandidate, ()>, cache: LRUCache<StyleSharingCandidate<C>, ()>,
} }
#[derive(Clone)] #[derive(Clone)]
pub struct StyleSharingCandidate { pub struct StyleSharingCandidate<C: TComputedValues> {
pub style: Arc<ComputedValues>, pub style: Arc<C>,
pub parent_style: Arc<ComputedValues>, pub parent_style: Arc<C>,
pub local_name: Atom, pub local_name: Atom,
// FIXME(pcwalton): Should be a list of atoms instead. // FIXME(pcwalton): Should be a list of atoms instead.
pub class: Option<String>, pub class: Option<String>,
@ -195,8 +195,8 @@ pub struct StyleSharingCandidate {
pub link: bool, pub link: bool,
} }
impl PartialEq for StyleSharingCandidate { impl<C: TComputedValues> PartialEq for StyleSharingCandidate<C> {
fn eq(&self, other: &StyleSharingCandidate) -> bool { fn eq(&self, other: &Self) -> bool {
arc_ptr_eq(&self.style, &other.style) && arc_ptr_eq(&self.style, &other.style) &&
arc_ptr_eq(&self.parent_style, &other.parent_style) && arc_ptr_eq(&self.parent_style, &other.parent_style) &&
self.local_name == other.local_name && self.local_name == other.local_name &&
@ -207,12 +207,12 @@ impl PartialEq for StyleSharingCandidate {
} }
} }
impl StyleSharingCandidate { impl<C: TComputedValues> StyleSharingCandidate<C> {
/// Attempts to create a style sharing candidate from this node. Returns /// Attempts to create a style sharing candidate from this node. Returns
/// the style sharing candidate or `None` if this node is ineligible for /// the style sharing candidate or `None` if this node is ineligible for
/// style sharing. /// style sharing.
#[allow(unsafe_code)] #[allow(unsafe_code)]
fn new<E: TElement>(element: &E) -> Option<StyleSharingCandidate> { fn new<N: TNode<ConcreteComputedValues=C>>(element: &N::ConcreteElement) -> Option<Self> {
let parent_element = match element.parent_element() { let parent_element = match element.parent_element() {
None => return None, None => return None,
Some(parent_element) => parent_element, Some(parent_element) => parent_element,
@ -254,7 +254,7 @@ impl StyleSharingCandidate {
link: element.is_link(), link: element.is_link(),
namespace: (*element.get_namespace()).clone(), namespace: (*element.get_namespace()).clone(),
common_style_affecting_attributes: common_style_affecting_attributes:
create_common_style_affecting_attributes_from_element::<E>(&element) create_common_style_affecting_attributes_from_element::<N::ConcreteElement>(&element)
}) })
} }
@ -332,19 +332,19 @@ impl StyleSharingCandidate {
static STYLE_SHARING_CANDIDATE_CACHE_SIZE: usize = 40; static STYLE_SHARING_CANDIDATE_CACHE_SIZE: usize = 40;
impl StyleSharingCandidateCache { impl<C: TComputedValues> StyleSharingCandidateCache<C> {
pub fn new() -> StyleSharingCandidateCache { pub fn new() -> Self {
StyleSharingCandidateCache { StyleSharingCandidateCache {
cache: LRUCache::new(STYLE_SHARING_CANDIDATE_CACHE_SIZE), cache: LRUCache::new(STYLE_SHARING_CANDIDATE_CACHE_SIZE),
} }
} }
pub fn iter(&self) -> Iter<(StyleSharingCandidate, ())> { pub fn iter(&self) -> Iter<(StyleSharingCandidate<C>, ())> {
self.cache.iter() self.cache.iter()
} }
pub fn insert_if_possible<E: TElement>(&mut self, element: &E) { pub fn insert_if_possible<N: TNode<ConcreteComputedValues=C>>(&mut self, element: &N::ConcreteElement) {
match StyleSharingCandidate::new(element) { match StyleSharingCandidate::new::<N>(element) {
None => {} None => {}
Some(candidate) => self.cache.insert(candidate, ()) Some(candidate) => self.cache.insert(candidate, ())
} }
@ -368,15 +368,15 @@ trait PrivateMatchMethods: TNode
where <Self::ConcreteElement as Element>::Impl: SelectorImplExt { where <Self::ConcreteElement as Element>::Impl: SelectorImplExt {
fn cascade_node_pseudo_element(&self, fn cascade_node_pseudo_element(&self,
context: &SharedStyleContext<<Self::ConcreteElement as Element>::Impl>, context: &SharedStyleContext<<Self::ConcreteElement as Element>::Impl>,
parent_style: Option<&Arc<ComputedValues>>, parent_style: Option<&Arc<Self::ConcreteComputedValues>>,
applicable_declarations: &[DeclarationBlock], applicable_declarations: &[DeclarationBlock],
mut style: Option<&mut Arc<ComputedValues>>, mut style: Option<&mut Arc<Self::ConcreteComputedValues>>,
applicable_declarations_cache: applicable_declarations_cache:
&mut ApplicableDeclarationsCache, &mut ApplicableDeclarationsCache<Self::ConcreteComputedValues>,
new_animations_sender: &Mutex<Sender<Animation>>, new_animations_sender: &Mutex<Sender<Animation>>,
shareable: bool, shareable: bool,
animate_properties: bool) animate_properties: bool)
-> (Self::ConcreteRestyleDamage, Arc<ComputedValues>) { -> (Self::ConcreteRestyleDamage, Arc<Self::ConcreteComputedValues>) {
let mut cacheable = true; let mut cacheable = true;
if animate_properties { if animate_properties {
cacheable = !self.update_animations_for_cascade(context, &mut style) && cacheable; cacheable = !self.update_animations_for_cascade(context, &mut style) && cacheable;
@ -416,10 +416,11 @@ trait PrivateMatchMethods: TNode
if animate_properties { if animate_properties {
if let Some(ref style) = style { if let Some(ref style) = style {
let animations_started = let animations_started =
animation::start_transitions_if_applicable(new_animations_sender, animation::start_transitions_if_applicable::<Self::ConcreteComputedValues>(
self.opaque(), new_animations_sender,
&**style, self.opaque(),
&mut this_style); &**style,
&mut this_style);
cacheable = cacheable && !animations_started cacheable = cacheable && !animations_started
} }
} }
@ -440,7 +441,7 @@ trait PrivateMatchMethods: TNode
fn update_animations_for_cascade(&self, fn update_animations_for_cascade(&self,
context: &SharedStyleContext<<Self::ConcreteElement as Element>::Impl>, context: &SharedStyleContext<<Self::ConcreteElement as Element>::Impl>,
style: &mut Option<&mut Arc<ComputedValues>>) style: &mut Option<&mut Arc<Self::ConcreteComputedValues>>)
-> bool { -> bool {
let style = match *style { let style = match *style {
None => return false, None => return false,
@ -456,7 +457,7 @@ trait PrivateMatchMethods: TNode
had_animations_to_expire = animations_to_expire.is_some(); had_animations_to_expire = animations_to_expire.is_some();
if let Some(ref animations) = animations_to_expire { if let Some(ref animations) = animations_to_expire {
for animation in *animations { for animation in *animations {
animation.property_animation.update(&mut *Arc::make_mut(style), 1.0); animation.property_animation.update(Arc::make_mut(style).as_servo_mut(), 1.0);
} }
} }
} }
@ -474,7 +475,8 @@ trait PrivateMatchMethods: TNode
if had_running_animations { if had_running_animations {
let mut all_running_animations = context.running_animations.write().unwrap(); let mut all_running_animations = context.running_animations.write().unwrap();
for running_animation in all_running_animations.get(&this_opaque).unwrap() { for running_animation in all_running_animations.get(&this_opaque).unwrap() {
animation::update_style_for_animation::<Self::ConcreteRestyleDamage>(running_animation, style, None); animation::update_style_for_animation::<Self::ConcreteComputedValues,
Self::ConcreteRestyleDamage>(running_animation, style, None);
} }
all_running_animations.remove(&this_opaque); all_running_animations.remove(&this_opaque);
} }
@ -489,14 +491,15 @@ impl<N: TNode> PrivateMatchMethods for N
trait PrivateElementMatchMethods: TElement { trait PrivateElementMatchMethods: TElement {
fn share_style_with_candidate_if_possible(&self, fn share_style_with_candidate_if_possible(&self,
parent_node: Option<Self::ConcreteNode>, parent_node: Option<Self::ConcreteNode>,
candidate: &StyleSharingCandidate) candidate: &StyleSharingCandidate<<Self::ConcreteNode as
-> Option<Arc<ComputedValues>> { TNode>::ConcreteComputedValues>)
-> Option<Arc<<Self::ConcreteNode as TNode>::ConcreteComputedValues>> {
let parent_node = match parent_node { let parent_node = match parent_node {
Some(ref parent_node) if parent_node.as_element().is_some() => parent_node, Some(ref parent_node) if parent_node.as_element().is_some() => parent_node,
Some(_) | None => return None, Some(_) | None => return None,
}; };
let parent_data: Option<&PrivateStyleData<_>> = unsafe { let parent_data: Option<&PrivateStyleData<_, _>> = unsafe {
parent_node.borrow_data_unchecked().map(|d| &*d) parent_node.borrow_data_unchecked().map(|d| &*d)
}; };
@ -550,7 +553,8 @@ pub trait ElementMatchMethods : TElement
/// guarantee that at the type system level yet. /// guarantee that at the type system level yet.
unsafe fn share_style_if_possible(&self, unsafe fn share_style_if_possible(&self,
style_sharing_candidate_cache: style_sharing_candidate_cache:
&mut StyleSharingCandidateCache, &mut StyleSharingCandidateCache<<Self::ConcreteNode as
TNode>::ConcreteComputedValues>,
parent: Option<Self::ConcreteNode>) parent: Option<Self::ConcreteNode>)
-> StyleSharingResult<<Self::ConcreteNode as TNode>::ConcreteRestyleDamage> { -> StyleSharingResult<<Self::ConcreteNode as TNode>::ConcreteRestyleDamage> {
if opts::get().disable_share_style_cache { if opts::get().disable_share_style_cache {
@ -639,7 +643,8 @@ pub trait MatchMethods : TNode {
context: &SharedStyleContext<<Self::ConcreteElement as Element>::Impl>, context: &SharedStyleContext<<Self::ConcreteElement as Element>::Impl>,
parent: Option<Self>, parent: Option<Self>,
applicable_declarations: &ApplicableDeclarations<<Self::ConcreteElement as Element>::Impl>, applicable_declarations: &ApplicableDeclarations<<Self::ConcreteElement as Element>::Impl>,
applicable_declarations_cache: &mut ApplicableDeclarationsCache, applicable_declarations_cache:
&mut ApplicableDeclarationsCache<Self::ConcreteComputedValues>,
new_animations_sender: &Mutex<Sender<Animation>>) new_animations_sender: &Mutex<Sender<Animation>>)
where <Self::ConcreteElement as Element>::Impl: SelectorImplExt { where <Self::ConcreteElement as Element>::Impl: SelectorImplExt {
// Get our parent's style. This must be unsafe so that we don't touch the parent's // Get our parent's style. This must be unsafe so that we don't touch the parent's

View file

@ -3,13 +3,14 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use context; use context;
use data; use data;
use properties::ComputedValues;
use selector_impl::ServoSelectorImpl; use selector_impl::ServoSelectorImpl;
use selector_matching; use selector_matching;
use stylesheets; use stylesheets;
/// Concrete types for servo Style implementation /// Concrete types for servo Style implementation
pub type Stylesheet = stylesheets::Stylesheet<ServoSelectorImpl>; pub type Stylesheet = stylesheets::Stylesheet<ServoSelectorImpl>;
pub type PrivateStyleData = data::PrivateStyleData<ServoSelectorImpl>; pub type PrivateStyleData = data::PrivateStyleData<ServoSelectorImpl, ComputedValues>;
pub type Stylist = selector_matching::Stylist<ServoSelectorImpl>; pub type Stylist = selector_matching::Stylist<ServoSelectorImpl>;
pub type StylistWrapper = context::StylistWrapper<ServoSelectorImpl>; pub type StylistWrapper = context::StylistWrapper<ServoSelectorImpl>;
pub type SharedStyleContext = context::SharedStyleContext<ServoSelectorImpl>; pub type SharedStyleContext = context::SharedStyleContext<ServoSelectorImpl>;

View file

@ -123,7 +123,7 @@ pub fn recalc_style_at<'a, N, C>(context: &'a C,
root: OpaqueNode, root: OpaqueNode,
node: N) node: N)
where N: TNode, where N: TNode,
C: StyleContext<'a, <N::ConcreteElement as Element>::Impl>, C: StyleContext<'a, <N::ConcreteElement as Element>::Impl, N::ConcreteComputedValues>,
<N::ConcreteElement as Element>::Impl: SelectorImplExt + 'a { <N::ConcreteElement as Element>::Impl: SelectorImplExt + 'a {
// Initialize layout data. // Initialize layout data.
// //
@ -195,7 +195,7 @@ pub fn recalc_style_at<'a, N, C>(context: &'a C,
// Add ourselves to the LRU cache. // Add ourselves to the LRU cache.
if let Some(element) = shareable_element { if let Some(element) = shareable_element {
style_sharing_candidate_cache.insert_if_possible(&element); style_sharing_candidate_cache.insert_if_possible::<'ln, N>(&element);
} }
} }
StyleSharingResult::StyleWasShared(index, damage) => { StyleSharingResult::StyleWasShared(index, damage) => {

View file

@ -37,6 +37,7 @@ mod bindings;
mod data; mod data;
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub mod glue; pub mod glue;
mod properties;
mod selector_impl; mod selector_impl;
mod traversal; mod traversal;
mod wrapper; mod wrapper;

View file

@ -0,0 +1,8 @@
/* 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 style::properties::ComputedValues;
// FIXME(bholley): Create and use an actual Gecko type here.
pub type GeckoComputedValues = ComputedValues;

View file

@ -7,6 +7,7 @@ use std::process;
use style; use style;
use style::element_state::ElementState; use style::element_state::ElementState;
use style::error_reporting::StdoutErrorReporter; use style::error_reporting::StdoutErrorReporter;
use style::properties::ComputedValues;
use style::selector_impl::SelectorImplExt; use style::selector_impl::SelectorImplExt;
use style::stylesheets::Origin; use style::stylesheets::Origin;
use url::Url; use url::Url;
@ -14,7 +15,7 @@ use url::Url;
pub type Stylist = style::selector_matching::Stylist<GeckoSelectorImpl>; pub type Stylist = style::selector_matching::Stylist<GeckoSelectorImpl>;
pub type Stylesheet = style::stylesheets::Stylesheet<GeckoSelectorImpl>; pub type Stylesheet = style::stylesheets::Stylesheet<GeckoSelectorImpl>;
pub type SharedStyleContext = style::context::SharedStyleContext<GeckoSelectorImpl>; pub type SharedStyleContext = style::context::SharedStyleContext<GeckoSelectorImpl>;
pub type PrivateStyleData = style::data::PrivateStyleData<GeckoSelectorImpl>; pub type PrivateStyleData = style::data::PrivateStyleData<GeckoSelectorImpl, ComputedValues>;
pub struct GeckoSelectorImpl; pub struct GeckoSelectorImpl;

View file

@ -2,20 +2,23 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use properties::GeckoComputedValues;
use selector_impl::{GeckoSelectorImpl, SharedStyleContext}; use selector_impl::{GeckoSelectorImpl, SharedStyleContext};
use std::cell::RefCell; use std::cell::RefCell;
use std::mem; use std::mem;
use std::rc::Rc; use std::rc::Rc;
use style::context::{LocalStyleContext, StyleContext}; use style::context::{LocalStyleContext, StyleContext};
use style::dom::{OpaqueNode, TNode}; use style::dom::OpaqueNode;
use style::matching::{ApplicableDeclarationsCache, StyleSharingCandidateCache}; use style::matching::{ApplicableDeclarationsCache, StyleSharingCandidateCache};
use style::traversal::{DomTraversalContext, recalc_style_at}; use style::traversal::{DomTraversalContext, recalc_style_at};
use wrapper::GeckoNode;
thread_local!(static LOCAL_CONTEXT_KEY: RefCell<Option<Rc<LocalStyleContext>>> = RefCell::new(None)); thread_local!(static LOCAL_CONTEXT_KEY:
RefCell<Option<Rc<LocalStyleContext<GeckoComputedValues>>>> = RefCell::new(None));
// Keep this implementation in sync with the one in components/layout/context.rs. // Keep this implementation in sync with the one in components/layout/context.rs.
fn create_or_get_local_context(shared: &SharedStyleContext) fn create_or_get_local_context(shared: &SharedStyleContext)
-> Rc<LocalStyleContext> { -> Rc<LocalStyleContext<GeckoComputedValues>> {
LOCAL_CONTEXT_KEY.with(|r| { LOCAL_CONTEXT_KEY.with(|r| {
let mut r = r.borrow_mut(); let mut r = r.borrow_mut();
if let Some(context) = r.clone() { if let Some(context) = r.clone() {
@ -36,7 +39,7 @@ fn create_or_get_local_context(shared: &SharedStyleContext)
pub struct StandaloneStyleContext<'a> { pub struct StandaloneStyleContext<'a> {
pub shared: &'a SharedStyleContext, pub shared: &'a SharedStyleContext,
cached_local_context: Rc<LocalStyleContext>, cached_local_context: Rc<LocalStyleContext<GeckoComputedValues>>,
} }
impl<'a> StandaloneStyleContext<'a> { impl<'a> StandaloneStyleContext<'a> {
@ -49,12 +52,12 @@ impl<'a> StandaloneStyleContext<'a> {
} }
} }
impl<'a> StyleContext<'a, GeckoSelectorImpl> for StandaloneStyleContext<'a> { impl<'a> StyleContext<'a, GeckoSelectorImpl, GeckoComputedValues> for StandaloneStyleContext<'a> {
fn shared_context(&self) -> &'a SharedStyleContext { fn shared_context(&self) -> &'a SharedStyleContext {
&self.shared &self.shared
} }
fn local_context(&self) -> &LocalStyleContext { fn local_context(&self) -> &LocalStyleContext<GeckoComputedValues> {
&self.cached_local_context &self.cached_local_context
} }
} }
@ -64,8 +67,7 @@ pub struct RecalcStyleOnly<'lc> {
root: OpaqueNode, root: OpaqueNode,
} }
impl<'lc, N: TNode> DomTraversalContext<N> for RecalcStyleOnly<'lc> impl<'lc, 'ln> DomTraversalContext<GeckoNode<'ln>> for RecalcStyleOnly<'lc> {
where N::ConcreteElement: ::selectors::Element<Impl=GeckoSelectorImpl> {
type SharedContext = SharedStyleContext; type SharedContext = SharedStyleContext;
#[allow(unsafe_code)] #[allow(unsafe_code)]
fn new<'a>(shared: &'a Self::SharedContext, root: OpaqueNode) -> Self { fn new<'a>(shared: &'a Self::SharedContext, root: OpaqueNode) -> Self {
@ -78,7 +80,7 @@ impl<'lc, N: TNode> DomTraversalContext<N> for RecalcStyleOnly<'lc>
} }
} }
fn process_preorder(&self, node: N) { recalc_style_at(&self.context, self.root, node); } fn process_preorder(&self, node: GeckoNode<'ln>) { recalc_style_at(&self.context, self.root, node); }
fn process_postorder(&self, _: N) {} fn process_postorder(&self, _: GeckoNode<'ln>) {}
} }

View file

@ -19,6 +19,7 @@ use bindings::{Gecko_LocalName, Gecko_Namespace, Gecko_NodeIsElement, Gecko_SetN
use bindings::{RawGeckoDocument, RawGeckoElement, RawGeckoNode}; use bindings::{RawGeckoDocument, RawGeckoElement, RawGeckoNode};
use bindings::{ServoNodeData}; use bindings::{ServoNodeData};
use libc::uintptr_t; use libc::uintptr_t;
use properties::GeckoComputedValues;
use selector_impl::{GeckoSelectorImpl, NonTSPseudoClass, PrivateStyleData}; use selector_impl::{GeckoSelectorImpl, NonTSPseudoClass, PrivateStyleData};
use selectors::Element; use selectors::Element;
use selectors::matching::DeclarationBlock; use selectors::matching::DeclarationBlock;
@ -35,7 +36,7 @@ use style::dom::{OpaqueNode, TDocument, TElement, TNode, TRestyleDamage, UnsafeN
use style::element_state::ElementState; use style::element_state::ElementState;
#[allow(unused_imports)] // Used in commented-out code. #[allow(unused_imports)] // Used in commented-out code.
use style::error_reporting::StdoutErrorReporter; use style::error_reporting::StdoutErrorReporter;
use style::properties::{ComputedValues, PropertyDeclaration, PropertyDeclarationBlock}; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock};
#[allow(unused_imports)] // Used in commented-out code. #[allow(unused_imports)] // Used in commented-out code.
use style::properties::{parse_style_attribute}; use style::properties::{parse_style_attribute};
use style::restyle_hints::ElementSnapshot; use style::restyle_hints::ElementSnapshot;
@ -78,7 +79,8 @@ impl<'ln> GeckoNode<'ln> {
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub struct DummyRestyleDamage; pub struct DummyRestyleDamage;
impl TRestyleDamage for DummyRestyleDamage { impl TRestyleDamage for DummyRestyleDamage {
fn compute(_: Option<&Arc<ComputedValues>>, _: &ComputedValues) -> Self { DummyRestyleDamage } type ConcreteComputedValues = GeckoComputedValues;
fn compute(_: Option<&Arc<GeckoComputedValues>>, _: &GeckoComputedValues) -> Self { DummyRestyleDamage }
fn rebuild_and_reflow() -> Self { DummyRestyleDamage } fn rebuild_and_reflow() -> Self { DummyRestyleDamage }
} }
impl BitOr for DummyRestyleDamage { impl BitOr for DummyRestyleDamage {
@ -92,6 +94,7 @@ impl<'ln> TNode for GeckoNode<'ln> {
type ConcreteDocument = GeckoDocument<'ln>; type ConcreteDocument = GeckoDocument<'ln>;
type ConcreteElement = GeckoElement<'ln>; type ConcreteElement = GeckoElement<'ln>;
type ConcreteRestyleDamage = DummyRestyleDamage; type ConcreteRestyleDamage = DummyRestyleDamage;
type ConcreteComputedValues = GeckoComputedValues;
fn to_unsafe(&self) -> UnsafeNode { fn to_unsafe(&self) -> UnsafeNode {
(self.node as usize, 0) (self.node as usize, 0)