style: Parse the legacy border attribute per the legacy HTML specification.

Additionally, this patch cleans up some miscellaneous formatting issues
and refactors files in `layout/css/` somewhat to eliminate needless
levels of indirection. It also fixes our handling of presentational
hints that only apply if border is nonzero.
This commit is contained in:
Patrick Walton 2014-12-07 22:54:56 -08:00
parent e0e14c60d6
commit 10f1ed5e31
19 changed files with 350 additions and 127 deletions

View file

@ -15,8 +15,10 @@ use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods;
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods;
use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods;
use dom::bindings::codegen::InheritTypes::{ElementDerived, HTMLInputElementDerived, HTMLTableCellElementDerived};
use dom::bindings::codegen::InheritTypes::{HTMLInputElementCast, NodeCast, EventTargetCast, ElementCast};
use dom::bindings::codegen::InheritTypes::{ElementCast, ElementDerived, EventTargetCast};
use dom::bindings::codegen::InheritTypes::{HTMLInputElementCast, HTMLInputElementDerived};
use dom::bindings::codegen::InheritTypes::{HTMLTableElementCast, HTMLTableElementDerived};
use dom::bindings::codegen::InheritTypes::{HTMLTableCellElementDerived, NodeCast};
use dom::bindings::js::{MutNullableJS, JS, JSRef, Temporary, TemporaryPushable};
use dom::bindings::js::{OptionalRootable, Root};
use dom::bindings::utils::{Reflectable, Reflector};
@ -32,14 +34,16 @@ use dom::eventtarget::{EventTarget, NodeTargetTypeId, EventTargetHelpers};
use dom::htmlcollection::HTMLCollection;
use dom::htmlinputelement::{HTMLInputElement, RawLayoutHTMLInputElementHelpers};
use dom::htmlserializer::serialize;
use dom::htmltableelement::{HTMLTableElement, HTMLTableElementHelpers};
use dom::htmltablecellelement::{HTMLTableCellElement, HTMLTableCellElementHelpers};
use dom::node::{CLICK_IN_PROGRESS, ElementNodeTypeId, Node, NodeHelpers, NodeIterator};
use dom::node::{document_from_node, window_from_node, LayoutNodeHelpers, NodeStyleDamaged};
use dom::node::{OtherNodeDamage};
use dom::node::{CLICK_IN_PROGRESS, ElementNodeTypeId, LayoutNodeHelpers, Node, NodeHelpers};
use dom::node::{NodeIterator, NodeStyleDamaged, OtherNodeDamage, document_from_node};
use dom::node::{window_from_node};
use dom::nodelist::NodeList;
use dom::virtualmethods::{VirtualMethods, vtable_for};
use devtools_traits::AttrInfo;
use style::{IntegerAttribute, LengthAttribute, SizeIntegerAttribute, WidthLengthAttribute};
use style::{BorderUnsignedIntegerAttribute, IntegerAttribute, LengthAttribute};
use style::{SizeIntegerAttribute, UnsignedIntegerAttribute, WidthLengthAttribute};
use style::{matches, parse_selector_list_from_str};
use style;
use servo_util::namespace;
@ -201,6 +205,8 @@ pub trait RawLayoutElementHelpers {
unsafe fn get_integer_attribute_for_layout(&self, integer_attribute: IntegerAttribute)
-> Option<i32>;
unsafe fn get_checked_state_for_layout(&self) -> bool;
unsafe fn get_unsigned_integer_attribute_for_layout(&self, attribute: UnsignedIntegerAttribute)
-> Option<u32>;
fn local_name<'a>(&'a self) -> &'a Atom;
fn namespace<'a>(&'a self) -> &'a Namespace;
fn style_attribute<'a>(&'a self) -> &'a DOMRefCell<Option<style::PropertyDeclarationBlock>>;
@ -285,11 +291,15 @@ impl RawLayoutElementHelpers for Element {
-> LengthOrPercentageOrAuto {
match length_attribute {
WidthLengthAttribute => {
if !self.is_htmltablecellelement() {
panic!("I'm not a table cell!")
if self.is_htmltableelement() {
let this: &HTMLTableElement = mem::transmute(self);
this.get_width()
} else if self.is_htmltablecellelement() {
let this: &HTMLTableCellElement = mem::transmute(self);
this.get_width()
} else {
panic!("I'm not a table or table cell!")
}
let this: &HTMLTableCellElement = mem::transmute(self);
this.get_width()
}
}
}
@ -319,6 +329,26 @@ impl RawLayoutElementHelpers for Element {
this.get_checked_state_for_layout()
}
unsafe fn get_unsigned_integer_attribute_for_layout(&self,
attribute: UnsignedIntegerAttribute)
-> Option<u32> {
match attribute {
BorderUnsignedIntegerAttribute => {
if self.is_htmltableelement() {
let this: &HTMLTableElement = mem::transmute(self);
this.get_border()
} else if self.is_htmltablecellelement() {
let this: &HTMLTableCellElement = mem::transmute(self);
this.get_border()
} else {
// Don't panic since `:-servo-nonzero-border` can cause this to be called on
// arbitrary elements.
None
}
}
}
}
// Getters used in components/layout/wrapper.rs
fn local_name<'a>(&'a self) -> &'a Atom {
@ -1222,6 +1252,17 @@ impl<'a> style::TElement<'a> for JSRef<'a, Element> {
}
}
}
fn has_nonzero_border(self) -> bool {
match HTMLTableElementCast::to_ref(self) {
None => false,
Some(this) => {
match this.get_border() {
None | Some(0) => false,
Some(_) => true,
}
}
}
}
}
pub trait ActivationElementHelpers<'a> {