From ef52da7acdcfbcf5b15cc82c2434f60ade0d0e33 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Sat, 7 Nov 2015 23:51:31 -0800 Subject: [PATCH] Move storage of color attribute on . --- components/script/dom/htmlfontelement.rs | 32 +++++++++--------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/components/script/dom/htmlfontelement.rs b/components/script/dom/htmlfontelement.rs index 61ac4f47797f..4e291db78029 100644 --- a/components/script/dom/htmlfontelement.rs +++ b/components/script/dom/htmlfontelement.rs @@ -3,25 +3,23 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use cssparser::RGBA; -use dom::attr::{Attr, AttrValue}; +use dom::attr::AttrValue; use dom::bindings::codegen::Bindings::HTMLFontElementBinding; use dom::bindings::codegen::Bindings::HTMLFontElementBinding::HTMLFontElementMethods; use dom::bindings::inheritance::Castable; use dom::bindings::js::Root; use dom::document::Document; -use dom::element::{AttributeMutation, Element, RawLayoutElementHelpers}; +use dom::element::{Element, RawLayoutElementHelpers}; use dom::htmlelement::HTMLElement; use dom::node::Node; use dom::virtualmethods::VirtualMethods; -use std::cell::Cell; use string_cache::Atom; use style::values::specified; -use util::str::{self, DOMString, parse_legacy_font_size}; +use util::str::{DOMString, parse_legacy_font_size}; #[dom_struct] pub struct HTMLFontElement { htmlelement: HTMLElement, - color: Cell>, } @@ -29,7 +27,6 @@ impl HTMLFontElement { fn new_inherited(localName: DOMString, prefix: Option, document: &Document) -> HTMLFontElement { HTMLFontElement { htmlelement: HTMLElement::new_inherited(localName, prefix, document), - color: Cell::new(None), } } @@ -47,7 +44,7 @@ impl HTMLFontElementMethods for HTMLFontElement { make_getter!(Color, "color"); // https://html.spec.whatwg.org/multipage/#dom-font-color - make_setter!(SetColor, "color"); + make_legacy_color_setter!(SetColor, "color"); // https://html.spec.whatwg.org/multipage/#dom-font-face make_getter!(Face); @@ -71,21 +68,10 @@ impl VirtualMethods for HTMLFontElement { Some(self.upcast::() as &VirtualMethods) } - fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { - self.super_type().unwrap().attribute_mutated(attr, mutation); - match attr.local_name() { - &atom!(color) => { - self.color.set(mutation.new_value(attr).and_then(|value| { - str::parse_legacy_color(&value).ok() - })); - }, - _ => {}, - } - } - fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { match name { &atom!("face") => AttrValue::from_atomic(value), + &atom!("color") => AttrValue::from_legacy_color(value), &atom!("size") => { let length = parse_length(&value); AttrValue::Length(value, length) @@ -97,8 +83,14 @@ impl VirtualMethods for HTMLFontElement { impl HTMLFontElement { + #[allow(unsafe_code)] pub fn get_color(&self) -> Option { - self.color.get() + unsafe { + self.upcast::() + .get_attr_for_layout(&ns!(""), &atom!("color")) + .and_then(AttrValue::as_color) + .cloned() + } } #[allow(unsafe_code)]