Inline PresentationalHintSynthesis::synthesize_presentational_hints_for_legacy_attributes.

This commit is contained in:
Ms2ger 2015-11-15 13:46:55 +01:00
parent 9c1d678b1b
commit 1154cf51c8
2 changed files with 6 additions and 39 deletions

View file

@ -5,45 +5,10 @@
//! Legacy presentational attributes defined in the HTML5 specification: `<td width>`,
//! `<input size>`, and so forth.
use node::TElementAttributes;
use properties::PropertyDeclaration;
use selector_matching::Stylist;
use selectors::Element;
use selectors::matching::DeclarationBlock;
use smallvec::VecLike;
use std::sync::Arc;
/// 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<E, V>(
&self, element: &E, matching_rules_list: &mut V, shareable: &mut bool)
where E: Element + TElementAttributes,
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
}
impl PresentationalHintSynthesis for Stylist {
fn synthesize_presentational_hints_for_legacy_attributes<E, V>(
&self, element: &E, matching_rules_list: &mut V, shareable: &mut bool)
where E: Element + TElementAttributes,
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>> {
let length = matching_rules_list.len();
element.synthesize_presentational_hints_for_legacy_attributes(matching_rules_list);
if matching_rules_list.len() != length {
// Never share style for elements with preshints
*shareable = false;
}
}
}
/// A convenience function to create a declaration block from a single declaration. This is
/// primarily used in `synthesize_rules_for_legacy_attributes`.
#[inline]

View file

@ -2,7 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use legacy::PresentationalHintSynthesis;
use media_queries::{Device, MediaType};
use node::TElementAttributes;
use properties::{PropertyDeclaration, PropertyDeclarationBlock};
@ -277,9 +276,12 @@ impl Stylist {
&mut shareable);
// Step 2: Presentational hints.
self.synthesize_presentational_hints_for_legacy_attributes(element,
applicable_declarations,
&mut shareable);
let length = applicable_declarations.len();
element.synthesize_presentational_hints_for_legacy_attributes(applicable_declarations);
if applicable_declarations.len() != length {
// Never share style for elements with preshints
shareable = false;
}
// Step 3: User and author normal rules.
map.user.normal.get_all_matching_rules(element,