aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2014-12-07 22:59:38 -0800
committerPatrick Walton <pcwalton@mimiga.net>2014-12-15 17:41:44 -0800
commit14bafb11bec973cd1362ff38a8e4aa2385c6ff37 (patch)
treee1dd41c6f1a2829e2be800cb27e7bdd4ee5f0a4f /components/script
parent10f1ed5e311e7092d3e24b58c4960f5e8a511ac0 (diff)
downloadservo-14bafb11bec973cd1362ff38a8e4aa2385c6ff37.tar.gz
servo-14bafb11bec973cd1362ff38a8e4aa2385c6ff37.zip
style: Parse the legacy `bgcolor` attribute per the HTML5 specification.
Additionally, this patch cleans up some miscellaneous formatting issues.
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/bindings/trace.rs3
-rw-r--r--components/script/dom/element.rs41
-rw-r--r--components/script/dom/htmlbodyelement.rs53
-rw-r--r--components/script/dom/htmltablecellelement.rs14
-rw-r--r--components/script/dom/htmltableelement.rs13
5 files changed, 103 insertions, 21 deletions
diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs
index afd329137c0..d5acb22ad7b 100644
--- a/components/script/dom/bindings/trace.rs
+++ b/components/script/dom/bindings/trace.rs
@@ -48,7 +48,7 @@ use script_traits::UntrustedNodeAddress;
use servo_msg::compositor_msg::ScriptListener;
use servo_msg::constellation_msg::ConstellationChan;
use servo_util::smallvec::{SmallVec1, SmallVec};
-use servo_util::str::LengthOrPercentageOrAuto;
+use servo_util::str::{LengthOrPercentageOrAuto, SimpleColor};
use std::cell::{Cell, RefCell};
use std::collections::HashMap;
use std::comm::{Receiver, Sender};
@@ -214,6 +214,7 @@ no_jsmanaged_fields!(LayoutChan)
no_jsmanaged_fields!(WindowProxyHandler)
no_jsmanaged_fields!(UntrustedNodeAddress)
no_jsmanaged_fields!(LengthOrPercentageOrAuto)
+no_jsmanaged_fields!(SimpleColor)
impl<'a> JSTraceable for &'a str {
#[inline]
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index db2b8d3d096..0cdf78b697d 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -16,9 +16,10 @@ 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::{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::codegen::InheritTypes::{HTMLBodyElementDerived, HTMLInputElementCast};
+use dom::bindings::codegen::InheritTypes::{HTMLInputElementDerived, HTMLTableElementCast};
+use dom::bindings::codegen::InheritTypes::{HTMLTableElementDerived, HTMLTableCellElementDerived};
+use dom::bindings::codegen::InheritTypes::{NodeCast};
use dom::bindings::js::{MutNullableJS, JS, JSRef, Temporary, TemporaryPushable};
use dom::bindings::js::{OptionalRootable, Root};
use dom::bindings::utils::{Reflectable, Reflector};
@@ -31,6 +32,7 @@ use dom::document::{Document, DocumentHelpers, LayoutDocumentHelpers};
use dom::domtokenlist::DOMTokenList;
use dom::event::Event;
use dom::eventtarget::{EventTarget, NodeTargetTypeId, EventTargetHelpers};
+use dom::htmlbodyelement::{HTMLBodyElement, HTMLBodyElementHelpers};
use dom::htmlcollection::HTMLCollection;
use dom::htmlinputelement::{HTMLInputElement, RawLayoutHTMLInputElementHelpers};
use dom::htmlserializer::serialize;
@@ -42,12 +44,11 @@ use dom::node::{window_from_node};
use dom::nodelist::NodeList;
use dom::virtualmethods::{VirtualMethods, vtable_for};
use devtools_traits::AttrInfo;
-use style::{BorderUnsignedIntegerAttribute, IntegerAttribute, LengthAttribute};
-use style::{SizeIntegerAttribute, UnsignedIntegerAttribute, WidthLengthAttribute};
-use style::{matches, parse_selector_list_from_str};
-use style;
+use style::{mod, BgColorSimpleColorAttribute, BorderUnsignedIntegerAttribute, IntegerAttribute};
+use style::{LengthAttribute, SimpleColorAttribute, SizeIntegerAttribute, UnsignedIntegerAttribute};
+use style::{WidthLengthAttribute, matches, parse_selector_list_from_str};
use servo_util::namespace;
-use servo_util::str::{DOMString, LengthOrPercentageOrAuto};
+use servo_util::str::{DOMString, LengthOrPercentageOrAuto, SimpleColor};
use std::ascii::AsciiExt;
use std::cell::{Ref, RefMut};
@@ -207,6 +208,8 @@ pub trait RawLayoutElementHelpers {
unsafe fn get_checked_state_for_layout(&self) -> bool;
unsafe fn get_unsigned_integer_attribute_for_layout(&self, attribute: UnsignedIntegerAttribute)
-> Option<u32>;
+ unsafe fn get_simple_color_attribute_for_layout(&self, attribute: SimpleColorAttribute)
+ -> Option<SimpleColor>;
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>>;
@@ -349,6 +352,28 @@ impl RawLayoutElementHelpers for Element {
}
}
+ #[inline]
+ #[allow(unrooted_must_root)]
+ unsafe fn get_simple_color_attribute_for_layout(&self, attribute: SimpleColorAttribute)
+ -> Option<SimpleColor> {
+ match attribute {
+ BgColorSimpleColorAttribute => {
+ if self.is_htmlbodyelement() {
+ let this: &HTMLBodyElement = mem::transmute(self);
+ this.get_background_color()
+ } else if self.is_htmltableelement() {
+ let this: &HTMLTableElement = mem::transmute(self);
+ this.get_background_color()
+ } else if self.is_htmltablecellelement() {
+ let this: &HTMLTableCellElement = mem::transmute(self);
+ this.get_background_color()
+ } else {
+ panic!("I'm not a body, table, or table cell!")
+ }
+ }
+ }
+ }
+
// Getters used in components/layout/wrapper.rs
fn local_name<'a>(&'a self) -> &'a Atom {
diff --git a/components/script/dom/htmlbodyelement.rs b/components/script/dom/htmlbodyelement.rs
index d088a6b8626..ebfe1e8025a 100644
--- a/components/script/dom/htmlbodyelement.rs
+++ b/components/script/dom/htmlbodyelement.rs
@@ -2,11 +2,9 @@
* 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;
-use dom::attr::AttrHelpers;
+use dom::attr::{Attr, AttrHelpers};
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
-use dom::bindings::codegen::Bindings::HTMLBodyElementBinding;
-use dom::bindings::codegen::Bindings::HTMLBodyElementBinding::HTMLBodyElementMethods;
+use dom::bindings::codegen::Bindings::HTMLBodyElementBinding::{mod, HTMLBodyElementMethods};
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use dom::bindings::codegen::InheritTypes::EventTargetCast;
use dom::bindings::codegen::InheritTypes::{HTMLBodyElementDerived, HTMLElementCast};
@@ -19,11 +17,13 @@ use dom::htmlelement::HTMLElement;
use dom::node::{Node, ElementNodeTypeId, window_from_node};
use dom::virtualmethods::VirtualMethods;
-use servo_util::str::DOMString;
+use servo_util::str::{mod, DOMString, SimpleColor};
+use std::cell::Cell;
#[dom_struct]
pub struct HTMLBodyElement {
- htmlelement: HTMLElement
+ htmlelement: HTMLElement,
+ background_color: Cell<Option<SimpleColor>>,
}
impl HTMLBodyElementDerived for EventTarget {
@@ -33,14 +33,20 @@ impl HTMLBodyElementDerived for EventTarget {
}
impl HTMLBodyElement {
- fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> HTMLBodyElement {
+ fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>)
+ -> HTMLBodyElement {
HTMLBodyElement {
- htmlelement: HTMLElement::new_inherited(HTMLBodyElementTypeId, localName, prefix, document)
+ htmlelement: HTMLElement::new_inherited(HTMLBodyElementTypeId,
+ localName,
+ prefix,
+ document),
+ background_color: Cell::new(None),
}
}
#[allow(unrooted_must_root)]
- pub fn new(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> Temporary<HTMLBodyElement> {
+ pub fn new(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>)
+ -> Temporary<HTMLBodyElement> {
let element = HTMLBodyElement::new_inherited(localName, prefix, document);
Node::reflect_node(box element, document, HTMLBodyElementBinding::Wrap)
}
@@ -58,6 +64,16 @@ impl<'a> HTMLBodyElementMethods for JSRef<'a, HTMLBodyElement> {
}
}
+pub trait HTMLBodyElementHelpers {
+ fn get_background_color(&self) -> Option<SimpleColor>;
+}
+
+impl HTMLBodyElementHelpers for HTMLBodyElement {
+ fn get_background_color(&self) -> Option<SimpleColor> {
+ self.background_color.get()
+ }
+}
+
impl<'a> VirtualMethods for JSRef<'a, HTMLBodyElement> {
fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods> {
let element: &JSRef<HTMLElement> = HTMLElementCast::from_borrowed_ref(self);
@@ -91,6 +107,25 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLBodyElement> {
name.slice_from(2),
attr.value().as_slice().to_string());
}
+
+ match attr.local_name() {
+ &atom!("bgcolor") => {
+ self.background_color.set(str::parse_legacy_color(attr.value().as_slice()).ok())
+ }
+ _ => {}
+ }
+ }
+
+ fn before_remove_attr(&self, attr: JSRef<Attr>) {
+ match self.super_type() {
+ Some(ref s) => s.before_remove_attr(attr),
+ _ => {}
+ }
+
+ match attr.local_name() {
+ &atom!("bgcolor") => self.background_color.set(None),
+ _ => {}
+ }
}
}
diff --git a/components/script/dom/htmltablecellelement.rs b/components/script/dom/htmltablecellelement.rs
index 622389397e9..25a5e9e78b0 100644
--- a/components/script/dom/htmltablecellelement.rs
+++ b/components/script/dom/htmltablecellelement.rs
@@ -14,13 +14,13 @@ use dom::htmlelement::HTMLElement;
use dom::node::ElementNodeTypeId;
use dom::virtualmethods::VirtualMethods;
-use servo_util::str::{AutoLpa, DOMString, LengthOrPercentageOrAuto};
-use servo_util::str;
+use servo_util::str::{mod, AutoLpa, DOMString, LengthOrPercentageOrAuto, SimpleColor};
use std::cell::Cell;
#[dom_struct]
pub struct HTMLTableCellElement {
htmlelement: HTMLElement,
+ background_color: Cell<Option<SimpleColor>>,
border: Cell<Option<u32>>,
width: Cell<LengthOrPercentageOrAuto>,
}
@@ -43,6 +43,7 @@ impl HTMLTableCellElement {
-> HTMLTableCellElement {
HTMLTableCellElement {
htmlelement: HTMLElement::new_inherited(type_id, tag_name, prefix, document),
+ background_color: Cell::new(None),
border: Cell::new(None),
width: Cell::new(AutoLpa),
}
@@ -55,11 +56,16 @@ impl HTMLTableCellElement {
}
pub trait HTMLTableCellElementHelpers {
+ fn get_background_color(&self) -> Option<SimpleColor>;
fn get_border(&self) -> Option<u32>;
fn get_width(&self) -> LengthOrPercentageOrAuto;
}
impl HTMLTableCellElementHelpers for HTMLTableCellElement {
+ fn get_background_color(&self) -> Option<SimpleColor> {
+ self.background_color.get()
+ }
+
fn get_border(&self) -> Option<u32> {
self.border.get()
}
@@ -82,6 +88,9 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTableCellElement> {
}
match attr.local_name() {
+ &atom!("bgcolor") => {
+ self.background_color.set(str::parse_legacy_color(attr.value().as_slice()).ok())
+ }
&atom!("border") => {
// According to HTML5 § 14.3.9, invalid values map to 1px.
self.border.set(Some(str::parse_unsigned_integer(attr.value()
@@ -100,6 +109,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTableCellElement> {
}
match attr.local_name() {
+ &atom!("bgcolor") => self.background_color.set(None),
&atom!("border") => self.border.set(None),
&atom!("width") => self.width.set(AutoLpa),
_ => ()
diff --git a/components/script/dom/htmltableelement.rs b/components/script/dom/htmltableelement.rs
index 9a7acd02559..4ece4c8b9f9 100644
--- a/components/script/dom/htmltableelement.rs
+++ b/components/script/dom/htmltableelement.rs
@@ -18,12 +18,13 @@ use dom::htmltablecaptionelement::HTMLTableCaptionElement;
use dom::node::{Node, NodeHelpers, ElementNodeTypeId};
use dom::virtualmethods::VirtualMethods;
-use servo_util::str::{mod, AutoLpa, DOMString, LengthOrPercentageOrAuto};
+use servo_util::str::{mod, AutoLpa, DOMString, LengthOrPercentageOrAuto, SimpleColor};
use std::cell::Cell;
#[dom_struct]
pub struct HTMLTableElement {
htmlelement: HTMLElement,
+ background_color: Cell<Option<SimpleColor>>,
border: Cell<Option<u32>>,
width: Cell<LengthOrPercentageOrAuto>,
}
@@ -42,6 +43,7 @@ impl HTMLTableElement {
localName,
prefix,
document),
+ background_color: Cell::new(None),
border: Cell::new(None),
width: Cell::new(AutoLpa),
}
@@ -93,11 +95,16 @@ impl<'a> HTMLTableElementMethods for JSRef<'a, HTMLTableElement> {
}
pub trait HTMLTableElementHelpers {
+ fn get_background_color(&self) -> Option<SimpleColor>;
fn get_border(&self) -> Option<u32>;
fn get_width(&self) -> LengthOrPercentageOrAuto;
}
impl HTMLTableElementHelpers for HTMLTableElement {
+ fn get_background_color(&self) -> Option<SimpleColor> {
+ self.background_color.get()
+ }
+
fn get_border(&self) -> Option<u32> {
self.border.get()
}
@@ -119,6 +126,9 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTableElement> {
}
match attr.local_name() {
+ &atom!("bgcolor") => {
+ self.background_color.set(str::parse_legacy_color(attr.value().as_slice()).ok())
+ }
&atom!("border") => {
// According to HTML5 § 14.3.9, invalid values map to 1px.
self.border.set(Some(str::parse_unsigned_integer(attr.value()
@@ -136,6 +146,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTableElement> {
}
match attr.local_name() {
+ &atom!("bgcolor") => self.background_color.set(None),
&atom!("border") => self.border.set(None),
_ => ()
}