From 9951e0b4d6fa22ed34a698d800fa9ca24e8a9681 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 9 May 2015 19:52:05 +0200 Subject: [PATCH 1/4] Parse table border. --- components/script/dom/htmltableelement.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/components/script/dom/htmltableelement.rs b/components/script/dom/htmltableelement.rs index b206f45429b..5d78305883c 100644 --- a/components/script/dom/htmltableelement.rs +++ b/components/script/dom/htmltableelement.rs @@ -2,7 +2,7 @@ * 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 dom::attr::{Attr, AttrHelpers}; +use dom::attr::{Attr, AttrHelpers, AttrValue}; use dom::bindings::codegen::Bindings::HTMLTableElementBinding::HTMLTableElementMethods; use dom::bindings::codegen::Bindings::HTMLTableElementBinding; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; @@ -17,8 +17,11 @@ use dom::htmltablecaptionelement::HTMLTableCaptionElement; use dom::node::{Node, NodeHelpers, NodeTypeId}; use dom::virtualmethods::VirtualMethods; -use cssparser::RGBA; use util::str::{self, DOMString, LengthOrPercentageOrAuto}; + +use cssparser::RGBA; +use string_cache::Atom; + use std::cell::Cell; #[dom_struct] @@ -158,5 +161,12 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTableElement> { _ => () } } + + fn parse_plain_attribute(&self, local_name: &Atom, value: DOMString) -> AttrValue { + match local_name { + &atom!("border") => AttrValue::from_u32(value, 1), + _ => self.super_type().unwrap().parse_plain_attribute(local_name, value), + } + } } From 1b99fd7ecb734b2b133d80e8850a8bc62001f09d Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 12 May 2015 13:02:50 +0200 Subject: [PATCH 2/4] Implement get_attr_for_layout that returns an AttrValue. --- components/script/dom/attr.rs | 7 +++++++ components/script/dom/element.rs | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs index 3e3979dbaef..8995f63ec2d 100644 --- a/components/script/dom/attr.rs +++ b/components/script/dom/attr.rs @@ -306,6 +306,7 @@ impl<'a> AttrHelpers<'a> for JSRef<'a, Attr> { #[allow(unsafe_code)] pub trait AttrHelpersForLayout { + unsafe fn value_forever(&self) -> &'static AttrValue; unsafe fn value_ref_forever(&self) -> &'static str; unsafe fn value_atom_forever(&self) -> Option; unsafe fn value_tokens_forever(&self) -> Option<&'static [Atom]>; @@ -314,6 +315,12 @@ pub trait AttrHelpersForLayout { #[allow(unsafe_code)] impl AttrHelpersForLayout for Attr { + #[inline] + unsafe fn value_forever(&self) -> &'static AttrValue { + // This transmute is used to cheat the lifetime restriction. + mem::transmute::<&AttrValue, &AttrValue>(self.value.borrow_for_layout()) + } + #[inline] unsafe fn value_ref_forever(&self) -> &'static str { // This transmute is used to cheat the lifetime restriction. diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 18481db2c2d..ef240679388 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -156,6 +156,8 @@ impl Element { #[allow(unsafe_code)] pub trait RawLayoutElementHelpers { + unsafe fn get_attr_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom) + -> Option<&'a AttrValue>; unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom) -> Option<&'a str>; unsafe fn get_attr_vals_for_layout<'a>(&'a self, name: &Atom) -> Vec<&'a str>; @@ -190,6 +192,13 @@ unsafe fn get_attr_for_layout(elem: &Element, namespace: &Namespace, name: &Atom #[allow(unsafe_code)] impl RawLayoutElementHelpers for Element { #[inline] + unsafe fn get_attr_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom) + -> Option<&'a AttrValue> { + get_attr_for_layout(self, namespace, name).map(|attr| { + (*attr.unsafe_get()).value_forever() + }) + } + unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom) -> Option<&'a str> { get_attr_for_layout(self, namespace, name).map(|attr| { From 52afa1dc348f0f9af74301be498a7392cfdc316d Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 12 May 2015 13:03:15 +0200 Subject: [PATCH 3/4] Stop using get_unsigned_integer_attribute_for_layout in has_nonzero_border. --- components/layout/wrapper.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index f9a214daf20..256aca623e0 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -40,6 +40,7 @@ use data::{LayoutDataAccess, LayoutDataFlags, LayoutDataWrapper, PrivateLayoutDa use opaque_node::OpaqueNodeMethods; use gfx::display_list::OpaqueNode; +use script::dom::attr::AttrValue; use script::dom::bindings::codegen::InheritTypes::{CharacterDataCast, ElementCast}; use script::dom::bindings::codegen::InheritTypes::{HTMLIFrameElementCast, HTMLCanvasElementCast}; use script::dom::bindings::codegen::InheritTypes::{HTMLImageElementCast, HTMLInputElementCast}; @@ -638,9 +639,8 @@ impl<'le> TElement<'le> for LayoutElement<'le> { #[inline] fn has_nonzero_border(self) -> bool { unsafe { - match self.element.get_unsigned_integer_attribute_for_layout( - UnsignedIntegerAttribute::Border) { - None | Some(0) => false, + match self.element.get_attr_for_layout(&ns!(""), &atom!("border")) { + None | Some(&AttrValue::UInt(_, 0)) => false, _ => true, } } From 69f92596cabcbd716fa5686232b8cc04e61bafe9 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 12 May 2015 14:18:58 +0200 Subject: [PATCH 4/4] Move table border to the new infrastructure. --- components/script/dom/element.rs | 34 ++++++++++++----- components/style/legacy.rs | 64 +------------------------------- 2 files changed, 25 insertions(+), 73 deletions(-) diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index ef240679388..f6e34985f5c 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -383,6 +383,30 @@ impl RawLayoutElementHelpers for Element { longhands::height::SpecifiedValue( specified::LengthOrPercentageOrAuto::Length(value)))))); } + + + let border = if self.is_htmltableelement() { + let this: &HTMLTableElement = mem::transmute(self); + this.get_border() + } else { + None + }; + + if let Some(border) = border { + let width_value = specified::Length::Absolute(Au::from_px(border as i32)); + hints.push(from_declaration( + PropertyDeclaration::BorderTopWidth(SpecifiedValue( + longhands::border_top_width::SpecifiedValue(width_value))))); + hints.push(from_declaration( + PropertyDeclaration::BorderLeftWidth(SpecifiedValue( + longhands::border_left_width::SpecifiedValue(width_value))))); + hints.push(from_declaration( + PropertyDeclaration::BorderBottomWidth(SpecifiedValue( + longhands::border_bottom_width::SpecifiedValue(width_value))))); + hints.push(from_declaration( + PropertyDeclaration::BorderRightWidth(SpecifiedValue( + longhands::border_right_width::SpecifiedValue(width_value))))); + } } #[inline] @@ -412,16 +436,6 @@ impl RawLayoutElementHelpers for Element { attribute: UnsignedIntegerAttribute) -> Option { match attribute { - UnsignedIntegerAttribute::Border => { - if self.is_htmltableelement() { - let this: &HTMLTableElement = mem::transmute(self); - this.get_border() - } else { - // Don't panic since `:-servo-nonzero-border` can cause this to be called on - // arbitrary elements. - None - } - } UnsignedIntegerAttribute::ColSpan => { if self.is_htmltablecellelement() { let this: &HTMLTableCellElement = mem::transmute(self); diff --git a/components/style/legacy.rs b/components/style/legacy.rs index 4d6e89756af..4d5123ff187 100644 --- a/components/style/legacy.rs +++ b/components/style/legacy.rs @@ -7,23 +7,17 @@ use std::sync::Arc; -use selectors::tree::{TElement, TNode}; +use selectors::tree::TNode; use selectors::matching::DeclarationBlock; use node::TElementAttributes; -use values::specified; -use properties::DeclaredValue::SpecifiedValue; use properties::PropertyDeclaration; -use properties::longhands; use selector_matching::Stylist; -use util::geometry::Au; use util::smallvec::VecLike; /// Legacy presentational attributes that take a nonnegative integer as defined in HTML5 ยง 2.4.4.2. #[derive(Copy, Clone, PartialEq, Eq)] pub enum UnsignedIntegerAttribute { - /// `` - Border, /// `` ColSpan, } @@ -46,16 +40,6 @@ pub trait PresentationalHintSynthesis { where N: TNode<'a>, N::Element: TElementAttributes<'a>, V: VecLike>>; - /// Synthesizes rules for the legacy `border` attribute. - fn synthesize_presentational_hint_for_legacy_border_attribute<'a,E,V>( - &self, - element: E, - matching_rules_list: &mut V, - shareable: &mut bool) - where - E: TElement<'a> + - TElementAttributes<'a>, - V: VecLike>>; } impl PresentationalHintSynthesis for Stylist { @@ -75,52 +59,6 @@ impl PresentationalHintSynthesis for Stylist { // Never share style for elements with preshints *shareable = false; } - - match element.get_local_name() { - name if *name == atom!("td") => { - self.synthesize_presentational_hint_for_legacy_border_attribute( - element, - matching_rules_list, - shareable); - } - name if *name == atom!("table") => { - self.synthesize_presentational_hint_for_legacy_border_attribute( - element, - matching_rules_list, - shareable); - } - _ => {} - } - } - - fn synthesize_presentational_hint_for_legacy_border_attribute<'a,E,V>( - &self, - element: E, - matching_rules_list: &mut V, - shareable: &mut bool) - where - E: TElement<'a> + - TElementAttributes<'a>, - V: VecLike>> { - match element.get_unsigned_integer_attribute(UnsignedIntegerAttribute::Border) { - None => {} - Some(length) => { - let width_value = specified::Length::Absolute(Au::from_px(length as i32)); - matching_rules_list.push(from_declaration( - PropertyDeclaration::BorderTopWidth(SpecifiedValue( - longhands::border_top_width::SpecifiedValue(width_value))))); - matching_rules_list.push(from_declaration( - PropertyDeclaration::BorderLeftWidth(SpecifiedValue( - longhands::border_left_width::SpecifiedValue(width_value))))); - matching_rules_list.push(from_declaration( - PropertyDeclaration::BorderBottomWidth(SpecifiedValue( - longhands::border_bottom_width::SpecifiedValue(width_value))))); - matching_rules_list.push(from_declaration( - PropertyDeclaration::BorderRightWidth(SpecifiedValue( - longhands::border_right_width::SpecifiedValue(width_value))))); - *shareable = false - } - } } }