mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Move table/td width to the new infrastructure.
This commit is contained in:
parent
0c8e55bff1
commit
f571a69b2e
4 changed files with 26 additions and 79 deletions
|
@ -60,7 +60,7 @@ use script::dom::node::{HAS_CHANGED, IS_DIRTY, HAS_DIRTY_SIBLINGS, HAS_DIRTY_DES
|
|||
use script::dom::text::Text;
|
||||
use script::layout_interface::LayoutChan;
|
||||
use msg::constellation_msg::{PipelineId, SubpageId};
|
||||
use util::str::{LengthOrPercentageOrAuto, is_whitespace};
|
||||
use util::str::is_whitespace;
|
||||
use std::borrow::ToOwned;
|
||||
use std::cell::{Ref, RefMut};
|
||||
use std::marker::PhantomData;
|
||||
|
@ -71,8 +71,7 @@ use style::computed_values::content::ContentItem;
|
|||
use style::computed_values::{content, display, white_space};
|
||||
use selectors::matching::DeclarationBlock;
|
||||
use selectors::parser::{NamespaceConstraint, AttrSelector};
|
||||
use style::legacy::{IntegerAttribute, LengthAttribute};
|
||||
use style::legacy::{UnsignedIntegerAttribute};
|
||||
use style::legacy::{IntegerAttribute, UnsignedIntegerAttribute};
|
||||
use style::node::{TElement, TElementAttributes, TNode};
|
||||
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock};
|
||||
use util::smallvec::VecLike;
|
||||
|
@ -657,12 +656,6 @@ impl<'le> TElementAttributes<'le> for LayoutElement<'le> {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_length_attribute(self, length_attribute: LengthAttribute) -> LengthOrPercentageOrAuto {
|
||||
unsafe {
|
||||
self.element.get_length_attribute_for_layout(length_attribute)
|
||||
}
|
||||
}
|
||||
|
||||
fn get_integer_attribute(self, integer_attribute: IntegerAttribute) -> Option<i32> {
|
||||
unsafe {
|
||||
self.element.get_integer_attribute_for_layout(integer_attribute)
|
||||
|
|
|
@ -59,7 +59,7 @@ use dom::virtualmethods::{VirtualMethods, vtable_for};
|
|||
|
||||
use devtools_traits::AttrInfo;
|
||||
use style;
|
||||
use style::legacy::{UnsignedIntegerAttribute, IntegerAttribute, LengthAttribute, from_declaration};
|
||||
use style::legacy::{UnsignedIntegerAttribute, IntegerAttribute, from_declaration};
|
||||
use style::properties::{PropertyDeclarationBlock, PropertyDeclaration, parse_style_attribute};
|
||||
use style::properties::DeclaredValue::SpecifiedValue;
|
||||
use style::properties::longhands::border_spacing;
|
||||
|
@ -164,8 +164,6 @@ pub trait RawLayoutElementHelpers {
|
|||
|
||||
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)
|
||||
-> Option<i32>;
|
||||
unsafe fn get_checked_state_for_layout(&self) -> bool;
|
||||
|
@ -307,22 +305,29 @@ impl RawLayoutElementHelpers for Element {
|
|||
PropertyDeclaration::Width(SpecifiedValue(
|
||||
specified::LengthOrPercentageOrAuto::Length(value)))));
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn get_length_attribute_for_layout(&self, length_attribute: LengthAttribute)
|
||||
-> LengthOrPercentageOrAuto {
|
||||
match length_attribute {
|
||||
LengthAttribute::Width => {
|
||||
if self.is_htmltableelement() {
|
||||
let this: &HTMLTableElement = mem::transmute(self);
|
||||
this.get_width()
|
||||
} else if self.is_htmltablecellelement() {
|
||||
let this: &HTMLTableCellElement = mem::transmute(self);
|
||||
this.get_width()
|
||||
} else {
|
||||
panic!("I'm not a table or table cell!")
|
||||
}
|
||||
|
||||
let width = if self.is_htmltableelement() {
|
||||
let this: &HTMLTableElement = mem::transmute(self);
|
||||
this.get_width()
|
||||
} else if self.is_htmltabledatacellelement() {
|
||||
let this: &HTMLTableCellElement = mem::transmute(self);
|
||||
this.get_width()
|
||||
} else {
|
||||
LengthOrPercentageOrAuto::Auto
|
||||
};
|
||||
|
||||
match width {
|
||||
LengthOrPercentageOrAuto::Auto => {}
|
||||
LengthOrPercentageOrAuto::Percentage(percentage) => {
|
||||
let width_value = specified::LengthOrPercentageOrAuto::Percentage(percentage);
|
||||
hints.push(from_declaration(
|
||||
PropertyDeclaration::Width(SpecifiedValue(width_value))));
|
||||
}
|
||||
LengthOrPercentageOrAuto::Length(length) => {
|
||||
let width_value = specified::LengthOrPercentageOrAuto::Length(specified::Length::Absolute(length));
|
||||
hints.push(from_declaration(
|
||||
PropertyDeclaration::Width(SpecifiedValue(width_value))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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>;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue