mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
style: Move presentational hint synthesis into legacy.rs
.
This commit is contained in:
parent
112ef5c484
commit
e0e14c60d6
2 changed files with 81 additions and 61 deletions
|
@ -5,6 +5,14 @@
|
||||||
//! Legacy presentational attributes defined in the HTML5 specification: `<td width>`,
|
//! Legacy presentational attributes defined in the HTML5 specification: `<td width>`,
|
||||||
//! `<input size>`, and so forth.
|
//! `<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.
|
/// Legacy presentational attributes that take a length as defined in HTML5 § 2.4.4.4.
|
||||||
pub enum LengthAttribute {
|
pub enum LengthAttribute {
|
||||||
/// `<td width>`
|
/// `<td width>`
|
||||||
|
@ -17,3 +25,74 @@ pub enum IntegerAttribute {
|
||||||
SizeIntegerAttribute,
|
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 => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,18 +11,15 @@ use sync::Arc;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use servo_util::bloom::BloomFilter;
|
use servo_util::bloom::BloomFilter;
|
||||||
use servo_util::geometry::Au;
|
|
||||||
use servo_util::resource_files::read_resource_file;
|
use servo_util::resource_files::read_resource_file;
|
||||||
use servo_util::smallvec::VecLike;
|
use servo_util::smallvec::VecLike;
|
||||||
use servo_util::sort;
|
use servo_util::sort;
|
||||||
use servo_util::str::{AutoLpa, LengthLpa, PercentageLpa};
|
|
||||||
use string_cache::Atom;
|
use string_cache::Atom;
|
||||||
|
|
||||||
use legacy::{SizeIntegerAttribute, WidthLengthAttribute};
|
use legacy::PresentationalHintSynthesis;
|
||||||
use media_queries::Device;
|
use media_queries::Device;
|
||||||
use node::{TElement, TElementAttributes, TNode};
|
use node::{TElement, TElementAttributes, TNode};
|
||||||
use properties::{PropertyDeclaration, PropertyDeclarationBlock, SpecifiedValue, WidthDeclaration};
|
use properties::{PropertyDeclaration, PropertyDeclarationBlock};
|
||||||
use properties::{specified};
|
|
||||||
use selectors::*;
|
use selectors::*;
|
||||||
use stylesheets::{Stylesheet, iter_stylesheet_media_rules, iter_stylesheet_style_rules};
|
use stylesheets::{Stylesheet, iter_stylesheet_media_rules, iter_stylesheet_style_rules};
|
||||||
|
|
||||||
|
@ -477,62 +474,6 @@ impl Stylist {
|
||||||
|
|
||||||
shareable
|
shareable
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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> {
|
|
||||||
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 => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct PerOriginSelectorMap {
|
struct PerOriginSelectorMap {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue