mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Shrink selectors::Component, add case-insensitive for other attr selectors
* https://bugzilla.mozilla.org/show_bug.cgi?id=1364148 * https://bugzilla.mozilla.org/show_bug.cgi?id=1364162
This commit is contained in:
parent
83c7824fda
commit
9376abdd2c
15 changed files with 377 additions and 357 deletions
|
@ -12,7 +12,6 @@ use cssparser::{self, Color, RGBA};
|
|||
use euclid::num::Zero;
|
||||
use num_traits::ToPrimitive;
|
||||
use properties::PropertyDeclarationBlock;
|
||||
use selector_parser::SelectorImpl;
|
||||
use selectors::attr::AttrSelectorOperation;
|
||||
use servo_url::ServoUrl;
|
||||
use shared_lock::Locked;
|
||||
|
@ -352,9 +351,10 @@ impl AttrValue {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn eval_selector(&self, selector: &AttrSelectorOperation<SelectorImpl>) -> bool {
|
||||
pub fn eval_selector(&self, selector: &AttrSelectorOperation<&String>) -> bool {
|
||||
// FIXME(SimonSapin) this can be more efficient by matching on `(self, selector)` variants
|
||||
// and doing Atom comparisons instead of string comparisons where possible.
|
||||
// and doing Atom comparisons instead of string comparisons where possible,
|
||||
// with SelectorImpl::AttrValue changed to Atom.
|
||||
selector.eval_str(self)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,10 +14,8 @@ use gecko_bindings::structs::ServoElementSnapshot;
|
|||
use gecko_bindings::structs::ServoElementSnapshotFlags as Flags;
|
||||
use gecko_bindings::structs::ServoElementSnapshotTable;
|
||||
use restyle_hints::ElementSnapshot;
|
||||
use selector_parser::SelectorImpl;
|
||||
use selectors::attr::{AttrSelectorOperation, AttrSelectorOperator, CaseSensitivity};
|
||||
use selectors::parser::NamespaceConstraint;
|
||||
use string_cache::Atom;
|
||||
use selectors::attr::{AttrSelectorOperation, AttrSelectorOperator, CaseSensitivity, NamespaceConstraint};
|
||||
use string_cache::{Atom, Namespace};
|
||||
|
||||
/// A snapshot of a Gecko element.
|
||||
pub type GeckoElementSnapshot = ServoElementSnapshot;
|
||||
|
@ -59,9 +57,9 @@ impl GeckoElementSnapshot {
|
|||
|
||||
/// selectors::Element::attr_matches
|
||||
pub fn attr_matches(&self,
|
||||
ns: &NamespaceConstraint<SelectorImpl>,
|
||||
ns: &NamespaceConstraint<&Namespace>,
|
||||
local_name: &Atom,
|
||||
operation: &AttrSelectorOperation<SelectorImpl>)
|
||||
operation: &AttrSelectorOperation<&Atom>)
|
||||
-> bool {
|
||||
unsafe {
|
||||
match *operation {
|
||||
|
|
|
@ -64,9 +64,8 @@ use properties::style_structs::Font;
|
|||
use rule_tree::CascadeLevel as ServoCascadeLevel;
|
||||
use selector_parser::ElementExt;
|
||||
use selectors::Element;
|
||||
use selectors::attr::{AttrSelectorOperation, AttrSelectorOperator, CaseSensitivity};
|
||||
use selectors::attr::{AttrSelectorOperation, AttrSelectorOperator, CaseSensitivity, NamespaceConstraint};
|
||||
use selectors::matching::{ElementSelectorFlags, MatchingContext, MatchingMode};
|
||||
use selectors::parser::NamespaceConstraint;
|
||||
use shared_lock::Locked;
|
||||
use sink::Push;
|
||||
use std::cell::RefCell;
|
||||
|
@ -1140,9 +1139,9 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
|
|||
}
|
||||
|
||||
fn attr_matches(&self,
|
||||
ns: &NamespaceConstraint<SelectorImpl>,
|
||||
ns: &NamespaceConstraint<&Namespace>,
|
||||
local_name: &Atom,
|
||||
operation: &AttrSelectorOperation<SelectorImpl>)
|
||||
operation: &AttrSelectorOperation<&Atom>)
|
||||
-> bool {
|
||||
unsafe {
|
||||
match *operation {
|
||||
|
@ -1413,11 +1412,11 @@ pub trait NamespaceConstraintHelpers {
|
|||
fn atom_or_null(&self) -> *mut nsIAtom;
|
||||
}
|
||||
|
||||
impl NamespaceConstraintHelpers for NamespaceConstraint<SelectorImpl> {
|
||||
impl<'a> NamespaceConstraintHelpers for NamespaceConstraint<&'a Namespace> {
|
||||
fn atom_or_null(&self) -> *mut nsIAtom {
|
||||
match *self {
|
||||
NamespaceConstraint::Any => ptr::null_mut(),
|
||||
NamespaceConstraint::Specific(ref ns) => ns.url.0.as_ptr(),
|
||||
NamespaceConstraint::Specific(ref ns) => ns.0.as_ptr(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,19 +8,19 @@
|
|||
|
||||
use Atom;
|
||||
use LocalName;
|
||||
use Namespace;
|
||||
use dom::TElement;
|
||||
use element_state::*;
|
||||
#[cfg(feature = "gecko")]
|
||||
use gecko_bindings::structs::nsRestyleHint;
|
||||
#[cfg(feature = "servo")]
|
||||
use heapsize::HeapSizeOf;
|
||||
use selector_parser::{NonTSPseudoClass, PseudoElement, SelectorImpl, Snapshot, SnapshotMap};
|
||||
use selector_parser::{NonTSPseudoClass, PseudoElement, SelectorImpl, Snapshot, SnapshotMap, AttrValue};
|
||||
use selectors::Element;
|
||||
use selectors::attr::AttrSelectorOperation;
|
||||
use selectors::attr::{AttrSelectorOperation, NamespaceConstraint};
|
||||
use selectors::matching::{ElementSelectorFlags, MatchingContext, MatchingMode};
|
||||
use selectors::matching::matches_selector;
|
||||
use selectors::parser::{Combinator, Component, Selector};
|
||||
use selectors::parser::{SelectorInner, SelectorMethods, NamespaceConstraint};
|
||||
use selectors::parser::{Combinator, Component, Selector, SelectorInner, SelectorMethods};
|
||||
use selectors::visitor::SelectorVisitor;
|
||||
use smallvec::SmallVec;
|
||||
use std::borrow::Borrow;
|
||||
|
@ -371,9 +371,9 @@ impl<'a, E> Element for ElementWrapper<'a, E>
|
|||
}
|
||||
|
||||
fn attr_matches(&self,
|
||||
ns: &NamespaceConstraint<Self::Impl>,
|
||||
ns: &NamespaceConstraint<&Namespace>,
|
||||
local_name: &LocalName,
|
||||
operation: &AttrSelectorOperation<Self::Impl>)
|
||||
operation: &AttrSelectorOperation<&AttrValue>)
|
||||
-> bool {
|
||||
match self.snapshot() {
|
||||
Some(snapshot) if snapshot.has_attrs() => {
|
||||
|
@ -437,13 +437,9 @@ fn is_attr_selector(sel: &Component<SelectorImpl>) -> bool {
|
|||
match *sel {
|
||||
Component::ID(_) |
|
||||
Component::Class(_) |
|
||||
Component::AttrExists(_) |
|
||||
Component::AttrEqual(_, _, _) |
|
||||
Component::AttrIncludes(_, _) |
|
||||
Component::AttrDashMatch(_, _) |
|
||||
Component::AttrPrefixMatch(_, _) |
|
||||
Component::AttrSubstringMatch(_, _) |
|
||||
Component::AttrSuffixMatch(_, _) => true,
|
||||
Component::AttributeInNoNamespaceExists { .. } |
|
||||
Component::AttributeInNoNamespace { .. } |
|
||||
Component::AttributeOther(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,10 +14,10 @@ use element_state::ElementState;
|
|||
use fnv::FnvHashMap;
|
||||
use restyle_hints::ElementSnapshot;
|
||||
use selector_parser::{ElementExt, PseudoElementCascadeType, SelectorParser};
|
||||
use selectors::{Element};
|
||||
use selectors::attr::AttrSelectorOperation;
|
||||
use selectors::Element;
|
||||
use selectors::attr::{AttrSelectorOperation, NamespaceConstraint};
|
||||
use selectors::matching::{MatchingContext, MatchingMode};
|
||||
use selectors::parser::{SelectorMethods, NamespaceConstraint};
|
||||
use selectors::parser::SelectorMethods;
|
||||
use selectors::visitor::SelectorVisitor;
|
||||
use std::borrow::Cow;
|
||||
use std::fmt;
|
||||
|
@ -559,14 +559,13 @@ impl ElementSnapshot for ServoElementSnapshot {
|
|||
impl ServoElementSnapshot {
|
||||
/// selectors::Element::attr_matches
|
||||
pub fn attr_matches(&self,
|
||||
ns: &NamespaceConstraint<SelectorImpl>,
|
||||
ns: &NamespaceConstraint<&Namespace>,
|
||||
local_name: &LocalName,
|
||||
operation: &AttrSelectorOperation<SelectorImpl>)
|
||||
operation: &AttrSelectorOperation<&String>)
|
||||
-> bool {
|
||||
use selectors::parser::NamespaceConstraint;
|
||||
match *ns {
|
||||
NamespaceConstraint::Specific(ref ns) => {
|
||||
self.get_attr(&ns.url, local_name)
|
||||
self.get_attr(ns, local_name)
|
||||
.map_or(false, |value| value.eval_selector(operation))
|
||||
}
|
||||
NamespaceConstraint::Any => {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use {Atom, LocalName};
|
||||
use {Atom, LocalName, Namespace};
|
||||
use bit_vec::BitVec;
|
||||
use context::QuirksMode;
|
||||
use data::ComputedStyle;
|
||||
|
@ -26,10 +26,11 @@ use properties::PropertyDeclarationBlock;
|
|||
use restyle_hints::{RestyleHint, DependencySet};
|
||||
use rule_tree::{CascadeLevel, RuleTree, StrongRuleNode, StyleSource};
|
||||
use selector_parser::{SelectorImpl, PseudoElement, SnapshotMap};
|
||||
use selectors::attr::NamespaceConstraint;
|
||||
use selectors::bloom::BloomFilter;
|
||||
use selectors::matching::{AFFECTED_BY_STYLE_ATTRIBUTE, AFFECTED_BY_PRESENTATIONAL_HINTS};
|
||||
use selectors::matching::{ElementSelectorFlags, matches_selector, MatchingContext, MatchingMode};
|
||||
use selectors::parser::{AttrSelector, Combinator, Component, Selector, SelectorInner, SelectorIter};
|
||||
use selectors::parser::{Combinator, Component, Selector, SelectorInner, SelectorIter};
|
||||
use selectors::parser::{SelectorMethods, LocalName as LocalNameSelector};
|
||||
use selectors::visitor::SelectorVisitor;
|
||||
use shared_lock::{Locked, SharedRwLockReadGuard, StylesheetGuards};
|
||||
|
@ -502,7 +503,7 @@ impl Stylist {
|
|||
/// Returns whether the given attribute might appear in an attribute
|
||||
/// selector of some rule in the stylist.
|
||||
pub fn might_have_attribute_dependency(&self,
|
||||
local_name: &<SelectorImpl as ::selectors::SelectorImpl>::LocalName)
|
||||
local_name: &LocalName)
|
||||
-> bool {
|
||||
#[cfg(feature = "servo")]
|
||||
let style_lower_name = local_name!("style");
|
||||
|
@ -1088,17 +1089,19 @@ struct AttributeAndStateDependencyVisitor<'a>(&'a mut Stylist);
|
|||
impl<'a> SelectorVisitor for AttributeAndStateDependencyVisitor<'a> {
|
||||
type Impl = SelectorImpl;
|
||||
|
||||
fn visit_attribute_selector(&mut self, selector: &AttrSelector<Self::Impl>) -> bool {
|
||||
fn visit_attribute_selector(&mut self, _ns: &NamespaceConstraint<&Namespace>,
|
||||
name: &LocalName, lower_name: &LocalName)
|
||||
-> bool {
|
||||
#[cfg(feature = "servo")]
|
||||
let style_lower_name = local_name!("style");
|
||||
#[cfg(feature = "gecko")]
|
||||
let style_lower_name = atom!("style");
|
||||
|
||||
if selector.lower_name == style_lower_name {
|
||||
if *lower_name == style_lower_name {
|
||||
self.0.style_attribute_dependency = true;
|
||||
} else {
|
||||
self.0.attribute_dependencies.insert(&selector.name);
|
||||
self.0.attribute_dependencies.insert(&selector.lower_name);
|
||||
self.0.attribute_dependencies.insert(&name);
|
||||
self.0.attribute_dependencies.insert(&lower_name);
|
||||
}
|
||||
true
|
||||
}
|
||||
|
@ -1157,13 +1160,9 @@ impl SelectorVisitor for RevalidationVisitor {
|
|||
/// concerned.
|
||||
fn visit_simple_selector(&mut self, s: &Component<SelectorImpl>) -> bool {
|
||||
match *s {
|
||||
Component::AttrExists(_) |
|
||||
Component::AttrEqual(_, _, _) |
|
||||
Component::AttrIncludes(_, _) |
|
||||
Component::AttrDashMatch(_, _) |
|
||||
Component::AttrPrefixMatch(_, _) |
|
||||
Component::AttrSubstringMatch(_, _) |
|
||||
Component::AttrSuffixMatch(_, _) |
|
||||
Component::AttributeInNoNamespaceExists { .. } |
|
||||
Component::AttributeInNoNamespace { .. } |
|
||||
Component::AttributeOther(_) |
|
||||
Component::Empty |
|
||||
Component::FirstChild |
|
||||
Component::LastChild |
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue