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

Move some presentational hints to the new infrastructure. #5988

Merged
merged 4 commits into from May 12, 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

Move table/td width to the new infrastructure.

  • Loading branch information
Ms2ger committed May 12, 2015
commit f571a69b2e02535cf240700463181b9221a56c25
@@ -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>;

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.