mirror of
https://github.com/servo/servo.git
synced 2025-08-02 04:00:32 +01:00
style: Parse the legacy bgcolor
attribute per the HTML5 specification.
Additionally, this patch cleans up some miscellaneous formatting issues.
This commit is contained in:
parent
10f1ed5e31
commit
14bafb11be
19 changed files with 370 additions and 36 deletions
|
@ -2,11 +2,9 @@
|
|||
* 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;
|
||||
use dom::attr::AttrHelpers;
|
||||
use dom::attr::{Attr, AttrHelpers};
|
||||
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
||||
use dom::bindings::codegen::Bindings::HTMLBodyElementBinding;
|
||||
use dom::bindings::codegen::Bindings::HTMLBodyElementBinding::HTMLBodyElementMethods;
|
||||
use dom::bindings::codegen::Bindings::HTMLBodyElementBinding::{mod, HTMLBodyElementMethods};
|
||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||
use dom::bindings::codegen::InheritTypes::EventTargetCast;
|
||||
use dom::bindings::codegen::InheritTypes::{HTMLBodyElementDerived, HTMLElementCast};
|
||||
|
@ -19,11 +17,13 @@ use dom::htmlelement::HTMLElement;
|
|||
use dom::node::{Node, ElementNodeTypeId, window_from_node};
|
||||
use dom::virtualmethods::VirtualMethods;
|
||||
|
||||
use servo_util::str::DOMString;
|
||||
use servo_util::str::{mod, DOMString, SimpleColor};
|
||||
use std::cell::Cell;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct HTMLBodyElement {
|
||||
htmlelement: HTMLElement
|
||||
htmlelement: HTMLElement,
|
||||
background_color: Cell<Option<SimpleColor>>,
|
||||
}
|
||||
|
||||
impl HTMLBodyElementDerived for EventTarget {
|
||||
|
@ -33,14 +33,20 @@ impl HTMLBodyElementDerived for EventTarget {
|
|||
}
|
||||
|
||||
impl HTMLBodyElement {
|
||||
fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> HTMLBodyElement {
|
||||
fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>)
|
||||
-> HTMLBodyElement {
|
||||
HTMLBodyElement {
|
||||
htmlelement: HTMLElement::new_inherited(HTMLBodyElementTypeId, localName, prefix, document)
|
||||
htmlelement: HTMLElement::new_inherited(HTMLBodyElementTypeId,
|
||||
localName,
|
||||
prefix,
|
||||
document),
|
||||
background_color: Cell::new(None),
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn new(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> Temporary<HTMLBodyElement> {
|
||||
pub fn new(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>)
|
||||
-> Temporary<HTMLBodyElement> {
|
||||
let element = HTMLBodyElement::new_inherited(localName, prefix, document);
|
||||
Node::reflect_node(box element, document, HTMLBodyElementBinding::Wrap)
|
||||
}
|
||||
|
@ -58,6 +64,16 @@ impl<'a> HTMLBodyElementMethods for JSRef<'a, HTMLBodyElement> {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait HTMLBodyElementHelpers {
|
||||
fn get_background_color(&self) -> Option<SimpleColor>;
|
||||
}
|
||||
|
||||
impl HTMLBodyElementHelpers for HTMLBodyElement {
|
||||
fn get_background_color(&self) -> Option<SimpleColor> {
|
||||
self.background_color.get()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> VirtualMethods for JSRef<'a, HTMLBodyElement> {
|
||||
fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods> {
|
||||
let element: &JSRef<HTMLElement> = HTMLElementCast::from_borrowed_ref(self);
|
||||
|
@ -91,6 +107,25 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLBodyElement> {
|
|||
name.slice_from(2),
|
||||
attr.value().as_slice().to_string());
|
||||
}
|
||||
|
||||
match attr.local_name() {
|
||||
&atom!("bgcolor") => {
|
||||
self.background_color.set(str::parse_legacy_color(attr.value().as_slice()).ok())
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn before_remove_attr(&self, attr: JSRef<Attr>) {
|
||||
match self.super_type() {
|
||||
Some(ref s) => s.before_remove_attr(attr),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
match attr.local_name() {
|
||||
&atom!("bgcolor") => self.background_color.set(None),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue