mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
style: Parse the legacy bgcolor
attribute per the HTML5 specification.
Additionally, this patch cleans up some miscellaneous formatting issues.
This commit is contained in:
parent
10f1ed5e31
commit
14bafb11be
19 changed files with 370 additions and 36 deletions
|
@ -6,11 +6,12 @@
|
|||
//! `<input size>`, and so forth.
|
||||
|
||||
use node::{TElement, TElementAttributes, TNode};
|
||||
use properties::{BorderBottomWidthDeclaration, BorderLeftWidthDeclaration};
|
||||
use properties::{BorderRightWidthDeclaration, BorderTopWidthDeclaration, SpecifiedValue};
|
||||
use properties::{WidthDeclaration, specified};
|
||||
use properties::{BackgroundColorDeclaration, BorderBottomWidthDeclaration};
|
||||
use properties::{BorderLeftWidthDeclaration, BorderRightWidthDeclaration};
|
||||
use properties::{BorderTopWidthDeclaration, SpecifiedValue, WidthDeclaration, specified};
|
||||
use selector_matching::{DeclarationBlock, Stylist};
|
||||
|
||||
use cssparser::{RGBA, RGBAColor};
|
||||
use servo_util::geometry::Au;
|
||||
use servo_util::smallvec::VecLike;
|
||||
use servo_util::str::{AutoLpa, LengthLpa, PercentageLpa};
|
||||
|
@ -33,11 +34,22 @@ pub enum UnsignedIntegerAttribute {
|
|||
BorderUnsignedIntegerAttribute,
|
||||
}
|
||||
|
||||
/// Legacy presentational attributes that take a simple color as defined in HTML5 § 2.4.6.
|
||||
pub enum SimpleColorAttribute {
|
||||
/// `<body bgcolor>`
|
||||
BgColorSimpleColorAttribute,
|
||||
}
|
||||
|
||||
/// 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.
|
||||
///
|
||||
/// NB: Beware! If you add an attribute to this list, be sure to add it to
|
||||
/// `common_style_affecting_attributes` or `rare_style_affecting_attributes` as appropriate. If
|
||||
/// you don't, you risk strange random nondeterministic failures due to false positives in
|
||||
/// style sharing.
|
||||
fn synthesize_presentational_hints_for_legacy_attributes<'a,E,N,V>(
|
||||
&self,
|
||||
node: &N,
|
||||
|
@ -47,6 +59,18 @@ pub trait PresentationalHintSynthesis {
|
|||
TElementAttributes,
|
||||
N: TNode<'a,E>,
|
||||
V: VecLike<DeclarationBlock>;
|
||||
/// 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>;
|
||||
/// Synthesizes rules for the legacy `border` attribute.
|
||||
fn synthesize_presentational_hint_for_legacy_border_attribute<'a,E,V>(
|
||||
&self,
|
||||
|
@ -87,17 +111,31 @@ 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,
|
||||
shareable);
|
||||
}
|
||||
name if *name == atom!("body") => {
|
||||
self.synthesize_presentational_hint_for_legacy_background_color_attribute(
|
||||
element,
|
||||
matching_rules_list,
|
||||
shareable);
|
||||
}
|
||||
name if *name == atom!("input") => {
|
||||
match element.get_integer_attribute(SizeIntegerAttribute) {
|
||||
Some(value) if value != 0 => {
|
||||
|
@ -123,6 +161,32 @@ 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> {
|
||||
match element.get_simple_color_attribute(BgColorSimpleColorAttribute) {
|
||||
None => {}
|
||||
Some(color) => {
|
||||
matching_rules_list.vec_push(DeclarationBlock::from_declaration(
|
||||
BackgroundColorDeclaration(SpecifiedValue(RGBAColor(RGBA {
|
||||
red: color.red as f32 / 255.0,
|
||||
green: color.green as f32 / 255.0,
|
||||
blue: color.blue as f32 / 255.0,
|
||||
alpha: 1.0,
|
||||
})))));
|
||||
*shareable = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn synthesize_presentational_hint_for_legacy_border_attribute<'a,E,V>(
|
||||
&self,
|
||||
element: E,
|
||||
|
|
|
@ -54,8 +54,9 @@ pub use selectors::{PseudoElement, Before, After, SelectorList, parse_selector_l
|
|||
pub use selectors::{AttrSelector, NamespaceConstraint, SpecificNamespace, AnyNamespace};
|
||||
pub use selectors::{SimpleSelector, LocalNameSelector};
|
||||
pub use cssparser::{Color, RGBA};
|
||||
pub use legacy::{BorderUnsignedIntegerAttribute, IntegerAttribute, LengthAttribute};
|
||||
pub use legacy::{SizeIntegerAttribute, UnsignedIntegerAttribute, WidthLengthAttribute};
|
||||
pub use legacy::{BgColorSimpleColorAttribute, BorderUnsignedIntegerAttribute, IntegerAttribute};
|
||||
pub use legacy::{LengthAttribute, SimpleColorAttribute, SizeIntegerAttribute};
|
||||
pub use legacy::{UnsignedIntegerAttribute, WidthLengthAttribute};
|
||||
pub use font_face::{Source, LocalSource, UrlSource_};
|
||||
|
||||
mod stylesheets;
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
//! Traits that nodes must implement. Breaks the otherwise-cyclic dependency between layout and
|
||||
//! style.
|
||||
|
||||
use legacy::{IntegerAttribute, LengthAttribute, UnsignedIntegerAttribute};
|
||||
use legacy::{IntegerAttribute, LengthAttribute, SimpleColorAttribute, UnsignedIntegerAttribute};
|
||||
use selectors::AttrSelector;
|
||||
use servo_util::str::LengthOrPercentageOrAuto;
|
||||
use servo_util::str::{LengthOrPercentageOrAuto, SimpleColor};
|
||||
use string_cache::{Atom, Namespace};
|
||||
|
||||
pub trait TNode<'a, E: TElement<'a>> : Clone + Copy {
|
||||
|
@ -60,4 +60,5 @@ 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<SimpleColor>;
|
||||
}
|
||||
|
|
|
@ -802,8 +802,8 @@ pub fn common_style_affecting_attributes() -> [CommonStyleAffectingAttributeInfo
|
|||
/// Attributes that, if present, disable style sharing. All legacy HTML attributes must be in
|
||||
/// either this list or `common_style_affecting_attributes`. See the comment in
|
||||
/// `synthesize_presentational_hints_for_legacy_attributes`.
|
||||
pub fn rare_style_affecting_attributes() -> [Atom, ..1] {
|
||||
[ atom!("border") ]
|
||||
pub fn rare_style_affecting_attributes() -> [Atom, ..2] {
|
||||
[ atom!("bgcolor"), atom!("border") ]
|
||||
}
|
||||
|
||||
/// Determines whether the given element matches the given single selector.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue