mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
script: Implement the color
attribute of the <font>
element.
Improves Hacker News.
This commit is contained in:
parent
c981e9b2e3
commit
7d9eda916b
9 changed files with 105 additions and 143 deletions
|
@ -2,19 +2,26 @@
|
|||
* 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, AttrHelpers};
|
||||
use dom::bindings::codegen::Bindings::HTMLFontElementBinding;
|
||||
use dom::bindings::codegen::InheritTypes::HTMLFontElementDerived;
|
||||
use dom::bindings::codegen::Bindings::HTMLFontElementBinding::HTMLFontElementMethods;
|
||||
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLFontElementDerived};
|
||||
use dom::bindings::js::{JSRef, Temporary};
|
||||
use dom::document::Document;
|
||||
use dom::eventtarget::{EventTarget, EventTargetTypeId};
|
||||
use dom::element::ElementTypeId;
|
||||
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
|
||||
use dom::node::{Node, NodeTypeId};
|
||||
use util::str::DOMString;
|
||||
use dom::virtualmethods::VirtualMethods;
|
||||
use util::str::{self, DOMString};
|
||||
|
||||
use cssparser::RGBA;
|
||||
use std::cell::Cell;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct HTMLFontElement {
|
||||
htmlelement: HTMLElement
|
||||
htmlelement: HTMLElement,
|
||||
color: Cell<Option<RGBA>>,
|
||||
}
|
||||
|
||||
impl HTMLFontElementDerived for EventTarget {
|
||||
|
@ -26,7 +33,8 @@ impl HTMLFontElementDerived for EventTarget {
|
|||
impl HTMLFontElement {
|
||||
fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> HTMLFontElement {
|
||||
HTMLFontElement {
|
||||
htmlelement: HTMLElement::new_inherited(HTMLElementTypeId::HTMLFontElement, localName, prefix, document)
|
||||
htmlelement: HTMLElement::new_inherited(HTMLElementTypeId::HTMLFontElement, localName, prefix, document),
|
||||
color: Cell::new(None),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,3 +45,49 @@ impl HTMLFontElement {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> HTMLFontElementMethods for JSRef<'a, HTMLFontElement> {
|
||||
make_getter!(Color, "color");
|
||||
make_setter!(SetColor, "color");
|
||||
}
|
||||
|
||||
impl<'a> VirtualMethods for JSRef<'a,HTMLFontElement> {
|
||||
fn super_type<'b>(&'b self) -> Option<&'b VirtualMethods> {
|
||||
let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_borrowed_ref(self);
|
||||
Some(htmlelement as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn after_set_attr(&self, attr: JSRef<Attr>) {
|
||||
if let Some(ref s) = self.super_type() {
|
||||
s.after_set_attr(attr);
|
||||
}
|
||||
|
||||
match attr.local_name() {
|
||||
&atom!("color") => {
|
||||
self.color.set(str::parse_legacy_color(&attr.value()).ok())
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn before_remove_attr(&self, attr: JSRef<Attr>) {
|
||||
if let Some(ref s) = self.super_type() {
|
||||
s.before_remove_attr(attr);
|
||||
}
|
||||
|
||||
match attr.local_name() {
|
||||
&atom!("color") => self.color.set(None),
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait HTMLFontElementHelpers {
|
||||
fn get_color(&self) -> Option<RGBA>;
|
||||
}
|
||||
|
||||
impl HTMLFontElementHelpers for HTMLFontElement {
|
||||
fn get_color(&self) -> Option<RGBA> {
|
||||
self.color.get()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue