Auto merge of #5857 - Ms2ger:preshints, r=pcwalton

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/5857)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-04-28 03:24:14 -05:00
commit 1cb012fc50
6 changed files with 115 additions and 108 deletions

View file

@ -10,14 +10,12 @@ use std::sync::Arc;
use selectors::tree::{TElement, TNode};
use selectors::matching::DeclarationBlock;
use node::TElementAttributes;
use values::specified::CSSColor;
use values::{CSSFloat, specified};
use properties::DeclaredValue::SpecifiedValue;
use properties::PropertyDeclaration;
use properties::longhands::{self, border_spacing};
use selector_matching::Stylist;
use cssparser::Color;
use selectors::smallvec::VecLike;
use util::geometry::Au;
use util::str::LengthOrPercentageOrAuto;
@ -49,13 +47,6 @@ pub enum UnsignedIntegerAttribute {
ColSpan,
}
/// Legacy presentational attributes that take a simple color as defined in HTML5 § 2.4.6.
#[derive(Copy, PartialEq, Eq)]
pub enum SimpleColorAttribute {
/// `<body bgcolor>`
BgColor,
}
/// Extension methods for `Stylist` that cause rules to be synthesized for legacy attributes.
pub trait PresentationalHintSynthesis {
/// Synthesizes rules from various HTML attributes (mostly legacy junk from HTML4) that confer
@ -74,18 +65,6 @@ pub trait PresentationalHintSynthesis {
where N: TNode<'a>,
N::Element: TElementAttributes,
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
/// Synthesizes rules for the legacy `bgcolor` attribute.
fn synthesize_presentational_hint_for_legacy_background_color_attribute<'a,E,V>(
&self,
element: E,
matching_rules_list:
&mut V,
shareable: &mut bool)
where
E: TElement<'a> +
TElementAttributes,
V: VecLike<
DeclarationBlock<Vec<PropertyDeclaration>>>;
/// Synthesizes rules for the legacy `border` attribute.
fn synthesize_presentational_hint_for_legacy_border_attribute<'a,E,V>(
&self,
@ -108,6 +87,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) {
@ -125,20 +112,12 @@ impl PresentationalHintSynthesis for Stylist {
*shareable = false
}
}
self.synthesize_presentational_hint_for_legacy_background_color_attribute(
element,
matching_rules_list,
shareable);
self.synthesize_presentational_hint_for_legacy_border_attribute(
element,
matching_rules_list,
shareable);
}
name if *name == atom!("table") => {
self.synthesize_presentational_hint_for_legacy_background_color_attribute(
element,
matching_rules_list,
shareable);
self.synthesize_presentational_hint_for_legacy_border_attribute(
element,
matching_rules_list,
@ -159,13 +138,6 @@ impl PresentationalHintSynthesis for Stylist {
}
}
}
name if *name == atom!("body") || *name == atom!("tr") || *name == atom!("thead") ||
*name == atom!("tbody") || *name == atom!("tfoot") => {
self.synthesize_presentational_hint_for_legacy_background_color_attribute(
element,
matching_rules_list,
shareable);
}
name if *name == atom!("input") => {
// FIXME(pcwalton): More use of atoms, please!
match element.get_attr(&ns!(""), &atom!("type")) {
@ -220,28 +192,6 @@ impl PresentationalHintSynthesis for Stylist {
}
}
fn synthesize_presentational_hint_for_legacy_background_color_attribute<'a,E,V>(
&self,
element: E,
matching_rules_list:
&mut V,
shareable: &mut bool)
where
E: TElement<'a> +
TElementAttributes,
V: VecLike<
DeclarationBlock<Vec<PropertyDeclaration>>> {
match element.get_simple_color_attribute(SimpleColorAttribute::BgColor) {
None => {}
Some(color) => {
matching_rules_list.vec_push(from_declaration(
PropertyDeclaration::BackgroundColor(SpecifiedValue(
CSSColor { parsed: Color::RGBA(color), authored: None }))));
*shareable = false
}
}
}
fn synthesize_presentational_hint_for_legacy_border_attribute<'a,E,V>(
&self,
element: E,

View file

@ -5,15 +5,18 @@
//! Traits that nodes must implement. Breaks the otherwise-cyclic dependency between layout and
//! style.
use cssparser::RGBA;
use legacy::{IntegerAttribute, LengthAttribute, SimpleColorAttribute, UnsignedIntegerAttribute};
use legacy::{IntegerAttribute, LengthAttribute, 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>;
fn get_simple_color_attribute(self, attribute: SimpleColorAttribute) -> Option<RGBA>;
}