aboutsummaryrefslogtreecommitdiffstats
path: root/components/style/legacy.rs
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2014-12-08 09:47:56 -0800
committerPatrick Walton <pcwalton@mimiga.net>2014-12-15 17:41:25 -0800
commite0e14c60d68474a0dec94d2ec71d979a95fbc6a6 (patch)
tree27be7cda35002dbe587106ac221c290c59b5a651 /components/style/legacy.rs
parent112ef5c484e821aa4869aeaf12a12146f2424fe0 (diff)
downloadservo-e0e14c60d68474a0dec94d2ec71d979a95fbc6a6.tar.gz
servo-e0e14c60d68474a0dec94d2ec71d979a95fbc6a6.zip
style: Move presentational hint synthesis into `legacy.rs`.
Diffstat (limited to 'components/style/legacy.rs')
-rw-r--r--components/style/legacy.rs79
1 files changed, 79 insertions, 0 deletions
diff --git a/components/style/legacy.rs b/components/style/legacy.rs
index f99314667b8..4a4e8a428f0 100644
--- a/components/style/legacy.rs
+++ b/components/style/legacy.rs
@@ -5,6 +5,14 @@
//! Legacy presentational attributes defined in the HTML5 specification: `<td width>`,
//! `<input size>`, and so forth.
+use node::{TElement, TElementAttributes, TNode};
+use properties::{SpecifiedValue, WidthDeclaration, specified};
+use selector_matching::{DeclarationBlock, Stylist};
+
+use servo_util::geometry::Au;
+use servo_util::smallvec::VecLike;
+use servo_util::str::{AutoLpa, LengthLpa, PercentageLpa};
+
/// Legacy presentational attributes that take a length as defined in HTML5 § 2.4.4.4.
pub enum LengthAttribute {
/// `<td width>`
@@ -17,3 +25,74 @@ pub enum IntegerAttribute {
SizeIntegerAttribute,
}
+/// 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
+ /// *presentational hints* as defined in the HTML5 specification. This handles stuff like
+ /// `<body bgcolor>`, `<input size>`, `<td width>`, and so forth.
+ fn synthesize_presentational_hints_for_legacy_attributes<'a,E,N,V>(
+ &self,
+ node: &N,
+ matching_rules_list: &mut V,
+ shareable: &mut bool)
+ where E: TElement<'a> +
+ TElementAttributes,
+ N: TNode<'a,E>,
+ V: VecLike<DeclarationBlock>;
+}
+
+impl PresentationalHintSynthesis for Stylist {
+ fn synthesize_presentational_hints_for_legacy_attributes<'a,E,N,V>(
+ &self,
+ node: &N,
+ matching_rules_list: &mut V,
+ shareable: &mut bool)
+ where E: TElement<'a> +
+ TElementAttributes,
+ N: TNode<'a,E>,
+ V: VecLike<DeclarationBlock> {
+ let element = node.as_element();
+ match element.get_local_name() {
+ name if *name == atom!("td") => {
+ match element.get_length_attribute(WidthLengthAttribute) {
+ AutoLpa => {}
+ PercentageLpa(percentage) => {
+ let width_value = specified::LPA_Percentage(percentage);
+ matching_rules_list.vec_push(DeclarationBlock::from_declaration(
+ WidthDeclaration(SpecifiedValue(width_value))));
+ *shareable = false
+ }
+ LengthLpa(length) => {
+ let width_value = specified::LPA_Length(specified::Au_(length));
+ matching_rules_list.vec_push(DeclarationBlock::from_declaration(
+ WidthDeclaration(SpecifiedValue(width_value))));
+ *shareable = false
+ }
+ };
+ }
+ name if *name == atom!("input") => {
+ match element.get_integer_attribute(SizeIntegerAttribute) {
+ Some(value) if value != 0 => {
+ // Per HTML 4.01 § 17.4, this value is in characters if `type` is `text` or
+ // `password` and in pixels otherwise.
+ //
+ // FIXME(pcwalton): More use of atoms, please!
+ let value = match element.get_attr(&ns!(""), &atom!("type")) {
+ Some("text") | Some("password") => {
+ specified::ServoCharacterWidth(value)
+ }
+ _ => specified::Au_(Au::from_px(value as int)),
+ };
+ matching_rules_list.vec_push(DeclarationBlock::from_declaration(
+ WidthDeclaration(SpecifiedValue(specified::LPA_Length(
+ value)))));
+ *shareable = false
+ }
+ Some(_) | None => {}
+ }
+ }
+ _ => {}
+ }
+ }
+}
+