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

Move bgcolor over to the new infrastructure.

Note that I call is_htmltabledatacellelement in
synthesize_presentational_hints_for_legacy_attributes, rather than
is_htmltablecellelement (which was used in
get_simple_color_attribute_for_layout), because that function was never called
for th elements.
  • Loading branch information
Ms2ger committed Apr 26, 2015
commit e3440c8a593b4b64908f0ca42b5d17c82965a7f4
@@ -39,7 +39,6 @@ use incremental::RestyleDamage;
use data::{LayoutDataAccess, LayoutDataFlags, LayoutDataWrapper, PrivateLayoutData};
use opaque_node::OpaqueNodeMethods;

use cssparser::RGBA;
use gfx::display_list::OpaqueNode;
use script::dom::bindings::codegen::InheritTypes::{CharacterDataCast, ElementCast};
use script::dom::bindings::codegen::InheritTypes::{HTMLIFrameElementCast, HTMLCanvasElementCast};
@@ -73,7 +72,7 @@ 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::{IntegerAttribute, LengthAttribute};
use style::legacy::{UnsignedIntegerAttribute};
use style::node::{TElement, TElementAttributes, TNode};
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock};
@@ -686,12 +685,6 @@ impl<'le> TElementAttributes for LayoutElement<'le> {
self.element.get_unsigned_integer_attribute_for_layout(attribute)
}
}

fn get_simple_color_attribute(self, attribute: SimpleColorAttribute) -> Option<RGBA> {
unsafe {
self.element.get_simple_color_attribute_for_layout(attribute)
}
}
}

fn get_content(content_list: &content::T) -> Vec<ContentItem> {
@@ -23,6 +23,7 @@ use dom::bindings::codegen::InheritTypes::{HTMLTableElementDerived, HTMLTableCel
use dom::bindings::codegen::InheritTypes::{HTMLTableRowElementDerived, HTMLTextAreaElementDerived};
use dom::bindings::codegen::InheritTypes::{HTMLTableSectionElementDerived, NodeCast};
use dom::bindings::codegen::InheritTypes::HTMLAnchorElementCast;
use dom::bindings::codegen::InheritTypes::HTMLTableDataCellElementDerived;
use dom::bindings::codegen::UnionTypes::NodeOrString;
use dom::bindings::error::{ErrorResult, Fallible};
use dom::bindings::error::Error::{InvalidCharacter, Syntax};
@@ -57,12 +58,14 @@ use dom::virtualmethods::{VirtualMethods, vtable_for};

use devtools_traits::AttrInfo;
use style;
use style::legacy::{SimpleColorAttribute, UnsignedIntegerAttribute, IntegerAttribute, LengthAttribute};
use style::legacy::{UnsignedIntegerAttribute, IntegerAttribute, LengthAttribute, from_declaration};
use style::properties::{PropertyDeclarationBlock, PropertyDeclaration, parse_style_attribute};
use style::properties::DeclaredValue::SpecifiedValue;
use style::values::specified::CSSColor;
use util::namespace;
use util::str::{DOMString, LengthOrPercentageOrAuto};

use cssparser::RGBA;
use cssparser::Color;
use html5ever::serialize;
use html5ever::serialize::SerializeOpts;
use html5ever::serialize::TraversalScope;
@@ -167,8 +170,7 @@ pub trait RawLayoutElementHelpers {
unsafe fn get_indeterminate_state_for_layout(&self) -> bool;
unsafe fn get_unsigned_integer_attribute_for_layout(&self, attribute: UnsignedIntegerAttribute)
-> Option<u32>;
unsafe fn get_simple_color_attribute_for_layout(&self, attribute: SimpleColorAttribute)
-> Option<RGBA>;

fn local_name<'a>(&'a self) -> &'a Atom;
fn namespace<'a>(&'a self) -> &'a Namespace;
fn style_attribute<'a>(&'a self) -> &'a DOMRefCell<Option<PropertyDeclarationBlock>>;
@@ -231,9 +233,33 @@ impl RawLayoutElementHelpers for Element {
})
}

unsafe fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, _: &mut V)
unsafe fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, hints: &mut V)
where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>
{
let bgcolor = if self.is_htmlbodyelement() {
let this: &HTMLBodyElement = mem::transmute(self);
this.get_background_color()
} else if self.is_htmltableelement() {
let this: &HTMLTableElement = mem::transmute(self);
this.get_background_color()
} else if self.is_htmltabledatacellelement() {
let this: &HTMLTableCellElement = mem::transmute(self);
this.get_background_color()
} else if self.is_htmltablerowelement() {
let this: &HTMLTableRowElement = mem::transmute(self);
this.get_background_color()
} else if self.is_htmltablesectionelement() {
let this: &HTMLTableSectionElement = mem::transmute(self);
this.get_background_color()
} else {
None
};

if let Some(color) = bgcolor {
hints.vec_push(from_declaration(
PropertyDeclaration::BackgroundColor(SpecifiedValue(
CSSColor { parsed: Color::RGBA(color), authored: None }))));
}
}

#[inline]
@@ -342,34 +368,6 @@ impl RawLayoutElementHelpers for Element {
}
}

#[inline]
#[allow(unrooted_must_root)]
unsafe fn get_simple_color_attribute_for_layout(&self, attribute: SimpleColorAttribute)
-> Option<RGBA> {
match attribute {
SimpleColorAttribute::BgColor => {
if self.is_htmlbodyelement() {
let this: &HTMLBodyElement = mem::transmute(self);
this.get_background_color()
} else if self.is_htmltableelement() {
let this: &HTMLTableElement = mem::transmute(self);
this.get_background_color()
} else if self.is_htmltablecellelement() {
let this: &HTMLTableCellElement = mem::transmute(self);
this.get_background_color()
} else if self.is_htmltablerowelement() {
let this: &HTMLTableRowElement = mem::transmute(self);
this.get_background_color()
} else if self.is_htmltablesectionelement() {
let this: &HTMLTableSectionElement = mem::transmute(self);
this.get_background_color()
} else {
None
}
}
}
}

// Getters used in components/layout/wrapper.rs

fn local_name<'a>(&'a self) -> &'a Atom {
@@ -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,
@@ -133,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,
@@ -167,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")) {
@@ -228,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,
@@ -5,8 +5,7 @@
//! 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;

@@ -20,5 +19,4 @@ pub trait TElementAttributes : Copy {
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>;
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.