Skip to content

Commit

Permalink
# This is a combination of 5 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:
# This is a combination of 9 commits.
# This is the 1st commit message:
ext. filtering for lang matching

# This is the commit message servo#2:

linting errors

# This is the commit message servo#3:

moving more common stuffs

# This is the commit message servo#4:

fixes as per comments

# This is the commit message servo#5:

reduced comments

# This is the commit message servo#6:

removed passed test ini files

# This is the commit message servo#7:

nit fixes

# This is the commit message servo#8:

reverting css3 test cases and renamed variables

# This is the commit message servo#9:

updates as per comments

linting fixes

# This is the commit message servo#2:

updated as per comments

# This is the commit message servo#3:

updated as per comments

# This is the commit message servo#4:

removed loop inside the for loop

# This is the commit message servo#5:

fixed per comments
  • Loading branch information
sendilkumarn committed Mar 7, 2017
1 parent c62973b commit cad6c8a
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 34 deletions.
58 changes: 58 additions & 0 deletions components/script/dom/bindings/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,64 @@ pub fn is_token(s: &[u8]) -> bool {
})
}

/// Returns whether the language is matched, as defined by
/// [RFC 4647](https://tools.ietf.org/html/rfc4647#section-3.3.2).
pub fn extended_filtering(tag: &str, range: &str) -> bool {
let lang_ranges: Vec<&str> = range.split(',').collect();

lang_ranges.iter().any(|&lang_range| {
// step 1
let range_subtags: Vec<&str> = lang_range.split('\x2d').collect();
let tag_subtags: Vec<&str> = tag.split('\x2d').collect();

let mut range_iter = range_subtags.iter();
let mut tag_iter = tag_subtags.iter();

// step 2
// Note: [Level-4 spec](https://drafts.csswg.org/selectors/#lang-pseudo) check for wild card
if let (Some(range_subtag), Some(tag_subtag)) = (range_iter.next(), tag_iter.next()) {
if !(range_subtag.eq_ignore_ascii_case(tag_subtag) || range_subtag.eq_ignore_ascii_case("*")) {
return false;
}
}

let mut current_tag_subtag = tag_iter.next();

// step 3
for range_subtag in range_iter {
// step 3a
if range_subtag.eq_ignore_ascii_case("*") {
continue;
}
match current_tag_subtag.clone() {
Some(tag_subtag) => {
// step 3c
if range_subtag.eq_ignore_ascii_case(tag_subtag) {
current_tag_subtag = tag_iter.next();
continue;
} else {
// step 3d
if tag_subtag.len() == 1 {
return false;
} else {
// else step 3e - continue with loop
current_tag_subtag = tag_iter.next();
if current_tag_subtag.is_none() {
return false;
}
}
}
},
// step 3b
None => { return false; }
}
}
// step 4
true
})
}


/// A DOMString.
///
/// This type corresponds to the [`DOMString`](idl) type in WebIDL.
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use dom::bindings::js::{JS, LayoutJS, MutNullableJS};
use dom::bindings::js::{Root, RootedReference};
use dom::bindings::refcounted::{Trusted, TrustedPromise};
use dom::bindings::reflector::DomObject;
use dom::bindings::str::DOMString;
use dom::bindings::str::{DOMString, extended_filtering};
use dom::bindings::xmlname::{namespace_from_domstring, validate_and_extract, xml_name_type};
use dom::bindings::xmlname::XMLName::InvalidXMLName;
use dom::characterdata::CharacterData;
Expand Down Expand Up @@ -2402,7 +2402,7 @@ impl<'a> ::selectors::Element for Root<Element> {

// FIXME(#15746): This is wrong, we need to instead use extended filtering as per RFC4647
// https://tools.ietf.org/html/rfc4647#section-3.3.2
NonTSPseudoClass::Lang(ref lang) => lang.eq_ignore_ascii_case(&self.get_lang()),
NonTSPseudoClass::Lang(ref lang) => extended_filtering(&*self.get_lang(), &*lang),

NonTSPseudoClass::ReadOnly =>
!Element::state(self).contains(pseudo_class.state_flag()),
Expand Down
4 changes: 2 additions & 2 deletions components/script/layout_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use atomic_refcell::AtomicRefCell;
use dom::bindings::inheritance::{CharacterDataTypeId, ElementTypeId};
use dom::bindings::inheritance::{HTMLElementTypeId, NodeTypeId};
use dom::bindings::js::LayoutJS;
use dom::bindings::str::extended_filtering;
use dom::characterdata::LayoutCharacterDataHelpers;
use dom::document::{Document, LayoutDocumentHelpers, PendingRestyle};
use dom::element::{Element, LayoutElementHelpers, RawLayoutElementHelpers};
Expand All @@ -53,7 +54,6 @@ use selectors::matching::ElementSelectorFlags;
use selectors::parser::{AttrSelector, NamespaceConstraint};
use servo_atoms::Atom;
use servo_url::ServoUrl;
use std::ascii::AsciiExt;
use std::fmt;
use std::fmt::Debug;
use std::marker::PhantomData;
Expand Down Expand Up @@ -621,7 +621,7 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> {

// FIXME(#15746): This is wrong, we need to instead use extended filtering as per RFC4647
// https://tools.ietf.org/html/rfc4647#section-3.3.2
NonTSPseudoClass::Lang(ref lang) => lang.eq_ignore_ascii_case(&self.element.get_lang_for_layout()),
NonTSPseudoClass::Lang(ref lang) => extended_filtering(&*self.element.get_lang_for_layout(), &*lang),

NonTSPseudoClass::ServoNonZeroBorder => unsafe {
match (*self.element.unsafe_get()).get_attr_for_layout(&ns!(), &local_name!("border")) {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[css3-selectors-lang-014.htm]
type: testharness
[A :lang value with language and region subtags will NOT match a lang attribute value with language, script and region subtags.]
expected: FAIL

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[css3-selectors-lang-014.xht]
type: testharness
[A :lang value with language and region subtags will NOT match a lang attribute value with language, script and region subtags.]
expected: FAIL

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[css3-selectors-lang-014.xht]
type: testharness
[A :lang value with language and region subtags will NOT match a lang attribute value with language, script and region subtags.]
expected: FAIL

0 comments on commit cad6c8a

Please sign in to comment.