aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2015-10-16 13:25:21 -0700
committerEli Friedman <eli.friedman@gmail.com>2015-11-04 17:09:26 -0800
commit1940c3d7d6ab67f0eb1f72231654f93a021d916a (patch)
treeaefeed97743cc99d9686c7e48e194f14d2d40f68
parentb4d234107e7fcc02e88915f37c06bf651842c1dd (diff)
downloadservo-1940c3d7d6ab67f0eb1f72231654f93a021d916a.tar.gz
servo-1940c3d7d6ab67f0eb1f72231654f93a021d916a.zip
Remove HTMLTableCellElement fields with parsed attribute values.
-rw-r--r--components/script/dom/attr.rs8
-rw-r--r--components/script/dom/htmlbodyelement.rs5
-rw-r--r--components/script/dom/htmltablecellelement.rs27
3 files changed, 17 insertions, 23 deletions
diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs
index 024522acfe8..856fb90aa5b 100644
--- a/components/script/dom/attr.rs
+++ b/components/script/dom/attr.rs
@@ -21,7 +21,8 @@ use std::mem;
use std::ops::Deref;
use string_cache::{Atom, Namespace};
use style::values::specified::Length;
-use util::str::{DOMString, parse_unsigned_integer, split_html_space_chars, str_join};
+use util::str::{DOMString, parse_unsigned_integer, parse_legacy_color};
+use util::str::{split_html_space_chars, str_join};
#[derive(JSTraceable, PartialEq, Clone, HeapSizeOf)]
pub enum AttrValue {
@@ -77,6 +78,11 @@ impl AttrValue {
AttrValue::Atom(value)
}
+ pub fn from_legacy_color(string: DOMString) -> AttrValue {
+ let parsed = parse_legacy_color(&string).ok();
+ AttrValue::Color(string, parsed)
+ }
+
/// Assumes the `AttrValue` is a `TokenList` and returns its tokens
///
/// ## Panics
diff --git a/components/script/dom/htmlbodyelement.rs b/components/script/dom/htmlbodyelement.rs
index 5e266646a1c..1f8de257596 100644
--- a/components/script/dom/htmlbodyelement.rs
+++ b/components/script/dom/htmlbodyelement.rs
@@ -142,10 +142,7 @@ impl VirtualMethods for HTMLBodyElement {
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
match name {
- &atom!("text") => {
- let parsed = str::parse_legacy_color(&value).ok();
- AttrValue::Color(value, parsed)
- },
+ &atom!("text") => AttrValue::from_legacy_color(value),
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}
}
diff --git a/components/script/dom/htmltablecellelement.rs b/components/script/dom/htmltablecellelement.rs
index d95d663ffee..f9754dc9a5b 100644
--- a/components/script/dom/htmltablecellelement.rs
+++ b/components/script/dom/htmltablecellelement.rs
@@ -9,13 +9,12 @@ use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use dom::bindings::inheritance::Castable;
use dom::bindings::js::LayoutJS;
use dom::document::Document;
-use dom::element::AttributeMutation;
+use dom::element::{AttributeMutation, Element, RawLayoutElementHelpers};
use dom::htmlelement::HTMLElement;
use dom::htmltablerowelement::HTMLTableRowElement;
use dom::node::Node;
use dom::virtualmethods::VirtualMethods;
use std::cell::Cell;
-use std::cmp::max;
use string_cache::Atom;
use util::str::{self, DOMString, LengthOrPercentageOrAuto};
@@ -24,8 +23,6 @@ const DEFAULT_COLSPAN: u32 = 1;
#[dom_struct]
pub struct HTMLTableCellElement {
htmlelement: HTMLElement,
- background_color: Cell<Option<RGBA>>,
- colspan: Cell<Option<u32>>,
width: Cell<LengthOrPercentageOrAuto>,
}
@@ -36,8 +33,6 @@ impl HTMLTableCellElement {
-> HTMLTableCellElement {
HTMLTableCellElement {
htmlelement: HTMLElement::new_inherited(tag_name, prefix, document),
- background_color: Cell::new(None),
- colspan: Cell::new(None),
width: Cell::new(LengthOrPercentageOrAuto::Auto),
}
}
@@ -83,13 +78,18 @@ pub trait HTMLTableCellElementLayoutHelpers {
impl HTMLTableCellElementLayoutHelpers for LayoutJS<HTMLTableCellElement> {
fn get_background_color(&self) -> Option<RGBA> {
unsafe {
- (*self.unsafe_get()).background_color.get()
+ (&*self.upcast::<Element>().unsafe_get())
+ .get_attr_for_layout(&ns!(""), &atom!("bgcolor"))
+ .and_then(AttrValue::as_color)
+ .cloned()
}
}
fn get_colspan(&self) -> Option<u32> {
unsafe {
- (*self.unsafe_get()).colspan.get()
+ (&*self.upcast::<Element>().unsafe_get())
+ .get_attr_for_layout(&ns!(""), &atom!("colspan"))
+ .map(AttrValue::as_uint)
}
}
@@ -108,16 +108,6 @@ impl VirtualMethods for HTMLTableCellElement {
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
self.super_type().unwrap().attribute_mutated(attr, mutation);
match *attr.local_name() {
- atom!(bgcolor) => {
- self.background_color.set(mutation.new_value(attr).and_then(|value| {
- str::parse_legacy_color(&value).ok()
- }));
- },
- atom!(colspan) => {
- self.colspan.set(mutation.new_value(attr).map(|value| {
- max(DEFAULT_COLSPAN, value.as_uint())
- }));
- },
atom!(width) => {
let width = mutation.new_value(attr).map(|value| {
str::parse_length(&value)
@@ -131,6 +121,7 @@ impl VirtualMethods for HTMLTableCellElement {
fn parse_plain_attribute(&self, local_name: &Atom, value: DOMString) -> AttrValue {
match *local_name {
atom!("colspan") => AttrValue::from_u32(value, DEFAULT_COLSPAN),
+ atom!("bgcolor") => AttrValue::from_legacy_color(value),
_ => self.super_type().unwrap().parse_plain_attribute(local_name, value),
}
}