Move table/td width to the new infrastructure.

This commit is contained in:
Ms2ger 2015-05-08 21:24:31 +02:00
parent 0c8e55bff1
commit f571a69b2e
4 changed files with 26 additions and 79 deletions

View file

@ -18,14 +18,6 @@ use selector_matching::Stylist;
use util::geometry::Au;
use util::smallvec::VecLike;
use util::str::LengthOrPercentageOrAuto;
/// Legacy presentational attributes that take a length as defined in HTML5 § 2.4.4.4.
#[derive(Copy, Clone, PartialEq, Eq)]
pub enum LengthAttribute {
/// `<td width>`
Width,
}
/// Legacy presentational attributes that take an integer as defined in HTML5 § 2.4.4.2.
#[derive(Copy, Clone, PartialEq, Eq)]
@ -71,14 +63,6 @@ pub trait PresentationalHintSynthesis {
E: TElement<'a> +
TElementAttributes<'a>,
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
/// Synthesizes rules for the legacy `width` attribute.
fn synthesize_presentational_hint_for_legacy_width_attribute<'a,E,V>(
&self,
element: E,
matching_rules_list: &mut V,
shareable: &mut bool)
where E: TElement<'a> + TElementAttributes<'a>,
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
}
impl PresentationalHintSynthesis for Stylist {
@ -101,20 +85,12 @@ impl PresentationalHintSynthesis for Stylist {
match element.get_local_name() {
name if *name == atom!("td") => {
self.synthesize_presentational_hint_for_legacy_width_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_width_attribute(
element,
matching_rules_list,
shareable);
self.synthesize_presentational_hint_for_legacy_border_attribute(
element,
matching_rules_list,
@ -184,31 +160,6 @@ impl PresentationalHintSynthesis for Stylist {
}
}
}
fn synthesize_presentational_hint_for_legacy_width_attribute<'a,E,V>(
&self,
element: E,
matching_rules_list: &mut V,
shareable: &mut bool)
where E: TElement<'a> + TElementAttributes<'a>,
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>> {
match element.get_length_attribute(LengthAttribute::Width) {
LengthOrPercentageOrAuto::Auto => {}
LengthOrPercentageOrAuto::Percentage(percentage) => {
let width_value = specified::LengthOrPercentageOrAuto::Percentage(percentage);
matching_rules_list.push(from_declaration(
PropertyDeclaration::Width(SpecifiedValue(width_value))));
*shareable = false
}
LengthOrPercentageOrAuto::Length(length) => {
let width_value = specified::LengthOrPercentageOrAuto::Length(
specified::Length::Absolute(length));
matching_rules_list.push(from_declaration(
PropertyDeclaration::Width(SpecifiedValue(width_value))));
*shareable = false
}
}
}
}

View file

@ -5,10 +5,9 @@
//! Traits that nodes must implement. Breaks the otherwise-cyclic dependency between layout and
//! style.
use legacy::{IntegerAttribute, LengthAttribute, UnsignedIntegerAttribute};
use legacy::{IntegerAttribute, UnsignedIntegerAttribute};
use properties::PropertyDeclaration;
use util::smallvec::VecLike;
use util::str::LengthOrPercentageOrAuto;
use selectors::matching::DeclarationBlock;
pub use selectors::tree::{TNode, TElement};
@ -17,7 +16,6 @@ use string_cache::{Atom, Namespace};
pub trait TElementAttributes<'a> : 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>;