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

Create a new infrastructure for presentational hints. #5857

Merged
merged 5 commits into from Apr 28, 2015
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Create a new infrastructure for presentational hints.

  • Loading branch information
Ms2ger committed Apr 26, 2015
commit 582ee1c2b3eced29a942ac692943a8b8a093e46f
@@ -27,7 +27,7 @@ use std::slice::Iter;
use std::sync::Arc;
use std::sync::mpsc::Sender;
use string_cache::{Atom, Namespace};
use style::node::{TElement, TNode};
use style::node::{TElement, TElementAttributes, TNode};
use style::properties::{ComputedValues, cascade};
use style::selector_matching::{Stylist, DeclarationBlock};
use util::arc_ptr_eq;
@@ -289,6 +289,12 @@ impl StyleSharingCandidate {
return false
}

let mut matching_rules = vec![];
element.synthesize_presentational_hints_for_legacy_attributes(&mut matching_rules);
if !matching_rules.is_empty() {
return false;
}

This comment has been minimized.

@pcwalton

pcwalton Apr 27, 2015

Contributor

This is probably going to be too slow. can_share_style_with is called zillions of times. Can you avoid creating the vector?


// FIXME(pcwalton): It's probably faster to iterate over all the element's attributes and
// use the {common, rare}-style-affecting-attributes tables as lookup tables.

@@ -70,11 +70,13 @@ use std::sync::mpsc::Sender;
use string_cache::{Atom, Namespace};
use style::computed_values::content::ContentItem;
use style::computed_values::{content, display, white_space};
use selectors::matching::DeclarationBlock;
use selectors::parser::{NamespaceConstraint, AttrSelector};
use selectors::smallvec::VecLike;
use style::legacy::{IntegerAttribute, LengthAttribute, SimpleColorAttribute};
use style::legacy::{UnsignedIntegerAttribute};
use style::node::{TElement, TElementAttributes, TNode};
use style::properties::PropertyDeclarationBlock;
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock};
use url::Url;

/// Allows some convenience methods on generic layout nodes.
@@ -659,6 +661,14 @@ impl<'le> TElement<'le> for LayoutElement<'le> {
}

impl<'le> TElementAttributes for LayoutElement<'le> {
fn synthesize_presentational_hints_for_legacy_attributes<V>(self, hints: &mut V)
where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>
{
unsafe {
self.element.synthesize_presentational_hints_for_legacy_attributes(hints);
}
}

fn get_length_attribute(self, length_attribute: LengthAttribute) -> LengthOrPercentageOrAuto {
unsafe {
self.element.get_length_attribute_for_layout(length_attribute)
@@ -68,8 +68,9 @@ use html5ever::serialize::SerializeOpts;
use html5ever::serialize::TraversalScope;
use html5ever::serialize::TraversalScope::{IncludeNode, ChildrenOnly};
use html5ever::tree_builder::{NoQuirks, LimitedQuirks, Quirks};
use selectors::matching::matches;
use selectors::matching::{matches, DeclarationBlock};
use selectors::parser::parse_author_origin_selector_list_from_str;
use selectors::smallvec::VecLike;
use string_cache::{Atom, Namespace, QualName};
use url::UrlParser;

@@ -155,6 +156,9 @@ pub trait RawLayoutElementHelpers {
unsafe fn get_attr_atom_for_layout(&self, namespace: &Namespace, name: &Atom) -> Option<Atom>;
unsafe fn has_class_for_layout(&self, name: &Atom) -> bool;
unsafe fn get_classes_for_layout(&self) -> Option<&'static [Atom]>;

unsafe fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, &mut V)
where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
unsafe fn get_length_attribute_for_layout(&self, length_attribute: LengthAttribute)
-> LengthOrPercentageOrAuto;
unsafe fn get_integer_attribute_for_layout(&self, integer_attribute: IntegerAttribute)
@@ -227,6 +231,11 @@ impl RawLayoutElementHelpers for Element {
})
}

unsafe fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, _: &mut V)
where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>
{
}

#[inline]
unsafe fn get_length_attribute_for_layout(&self, length_attribute: LengthAttribute)
-> LengthOrPercentageOrAuto {
@@ -108,6 +108,14 @@ impl PresentationalHintSynthesis for Stylist {
N::Element: TElementAttributes,
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>> {
let element = node.as_element();

let length = matching_rules_list.vec_len();
element.synthesize_presentational_hints_for_legacy_attributes(matching_rules_list);
if matching_rules_list.vec_len() != length {
// Never share style for elements with preshints
*shareable = false;
}

match element.get_local_name() {
name if *name == atom!("td") => {
match element.get_length_attribute(LengthAttribute::Width) {
@@ -7,11 +7,16 @@

use cssparser::RGBA;
use legacy::{IntegerAttribute, LengthAttribute, SimpleColorAttribute, UnsignedIntegerAttribute};
use properties::PropertyDeclaration;
use util::str::LengthOrPercentageOrAuto;

use selectors::matching::DeclarationBlock;
use selectors::smallvec::VecLike;
pub use selectors::tree::{TNode, TElement};

pub trait TElementAttributes : Copy {
fn synthesize_presentational_hints_for_legacy_attributes<V>(self, &mut V)
where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
fn get_length_attribute(self, attribute: LengthAttribute) -> LengthOrPercentageOrAuto;
fn get_integer_attribute(self, attribute: IntegerAttribute) -> Option<i32>;
fn get_unsigned_integer_attribute(self, attribute: UnsignedIntegerAttribute) -> Option<u32>;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.