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 all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -17,6 +17,7 @@ use devtools_traits::AttrInfo;
use util::str::{DOMString, parse_unsigned_integer, split_html_space_chars};

use string_cache::{Atom, Namespace};
use style::properties::PropertyDeclaration;

use std::borrow::ToOwned;
use std::cell::Ref;
@@ -120,6 +121,8 @@ pub struct Attr {

/// the element that owns this attribute.
owner: MutNullableHeap<JS<Element>>,

presentational_hints: DOMRefCell<Vec<PropertyDeclaration>>,
}

impl Attr {
@@ -133,6 +136,7 @@ impl Attr {
namespace: namespace,
prefix: prefix,
owner: MutNullableHeap::new(owner.map(JS::from_ref)),
presentational_hints: DOMRefCell::new(Vec::new()),
}
}

@@ -258,6 +262,7 @@ impl<'a> AttrHelpers<'a> for &'a Attr {
*self.value.borrow_mut() = value;

if namespace_is_null {
*self.presentational_hints.borrow_mut() = vtable_for(&node).presentational_hints(self);
vtable_for(&node).after_set_attr(self)
}
}
@@ -310,6 +315,7 @@ pub trait AttrHelpersForLayout {
unsafe fn value_tokens_forever(&self) -> Option<&'static [Atom]>;
unsafe fn local_name_atom_forever(&self) -> Atom;
unsafe fn value_for_layout(&self) -> &AttrValue;
fn presentational_hints(&self) -> &[PropertyDeclaration];
}

#[allow(unsafe_code)]
@@ -352,4 +358,11 @@ impl AttrHelpersForLayout for LayoutJS<Attr> {
unsafe fn value_for_layout(&self) -> &AttrValue {
(*self.unsafe_get()).value.borrow_for_layout()
}

#[inline]
fn presentational_hints(&self) -> &[PropertyDeclaration] {
unsafe {
(*self.unsafe_get()).presentational_hints.borrow_for_layout()
}
}
}
@@ -71,7 +71,7 @@ use std::rc::Rc;
use std::sync::Arc;
use std::sync::mpsc::{Receiver, Sender};
use string_cache::{Atom, Namespace};
use style::properties::PropertyDeclarationBlock;
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock};
use url::Url;


@@ -277,6 +277,7 @@ no_jsmanaged_fields!(Arc<T>);
no_jsmanaged_fields!(Image, ImageCacheChan, ImageCacheTask, ScriptControlChan);
no_jsmanaged_fields!(Atom, Namespace);
no_jsmanaged_fields!(Trusted<T>);
no_jsmanaged_fields!(PropertyDeclaration);
no_jsmanaged_fields!(PropertyDeclarationBlock);
no_jsmanaged_fields!(HashSet<T>);
// These three are interdependent, if you plan to put jsmanaged data
@@ -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};
@@ -255,6 +254,13 @@ impl RawLayoutElementHelpers for Element {
unsafe fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, hints: &mut V)
where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>
{
for attribute in self.attrs.borrow_for_layout().iter() {
let attribute = attribute.to_layout();
for hint in attribute.presentational_hints() {
hints.push(from_declaration(hint.clone()));
}
}

let bgcolor = if self.is_htmlbodyelement() {
let this: &HTMLBodyElement = mem::transmute(self);
this.get_background_color()
@@ -280,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()
}
}

@@ -37,6 +37,7 @@ use dom::event::Event;
use dom::htmlelement::HTMLElementTypeId;
use dom::node::{Node, NodeHelpers, NodeTypeId, CloneChildrenFlag};

use style::properties::PropertyDeclaration;
use util::str::DOMString;

use string_cache::Atom;
@@ -81,6 +82,14 @@ pub trait VirtualMethods {
}
}

/// 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(),
}
}

/// Called when a Node is appended to a tree, where 'tree_in_doc' indicates
/// whether the tree is part of a Document.
fn bind_to_tree(&self, tree_in_doc: bool) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.