Skip to content

Commit

Permalink
Move storage of color attribute on <font>.
Browse files Browse the repository at this point in the history
  • Loading branch information
eefriedman committed Nov 9, 2015
1 parent 0901e5b commit ef52da7
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions components/script/dom/htmlfontelement.rs
Expand Up @@ -3,33 +3,30 @@
* 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<Option<RGBA>>,
}


impl HTMLFontElement {
fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: &Document) -> HTMLFontElement {
HTMLFontElement {
htmlelement: HTMLElement::new_inherited(localName, prefix, document),
color: Cell::new(None),
}
}

Expand All @@ -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);
Expand All @@ -71,21 +68,10 @@ impl VirtualMethods for HTMLFontElement {
Some(self.upcast::<HTMLElement>() 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)
Expand All @@ -97,8 +83,14 @@ impl VirtualMethods for HTMLFontElement {


impl HTMLFontElement {
#[allow(unsafe_code)]
pub fn get_color(&self) -> Option<RGBA> {
self.color.get()
unsafe {
self.upcast::<Element>()
.get_attr_for_layout(&ns!(""), &atom!("color"))
.and_then(AttrValue::as_color)
.cloned()
}
}

#[allow(unsafe_code)]
Expand Down

0 comments on commit ef52da7

Please sign in to comment.