source: webkit/trunk/Source/WebCore/css/parser/CSSParserObserverWrapper.cpp

Last change on this file was 205103, checked in by [email protected], 9 years ago

Initial landing of CSS Parser Tokenization (and files to support that). Not used yet.
https://bugs.webkit.org/show_bug.cgi?id=161174

This code is imported from Blink and is their CSS parser (modified to work in WebKit).
It is from commit e4bb90df7f2ed8a63975b5ed27a1b488cb9b146f, Mon Aug 22 2016.

Reviewed by Simon Fraser.

  • CMakeLists.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • css/CSSMarkup.cpp: Added.

(WebCore::isCSSTokenizerIdentifier):
(WebCore::serializeCharacter):
(WebCore::serializeCharacterAsCodePoint):
(WebCore::serializeIdentifier):
(WebCore::serializeString):
(WebCore::serializeURI):
(WebCore::serializeFontFamily):

  • css/CSSMarkup.h: Added.
  • css/CSSOMUtils.cpp: Removed.
  • css/CSSOMUtils.h: Removed.
  • css/CSSSelector.cpp:
  • css/parser/CSSParserFastPaths.cpp: Added.
  • css/parser/CSSParserFastPaths.h: Added.
  • css/parser/CSSParserIdioms.h: Added.

(WebCore::isCSSSpace):
(WebCore::isNameStartCodePoint):
(WebCore::isNameCodePoint):

  • css/parser/CSSParserObserver.h: Added.

(WebCore::CSSParserObserver::~CSSParserObserver):

  • css/parser/CSSParserObserverWrapper.cpp: Added.

(WebCore::CSSParserObserverWrapper::startOffset):
(WebCore::CSSParserObserverWrapper::previousTokenStartOffset):
(WebCore::CSSParserObserverWrapper::endOffset):
(WebCore::CSSParserObserverWrapper::skipCommentsBefore):
(WebCore::CSSParserObserverWrapper::yieldCommentsBefore):

  • css/parser/CSSParserObserverWrapper.h: Added.

(WebCore::CSSParserObserverWrapper::CSSParserObserverWrapper):
(WebCore::CSSParserObserverWrapper::observer):
(WebCore::CSSParserObserverWrapper::addComment):
(WebCore::CSSParserObserverWrapper::addToken):
(WebCore::CSSParserObserverWrapper::finalizeConstruction):

  • css/parser/CSSParserToken.cpp: Added.

(WebCore::cssPrimitiveValueUnitFromTrie):
(WebCore::stringToUnitType):
(WebCore::CSSParserToken::CSSParserToken):
(WebCore::CSSParserToken::convertToDimensionWithUnit):
(WebCore::CSSParserToken::convertToPercentage):
(WebCore::CSSParserToken::delimiter):
(WebCore::CSSParserToken::numericSign):
(WebCore::CSSParserToken::numericValueType):
(WebCore::CSSParserToken::numericValue):
(WebCore::CSSParserToken::parseAsUnresolvedCSSPropertyID):
(WebCore::CSSParserToken::id):
(WebCore::CSSParserToken::functionId):
(WebCore::CSSParserToken::hasStringBacking):
(WebCore::CSSParserToken::copyWithUpdatedString):
(WebCore::CSSParserToken::valueDataCharRawEqual):
(WebCore::CSSParserToken::operator==):
(WebCore::CSSParserToken::serialize):

  • css/parser/CSSParserToken.h: Added.

(WebCore::CSSParserToken::operator!=):
(WebCore::CSSParserToken::type):
(WebCore::CSSParserToken::value):
(WebCore::CSSParserToken::getHashTokenType):
(WebCore::CSSParserToken::getBlockType):
(WebCore::CSSParserToken::unitType):
(WebCore::CSSParserToken::unicodeRangeStart):
(WebCore::CSSParserToken::unicodeRangeEnd):
(WebCore::CSSParserToken::initValueFromStringView):

  • css/parser/CSSParserTokenRange.cpp: Added.

(WebCore::CSSParserTokenRange::eofToken):
(WebCore::CSSParserTokenRange::makeSubRange):
(WebCore::CSSParserTokenRange::consumeBlock):
(WebCore::CSSParserTokenRange::consumeComponentValue):
(WebCore::CSSParserTokenRange::serialize):

  • css/parser/CSSParserTokenRange.h: Added.

(WebCore::CSSParserTokenRange::CSSParserTokenRange):
(WebCore::CSSParserTokenRange::atEnd):
(WebCore::CSSParserTokenRange::end):
(WebCore::CSSParserTokenRange::peek):
(WebCore::CSSParserTokenRange::consume):
(WebCore::CSSParserTokenRange::consumeIncludingWhitespace):
(WebCore::CSSParserTokenRange::consumeWhitespace):
(WebCore::CSSParserTokenRange::begin):

  • css/parser/CSSPropertyParser.cpp: Added.

(WebCore::hasPrefix):
(WebCore::cssPropertyID):
(WebCore::cssPropertyNameIOSAliasing):
(WebCore::isAppleLegacyCssValueKeyword):
(WebCore::cssValueKeywordID):
(WebCore::unresolvedCSSPropertyID):

  • css/parser/CSSPropertyParser.h: Added.

(WebCore::CSSPropertyParser::inQuirksMode):

  • css/parser/CSSPropertyParserHelpers.cpp: Added.
  • css/parser/CSSPropertyParserHelpers.h: Added.

(WebCore::CSSPropertyParserHelpers::identMatches):
(WebCore::CSSPropertyParserHelpers::consumeIdent):
(WebCore::CSSPropertyParserHelpers::isCSSWideKeyword):

  • css/parser/CSSTokenizer.cpp: Added.

(WebCore::CSSTokenizer::Scope::Scope):
(WebCore::CSSTokenizer::Scope::tokenRange):
(WebCore::CSSTokenizer::Scope::tokenCount):
(WebCore::isNewLine):
(WebCore::twoCharsAreValidEscape):
(WebCore::CSSTokenizer::CSSTokenizer):
(WebCore::CSSTokenizer::reconsume):
(WebCore::CSSTokenizer::consume):
(WebCore::CSSTokenizer::whiteSpace):
(WebCore::CSSTokenizer::blockStart):
(WebCore::CSSTokenizer::blockEnd):
(WebCore::CSSTokenizer::leftParenthesis):
(WebCore::CSSTokenizer::rightParenthesis):
(WebCore::CSSTokenizer::leftBracket):
(WebCore::CSSTokenizer::rightBracket):
(WebCore::CSSTokenizer::leftBrace):
(WebCore::CSSTokenizer::rightBrace):
(WebCore::CSSTokenizer::plusOrFullStop):
(WebCore::CSSTokenizer::asterisk):
(WebCore::CSSTokenizer::lessThan):
(WebCore::CSSTokenizer::comma):
(WebCore::CSSTokenizer::hyphenMinus):
(WebCore::CSSTokenizer::solidus):
(WebCore::CSSTokenizer::colon):
(WebCore::CSSTokenizer::semiColon):
(WebCore::CSSTokenizer::hash):
(WebCore::CSSTokenizer::circumflexAccent):
(WebCore::CSSTokenizer::dollarSign):
(WebCore::CSSTokenizer::verticalLine):
(WebCore::CSSTokenizer::tilde):
(WebCore::CSSTokenizer::commercialAt):
(WebCore::CSSTokenizer::reverseSolidus):
(WebCore::CSSTokenizer::asciiDigit):
(WebCore::CSSTokenizer::letterU):
(WebCore::CSSTokenizer::nameStart):
(WebCore::CSSTokenizer::stringStart):
(WebCore::CSSTokenizer::endOfFile):
(WebCore::CSSTokenizer::nextToken):
(WebCore::CSSTokenizer::consumeNumber):
(WebCore::CSSTokenizer::consumeNumericToken):
(WebCore::CSSTokenizer::consumeIdentLikeToken):
(WebCore::CSSTokenizer::consumeStringTokenUntil):
(WebCore::CSSTokenizer::consumeUnicodeRange):
(WebCore::isNonPrintableCodePoint):
(WebCore::CSSTokenizer::consumeUrlToken):
(WebCore::CSSTokenizer::consumeBadUrlRemnants):
(WebCore::CSSTokenizer::consumeSingleWhitespaceIfNext):
(WebCore::CSSTokenizer::consumeUntilCommentEndFound):
(WebCore::CSSTokenizer::consumeIfNext):
(WebCore::CSSTokenizer::consumeName):
(WebCore::CSSTokenizer::consumeEscape):
(WebCore::CSSTokenizer::nextTwoCharsAreValidEscape):
(WebCore::CSSTokenizer::nextCharsAreNumber):
(WebCore::CSSTokenizer::nextCharsAreIdentifier):
(WebCore::CSSTokenizer::registerString):

  • css/parser/CSSTokenizer.h: Added.

(WebCore::CSSTokenizer::Scope::storeString):

  • css/parser/CSSTokenizerInputStream.cpp: Added.

(WebCore::CSSTokenizerInputStream::CSSTokenizerInputStream):
(WebCore::CSSTokenizerInputStream::advanceUntilNonWhitespace):
(WebCore::CSSTokenizerInputStream::getDouble):

  • css/parser/CSSTokenizerInputStream.h: Added.

(WebCore::CSSTokenizerInputStream::nextInputChar):
(WebCore::CSSTokenizerInputStream::peekWithoutReplacement):
(WebCore::CSSTokenizerInputStream::advance):
(WebCore::CSSTokenizerInputStream::pushBack):
(WebCore::CSSTokenizerInputStream::skipWhilePredicate):
(WebCore::CSSTokenizerInputStream::length):
(WebCore::CSSTokenizerInputStream::offset):
(WebCore::CSSTokenizerInputStream::rangeAt):

  • platform/Length.h:
File size: 3.0 KB
Line 
1// Copyright 2015 The Chromium Authors. All rights reserved.
2// Copyright (C) 2016 Apple Inc. All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30#include "config.h"
31#include "CSSParserObserverWrapper.h"
32
33#include "CSSParserTokenRange.h"
34
35namespace WebCore {
36
37unsigned CSSParserObserverWrapper::startOffset(const CSSParserTokenRange& range)
38{
39 return m_tokenOffsets[range.begin() - m_firstParserToken];
40}
41
42unsigned CSSParserObserverWrapper::previousTokenStartOffset(const CSSParserTokenRange& range)
43{
44 if (range.begin() == m_firstParserToken)
45 return 0;
46 return m_tokenOffsets[range.begin() - m_firstParserToken - 1];
47}
48
49unsigned CSSParserObserverWrapper::endOffset(const CSSParserTokenRange& range)
50{
51 return m_tokenOffsets[range.end() - m_firstParserToken];
52}
53
54void CSSParserObserverWrapper::skipCommentsBefore(const CSSParserTokenRange& range, bool leaveDirectlyBefore)
55{
56 unsigned startIndex = range.begin() - m_firstParserToken;
57 if (!leaveDirectlyBefore)
58 startIndex++;
59 while (m_commentIterator < m_commentOffsets.end() && m_commentIterator->tokensBefore < startIndex)
60 m_commentIterator++;
61}
62
63void CSSParserObserverWrapper::yieldCommentsBefore(const CSSParserTokenRange& range)
64{
65 unsigned startIndex = range.begin() - m_firstParserToken;
66 while (m_commentIterator < m_commentOffsets.end() && m_commentIterator->tokensBefore <= startIndex) {
67 m_observer.observeComment(m_commentIterator->startOffset, m_commentIterator->endOffset);
68 m_commentIterator++;
69 }
70}
71
72} // namespace WebCore
Note: See TracBrowser for help on using the repository browser.