Update to selectors 0.8.2

This commit is contained in:
Simon Sapin 2016-07-15 10:24:10 +02:00
parent f419db834c
commit fdb2071b2d
28 changed files with 455 additions and 286 deletions

View file

@ -4,11 +4,12 @@
//! The pseudo-classes and pseudo-elements supported by the style system.
use matching::{common_style_affecting_attributes, CommonStyleAffectingAttributeMode};
use restyle_hints;
use selectors::Element;
use selectors::parser::SelectorImpl;
use selectors::parser::{AttrSelector, SelectorImpl};
pub type AttrString = <TheSelectorImpl as SelectorImpl>::AttrString;
pub type AttrValue = <TheSelectorImpl as SelectorImpl>::AttrValue;
#[cfg(feature = "servo")]
pub use servo_selector_impl::*;
@ -69,8 +70,8 @@ impl PseudoElementCascadeType {
}
}
pub trait ElementExt: Element<Impl=TheSelectorImpl, AttrString=<TheSelectorImpl as SelectorImpl>::AttrString> {
type Snapshot: restyle_hints::ElementSnapshot<AttrString = Self::AttrString> + 'static;
pub trait ElementExt: Element<Impl=TheSelectorImpl> {
type Snapshot: restyle_hints::ElementSnapshot + 'static;
fn is_link(&self) -> bool;
}
@ -96,3 +97,29 @@ impl TheSelectorImpl {
})
}
}
pub fn attr_exists_selector_is_shareable(attr_selector: &AttrSelector<TheSelectorImpl>) -> bool {
// NB(pcwalton): If you update this, remember to update the corresponding list in
// `can_share_style_with()` as well.
common_style_affecting_attributes().iter().any(|common_attr_info| {
common_attr_info.atom == attr_selector.name && match common_attr_info.mode {
CommonStyleAffectingAttributeMode::IsPresent(_) => true,
CommonStyleAffectingAttributeMode::IsEqual(..) => false,
}
})
}
pub fn attr_equals_selector_is_shareable(attr_selector: &AttrSelector<TheSelectorImpl>,
value: &AttrValue) -> bool {
// FIXME(pcwalton): Remove once we start actually supporting RTL text. This is in
// here because the UA style otherwise disables all style sharing completely.
atom!("dir") == *value ||
common_style_affecting_attributes().iter().any(|common_attr_info| {
common_attr_info.atom == attr_selector.name && match common_attr_info.mode {
CommonStyleAffectingAttributeMode::IsEqual(ref target_value, _) => {
*target_value == *value
}
CommonStyleAffectingAttributeMode::IsPresent(_) => false,
}
})
}