From 5417df63971494c55d6d0bf4a6988c11f6e6e482 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 14 Nov 2015 21:18:45 +0100 Subject: [PATCH 1/4] Introduce a get_colspan method on LayoutJS. --- components/layout/table_cell.rs | 4 +--- components/layout/wrapper.rs | 6 ++++++ components/script/dom/element.rs | 13 +++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/components/layout/table_cell.rs b/components/layout/table_cell.rs index 963a7981562..eda755f177c 100644 --- a/components/layout/table_cell.rs +++ b/components/layout/table_cell.rs @@ -20,7 +20,6 @@ use model::MaybeAuto; use std::fmt; use std::sync::Arc; use style::computed_values::{border_collapse, border_top_style}; -use style::legacy::UnsignedIntegerAttribute; use style::properties::ComputedValues; use table::InternalTable; use table_row::{CollapsedBorder, CollapsedBorderProvenance}; @@ -52,8 +51,7 @@ impl TableCellFlow { TableCellFlow { block_flow: BlockFlow::from_fragment(fragment, None), collapsed_borders: CollapsedBordersForCell::new(), - column_span: node.get_unsigned_integer_attribute(UnsignedIntegerAttribute::ColSpan) - .unwrap_or(1), + column_span: node.get_colspan(), visible: visible, } } diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index b5f507f0108..8feba75a690 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -1039,6 +1039,12 @@ impl<'ln> ThreadSafeLayoutNode<'ln> { iframe_element.pipeline_id().unwrap() } } + + pub fn get_colspan(&self) -> u32 { + unsafe { + self.get_jsmanaged().downcast::().unwrap().get_colspan() + } + } } pub struct ThreadSafeLayoutNodeChildrenIterator<'a> { diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 158d9612442..a1a98e78edf 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -225,6 +225,8 @@ pub trait LayoutElementHelpers { unsafe fn synthesize_presentational_hints_for_legacy_attributes(&self, &mut V) where V: VecLike>>; #[allow(unsafe_code)] + unsafe fn get_colspan(self) -> u32; + #[allow(unsafe_code)] unsafe fn get_unsigned_integer_attribute_for_layout(&self, attribute: UnsignedIntegerAttribute) -> Option; #[allow(unsafe_code)] @@ -499,6 +501,17 @@ impl LayoutElementHelpers for LayoutJS { } } + #[allow(unsafe_code)] + unsafe fn get_colspan(self) -> u32 { + if let Some(this) = self.downcast::() { + this.get_colspan().unwrap_or(1) + } else { + // Don't panic since `display` can cause this to be called on arbitrary + // elements. + 1 + } + } + #[allow(unsafe_code)] unsafe fn get_unsigned_integer_attribute_for_layout(&self, attribute: UnsignedIntegerAttribute) From 9c1d678b1b82098c949123f7f8f8e0b9ab729127 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sun, 15 Nov 2015 11:24:03 +0100 Subject: [PATCH 2/4] Remove get_unsigned_integer_attribute. --- components/layout/wrapper.rs | 19 ------------------- components/script/dom/element.rs | 22 +--------------------- components/style/legacy.rs | 8 -------- components/style/node.rs | 2 -- 4 files changed, 1 insertion(+), 50 deletions(-) diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 8feba75a690..96bf3927381 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -64,7 +64,6 @@ use std::sync::Arc; use string_cache::{Atom, Namespace}; use style::computed_values::content::ContentItem; use style::computed_values::{content, display, white_space}; -use style::legacy::UnsignedIntegerAttribute; use style::node::TElementAttributes; use style::properties::ComputedValues; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock}; @@ -643,12 +642,6 @@ impl<'le> TElementAttributes for LayoutElement<'le> { } } - fn get_unsigned_integer_attribute(&self, attribute: UnsignedIntegerAttribute) -> Option { - unsafe { - self.element.get_unsigned_integer_attribute_for_layout(attribute) - } - } - #[inline] fn get_attr<'a>(&'a self, namespace: &Namespace, name: &Atom) -> Option<&'a str> { unsafe { @@ -885,18 +878,6 @@ impl<'ln> ThreadSafeLayoutNode<'ln> { } } - pub fn get_unsigned_integer_attribute(self, attribute: UnsignedIntegerAttribute) - -> Option { - unsafe { - match self.get_jsmanaged().downcast::() { - Some(element) => { - element.get_unsigned_integer_attribute_for_layout(attribute) - } - None => panic!("not an element!") - } - } - } - /// Get the description of how to account for recent style changes. /// This is a simple bitfield and fine to copy by value. pub fn restyle_damage(self) -> RestyleDamage { diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index a1a98e78edf..79d091505bc 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -75,7 +75,7 @@ use std::default::Default; use std::mem; use std::sync::Arc; use string_cache::{Atom, Namespace, QualName}; -use style::legacy::{UnsignedIntegerAttribute, from_declaration}; +use style::legacy::from_declaration; use style::properties::DeclaredValue; use style::properties::longhands::{self, background_image, border_spacing, font_family, font_size}; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, parse_style_attribute}; @@ -227,9 +227,6 @@ pub trait LayoutElementHelpers { #[allow(unsafe_code)] unsafe fn get_colspan(self) -> u32; #[allow(unsafe_code)] - unsafe fn get_unsigned_integer_attribute_for_layout(&self, attribute: UnsignedIntegerAttribute) - -> Option; - #[allow(unsafe_code)] unsafe fn html_element_in_html_document_for_layout(&self) -> bool; fn id_attribute(&self) -> *const Option; fn style_attribute(&self) -> *const Option; @@ -512,23 +509,6 @@ impl LayoutElementHelpers for LayoutJS { } } - #[allow(unsafe_code)] - unsafe fn get_unsigned_integer_attribute_for_layout(&self, - attribute: UnsignedIntegerAttribute) - -> Option { - match attribute { - UnsignedIntegerAttribute::ColSpan => { - if let Some(this) = self.downcast::() { - this.get_colspan() - } else { - // Don't panic since `display` can cause this to be called on arbitrary - // elements. - None - } - } - } - } - #[inline] #[allow(unsafe_code)] unsafe fn html_element_in_html_document_for_layout(&self) -> bool { diff --git a/components/style/legacy.rs b/components/style/legacy.rs index ffaaaadcab6..9d48b17d938 100644 --- a/components/style/legacy.rs +++ b/components/style/legacy.rs @@ -13,14 +13,6 @@ use selectors::matching::DeclarationBlock; use smallvec::VecLike; use std::sync::Arc; - -/// Legacy presentational attributes that take a nonnegative integer as defined in HTML5 ยง 2.4.4.2. -#[derive(Copy, Clone, PartialEq, Eq)] -pub enum UnsignedIntegerAttribute { - /// `` - ColSpan, -} - /// Extension methods for `Stylist` that cause rules to be synthesized for legacy attributes. pub trait PresentationalHintSynthesis { /// Synthesizes rules from various HTML attributes (mostly legacy junk from HTML4) that confer diff --git a/components/style/node.rs b/components/style/node.rs index aa764f5f662..302ad48fd80 100644 --- a/components/style/node.rs +++ b/components/style/node.rs @@ -5,7 +5,6 @@ //! Traits that nodes must implement. Breaks the otherwise-cyclic dependency between layout and //! style. -use legacy::UnsignedIntegerAttribute; use properties::PropertyDeclaration; use selectors::matching::DeclarationBlock; use smallvec::VecLike; @@ -14,7 +13,6 @@ use string_cache::{Atom, Namespace}; pub trait TElementAttributes { fn synthesize_presentational_hints_for_legacy_attributes(&self, &mut V) where V: VecLike>>; - fn get_unsigned_integer_attribute(&self, attribute: UnsignedIntegerAttribute) -> Option; fn get_attr<'a>(&'a self, namespace: &Namespace, attr: &Atom) -> Option<&'a str>; fn get_attrs<'a>(&'a self, attr: &Atom) -> Vec<&'a str>; From 1154cf51c8d97f777ee99b8362ec9fb270ffd011 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sun, 15 Nov 2015 13:46:55 +0100 Subject: [PATCH 3/4] Inline PresentationalHintSynthesis::synthesize_presentational_hints_for_legacy_attributes. --- components/style/legacy.rs | 35 --------------------------- components/style/selector_matching.rs | 10 +++++--- 2 files changed, 6 insertions(+), 39 deletions(-) diff --git a/components/style/legacy.rs b/components/style/legacy.rs index 9d48b17d938..9a67fa518c7 100644 --- a/components/style/legacy.rs +++ b/components/style/legacy.rs @@ -5,45 +5,10 @@ //! Legacy presentational attributes defined in the HTML5 specification: ``, //! ``, and so forth. -use node::TElementAttributes; use properties::PropertyDeclaration; -use selector_matching::Stylist; -use selectors::Element; use selectors::matching::DeclarationBlock; -use smallvec::VecLike; use std::sync::Arc; -/// Extension methods for `Stylist` that cause rules to be synthesized for legacy attributes. -pub trait PresentationalHintSynthesis { - /// Synthesizes rules from various HTML attributes (mostly legacy junk from HTML4) that confer - /// *presentational hints* as defined in the HTML5 specification. This handles stuff like - /// ``, ``, ``, and so forth. - /// - /// NB: Beware! If you add an attribute to this list, be sure to add it to - /// `common_style_affecting_attributes` or `rare_style_affecting_attributes` as appropriate. If - /// you don't, you risk strange random nondeterministic failures due to false positives in - /// style sharing. - fn synthesize_presentational_hints_for_legacy_attributes( - &self, element: &E, matching_rules_list: &mut V, shareable: &mut bool) - where E: Element + TElementAttributes, - V: VecLike>>; -} - -impl PresentationalHintSynthesis for Stylist { - fn synthesize_presentational_hints_for_legacy_attributes( - &self, element: &E, matching_rules_list: &mut V, shareable: &mut bool) - where E: Element + TElementAttributes, - V: VecLike>> { - let length = matching_rules_list.len(); - element.synthesize_presentational_hints_for_legacy_attributes(matching_rules_list); - if matching_rules_list.len() != length { - // Never share style for elements with preshints - *shareable = false; - } - } -} - - /// A convenience function to create a declaration block from a single declaration. This is /// primarily used in `synthesize_rules_for_legacy_attributes`. #[inline] diff --git a/components/style/selector_matching.rs b/components/style/selector_matching.rs index 5a4b1734917..e8887163b61 100644 --- a/components/style/selector_matching.rs +++ b/components/style/selector_matching.rs @@ -2,7 +2,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use legacy::PresentationalHintSynthesis; use media_queries::{Device, MediaType}; use node::TElementAttributes; use properties::{PropertyDeclaration, PropertyDeclarationBlock}; @@ -277,9 +276,12 @@ impl Stylist { &mut shareable); // Step 2: Presentational hints. - self.synthesize_presentational_hints_for_legacy_attributes(element, - applicable_declarations, - &mut shareable); + let length = applicable_declarations.len(); + element.synthesize_presentational_hints_for_legacy_attributes(applicable_declarations); + if applicable_declarations.len() != length { + // Never share style for elements with preshints + shareable = false; + } // Step 3: User and author normal rules. map.user.normal.get_all_matching_rules(element, From f2be9eb7358f2ea3a46e7c698a17073fba65f67e Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sun, 15 Nov 2015 13:57:22 +0100 Subject: [PATCH 4/4] Move the from_declaration to its only caller and remove the empty legacy module. --- components/script/dom/element.rs | 7 ++++++- components/style/legacy.rs | 17 ----------------- components/style/lib.rs | 1 - 3 files changed, 6 insertions(+), 19 deletions(-) delete mode 100644 components/style/legacy.rs diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 79d091505bc..47ccfdec7b8 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -75,7 +75,6 @@ use std::default::Default; use std::mem; use std::sync::Arc; use string_cache::{Atom, Namespace, QualName}; -use style::legacy::from_declaration; use style::properties::DeclaredValue; use style::properties::longhands::{self, background_image, border_spacing, font_family, font_size}; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, parse_style_attribute}; @@ -259,6 +258,12 @@ impl LayoutElementHelpers for LayoutJS { unsafe fn synthesize_presentational_hints_for_legacy_attributes(&self, hints: &mut V) where V: VecLike>> { + #[inline] + fn from_declaration(rule: PropertyDeclaration) + -> DeclarationBlock> { + DeclarationBlock::from_declarations(Arc::new(vec![rule])) + } + let bgcolor = if let Some(this) = self.downcast::() { this.get_background_color() } else if let Some(this) = self.downcast::() { diff --git a/components/style/legacy.rs b/components/style/legacy.rs deleted file mode 100644 index 9a67fa518c7..00000000000 --- a/components/style/legacy.rs +++ /dev/null @@ -1,17 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -//! Legacy presentational attributes defined in the HTML5 specification: ``, -//! ``, and so forth. - -use properties::PropertyDeclaration; -use selectors::matching::DeclarationBlock; -use std::sync::Arc; - -/// A convenience function to create a declaration block from a single declaration. This is -/// primarily used in `synthesize_rules_for_legacy_attributes`. -#[inline] -pub fn from_declaration(rule: PropertyDeclaration) -> DeclarationBlock> { - DeclarationBlock::from_declarations(Arc::new(vec![rule])) -} diff --git a/components/style/lib.rs b/components/style/lib.rs index a30274233d9..230a6cd0e28 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -45,7 +45,6 @@ pub mod animation; pub mod attr; mod custom_properties; pub mod font_face; -pub mod legacy; pub mod media_queries; pub mod node; pub mod parser;