Remove the ComputedValue traits and style_struct_traits

This commit is contained in:
Simon Sapin 2016-07-19 20:29:22 +02:00
parent b2a7e44373
commit 789807b7b0
60 changed files with 589 additions and 652 deletions

View file

@ -25,7 +25,7 @@ use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT}; use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};
use string_cache::Atom; use string_cache::Atom;
use style::computed_values::{font_style, font_variant}; use style::computed_values::{font_style, font_variant};
use style::properties::style_structs::ServoFont; use style::properties::style_structs;
use webrender_traits; use webrender_traits;
#[cfg(any(target_os = "linux", target_os = "android", target_os = "windows"))] #[cfg(any(target_os = "linux", target_os = "android", target_os = "windows"))]
@ -141,7 +141,7 @@ impl FontContext {
/// Create a group of fonts for use in layout calculations. May return /// Create a group of fonts for use in layout calculations. May return
/// a cached font if this font instance has already been used by /// a cached font if this font instance has already been used by
/// this context. /// this context.
pub fn layout_font_group_for_style(&mut self, style: Arc<ServoFont>) pub fn layout_font_group_for_style(&mut self, style: Arc<style_structs::Font>)
-> Rc<FontGroup> { -> Rc<FontGroup> {
self.expire_font_caches_if_necessary(); self.expire_font_caches_if_necessary();
@ -297,7 +297,7 @@ impl HeapSizeOf for FontContext {
#[derive(Debug)] #[derive(Debug)]
struct LayoutFontGroupCacheKey { struct LayoutFontGroupCacheKey {
pointer: Arc<ServoFont>, pointer: Arc<style_structs::Font>,
size: Au, size: Au,
} }

View file

@ -14,17 +14,16 @@ use script_traits::{AnimationState, LayoutMsg as ConstellationMsg};
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::mpsc::Receiver; use std::sync::mpsc::Receiver;
use style::animation::{Animation, update_style_for_animation}; use style::animation::{Animation, update_style_for_animation};
use style::selector_impl::{SelectorImplExt, ServoSelectorImpl};
use time; use time;
/// Processes any new animations that were discovered after style recalculation. /// Processes any new animations that were discovered after style recalculation.
/// Also expire any old animations that have completed, inserting them into /// Also expire any old animations that have completed, inserting them into
/// `expired_animations`. /// `expired_animations`.
pub fn update_animation_state<Impl: SelectorImplExt>(constellation_chan: &IpcSender<ConstellationMsg>, pub fn update_animation_state(constellation_chan: &IpcSender<ConstellationMsg>,
running_animations: &mut HashMap<OpaqueNode, Vec<Animation<Impl>>>, running_animations: &mut HashMap<OpaqueNode, Vec<Animation>>,
expired_animations: &mut HashMap<OpaqueNode, Vec<Animation<Impl>>>, expired_animations: &mut HashMap<OpaqueNode, Vec<Animation>>,
new_animations_receiver: &Receiver<Animation<Impl>>, new_animations_receiver: &Receiver<Animation>,
pipeline_id: PipelineId) { pipeline_id: PipelineId) {
let mut new_running_animations = vec![]; let mut new_running_animations = vec![];
while let Ok(animation) = new_animations_receiver.try_recv() { while let Ok(animation) = new_animations_receiver.try_recv() {
let mut should_push = true; let mut should_push = true;
@ -125,7 +124,7 @@ pub fn update_animation_state<Impl: SelectorImplExt>(constellation_chan: &IpcSen
pub fn recalc_style_for_animations(context: &SharedLayoutContext, pub fn recalc_style_for_animations(context: &SharedLayoutContext,
flow: &mut Flow, flow: &mut Flow,
animations: &HashMap<OpaqueNode, animations: &HashMap<OpaqueNode,
Vec<Animation<ServoSelectorImpl>>>) { Vec<Animation>>) {
let mut damage = RestyleDamage::empty(); let mut damage = RestyleDamage::empty();
flow.mutate_fragments(&mut |fragment| { flow.mutate_fragments(&mut |fragment| {
if let Some(ref animations) = animations.get(&fragment.node) { if let Some(ref animations) = animations.get(&fragment.node) {

View file

@ -58,7 +58,7 @@ use style::computed_values::{border_collapse, box_sizing, display, float, overfl
use style::computed_values::{position, text_align, transform, transform_style}; use style::computed_values::{position, text_align, transform, 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, ServoComputedValues}; use style::properties::ServoComputedValues;
use style::servo::SharedStyleContext; use style::servo::SharedStyleContext;
use style::values::computed::{LengthOrNone, LengthOrPercentageOrNone}; use style::values::computed::{LengthOrNone, LengthOrPercentageOrNone};
use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto}; use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};

View file

@ -46,7 +46,7 @@ use std::sync::atomic::Ordering;
use style::computed_values::content::ContentItem; use style::computed_values::content::ContentItem;
use style::computed_values::position; use style::computed_values::position;
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::properties::{self, ComputedValues, ServoComputedValues}; use style::properties::{self, ServoComputedValues};
use style::servo::SharedStyleContext; use style::servo::SharedStyleContext;
use table::TableFlow; use table::TableFlow;
use table_caption::TableCaptionFlow; use table_caption::TableCaptionFlow;

View file

@ -31,7 +31,7 @@ use url::Url;
use util::opts; use util::opts;
struct LocalLayoutContext { struct LocalLayoutContext {
style_context: LocalStyleContext<ServoSelectorImpl>, style_context: LocalStyleContext,
font_context: RefCell<FontContext>, font_context: RefCell<FontContext>,
} }
@ -108,7 +108,7 @@ impl<'a> StyleContext<'a, ServoSelectorImpl> for LayoutContext<'a> {
&self.shared.style_context &self.shared.style_context
} }
fn local_context(&self) -> &LocalStyleContext<ServoSelectorImpl> { fn local_context(&self) -> &LocalStyleContext {
&self.cached_local_layout_context.style_context &self.cached_local_layout_context.style_context
} }
} }

View file

@ -50,8 +50,8 @@ use style::computed_values::{background_repeat, background_size, border_style};
use style::computed_values::{cursor, image_rendering, overflow_x, pointer_events, position}; use style::computed_values::{cursor, image_rendering, overflow_x, pointer_events, 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::ServoBorder; use style::properties::style_structs;
use style::properties::{self, ComputedValues, ServoComputedValues}; use style::properties::{self, ServoComputedValues};
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};
@ -315,7 +315,7 @@ fn handle_overlapping_radii(size: &Size2D<Au>, radii: &BorderRadii<Au>) -> Borde
} }
} }
fn build_border_radius(abs_bounds: &Rect<Au>, border_style: &ServoBorder) -> BorderRadii<Au> { fn build_border_radius(abs_bounds: &Rect<Au>, border_style: &style_structs::Border) -> BorderRadii<Au> {
// TODO(cgaebel): Support border radii even in the case of multiple border widths. // TODO(cgaebel): Support border radii even in the case of multiple border widths.
// This is an extension of supporting elliptical radii. For now, all percentage // This is an extension of supporting elliptical radii. For now, all percentage
// radii will be relative to the width. // radii will be relative to the width.

View file

@ -26,7 +26,7 @@ use std::cmp::max;
use std::sync::Arc; use std::sync::Arc;
use style::computed_values::flex_direction; use style::computed_values::flex_direction;
use style::logical_geometry::LogicalSize; use style::logical_geometry::LogicalSize;
use style::properties::{ComputedValues, ServoComputedValues}; use style::properties::ServoComputedValues;
use style::servo::SharedStyleContext; use style::servo::SharedStyleContext;
use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto, LengthOrPercentageOrNone}; use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto, LengthOrPercentageOrNone};

View file

@ -52,7 +52,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, ServoComputedValues}; use style::properties::{self, ServoComputedValues};
use style::servo::SharedStyleContext; use style::servo::SharedStyleContext;
use style::values::computed::LengthOrPercentageOrAuto; use style::values::computed::LengthOrPercentageOrAuto;
use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize, TableFlow}; use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize, TableFlow};

View file

@ -44,7 +44,7 @@ use style::computed_values::{overflow_wrap, overflow_x, position, text_decoratio
use style::computed_values::{transform_style, vertical_align, white_space, word_break, z_index}; use style::computed_values::{transform_style, vertical_align, 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, ServoComputedValues}; use style::properties::ServoComputedValues;
use style::str::char_is_whitespace; use style::str::char_is_whitespace;
use style::values::computed::LengthOrPercentageOrNone; use style::values::computed::LengthOrPercentageOrNone;
use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto}; use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};

View file

@ -21,7 +21,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, ServoComputedValues}; use style::properties::ServoComputedValues;
use text::TextRunScanner; use text::TextRunScanner;
// Decimal styles per CSS-COUNTER-STYLES § 6.1: // Decimal styles per CSS-COUNTER-STYLES § 6.1:

View file

@ -37,7 +37,7 @@ use style::computed_values::{display, overflow_x, position, text_align, text_jus
use style::computed_values::{text_overflow, vertical_align, white_space}; use style::computed_values::{text_overflow, vertical_align, white_space};
use style::context::StyleContext; use style::context::StyleContext;
use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode}; use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode};
use style::properties::{ComputedValues, ServoComputedValues}; use style::properties::ServoComputedValues;
use style::servo::SharedStyleContext; use style::servo::SharedStyleContext;
use style::values::computed::LengthOrPercentage; use style::values::computed::LengthOrPercentage;
use text; use text;

View file

@ -24,7 +24,7 @@ use script_layout_interface::restyle_damage::RESOLVE_GENERATED_CONTENT;
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, ServoComputedValues}; use style::properties::ServoComputedValues;
use style::servo::SharedStyleContext; use style::servo::SharedStyleContext;
use text; use text;

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, ServoComputedValues}; use style::properties::ServoComputedValues;
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

@ -23,7 +23,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, ServoComputedValues}; use style::properties::ServoComputedValues;
use style::servo::SharedStyleContext; use style::servo::SharedStyleContext;
use style::values::computed::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone}; use style::values::computed::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone};

View file

@ -31,7 +31,6 @@ 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::ComputedValues;
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;
@ -450,7 +449,7 @@ impl ParentOffsetBorderBoxIterator {
impl FragmentBorderBoxIterator for FragmentLocatingFragmentIterator { impl FragmentBorderBoxIterator for FragmentLocatingFragmentIterator {
fn process(&mut self, fragment: &Fragment, _: i32, border_box: &Rect<Au>) { fn process(&mut self, fragment: &Fragment, _: i32, border_box: &Rect<Au>) {
let style_structs::ServoBorder { let style_structs::Border {
border_top_width: top_width, border_top_width: top_width,
border_right_width: right_width, border_right_width: right_width,
border_bottom_width: bottom_width, border_bottom_width: bottom_width,
@ -476,7 +475,7 @@ impl FragmentBorderBoxIterator for UnioningFragmentScrollAreaIterator {
// increase in size. To work around this, we store the original elements padding // increase in size. To work around this, we store the original elements padding
// rectangle as `origin_rect` and the union of all child elements padding and // rectangle as `origin_rect` and the union of all child elements padding and
// margin rectangles as `union_rect`. // margin rectangles as `union_rect`.
let style_structs::ServoBorder { let style_structs::Border {
border_top_width: top_border, border_top_width: top_border,
border_right_width: right_border, border_right_width: right_border,
border_bottom_width: bottom_border, border_bottom_width: bottom_border,

View file

@ -27,7 +27,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, ServoComputedValues}; use style::properties::ServoComputedValues;
use style::servo::SharedStyleContext; use style::servo::SharedStyleContext;
use style::values::CSSFloat; use style::values::CSSFloat;
use style::values::computed::LengthOrPercentageOrAuto; use style::values::computed::LengthOrPercentageOrAuto;

View file

@ -25,7 +25,7 @@ use std::fmt;
use std::sync::Arc; use std::sync::Arc;
use style::computed_values::{border_collapse, border_top_style, vertical_align}; use style::computed_values::{border_collapse, border_top_style, vertical_align};
use style::logical_geometry::{LogicalMargin, LogicalRect, LogicalSize, WritingMode}; use style::logical_geometry::{LogicalMargin, LogicalRect, LogicalSize, WritingMode};
use style::properties::{ComputedValues, ServoComputedValues}; use style::properties::ServoComputedValues;
use style::servo::SharedStyleContext; use style::servo::SharedStyleContext;
use table::InternalTable; use table::InternalTable;
use table_row::{CollapsedBorder, CollapsedBorderProvenance}; use table_row::{CollapsedBorder, CollapsedBorderProvenance};

View file

@ -27,7 +27,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, ServoComputedValues}; use style::properties::ServoComputedValues;
use style::servo::SharedStyleContext; use style::servo::SharedStyleContext;
use style::values::computed::LengthOrPercentageOrAuto; use style::values::computed::LengthOrPercentageOrAuto;
use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize, InternalTable, VecExt}; use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize, InternalTable, VecExt};

View file

@ -23,7 +23,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, ServoComputedValues}; use style::properties::ServoComputedValues;
use style::servo::SharedStyleContext; use style::servo::SharedStyleContext;
use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize, InternalTable, TableLikeFlow}; use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize, InternalTable, TableLikeFlow};
use table_row; use table_row;

View file

@ -32,7 +32,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, ServoComputedValues}; use style::properties::ServoComputedValues;
use style::servo::SharedStyleContext; use style::servo::SharedStyleContext;
use style::values::CSSFloat; use style::values::CSSFloat;
use style::values::computed::LengthOrPercentageOrAuto; use style::values::computed::LengthOrPercentageOrAuto;

View file

@ -25,8 +25,8 @@ use std::sync::Arc;
use style::computed_values::white_space; use style::computed_values::white_space;
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::logical_geometry::{LogicalSize, WritingMode}; use style::logical_geometry::{LogicalSize, WritingMode};
use style::properties::style_structs::ServoFont; use style::properties::ServoComputedValues;
use style::properties::{ComputedValues, ServoComputedValues}; use style::properties::style_structs;
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};
@ -431,11 +431,11 @@ fn bounding_box_for_run_metrics(metrics: &RunMetrics, writing_mode: WritingMode)
} }
/// Returns the metrics of the font represented by the given `ServoFont`, respectively. /// Returns the metrics of the font represented by the given `style_structs::Font`, respectively.
/// ///
/// `#[inline]` because often the caller only needs a few fields from the font metrics. /// `#[inline]` because often the caller only needs a few fields from the font metrics.
#[inline] #[inline]
pub fn font_metrics_for_style(font_context: &mut FontContext, font_style: Arc<ServoFont>) pub fn font_metrics_for_style(font_context: &mut FontContext, font_style: Arc<style_structs::Font>)
-> FontMetrics { -> FontMetrics {
let fontgroup = font_context.layout_font_group_for_style(font_style); let fontgroup = font_context.layout_font_group_for_style(font_style);
// FIXME(https://github.com/rust-lang/rust/issues/23338) // FIXME(https://github.com/rust-lang/rust/issues/23338)

View file

@ -14,7 +14,6 @@ use script_layout_interface::restyle_damage::{BUBBLE_ISIZES, REFLOW, REFLOW_OUT_
use script_layout_interface::wrapper_traits::{LayoutNode, ThreadSafeLayoutNode}; use script_layout_interface::wrapper_traits::{LayoutNode, ThreadSafeLayoutNode};
use std::mem; use std::mem;
use style::dom::TNode; use style::dom::TNode;
use style::properties::ServoComputedValues;
use style::selector_impl::ServoSelectorImpl; use style::selector_impl::ServoSelectorImpl;
use style::servo::SharedStyleContext; use style::servo::SharedStyleContext;
use style::traversal::{DomTraversalContext, remove_from_bloom_filter, recalc_style_at}; use style::traversal::{DomTraversalContext, remove_from_bloom_filter, recalc_style_at};
@ -27,7 +26,7 @@ pub struct RecalcStyleAndConstructFlows<'lc> {
} }
impl<'lc, N> DomTraversalContext<N> for RecalcStyleAndConstructFlows<'lc> impl<'lc, N> DomTraversalContext<N> for RecalcStyleAndConstructFlows<'lc>
where N: LayoutNode + TNode<ConcreteComputedValues=ServoComputedValues>, where N: LayoutNode + TNode,
N::ConcreteElement: ::selectors::Element<Impl=ServoSelectorImpl, AttrString=String> N::ConcreteElement: ::selectors::Element<Impl=ServoSelectorImpl, AttrString=String>
{ {

View file

@ -35,7 +35,6 @@ use data::{LayoutDataFlags, PrivateLayoutData};
use script_layout_interface::wrapper_traits::{LayoutNode, ThreadSafeLayoutNode}; use script_layout_interface::wrapper_traits::{LayoutNode, ThreadSafeLayoutNode};
use script_layout_interface::{OpaqueStyleAndLayoutData, PartialStyleAndLayoutData}; use script_layout_interface::{OpaqueStyleAndLayoutData, PartialStyleAndLayoutData};
use style::computed_values::content::{self, ContentItem}; use style::computed_values::content::{self, ContentItem};
use style::properties::ComputedValues;
use style::refcell::{Ref, RefCell, RefMut}; use style::refcell::{Ref, RefCell, RefMut};
pub type NonOpaqueStyleAndLayoutData = *mut RefCell<PrivateLayoutData>; pub type NonOpaqueStyleAndLayoutData = *mut RefCell<PrivateLayoutData>;

View file

@ -105,7 +105,6 @@ 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::ComputedValues;
use style::refcell::RefCell; use style::refcell::RefCell;
use style::servo::{Animation, LocalStyleContextCreationInfo, SharedStyleContext, Stylesheet, Stylist}; use style::servo::{Animation, LocalStyleContextCreationInfo, SharedStyleContext, Stylesheet, Stylist};
use style::servo_selector_impl::USER_OR_USER_AGENT_STYLESHEETS; use style::servo_selector_impl::USER_OR_USER_AGENT_STYLESHEETS;

View file

@ -56,7 +56,6 @@ use style::attr::AttrValue;
use style::computed_values::display; use style::computed_values::display;
use style::dom::{PresentationalHintsSynthetizer, OpaqueNode, TDocument, TElement, TNode, UnsafeNode}; use style::dom::{PresentationalHintsSynthetizer, OpaqueNode, TDocument, TElement, TNode, UnsafeNode};
use style::element_state::*; use style::element_state::*;
use style::properties::{ComputedValues, ServoComputedValues};
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock}; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock};
use style::refcell::{Ref, RefCell, RefMut}; use style::refcell::{Ref, RefCell, RefMut};
use style::restyle_hints::ElementSnapshot; use style::restyle_hints::ElementSnapshot;
@ -110,7 +109,6 @@ impl<'ln> ServoLayoutNode<'ln> {
} }
impl<'ln> TNode for ServoLayoutNode<'ln> { impl<'ln> TNode for ServoLayoutNode<'ln> {
type ConcreteComputedValues = ServoComputedValues;
type ConcreteElement = ServoLayoutElement<'ln>; type ConcreteElement = ServoLayoutElement<'ln>;
type ConcreteDocument = ServoLayoutDocument<'ln>; type ConcreteDocument = ServoLayoutDocument<'ln>;
type ConcreteRestyleDamage = RestyleDamage; type ConcreteRestyleDamage = RestyleDamage;

View file

@ -6,7 +6,7 @@ use std::fmt;
use std::sync::Arc; use std::sync::Arc;
use style::computed_values::display; use style::computed_values::display;
use style::dom::TRestyleDamage; use style::dom::TRestyleDamage;
use style::properties::{ComputedValues, ServoComputedValues}; use style::properties::ServoComputedValues;
bitflags! { bitflags! {
#[doc = "Individual layout actions that may be necessary after restyling."] #[doc = "Individual layout actions that may be necessary after restyling."]
@ -44,7 +44,6 @@ bitflags! {
} }
impl TRestyleDamage for RestyleDamage { impl TRestyleDamage for RestyleDamage {
type ConcreteComputedValues = ServoComputedValues;
fn compute(old: Option<&Arc<ServoComputedValues>>, new: &ServoComputedValues) -> fn compute(old: Option<&Arc<ServoComputedValues>>, new: &ServoComputedValues) ->
RestyleDamage { compute_damage(old, new) } RestyleDamage { compute_damage(old, new) }

View file

@ -15,8 +15,7 @@ use properties::longhands::animation_iteration_count::computed_value::AnimationI
use properties::longhands::animation_play_state::computed_value::AnimationPlayState; use properties::longhands::animation_play_state::computed_value::AnimationPlayState;
use properties::longhands::transition_timing_function::computed_value::StartEnd; use properties::longhands::transition_timing_function::computed_value::StartEnd;
use properties::longhands::transition_timing_function::computed_value::TransitionTimingFunction; use properties::longhands::transition_timing_function::computed_value::TransitionTimingFunction;
use properties::style_struct_traits::Box; use properties::{self, ComputedValuesStruct};
use properties::{self, ComputedValues};
use selector_impl::SelectorImplExt; use selector_impl::SelectorImplExt;
use selectors::matching::DeclarationBlock; use selectors::matching::DeclarationBlock;
use std::sync::Arc; use std::sync::Arc;
@ -53,7 +52,7 @@ pub enum KeyframesRunningState {
/// playing or paused). /// playing or paused).
// TODO: unify the use of f32/f64 in this file. // TODO: unify the use of f32/f64 in this file.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct KeyframesAnimationState<Impl: SelectorImplExt> { pub struct KeyframesAnimationState {
/// The time this animation started at. /// The time this animation started at.
pub started_at: f64, pub started_at: f64,
/// The duration of this animation. /// The duration of this animation.
@ -72,10 +71,10 @@ pub struct KeyframesAnimationState<Impl: SelectorImplExt> {
pub expired: bool, pub expired: bool,
/// The original cascade style, needed to compute the generated keyframes of /// The original cascade style, needed to compute the generated keyframes of
/// the animation. /// the animation.
pub cascade_style: Arc<Impl::ComputedValues>, pub cascade_style: Arc<ComputedValuesStruct>,
} }
impl<Impl: SelectorImplExt> KeyframesAnimationState<Impl> { impl KeyframesAnimationState {
/// Performs a tick in the animation state, i.e., increments the counter of /// Performs a tick in the animation state, i.e., increments the counter of
/// the current iteration count, updates times and then toggles the /// the current iteration count, updates times and then toggles the
/// direction if appropriate. /// direction if appropriate.
@ -180,7 +179,7 @@ impl<Impl: SelectorImplExt> KeyframesAnimationState<Impl> {
/// State relating to an animation. /// State relating to an animation.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum Animation<Impl: SelectorImplExt> { pub enum Animation {
/// A transition is just a single frame triggered at a time, with a reflow. /// A transition is just a single frame triggered at a time, with a reflow.
/// ///
/// the f64 field is the start time as returned by `time::precise_time_s()`. /// the f64 field is the start time as returned by `time::precise_time_s()`.
@ -189,10 +188,10 @@ pub enum Animation<Impl: SelectorImplExt> {
Transition(OpaqueNode, f64, AnimationFrame, bool), Transition(OpaqueNode, f64, AnimationFrame, bool),
/// A keyframes animation is identified by a name, and can have a /// A keyframes animation is identified by a name, and can have a
/// node-dependent state (i.e. iteration count, etc.). /// node-dependent state (i.e. iteration count, etc.).
Keyframes(OpaqueNode, Atom, KeyframesAnimationState<Impl>), Keyframes(OpaqueNode, Atom, KeyframesAnimationState),
} }
impl<Impl: SelectorImplExt> Animation<Impl> { impl Animation {
#[inline] #[inline]
pub fn mark_as_expired(&mut self) { pub fn mark_as_expired(&mut self) {
debug_assert!(!self.is_expired()); debug_assert!(!self.is_expired());
@ -249,10 +248,10 @@ impl PropertyAnimation {
/// Creates a new property animation for the given transition index and old and new styles. /// Creates a new property animation for the given transition index and old and new styles.
/// Any number of animations may be returned, from zero (if the property did not animate) to /// Any number of animations may be returned, from zero (if the property did not animate) to
/// one (for a single transition property) to arbitrarily many (for `all`). /// one (for a single transition property) to arbitrarily many (for `all`).
pub fn from_transition<C: ComputedValues>(transition_index: usize, pub fn from_transition(transition_index: usize,
old_style: &C, old_style: &ComputedValuesStruct,
new_style: &mut C) new_style: &mut ComputedValuesStruct)
-> Vec<PropertyAnimation> { -> Vec<PropertyAnimation> {
let mut result = vec![]; let mut result = vec![];
let box_style = new_style.get_box(); let box_style = new_style.get_box();
let transition_property = box_style.transition_property_at(transition_index); let transition_property = box_style.transition_property_at(transition_index);
@ -286,12 +285,12 @@ impl PropertyAnimation {
result result
} }
fn from_transition_property<C: ComputedValues>(transition_property: TransitionProperty, fn from_transition_property(transition_property: TransitionProperty,
timing_function: TransitionTimingFunction, timing_function: TransitionTimingFunction,
duration: Time, duration: Time,
old_style: &C, old_style: &ComputedValuesStruct,
new_style: &C) new_style: &ComputedValuesStruct)
-> Option<PropertyAnimation> { -> Option<PropertyAnimation> {
let animated_property = AnimatedProperty::from_transition_property(&transition_property, let animated_property = AnimatedProperty::from_transition_property(&transition_property,
old_style, old_style,
new_style); new_style);
@ -309,7 +308,7 @@ impl PropertyAnimation {
} }
} }
pub fn update<C: ComputedValues>(&self, style: &mut C, time: f64) { pub fn update(&self, style: &mut ComputedValuesStruct, time: f64) {
let progress = match self.timing_function { let progress = match self.timing_function {
TransitionTimingFunction::CubicBezier(p1, p2) => { TransitionTimingFunction::CubicBezier(p1, p2) => {
// See `WebCore::AnimationBase::solveEpsilon(double)` in WebKit. // See `WebCore::AnimationBase::solveEpsilon(double)` in WebKit.
@ -340,10 +339,10 @@ impl PropertyAnimation {
// //
// TODO(emilio): Take rid of this mutex splitting SharedLayoutContex into a // TODO(emilio): Take rid of this mutex splitting SharedLayoutContex into a
// cloneable part and a non-cloneable part.. // cloneable part and a non-cloneable part..
pub fn start_transitions_if_applicable<Impl: SelectorImplExt>(new_animations_sender: &Sender<Animation<Impl>>, pub fn start_transitions_if_applicable<Impl: SelectorImplExt>(new_animations_sender: &Sender<Animation>,
node: OpaqueNode, node: OpaqueNode,
old_style: &Impl::ComputedValues, old_style: &ComputedValuesStruct,
new_style: &mut Arc<Impl::ComputedValues>) new_style: &mut Arc<ComputedValuesStruct>)
-> bool { -> bool {
let mut had_animations = false; let mut had_animations = false;
for i in 0..new_style.get_box().transition_property_count() { for i in 0..new_style.get_box().transition_property_count() {
@ -375,9 +374,9 @@ pub fn start_transitions_if_applicable<Impl: SelectorImplExt>(new_animations_sen
fn compute_style_for_animation_step<Impl: SelectorImplExt>(context: &SharedStyleContext<Impl>, fn compute_style_for_animation_step<Impl: SelectorImplExt>(context: &SharedStyleContext<Impl>,
step: &KeyframesStep, step: &KeyframesStep,
previous_style: &Impl::ComputedValues, previous_style: &ComputedValuesStruct,
style_from_cascade: &Impl::ComputedValues) style_from_cascade: &ComputedValuesStruct)
-> Impl::ComputedValues { -> ComputedValuesStruct {
match step.value { match step.value {
// TODO: avoiding this spurious clone might involve having to create // TODO: avoiding this spurious clone might involve having to create
// an Arc in the below (more common case). // an Arc in the below (more common case).
@ -400,9 +399,9 @@ fn compute_style_for_animation_step<Impl: SelectorImplExt>(context: &SharedStyle
} }
pub fn maybe_start_animations<Impl: SelectorImplExt>(context: &SharedStyleContext<Impl>, pub fn maybe_start_animations<Impl: SelectorImplExt>(context: &SharedStyleContext<Impl>,
new_animations_sender: &Sender<Animation<Impl>>, new_animations_sender: &Sender<Animation>,
node: OpaqueNode, node: OpaqueNode,
new_style: &Arc<Impl::ComputedValues>) -> bool new_style: &Arc<ComputedValuesStruct>) -> bool
{ {
let mut had_animations = false; let mut had_animations = false;
@ -470,10 +469,10 @@ pub fn maybe_start_animations<Impl: SelectorImplExt>(context: &SharedStyleContex
/// Updates a given computed style for a given animation frame. Returns a bool /// Updates a given computed style for a given animation frame. Returns a bool
/// representing if the style was indeed updated. /// representing if the style was indeed updated.
pub fn update_style_for_animation_frame<C: ComputedValues>(mut new_style: &mut Arc<C>, pub fn update_style_for_animation_frame(mut new_style: &mut Arc<ComputedValuesStruct>,
now: f64, now: f64,
start_time: f64, start_time: f64,
frame: &AnimationFrame) -> bool { frame: &AnimationFrame) -> bool {
let mut progress = (now - start_time) / frame.duration; let mut progress = (now - start_time) / frame.duration;
if progress > 1.0 { if progress > 1.0 {
progress = 1.0 progress = 1.0
@ -490,11 +489,11 @@ pub fn update_style_for_animation_frame<C: ComputedValues>(mut new_style: &mut A
/// Updates a single animation and associated style based on the current time. /// Updates a single animation and associated style based on the current time.
/// If `damage` is provided, inserts the appropriate restyle damage. /// If `damage` is provided, inserts the appropriate restyle damage.
pub fn update_style_for_animation<Damage, Impl>(context: &SharedStyleContext<Impl>, pub fn update_style_for_animation<Damage, Impl>(context: &SharedStyleContext<Impl>,
animation: &Animation<Impl>, animation: &Animation,
style: &mut Arc<Damage::ConcreteComputedValues>, style: &mut Arc<ComputedValuesStruct>,
damage: Option<&mut Damage>) damage: Option<&mut Damage>)
where Impl: SelectorImplExt, where Impl: SelectorImplExt,
Damage: TRestyleDamage<ConcreteComputedValues = Impl::ComputedValues> { Damage: TRestyleDamage {
debug!("update_style_for_animation: entering"); debug!("update_style_for_animation: entering");
debug_assert!(!animation.is_expired()); debug_assert!(!animation.is_expired());
match *animation { match *animation {

View file

@ -18,12 +18,12 @@ use std::sync::mpsc::Sender;
use std::sync::{Arc, Mutex, RwLock}; use std::sync::{Arc, Mutex, RwLock};
/// This structure is used to create a local style context from a shared one. /// This structure is used to create a local style context from a shared one.
pub struct LocalStyleContextCreationInfo<Impl: SelectorImplExt> { pub struct LocalStyleContextCreationInfo {
new_animations_sender: Sender<Animation<Impl>>, new_animations_sender: Sender<Animation>,
} }
impl<Impl: SelectorImplExt> LocalStyleContextCreationInfo<Impl> { impl LocalStyleContextCreationInfo {
pub fn new(animations_sender: Sender<Animation<Impl>>) -> Self { pub fn new(animations_sender: Sender<Animation>) -> Self {
LocalStyleContextCreationInfo { LocalStyleContextCreationInfo {
new_animations_sender: animations_sender, new_animations_sender: animations_sender,
} }
@ -48,28 +48,28 @@ pub struct SharedStyleContext<Impl: SelectorImplExt> {
pub goal: ReflowGoal, pub goal: ReflowGoal,
/// The animations that are currently running. /// The animations that are currently running.
pub running_animations: Arc<RwLock<HashMap<OpaqueNode, Vec<Animation<Impl>>>>>, pub running_animations: Arc<RwLock<HashMap<OpaqueNode, Vec<Animation>>>>,
/// The list of animations that have expired since the last style recalculation. /// The list of animations that have expired since the last style recalculation.
pub expired_animations: Arc<RwLock<HashMap<OpaqueNode, Vec<Animation<Impl>>>>>, pub expired_animations: Arc<RwLock<HashMap<OpaqueNode, Vec<Animation>>>>,
///The CSS error reporter for all CSS loaded in this layout thread ///The CSS error reporter for all CSS loaded in this layout thread
pub error_reporter: Box<ParseErrorReporter + Sync>, pub error_reporter: Box<ParseErrorReporter + Sync>,
/// Data needed to create the local style context from the shared one. /// Data needed to create the local style context from the shared one.
pub local_context_creation_data: Mutex<LocalStyleContextCreationInfo<Impl>>, pub local_context_creation_data: Mutex<LocalStyleContextCreationInfo>,
} }
pub struct LocalStyleContext<Impl: SelectorImplExt> { pub struct LocalStyleContext {
pub applicable_declarations_cache: RefCell<ApplicableDeclarationsCache<Impl::ComputedValues>>, pub applicable_declarations_cache: RefCell<ApplicableDeclarationsCache>,
pub style_sharing_candidate_cache: RefCell<StyleSharingCandidateCache<Impl::ComputedValues>>, pub style_sharing_candidate_cache: RefCell<StyleSharingCandidateCache>,
/// A channel on which new animations that have been triggered by style /// A channel on which new animations that have been triggered by style
/// recalculation can be sent. /// recalculation can be sent.
pub new_animations_sender: Sender<Animation<Impl>>, pub new_animations_sender: Sender<Animation>,
} }
impl<Impl: SelectorImplExt> LocalStyleContext<Impl> { impl LocalStyleContext {
pub fn new(local_context_creation_data: &LocalStyleContextCreationInfo<Impl>) -> Self { pub fn new(local_context_creation_data: &LocalStyleContextCreationInfo) -> Self {
LocalStyleContext { LocalStyleContext {
applicable_declarations_cache: RefCell::new(ApplicableDeclarationsCache::new()), applicable_declarations_cache: RefCell::new(ApplicableDeclarationsCache::new()),
style_sharing_candidate_cache: RefCell::new(StyleSharingCandidateCache::new()), style_sharing_candidate_cache: RefCell::new(StyleSharingCandidateCache::new()),
@ -80,7 +80,7 @@ impl<Impl: SelectorImplExt> LocalStyleContext<Impl> {
pub trait StyleContext<'a, Impl: SelectorImplExt> { pub trait StyleContext<'a, Impl: SelectorImplExt> {
fn shared_context(&self) -> &'a SharedStyleContext<Impl>; fn shared_context(&self) -> &'a SharedStyleContext<Impl>;
fn local_context(&self) -> &LocalStyleContext<Impl>; fn local_context(&self) -> &LocalStyleContext;
} }
/// Why we're doing reflow. /// Why we're doing reflow.

View file

@ -4,28 +4,28 @@
//! Per-node data used in style calculation. //! Per-node data used in style calculation.
use properties::ComputedValues; use properties::ComputedValuesStruct;
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, ConcreteComputedValues: ComputedValues> { pub struct PrivateStyleData<Impl: SelectorImpl> {
/// The results of CSS styling for this node. /// The results of CSS styling for this node.
pub style: Option<Arc<ConcreteComputedValues>>, pub style: Option<Arc<ComputedValuesStruct>>,
/// 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<ConcreteComputedValues>, pub per_pseudo: HashMap<Impl::PseudoElement, Arc<ComputedValuesStruct>,
BuildHasherDefault<::fnv::FnvHasher>>, BuildHasherDefault<::fnv::FnvHasher>>,
/// Information needed during parallel traversals. /// Information needed during parallel traversals.
pub parallel: DomParallelInfo, pub parallel: DomParallelInfo,
} }
impl<Impl, ConcreteComputedValues> PrivateStyleData<Impl, ConcreteComputedValues> impl<Impl> PrivateStyleData<Impl>
where Impl: SelectorImpl, ConcreteComputedValues: ComputedValues { where Impl: SelectorImpl {
pub fn new() -> PrivateStyleData<Impl, ConcreteComputedValues> { pub fn new() -> Self {
PrivateStyleData { PrivateStyleData {
style: None, style: None,
per_pseudo: HashMap::with_hasher(Default::default()), per_pseudo: HashMap::with_hasher(Default::default()),

View file

@ -9,7 +9,7 @@
use context::SharedStyleContext; use context::SharedStyleContext;
use data::PrivateStyleData; use data::PrivateStyleData;
use element_state::ElementState; use element_state::ElementState;
use properties::{ComputedValues, PropertyDeclaration, PropertyDeclarationBlock}; use properties::{ComputedValuesStruct, PropertyDeclaration, PropertyDeclarationBlock};
use refcell::{Ref, RefMut}; use refcell::{Ref, RefMut};
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, SelectorImplExt}; use selector_impl::{ElementExt, SelectorImplExt};
@ -46,16 +46,14 @@ impl OpaqueNode {
} }
pub trait TRestyleDamage : BitOr<Output=Self> + Copy { pub trait TRestyleDamage : BitOr<Output=Self> + Copy {
type ConcreteComputedValues: ComputedValues; fn compute(old: Option<&Arc<ComputedValuesStruct>>, new: &ComputedValuesStruct) -> Self;
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<ConcreteComputedValues = Self::ConcreteComputedValues>; type ConcreteRestyleDamage: TRestyleDamage;
type ConcreteComputedValues: ComputedValues;
fn to_unsafe(&self) -> UnsafeNode; fn to_unsafe(&self) -> UnsafeNode;
unsafe fn from_unsafe(n: &UnsafeNode) -> Self; unsafe fn from_unsafe(n: &UnsafeNode) -> Self;
@ -147,20 +145,17 @@ 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;
@ -183,8 +178,8 @@ pub trait TNode : Sized + Copy + Clone {
/// has not yet been performed, fails. /// has not yet been performed, fails.
fn style(&self, fn style(&self,
_context: &SharedStyleContext<<Self::ConcreteElement as Element>::Impl>) _context: &SharedStyleContext<<Self::ConcreteElement as Element>::Impl>)
-> Ref<Arc<Self::ConcreteComputedValues>> -> Ref<Arc<ComputedValuesStruct>>
where <Self::ConcreteElement as Element>::Impl: SelectorImplExt<ComputedValues=Self::ConcreteComputedValues> { where <Self::ConcreteElement as Element>::Impl: SelectorImplExt {
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

@ -3,7 +3,6 @@
* 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 element_state::ElementState; use element_state::ElementState;
use gecko_properties::GeckoComputedValues;
use selector_impl::{PseudoElementCascadeType, SelectorImplExt}; use selector_impl::{PseudoElementCascadeType, SelectorImplExt};
use selectors::parser::{ParserContext, SelectorImpl}; use selectors::parser::{ParserContext, SelectorImpl};
use string_cache::Atom; use string_cache::Atom;
@ -11,8 +10,8 @@ use string_cache::Atom;
pub type Stylist = ::selector_matching::Stylist<GeckoSelectorImpl>; pub type Stylist = ::selector_matching::Stylist<GeckoSelectorImpl>;
pub type Stylesheet = ::stylesheets::Stylesheet<GeckoSelectorImpl>; pub type Stylesheet = ::stylesheets::Stylesheet<GeckoSelectorImpl>;
pub type SharedStyleContext = ::context::SharedStyleContext<GeckoSelectorImpl>; pub type SharedStyleContext = ::context::SharedStyleContext<GeckoSelectorImpl>;
pub type PrivateStyleData = ::data::PrivateStyleData<GeckoSelectorImpl, GeckoComputedValues>; pub type PrivateStyleData = ::data::PrivateStyleData<GeckoSelectorImpl>;
pub type Animation = ::animation::Animation<GeckoSelectorImpl>; pub type Animation = ::animation::Animation;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct GeckoSelectorImpl; pub struct GeckoSelectorImpl;
@ -291,8 +290,6 @@ impl SelectorImpl for GeckoSelectorImpl {
} }
impl SelectorImplExt for GeckoSelectorImpl { impl SelectorImplExt for GeckoSelectorImpl {
type ComputedValues = GeckoComputedValues;
#[inline] #[inline]
fn pseudo_element_cascade_type(pseudo: &PseudoElement) -> PseudoElementCascadeType { fn pseudo_element_cascade_type(pseudo: &PseudoElement) -> PseudoElementCascadeType {
match *pseudo { match *pseudo {

View file

@ -12,7 +12,7 @@ use cache::{LRUCache, SimpleHashCache};
use context::{StyleContext, SharedStyleContext}; use context::{StyleContext, SharedStyleContext};
use data::PrivateStyleData; use data::PrivateStyleData;
use dom::{TElement, TNode, TRestyleDamage}; use dom::{TElement, TNode, TRestyleDamage};
use properties::{ComputedValues, PropertyDeclaration, cascade}; use properties::{ComputedValuesStruct, PropertyDeclaration, cascade};
use selector_impl::{ElementExt, SelectorImplExt}; use selector_impl::{ElementExt, SelectorImplExt};
use selector_matching::{DeclarationBlock, Stylist}; use selector_matching::{DeclarationBlock, Stylist};
use selectors::Element; use selectors::Element;
@ -149,25 +149,25 @@ impl<'a> Hash for ApplicableDeclarationsCacheQuery<'a> {
static APPLICABLE_DECLARATIONS_CACHE_SIZE: usize = 32; static APPLICABLE_DECLARATIONS_CACHE_SIZE: usize = 32;
pub struct ApplicableDeclarationsCache<C: ComputedValues> { pub struct ApplicableDeclarationsCache {
cache: SimpleHashCache<ApplicableDeclarationsCacheEntry, Arc<C>>, cache: SimpleHashCache<ApplicableDeclarationsCacheEntry, Arc<ComputedValuesStruct>>,
} }
impl<C: ComputedValues> ApplicableDeclarationsCache<C> { impl ApplicableDeclarationsCache {
pub fn new() -> Self { 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<C>> { pub fn find(&self, declarations: &[DeclarationBlock]) -> Option<Arc<ComputedValuesStruct>> {
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<C>) { pub fn insert(&mut self, declarations: Vec<DeclarationBlock>, style: Arc<ComputedValuesStruct>) {
self.cache.insert(ApplicableDeclarationsCacheEntry::new(declarations), style) self.cache.insert(ApplicableDeclarationsCacheEntry::new(declarations), style)
} }
@ -177,14 +177,14 @@ impl<C: ComputedValues> ApplicableDeclarationsCache<C> {
} }
/// 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<C: ComputedValues> { pub struct StyleSharingCandidateCache {
cache: LRUCache<StyleSharingCandidate<C>, ()>, cache: LRUCache<StyleSharingCandidate, ()>,
} }
#[derive(Clone)] #[derive(Clone)]
pub struct StyleSharingCandidate<C: ComputedValues> { pub struct StyleSharingCandidate {
pub style: Arc<C>, pub style: Arc<ComputedValuesStruct>,
pub parent_style: Arc<C>, pub parent_style: Arc<ComputedValuesStruct>,
pub local_name: Atom, pub local_name: Atom,
pub classes: Vec<Atom>, pub classes: Vec<Atom>,
pub namespace: Namespace, pub namespace: Namespace,
@ -192,7 +192,7 @@ pub struct StyleSharingCandidate<C: ComputedValues> {
pub link: bool, pub link: bool,
} }
impl<C: ComputedValues> PartialEq for StyleSharingCandidate<C> { impl PartialEq for StyleSharingCandidate {
fn eq(&self, other: &Self) -> 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) &&
@ -204,12 +204,12 @@ impl<C: ComputedValues> PartialEq for StyleSharingCandidate<C> {
} }
} }
impl<C: ComputedValues> StyleSharingCandidate<C> { impl StyleSharingCandidate {
/// 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<N: TNode<ConcreteComputedValues=C>>(element: &N::ConcreteElement) -> Option<Self> { fn new<N: TNode>(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,
@ -329,18 +329,18 @@ impl<C: ComputedValues> StyleSharingCandidate<C> {
static STYLE_SHARING_CANDIDATE_CACHE_SIZE: usize = 40; static STYLE_SHARING_CANDIDATE_CACHE_SIZE: usize = 40;
impl<C: ComputedValues> StyleSharingCandidateCache<C> { impl StyleSharingCandidateCache {
pub fn new() -> Self { 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<C>, ())> { pub fn iter(&self) -> Iter<(StyleSharingCandidate, ())> {
self.cache.iter() self.cache.iter()
} }
pub fn insert_if_possible<N: TNode<ConcreteComputedValues=C>>(&mut self, element: &N::ConcreteElement) { pub fn insert_if_possible<N: TNode>(&mut self, element: &N::ConcreteElement) {
match StyleSharingCandidate::new::<N>(element) { match StyleSharingCandidate::new::<N>(element) {
None => {} None => {}
Some(candidate) => self.cache.insert(candidate, ()) Some(candidate) => self.cache.insert(candidate, ())
@ -362,21 +362,21 @@ pub enum StyleSharingResult<ConcreteRestyleDamage: TRestyleDamage> {
} }
trait PrivateMatchMethods: TNode trait PrivateMatchMethods: TNode
where <Self::ConcreteElement as Element>::Impl: SelectorImplExt<ComputedValues = Self::ConcreteComputedValues> { where <Self::ConcreteElement as Element>::Impl: SelectorImplExt {
/// Actually cascades style for a node or a pseudo-element of a node. /// Actually cascades style for a node or a pseudo-element of a node.
/// ///
/// Note that animations only apply to nodes or ::before or ::after /// Note that animations only apply to nodes or ::before or ::after
/// pseudo-elements. /// pseudo-elements.
fn cascade_node_pseudo_element<'a, Ctx>(&self, fn cascade_node_pseudo_element<'a, Ctx>(&self,
context: &Ctx, context: &Ctx,
parent_style: Option<&Arc<Self::ConcreteComputedValues>>, parent_style: Option<&Arc<ComputedValuesStruct>>,
applicable_declarations: &[DeclarationBlock], applicable_declarations: &[DeclarationBlock],
mut style: Option<&mut Arc<Self::ConcreteComputedValues>>, mut style: Option<&mut Arc<ComputedValuesStruct>>,
applicable_declarations_cache: applicable_declarations_cache:
&mut ApplicableDeclarationsCache<Self::ConcreteComputedValues>, &mut ApplicableDeclarationsCache,
shareable: bool, shareable: bool,
animate_properties: bool) animate_properties: bool)
-> (Self::ConcreteRestyleDamage, Arc<Self::ConcreteComputedValues>) -> (Self::ConcreteRestyleDamage, Arc<ComputedValuesStruct>)
where Ctx: StyleContext<'a, <Self::ConcreteElement as Element>::Impl> { where Ctx: StyleContext<'a, <Self::ConcreteElement as Element>::Impl> {
let mut cacheable = true; let mut cacheable = true;
let shared_context = context.shared_context(); let shared_context = context.shared_context();
@ -456,7 +456,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<Self::ConcreteComputedValues>>) style: &mut Option<&mut Arc<ComputedValuesStruct>>)
-> bool { -> bool {
let style = match *style { let style = match *style {
None => return false, None => return false,
@ -518,21 +518,19 @@ trait PrivateMatchMethods: TNode
} }
impl<N: TNode> PrivateMatchMethods for N impl<N: TNode> PrivateMatchMethods for N
where <N::ConcreteElement as Element>::Impl: where <N::ConcreteElement as Element>::Impl: SelectorImplExt {}
SelectorImplExt<ComputedValues = N::ConcreteComputedValues> {}
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<<Self::ConcreteNode as candidate: &StyleSharingCandidate)
TNode>::ConcreteComputedValues>) -> Option<Arc<ComputedValuesStruct>> {
-> 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)
}; };
@ -586,8 +584,7 @@ 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<<Self::ConcreteNode as &mut StyleSharingCandidateCache,
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 {
@ -674,7 +671,7 @@ pub trait MatchMethods : TNode {
parent: Option<Self>, parent: Option<Self>,
applicable_declarations: applicable_declarations:
&ApplicableDeclarations<<Self::ConcreteElement as Element>::Impl>) &ApplicableDeclarations<<Self::ConcreteElement as Element>::Impl>)
where <Self::ConcreteElement as Element>::Impl: SelectorImplExt<ComputedValues = Self::ConcreteComputedValues>, where <Self::ConcreteElement as Element>::Impl: SelectorImplExt,
Ctx: StyleContext<'a, <Self::ConcreteElement as Element>::Impl> Ctx: StyleContext<'a, <Self::ConcreteElement as Element>::Impl>
{ {
// 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
@ -697,7 +694,7 @@ pub trait MatchMethods : TNode {
if self.is_text_node() { if self.is_text_node() {
let mut data_ref = self.mutate_data().unwrap(); let mut data_ref = self.mutate_data().unwrap();
let mut data = &mut *data_ref; let mut data = &mut *data_ref;
let cloned_parent_style = Self::ConcreteComputedValues::style_for_child_text_node(parent_style.unwrap()); let cloned_parent_style = ComputedValuesStruct::style_for_child_text_node(parent_style.unwrap());
damage = Self::ConcreteRestyleDamage::compute(data.style.as_ref(), damage = Self::ConcreteRestyleDamage::compute(data.style.as_ref(),
&*cloned_parent_style); &*cloned_parent_style);
data.style = Some(cloned_parent_style); data.style = Some(cloned_parent_style);

View file

@ -117,11 +117,10 @@ class Method(object):
class StyleStruct(object): class StyleStruct(object):
def __init__(self, name, inherited, gecko_name=None, additional_methods=None): def __init__(self, name, inherited, gecko_name=None, additional_methods=None):
self.servo_struct_name = "Servo" + name
self.gecko_struct_name = "Gecko" + name self.gecko_struct_name = "Gecko" + name
self.trait_name = name self.name = name
self.trait_name_lower = name.lower() self.name_lower = name.lower()
self.ident = to_rust_ident(self.trait_name_lower) self.ident = to_rust_ident(self.name_lower)
self.longhands = [] self.longhands = []
self.inherited = inherited self.inherited = inherited
self.gecko_name = gecko_name or name self.gecko_name = gecko_name or name

View file

@ -24,24 +24,30 @@ use gecko_bindings::bindings::{Gecko_EnsureImageLayersLength, Gecko_CreateGradie
use gecko_bindings::bindings::{Gecko_CopyImageValueFrom, Gecko_CopyFontFamilyFrom}; use gecko_bindings::bindings::{Gecko_CopyImageValueFrom, Gecko_CopyFontFamilyFrom};
use gecko_bindings::bindings::{Gecko_FontFamilyList_AppendGeneric, Gecko_FontFamilyList_AppendNamed}; use gecko_bindings::bindings::{Gecko_FontFamilyList_AppendGeneric, Gecko_FontFamilyList_AppendNamed};
use gecko_bindings::bindings::{Gecko_FontFamilyList_Clear, Gecko_InitializeImageLayer}; use gecko_bindings::bindings::{Gecko_FontFamilyList_Clear, Gecko_InitializeImageLayer};
use gecko_bindings::bindings;
use gecko_bindings::structs; use gecko_bindings::structs;
use gecko_glue::ArcHelpers; use gecko_glue::ArcHelpers;
use gecko_values::{StyleCoordHelpers, GeckoStyleCoordConvertible, convert_nscolor_to_rgba}; use gecko_values::{StyleCoordHelpers, GeckoStyleCoordConvertible, convert_nscolor_to_rgba};
use gecko_values::convert_rgba_to_nscolor; use gecko_values::convert_rgba_to_nscolor;
use gecko_values::round_border_to_device_pixels; use gecko_values::round_border_to_device_pixels;
use logical_geometry::WritingMode; use logical_geometry::WritingMode;
use properties::{CascadePropertyFn, ServoComputedValues, ComputedValues}; use properties::CascadePropertyFn;
use properties::longhands; use properties::longhands;
use properties::style_struct_traits::*;
use std::fmt::{self, Debug}; use std::fmt::{self, Debug};
use std::mem::{transmute, uninitialized, zeroed}; use std::mem::{transmute, uninitialized, zeroed};
use std::sync::Arc; use std::sync::Arc;
use std::cmp; use std::cmp;
#[derive(Clone, Debug)] pub mod style_structs {
pub struct GeckoComputedValues {
% for style_struct in data.style_structs: % for style_struct in data.style_structs:
${style_struct.ident}: Arc<${style_struct.gecko_struct_name}>, pub use super::${style_struct.gecko_struct_name} as ${style_struct.name};
% endfor
}
#[derive(Clone, Debug)]
pub struct ComputedValuesStruct {
% for style_struct in data.style_structs:
${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
% endfor % endfor
custom_properties: Option<Arc<ComputedValuesMap>>, custom_properties: Option<Arc<ComputedValuesMap>>,
@ -50,9 +56,9 @@ pub struct GeckoComputedValues {
pub root_font_size: Au, pub root_font_size: Au,
} }
impl GeckoComputedValues { impl ComputedValuesStruct {
pub fn inherit_from(parent: &Arc<Self>) -> Arc<Self> { pub fn inherit_from(parent: &Arc<Self>) -> Arc<Self> {
Arc::new(GeckoComputedValues { Arc::new(ComputedValuesStruct {
custom_properties: parent.custom_properties.clone(), custom_properties: parent.custom_properties.clone(),
shareable: parent.shareable, shareable: parent.shareable,
writing_mode: parent.writing_mode, writing_mode: parent.writing_mode,
@ -66,22 +72,16 @@ impl GeckoComputedValues {
% endfor % endfor
}) })
} }
}
impl ComputedValues for GeckoComputedValues { pub fn new(custom_properties: Option<Arc<ComputedValuesMap>>,
% for style_struct in data.style_structs:
type Concrete${style_struct.trait_name} = ${style_struct.gecko_struct_name};
% endfor
fn new(custom_properties: Option<Arc<ComputedValuesMap>>,
shareable: bool, shareable: bool,
writing_mode: WritingMode, writing_mode: WritingMode,
root_font_size: Au, root_font_size: Au,
% for style_struct in data.style_structs: % for style_struct in data.style_structs:
${style_struct.ident}: Arc<${style_struct.gecko_struct_name}>, ${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
% endfor % endfor
) -> Self { ) -> Self {
GeckoComputedValues { ComputedValuesStruct {
custom_properties: custom_properties, custom_properties: custom_properties,
shareable: shareable, shareable: shareable,
writing_mode: writing_mode, writing_mode: writing_mode,
@ -92,43 +92,46 @@ impl ComputedValues for GeckoComputedValues {
} }
} }
fn style_for_child_text_node(parent: &Arc<Self>) -> Arc<Self> { pub fn style_for_child_text_node(parent: &Arc<Self>) -> Arc<Self> {
// Gecko expects text nodes to be styled as if they were elements that // Gecko expects text nodes to be styled as if they were elements that
// matched no rules (that is, inherited style structs are inherited and // matched no rules (that is, inherited style structs are inherited and
// non-inherited style structs are set to their initial values). // non-inherited style structs are set to their initial values).
GeckoComputedValues::inherit_from(parent) ComputedValuesStruct::inherit_from(parent)
} }
fn initial_values() -> &'static Self { &*INITIAL_GECKO_VALUES } pub fn initial_values() -> &'static Self { &*INITIAL_GECKO_VALUES }
#[inline] #[inline]
fn do_cascade_property<F: FnOnce(&[CascadePropertyFn<Self>])>(f: F) { pub fn do_cascade_property<F: FnOnce(&[CascadePropertyFn])>(f: F) {
f(&CASCADE_PROPERTY) f(&CASCADE_PROPERTY)
} }
% for style_struct in data.style_structs: % for style_struct in data.style_structs:
#[inline] #[inline]
fn clone_${style_struct.trait_name_lower}(&self) -> Arc<Self::Concrete${style_struct.trait_name}> { pub fn clone_${style_struct.name_lower}(&self) -> Arc<style_structs::${style_struct.name}> {
self.${style_struct.ident}.clone() self.${style_struct.ident}.clone()
} }
#[inline] #[inline]
fn get_${style_struct.trait_name_lower}<'a>(&'a self) -> &'a Self::Concrete${style_struct.trait_name} { pub fn get_${style_struct.name_lower}(&self) -> &style_structs::${style_struct.name} {
&self.${style_struct.ident} &self.${style_struct.ident}
} }
#[inline] #[inline]
fn mutate_${style_struct.trait_name_lower}<'a>(&'a mut self) -> &'a mut Self::Concrete${style_struct.trait_name} { pub fn mutate_${style_struct.name_lower}(&mut self) -> &mut style_structs::${style_struct.name} {
Arc::make_mut(&mut self.${style_struct.ident}) Arc::make_mut(&mut self.${style_struct.ident})
} }
% endfor % endfor
fn custom_properties(&self) -> Option<Arc<ComputedValuesMap>> { self.custom_properties.as_ref().map(|x| x.clone())} pub fn custom_properties(&self) -> Option<Arc<ComputedValuesMap>> {
fn root_font_size(&self) -> Au { self.root_font_size } self.custom_properties.as_ref().map(|x| x.clone())
fn set_root_font_size(&mut self, s: Au) { self.root_font_size = s; } }
fn set_writing_mode(&mut self, mode: WritingMode) { self.writing_mode = mode; }
pub fn root_font_size(&self) -> Au { self.root_font_size }
pub fn set_root_font_size(&mut self, s: Au) { self.root_font_size = s; }
pub fn set_writing_mode(&mut self, mode: WritingMode) { self.writing_mode = mode; }
// FIXME(bholley): Implement this properly. // FIXME(bholley): Implement this properly.
#[inline] #[inline]
fn is_multicol(&self) -> bool { false } pub fn is_multicol(&self) -> bool { false }
} }
<%def name="declare_style_struct(style_struct)"> <%def name="declare_style_struct(style_struct)">
@ -138,25 +141,29 @@ pub struct ${style_struct.gecko_struct_name} {
</%def> </%def>
<%def name="impl_simple_setter(ident, gecko_ffi_name)"> <%def name="impl_simple_setter(ident, gecko_ffi_name)">
fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) { #[allow(non_snake_case)]
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
${set_gecko_property(gecko_ffi_name, "v")} ${set_gecko_property(gecko_ffi_name, "v")}
} }
</%def> </%def>
<%def name="impl_simple_clone(ident, gecko_ffi_name)"> <%def name="impl_simple_clone(ident, gecko_ffi_name)">
fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { #[allow(non_snake_case)]
pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
self.gecko.${gecko_ffi_name} self.gecko.${gecko_ffi_name}
} }
</%def> </%def>
<%def name="impl_simple_copy(ident, gecko_ffi_name, *kwargs)"> <%def name="impl_simple_copy(ident, gecko_ffi_name, *kwargs)">
fn copy_${ident}_from(&mut self, other: &Self) { #[allow(non_snake_case)]
pub fn copy_${ident}_from(&mut self, other: &Self) {
self.gecko.${gecko_ffi_name} = other.gecko.${gecko_ffi_name}; self.gecko.${gecko_ffi_name} = other.gecko.${gecko_ffi_name};
} }
</%def> </%def>
<%def name="impl_coord_copy(ident, gecko_ffi_name)"> <%def name="impl_coord_copy(ident, gecko_ffi_name)">
fn copy_${ident}_from(&mut self, other: &Self) { #[allow(non_snake_case)]
pub fn copy_${ident}_from(&mut self, other: &Self) {
self.gecko.${gecko_ffi_name}.copy_from(&other.gecko.${gecko_ffi_name}); self.gecko.${gecko_ffi_name}.copy_from(&other.gecko.${gecko_ffi_name});
} }
</%def> </%def>
@ -180,7 +187,8 @@ def set_gecko_property(ffi_name, expr):
%> %>
<%def name="impl_keyword_setter(ident, gecko_ffi_name, keyword)"> <%def name="impl_keyword_setter(ident, gecko_ffi_name, keyword)">
fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) { #[allow(non_snake_case)]
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
use properties::longhands::${ident}::computed_value::T as Keyword; use properties::longhands::${ident}::computed_value::T as Keyword;
// FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts // FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts
let result = match v { let result = match v {
@ -193,7 +201,8 @@ def set_gecko_property(ffi_name, expr):
</%def> </%def>
<%def name="impl_keyword_clone(ident, gecko_ffi_name, keyword)"> <%def name="impl_keyword_clone(ident, gecko_ffi_name, keyword)">
fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { #[allow(non_snake_case)]
pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
use properties::longhands::${ident}::computed_value::T as Keyword; use properties::longhands::${ident}::computed_value::T as Keyword;
// FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts // FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts
match ${get_gecko_property(gecko_ffi_name)} as u32 { match ${get_gecko_property(gecko_ffi_name)} as u32 {
@ -232,7 +241,8 @@ def set_gecko_property(ffi_name, expr):
<%def name="impl_color_setter(ident, gecko_ffi_name, color_flags_ffi_name=None)"> <%def name="impl_color_setter(ident, gecko_ffi_name, color_flags_ffi_name=None)">
#[allow(unreachable_code)] #[allow(unreachable_code)]
fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) { #[allow(non_snake_case)]
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
use cssparser::Color; use cssparser::Color;
${clear_color_flags(color_flags_ffi_name)} ${clear_color_flags(color_flags_ffi_name)}
let result = match v { let result = match v {
@ -247,7 +257,8 @@ def set_gecko_property(ffi_name, expr):
</%def> </%def>
<%def name="impl_color_copy(ident, gecko_ffi_name, color_flags_ffi_name=None)"> <%def name="impl_color_copy(ident, gecko_ffi_name, color_flags_ffi_name=None)">
fn copy_${ident}_from(&mut self, other: &Self) { #[allow(non_snake_case)]
pub fn copy_${ident}_from(&mut self, other: &Self) {
% if color_flags_ffi_name: % if color_flags_ffi_name:
${clear_color_flags(color_flags_ffi_name)} ${clear_color_flags(color_flags_ffi_name)}
if ${get_current_color_flag_from("other.gecko." + color_flags_ffi_name)} { if ${get_current_color_flag_from("other.gecko." + color_flags_ffi_name)} {
@ -259,7 +270,8 @@ def set_gecko_property(ffi_name, expr):
</%def> </%def>
<%def name="impl_color_clone(ident, gecko_ffi_name, color_flags_ffi_name=None)"> <%def name="impl_color_clone(ident, gecko_ffi_name, color_flags_ffi_name=None)">
fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { #[allow(non_snake_case)]
pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
use cssparser::Color; use cssparser::Color;
% if color_flags_ffi_name: % if color_flags_ffi_name:
if ${get_current_color_flag_from("self.gecko." + color_flags_ffi_name)} { if ${get_current_color_flag_from("self.gecko." + color_flags_ffi_name)} {
@ -295,7 +307,8 @@ def set_gecko_property(ffi_name, expr):
</%def> </%def>
<%def name="impl_app_units(ident, gecko_ffi_name, need_clone, round_to_pixels=False)"> <%def name="impl_app_units(ident, gecko_ffi_name, need_clone, round_to_pixels=False)">
fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) { #[allow(non_snake_case)]
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
% if round_to_pixels: % if round_to_pixels:
let au_per_device_px = Au(self.gecko.mTwipsPerPixel); let au_per_device_px = Au(self.gecko.mTwipsPerPixel);
self.gecko.${gecko_ffi_name} = round_border_to_device_pixels(v, au_per_device_px).0; self.gecko.${gecko_ffi_name} = round_border_to_device_pixels(v, au_per_device_px).0;
@ -305,25 +318,29 @@ def set_gecko_property(ffi_name, expr):
} }
<%call expr="impl_simple_copy(ident, gecko_ffi_name)"></%call> <%call expr="impl_simple_copy(ident, gecko_ffi_name)"></%call>
%if need_clone: %if need_clone:
fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { #[allow(non_snake_case)]
pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
Au(self.gecko.${gecko_ffi_name}) Au(self.gecko.${gecko_ffi_name})
} }
% endif % endif
</%def> </%def>
<%def name="impl_split_style_coord(ident, unit_ffi_name, union_ffi_name, need_clone=False)"> <%def name="impl_split_style_coord(ident, unit_ffi_name, union_ffi_name, need_clone=False)">
fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) { #[allow(non_snake_case)]
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
v.to_gecko_style_coord(&mut self.gecko.${unit_ffi_name}, v.to_gecko_style_coord(&mut self.gecko.${unit_ffi_name},
&mut self.gecko.${union_ffi_name}); &mut self.gecko.${union_ffi_name});
} }
fn copy_${ident}_from(&mut self, other: &Self) { #[allow(non_snake_case)]
pub fn copy_${ident}_from(&mut self, other: &Self) {
unsafe { self.gecko.${union_ffi_name}.reset(&mut self.gecko.${unit_ffi_name}) }; unsafe { self.gecko.${union_ffi_name}.reset(&mut self.gecko.${unit_ffi_name}) };
self.gecko.${unit_ffi_name} = other.gecko.${unit_ffi_name}; self.gecko.${unit_ffi_name} = other.gecko.${unit_ffi_name};
self.gecko.${union_ffi_name} = other.gecko.${union_ffi_name}; self.gecko.${union_ffi_name} = other.gecko.${union_ffi_name};
unsafe { self.gecko.${union_ffi_name}.addref_if_calc(&self.gecko.${unit_ffi_name}) }; unsafe { self.gecko.${union_ffi_name}.addref_if_calc(&self.gecko.${unit_ffi_name}) };
} }
% if need_clone: % if need_clone:
fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { #[allow(non_snake_case)]
pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
use properties::longhands::${ident}::computed_value::T; use properties::longhands::${ident}::computed_value::T;
T::from_gecko_style_coord(&self.gecko.${unit_ffi_name}, T::from_gecko_style_coord(&self.gecko.${unit_ffi_name},
&self.gecko.${union_ffi_name}) &self.gecko.${union_ffi_name})
@ -341,13 +358,15 @@ ${impl_split_style_coord(ident,
<%def name="impl_corner_style_coord(ident, x_unit_ffi_name, x_union_ffi_name, \ <%def name="impl_corner_style_coord(ident, x_unit_ffi_name, x_union_ffi_name, \
y_unit_ffi_name, y_union_ffi_name, need_clone=False)"> y_unit_ffi_name, y_union_ffi_name, need_clone=False)">
fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) { #[allow(non_snake_case)]
pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
v.0.width.to_gecko_style_coord(&mut self.gecko.${x_unit_ffi_name}, v.0.width.to_gecko_style_coord(&mut self.gecko.${x_unit_ffi_name},
&mut self.gecko.${x_union_ffi_name}); &mut self.gecko.${x_union_ffi_name});
v.0.height.to_gecko_style_coord(&mut self.gecko.${y_unit_ffi_name}, v.0.height.to_gecko_style_coord(&mut self.gecko.${y_unit_ffi_name},
&mut self.gecko.${y_union_ffi_name}); &mut self.gecko.${y_union_ffi_name});
} }
fn copy_${ident}_from(&mut self, other: &Self) { #[allow(non_snake_case)]
pub fn copy_${ident}_from(&mut self, other: &Self) {
unsafe { self.gecko.${x_union_ffi_name}.reset(&mut self.gecko.${x_unit_ffi_name}) }; unsafe { self.gecko.${x_union_ffi_name}.reset(&mut self.gecko.${x_unit_ffi_name}) };
unsafe { self.gecko.${y_union_ffi_name}.reset(&mut self.gecko.${y_unit_ffi_name}) }; unsafe { self.gecko.${y_union_ffi_name}.reset(&mut self.gecko.${y_unit_ffi_name}) };
self.gecko.${x_unit_ffi_name} = other.gecko.${x_unit_ffi_name}; self.gecko.${x_unit_ffi_name} = other.gecko.${x_unit_ffi_name};
@ -358,7 +377,8 @@ ${impl_split_style_coord(ident,
unsafe { self.gecko.${y_union_ffi_name}.addref_if_calc(&self.gecko.${y_unit_ffi_name}) }; unsafe { self.gecko.${y_union_ffi_name}.addref_if_calc(&self.gecko.${y_unit_ffi_name}) };
} }
% if need_clone: % if need_clone:
fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { #[allow(non_snake_case)]
pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
use properties::longhands::${ident}::computed_value::T; use properties::longhands::${ident}::computed_value::T;
use euclid::Size2D; use euclid::Size2D;
let width = GeckoStyleCoordConvertible::from_gecko_style_coord(&self.gecko.${x_unit_ffi_name}, let width = GeckoStyleCoordConvertible::from_gecko_style_coord(&self.gecko.${x_unit_ffi_name},
@ -375,7 +395,7 @@ ${impl_split_style_coord(ident,
<%def name="impl_style_struct(style_struct)"> <%def name="impl_style_struct(style_struct)">
impl ${style_struct.gecko_struct_name} { impl ${style_struct.gecko_struct_name} {
#[allow(dead_code, unused_variables)] #[allow(dead_code, unused_variables)]
fn initial() -> Arc<Self> { pub fn initial() -> Arc<Self> {
let mut result = Arc::new(${style_struct.gecko_struct_name} { gecko: unsafe { zeroed() } }); let mut result = Arc::new(${style_struct.gecko_struct_name} { gecko: unsafe { zeroed() } });
unsafe { unsafe {
Gecko_Construct_${style_struct.gecko_ffi_name}(&mut Arc::make_mut(&mut result).gecko); Gecko_Construct_${style_struct.gecko_ffi_name}(&mut Arc::make_mut(&mut result).gecko);
@ -455,7 +475,7 @@ impl Debug for ${style_struct.gecko_struct_name} {
if x.predefined_type in predefined_types and not x.name in force_stub] if x.predefined_type in predefined_types and not x.name in force_stub]
stub_longhands = [x for x in longhands if x not in keyword_longhands + predefined_longhands] stub_longhands = [x for x in longhands if x not in keyword_longhands + predefined_longhands]
%> %>
impl ${style_struct.trait_name} for ${style_struct.gecko_struct_name} { impl ${style_struct.gecko_struct_name} {
/* /*
* Manually-Implemented Methods. * Manually-Implemented Methods.
*/ */
@ -476,24 +496,28 @@ impl ${style_struct.trait_name} for ${style_struct.gecko_struct_name} {
* Stubs. * Stubs.
*/ */
% for longhand in stub_longhands: % for longhand in stub_longhands:
fn set_${longhand.ident}(&mut self, _: longhands::${longhand.ident}::computed_value::T) { #[allow(non_snake_case)]
pub fn set_${longhand.ident}(&mut self, _: longhands::${longhand.ident}::computed_value::T) {
if cfg!(debug_assertions) { if cfg!(debug_assertions) {
println!("stylo: Unimplemented property setter: ${longhand.name}"); println!("stylo: Unimplemented property setter: ${longhand.name}");
} }
} }
fn copy_${longhand.ident}_from(&mut self, _: &Self) { #[allow(non_snake_case)]
pub fn copy_${longhand.ident}_from(&mut self, _: &Self) {
if cfg!(debug_assertions) { if cfg!(debug_assertions) {
println!("stylo: Unimplemented property setter: ${longhand.name}"); println!("stylo: Unimplemented property setter: ${longhand.name}");
} }
} }
% if longhand.need_clone: % if longhand.need_clone:
fn clone_${longhand.ident}(&self) -> longhands::${longhand.ident}::computed_value::T { #[allow(non_snake_case)]
pub fn clone_${longhand.ident}(&self) -> longhands::${longhand.ident}::computed_value::T {
unimplemented!() unimplemented!()
} }
% endif % endif
% if longhand.need_index: % if longhand.need_index:
fn ${longhand.ident}_count(&self) -> usize { 0 } pub fn ${longhand.ident}_count(&self) -> usize { 0 }
fn ${longhand.ident}_at(&self, _index: usize) -> longhands::${longhand.ident}::computed_value::SingleComputedValue { pub fn ${longhand.ident}_at(&self, _index: usize)
-> longhands::${longhand.ident}::computed_value::SingleComputedValue {
unimplemented!() unimplemented!()
} }
% endif % endif
@ -508,7 +532,7 @@ impl ${style_struct.trait_name} for ${style_struct.gecko_struct_name} {
<% data.manual_style_structs = [] %> <% data.manual_style_structs = [] %>
<%def name="impl_trait(style_struct_name, skip_longhands='', skip_additionals='')"> <%def name="impl_trait(style_struct_name, skip_longhands='', skip_additionals='')">
<%self:raw_impl_trait style_struct="${next(x for x in data.style_structs if x.trait_name == style_struct_name)}" <%self:raw_impl_trait style_struct="${next(x for x in data.style_structs if x.name == style_struct_name)}"
skip_longhands="${skip_longhands}" skip_additionals="${skip_additionals}"> skip_longhands="${skip_longhands}" skip_additionals="${skip_additionals}">
${caller.body()} ${caller.body()}
</%self:raw_impl_trait> </%self:raw_impl_trait>
@ -571,7 +595,7 @@ fn static_assert() {
<% impl_app_units("border_%s_width" % side.ident, "mComputedBorder.%s" % side.ident, need_clone=True, <% impl_app_units("border_%s_width" % side.ident, "mComputedBorder.%s" % side.ident, need_clone=True,
round_to_pixels=True) %> round_to_pixels=True) %>
fn border_${side.ident}_has_nonzero_width(&self) -> bool { pub fn border_${side.ident}_has_nonzero_width(&self) -> bool {
self.gecko.mComputedBorder.${side.ident} != 0 self.gecko.mComputedBorder.${side.ident} != 0
} }
% endfor % endfor
@ -621,7 +645,7 @@ fn static_assert() {
need_clone=True) %> need_clone=True) %>
% endfor % endfor
fn set_z_index(&mut self, v: longhands::z_index::computed_value::T) { pub fn set_z_index(&mut self, v: longhands::z_index::computed_value::T) {
use properties::longhands::z_index::computed_value::T; use properties::longhands::z_index::computed_value::T;
match v { match v {
T::Auto => self.gecko.mZIndex.set_auto(), T::Auto => self.gecko.mZIndex.set_auto(),
@ -629,7 +653,7 @@ fn static_assert() {
} }
} }
fn copy_z_index_from(&mut self, other: &Self) { pub fn copy_z_index_from(&mut self, other: &Self) {
use gecko_bindings::structs::nsStyleUnit; use gecko_bindings::structs::nsStyleUnit;
// z-index is never a calc(). If it were, we'd be leaking here, so // z-index is never a calc(). If it were, we'd be leaking here, so
// assert that it isn't. // assert that it isn't.
@ -638,7 +662,7 @@ fn static_assert() {
self.gecko.mZIndex.mValue = other.gecko.mZIndex.mValue; self.gecko.mZIndex.mValue = other.gecko.mZIndex.mValue;
} }
fn clone_z_index(&self) -> longhands::z_index::computed_value::T { pub fn clone_z_index(&self) -> longhands::z_index::computed_value::T {
use properties::longhands::z_index::computed_value::T; use properties::longhands::z_index::computed_value::T;
if self.gecko.mZIndex.is_auto() { if self.gecko.mZIndex.is_auto() {
@ -649,7 +673,7 @@ fn static_assert() {
T::Number(self.gecko.mZIndex.get_int()) T::Number(self.gecko.mZIndex.get_int())
} }
fn set_box_sizing(&mut self, v: longhands::box_sizing::computed_value::T) { pub fn set_box_sizing(&mut self, v: longhands::box_sizing::computed_value::T) {
use computed_values::box_sizing::T; use computed_values::box_sizing::T;
use gecko_bindings::structs::StyleBoxSizing; use gecko_bindings::structs::StyleBoxSizing;
// TODO: guess what to do with box-sizing: padding-box // TODO: guess what to do with box-sizing: padding-box
@ -684,7 +708,7 @@ fn static_assert() {
"mOutlineRadius.mValues[%s]" % corner.y_index) %> "mOutlineRadius.mValues[%s]" % corner.y_index) %>
% endfor % endfor
fn outline_has_nonzero_width(&self) -> bool { pub fn outline_has_nonzero_width(&self) -> bool {
self.gecko.mActualOutlineWidth != 0 self.gecko.mActualOutlineWidth != 0
} }
</%self:impl_trait> </%self:impl_trait>
@ -693,7 +717,7 @@ fn static_assert() {
skip_longhands="font-family font-style font-size font-weight" skip_longhands="font-family font-style font-size font-weight"
skip_additionals="*"> skip_additionals="*">
fn set_font_family(&mut self, v: longhands::font_family::computed_value::T) { pub fn set_font_family(&mut self, v: longhands::font_family::computed_value::T) {
use properties::longhands::font_family::computed_value::FontFamily; use properties::longhands::font_family::computed_value::FontFamily;
use gecko_bindings::structs::FontFamilyType; use gecko_bindings::structs::FontFamilyType;
@ -719,7 +743,7 @@ fn static_assert() {
} }
} }
fn copy_font_family_from(&mut self, other: &Self) { pub fn copy_font_family_from(&mut self, other: &Self) {
unsafe { Gecko_CopyFontFamilyFrom(&mut self.gecko.mFont, &other.gecko.mFont); } unsafe { Gecko_CopyFontFamilyFrom(&mut self.gecko.mFont, &other.gecko.mFont); }
} }
@ -729,24 +753,24 @@ fn static_assert() {
// FIXME(bholley): Gecko has two different sizes, one of which (mSize) is the // FIXME(bholley): Gecko has two different sizes, one of which (mSize) is the
// actual computed size, and the other of which (mFont.size) is the 'display // actual computed size, and the other of which (mFont.size) is the 'display
// size' which takes font zooming into account. We don't handle font zooming yet. // size' which takes font zooming into account. We don't handle font zooming yet.
fn set_font_size(&mut self, v: longhands::font_size::computed_value::T) { pub fn set_font_size(&mut self, v: longhands::font_size::computed_value::T) {
self.gecko.mFont.size = v.0; self.gecko.mFont.size = v.0;
self.gecko.mSize = v.0; self.gecko.mSize = v.0;
} }
fn copy_font_size_from(&mut self, other: &Self) { pub fn copy_font_size_from(&mut self, other: &Self) {
self.gecko.mFont.size = other.gecko.mFont.size; self.gecko.mFont.size = other.gecko.mFont.size;
self.gecko.mSize = other.gecko.mSize; self.gecko.mSize = other.gecko.mSize;
} }
fn clone_font_size(&self) -> longhands::font_size::computed_value::T { pub fn clone_font_size(&self) -> longhands::font_size::computed_value::T {
Au(self.gecko.mSize) Au(self.gecko.mSize)
} }
fn set_font_weight(&mut self, v: longhands::font_weight::computed_value::T) { pub fn set_font_weight(&mut self, v: longhands::font_weight::computed_value::T) {
self.gecko.mFont.weight = v as u16; self.gecko.mFont.weight = v as u16;
} }
${impl_simple_copy('font_weight', 'mFont.weight')} ${impl_simple_copy('font_weight', 'mFont.weight')}
fn clone_font_weight(&self) -> longhands::font_weight::computed_value::T { pub fn clone_font_weight(&self) -> longhands::font_weight::computed_value::T {
debug_assert!(self.gecko.mFont.weight >= 100); debug_assert!(self.gecko.mFont.weight >= 100);
debug_assert!(self.gecko.mFont.weight <= 900); debug_assert!(self.gecko.mFont.weight <= 900);
debug_assert!(self.gecko.mFont.weight % 10 == 0); debug_assert!(self.gecko.mFont.weight % 10 == 0);
@ -754,7 +778,7 @@ fn static_assert() {
} }
// This is used for PartialEq, which we don't implement for gecko style structs. // This is used for PartialEq, which we don't implement for gecko style structs.
fn compute_font_hash(&mut self) {} pub fn compute_font_hash(&mut self) {}
</%self:impl_trait> </%self:impl_trait>
@ -773,7 +797,7 @@ fn static_assert() {
// overflow-y is implemented as a newtype of overflow-x, so we need special handling. // overflow-y is implemented as a newtype of overflow-x, so we need special handling.
// We could generalize this if we run into other newtype keywords. // We could generalize this if we run into other newtype keywords.
<% overflow_x = data.longhands_by_name["overflow-x"] %> <% overflow_x = data.longhands_by_name["overflow-x"] %>
fn set_overflow_y(&mut self, v: longhands::overflow_y::computed_value::T) { pub fn set_overflow_y(&mut self, v: longhands::overflow_y::computed_value::T) {
use properties::longhands::overflow_x::computed_value::T as BaseType; use properties::longhands::overflow_x::computed_value::T as BaseType;
// FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts // FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts
self.gecko.mOverflowY = match v.0 { self.gecko.mOverflowY = match v.0 {
@ -783,7 +807,7 @@ fn static_assert() {
}; };
} }
${impl_simple_copy('overflow_y', 'mOverflowY')} ${impl_simple_copy('overflow_y', 'mOverflowY')}
fn clone_overflow_y(&self) -> longhands::overflow_y::computed_value::T { pub fn clone_overflow_y(&self) -> longhands::overflow_y::computed_value::T {
use properties::longhands::overflow_x::computed_value::T as BaseType; use properties::longhands::overflow_x::computed_value::T as BaseType;
use properties::longhands::overflow_y::computed_value::T as NewType; use properties::longhands::overflow_y::computed_value::T as NewType;
// FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts // FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts
@ -795,7 +819,7 @@ fn static_assert() {
} }
} }
fn set_vertical_align(&mut self, v: longhands::vertical_align::computed_value::T) { pub fn set_vertical_align(&mut self, v: longhands::vertical_align::computed_value::T) {
<% keyword = data.longhands_by_name["vertical-align"].keyword %> <% keyword = data.longhands_by_name["vertical-align"].keyword %>
use properties::longhands::vertical_align::computed_value::T; use properties::longhands::vertical_align::computed_value::T;
// FIXME: Align binary representations and ditch |match| for cast + static_asserts // FIXME: Align binary representations and ditch |match| for cast + static_asserts
@ -808,7 +832,7 @@ fn static_assert() {
} }
} }
fn clone_vertical_align(&self) -> longhands::vertical_align::computed_value::T { pub fn clone_vertical_align(&self) -> longhands::vertical_align::computed_value::T {
use properties::longhands::vertical_align::computed_value::T; use properties::longhands::vertical_align::computed_value::T;
use values::computed::LengthOrPercentage; use values::computed::LengthOrPercentage;
@ -830,7 +854,8 @@ fn static_assert() {
<%call expr="impl_coord_copy('vertical_align', 'mVerticalAlign')"></%call> <%call expr="impl_coord_copy('vertical_align', 'mVerticalAlign')"></%call>
fn set__moz_binding(&mut self, v: longhands::_moz_binding::computed_value::T) { #[allow(non_snake_case)]
pub fn set__moz_binding(&mut self, v: longhands::_moz_binding::computed_value::T) {
use properties::longhands::_moz_binding::SpecifiedValue as BindingValue; use properties::longhands::_moz_binding::SpecifiedValue as BindingValue;
match v { match v {
BindingValue::None => debug_assert!(self.gecko.mBinding.mRawPtr.is_null()), BindingValue::None => debug_assert!(self.gecko.mBinding.mRawPtr.is_null()),
@ -846,7 +871,8 @@ fn static_assert() {
} }
} }
} }
fn copy__moz_binding_from(&mut self, other: &Self) { #[allow(non_snake_case)]
pub fn copy__moz_binding_from(&mut self, other: &Self) {
unsafe { Gecko_CopyMozBindingFrom(&mut self.gecko, &other.gecko); } unsafe { Gecko_CopyMozBindingFrom(&mut self.gecko, &other.gecko); }
} }
@ -854,7 +880,7 @@ fn static_assert() {
// Map 'auto' and 'avoid' to false, and 'always', 'left', and 'right' to true. // Map 'auto' and 'avoid' to false, and 'always', 'left', and 'right' to true.
// "A conforming user agent may interpret the values 'left' and 'right' // "A conforming user agent may interpret the values 'left' and 'right'
// as 'always'." - CSS2.1, section 13.3.1 // as 'always'." - CSS2.1, section 13.3.1
fn set_page_break_before(&mut self, v: longhands::page_break_before::computed_value::T) { pub fn set_page_break_before(&mut self, v: longhands::page_break_before::computed_value::T) {
use computed_values::page_break_before::T; use computed_values::page_break_before::T;
let result = match v { let result = match v {
T::auto => false, T::auto => false,
@ -871,7 +897,7 @@ fn static_assert() {
// Temp fix for Bugzilla bug 24000. // Temp fix for Bugzilla bug 24000.
// See set_page_break_before for detail. // See set_page_break_before for detail.
fn set_page_break_after(&mut self, v: longhands::page_break_after::computed_value::T) { pub fn set_page_break_after(&mut self, v: longhands::page_break_after::computed_value::T) {
use computed_values::page_break_after::T; use computed_values::page_break_after::T;
let result = match v { let result = match v {
T::auto => false, T::auto => false,
@ -900,13 +926,13 @@ fn static_assert() {
<% impl_color("background_color", "mBackgroundColor", need_clone=True) %> <% impl_color("background_color", "mBackgroundColor", need_clone=True) %>
fn copy_background_repeat_from(&mut self, other: &Self) { pub fn copy_background_repeat_from(&mut self, other: &Self) {
self.gecko.mImage.mRepeatCount = cmp::min(1, other.gecko.mImage.mRepeatCount); self.gecko.mImage.mRepeatCount = cmp::min(1, other.gecko.mImage.mRepeatCount);
self.gecko.mImage.mLayers.mFirstElement.mRepeat = self.gecko.mImage.mLayers.mFirstElement.mRepeat =
other.gecko.mImage.mLayers.mFirstElement.mRepeat; other.gecko.mImage.mLayers.mFirstElement.mRepeat;
} }
fn set_background_repeat(&mut self, v: longhands::background_repeat::computed_value::T) { pub fn set_background_repeat(&mut self, v: longhands::background_repeat::computed_value::T) {
use properties::longhands::background_repeat::computed_value::T; use properties::longhands::background_repeat::computed_value::T;
use gecko_bindings::structs::{NS_STYLE_IMAGELAYER_REPEAT_REPEAT, NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT}; use gecko_bindings::structs::{NS_STYLE_IMAGELAYER_REPEAT_REPEAT, NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT};
use gecko_bindings::structs::nsStyleImageLayers_Repeat; use gecko_bindings::structs::nsStyleImageLayers_Repeat;
@ -928,13 +954,13 @@ fn static_assert() {
}; };
} }
fn copy_background_clip_from(&mut self, other: &Self) { pub fn copy_background_clip_from(&mut self, other: &Self) {
self.gecko.mImage.mClipCount = cmp::min(1, other.gecko.mImage.mClipCount); self.gecko.mImage.mClipCount = cmp::min(1, other.gecko.mImage.mClipCount);
self.gecko.mImage.mLayers.mFirstElement.mClip = self.gecko.mImage.mLayers.mFirstElement.mClip =
other.gecko.mImage.mLayers.mFirstElement.mClip; other.gecko.mImage.mLayers.mFirstElement.mClip;
} }
fn set_background_clip(&mut self, v: longhands::background_clip::computed_value::T) { pub fn set_background_clip(&mut self, v: longhands::background_clip::computed_value::T) {
use properties::longhands::background_clip::computed_value::T; use properties::longhands::background_clip::computed_value::T;
self.gecko.mImage.mClipCount = 1; self.gecko.mImage.mClipCount = 1;
@ -947,13 +973,13 @@ fn static_assert() {
}; };
} }
fn copy_background_origin_from(&mut self, other: &Self) { pub fn copy_background_origin_from(&mut self, other: &Self) {
self.gecko.mImage.mOriginCount = cmp::min(1, other.gecko.mImage.mOriginCount); self.gecko.mImage.mOriginCount = cmp::min(1, other.gecko.mImage.mOriginCount);
self.gecko.mImage.mLayers.mFirstElement.mOrigin = self.gecko.mImage.mLayers.mFirstElement.mOrigin =
other.gecko.mImage.mLayers.mFirstElement.mOrigin; other.gecko.mImage.mLayers.mFirstElement.mOrigin;
} }
fn set_background_origin(&mut self, v: longhands::background_origin::computed_value::T) { pub fn set_background_origin(&mut self, v: longhands::background_origin::computed_value::T) {
use properties::longhands::background_origin::computed_value::T; use properties::longhands::background_origin::computed_value::T;
self.gecko.mImage.mOriginCount = 1; self.gecko.mImage.mOriginCount = 1;
@ -964,13 +990,13 @@ fn static_assert() {
}; };
} }
fn copy_background_attachment_from(&mut self, other: &Self) { pub fn copy_background_attachment_from(&mut self, other: &Self) {
self.gecko.mImage.mAttachmentCount = cmp::min(1, other.gecko.mImage.mAttachmentCount); self.gecko.mImage.mAttachmentCount = cmp::min(1, other.gecko.mImage.mAttachmentCount);
self.gecko.mImage.mLayers.mFirstElement.mAttachment = self.gecko.mImage.mLayers.mFirstElement.mAttachment =
other.gecko.mImage.mLayers.mFirstElement.mAttachment; other.gecko.mImage.mLayers.mFirstElement.mAttachment;
} }
fn set_background_attachment(&mut self, v: longhands::background_attachment::computed_value::T) { pub fn set_background_attachment(&mut self, v: longhands::background_attachment::computed_value::T) {
use properties::longhands::background_attachment::computed_value::T; use properties::longhands::background_attachment::computed_value::T;
self.gecko.mImage.mAttachmentCount = 1; self.gecko.mImage.mAttachmentCount = 1;
@ -981,14 +1007,14 @@ fn static_assert() {
}; };
} }
fn copy_background_image_from(&mut self, other: &Self) { pub fn copy_background_image_from(&mut self, other: &Self) {
unsafe { unsafe {
Gecko_CopyImageValueFrom(&mut self.gecko.mImage.mLayers.mFirstElement.mImage, Gecko_CopyImageValueFrom(&mut self.gecko.mImage.mLayers.mFirstElement.mImage,
&other.gecko.mImage.mLayers.mFirstElement.mImage); &other.gecko.mImage.mLayers.mFirstElement.mImage);
} }
} }
fn set_background_image(&mut self, images: longhands::background_image::computed_value::T) { pub fn set_background_image(&mut self, images: longhands::background_image::computed_value::T) {
use gecko_bindings::structs::nsStyleImageLayers_LayerType as LayerType; use gecko_bindings::structs::nsStyleImageLayers_LayerType as LayerType;
use gecko_bindings::structs::{NS_STYLE_GRADIENT_SHAPE_LINEAR, NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER}; use gecko_bindings::structs::{NS_STYLE_GRADIENT_SHAPE_LINEAR, NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER};
use gecko_bindings::structs::nsStyleCoord; use gecko_bindings::structs::nsStyleCoord;
@ -1088,7 +1114,7 @@ fn static_assert() {
${impl_keyword_setter("list_style_type", "__LIST_STYLE_TYPE__", ${impl_keyword_setter("list_style_type", "__LIST_STYLE_TYPE__",
data.longhands_by_name["list-style-type"].keyword)} data.longhands_by_name["list-style-type"].keyword)}
fn copy_list_style_type_from(&mut self, other: &Self) { pub fn copy_list_style_type_from(&mut self, other: &Self) {
unsafe { unsafe {
Gecko_CopyListStyleTypeFrom(&mut self.gecko, &other.gecko); Gecko_CopyListStyleTypeFrom(&mut self.gecko, &other.gecko);
} }
@ -1103,7 +1129,7 @@ fn static_assert() {
"-moz-right match-parent") %> "-moz-right match-parent") %>
${impl_keyword('text_align', 'mTextAlign', text_align_keyword, need_clone=False)} ${impl_keyword('text_align', 'mTextAlign', text_align_keyword, need_clone=False)}
fn set_line_height(&mut self, v: longhands::line_height::computed_value::T) { pub fn set_line_height(&mut self, v: longhands::line_height::computed_value::T) {
use properties::longhands::line_height::computed_value::T; use properties::longhands::line_height::computed_value::T;
// FIXME: Align binary representations and ditch |match| for cast + static_asserts // FIXME: Align binary representations and ditch |match| for cast + static_asserts
match v { match v {
@ -1115,7 +1141,7 @@ fn static_assert() {
} }
} }
fn clone_line_height(&self) -> longhands::line_height::computed_value::T { pub fn clone_line_height(&self) -> longhands::line_height::computed_value::T {
use properties::longhands::line_height::computed_value::T; use properties::longhands::line_height::computed_value::T;
if self.gecko.mLineHeight.is_normal() { if self.gecko.mLineHeight.is_normal() {
return T::Normal; return T::Normal;
@ -1142,7 +1168,7 @@ fn static_assert() {
${impl_color("text_decoration_color", "mTextDecorationColor", ${impl_color("text_decoration_color", "mTextDecorationColor",
color_flags_ffi_name="mTextDecorationStyle", need_clone=True)} color_flags_ffi_name="mTextDecorationStyle", need_clone=True)}
fn set_text_decoration_line(&mut self, v: longhands::text_decoration_line::computed_value::T) { pub fn set_text_decoration_line(&mut self, v: longhands::text_decoration_line::computed_value::T) {
let mut bits: u8 = 0; let mut bits: u8 = 0;
if v.underline { if v.underline {
bits |= structs::NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE as u8; bits |= structs::NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE as u8;
@ -1159,17 +1185,17 @@ fn static_assert() {
${impl_simple_copy('text_decoration_line', 'mTextDecorationLine')} ${impl_simple_copy('text_decoration_line', 'mTextDecorationLine')}
#[inline] #[inline]
fn has_underline(&self) -> bool { pub fn has_underline(&self) -> bool {
(self.gecko.mTextDecorationLine & (structs::NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE as u8)) != 0 (self.gecko.mTextDecorationLine & (structs::NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE as u8)) != 0
} }
#[inline] #[inline]
fn has_overline(&self) -> bool { pub fn has_overline(&self) -> bool {
(self.gecko.mTextDecorationLine & (structs::NS_STYLE_TEXT_DECORATION_LINE_OVERLINE as u8)) != 0 (self.gecko.mTextDecorationLine & (structs::NS_STYLE_TEXT_DECORATION_LINE_OVERLINE as u8)) != 0
} }
#[inline] #[inline]
fn has_line_through(&self) -> bool { pub fn has_line_through(&self) -> bool {
(self.gecko.mTextDecorationLine & (structs::NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH as u8)) != 0 (self.gecko.mTextDecorationLine & (structs::NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH as u8)) != 0
} }
</%self:impl_trait> </%self:impl_trait>
@ -1188,14 +1214,14 @@ fn static_assert() {
<%self:impl_trait style_struct_name="Color" <%self:impl_trait style_struct_name="Color"
skip_longhands="*"> skip_longhands="*">
fn set_color(&mut self, v: longhands::color::computed_value::T) { pub fn set_color(&mut self, v: longhands::color::computed_value::T) {
let result = convert_rgba_to_nscolor(&v); let result = convert_rgba_to_nscolor(&v);
${set_gecko_property("mColor", "result")} ${set_gecko_property("mColor", "result")}
} }
<%call expr="impl_simple_copy('color', 'mColor')"></%call> <%call expr="impl_simple_copy('color', 'mColor')"></%call>
fn clone_color(&self) -> longhands::color::computed_value::T { pub fn clone_color(&self) -> longhands::color::computed_value::T {
let color = ${get_gecko_property("mColor")} as u32; let color = ${get_gecko_property("mColor")} as u32;
convert_nscolor_to_rgba(color) convert_nscolor_to_rgba(color)
} }
@ -1203,7 +1229,7 @@ fn static_assert() {
<%self:impl_trait style_struct_name="Pointing" <%self:impl_trait style_struct_name="Pointing"
skip_longhands="cursor"> skip_longhands="cursor">
fn set_cursor(&mut self, v: longhands::cursor::computed_value::T) { pub fn set_cursor(&mut self, v: longhands::cursor::computed_value::T) {
use properties::longhands::cursor::computed_value::T; use properties::longhands::cursor::computed_value::T;
use style_traits::cursor::Cursor; use style_traits::cursor::Cursor;
@ -1255,7 +1281,7 @@ fn static_assert() {
<%self:impl_trait style_struct_name="Column" <%self:impl_trait style_struct_name="Column"
skip_longhands="column-width"> skip_longhands="column-width">
fn set_column_width(&mut self, v: longhands::column_width::computed_value::T) { pub fn set_column_width(&mut self, v: longhands::column_width::computed_value::T) {
match v.0 { match v.0 {
Some(au) => self.gecko.mColumnWidth.set_coord(au), Some(au) => self.gecko.mColumnWidth.set_coord(au),
None => self.gecko.mColumnWidth.set_auto(), None => self.gecko.mColumnWidth.set_auto(),
@ -1268,10 +1294,10 @@ fn static_assert() {
<%def name="define_ffi_struct_accessor(style_struct)"> <%def name="define_ffi_struct_accessor(style_struct)">
#[no_mangle] #[no_mangle]
#[allow(non_snake_case, unused_variables)] #[allow(non_snake_case, unused_variables)]
pub extern "C" fn Servo_GetStyle${style_struct.gecko_name}(computed_values: *mut ServoComputedValues) pub extern "C" fn Servo_GetStyle${style_struct.gecko_name}(computed_values: *mut bindings::ServoComputedValues)
-> *const ${style_struct.gecko_ffi_name} { -> *const ${style_struct.gecko_ffi_name} {
type Helpers = ArcHelpers<ServoComputedValues, GeckoComputedValues>; type Helpers = ArcHelpers<bindings::ServoComputedValues, ComputedValuesStruct>;
Helpers::with(computed_values, |values| values.get_${style_struct.trait_name_lower}().get_gecko() Helpers::with(computed_values, |values| values.get_${style_struct.name_lower}().get_gecko()
as *const ${style_struct.gecko_ffi_name}) as *const ${style_struct.gecko_ffi_name})
} }
</%def> </%def>
@ -1279,16 +1305,16 @@ pub extern "C" fn Servo_GetStyle${style_struct.gecko_name}(computed_values: *mut
% for style_struct in data.style_structs: % for style_struct in data.style_structs:
${declare_style_struct(style_struct)} ${declare_style_struct(style_struct)}
${impl_style_struct(style_struct)} ${impl_style_struct(style_struct)}
% if not style_struct.trait_name in data.manual_style_structs: % if not style_struct.name in data.manual_style_structs:
<%self:raw_impl_trait style_struct="${style_struct}"></%self:raw_impl_trait> <%self:raw_impl_trait style_struct="${style_struct}"></%self:raw_impl_trait>
% endif % endif
${define_ffi_struct_accessor(style_struct)} ${define_ffi_struct_accessor(style_struct)}
% endfor % endfor
lazy_static! { lazy_static! {
pub static ref INITIAL_GECKO_VALUES: GeckoComputedValues = GeckoComputedValues { pub static ref INITIAL_GECKO_VALUES: ComputedValuesStruct = ComputedValuesStruct {
% for style_struct in data.style_structs: % for style_struct in data.style_structs:
${style_struct.ident}: ${style_struct.gecko_struct_name}::initial(), ${style_struct.ident}: style_structs::${style_struct.name}::initial(),
% endfor % endfor
custom_properties: None, custom_properties: None,
shareable: true, shareable: true,
@ -1297,7 +1323,7 @@ lazy_static! {
}; };
} }
static CASCADE_PROPERTY: [CascadePropertyFn<GeckoComputedValues>; ${len(data.longhands)}] = [ static CASCADE_PROPERTY: [CascadePropertyFn; ${len(data.longhands)}] = [
% for property in data.longhands: % for property in data.longhands:
longhands::${property.ident}::cascade_property, longhands::${property.ident}::cascade_property,
% endfor % endfor

View file

@ -64,7 +64,7 @@
use cssparser::Parser; use cssparser::Parser;
use parser::{ParserContext, ParserContextExtraData}; use parser::{ParserContext, ParserContextExtraData};
use properties::{CSSWideKeyword, DeclaredValue, Shorthand}; use properties::{CSSWideKeyword, DeclaredValue, Shorthand};
use values::computed::{TContext, ToComputedValue}; use values::computed::{Context, ToComputedValue};
use values::{computed, specified}; use values::{computed, specified};
${caller.body()} ${caller.body()}
} }
@ -144,7 +144,7 @@
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
computed_value::T(self.0.iter().map(|x| x.to_computed_value(context)).collect()) computed_value::T(self.0.iter().map(|x| x.to_computed_value(context)).collect())
} }
} }
@ -170,21 +170,19 @@
use error_reporting::ParseErrorReporter; use error_reporting::ParseErrorReporter;
use properties::longhands; use properties::longhands;
use properties::property_bit_field::PropertyBitField; use properties::property_bit_field::PropertyBitField;
use properties::{ComputedValues, ServoComputedValues, PropertyDeclaration}; use properties::{ComputedValuesStruct, PropertyDeclaration};
use properties::style_struct_traits::${data.current_style_struct.trait_name};
use properties::style_structs; use properties::style_structs;
use std::boxed::Box as StdBox; use std::boxed::Box as StdBox;
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::Arc; use std::sync::Arc;
use values::computed::{TContext, ToComputedValue}; use values::computed::{Context, ToComputedValue};
use values::{computed, specified}; use values::{computed, specified};
use string_cache::Atom; use string_cache::Atom;
${caller.body()} ${caller.body()}
#[allow(unused_variables)] #[allow(unused_variables)]
pub fn cascade_property<C: ComputedValues>( pub fn cascade_property(declaration: &PropertyDeclaration,
declaration: &PropertyDeclaration, inherited_style: &ComputedValuesStruct,
inherited_style: &C, context: &mut computed::Context,
context: &mut computed::Context<C>,
seen: &mut PropertyBitField, seen: &mut PropertyBitField,
cacheable: &mut bool, cacheable: &mut bool,
error_reporter: &mut StdBox<ParseErrorReporter + Send>) { error_reporter: &mut StdBox<ParseErrorReporter + Send>) {
@ -205,16 +203,16 @@
declared_value, &custom_props, |value| match *value { declared_value, &custom_props, |value| match *value {
DeclaredValue::Value(ref specified_value) => { DeclaredValue::Value(ref specified_value) => {
let computed = specified_value.to_computed_value(context); let computed = specified_value.to_computed_value(context);
context.mutate_style().mutate_${data.current_style_struct.trait_name_lower}() context.mutate_style().mutate_${data.current_style_struct.name_lower}()
.set_${property.ident}(computed); .set_${property.ident}(computed);
} }
DeclaredValue::WithVariables { .. } => unreachable!(), DeclaredValue::WithVariables { .. } => unreachable!(),
DeclaredValue::Initial => { DeclaredValue::Initial => {
// We assume that it's faster to use copy_*_from rather than // We assume that it's faster to use copy_*_from rather than
// set_*(get_initial_value()); // set_*(get_initial_value());
let initial_struct = C::initial_values() let initial_struct = ComputedValuesStruct::initial_values()
.get_${data.current_style_struct.trait_name_lower}(); .get_${data.current_style_struct.name_lower}();
context.mutate_style().mutate_${data.current_style_struct.trait_name_lower}() context.mutate_style().mutate_${data.current_style_struct.name_lower}()
.copy_${property.ident}_from(initial_struct); .copy_${property.ident}_from(initial_struct);
}, },
DeclaredValue::Inherit => { DeclaredValue::Inherit => {
@ -224,8 +222,8 @@
// FIXME: is it still? // FIXME: is it still?
*cacheable = false; *cacheable = false;
let inherited_struct = let inherited_struct =
inherited_style.get_${data.current_style_struct.trait_name_lower}(); inherited_style.get_${data.current_style_struct.name_lower}();
context.mutate_style().mutate_${data.current_style_struct.trait_name_lower}() context.mutate_style().mutate_${data.current_style_struct.name_lower}()
.copy_${property.ident}_from(inherited_struct); .copy_${property.ident}_from(inherited_struct);
} }
}, error_reporter }, error_reporter

View file

@ -24,10 +24,9 @@ use properties::longhands::transform_origin::computed_value::T as TransformOrigi
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::*;
use std::cmp; use std::cmp;
use std::fmt; use std::fmt;
use super::ComputedValues; use super::ComputedValuesStruct;
use values::computed::{Angle, LengthOrPercentageOrAuto, LengthOrPercentageOrNone}; use values::computed::{Angle, LengthOrPercentageOrAuto, LengthOrPercentageOrNone};
use values::computed::{BorderRadiusSize, LengthOrNone}; use values::computed::{BorderRadiusSize, LengthOrNone};
use values::computed::{CalcLengthOrPercentage, LengthOrPercentage}; use values::computed::{CalcLengthOrPercentage, LengthOrPercentage};
@ -115,7 +114,7 @@ impl AnimatedProperty {
} }
} }
pub fn update<C: ComputedValues>(&self, style: &mut C, progress: f64) { pub fn update(&self, style: &mut ComputedValuesStruct, progress: f64) {
match *self { match *self {
% for prop in data.longhands: % for prop in data.longhands:
% if prop.animatable: % if prop.animatable:
@ -129,9 +128,10 @@ impl AnimatedProperty {
} }
} }
pub fn from_transition_property<C: ComputedValues>(transition_property: &TransitionProperty, pub fn from_transition_property(transition_property: &TransitionProperty,
old_style: &C, old_style: &ComputedValuesStruct,
new_style: &C) -> AnimatedProperty { new_style: &ComputedValuesStruct)
-> AnimatedProperty {
match *transition_property { match *transition_property {
TransitionProperty::All => panic!("Can't use TransitionProperty::All here."), TransitionProperty::All => panic!("Can't use TransitionProperty::All here."),
% for prop in data.longhands: % for prop in data.longhands:

View file

@ -65,7 +65,7 @@ ${helpers.predefined_type("background-color", "CSSColor",
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
match *self { match *self {
SpecifiedValue(None) => computed_value::T(None), SpecifiedValue(None) => computed_value::T(None),
SpecifiedValue(Some(ref image)) => SpecifiedValue(Some(ref image)) =>
@ -172,7 +172,7 @@ ${helpers.predefined_type("background-color", "CSSColor",
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
computed_value::T { computed_value::T {
horizontal: self.horizontal.to_computed_value(context), horizontal: self.horizontal.to_computed_value(context),
vertical: self.vertical.to_computed_value(context), vertical: self.vertical.to_computed_value(context),
@ -308,7 +308,7 @@ ${helpers.single_keyword("background-origin",
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
match *self { match *self {
SpecifiedValue::Explicit(ref size) => { SpecifiedValue::Explicit(ref size) => {
computed_value::T::Explicit(computed_value::ExplicitSize { computed_value::T::Explicit(computed_value::ExplicitSize {

View file

@ -62,7 +62,7 @@
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
self.0.to_computed_value(context) self.0.to_computed_value(context)
} }
} }

View file

@ -26,7 +26,7 @@
experimental_values = set("flex".split()) experimental_values = set("flex".split())
%> %>
pub use self::computed_value::T as SpecifiedValue; pub use self::computed_value::T as SpecifiedValue;
use values::computed::{Context, ComputedValueAsSpecified}; use values::computed::ComputedValueAsSpecified;
use values::NoViewportPercentage; use values::NoViewportPercentage;
impl NoViewportPercentage for SpecifiedValue {} impl NoViewportPercentage for SpecifiedValue {}
@ -76,10 +76,9 @@
impl ComputedValueAsSpecified for SpecifiedValue {} impl ComputedValueAsSpecified for SpecifiedValue {}
% if product == "servo": % if product == "servo":
fn cascade_property_custom<C: ComputedValues>( fn cascade_property_custom(_declaration: &PropertyDeclaration,
_declaration: &PropertyDeclaration, _inherited_style: &ComputedValuesStruct,
_inherited_style: &C, context: &mut computed::Context,
context: &mut computed::Context<C>,
_seen: &mut PropertyBitField, _seen: &mut PropertyBitField,
_cacheable: &mut bool, _cacheable: &mut bool,
_error_reporter: &mut StdBox<ParseErrorReporter + Send>) { _error_reporter: &mut StdBox<ParseErrorReporter + Send>) {
@ -105,7 +104,7 @@ ${helpers.single_keyword("position", "static absolute relative fixed",
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
let positioned = matches!(context.style().get_box().clone_position(), let positioned = matches!(context.style().get_box().clone_position(),
longhands::position::SpecifiedValue::absolute | longhands::position::SpecifiedValue::absolute |
longhands::position::SpecifiedValue::fixed); longhands::position::SpecifiedValue::fixed);
@ -134,7 +133,7 @@ ${helpers.single_keyword("clear", "none left right both",
} }
#[inline] #[inline]
pub fn derive_from_display<Cx: TContext>(context: &mut Cx) { pub fn derive_from_display(context: &mut Context) {
let d = context.style().get_box().clone_display(); let d = context.style().get_box().clone_display();
context.mutate_style().mutate_box().set__servo_display_for_hypothetical_box(d); context.mutate_style().mutate_box().set__servo_display_for_hypothetical_box(d);
} }
@ -228,7 +227,7 @@ ${helpers.single_keyword("clear", "none left right both",
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
match *self { match *self {
% for keyword in vertical_align_keywords: % for keyword in vertical_align_keywords:
SpecifiedValue::${to_rust_ident(keyword)} => { SpecifiedValue::${to_rust_ident(keyword)} => {
@ -287,7 +286,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
computed_value::T(self.0.to_computed_value(context)) computed_value::T(self.0.to_computed_value(context))
} }
} }
@ -316,7 +315,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
pub mod computed_value { pub mod computed_value {
use cssparser::ToCss; use cssparser::ToCss;
use std::fmt; use std::fmt;
use values::computed::{TContext, ToComputedValue}; use values::computed::{Context, ToComputedValue};
pub use values::computed::Time as SingleComputedValue; pub use values::computed::Time as SingleComputedValue;
@ -497,7 +496,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, _: &Cx) -> computed_value::T { fn to_computed_value(&self, _: &Context) -> computed_value::T {
(*self).clone() (*self).clone()
} }
} }
@ -623,7 +622,7 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, _: &Cx) -> computed_value::T { fn to_computed_value(&self, _: &Context) -> computed_value::T {
(*self).clone() (*self).clone()
} }
} }

View file

@ -15,7 +15,7 @@
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, _context: &Cx) -> computed_value::T { fn to_computed_value(&self, _context: &Context) -> computed_value::T {
self.parsed self.parsed
} }
} }

View file

@ -63,7 +63,7 @@
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
match *self { match *self {
SpecifiedValue::Auto => computed_value::T(None), SpecifiedValue::Auto => computed_value::T(None),
SpecifiedValue::Specified(l) => SpecifiedValue::Specified(l) =>
@ -129,7 +129,7 @@
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, _context: &Cx) -> computed_value::T { fn to_computed_value(&self, _context: &Context) -> computed_value::T {
match *self { match *self {
SpecifiedValue::Auto => computed_value::T(None), SpecifiedValue::Auto => computed_value::T(None),
SpecifiedValue::Specified(count) => SpecifiedValue::Specified(count) =>
@ -209,7 +209,7 @@
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
match *self { match *self {
SpecifiedValue::Normal => computed_value::T(None), SpecifiedValue::Normal => computed_value::T(None),
SpecifiedValue::Specified(l) => SpecifiedValue::Specified(l) =>

View file

@ -98,7 +98,7 @@ ${helpers.predefined_type("opacity",
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
computed_value::T { computed_value::T {
offset_x: self.offset_x.to_computed_value(context), offset_x: self.offset_x.to_computed_value(context),
offset_y: self.offset_y.to_computed_value(context), offset_y: self.offset_y.to_computed_value(context),
@ -306,7 +306,7 @@ ${helpers.predefined_type("opacity",
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
computed_value::T(self.0.map(|value| computed_value::ClipRect { computed_value::T(self.0.map(|value| computed_value::ClipRect {
top: value.top.to_computed_value(context), top: value.top.to_computed_value(context),
right: value.right.map(|right| right.to_computed_value(context)), right: value.right.map(|right| right.to_computed_value(context)),
@ -598,7 +598,7 @@ ${helpers.predefined_type("opacity",
impl ToComputedValue for SpecifiedValue { impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
computed_value::T{ filters: self.0.iter().map(|value| { computed_value::T{ filters: self.0.iter().map(|value| {
match *value { match *value {
SpecifiedFilter::Blur(factor) => SpecifiedFilter::Blur(factor) =>
@ -1064,7 +1064,7 @@ ${helpers.predefined_type("opacity",
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
if self.0.is_empty() { if self.0.is_empty() {
return computed_value::T(None) return computed_value::T(None)
} }
@ -1275,7 +1275,7 @@ ${helpers.single_keyword("transform-style",
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
computed_value::T { computed_value::T {
horizontal: self.horizontal.to_computed_value(context), horizontal: self.horizontal.to_computed_value(context),
vertical: self.vertical.to_computed_value(context), vertical: self.vertical.to_computed_value(context),
@ -1361,7 +1361,7 @@ ${helpers.predefined_type("perspective",
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
computed_value::T { computed_value::T {
horizontal: self.horizontal.to_computed_value(context), horizontal: self.horizontal.to_computed_value(context),
vertical: self.vertical.to_computed_value(context), vertical: self.vertical.to_computed_value(context),

View file

@ -220,7 +220,7 @@ ${helpers.single_keyword("font-variant",
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
match *self { match *self {
% for weight in range(100, 901, 100): % for weight in range(100, 901, 100):
SpecifiedValue::Weight${weight} => computed_value::T::Weight${weight}, SpecifiedValue::Weight${weight} => computed_value::T::Weight${weight},
@ -288,7 +288,7 @@ ${helpers.single_keyword("font-variant",
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
match self.0 { match self.0 {
LengthOrPercentage::Length(Length::FontRelative(value)) => { LengthOrPercentage::Length(Length::FontRelative(value)) => {
value.to_computed_value(context.inherited_style().get_font().clone_font_size(), value.to_computed_value(context.inherited_style().get_font().clone_font_size(),

View file

@ -92,7 +92,7 @@ ${helpers.single_keyword("color-adjust",
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, _: &Cx) -> computed_value::T { fn to_computed_value(&self, _: &Context) -> computed_value::T {
*self *self
} }
} }
@ -131,8 +131,7 @@ ${helpers.single_keyword("color-adjust",
} }
#[inline] #[inline]
pub fn derive_from_display<Cx: TContext>(context: &mut Cx) { pub fn derive_from_display(context: &mut Context) {
use properties::style_struct_traits::Box;
use super::display::computed_value::T as Display; use super::display::computed_value::T as Display;
if context.style().get_box().clone_display() == Display::none { if context.style().get_box().clone_display() == Display::none {

View file

@ -76,7 +76,7 @@ ${helpers.single_keyword("caption-side", "top bottom",
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
computed_value::T { computed_value::T {
horizontal: self.horizontal.to_computed_value(context), horizontal: self.horizontal.to_computed_value(context),
vertical: self.vertical.to_computed_value(context), vertical: self.vertical.to_computed_value(context),

View file

@ -102,7 +102,7 @@
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
match *self { match *self {
SpecifiedValue::Normal => computed_value::T::Normal, SpecifiedValue::Normal => computed_value::T::Normal,
% if product == "gecko": % if product == "gecko":
@ -248,7 +248,7 @@
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
match *self { match *self {
SpecifiedValue::Normal => computed_value::T(None), SpecifiedValue::Normal => computed_value::T(None),
SpecifiedValue::Specified(l) => SpecifiedValue::Specified(l) =>
@ -322,7 +322,7 @@
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
match *self { match *self {
SpecifiedValue::Normal => computed_value::T(None), SpecifiedValue::Normal => computed_value::T(None),
SpecifiedValue::Specified(l) => SpecifiedValue::Specified(l) =>
@ -374,7 +374,6 @@ ${helpers.single_keyword("text-justify",
use values:: NoViewportPercentage; use values:: NoViewportPercentage;
use values::computed::ComputedValueAsSpecified; use values::computed::ComputedValueAsSpecified;
use properties::style_struct_traits::{Box, Color, Text};
impl ComputedValueAsSpecified for SpecifiedValue {} impl ComputedValueAsSpecified for SpecifiedValue {}
impl NoViewportPercentage for SpecifiedValue {} impl NoViewportPercentage for SpecifiedValue {}
@ -407,7 +406,7 @@ ${helpers.single_keyword("text-justify",
} }
} }
fn maybe<Cx: TContext>(flag: bool, context: &Cx) -> Option<RGBA> { fn maybe(flag: bool, context: &Context) -> Option<RGBA> {
if flag { if flag {
Some(context.style().get_color().clone_color()) Some(context.style().get_color().clone_color())
} else { } else {
@ -415,7 +414,7 @@ ${helpers.single_keyword("text-justify",
} }
} }
fn derive<Cx: TContext>(context: &Cx) -> computed_value::T { fn derive(context: &Context) -> computed_value::T {
// Start with no declarations if this is an atomic inline-level box; otherwise, start with the // Start with no declarations if this is an atomic inline-level box; otherwise, start with the
// declarations in effect and add in the text decorations that this block specifies. // declarations in effect and add in the text decorations that this block specifies.
let mut result = match context.style().get_box().clone_display() { let mut result = match context.style().get_box().clone_display() {
@ -439,13 +438,13 @@ ${helpers.single_keyword("text-justify",
} }
#[inline] #[inline]
pub fn derive_from_text_decoration<Cx: TContext>(context: &mut Cx) { pub fn derive_from_text_decoration(context: &mut Context) {
let derived = derive(context); let derived = derive(context);
context.mutate_style().mutate_inheritedtext().set__servo_text_decorations_in_effect(derived); context.mutate_style().mutate_inheritedtext().set__servo_text_decorations_in_effect(derived);
} }
#[inline] #[inline]
pub fn derive_from_display<Cx: TContext>(context: &mut Cx) { pub fn derive_from_display(context: &mut Context) {
let derived = derive(context); let derived = derive(context);
context.mutate_style().mutate_inheritedtext().set__servo_text_decorations_in_effect(derived); context.mutate_style().mutate_inheritedtext().set__servo_text_decorations_in_effect(derived);
} }
@ -675,7 +674,7 @@ ${helpers.single_keyword("text-justify",
impl ToComputedValue for SpecifiedValue { impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
computed_value::T(self.0.iter().map(|value| { computed_value::T(self.0.iter().map(|value| {
computed_value::TextShadow { computed_value::TextShadow {
offset_x: value.offset_x.to_computed_value(context), offset_x: value.offset_x.to_computed_value(context),

View file

@ -75,7 +75,7 @@ ${helpers.single_keyword("list-style-type", """
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, _context: &Cx) -> computed_value::T { fn to_computed_value(&self, _context: &Context) -> computed_value::T {
match *self { match *self {
SpecifiedValue::None => computed_value::T(None), SpecifiedValue::None => computed_value::T(None),
SpecifiedValue::Url(ref url) => computed_value::T(Some(url.clone())), SpecifiedValue::Url(ref url) => computed_value::T(Some(url.clone())),

View file

@ -63,7 +63,7 @@ ${helpers.predefined_type("outline-color", "CSSColor", "::cssparser::Color::Curr
type ComputedValue = computed_value::T; type ComputedValue = computed_value::T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
self.0.to_computed_value(context) self.0.to_computed_value(context)
} }
} }

View file

@ -108,10 +108,9 @@ ${helpers.single_keyword("unicode-bidi",
} }
% if product == "servo": % if product == "servo":
fn cascade_property_custom<C: ComputedValues>( fn cascade_property_custom(_declaration: &PropertyDeclaration,
_declaration: &PropertyDeclaration, _inherited_style: &ComputedValuesStruct,
_inherited_style: &C, context: &mut computed::Context,
context: &mut computed::Context<C>,
_seen: &mut PropertyBitField, _seen: &mut PropertyBitField,
_cacheable: &mut bool, _cacheable: &mut bool,
_error_reporter: &mut StdBox<ParseErrorReporter + Send>) { _error_reporter: &mut StdBox<ParseErrorReporter + Send>) {

View file

@ -13,28 +13,28 @@
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use std::boxed::Box as StdBox; use std::boxed::Box as StdBox;
use std::collections::HashSet; use std::collections::HashSet;
use std::fmt; use std::fmt::{self, Write};
use std::fmt::{Debug, Write};
use std::sync::Arc; use std::sync::Arc;
use app_units::Au; use app_units::Au;
use cssparser::Color as CSSParserColor; #[cfg(feature = "servo")] use cssparser::{Color as CSSParserColor, RGBA};
use cssparser::{Parser, RGBA, AtRuleParser, DeclarationParser, Delimiter, use cssparser::{Parser, AtRuleParser, DeclarationParser, Delimiter,
DeclarationListParser, parse_important, ToCss, TokenSerializationType}; DeclarationListParser, parse_important, ToCss, TokenSerializationType};
use error_reporting::ParseErrorReporter; use error_reporting::ParseErrorReporter;
use url::Url; use url::Url;
use euclid::side_offsets::SideOffsets2D; #[cfg(feature = "servo")] use euclid::side_offsets::SideOffsets2D;
use euclid::size::Size2D; use euclid::size::Size2D;
use string_cache::Atom; use string_cache::Atom;
use computed_values; use computed_values;
use logical_geometry::{LogicalMargin, PhysicalSide, WritingMode}; #[cfg(feature = "servo")] use logical_geometry::{LogicalMargin, PhysicalSide};
use logical_geometry::WritingMode;
use parser::{ParserContext, ParserContextExtraData, log_css_error}; use parser::{ParserContext, ParserContextExtraData, log_css_error};
use selectors::matching::DeclarationBlock; use selectors::matching::DeclarationBlock;
use stylesheets::Origin; use stylesheets::Origin;
use values::LocalToCss; use values::LocalToCss;
use values::HasViewportPercentage; use values::HasViewportPercentage;
use values::computed::{self, TContext, ToComputedValue}; use values::computed::{self, ToComputedValue};
use values::specified::BorderStyle; #[cfg(feature = "servo")] use values::specified::BorderStyle;
use self::property_bit_field::PropertyBitField; use self::property_bit_field::PropertyBitField;
@ -1082,104 +1082,34 @@ impl PropertyDeclaration {
} }
} }
pub mod style_struct_traits { #[cfg(feature = "gecko")]
use super::longhands; pub use gecko_properties::style_structs;
use std::fmt::Debug;
% for style_struct in data.active_style_structs():
pub trait ${style_struct.trait_name}: Debug + Clone {
% for longhand in style_struct.longhands:
#[allow(non_snake_case)]
fn set_${longhand.ident}(&mut self, v: longhands::${longhand.ident}::computed_value::T);
#[allow(non_snake_case)]
fn copy_${longhand.ident}_from(&mut self, other: &Self);
% if longhand.need_clone:
#[allow(non_snake_case)]
fn clone_${longhand.ident}(&self) -> longhands::${longhand.ident}::computed_value::T;
% endif
% if longhand.need_index:
#[allow(non_snake_case)]
fn ${longhand.ident}_count(&self) -> usize;
#[allow(non_snake_case)]
fn ${longhand.ident}_at(&self, index: usize)
-> longhands::${longhand.ident}::computed_value::SingleComputedValue;
#[allow(non_snake_case)]
#[inline]
fn ${longhand.ident}_iter<'a>(&'a self)
-> ${longhand.camel_case}Iter<'a, Self> {
${longhand.camel_case}Iter {
style_struct: self,
current: 0,
max: self.${longhand.ident}_count(),
}
}
#[allow(non_snake_case)]
#[inline]
fn ${longhand.ident}_mod(&self, index: usize)
-> longhands::${longhand.ident}::computed_value::SingleComputedValue {
self.${longhand.ident}_at(index % self.${longhand.ident}_count())
}
% endif
% endfor
% for additional in style_struct.additional_methods:
#[allow(non_snake_case)]
${additional.declare()}
% endfor
}
% for longhand in style_struct.longhands:
% if longhand.need_index:
pub struct ${longhand.camel_case}Iter<'a, S: ${style_struct.trait_name} + 'static> {
style_struct: &'a S,
current: usize,
max: usize,
}
impl<'a, S: ${style_struct.trait_name} + 'static> Iterator for ${longhand.camel_case}Iter<'a, S> {
type Item = longhands::${longhand.ident}::computed_value::SingleComputedValue;
fn next(&mut self) -> Option<Self::Item> {
self.current += 1;
if self.current <= self.max {
Some(self.style_struct.${longhand.ident}_at(self.current - 1))
} else {
None
}
}
}
% endif
% endfor
% endfor
}
#[cfg(feature = "servo")]
pub mod style_structs { pub mod style_structs {
use fnv::FnvHasher; use fnv::FnvHasher;
use super::longhands; use super::longhands;
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
% for style_struct in data.active_style_structs(): % for style_struct in data.active_style_structs():
% if style_struct.trait_name == "Font": % if style_struct.name == "Font":
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
% else: % else:
#[derive(PartialEq, Clone, Debug)] #[derive(PartialEq, Clone, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
% endif % endif
pub struct ${style_struct.servo_struct_name} { #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct ${style_struct.name} {
% for longhand in style_struct.longhands: % for longhand in style_struct.longhands:
pub ${longhand.ident}: longhands::${longhand.ident}::computed_value::T, pub ${longhand.ident}: longhands::${longhand.ident}::computed_value::T,
% endfor % endfor
% if style_struct.trait_name == "Font": % if style_struct.name == "Font":
pub hash: u64, pub hash: u64,
% endif % endif
} }
% if style_struct.trait_name == "Font": % if style_struct.name == "Font":
impl PartialEq for ${style_struct.servo_struct_name} { impl PartialEq for ${style_struct.name} {
fn eq(&self, other: &${style_struct.servo_struct_name}) -> bool { fn eq(&self, other: &${style_struct.name}) -> bool {
self.hash == other.hash self.hash == other.hash
% for longhand in style_struct.longhands: % for longhand in style_struct.longhands:
&& self.${longhand.ident} == other.${longhand.ident} && self.${longhand.ident} == other.${longhand.ident}
@ -1188,42 +1118,48 @@ pub mod style_structs {
} }
% endif % endif
impl super::style_struct_traits::${style_struct.trait_name} for ${style_struct.servo_struct_name} { impl ${style_struct.name} {
% for longhand in style_struct.longhands: % for longhand in style_struct.longhands:
#[allow(non_snake_case)]
#[inline] #[inline]
fn set_${longhand.ident}(&mut self, v: longhands::${longhand.ident}::computed_value::T) { pub fn set_${longhand.ident}(&mut self, v: longhands::${longhand.ident}::computed_value::T) {
self.${longhand.ident} = v; self.${longhand.ident} = v;
} }
#[allow(non_snake_case)]
#[inline] #[inline]
fn copy_${longhand.ident}_from(&mut self, other: &Self) { pub fn copy_${longhand.ident}_from(&mut self, other: &Self) {
self.${longhand.ident} = other.${longhand.ident}.clone(); self.${longhand.ident} = other.${longhand.ident}.clone();
} }
% if longhand.need_clone: % if longhand.need_clone:
#[allow(non_snake_case)]
#[inline] #[inline]
fn clone_${longhand.ident}(&self) -> longhands::${longhand.ident}::computed_value::T { pub fn clone_${longhand.ident}(&self) -> longhands::${longhand.ident}::computed_value::T {
self.${longhand.ident}.clone() self.${longhand.ident}.clone()
} }
% endif % endif
% if longhand.need_index: % if longhand.need_index:
fn ${longhand.ident}_count(&self) -> usize { #[allow(non_snake_case)]
pub fn ${longhand.ident}_count(&self) -> usize {
self.${longhand.ident}.0.len() self.${longhand.ident}.0.len()
} }
fn ${longhand.ident}_at(&self, index: usize) #[allow(non_snake_case)]
pub fn ${longhand.ident}_at(&self, index: usize)
-> longhands::${longhand.ident}::computed_value::SingleComputedValue { -> longhands::${longhand.ident}::computed_value::SingleComputedValue {
self.${longhand.ident}.0[index].clone() self.${longhand.ident}.0[index].clone()
} }
% endif % endif
% endfor % endfor
% if style_struct.trait_name == "Border": % if style_struct.name == "Border":
% for side in ["top", "right", "bottom", "left"]: % for side in ["top", "right", "bottom", "left"]:
fn border_${side}_has_nonzero_width(&self) -> bool { #[allow(non_snake_case)]
pub fn border_${side}_has_nonzero_width(&self) -> bool {
self.border_${side}_width != ::app_units::Au(0) self.border_${side}_width != ::app_units::Au(0)
} }
% endfor % endfor
% elif style_struct.trait_name == "Font": % elif style_struct.name == "Font":
fn compute_font_hash(&mut self) { pub fn compute_font_hash(&mut self) {
// Corresponds to the fields in `gfx::font_template::FontTemplateDescriptor`. // Corresponds to the fields in `gfx::font_template::FontTemplateDescriptor`.
let mut hasher: FnvHasher = Default::default(); let mut hasher: FnvHasher = Default::default();
hasher.write_u16(self.font_weight as u16); hasher.write_u16(self.font_weight as u16);
@ -1231,23 +1167,23 @@ pub mod style_structs {
self.font_family.hash(&mut hasher); self.font_family.hash(&mut hasher);
self.hash = hasher.finish() self.hash = hasher.finish()
} }
% elif style_struct.trait_name == "Outline": % elif style_struct.name == "Outline":
#[inline] #[inline]
fn outline_has_nonzero_width(&self) -> bool { pub fn outline_has_nonzero_width(&self) -> bool {
self.outline_width != ::app_units::Au(0) self.outline_width != ::app_units::Au(0)
} }
% elif style_struct.trait_name == "Text": % elif style_struct.name == "Text":
<% text_decoration_field = 'text_decoration' if product == 'servo' else 'text_decoration_line' %> <% text_decoration_field = 'text_decoration' if product == 'servo' else 'text_decoration_line' %>
#[inline] #[inline]
fn has_underline(&self) -> bool { pub fn has_underline(&self) -> bool {
self.${text_decoration_field}.underline self.${text_decoration_field}.underline
} }
#[inline] #[inline]
fn has_overline(&self) -> bool { pub fn has_overline(&self) -> bool {
self.${text_decoration_field}.overline self.${text_decoration_field}.overline
} }
#[inline] #[inline]
fn has_line_through(&self) -> bool { pub fn has_line_through(&self) -> bool {
self.${text_decoration_field}.line_through self.${text_decoration_field}.line_through
} }
% endif % endif
@ -1256,47 +1192,66 @@ pub mod style_structs {
% endfor % endfor
} }
pub trait ComputedValues : Debug + Clone + Send + Sync + 'static { % for style_struct in data.active_style_structs():
% for style_struct in data.active_style_structs(): impl style_structs::${style_struct.name} {
type Concrete${style_struct.trait_name}: style_struct_traits::${style_struct.trait_name}; % for longhand in style_struct.longhands:
% endfor % if longhand.need_index:
#[allow(non_snake_case)]
#[inline]
pub fn ${longhand.ident}_iter(&self) -> ${longhand.camel_case}Iter {
${longhand.camel_case}Iter {
style_struct: self,
current: 0,
max: self.${longhand.ident}_count(),
}
}
fn new(custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>, #[allow(non_snake_case)]
shareable: bool, #[inline]
writing_mode: WritingMode, pub fn ${longhand.ident}_mod(&self, index: usize)
root_font_size: Au, -> longhands::${longhand.ident}::computed_value::SingleComputedValue {
% for style_struct in data.active_style_structs(): self.${longhand.ident}_at(index % self.${longhand.ident}_count())
${style_struct.ident}: Arc<Self::Concrete${style_struct.trait_name}>, }
% endif
% endfor % endfor
) -> Self; }
fn style_for_child_text_node(parent: &Arc<Self>) -> Arc<Self>; % for longhand in style_struct.longhands:
% if longhand.need_index:
pub struct ${longhand.camel_case}Iter<'a> {
style_struct: &'a style_structs::${style_struct.name},
current: usize,
max: usize,
}
fn initial_values() -> &'static Self; impl<'a> Iterator for ${longhand.camel_case}Iter<'a> {
type Item = longhands::${longhand.ident}::computed_value::SingleComputedValue;
fn do_cascade_property<F: FnOnce(&[CascadePropertyFn<Self>])>(f: F); fn next(&mut self) -> Option<Self::Item> {
self.current += 1;
% for style_struct in data.active_style_structs(): if self.current <= self.max {
fn clone_${style_struct.trait_name_lower}(&self) -> Some(self.style_struct.${longhand.ident}_at(self.current - 1))
Arc<Self::Concrete${style_struct.trait_name}>; } else {
fn get_${style_struct.trait_name_lower}<'a>(&'a self) -> None
&'a Self::Concrete${style_struct.trait_name}; }
fn mutate_${style_struct.trait_name_lower}<'a>(&'a mut self) -> }
&'a mut Self::Concrete${style_struct.trait_name}; }
% endif
% endfor % endfor
% endfor
fn custom_properties(&self) -> Option<Arc<::custom_properties::ComputedValuesMap>>;
fn root_font_size(&self) -> Au;
fn set_root_font_size(&mut self, size: Au);
fn set_writing_mode(&mut self, mode: WritingMode);
fn is_multicol(&self) -> bool;
}
#[derive(Clone, Debug)] #[cfg(feature = "gecko")]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub use gecko_properties::ComputedValuesStruct;
pub struct ServoComputedValues {
#[cfg(feature = "servo")]
pub type ServoComputedValues = ComputedValuesStruct;
#[cfg(feature = "servo")]
#[cfg_attr(feature = "servo", derive(Clone, Debug, HeapSizeOf))]
pub struct ComputedValuesStruct {
% for style_struct in data.active_style_structs(): % for style_struct in data.active_style_structs():
${style_struct.ident}: Arc<style_structs::${style_struct.servo_struct_name}>, ${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
% endfor % endfor
custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>, custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>,
shareable: bool, shareable: bool,
@ -1304,85 +1259,77 @@ pub struct ServoComputedValues {
pub root_font_size: Au, pub root_font_size: Au,
} }
impl ComputedValues for ServoComputedValues { #[cfg(feature = "servo")]
% for style_struct in data.active_style_structs(): impl ComputedValuesStruct {
type Concrete${style_struct.trait_name} = style_structs::${style_struct.servo_struct_name}; pub fn new(custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>,
% endfor shareable: bool,
writing_mode: WritingMode,
fn new(custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>, root_font_size: Au,
shareable: bool, % for style_struct in data.active_style_structs():
writing_mode: WritingMode, ${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
root_font_size: Au, % endfor
% for style_struct in data.active_style_structs(): ) -> Self {
${style_struct.ident}: Arc<style_structs::${style_struct.servo_struct_name}>, ComputedValuesStruct {
% endfor custom_properties: custom_properties,
) -> Self { shareable: shareable,
ServoComputedValues { writing_mode: writing_mode,
custom_properties: custom_properties, root_font_size: root_font_size,
shareable: shareable, % for style_struct in data.active_style_structs():
writing_mode: writing_mode, ${style_struct.ident}: ${style_struct.ident},
root_font_size: root_font_size, % endfor
% for style_struct in data.active_style_structs():
${style_struct.ident}: ${style_struct.ident},
% endfor
}
} }
}
fn style_for_child_text_node(parent: &Arc<Self>) -> Arc<Self> { pub fn style_for_child_text_node(parent: &Arc<Self>) -> Arc<Self> {
// Text nodes get a copy of the parent style. Inheriting all non- // Text nodes get a copy of the parent style. Inheriting all non-
// inherited properties into the text node is odd from a CSS // inherited properties into the text node is odd from a CSS
// perspective, but makes fragment construction easier (by making // perspective, but makes fragment construction easier (by making
// properties like vertical-align on fragments have values that // properties like vertical-align on fragments have values that
// match the parent element). This is an implementation detail of // match the parent element). This is an implementation detail of
// Servo layout that is not central to how fragment construction // Servo layout that is not central to how fragment construction
// works, but would be difficult to change. (Text node style is // works, but would be difficult to change. (Text node style is
// also not visible to script.) // also not visible to script.)
parent.clone() parent.clone()
} }
fn initial_values() -> &'static Self { &*INITIAL_SERVO_VALUES } pub fn initial_values() -> &'static Self { &*INITIAL_SERVO_VALUES }
#[inline] #[inline]
fn do_cascade_property<F: FnOnce(&[CascadePropertyFn<Self>])>(f: F) { pub fn do_cascade_property<F: FnOnce(&[CascadePropertyFn])>(f: F) {
f(&CASCADE_PROPERTY) f(&CASCADE_PROPERTY)
} }
% for style_struct in data.active_style_structs(): % for style_struct in data.active_style_structs():
#[inline] #[inline]
fn clone_${style_struct.trait_name_lower}(&self) -> pub fn clone_${style_struct.name_lower}(&self) -> Arc<style_structs::${style_struct.name}> {
Arc<Self::Concrete${style_struct.trait_name}> {
self.${style_struct.ident}.clone() self.${style_struct.ident}.clone()
} }
#[inline] #[inline]
fn get_${style_struct.trait_name_lower}<'a>(&'a self) -> pub fn get_${style_struct.name_lower}(&self) -> &style_structs::${style_struct.name} {
&'a Self::Concrete${style_struct.trait_name} { &self.${style_struct.ident}
&self.${style_struct.ident} }
}
#[inline] #[inline]
fn mutate_${style_struct.trait_name_lower}<'a>(&'a mut self) -> pub fn mutate_${style_struct.name_lower}(&mut self) -> &mut style_structs::${style_struct.name} {
&'a mut Self::Concrete${style_struct.trait_name} { Arc::make_mut(&mut self.${style_struct.ident})
Arc::make_mut(&mut self.${style_struct.ident}) }
}
% endfor % endfor
// Cloning the Arc here is fine because it only happens in the case where we have custom // Cloning the Arc here is fine because it only happens in the case where we have custom
// properties, and those are both rare and expensive. // properties, and those are both rare and expensive.
fn custom_properties(&self) -> Option<Arc<::custom_properties::ComputedValuesMap>> { pub fn custom_properties(&self) -> Option<Arc<::custom_properties::ComputedValuesMap>> {
self.custom_properties.as_ref().map(|x| x.clone()) self.custom_properties.as_ref().map(|x| x.clone())
} }
fn root_font_size(&self) -> Au { self.root_font_size } pub fn root_font_size(&self) -> Au { self.root_font_size }
fn set_root_font_size(&mut self, size: Au) { self.root_font_size = size } pub fn set_root_font_size(&mut self, size: Au) { self.root_font_size = size }
fn set_writing_mode(&mut self, mode: WritingMode) { self.writing_mode = mode; } pub fn set_writing_mode(&mut self, mode: WritingMode) { self.writing_mode = mode; }
#[inline] #[inline]
fn is_multicol(&self) -> bool { pub fn is_multicol(&self) -> bool {
let style = self.get_column(); let style = self.get_column();
style.column_count.0.is_some() || style.column_width.0.is_some() style.column_count.0.is_some() || style.column_width.0.is_some()
} }
}
impl ServoComputedValues {
/// Resolves the currentColor keyword. /// Resolves the currentColor keyword.
/// Any color value form computed values (except for the 'color' property itself) /// Any color value form computed values (except for the 'color' property itself)
/// should go through this method. /// should go through this method.
@ -1483,7 +1430,7 @@ impl ServoComputedValues {
} }
#[inline] #[inline]
pub fn get_font_arc(&self) -> Arc<style_structs::ServoFont> { pub fn get_font_arc(&self) -> Arc<style_structs::Font> {
self.font.clone() self.font.clone()
} }
@ -1566,7 +1513,7 @@ impl ServoComputedValues {
/// Return a WritingMode bitflags from the relevant CSS properties. /// Return a WritingMode bitflags from the relevant CSS properties.
pub fn get_writing_mode<S: style_struct_traits::InheritedBox>(inheritedbox_style: &S) -> WritingMode { pub fn get_writing_mode(inheritedbox_style: &style_structs::InheritedBox) -> WritingMode {
use logical_geometry; use logical_geometry;
let mut flags = WritingMode::empty(); let mut flags = WritingMode::empty();
match inheritedbox_style.clone_direction() { match inheritedbox_style.clone_direction() {
@ -1607,43 +1554,53 @@ pub fn get_writing_mode<S: style_struct_traits::InheritedBox>(inheritedbox_style
} }
/// The initial values for all style structs as defined by the specification. #[cfg(feature = "servo")]
lazy_static! { pub use self::lazy_static_module::INITIAL_SERVO_VALUES;
pub static ref INITIAL_SERVO_VALUES: ServoComputedValues = ServoComputedValues {
% for style_struct in data.active_style_structs():
${style_struct.ident}: Arc::new(style_structs::${style_struct.servo_struct_name} {
% for longhand in style_struct.longhands:
${longhand.ident}: longhands::${longhand.ident}::get_initial_value(),
% endfor
% if style_struct.trait_name == "Font":
hash: 0,
% endif
}),
% endfor
custom_properties: None,
shareable: true,
writing_mode: WritingMode::empty(),
root_font_size: longhands::font_size::get_initial_value(),
};
}
// Use a module to work around #[cfg] on lazy_static! not being applied to every generated item.
#[cfg(feature = "servo")]
mod lazy_static_module {
use logical_geometry::WritingMode;
use std::sync::Arc;
use super::{ComputedValuesStruct, longhands, style_structs};
/// The initial values for all style structs as defined by the specification.
lazy_static! {
pub static ref INITIAL_SERVO_VALUES: ComputedValuesStruct = ComputedValuesStruct {
% for style_struct in data.active_style_structs():
${style_struct.ident}: Arc::new(style_structs::${style_struct.name} {
% for longhand in style_struct.longhands:
${longhand.ident}: longhands::${longhand.ident}::get_initial_value(),
% endfor
% if style_struct.name == "Font":
hash: 0,
% endif
}),
% endfor
custom_properties: None,
shareable: true,
writing_mode: WritingMode::empty(),
root_font_size: longhands::font_size::get_initial_value(),
};
}
}
/// Fast path for the function below. Only computes new inherited styles. /// Fast path for the function below. Only computes new inherited styles.
#[allow(unused_mut, unused_imports)] #[allow(unused_mut, unused_imports)]
fn cascade_with_cached_declarations<C: ComputedValues>( fn cascade_with_cached_declarations(
viewport_size: Size2D<Au>, viewport_size: Size2D<Au>,
applicable_declarations: &[DeclarationBlock<Vec<PropertyDeclaration>>], applicable_declarations: &[DeclarationBlock<Vec<PropertyDeclaration>>],
shareable: bool, shareable: bool,
parent_style: &C, parent_style: &ComputedValuesStruct,
cached_style: &C, cached_style: &ComputedValuesStruct,
custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>, custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>,
mut error_reporter: StdBox<ParseErrorReporter + Send>) mut error_reporter: StdBox<ParseErrorReporter + Send>)
-> C { -> ComputedValuesStruct {
let mut context = computed::Context { let mut context = computed::Context {
is_root_element: false, is_root_element: false,
viewport_size: viewport_size, viewport_size: viewport_size,
inherited_style: parent_style, inherited_style: parent_style,
style: C::new( style: ComputedValuesStruct::new(
custom_properties, custom_properties,
shareable, shareable,
WritingMode::empty(), WritingMode::empty(),
@ -1654,7 +1611,7 @@ fn cascade_with_cached_declarations<C: ComputedValues>(
% else: % else:
cached_style cached_style
% endif % endif
.clone_${style_struct.trait_name_lower}(), .clone_${style_struct.name_lower}(),
% endfor % endfor
), ),
}; };
@ -1671,7 +1628,6 @@ fn cascade_with_cached_declarations<C: ComputedValues>(
PropertyDeclaration::${property.camel_case}(ref PropertyDeclaration::${property.camel_case}(ref
${'_' if not style_struct.inherited else ''}declared_value) ${'_' if not style_struct.inherited else ''}declared_value)
=> { => {
use properties::style_struct_traits::${style_struct.trait_name};
% if style_struct.inherited: % if style_struct.inherited:
if seen.get_${property.ident}() { if seen.get_${property.ident}() {
continue continue
@ -1684,14 +1640,14 @@ fn cascade_with_cached_declarations<C: ComputedValues>(
DeclaredValue::Value(ref specified_value) DeclaredValue::Value(ref specified_value)
=> { => {
let computed = specified_value.to_computed_value(&context); let computed = specified_value.to_computed_value(&context);
context.mutate_style().mutate_${style_struct.trait_name_lower}() context.mutate_style().mutate_${style_struct.name_lower}()
.set_${property.ident}(computed); .set_${property.ident}(computed);
}, },
DeclaredValue::Initial DeclaredValue::Initial
=> { => {
// FIXME(bholley): We may want set_X_to_initial_value() here. // FIXME(bholley): We may want set_X_to_initial_value() here.
let initial = longhands::${property.ident}::get_initial_value(); let initial = longhands::${property.ident}::get_initial_value();
context.mutate_style().mutate_${style_struct.trait_name_lower}() context.mutate_style().mutate_${style_struct.name_lower}()
.set_${property.ident}(initial); .set_${property.ident}(initial);
}, },
DeclaredValue::Inherit => { DeclaredValue::Inherit => {
@ -1700,7 +1656,7 @@ fn cascade_with_cached_declarations<C: ComputedValues>(
// //
// FIXME: is it still? // FIXME: is it still?
let inherited_struct = parent_style.get_${style_struct.ident}(); let inherited_struct = parent_style.get_${style_struct.ident}();
context.mutate_style().mutate_${style_struct.trait_name_lower}() context.mutate_style().mutate_${style_struct.name_lower}()
.copy_${property.ident}_from(inherited_struct); .copy_${property.ident}_from(inherited_struct);
} }
DeclaredValue::WithVariables { .. } => unreachable!() DeclaredValue::WithVariables { .. } => unreachable!()
@ -1729,22 +1685,22 @@ fn cascade_with_cached_declarations<C: ComputedValues>(
if seen.get_font_style() || seen.get_font_weight() || seen.get_font_stretch() || if seen.get_font_style() || seen.get_font_weight() || seen.get_font_stretch() ||
seen.get_font_family() { seen.get_font_family() {
use properties::style_struct_traits::Font;
context.mutate_style().mutate_font().compute_font_hash(); context.mutate_style().mutate_font().compute_font_hash();
} }
context.style context.style
} }
pub type CascadePropertyFn<C /*: ComputedValues */> = pub type CascadePropertyFn =
extern "Rust" fn(declaration: &PropertyDeclaration, extern "Rust" fn(declaration: &PropertyDeclaration,
inherited_style: &C, inherited_style: &ComputedValuesStruct,
context: &mut computed::Context<C>, context: &mut computed::Context,
seen: &mut PropertyBitField, seen: &mut PropertyBitField,
cacheable: &mut bool, cacheable: &mut bool,
error_reporter: &mut StdBox<ParseErrorReporter + Send>); error_reporter: &mut StdBox<ParseErrorReporter + Send>);
static CASCADE_PROPERTY: [CascadePropertyFn<ServoComputedValues>; ${len(data.longhands)}] = [ #[cfg(feature = "servo")]
static CASCADE_PROPERTY: [CascadePropertyFn; ${len(data.longhands)}] = [
% for property in data.longhands: % for property in data.longhands:
longhands::${property.ident}::cascade_property, longhands::${property.ident}::cascade_property,
% endfor % endfor
@ -1768,16 +1724,14 @@ static CASCADE_PROPERTY: [CascadePropertyFn<ServoComputedValues>; ${len(data.lon
/// this is ignored. /// this is ignored.
/// ///
/// Returns the computed values and a boolean indicating whether the result is cacheable. /// Returns the computed values and a boolean indicating whether the result is cacheable.
pub fn cascade<C: ComputedValues>( pub fn cascade(viewport_size: Size2D<Au>,
viewport_size: Size2D<Au>,
applicable_declarations: &[DeclarationBlock<Vec<PropertyDeclaration>>], applicable_declarations: &[DeclarationBlock<Vec<PropertyDeclaration>>],
shareable: bool, shareable: bool,
parent_style: Option<<&C>, parent_style: Option<<&ComputedValuesStruct>,
cached_style: Option<<&C>, cached_style: Option<<&ComputedValuesStruct>,
mut error_reporter: StdBox<ParseErrorReporter + Send>) mut error_reporter: StdBox<ParseErrorReporter + Send>)
-> (C, bool) { -> (ComputedValuesStruct, bool) {
use properties::style_struct_traits::{Border, Box, Font, Outline}; let initial_values = ComputedValuesStruct::initial_values();
let initial_values = C::initial_values();
let (is_root_element, inherited_style) = match parent_style { let (is_root_element, inherited_style) = match parent_style {
Some(parent_style) => (false, parent_style), Some(parent_style) => (false, parent_style),
None => (true, initial_values), None => (true, initial_values),
@ -1817,7 +1771,7 @@ pub fn cascade<C: ComputedValues>(
is_root_element: is_root_element, is_root_element: is_root_element,
viewport_size: viewport_size, viewport_size: viewport_size,
inherited_style: inherited_style, inherited_style: inherited_style,
style: C::new( style: ComputedValuesStruct::new(
custom_properties, custom_properties,
shareable, shareable,
WritingMode::empty(), WritingMode::empty(),
@ -1828,7 +1782,7 @@ pub fn cascade<C: ComputedValues>(
% else: % else:
initial_values initial_values
% endif % endif
.clone_${style_struct.trait_name_lower}(), .clone_${style_struct.name_lower}(),
% endfor % endfor
), ),
}; };
@ -1842,7 +1796,7 @@ pub fn cascade<C: ComputedValues>(
// We could (and used to) use a pattern match here, but that bloats this function to over 100K // We could (and used to) use a pattern match here, but that bloats this function to over 100K
// of compiled code! To improve i-cache behavior, we outline the individual functions and use // of compiled code! To improve i-cache behavior, we outline the individual functions and use
// virtual dispatch instead. // virtual dispatch instead.
C::do_cascade_property(|cascade_property| { ComputedValuesStruct::do_cascade_property(|cascade_property| {
% for category_to_cascade_now in ["early", "other"]: % for category_to_cascade_now in ["early", "other"]:
for sub_list in applicable_declarations.iter().rev() { for sub_list in applicable_declarations.iter().rev() {
// Declarations are already stored in reverse order. // Declarations are already stored in reverse order.
@ -1940,7 +1894,6 @@ pub fn cascade<C: ComputedValues>(
% if "align-items" in data.longhands_by_name: % if "align-items" in data.longhands_by_name:
{ {
use self::style_struct_traits::Position;
use computed_values::align_self::T as align_self; use computed_values::align_self::T as align_self;
use computed_values::align_items::T as align_items; use computed_values::align_items::T as align_items;
if style.get_position().clone_align_self() == computed_values::align_self::T::auto && !positioned { if style.get_position().clone_align_self() == computed_values::align_self::T::auto && !positioned {
@ -1979,7 +1932,6 @@ pub fn cascade<C: ComputedValues>(
if seen.get_font_style() || seen.get_font_weight() || seen.get_font_stretch() || if seen.get_font_style() || seen.get_font_weight() || seen.get_font_stretch() ||
seen.get_font_family() { seen.get_font_family() {
use properties::style_struct_traits::Font;
style.mutate_font().compute_font_hash(); style.mutate_font().compute_font_hash();
} }
@ -1988,7 +1940,8 @@ pub fn cascade<C: ComputedValues>(
(style, cacheable) (style, cacheable)
} }
pub fn modify_style_for_anonymous_flow(style: &mut Arc<ServoComputedValues>, #[cfg(feature = "servo")]
pub fn modify_style_for_anonymous_flow(style: &mut Arc<ComputedValuesStruct>,
new_display_value: longhands::display::computed_value::T) { new_display_value: longhands::display::computed_value::T) {
// The 'align-self' property needs some special treatment since // The 'align-self' property needs some special treatment since
// its value depends on the 'align-items' value of its parent. // its value depends on the 'align-items' value of its parent.
@ -2008,7 +1961,7 @@ pub fn modify_style_for_anonymous_flow(style: &mut Arc<ServoComputedValues>,
let mut style = Arc::make_mut(style); let mut style = Arc::make_mut(style);
% for style_struct in data.active_style_structs(): % for style_struct in data.active_style_structs():
% if not style_struct.inherited: % if not style_struct.inherited:
style.${style_struct.ident} = inital_values.clone_${style_struct.trait_name_lower}(); style.${style_struct.ident} = inital_values.clone_${style_struct.name_lower}();
% endif % endif
% endfor % endfor
% if "align-items" in data.longhands_by_name: % if "align-items" in data.longhands_by_name:
@ -2035,8 +1988,9 @@ pub fn modify_style_for_anonymous_flow(style: &mut Arc<ServoComputedValues>,
/// `vertical-align: top` style of `sup` must not propagate down into `Foo`). /// `vertical-align: top` style of `sup` must not propagate down into `Foo`).
/// ///
/// FIXME(#5625, pcwalton): It would probably be cleaner and faster to do this in the cascade. /// FIXME(#5625, pcwalton): It would probably be cleaner and faster to do this in the cascade.
#[cfg(feature = "servo")]
#[inline] #[inline]
pub fn modify_style_for_replaced_content(style: &mut Arc<ServoComputedValues>) { pub fn modify_style_for_replaced_content(style: &mut Arc<ComputedValuesStruct>) {
// Reset `position` to handle cases like `<div style="position: absolute">foo bar baz</div>`. // Reset `position` to handle cases like `<div style="position: absolute">foo bar baz</div>`.
if style.box_.display != longhands::display::computed_value::T::inline { if style.box_.display != longhands::display::computed_value::T::inline {
let mut style = Arc::make_mut(style); let mut style = Arc::make_mut(style);
@ -2071,11 +2025,12 @@ pub fn modify_style_for_replaced_content(style: &mut Arc<ServoComputedValues>) {
/// ///
/// Specifically, this function sets border widths to zero on the sides for which the fragment is /// Specifically, this function sets border widths to zero on the sides for which the fragment is
/// not outermost. /// not outermost.
#[cfg(feature = "servo")]
#[inline] #[inline]
pub fn modify_border_style_for_inline_sides(style: &mut Arc<ServoComputedValues>, pub fn modify_border_style_for_inline_sides(style: &mut Arc<ComputedValuesStruct>,
is_first_fragment_of_element: bool, is_first_fragment_of_element: bool,
is_last_fragment_of_element: bool) { is_last_fragment_of_element: bool) {
fn modify_side(style: &mut Arc<ServoComputedValues>, side: PhysicalSide) { fn modify_side(style: &mut Arc<ComputedValuesStruct>, side: PhysicalSide) {
{ {
let border = &style.border; let border = &style.border;
let current_style = match side { let current_style = match side {
@ -2122,9 +2077,10 @@ pub fn modify_border_style_for_inline_sides(style: &mut Arc<ServoComputedValues>
} }
/// Adjusts the display and position properties as appropriate for an anonymous table object. /// Adjusts the display and position properties as appropriate for an anonymous table object.
#[cfg(feature = "servo")]
#[inline] #[inline]
pub fn modify_style_for_anonymous_table_object( pub fn modify_style_for_anonymous_table_object(
style: &mut Arc<ServoComputedValues>, style: &mut Arc<ComputedValuesStruct>,
new_display_value: longhands::display::computed_value::T) { new_display_value: longhands::display::computed_value::T) {
let mut style = Arc::make_mut(style); let mut style = Arc::make_mut(style);
let box_style = Arc::make_mut(&mut style.box_); let box_style = Arc::make_mut(&mut style.box_);
@ -2133,8 +2089,9 @@ pub fn modify_style_for_anonymous_table_object(
} }
/// Adjusts the `position` property as necessary for the outer fragment wrapper of an inline-block. /// Adjusts the `position` property as necessary for the outer fragment wrapper of an inline-block.
#[cfg(feature = "servo")]
#[inline] #[inline]
pub fn modify_style_for_outer_inline_block_fragment(style: &mut Arc<ServoComputedValues>) { pub fn modify_style_for_outer_inline_block_fragment(style: &mut Arc<ComputedValuesStruct>) {
let mut style = Arc::make_mut(style); let mut style = Arc::make_mut(style);
let box_style = Arc::make_mut(&mut style.box_); let box_style = Arc::make_mut(&mut style.box_);
box_style.position = longhands::position::computed_value::T::static_ box_style.position = longhands::position::computed_value::T::static_
@ -2144,8 +2101,9 @@ pub fn modify_style_for_outer_inline_block_fragment(style: &mut Arc<ServoCompute
/// ///
/// Text is never directly relatively positioned; it's always contained within an element that is /// Text is never directly relatively positioned; it's always contained within an element that is
/// itself relatively positioned. /// itself relatively positioned.
#[cfg(feature = "servo")]
#[inline] #[inline]
pub fn modify_style_for_text(style: &mut Arc<ServoComputedValues>) { pub fn modify_style_for_text(style: &mut Arc<ComputedValuesStruct>) {
if style.box_.position == longhands::position::computed_value::T::relative { if style.box_.position == longhands::position::computed_value::T::relative {
// We leave the `position` property set to `relative` so that we'll still establish a // We leave the `position` property set to `relative` so that we'll still establish a
// containing block if needed. But we reset all position offsets to `auto`. // containing block if needed. But we reset all position offsets to `auto`.
@ -2180,7 +2138,8 @@ pub fn modify_style_for_text(style: &mut Arc<ServoComputedValues>) {
/// ///
/// Margins apply to the `input` element itself, so including them in the text will cause them to /// Margins apply to the `input` element itself, so including them in the text will cause them to
/// be double-counted. /// be double-counted.
pub fn modify_style_for_input_text(style: &mut Arc<ServoComputedValues>) { #[cfg(feature = "servo")]
pub fn modify_style_for_input_text(style: &mut Arc<ComputedValuesStruct>) {
let mut style = Arc::make_mut(style); let mut style = Arc::make_mut(style);
let margin_style = Arc::make_mut(&mut style.margin); let margin_style = Arc::make_mut(&mut style.margin);
margin_style.margin_top = computed::LengthOrPercentageOrAuto::Length(Au(0)); margin_style.margin_top = computed::LengthOrPercentageOrAuto::Length(Au(0));
@ -2195,7 +2154,8 @@ pub fn modify_style_for_input_text(style: &mut Arc<ServoComputedValues>) {
/// Adjusts the `clip` property so that an inline absolute hypothetical fragment doesn't clip its /// Adjusts the `clip` property so that an inline absolute hypothetical fragment doesn't clip its
/// children. /// children.
pub fn modify_style_for_inline_absolute_hypothetical_fragment(style: &mut Arc<ServoComputedValues>) { #[cfg(feature = "servo")]
pub fn modify_style_for_inline_absolute_hypothetical_fragment(style: &mut Arc<ComputedValuesStruct>) {
if style.get_effects().clip.0.is_some() { if style.get_effects().clip.0.is_some() {
let mut style = Arc::make_mut(style); let mut style = Arc::make_mut(style);
let effects_style = Arc::make_mut(&mut style.effects); let effects_style = Arc::make_mut(&mut style.effects);

View file

@ -5,7 +5,6 @@
//! The pseudo-classes and pseudo-elements supported by the style system. //! The pseudo-classes and pseudo-elements supported by the style system.
use element_state::ElementState; use element_state::ElementState;
use properties;
use selectors::Element; use selectors::Element;
use selectors::parser::SelectorImpl; use selectors::parser::SelectorImpl;
use std::fmt::Debug; use std::fmt::Debug;
@ -74,8 +73,6 @@ pub trait ElementExt: Element {
// NB: The `Clone` trait is here for convenience due to: // NB: The `Clone` trait is here for convenience due to:
// https://github.com/rust-lang/rust/issues/26925 // https://github.com/rust-lang/rust/issues/26925
pub trait SelectorImplExt : SelectorImpl + Clone + Debug + Sized + 'static { pub trait SelectorImplExt : SelectorImpl + Clone + Debug + Sized + 'static {
type ComputedValues: properties::ComputedValues;
fn pseudo_element_cascade_type(pseudo: &Self::PseudoElement) -> PseudoElementCascadeType; fn pseudo_element_cascade_type(pseudo: &Self::PseudoElement) -> PseudoElementCascadeType;
fn each_pseudo_element<F>(mut fun: F) fn each_pseudo_element<F>(mut fun: F)

View file

@ -9,7 +9,7 @@ use element_state::*;
use error_reporting::StdoutErrorReporter; use error_reporting::StdoutErrorReporter;
use keyframes::KeyframesAnimation; use keyframes::KeyframesAnimation;
use media_queries::{Device, MediaType}; use media_queries::{Device, MediaType};
use properties::{self, PropertyDeclaration, PropertyDeclarationBlock}; use properties::{self, PropertyDeclaration, PropertyDeclarationBlock, ComputedValuesStruct};
use restyle_hints::{ElementSnapshot, RestyleHint, DependencySet}; use restyle_hints::{ElementSnapshot, RestyleHint, DependencySet};
use selector_impl::SelectorImplExt; use selector_impl::SelectorImplExt;
use selectors::bloom::BloomFilter; use selectors::bloom::BloomFilter;
@ -231,8 +231,8 @@ impl<Impl: SelectorImplExt> Stylist<Impl> {
/// universal rules and applying them. /// universal rules and applying them.
pub fn precomputed_values_for_pseudo(&self, pub fn precomputed_values_for_pseudo(&self,
pseudo: &Impl::PseudoElement, pseudo: &Impl::PseudoElement,
parent: Option<&Arc<Impl::ComputedValues>>) parent: Option<&Arc<ComputedValuesStruct>>)
-> Option<Arc<Impl::ComputedValues>> { -> Option<Arc<ComputedValuesStruct>> {
debug_assert!(Impl::pseudo_element_cascade_type(pseudo).is_precomputed()); debug_assert!(Impl::pseudo_element_cascade_type(pseudo).is_precomputed());
if let Some(declarations) = self.precomputed_pseudo_element_decls.get(pseudo) { if let Some(declarations) = self.precomputed_pseudo_element_decls.get(pseudo) {
let (computed, _) = let (computed, _) =
@ -250,8 +250,8 @@ impl<Impl: SelectorImplExt> Stylist<Impl> {
pub fn lazily_compute_pseudo_element_style<E>(&self, pub fn lazily_compute_pseudo_element_style<E>(&self,
element: &E, element: &E,
pseudo: &Impl::PseudoElement, pseudo: &Impl::PseudoElement,
parent: &Arc<Impl::ComputedValues>) parent: &Arc<ComputedValuesStruct>)
-> Option<Arc<Impl::ComputedValues>> -> Option<Arc<ComputedValuesStruct>>
where E: Element<Impl=Impl, AttrString=Impl::AttrString> + where E: Element<Impl=Impl, AttrString=Impl::AttrString> +
PresentationalHintsSynthetizer { PresentationalHintsSynthetizer {
debug_assert!(Impl::pseudo_element_cascade_type(pseudo).is_lazy()); debug_assert!(Impl::pseudo_element_cascade_type(pseudo).is_lazy());

View file

@ -6,14 +6,13 @@
use animation; use animation;
use context; use context;
use data; use data;
use properties::ServoComputedValues;
use selector_matching; use selector_matching;
use servo_selector_impl::ServoSelectorImpl; use servo_selector_impl::ServoSelectorImpl;
use stylesheets; use stylesheets;
pub type Stylesheet = stylesheets::Stylesheet<ServoSelectorImpl>; pub type Stylesheet = stylesheets::Stylesheet<ServoSelectorImpl>;
pub type PrivateStyleData = data::PrivateStyleData<ServoSelectorImpl, ServoComputedValues>; pub type PrivateStyleData = data::PrivateStyleData<ServoSelectorImpl>;
pub type Stylist = selector_matching::Stylist<ServoSelectorImpl>; pub type Stylist = selector_matching::Stylist<ServoSelectorImpl>;
pub type SharedStyleContext = context::SharedStyleContext<ServoSelectorImpl>; pub type SharedStyleContext = context::SharedStyleContext<ServoSelectorImpl>;
pub type LocalStyleContextCreationInfo = context::LocalStyleContextCreationInfo<ServoSelectorImpl>; pub type LocalStyleContextCreationInfo = context::LocalStyleContextCreationInfo;
pub type Animation = animation::Animation<ServoSelectorImpl>; pub type Animation = animation::Animation;

View file

@ -5,7 +5,6 @@
use element_state::ElementState; use element_state::ElementState;
use error_reporting::StdoutErrorReporter; use error_reporting::StdoutErrorReporter;
use parser::ParserContextExtraData; use parser::ParserContextExtraData;
use properties::ServoComputedValues;
use selector_impl::{SelectorImplExt, ElementExt, PseudoElementCascadeType}; use selector_impl::{SelectorImplExt, ElementExt, PseudoElementCascadeType};
use selectors::Element; use selectors::Element;
use selectors::parser::{ParserContext, SelectorImpl}; use selectors::parser::{ParserContext, SelectorImpl};
@ -154,8 +153,6 @@ impl SelectorImpl for ServoSelectorImpl {
} }
impl SelectorImplExt for ServoSelectorImpl { impl SelectorImplExt for ServoSelectorImpl {
type ComputedValues = ServoComputedValues;
#[inline] #[inline]
fn pseudo_element_cascade_type(pseudo: &PseudoElement) -> PseudoElementCascadeType { fn pseudo_element_cascade_type(pseudo: &PseudoElement) -> PseudoElementCascadeType {
pseudo.cascade_type() pseudo.cascade_type()

View file

@ -159,7 +159,7 @@ pub fn recalc_style_at<'a, N, C>(context: &'a C,
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::ConcreteElement as Element>::Impl: SelectorImplExt<ComputedValues=N::ConcreteComputedValues> + 'a { <N::ConcreteElement as Element>::Impl: SelectorImplExt + 'a {
// Get the parent node. // Get the parent node.
let parent_opt = match node.parent_node() { let parent_opt = match node.parent_node() {
Some(parent) if parent.is_element() => Some(parent), Some(parent) if parent.is_element() => Some(parent),

View file

@ -105,7 +105,7 @@ pub mod specified {
use std::fmt; use std::fmt;
use std::ops::Mul; use std::ops::Mul;
use style_traits::values::specified::AllowedNumericType; use style_traits::values::specified::AllowedNumericType;
use super::computed::{TContext, ToComputedValue}; use super::computed::{Context, ToComputedValue};
use super::{CSSFloat, FONT_MEDIUM_PX, HasViewportPercentage, LocalToCss, NoViewportPercentage}; use super::{CSSFloat, FONT_MEDIUM_PX, HasViewportPercentage, LocalToCss, NoViewportPercentage};
use url::Url; use url::Url;
@ -1569,7 +1569,7 @@ pub mod specified {
type ComputedValue = Time; type ComputedValue = Time;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, _: &Cx) -> Time { fn to_computed_value(&self, _: &Context) -> Time {
*self *self
} }
} }
@ -1611,7 +1611,7 @@ pub mod specified {
type ComputedValue = CSSFloat; type ComputedValue = CSSFloat;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, _: &Cx) -> CSSFloat { self.0 } fn to_computed_value(&self, _: &Context) -> CSSFloat { self.0 }
} }
impl ToCss for Number { impl ToCss for Number {
@ -1636,7 +1636,7 @@ pub mod specified {
type ComputedValue = CSSFloat; type ComputedValue = CSSFloat;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, _: &Cx) -> CSSFloat { fn to_computed_value(&self, _: &Context) -> CSSFloat {
if self.0 < 0.0 { if self.0 < 0.0 {
0.0 0.0
} else if self.0 > 1.0 { } else if self.0 > 1.0 {
@ -1657,8 +1657,7 @@ pub mod specified {
pub mod computed { pub mod computed {
use app_units::Au; use app_units::Au;
use euclid::size::Size2D; use euclid::size::Size2D;
use properties::ComputedValues; use properties::ComputedValuesStruct;
use properties::style_struct_traits::Font;
use std::fmt; use std::fmt;
use super::LocalToCss; use super::LocalToCss;
use super::specified::AngleOrCorner; use super::specified::AngleOrCorner;
@ -1667,39 +1666,29 @@ pub mod computed {
pub use cssparser::Color as CSSColor; pub use cssparser::Color as CSSColor;
pub use super::specified::{Angle, BorderStyle, Time}; pub use super::specified::{Angle, BorderStyle, Time};
pub trait TContext { pub struct Context<'a> {
type ConcreteComputedValues: ComputedValues;
fn is_root_element(&self) -> bool;
fn viewport_size(&self) -> Size2D<Au>;
fn inherited_style(&self) -> &Self::ConcreteComputedValues;
fn style(&self) -> &Self::ConcreteComputedValues;
fn mutate_style(&mut self) -> &mut Self::ConcreteComputedValues;
}
pub struct Context<'a, C: ComputedValues> {
pub is_root_element: bool, pub is_root_element: bool,
pub viewport_size: Size2D<Au>, pub viewport_size: Size2D<Au>,
pub inherited_style: &'a C, pub inherited_style: &'a ComputedValuesStruct,
/// Values access through this need to be in the properties "computed early": /// Values access through this need to be in the properties "computed early":
/// color, text-decoration, font-size, display, position, float, border-*-style, outline-style /// color, text-decoration, font-size, display, position, float, border-*-style, outline-style
pub style: C, pub style: ComputedValuesStruct,
} }
impl<'a, C: ComputedValues> TContext for Context<'a, C> { impl<'a> Context<'a> {
type ConcreteComputedValues = C; pub fn is_root_element(&self) -> bool { self.is_root_element }
fn is_root_element(&self) -> bool { self.is_root_element } pub fn viewport_size(&self) -> Size2D<Au> { self.viewport_size }
fn viewport_size(&self) -> Size2D<Au> { self.viewport_size } pub fn inherited_style(&self) -> &ComputedValuesStruct { &self.inherited_style }
fn inherited_style(&self) -> &C { &self.inherited_style } pub fn style(&self) -> &ComputedValuesStruct { &self.style }
fn style(&self) -> &C { &self.style } pub fn mutate_style(&mut self) -> &mut ComputedValuesStruct { &mut self.style }
fn mutate_style(&mut self) -> &mut C { &mut self.style }
} }
pub trait ToComputedValue { pub trait ToComputedValue {
type ComputedValue; type ComputedValue;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, _context: &Cx) -> Self::ComputedValue; fn to_computed_value(&self, _context: &Context) -> Self::ComputedValue;
} }
pub trait ComputedValueAsSpecified {} pub trait ComputedValueAsSpecified {}
@ -1708,7 +1697,7 @@ pub mod computed {
type ComputedValue = T; type ComputedValue = T;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, _context: &Cx) -> T { fn to_computed_value(&self, _context: &Context) -> T {
self.clone() self.clone()
} }
} }
@ -1717,7 +1706,7 @@ pub mod computed {
type ComputedValue = CSSColor; type ComputedValue = CSSColor;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, _context: &Cx) -> CSSColor { fn to_computed_value(&self, _context: &Context) -> CSSColor {
self.parsed self.parsed
} }
} }
@ -1728,7 +1717,7 @@ pub mod computed {
type ComputedValue = Au; type ComputedValue = Au;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> Au { fn to_computed_value(&self, context: &Context) -> Au {
match *self { match *self {
specified::Length::Absolute(length) => length, specified::Length::Absolute(length) => length,
specified::Length::Calc(calc) => calc.to_computed_value(context).length(), specified::Length::Calc(calc) => calc.to_computed_value(context).length(),
@ -1823,7 +1812,7 @@ pub mod computed {
impl ToComputedValue for specified::CalcLengthOrPercentage { impl ToComputedValue for specified::CalcLengthOrPercentage {
type ComputedValue = CalcLengthOrPercentage; type ComputedValue = CalcLengthOrPercentage;
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> CalcLengthOrPercentage { fn to_computed_value(&self, context: &Context) -> CalcLengthOrPercentage {
let mut length = None; let mut length = None;
if let Some(absolute) = self.absolute { if let Some(absolute) = self.absolute {
@ -1862,7 +1851,7 @@ pub mod computed {
type ComputedValue = BorderRadiusSize; type ComputedValue = BorderRadiusSize;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> BorderRadiusSize { fn to_computed_value(&self, context: &Context) -> BorderRadiusSize {
let w = self.0.width.to_computed_value(context); let w = self.0.width.to_computed_value(context);
let h = self.0.height.to_computed_value(context); let h = self.0.height.to_computed_value(context);
BorderRadiusSize(Size2D::new(w, h)) BorderRadiusSize(Size2D::new(w, h))
@ -1917,7 +1906,7 @@ pub mod computed {
impl ToComputedValue for specified::LengthOrPercentage { impl ToComputedValue for specified::LengthOrPercentage {
type ComputedValue = LengthOrPercentage; type ComputedValue = LengthOrPercentage;
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> LengthOrPercentage { fn to_computed_value(&self, context: &Context) -> LengthOrPercentage {
match *self { match *self {
specified::LengthOrPercentage::Length(value) => { specified::LengthOrPercentage::Length(value) => {
LengthOrPercentage::Length(value.to_computed_value(context)) LengthOrPercentage::Length(value.to_computed_value(context))
@ -1981,7 +1970,7 @@ pub mod computed {
type ComputedValue = LengthOrPercentageOrAuto; type ComputedValue = LengthOrPercentageOrAuto;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> LengthOrPercentageOrAuto { fn to_computed_value(&self, context: &Context) -> LengthOrPercentageOrAuto {
match *self { match *self {
specified::LengthOrPercentageOrAuto::Length(value) => { specified::LengthOrPercentageOrAuto::Length(value) => {
LengthOrPercentageOrAuto::Length(value.to_computed_value(context)) LengthOrPercentageOrAuto::Length(value.to_computed_value(context))
@ -2037,7 +2026,7 @@ pub mod computed {
type ComputedValue = LengthOrPercentageOrAutoOrContent; type ComputedValue = LengthOrPercentageOrAutoOrContent;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> LengthOrPercentageOrAutoOrContent { fn to_computed_value(&self, context: &Context) -> LengthOrPercentageOrAutoOrContent {
match *self { match *self {
specified::LengthOrPercentageOrAutoOrContent::Length(value) => { specified::LengthOrPercentageOrAutoOrContent::Length(value) => {
LengthOrPercentageOrAutoOrContent::Length(value.to_computed_value(context)) LengthOrPercentageOrAutoOrContent::Length(value.to_computed_value(context))
@ -2095,7 +2084,7 @@ pub mod computed {
type ComputedValue = LengthOrPercentageOrNone; type ComputedValue = LengthOrPercentageOrNone;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> LengthOrPercentageOrNone { fn to_computed_value(&self, context: &Context) -> LengthOrPercentageOrNone {
match *self { match *self {
specified::LengthOrPercentageOrNone::Length(value) => { specified::LengthOrPercentageOrNone::Length(value) => {
LengthOrPercentageOrNone::Length(value.to_computed_value(context)) LengthOrPercentageOrNone::Length(value.to_computed_value(context))
@ -2145,7 +2134,7 @@ pub mod computed {
type ComputedValue = LengthOrNone; type ComputedValue = LengthOrNone;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> LengthOrNone { fn to_computed_value(&self, context: &Context) -> LengthOrNone {
match *self { match *self {
specified::LengthOrNone::Length(specified::Length::Calc(calc)) => { specified::LengthOrNone::Length(specified::Length::Calc(calc)) => {
LengthOrNone::Length(calc.to_computed_value(context).length()) LengthOrNone::Length(calc.to_computed_value(context).length())
@ -2173,7 +2162,7 @@ pub mod computed {
type ComputedValue = Image; type ComputedValue = Image;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> Image { fn to_computed_value(&self, context: &Context) -> Image {
match *self { match *self {
specified::Image::Url(ref url) => Image::Url(url.clone()), specified::Image::Url(ref url) => Image::Url(url.clone()),
specified::Image::LinearGradient(ref linear_gradient) => { specified::Image::LinearGradient(ref linear_gradient) => {
@ -2272,7 +2261,7 @@ pub mod computed {
type ComputedValue = LinearGradient; type ComputedValue = LinearGradient;
#[inline] #[inline]
fn to_computed_value<Cx: TContext>(&self, context: &Cx) -> LinearGradient { fn to_computed_value(&self, context: &Context) -> LinearGradient {
let specified::LinearGradient { let specified::LinearGradient {
angle_or_corner, angle_or_corner,
ref stops ref stops

View file

@ -13,7 +13,7 @@ use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser,
use euclid::scale_factor::ScaleFactor; use euclid::scale_factor::ScaleFactor;
use euclid::size::{Size2D, TypedSize2D}; use euclid::size::{Size2D, TypedSize2D};
use parser::{ParserContext, log_css_error}; use parser::{ParserContext, log_css_error};
use properties::{ComputedValues, ServoComputedValues}; use properties::ComputedValuesStruct;
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use std::fmt; use std::fmt;
use std::iter::Enumerate; use std::iter::Enumerate;
@ -646,8 +646,8 @@ impl MaybeNew for ViewportConstraints {
let context = Context { let context = Context {
is_root_element: false, is_root_element: false,
viewport_size: initial_viewport, viewport_size: initial_viewport,
inherited_style: ServoComputedValues::initial_values(), inherited_style: ComputedValuesStruct::initial_values(),
style: ServoComputedValues::initial_values().clone(), style: ComputedValuesStruct::initial_values().clone(),
}; };
// DEVICE-ADAPT § 9.3 Resolving 'extend-to-zoom' // DEVICE-ADAPT § 9.3 Resolving 'extend-to-zoom'

View file

@ -6,12 +6,10 @@ use std::cell::RefCell;
use std::rc::Rc; use std::rc::Rc;
use style::context::{LocalStyleContext, StyleContext}; use style::context::{LocalStyleContext, StyleContext};
thread_local!(static LOCAL_CONTEXT_KEY: thread_local!(static LOCAL_CONTEXT_KEY: RefCell<Option<Rc<LocalStyleContext>>> = RefCell::new(None));
RefCell<Option<Rc<LocalStyleContext<GeckoSelectorImpl>>>> = 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<GeckoSelectorImpl>> {
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() {
@ -29,7 +27,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<GeckoSelectorImpl>>, cached_local_context: Rc<LocalStyleContext>,
} }
impl<'a> StandaloneStyleContext<'a> { impl<'a> StandaloneStyleContext<'a> {
@ -47,7 +45,7 @@ impl<'a> StyleContext<'a, GeckoSelectorImpl> for StandaloneStyleContext<'a> {
&self.shared &self.shared
} }
fn local_context(&self) -> &LocalStyleContext<GeckoSelectorImpl> { fn local_context(&self) -> &LocalStyleContext {
&self.cached_local_context &self.cached_local_context
} }
} }

View file

@ -14,7 +14,7 @@ use gecko_bindings::bindings::{ServoDeclarationBlock, ServoNodeData, ThreadSafeP
use gecko_bindings::bindings::{ThreadSafeURIHolder, nsHTMLCSSStyleSheet}; use gecko_bindings::bindings::{ThreadSafeURIHolder, nsHTMLCSSStyleSheet};
use gecko_bindings::ptr::{GeckoArcPrincipal, GeckoArcURI}; use gecko_bindings::ptr::{GeckoArcPrincipal, GeckoArcURI};
use gecko_bindings::structs::{SheetParsingMode, nsIAtom}; use gecko_bindings::structs::{SheetParsingMode, nsIAtom};
use properties::GeckoComputedValues; use properties::ComputedValuesStruct;
use selector_impl::{GeckoSelectorImpl, PseudoElement, SharedStyleContext, Stylesheet}; use selector_impl::{GeckoSelectorImpl, PseudoElement, SharedStyleContext, Stylesheet};
use std::mem::transmute; use std::mem::transmute;
use std::ptr; use std::ptr;
@ -28,7 +28,7 @@ use style::error_reporting::StdoutErrorReporter;
use style::gecko_glue::ArcHelpers; use style::gecko_glue::ArcHelpers;
use style::parallel; use style::parallel;
use style::parser::ParserContextExtraData; use style::parser::ParserContextExtraData;
use style::properties::{ComputedValues, PropertyDeclarationBlock, parse_one_declaration}; use style::properties::{PropertyDeclarationBlock, parse_one_declaration};
use style::selector_impl::{SelectorImplExt, PseudoElementCascadeType}; use style::selector_impl::{SelectorImplExt, PseudoElementCascadeType};
use style::sequential; use style::sequential;
use style::stylesheets::Origin; use style::stylesheets::Origin;
@ -87,7 +87,7 @@ fn restyle_subtree(node: GeckoNode, raw_data: *mut RawServoStyleSet) {
// rid of the HackilyFindSomeDeviceContext stuff that happens during // rid of the HackilyFindSomeDeviceContext stuff that happens during
// initial_values computation, since that stuff needs to be called further // initial_values computation, since that stuff needs to be called further
// along in startup than the sensible place to call Servo_Initialize. // along in startup than the sensible place to call Servo_Initialize.
GeckoComputedValues::initial_values(); ComputedValuesStruct::initial_values();
let _needs_dirtying = Arc::get_mut(&mut per_doc_data.stylist).unwrap() let _needs_dirtying = Arc::get_mut(&mut per_doc_data.stylist).unwrap()
.update(&per_doc_data.stylesheets, .update(&per_doc_data.stylesheets,
@ -259,7 +259,7 @@ pub extern "C" fn Servo_GetComputedValues(node: *mut RawGeckoNode)
// cases where Gecko wants the style for a node that Servo never // cases where Gecko wants the style for a node that Servo never
// traversed. We should remove this as soon as possible. // traversed. We should remove this as soon as possible.
error!("stylo: encountered unstyled node, substituting default values."); error!("stylo: encountered unstyled node, substituting default values.");
Arc::new(GeckoComputedValues::initial_values().clone()) Arc::new(ComputedValuesStruct::initial_values().clone())
}, },
}; };
unsafe { transmute(arc_cv) } unsafe { transmute(arc_cv) }
@ -280,7 +280,7 @@ pub extern "C" fn Servo_GetComputedValuesForAnonymousBox(parent_style_or_null: *
} }
}; };
type Helpers = ArcHelpers<ServoComputedValues, GeckoComputedValues>; type Helpers = ArcHelpers<ServoComputedValues, ComputedValuesStruct>;
Helpers::maybe_with(parent_style_or_null, |maybe_parent| { Helpers::maybe_with(parent_style_or_null, |maybe_parent| {
let new_computed = data.stylist.precomputed_values_for_pseudo(&pseudo, maybe_parent); let new_computed = data.stylist.precomputed_values_for_pseudo(&pseudo, maybe_parent);
@ -319,7 +319,7 @@ pub extern "C" fn Servo_GetComputedValuesForPseudoElement(parent_style: *mut Ser
let element = unsafe { GeckoElement::from_raw(match_element) }; let element = unsafe { GeckoElement::from_raw(match_element) };
type Helpers = ArcHelpers<ServoComputedValues, GeckoComputedValues>; type Helpers = ArcHelpers<ServoComputedValues, ComputedValuesStruct>;
match GeckoSelectorImpl::pseudo_element_cascade_type(&pseudo) { match GeckoSelectorImpl::pseudo_element_cascade_type(&pseudo) {
PseudoElementCascadeType::Eager => { PseudoElementCascadeType::Eager => {
@ -347,22 +347,22 @@ pub extern "C" fn Servo_GetComputedValuesForPseudoElement(parent_style: *mut Ser
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_InheritComputedValues(parent_style: *mut ServoComputedValues) pub extern "C" fn Servo_InheritComputedValues(parent_style: *mut ServoComputedValues)
-> *mut ServoComputedValues { -> *mut ServoComputedValues {
type Helpers = ArcHelpers<ServoComputedValues, GeckoComputedValues>; type Helpers = ArcHelpers<ServoComputedValues, ComputedValuesStruct>;
Helpers::with(parent_style, |parent| { Helpers::with(parent_style, |parent| {
let style = GeckoComputedValues::inherit_from(parent); let style = ComputedValuesStruct::inherit_from(parent);
Helpers::from(style) Helpers::from(style)
}) })
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_AddRefComputedValues(ptr: *mut ServoComputedValues) -> () { pub extern "C" fn Servo_AddRefComputedValues(ptr: *mut ServoComputedValues) -> () {
type Helpers = ArcHelpers<ServoComputedValues, GeckoComputedValues>; type Helpers = ArcHelpers<ServoComputedValues, ComputedValuesStruct>;
unsafe { Helpers::addref(ptr) }; unsafe { Helpers::addref(ptr) };
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_ReleaseComputedValues(ptr: *mut ServoComputedValues) -> () { pub extern "C" fn Servo_ReleaseComputedValues(ptr: *mut ServoComputedValues) -> () {
type Helpers = ArcHelpers<ServoComputedValues, GeckoComputedValues>; type Helpers = ArcHelpers<ServoComputedValues, ComputedValuesStruct>;
unsafe { Helpers::release(ptr) }; unsafe { Helpers::release(ptr) };
} }

View file

@ -27,7 +27,7 @@ use gecko_bindings::structs::nsIAtom;
use gecko_bindings::structs::{NODE_HAS_DIRTY_DESCENDANTS_FOR_SERVO, NODE_IS_DIRTY_FOR_SERVO}; use gecko_bindings::structs::{NODE_HAS_DIRTY_DESCENDANTS_FOR_SERVO, NODE_IS_DIRTY_FOR_SERVO};
use glue::GeckoDeclarationBlock; use glue::GeckoDeclarationBlock;
use libc::uintptr_t; use libc::uintptr_t;
use properties::GeckoComputedValues; use properties::ComputedValuesStruct;
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;
@ -99,8 +99,7 @@ impl<'ln> GeckoNode<'ln> {
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub struct DummyRestyleDamage; pub struct DummyRestyleDamage;
impl TRestyleDamage for DummyRestyleDamage { impl TRestyleDamage for DummyRestyleDamage {
type ConcreteComputedValues = GeckoComputedValues; fn compute(_: Option<&Arc<ComputedValuesStruct>>, _: &ComputedValuesStruct) -> Self { DummyRestyleDamage }
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 {
@ -114,7 +113,6 @@ 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)