CSS value in whitespace-separated list attribute selector (~=) mishandles tab/newline/etc.
https://bugs.webkit.org/show_bug.cgi?id=136807

Patch by Benjamin Poulain <bpoulain@apple.com> on 2014-09-17
Reviewed by Antti Koivisto.

Source/WebCore:

The spec defines selector lists as token separated by white space.

The definition of white space for CSS Selectors is:
"White space in Selectors consists of the code points SPACE (U+0020),
TAB (U+0009), LINE FEED (U+000A), CARRIAGE RETURN (U+000D), and FORM FEED (U+000C)
can occur in whitespace. Other space-like code points, such as EM SPACE (U+2003)
and IDEOGRAPHIC SPACE (U+3000), are never part of white space."

The old code was only matching SPACE (U+0020) which is buggy. This patch
adds support for the other caracters.

Tests: fast/selectors/attr-list-01.html
       fast/selectors/attribute-list-with-whitespace-in-selector.html
       fast/selectors/attribute-list-with-whitespace-in-value.html

* css/SelectorChecker.cpp:
(WebCore::attributeValueMatches):
* cssjit/SelectorCompiler.cpp:
(WebCore::SelectorCompiler::constructFragments):
(WebCore::SelectorCompiler::attributeValueSpaceSeparetedListContains):
Add the missing checks.

* html/track/VTTRegion.cpp:
(WebCore::VTTRegion::setRegionSettings):
(WebCore::VTTRegion::parseSettingValue):
* html/track/WebVTTParser.cpp:
(WebCore::WebVTTParser::hasRequiredFileIdentifier):
(WebCore::WebVTTParser::collectTimingsAndSettings):
* html/track/WebVTTParser.h:
While looking for affected code, I discovered WebVTT redefines isHTMLSpace().
I cleaned that code.

Source/WTF:

* wtf/text/AtomicString.h:
(WTF::AtomicString::find):

LayoutTests:

* fast/selectors/attr-list-01-expected.html: Added.
* fast/selectors/attr-list-01.html: Added.
This test is from a similar fix from Opera for the blink fork.
Review URL: https://chromiumcodereview.appspot.com/14980012
No other part of that patch is included.

* fast/selectors/attribute-list-with-whitespace-in-selector-expected.txt: Added.
* fast/selectors/attribute-list-with-whitespace-in-selector.html: Added.
Test whitespace characters in the selector itself.

* fast/selectors/attribute-list-with-whitespace-in-value-expected.txt: Added.
* fast/selectors/attribute-list-with-whitespace-in-value.html: Added.
Test whitespace characters in the attribute value.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@173697 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Add parsing for :nth-child(An+B of selector)
https://bugs.webkit.org/show_bug.cgi?id=136845

Patch by Benjamin Poulain <bpoulain@apple.com> on 2014-09-17
Reviewed by Antti Koivisto.

Source/WebCore:

Add support for parsing :nth-child(of). The implementation of selector matching
will be in a follow up, there are enough edge cases here already.

Spec here: http://dev.w3.org/csswg/selectors4/#the-nth-child-pseudo

Test: fast/css/parsing-css-nth-child-of.html

* css/CSSParser.cpp:
(WebCore::CSSParser::detectFunctionTypeToken):
(WebCore::CSSParser::realLex):
The parser generate two new kinds of tokens:
-NTHCHILDFUNCTION, matching the "nth-child" identifier.
-NTHCHILDSELECTORSEPARATOR, matching the "of" keyword separating An+B from the selector list.

NTHCHILDFUNCTION is used to extend the new syntax only for :nth-child() and not all the "nth" functions
(e.g. :nth-of-type()).

NTHCHILDSELECTORSEPARATOR exists for two reasons:
-We must clear the "parsingMode" before parsing selectorList. If we failed to do that, the complex selectors
 would be parsed in NthChildMode, which has all kind of bad side effects.
-The second reason is differentiacting "of" for all the other identifiers. Arguably, this could have been done
 in the grammar, but it is clearer this way since we already need the branches for the parsingMode.

* css/CSSGrammar.y.in:
Those are pretty much duplicates of the existing FUNCTION rules but supporting the new syntax.

* css/CSSParserValues.cpp:
(WebCore::selectorListMatchesPseudoElement):
(WebCore::CSSParserSelector::matchesPseudoElement):
Matching pseudo elements does not make much sense for those selectorList (e.g. :nth-child(2n of ::before)).
Add helper function to fail parsing of those cases.

* css/CSSParserValues.h:
* css/CSSSelector.cpp:
(WebCore::CSSSelector::selectorText):
* css/CSSSelector.h:
(WebCore::CSSSelector::selectorList):
Updated serialization code for CSS OM.

LayoutTests:

* fast/css/parsing-css-nth-child-of-expected.txt: Added.
* fast/css/parsing-css-nth-child-of.html: Added.
Two new tests to cover the new syntax.

* fast/css/css-selector-text-expected.txt:
* fast/css/css-selector-text.html:
* fast/css/css-set-selector-text-expected.txt:
* fast/css/css-set-selector-text.html:
The usual tests for CSS OM.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@173698 268f45cc-cd09-0410-ab3c-d52691b4dbfc