Skip to content

Commit

Permalink
Remove HTMLTableCellElement fields with parsed attribute values.
Browse files Browse the repository at this point in the history
  • Loading branch information
eefriedman committed Nov 5, 2015
1 parent b4d2341 commit 1940c3d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
8 changes: 7 additions & 1 deletion components/script/dom/attr.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions components/script/dom/htmlbodyelement.rs
Expand Up @@ -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),
}
}
Expand Down
27 changes: 9 additions & 18 deletions components/script/dom/htmltablecellelement.rs
Expand Up @@ -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};

Expand All @@ -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>,
}

Expand All @@ -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),
}
}
Expand Down Expand Up @@ -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)
}
}

Expand All @@ -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)
Expand All @@ -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),
}
}
Expand Down

0 comments on commit 1940c3d

Please sign in to comment.