From c2daea2c9c490b4cd36dfa4a8da094cdd3ff4712 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Thu, 10 Mar 2016 16:17:52 -0800 Subject: [PATCH] Parameterize the rest of the style system on TNode. --- components/layout/block.rs | 2 +- components/layout/construct.rs | 2 +- components/layout/context.rs | 7 +- components/layout/display_list_builder.rs | 2 +- components/layout/flex.rs | 2 +- components/layout/flow.rs | 2 +- components/layout/fragment.rs | 2 +- components/layout/generated_content.rs | 2 +- components/layout/incremental.rs | 3 +- components/layout/inline.rs | 2 +- components/layout/layout_thread.rs | 1 + components/layout/list_item.rs | 2 +- components/layout/model.rs | 2 +- components/layout/multicol.rs | 2 +- components/layout/query.rs | 1 + components/layout/table.rs | 2 +- components/layout/table_caption.rs | 2 +- components/layout/table_cell.rs | 2 +- components/layout/table_colgroup.rs | 2 +- components/layout/table_row.rs | 2 +- components/layout/table_rowgroup.rs | 2 +- components/layout/table_wrapper.rs | 2 +- components/layout/text.rs | 2 +- components/layout/traversal.rs | 2 +- components/layout/wrapper.rs | 3 +- components/style/animation.rs | 32 +++++---- components/style/context.rs | 11 +-- components/style/data.rs | 14 ++-- components/style/dom.rs | 19 ++++-- components/style/matching.rs | 83 ++++++++++++----------- components/style/servo.rs | 3 +- components/style/traversal.rs | 4 +- ports/geckolib/lib.rs | 1 + ports/geckolib/properties.rs | 8 +++ ports/geckolib/selector_impl.rs | 3 +- ports/geckolib/traversal.rs | 22 +++--- ports/geckolib/wrapper.rs | 7 +- 37 files changed, 149 insertions(+), 113 deletions(-) create mode 100644 ports/geckolib/properties.rs diff --git a/components/layout/block.rs b/components/layout/block.rs index 19bb6e71ce2..06f41861425 100644 --- a/components/layout/block.rs +++ b/components/layout/block.rs @@ -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::context::StyleContext; 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::{LengthOrPercentage, LengthOrPercentageOrAuto}; use util::geometry::MAX_RECT; diff --git a/components/layout/construct.rs b/components/layout/construct.rs index 25988b7eb11..aedbeaf04f6 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -45,7 +45,7 @@ use std::sync::atomic::Ordering; use style::computed_values::content::ContentItem; use style::computed_values::{caption_side, display, empty_cells, float, list_style_position}; use style::computed_values::{position}; -use style::properties::{self, ComputedValues}; +use style::properties::{self, ComputedValues, TComputedValues}; use table::TableFlow; use table_caption::TableCaptionFlow; use table_cell::TableCellFlow; diff --git a/components/layout/context.rs b/components/layout/context.rs index 143e78f810e..485ff2d5888 100644 --- a/components/layout/context.rs +++ b/components/layout/context.rs @@ -28,13 +28,14 @@ use std::sync::mpsc::Sender; use std::sync::{Arc, Mutex, RwLock}; use style::context::{LocalStyleContext, StyleContext}; use style::matching::{ApplicableDeclarationsCache, StyleSharingCandidateCache}; +use style::properties::ComputedValues; use style::selector_impl::ServoSelectorImpl; use style::servo::SharedStyleContext; use url::Url; use util::opts; struct LocalLayoutContext { - style_context: LocalStyleContext, + style_context: LocalStyleContext, font_context: RefCell, } @@ -112,12 +113,12 @@ pub struct LayoutContext<'a> { cached_local_layout_context: Rc, } -impl<'a> StyleContext<'a, ServoSelectorImpl> for LayoutContext<'a> { +impl<'a> StyleContext<'a, ServoSelectorImpl, ComputedValues> for LayoutContext<'a> { fn shared_context(&self) -> &'a SharedStyleContext { &self.shared.style_context } - fn local_context(&self) -> &LocalStyleContext { + fn local_context(&self) -> &LocalStyleContext { &self.cached_local_layout_context.style_context } } diff --git a/components/layout/display_list_builder.rs b/components/layout/display_list_builder.rs index 407d4d19a05..c5e160e87b5 100644 --- a/components/layout/display_list_builder.rs +++ b/components/layout/display_list_builder.rs @@ -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::logical_geometry::{LogicalPoint, LogicalRect, LogicalSize, WritingMode}; use style::properties::style_structs::Border; -use style::properties::{self, ComputedValues}; +use style::properties::{self, ComputedValues, TComputedValues}; use style::values::RGBA; use style::values::computed; use style::values::computed::{LengthOrNone, LengthOrPercentage, LengthOrPercentageOrAuto, LinearGradient}; diff --git a/components/layout/flex.rs b/components/layout/flex.rs index b53bb697c49..dbc01b58178 100644 --- a/components/layout/flex.rs +++ b/components/layout/flex.rs @@ -28,8 +28,8 @@ use std::cmp::max; use std::sync::Arc; use style::computed_values::{flex_direction, float}; use style::logical_geometry::LogicalSize; -use style::properties::ComputedValues; use style::properties::style_structs; +use style::properties::{ComputedValues, TComputedValues}; use style::values::computed::LengthOrPercentageOrAuto; // A mode describes which logical axis a flex axis is parallel with. diff --git a/components/layout/flow.rs b/components/layout/flow.rs index b61540dfb3b..dc434ce03f2 100644 --- a/components/layout/flow.rs +++ b/components/layout/flow.rs @@ -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::dom::TRestyleDamage; use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode}; -use style::properties::{self, ComputedValues}; +use style::properties::{self, ComputedValues, TComputedValues}; use style::values::computed::LengthOrPercentageOrAuto; use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize, TableFlow}; use table_caption::TableCaptionFlow; diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index 8c1c54fd282..227b492b038 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -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::dom::TRestyleDamage; 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::{LengthOrPercentageOrNone}; use text; diff --git a/components/layout/generated_content.rs b/components/layout/generated_content.rs index b0284c62d7e..7af9c4349d2 100644 --- a/components/layout/generated_content.rs +++ b/components/layout/generated_content.rs @@ -20,7 +20,7 @@ use std::sync::Arc; use style::computed_values::content::ContentItem; use style::computed_values::{display, list_style_type}; use style::dom::TRestyleDamage; -use style::properties::ComputedValues; +use style::properties::{ComputedValues, TComputedValues}; use text::TextRunScanner; use wrapper::PseudoElementType; diff --git a/components/layout/incremental.rs b/components/layout/incremental.rs index d909192c0d3..8daf3cdd14f 100644 --- a/components/layout/incremental.rs +++ b/components/layout/incremental.rs @@ -7,7 +7,7 @@ use std::fmt; use std::sync::Arc; use style::computed_values::float; use style::dom::TRestyleDamage; -use style::properties::ComputedValues; +use style::properties::{ComputedValues, TComputedValues}; bitflags! { #[doc = "Individual layout actions that may be necessary after restyling."] @@ -53,6 +53,7 @@ bitflags! { } impl TRestyleDamage for RestyleDamage { + type ConcreteComputedValues = ComputedValues; fn compute(old: Option<&Arc>, new: &ComputedValues) -> RestyleDamage { compute_damage(old, new) } /// Returns a bitmask that represents a flow that needs to be rebuilt and reflowed. diff --git a/components/layout/inline.rs b/components/layout/inline.rs index 8784728d808..175295c6f09 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -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::{text_overflow, vertical_align, white_space}; use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode}; -use style::properties::ComputedValues; +use style::properties::{ComputedValues, TComputedValues}; use style::values::computed::LengthOrPercentage; use text; use unicode_bidi; diff --git a/components/layout/layout_thread.rs b/components/layout/layout_thread.rs index 041eab87168..41ffa91cac4 100644 --- a/components/layout/layout_thread.rs +++ b/components/layout/layout_thread.rs @@ -73,6 +73,7 @@ use style::error_reporting::ParseErrorReporter; use style::logical_geometry::LogicalPoint; use style::media_queries::{Device, MediaType}; use style::parallel::WorkQueueData; +use style::properties::TComputedValues; use style::selector_impl::ServoSelectorImpl; use style::selector_matching::USER_OR_USER_AGENT_STYLESHEETS; use style::servo::{SharedStyleContext, Stylesheet, Stylist}; diff --git a/components/layout/list_item.rs b/components/layout/list_item.rs index 6c8817ec1da..e64faa96758 100644 --- a/components/layout/list_item.rs +++ b/components/layout/list_item.rs @@ -23,7 +23,7 @@ use inline::InlineMetrics; use std::sync::Arc; use style::computed_values::{list_style_type, position}; use style::logical_geometry::LogicalSize; -use style::properties::ComputedValues; +use style::properties::{ComputedValues, TComputedValues}; use text; /// A block with the CSS `display` property equal to `list-item`. diff --git a/components/layout/model.rs b/components/layout/model.rs index 057bb46fa52..6312bf3d30b 100644 --- a/components/layout/model.rs +++ b/components/layout/model.rs @@ -13,7 +13,7 @@ use std::cmp::{max, min}; use std::fmt; use style::computed_values::transform::ComputedMatrix; use style::logical_geometry::LogicalMargin; -use style::properties::ComputedValues; +use style::properties::{ComputedValues, TComputedValues}; use style::values::computed::{BorderRadiusSize, LengthOrPercentageOrAuto}; use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrNone}; diff --git a/components/layout/multicol.rs b/components/layout/multicol.rs index 4b7ac7d8814..b7e89fecf6c 100644 --- a/components/layout/multicol.rs +++ b/components/layout/multicol.rs @@ -21,7 +21,7 @@ use std::fmt; use std::sync::Arc; use style::context::StyleContext; use style::logical_geometry::LogicalSize; -use style::properties::ComputedValues; +use style::properties::{ComputedValues, TComputedValues}; use style::values::computed::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone}; use util::print_tree::PrintTree; diff --git a/components/layout/query.rs b/components/layout/query.rs index 9d1b9ed1db3..e05564f1aca 100644 --- a/components/layout/query.rs +++ b/components/layout/query.rs @@ -27,6 +27,7 @@ use std::sync::{Arc, Mutex}; use string_cache::Atom; use style::computed_values; use style::logical_geometry::{WritingMode, BlockFlowDirection, InlineBaseDirection}; +use style::properties::TComputedValues; use style::properties::longhands::{display, position}; use style::properties::style_structs; use style::selector_impl::PseudoElement; diff --git a/components/layout/table.rs b/components/layout/table.rs index 0c8d8865a8d..bd6b6bee6ed 100644 --- a/components/layout/table.rs +++ b/components/layout/table.rs @@ -25,7 +25,7 @@ use std::fmt; use std::sync::Arc; use style::computed_values::{border_collapse, border_spacing, table_layout}; use style::logical_geometry::LogicalSize; -use style::properties::ComputedValues; +use style::properties::{ComputedValues, TComputedValues}; use style::values::CSSFloat; use style::values::computed::LengthOrPercentageOrAuto; use table_row::{TableRowFlow}; diff --git a/components/layout/table_caption.rs b/components/layout/table_caption.rs index e1706fc53cd..20ca8d8a8dc 100644 --- a/components/layout/table_caption.rs +++ b/components/layout/table_caption.rs @@ -17,7 +17,7 @@ use gfx::display_list::{StackingContext, StackingContextId}; use std::fmt; use std::sync::Arc; use style::logical_geometry::LogicalSize; -use style::properties::ComputedValues; +use style::properties::{ComputedValues, TComputedValues}; use util::print_tree::PrintTree; /// A table formatting context. diff --git a/components/layout/table_cell.rs b/components/layout/table_cell.rs index ea16a5b5a59..508d201f6fd 100644 --- a/components/layout/table_cell.rs +++ b/components/layout/table_cell.rs @@ -21,7 +21,7 @@ use std::fmt; use std::sync::Arc; use style::computed_values::{border_collapse, border_top_style}; use style::logical_geometry::{LogicalMargin, LogicalRect, LogicalSize, WritingMode}; -use style::properties::ComputedValues; +use style::properties::{ComputedValues, TComputedValues}; use table::InternalTable; use table_row::{CollapsedBorder, CollapsedBorderProvenance}; use util::print_tree::PrintTree; diff --git a/components/layout/table_colgroup.rs b/components/layout/table_colgroup.rs index 32d2c693131..762e3526cf6 100644 --- a/components/layout/table_colgroup.rs +++ b/components/layout/table_colgroup.rs @@ -18,7 +18,7 @@ use std::cmp::max; use std::fmt; use std::sync::Arc; use style::logical_geometry::LogicalSize; -use style::properties::ComputedValues; +use style::properties::{ComputedValues, TComputedValues}; use style::values::computed::LengthOrPercentageOrAuto; /// A table formatting context. diff --git a/components/layout/table_row.rs b/components/layout/table_row.rs index 45e8bca12ec..64a2e71beed 100644 --- a/components/layout/table_row.rs +++ b/components/layout/table_row.rs @@ -25,7 +25,7 @@ use std::iter::{Enumerate, IntoIterator, Peekable}; use std::sync::Arc; use style::computed_values::{border_collapse, border_spacing, border_top_style}; use style::logical_geometry::{LogicalSize, PhysicalSide, WritingMode}; -use style::properties::ComputedValues; +use style::properties::{ComputedValues, TComputedValues}; use style::values::computed::LengthOrPercentageOrAuto; use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize, InternalTable, VecExt}; use table_cell::{CollapsedBordersForCell, TableCellFlow}; diff --git a/components/layout/table_rowgroup.rs b/components/layout/table_rowgroup.rs index 44da4878119..a43d6f6ebbc 100644 --- a/components/layout/table_rowgroup.rs +++ b/components/layout/table_rowgroup.rs @@ -21,7 +21,7 @@ use std::iter::{IntoIterator, Iterator, Peekable}; use std::sync::Arc; use style::computed_values::{border_collapse, border_spacing}; use style::logical_geometry::{LogicalSize, WritingMode}; -use style::properties::ComputedValues; +use style::properties::{ComputedValues, TComputedValues}; use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize, InternalTable, TableLikeFlow}; use table_row; use util::print_tree::PrintTree; diff --git a/components/layout/table_wrapper.rs b/components/layout/table_wrapper.rs index a8e16812efd..e543f981127 100644 --- a/components/layout/table_wrapper.rs +++ b/components/layout/table_wrapper.rs @@ -31,7 +31,7 @@ use std::ops::Add; use std::sync::Arc; use style::computed_values::{border_collapse, table_layout}; use style::logical_geometry::LogicalSize; -use style::properties::ComputedValues; +use style::properties::{ComputedValues, TComputedValues}; use style::values::CSSFloat; use style::values::computed::LengthOrPercentageOrAuto; use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize}; diff --git a/components/layout/text.rs b/components/layout/text.rs index 2a9e99d18d3..0969bc4e43e 100644 --- a/components/layout/text.rs +++ b/components/layout/text.rs @@ -23,8 +23,8 @@ use std::sync::Arc; use style::computed_values::{line_height, text_orientation, text_rendering, text_transform}; use style::computed_values::{white_space}; use style::logical_geometry::{LogicalSize, WritingMode}; -use style::properties::ComputedValues; use style::properties::style_structs::Font as FontStyle; +use style::properties::{ComputedValues, TComputedValues}; use unicode_bidi::{is_rtl, process_text}; use unicode_script::{get_script, Script}; use util::linked_list::split_off_head; diff --git a/components/layout/traversal.rs b/components/layout/traversal.rs index 6c774b76bcf..61d045a4048 100644 --- a/components/layout/traversal.rs +++ b/components/layout/traversal.rs @@ -15,7 +15,7 @@ use flow::{self, Flow, CAN_BE_FRAGMENTED}; use gfx::display_list::OpaqueNode; use incremental::{BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW, REPAINT, RestyleDamage}; use std::mem; -use style::context::{StyleContext, ReflowGoal}; +use style::context::StyleContext; use style::matching::MatchMethods; use style::traversal::{DomTraversalContext, STYLE_BLOOM}; use style::traversal::{put_thread_local_bloom_filter, recalc_style_at}; diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 30ca65f6e39..094bc40a4a0 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -66,7 +66,7 @@ use style::computed_values::content::ContentItem; use style::computed_values::{content, display}; use style::dom::{TDocument, TElement, TNode, UnsafeNode}; use style::element_state::*; -use style::properties::ComputedValues; +use style::properties::{ComputedValues, TComputedValues}; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock}; use style::restyle_hints::ElementSnapshot; use style::selector_impl::{NonTSPseudoClass, PseudoElement, ServoSelectorImpl}; @@ -131,6 +131,7 @@ impl<'ln> ServoLayoutNode<'ln> { } impl<'ln> TNode for ServoLayoutNode<'ln> { + type ConcreteComputedValues = ComputedValues; type ConcreteElement = ServoLayoutElement<'ln>; type ConcreteDocument = ServoLayoutDocument<'ln>; type ConcreteRestyleDamage = RestyleDamage; diff --git a/components/style/animation.rs b/components/style/animation.rs index ea901beca92..e7663093cd5 100644 --- a/components/style/animation.rs +++ b/components/style/animation.rs @@ -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::visibility::computed_value::T as Visibility; use properties::longhands::z_index::computed_value::T as ZIndex; +use properties::style_struct_traits::TAnimation; use properties::{ComputedValues, TComputedValues}; use std::cmp::Ordering; use std::iter::repeat; @@ -73,7 +74,7 @@ impl PropertyAnimation { -> Vec { let mut result = Vec::new(); 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 let Some(property_animation) = PropertyAnimation::from_transition_property(transition_property, @@ -929,22 +930,22 @@ impl GetMod for Vec { /// 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 /// kicked off and false otherwise. -pub fn start_transitions_if_applicable(new_animations_sender: &Mutex>, - node: OpaqueNode, - old_style: &ComputedValues, - new_style: &mut ComputedValues) - -> bool { +pub fn start_transitions_if_applicable(new_animations_sender: &Mutex>, + node: OpaqueNode, + old_style: &C, + new_style: &mut C) + -> bool { 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. - 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 { // 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. 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 = now + (animation_style.transition_delay.0.get_mod(i).seconds() as f64); new_animations_sender.lock().unwrap().send(Animation { @@ -964,9 +965,10 @@ pub fn start_transitions_if_applicable(new_animations_sender: &Mutex(animation: &Animation, - style: &mut Arc, - damage: Option<&mut ConcreteRestyleDamage>) { +pub fn update_style_for_animation>(animation: &Animation, + style: &mut Arc, + damage: Option<&mut Damage>) { let now = time::precise_time_s(); let mut progress = (now - animation.start_time) / animation.duration(); if progress > 1.0 { @@ -977,9 +979,9 @@ pub fn update_style_for_animation(animati } 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 { - *damage = *damage | ConcreteRestyleDamage::compute(Some(style), &new_style); + *damage = *damage | Damage::compute(Some(style), &new_style); } *style = new_style diff --git a/components/style/context.rs b/components/style/context.rs index 6e4edfd1b52..ef19bc2561e 100644 --- a/components/style/context.rs +++ b/components/style/context.rs @@ -8,6 +8,7 @@ use dom::OpaqueNode; use error_reporting::ParseErrorReporter; use euclid::Size2D; use matching::{ApplicableDeclarationsCache, StyleSharingCandidateCache}; +use properties::TComputedValues; use selector_impl::SelectorImplExt; use selector_matching::Stylist; use std::cell::RefCell; @@ -54,15 +55,15 @@ pub struct SharedStyleContext { pub error_reporter: Box, } -pub struct LocalStyleContext { - pub applicable_declarations_cache: RefCell, - pub style_sharing_candidate_cache: RefCell, +pub struct LocalStyleContext { + pub applicable_declarations_cache: RefCell>, + pub style_sharing_candidate_cache: RefCell>, } -pub trait StyleContext<'a, Impl: SelectorImplExt> { +pub trait StyleContext<'a, Impl: SelectorImplExt, C: TComputedValues> { fn shared_context(&self) -> &'a SharedStyleContext; - fn local_context(&self) -> &LocalStyleContext; + fn local_context(&self) -> &LocalStyleContext; } /// Why we're doing reflow. diff --git a/components/style/data.rs b/components/style/data.rs index ffe12908cba..6bc6916a564 100644 --- a/components/style/data.rs +++ b/components/style/data.rs @@ -2,26 +2,28 @@ * 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 properties::ComputedValues; +use properties::TComputedValues; use selectors::parser::SelectorImpl; use std::collections::HashMap; use std::hash::BuildHasherDefault; use std::sync::Arc; use std::sync::atomic::AtomicIsize; -pub struct PrivateStyleData { +pub struct PrivateStyleData { /// The results of CSS styling for this node. - pub style: Option>, + pub style: Option>, /// The results of CSS styling for each pseudo-element (if any). - pub per_pseudo: HashMap, BuildHasherDefault<::fnv::FnvHasher>>, + pub per_pseudo: HashMap, + BuildHasherDefault<::fnv::FnvHasher>>, /// Information needed during parallel traversals. pub parallel: DomParallelInfo, } -impl PrivateStyleData { - pub fn new() -> PrivateStyleData { +impl PrivateStyleData + where Impl: SelectorImpl, ConcreteComputedValues: TComputedValues { + pub fn new() -> PrivateStyleData { PrivateStyleData { style: None, per_pseudo: HashMap::with_hasher(Default::default()), diff --git a/components/style/dom.rs b/components/style/dom.rs index 37859736dbe..861cec599a2 100644 --- a/components/style/dom.rs +++ b/components/style/dom.rs @@ -6,7 +6,7 @@ use data::PrivateStyleData; 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 selector_impl::ElementExt; use selectors::Element; @@ -43,14 +43,16 @@ impl OpaqueNode { } pub trait TRestyleDamage : BitOr + Copy { - fn compute(old: Option<&Arc>, new: &ComputedValues) -> Self; + type ConcreteComputedValues: TComputedValues; + fn compute(old: Option<&Arc>, new: &Self::ConcreteComputedValues) -> Self; fn rebuild_and_reflow() -> Self; } pub trait TNode : Sized + Copy + Clone { type ConcreteElement: TElement; type ConcreteDocument: TDocument; - type ConcreteRestyleDamage: TRestyleDamage; + type ConcreteRestyleDamage: TRestyleDamage; + type ConcreteComputedValues: TComputedValues; fn to_unsafe(&self) -> UnsafeNode; unsafe fn from_unsafe(n: &UnsafeNode) -> Self; @@ -135,17 +137,20 @@ pub trait TNode : Sized + Copy + Clone { /// Borrows the PrivateStyleData without checks. #[inline(always)] unsafe fn borrow_data_unchecked(&self) - -> Option<*const PrivateStyleData<::Impl>>; + -> Option<*const PrivateStyleData<::Impl, + Self::ConcreteComputedValues>>; /// Borrows the PrivateStyleData immutably. Fails on a conflicting borrow. #[inline(always)] fn borrow_data(&self) - -> Option::Impl>>>; + -> Option::Impl, + Self::ConcreteComputedValues>>>; /// Borrows the PrivateStyleData mutably. Fails on a conflicting borrow. #[inline(always)] fn mutate_data(&self) - -> Option::Impl>>>; + -> Option::Impl, + Self::ConcreteComputedValues>>>; /// Get the description of how to account for recent style changes. 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 /// has not yet been performed, fails. - fn style(&self) -> Ref> { + fn style(&self) -> Ref> { Ref::map(self.borrow_data().unwrap(), |data| data.style.as_ref().unwrap()) } diff --git a/components/style/matching.rs b/components/style/matching.rs index 2459500f308..025e229e57c 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -8,8 +8,8 @@ use animation::{self, Animation}; use context::SharedStyleContext; use data::PrivateStyleData; use dom::{TElement, TNode, TRestyleDamage}; -use properties::{ComputedValues, PropertyDeclaration, TComputedValues, cascade}; -use selector_impl::SelectorImplExt; +use properties::{PropertyDeclaration, TComputedValues, cascade}; +use selector_impl::{ElementExt, SelectorImplExt}; use selector_matching::{DeclarationBlock, Stylist}; use selectors::Element; use selectors::bloom::BloomFilter; @@ -151,25 +151,25 @@ impl<'a> Hash for ApplicableDeclarationsCacheQuery<'a> { static APPLICABLE_DECLARATIONS_CACHE_SIZE: usize = 32; -pub struct ApplicableDeclarationsCache { - cache: SimpleHashCache>, +pub struct ApplicableDeclarationsCache { + cache: SimpleHashCache>, } -impl ApplicableDeclarationsCache { - pub fn new() -> ApplicableDeclarationsCache { +impl ApplicableDeclarationsCache { + pub fn new() -> Self { ApplicableDeclarationsCache { cache: SimpleHashCache::new(APPLICABLE_DECLARATIONS_CACHE_SIZE), } } - pub fn find(&self, declarations: &[DeclarationBlock]) -> Option> { + pub fn find(&self, declarations: &[DeclarationBlock]) -> Option> { match self.cache.find(&ApplicableDeclarationsCacheQuery::new(declarations)) { None => None, Some(ref values) => Some((*values).clone()), } } - pub fn insert(&mut self, declarations: Vec, style: Arc) { + pub fn insert(&mut self, declarations: Vec, style: Arc) { 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. -pub struct StyleSharingCandidateCache { - cache: LRUCache, +pub struct StyleSharingCandidateCache { + cache: LRUCache, ()>, } #[derive(Clone)] -pub struct StyleSharingCandidate { - pub style: Arc, - pub parent_style: Arc, +pub struct StyleSharingCandidate { + pub style: Arc, + pub parent_style: Arc, pub local_name: Atom, // FIXME(pcwalton): Should be a list of atoms instead. pub class: Option, @@ -195,8 +195,8 @@ pub struct StyleSharingCandidate { pub link: bool, } -impl PartialEq for StyleSharingCandidate { - fn eq(&self, other: &StyleSharingCandidate) -> bool { +impl PartialEq for StyleSharingCandidate { + fn eq(&self, other: &Self) -> bool { arc_ptr_eq(&self.style, &other.style) && arc_ptr_eq(&self.parent_style, &other.parent_style) && self.local_name == other.local_name && @@ -207,12 +207,12 @@ impl PartialEq for StyleSharingCandidate { } } -impl StyleSharingCandidate { +impl StyleSharingCandidate { /// Attempts to create a style sharing candidate from this node. Returns /// the style sharing candidate or `None` if this node is ineligible for /// style sharing. #[allow(unsafe_code)] - fn new(element: &E) -> Option { + fn new>(element: &N::ConcreteElement) -> Option { let parent_element = match element.parent_element() { None => return None, Some(parent_element) => parent_element, @@ -254,7 +254,7 @@ impl StyleSharingCandidate { link: element.is_link(), namespace: (*element.get_namespace()).clone(), common_style_affecting_attributes: - create_common_style_affecting_attributes_from_element::(&element) + create_common_style_affecting_attributes_from_element::(&element) }) } @@ -332,19 +332,19 @@ impl StyleSharingCandidate { static STYLE_SHARING_CANDIDATE_CACHE_SIZE: usize = 40; -impl StyleSharingCandidateCache { - pub fn new() -> StyleSharingCandidateCache { +impl StyleSharingCandidateCache { + pub fn new() -> Self { StyleSharingCandidateCache { cache: LRUCache::new(STYLE_SHARING_CANDIDATE_CACHE_SIZE), } } - pub fn iter(&self) -> Iter<(StyleSharingCandidate, ())> { + pub fn iter(&self) -> Iter<(StyleSharingCandidate, ())> { self.cache.iter() } - pub fn insert_if_possible(&mut self, element: &E) { - match StyleSharingCandidate::new(element) { + pub fn insert_if_possible>(&mut self, element: &N::ConcreteElement) { + match StyleSharingCandidate::new::(element) { None => {} Some(candidate) => self.cache.insert(candidate, ()) } @@ -368,15 +368,15 @@ trait PrivateMatchMethods: TNode where ::Impl: SelectorImplExt { fn cascade_node_pseudo_element(&self, context: &SharedStyleContext<::Impl>, - parent_style: Option<&Arc>, + parent_style: Option<&Arc>, applicable_declarations: &[DeclarationBlock], - mut style: Option<&mut Arc>, + mut style: Option<&mut Arc>, applicable_declarations_cache: - &mut ApplicableDeclarationsCache, + &mut ApplicableDeclarationsCache, new_animations_sender: &Mutex>, shareable: bool, animate_properties: bool) - -> (Self::ConcreteRestyleDamage, Arc) { + -> (Self::ConcreteRestyleDamage, Arc) { let mut cacheable = true; if animate_properties { cacheable = !self.update_animations_for_cascade(context, &mut style) && cacheable; @@ -416,10 +416,11 @@ trait PrivateMatchMethods: TNode if animate_properties { if let Some(ref style) = style { let animations_started = - animation::start_transitions_if_applicable(new_animations_sender, - self.opaque(), - &**style, - &mut this_style); + animation::start_transitions_if_applicable::( + new_animations_sender, + self.opaque(), + &**style, + &mut this_style); cacheable = cacheable && !animations_started } } @@ -440,7 +441,7 @@ trait PrivateMatchMethods: TNode fn update_animations_for_cascade(&self, context: &SharedStyleContext<::Impl>, - style: &mut Option<&mut Arc>) + style: &mut Option<&mut Arc>) -> bool { let style = match *style { None => return false, @@ -456,7 +457,7 @@ trait PrivateMatchMethods: TNode had_animations_to_expire = animations_to_expire.is_some(); if let Some(ref animations) = animations_to_expire { 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 { let mut all_running_animations = context.running_animations.write().unwrap(); for running_animation in all_running_animations.get(&this_opaque).unwrap() { - animation::update_style_for_animation::(running_animation, style, None); + animation::update_style_for_animation::(running_animation, style, None); } all_running_animations.remove(&this_opaque); } @@ -489,14 +491,15 @@ impl PrivateMatchMethods for N trait PrivateElementMatchMethods: TElement { fn share_style_with_candidate_if_possible(&self, parent_node: Option, - candidate: &StyleSharingCandidate) - -> Option> { + candidate: &StyleSharingCandidate<::ConcreteComputedValues>) + -> Option::ConcreteComputedValues>> { let parent_node = match parent_node { Some(ref parent_node) if parent_node.as_element().is_some() => parent_node, Some(_) | None => return None, }; - let parent_data: Option<&PrivateStyleData<_>> = unsafe { + let parent_data: Option<&PrivateStyleData<_, _>> = unsafe { parent_node.borrow_data_unchecked().map(|d| &*d) }; @@ -550,7 +553,8 @@ pub trait ElementMatchMethods : TElement /// guarantee that at the type system level yet. unsafe fn share_style_if_possible(&self, style_sharing_candidate_cache: - &mut StyleSharingCandidateCache, + &mut StyleSharingCandidateCache<::ConcreteComputedValues>, parent: Option) -> StyleSharingResult<::ConcreteRestyleDamage> { if opts::get().disable_share_style_cache { @@ -639,7 +643,8 @@ pub trait MatchMethods : TNode { context: &SharedStyleContext<::Impl>, parent: Option, applicable_declarations: &ApplicableDeclarations<::Impl>, - applicable_declarations_cache: &mut ApplicableDeclarationsCache, + applicable_declarations_cache: + &mut ApplicableDeclarationsCache, new_animations_sender: &Mutex>) where ::Impl: SelectorImplExt { // Get our parent's style. This must be unsafe so that we don't touch the parent's diff --git a/components/style/servo.rs b/components/style/servo.rs index 56aef8f6210..10867d4eaf8 100644 --- a/components/style/servo.rs +++ b/components/style/servo.rs @@ -3,13 +3,14 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use context; use data; +use properties::ComputedValues; use selector_impl::ServoSelectorImpl; use selector_matching; use stylesheets; /// Concrete types for servo Style implementation pub type Stylesheet = stylesheets::Stylesheet; -pub type PrivateStyleData = data::PrivateStyleData; +pub type PrivateStyleData = data::PrivateStyleData; pub type Stylist = selector_matching::Stylist; pub type StylistWrapper = context::StylistWrapper; pub type SharedStyleContext = context::SharedStyleContext; diff --git a/components/style/traversal.rs b/components/style/traversal.rs index 79759cf26b9..f39347e83ab 100644 --- a/components/style/traversal.rs +++ b/components/style/traversal.rs @@ -123,7 +123,7 @@ pub fn recalc_style_at<'a, N, C>(context: &'a C, root: OpaqueNode, node: N) where N: TNode, - C: StyleContext<'a, ::Impl>, + C: StyleContext<'a, ::Impl, N::ConcreteComputedValues>, ::Impl: SelectorImplExt + 'a { // Initialize layout data. // @@ -195,7 +195,7 @@ pub fn recalc_style_at<'a, N, C>(context: &'a C, // Add ourselves to the LRU cache. 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) => { diff --git a/ports/geckolib/lib.rs b/ports/geckolib/lib.rs index dfb9bb06ea3..70f265526d9 100644 --- a/ports/geckolib/lib.rs +++ b/ports/geckolib/lib.rs @@ -37,6 +37,7 @@ mod bindings; mod data; #[allow(non_snake_case)] pub mod glue; +mod properties; mod selector_impl; mod traversal; mod wrapper; diff --git a/ports/geckolib/properties.rs b/ports/geckolib/properties.rs new file mode 100644 index 00000000000..176c2927e14 --- /dev/null +++ b/ports/geckolib/properties.rs @@ -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; diff --git a/ports/geckolib/selector_impl.rs b/ports/geckolib/selector_impl.rs index 45ded949052..0b3b883e4ef 100644 --- a/ports/geckolib/selector_impl.rs +++ b/ports/geckolib/selector_impl.rs @@ -7,6 +7,7 @@ use std::process; use style; use style::element_state::ElementState; use style::error_reporting::StdoutErrorReporter; +use style::properties::ComputedValues; use style::selector_impl::SelectorImplExt; use style::stylesheets::Origin; use url::Url; @@ -14,7 +15,7 @@ use url::Url; pub type Stylist = style::selector_matching::Stylist; pub type Stylesheet = style::stylesheets::Stylesheet; pub type SharedStyleContext = style::context::SharedStyleContext; -pub type PrivateStyleData = style::data::PrivateStyleData; +pub type PrivateStyleData = style::data::PrivateStyleData; pub struct GeckoSelectorImpl; diff --git a/ports/geckolib/traversal.rs b/ports/geckolib/traversal.rs index b1cfbd1fbbd..33fc1fd322e 100644 --- a/ports/geckolib/traversal.rs +++ b/ports/geckolib/traversal.rs @@ -2,20 +2,23 @@ * 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 properties::GeckoComputedValues; use selector_impl::{GeckoSelectorImpl, SharedStyleContext}; use std::cell::RefCell; use std::mem; use std::rc::Rc; use style::context::{LocalStyleContext, StyleContext}; -use style::dom::{OpaqueNode, TNode}; +use style::dom::OpaqueNode; use style::matching::{ApplicableDeclarationsCache, StyleSharingCandidateCache}; use style::traversal::{DomTraversalContext, recalc_style_at}; +use wrapper::GeckoNode; -thread_local!(static LOCAL_CONTEXT_KEY: RefCell>> = RefCell::new(None)); +thread_local!(static LOCAL_CONTEXT_KEY: + RefCell>>> = RefCell::new(None)); // Keep this implementation in sync with the one in components/layout/context.rs. fn create_or_get_local_context(shared: &SharedStyleContext) - -> Rc { + -> Rc> { LOCAL_CONTEXT_KEY.with(|r| { let mut r = r.borrow_mut(); if let Some(context) = r.clone() { @@ -36,7 +39,7 @@ fn create_or_get_local_context(shared: &SharedStyleContext) pub struct StandaloneStyleContext<'a> { pub shared: &'a SharedStyleContext, - cached_local_context: Rc, + cached_local_context: Rc>, } 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 { &self.shared } - fn local_context(&self) -> &LocalStyleContext { + fn local_context(&self) -> &LocalStyleContext { &self.cached_local_context } } @@ -64,8 +67,7 @@ pub struct RecalcStyleOnly<'lc> { root: OpaqueNode, } -impl<'lc, N: TNode> DomTraversalContext for RecalcStyleOnly<'lc> - where N::ConcreteElement: ::selectors::Element { +impl<'lc, 'ln> DomTraversalContext> for RecalcStyleOnly<'lc> { type SharedContext = SharedStyleContext; #[allow(unsafe_code)] fn new<'a>(shared: &'a Self::SharedContext, root: OpaqueNode) -> Self { @@ -78,7 +80,7 @@ impl<'lc, N: TNode> DomTraversalContext for RecalcStyleOnly<'lc> } } - fn process_preorder(&self, node: N) { recalc_style_at(&self.context, self.root, node); } - fn process_postorder(&self, _: N) {} + fn process_preorder(&self, node: GeckoNode<'ln>) { recalc_style_at(&self.context, self.root, node); } + fn process_postorder(&self, _: GeckoNode<'ln>) {} } diff --git a/ports/geckolib/wrapper.rs b/ports/geckolib/wrapper.rs index bb2e58c4ee2..bdf9cea4259 100644 --- a/ports/geckolib/wrapper.rs +++ b/ports/geckolib/wrapper.rs @@ -19,6 +19,7 @@ use bindings::{Gecko_LocalName, Gecko_Namespace, Gecko_NodeIsElement, Gecko_SetN use bindings::{RawGeckoDocument, RawGeckoElement, RawGeckoNode}; use bindings::{ServoNodeData}; use libc::uintptr_t; +use properties::GeckoComputedValues; use selector_impl::{GeckoSelectorImpl, NonTSPseudoClass, PrivateStyleData}; use selectors::Element; use selectors::matching::DeclarationBlock; @@ -35,7 +36,7 @@ use style::dom::{OpaqueNode, TDocument, TElement, TNode, TRestyleDamage, UnsafeN use style::element_state::ElementState; #[allow(unused_imports)] // Used in commented-out code. use style::error_reporting::StdoutErrorReporter; -use style::properties::{ComputedValues, PropertyDeclaration, PropertyDeclarationBlock}; +use style::properties::{PropertyDeclaration, PropertyDeclarationBlock}; #[allow(unused_imports)] // Used in commented-out code. use style::properties::{parse_style_attribute}; use style::restyle_hints::ElementSnapshot; @@ -78,7 +79,8 @@ impl<'ln> GeckoNode<'ln> { #[derive(Clone, Copy)] pub struct DummyRestyleDamage; impl TRestyleDamage for DummyRestyleDamage { - fn compute(_: Option<&Arc>, _: &ComputedValues) -> Self { DummyRestyleDamage } + type ConcreteComputedValues = GeckoComputedValues; + fn compute(_: Option<&Arc>, _: &GeckoComputedValues) -> Self { DummyRestyleDamage } fn rebuild_and_reflow() -> Self { DummyRestyleDamage } } impl BitOr for DummyRestyleDamage { @@ -92,6 +94,7 @@ impl<'ln> TNode for GeckoNode<'ln> { type ConcreteDocument = GeckoDocument<'ln>; type ConcreteElement = GeckoElement<'ln>; type ConcreteRestyleDamage = DummyRestyleDamage; + type ConcreteComputedValues = GeckoComputedValues; fn to_unsafe(&self) -> UnsafeNode { (self.node as usize, 0)