Auto merge of #17247 - Manishearth:stylo-insensitive-selectors, r=SimonSapin

stylo: Make all attribute selectors respect case insensitivity

r=simonsapin https://bugzilla.mozilla.org/show_bug.cgi?id=1364162

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17247)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-06-08 17:26:45 -07:00 committed by GitHub
commit a6b3bf1517
5 changed files with 26 additions and 29 deletions

View file

@ -399,11 +399,6 @@ impl<'le> TElement for ServoLayoutElement<'le> {
self.get_attr(namespace, attr).is_some() self.get_attr(namespace, attr).is_some()
} }
#[inline]
fn attr_equals(&self, namespace: &Namespace, attr: &LocalName, val: &Atom) -> bool {
self.get_attr(namespace, attr).map_or(false, |x| x == val)
}
#[inline(always)] #[inline(always)]
fn each_class<F>(&self, mut callback: F) where F: FnMut(&Atom) { fn each_class<F>(&self, mut callback: F) where F: FnMut(&Atom) {
unsafe { unsafe {

View file

@ -368,9 +368,6 @@ pub trait TElement : Eq + PartialEq + Debug + Hash + Sized + Copy + Clone +
/// Whether this element has an attribute with a given namespace. /// Whether this element has an attribute with a given namespace.
fn has_attr(&self, namespace: &Namespace, attr: &LocalName) -> bool; fn has_attr(&self, namespace: &Namespace, attr: &LocalName) -> bool;
/// Whether an attribute value equals `value`.
fn attr_equals(&self, namespace: &Namespace, attr: &LocalName, value: &Atom) -> bool;
/// Internal iterator for the classes of this element. /// Internal iterator for the classes of this element.
fn each_class<F>(&self, callback: F) where F: FnMut(&Atom); fn each_class<F>(&self, callback: F) where F: FnMut(&Atom);

View file

@ -619,27 +619,28 @@ extern "C" {
extern "C" { extern "C" {
pub fn Gecko_AttrDashEquals(element: RawGeckoElementBorrowed, pub fn Gecko_AttrDashEquals(element: RawGeckoElementBorrowed,
ns: *mut nsIAtom, name: *mut nsIAtom, ns: *mut nsIAtom, name: *mut nsIAtom,
str: *mut nsIAtom) -> bool; str: *mut nsIAtom, ignore_case: bool) -> bool;
} }
extern "C" { extern "C" {
pub fn Gecko_AttrIncludes(element: RawGeckoElementBorrowed, pub fn Gecko_AttrIncludes(element: RawGeckoElementBorrowed,
ns: *mut nsIAtom, name: *mut nsIAtom, ns: *mut nsIAtom, name: *mut nsIAtom,
str: *mut nsIAtom) -> bool; str: *mut nsIAtom, ignore_case: bool) -> bool;
} }
extern "C" { extern "C" {
pub fn Gecko_AttrHasSubstring(element: RawGeckoElementBorrowed, pub fn Gecko_AttrHasSubstring(element: RawGeckoElementBorrowed,
ns: *mut nsIAtom, name: *mut nsIAtom, ns: *mut nsIAtom, name: *mut nsIAtom,
str: *mut nsIAtom) -> bool; str: *mut nsIAtom, ignore_case: bool)
-> bool;
} }
extern "C" { extern "C" {
pub fn Gecko_AttrHasPrefix(element: RawGeckoElementBorrowed, pub fn Gecko_AttrHasPrefix(element: RawGeckoElementBorrowed,
ns: *mut nsIAtom, name: *mut nsIAtom, ns: *mut nsIAtom, name: *mut nsIAtom,
str: *mut nsIAtom) -> bool; str: *mut nsIAtom, ignore_case: bool) -> bool;
} }
extern "C" { extern "C" {
pub fn Gecko_AttrHasSuffix(element: RawGeckoElementBorrowed, pub fn Gecko_AttrHasSuffix(element: RawGeckoElementBorrowed,
ns: *mut nsIAtom, name: *mut nsIAtom, ns: *mut nsIAtom, name: *mut nsIAtom,
str: *mut nsIAtom) -> bool; str: *mut nsIAtom, ignore_case: bool) -> bool;
} }
extern "C" { extern "C" {
pub fn Gecko_ClassOrClassList(element: RawGeckoElementBorrowed, pub fn Gecko_ClassOrClassList(element: RawGeckoElementBorrowed,
@ -669,29 +670,34 @@ extern "C" {
extern "C" { extern "C" {
pub fn Gecko_SnapshotAttrDashEquals(element: *const ServoElementSnapshot, pub fn Gecko_SnapshotAttrDashEquals(element: *const ServoElementSnapshot,
ns: *mut nsIAtom, name: *mut nsIAtom, ns: *mut nsIAtom, name: *mut nsIAtom,
str: *mut nsIAtom) -> bool; str: *mut nsIAtom, ignore_case: bool)
-> bool;
} }
extern "C" { extern "C" {
pub fn Gecko_SnapshotAttrIncludes(element: *const ServoElementSnapshot, pub fn Gecko_SnapshotAttrIncludes(element: *const ServoElementSnapshot,
ns: *mut nsIAtom, name: *mut nsIAtom, ns: *mut nsIAtom, name: *mut nsIAtom,
str: *mut nsIAtom) -> bool; str: *mut nsIAtom, ignore_case: bool)
-> bool;
} }
extern "C" { extern "C" {
pub fn Gecko_SnapshotAttrHasSubstring(element: pub fn Gecko_SnapshotAttrHasSubstring(element:
*const ServoElementSnapshot, *const ServoElementSnapshot,
ns: *mut nsIAtom, ns: *mut nsIAtom,
name: *mut nsIAtom, name: *mut nsIAtom,
str: *mut nsIAtom) -> bool; str: *mut nsIAtom,
ignore_case: bool) -> bool;
} }
extern "C" { extern "C" {
pub fn Gecko_SnapshotAttrHasPrefix(element: *const ServoElementSnapshot, pub fn Gecko_SnapshotAttrHasPrefix(element: *const ServoElementSnapshot,
ns: *mut nsIAtom, name: *mut nsIAtom, ns: *mut nsIAtom, name: *mut nsIAtom,
str: *mut nsIAtom) -> bool; str: *mut nsIAtom, ignore_case: bool)
-> bool;
} }
extern "C" { extern "C" {
pub fn Gecko_SnapshotAttrHasSuffix(element: *const ServoElementSnapshot, pub fn Gecko_SnapshotAttrHasSuffix(element: *const ServoElementSnapshot,
ns: *mut nsIAtom, name: *mut nsIAtom, ns: *mut nsIAtom, name: *mut nsIAtom,
str: *mut nsIAtom) -> bool; str: *mut nsIAtom, ignore_case: bool)
-> bool;
} }
extern "C" { extern "C" {
pub fn Gecko_SnapshotClassOrClassList(element: pub fn Gecko_SnapshotClassOrClassList(element:

View file

@ -94,30 +94,35 @@ impl GeckoElementSnapshot {
ns.atom_or_null(), ns.atom_or_null(),
local_name.as_ptr(), local_name.as_ptr(),
expected_value.as_ptr(), expected_value.as_ptr(),
ignore_case,
), ),
AttrSelectorOperator::DashMatch => bindings::Gecko_SnapshotAttrDashEquals( AttrSelectorOperator::DashMatch => bindings::Gecko_SnapshotAttrDashEquals(
self, self,
ns.atom_or_null(), ns.atom_or_null(),
local_name.as_ptr(), local_name.as_ptr(),
expected_value.as_ptr(), expected_value.as_ptr(),
ignore_case,
), ),
AttrSelectorOperator::Prefix => bindings::Gecko_SnapshotAttrHasPrefix( AttrSelectorOperator::Prefix => bindings::Gecko_SnapshotAttrHasPrefix(
self, self,
ns.atom_or_null(), ns.atom_or_null(),
local_name.as_ptr(), local_name.as_ptr(),
expected_value.as_ptr(), expected_value.as_ptr(),
ignore_case,
), ),
AttrSelectorOperator::Suffix => bindings::Gecko_SnapshotAttrHasSuffix( AttrSelectorOperator::Suffix => bindings::Gecko_SnapshotAttrHasSuffix(
self, self,
ns.atom_or_null(), ns.atom_or_null(),
local_name.as_ptr(), local_name.as_ptr(),
expected_value.as_ptr(), expected_value.as_ptr(),
ignore_case,
), ),
AttrSelectorOperator::Substring => bindings::Gecko_SnapshotAttrHasSubstring( AttrSelectorOperator::Substring => bindings::Gecko_SnapshotAttrHasSubstring(
self, self,
ns.atom_or_null(), ns.atom_or_null(),
local_name.as_ptr(), local_name.as_ptr(),
expected_value.as_ptr(), expected_value.as_ptr(),
ignore_case,
), ),
} }
} }

View file

@ -726,17 +726,6 @@ impl<'le> TElement for GeckoElement<'le> {
} }
} }
#[inline]
fn attr_equals(&self, namespace: &Namespace, attr: &Atom, val: &Atom) -> bool {
unsafe {
bindings::Gecko_AttrEquals(self.0,
namespace.0.as_ptr(),
attr.as_ptr(),
val.as_ptr(),
/* ignoreCase = */ false)
}
}
fn each_class<F>(&self, callback: F) fn each_class<F>(&self, callback: F)
where F: FnMut(&Atom) where F: FnMut(&Atom)
{ {
@ -1355,30 +1344,35 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
ns.atom_or_null(), ns.atom_or_null(),
local_name.as_ptr(), local_name.as_ptr(),
expected_value.as_ptr(), expected_value.as_ptr(),
ignore_case,
), ),
AttrSelectorOperator::DashMatch => bindings::Gecko_AttrDashEquals( AttrSelectorOperator::DashMatch => bindings::Gecko_AttrDashEquals(
self.0, self.0,
ns.atom_or_null(), ns.atom_or_null(),
local_name.as_ptr(), local_name.as_ptr(),
expected_value.as_ptr(), expected_value.as_ptr(),
ignore_case,
), ),
AttrSelectorOperator::Prefix => bindings::Gecko_AttrHasPrefix( AttrSelectorOperator::Prefix => bindings::Gecko_AttrHasPrefix(
self.0, self.0,
ns.atom_or_null(), ns.atom_or_null(),
local_name.as_ptr(), local_name.as_ptr(),
expected_value.as_ptr(), expected_value.as_ptr(),
ignore_case,
), ),
AttrSelectorOperator::Suffix => bindings::Gecko_AttrHasSuffix( AttrSelectorOperator::Suffix => bindings::Gecko_AttrHasSuffix(
self.0, self.0,
ns.atom_or_null(), ns.atom_or_null(),
local_name.as_ptr(), local_name.as_ptr(),
expected_value.as_ptr(), expected_value.as_ptr(),
ignore_case,
), ),
AttrSelectorOperator::Substring => bindings::Gecko_AttrHasSubstring( AttrSelectorOperator::Substring => bindings::Gecko_AttrHasSubstring(
self.0, self.0,
ns.atom_or_null(), ns.atom_or_null(),
local_name.as_ptr(), local_name.as_ptr(),
expected_value.as_ptr(), expected_value.as_ptr(),
ignore_case,
), ),
} }
} }