Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start precomputing presentational hints. #6311

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

Move the parsed value of font color into the attribute.

  • Loading branch information
Ms2ger committed Jun 22, 2015
commit 80a18bfb9a437634f5e0e8a3b45e33b4af470d62
@@ -17,7 +17,7 @@ use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementM
use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods;
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use dom::bindings::codegen::InheritTypes::{ElementCast, ElementDerived, EventTargetCast};
use dom::bindings::codegen::InheritTypes::{HTMLBodyElementDerived, HTMLFontElementDerived};
use dom::bindings::codegen::InheritTypes::HTMLBodyElementDerived;
use dom::bindings::codegen::InheritTypes::{HTMLIFrameElementDerived, HTMLInputElementCast};
use dom::bindings::codegen::InheritTypes::{HTMLInputElementDerived, HTMLTableElementCast};
use dom::bindings::codegen::InheritTypes::{HTMLTableElementDerived, HTMLTableCellElementDerived};
@@ -44,7 +44,6 @@ use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlbodyelement::{HTMLBodyElement, HTMLBodyElementHelpers};
use dom::htmlcollection::HTMLCollection;
use dom::htmlelement::HTMLElementTypeId;
use dom::htmlfontelement::{HTMLFontElement, HTMLFontElementHelpers};
use dom::htmliframeelement::{HTMLIFrameElement, RawHTMLIFrameElementHelpers};
use dom::htmlinputelement::{HTMLInputElement, RawLayoutHTMLInputElementHelpers, HTMLInputElementHelpers};
use dom::htmltableelement::{HTMLTableElement, HTMLTableElementHelpers};
@@ -66,7 +65,7 @@ use style::properties::{PropertyDeclarationBlock, PropertyDeclaration, parse_sty
use style::properties::DeclaredValue::SpecifiedValue;
use style::properties::longhands::{self, border_spacing, height};
use style::values::CSSFloat;
use style::values::specified::{self, CSSColor, CSSRGBA};
use style::values::specified::{self, CSSColor};
use util::geometry::Au;
use util::namespace;
use util::str::{DOMString, LengthOrPercentageOrAuto};
@@ -287,21 +286,6 @@ impl RawLayoutElementHelpers for Element {
CSSColor { parsed: Color::RGBA(color), authored: None }))));
}

let color = if self.is_htmlfontelement() {
let this: &HTMLFontElement = mem::transmute(self);
this.get_color()
} else {
None
};

if let Some(color) = color {
hints.push(from_declaration(
PropertyDeclaration::Color(SpecifiedValue(CSSRGBA {
parsed: color,
authored: None,
}))));
}

let cellspacing = if self.is_htmltableelement() {
let this: &HTMLTableElement = mem::transmute(self);
this.get_cellspacing()
@@ -13,15 +13,15 @@ use dom::element::ElementTypeId;
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::node::{Node, NodeTypeId};
use dom::virtualmethods::VirtualMethods;
use util::str::{self, DOMString};

use cssparser::RGBA;
use std::cell::Cell;
use style::properties::DeclaredValue::SpecifiedValue;
use style::properties::PropertyDeclaration;
use style::values::specified::CSSRGBA;
use util::str::{self, DOMString};

#[dom_struct]
pub struct HTMLFontElement {
htmlelement: HTMLElement,
color: Cell<Option<RGBA>>,
}

impl HTMLFontElementDerived for EventTarget {
@@ -36,7 +36,6 @@ impl HTMLFontElement {
fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: &Document) -> HTMLFontElement {
HTMLFontElement {
htmlelement: HTMLElement::new_inherited(HTMLElementTypeId::HTMLFontElement, localName, prefix, document),
color: Cell::new(None),
}
}

@@ -60,38 +59,21 @@ impl<'a> VirtualMethods for &'a HTMLFontElement {
Some(htmlelement as &VirtualMethods)
}

fn after_set_attr(&self, attr: &Attr) {
if let Some(ref s) = self.super_type() {
s.after_set_attr(attr);
}
fn presentational_hints(&self, attribute: &Attr) -> Vec<PropertyDeclaration> {
let mut hints = self.super_type().unwrap().presentational_hints(attribute);

match attr.local_name() {
match attribute.local_name() {
&atom!("color") => {
self.color.set(str::parse_legacy_color(&attr.value()).ok())
}
_ => {}
if let Ok(color) = str::parse_legacy_color(&attribute.value()) {
hints.push(PropertyDeclaration::Color(SpecifiedValue(CSSRGBA {
parsed: color,
authored: None,
})));
}
},
_ => (),
}
}

fn before_remove_attr(&self, attr: &Attr) {
if let Some(ref s) = self.super_type() {
s.before_remove_attr(attr);
}

match attr.local_name() {
&atom!("color") => self.color.set(None),
_ => ()
}
hints
}
}

pub trait HTMLFontElementHelpers {
fn get_color(&self) -> Option<RGBA>;
}

impl HTMLFontElementHelpers for HTMLFontElement {
fn get_color(&self) -> Option<RGBA> {
self.color.get()
}
}

@@ -82,8 +82,8 @@ pub trait VirtualMethods {
}
}

/// ...
fn presentational_hints(&self, attribute: JSRef<Attr>) -> Vec<PropertyDeclaration> {
/// Returns a `Vec` of presentational hints generated by `attribute`.
fn presentational_hints(&self, attribute: &Attr) -> Vec<PropertyDeclaration> {
match self.super_type() {
Some(ref s) => s.presentational_hints(attribute),
_ => Vec::new(),
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.