1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
|
/*
* Copyright (C) 2003 Lars Knoll (knoll@kde.org)
* Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010 Apple Inc. All rights reserved.
* Copyright (C) 2008 Eric Seidel <eric@webkit.org>
* Copyright (C) 2009 - 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef BisonCSSParser_h
#define BisonCSSParser_h
#include "core/CSSPropertyNames.h"
#include "core/CSSValueKeywords.h"
#include "core/css/CSSCalculationValue.h"
#include "core/css/CSSFilterValue.h"
#include "core/css/CSSGradientValue.h"
#include "core/css/CSSParserMode.h"
#include "core/css/CSSParserValues.h"
#include "core/css/CSSProperty.h"
#include "core/css/CSSPropertySourceData.h"
#include "core/css/CSSSelector.h"
#include "core/css/CSSTokenizer.h"
#include "core/css/MediaQuery.h"
#include "core/css/StylePropertySet.h"
#include "core/css/parser/CSSParserObserver.h"
#include "core/css/parser/CSSPropertyParser.h"
#include "platform/graphics/Color.h"
#include "wtf/HashSet.h"
#include "wtf/OwnPtr.h"
#include "wtf/Vector.h"
#include "wtf/text/AtomicString.h"
#include "wtf/text/TextPosition.h"
namespace WebCore {
class AnimationParseContext;
class CSSArrayFunctionValue;
class CSSBorderImageSliceValue;
class CSSPrimitiveValue;
class CSSSelectorList;
class CSSValue;
class CSSValueList;
class CSSBasicShape;
class CSSBasicShapeInset;
class Document;
class Element;
class ImmutableStylePropertySet;
class MediaQueryExp;
class MediaQuerySet;
class MutableStylePropertySet;
class StyleKeyframe;
class StylePropertyShorthand;
class StyleRuleBase;
class StyleRuleKeyframes;
class StyleKeyframe;
class StyleSheetContents;
class UseCounter;
// FIXME: This class is shared with CSSTokenizer so should we rename it to CSSSourceLocation?
struct CSSParserLocation {
unsigned offset;
unsigned lineNumber;
CSSParserString token;
};
class BisonCSSParser {
STACK_ALLOCATED();
friend inline int cssyylex(void*, BisonCSSParser*);
public:
explicit BisonCSSParser(const CSSParserContext&);
~BisonCSSParser();
void rollbackLastProperties(int num);
void setCurrentProperty(CSSPropertyID);
void parseSheet(StyleSheetContents*, const String&, const TextPosition& startPosition = TextPosition::minimumPosition(), CSSParserObserver* = 0, bool = false);
PassRefPtrWillBeRawPtr<StyleRuleBase> parseRule(StyleSheetContents*, const String&);
PassRefPtrWillBeRawPtr<StyleKeyframe> parseKeyframeRule(StyleSheetContents*, const String&);
bool parseSupportsCondition(const String&);
static bool parseValue(MutableStylePropertySet*, CSSPropertyID, const String&, bool important, CSSParserMode, StyleSheetContents*);
static bool parseColor(RGBA32& color, const String&, bool strict = false);
static bool parseSystemColor(RGBA32& color, const String&);
static PassRefPtrWillBeRawPtr<CSSValueList> parseFontFaceValue(const AtomicString&);
static PassRefPtrWillBeRawPtr<CSSValue> parseAnimationTimingFunctionValue(const String&);
bool parseDeclaration(MutableStylePropertySet*, const String&, CSSParserObserver*, StyleSheetContents* contextStyleSheet);
static PassRefPtr<ImmutableStylePropertySet> parseInlineStyleDeclaration(const String&, Element*);
PassRefPtrWillBeRawPtr<MediaQuerySet> parseMediaQueryList(const String&);
PassOwnPtr<Vector<double> > parseKeyframeKeyList(const String&);
static bool parseValue(MutableStylePropertySet*, CSSPropertyID, const String&, bool important, const Document&);
bool parseValue(CSSPropertyID, bool important);
void parseSelector(const String&, CSSSelectorList&);
CSSParserSelector* createFloatingSelector();
CSSParserSelector* createFloatingSelectorWithTagName(const QualifiedName&);
PassOwnPtr<CSSParserSelector> sinkFloatingSelector(CSSParserSelector*);
Vector<OwnPtr<CSSParserSelector> >* createFloatingSelectorVector();
PassOwnPtr<Vector<OwnPtr<CSSParserSelector> > > sinkFloatingSelectorVector(Vector<OwnPtr<CSSParserSelector> >*);
CSSParserValueList* createFloatingValueList();
PassOwnPtr<CSSParserValueList> sinkFloatingValueList(CSSParserValueList*);
CSSParserFunction* createFloatingFunction();
CSSParserFunction* createFloatingFunction(const CSSParserString& name, PassOwnPtr<CSSParserValueList> args);
PassOwnPtr<CSSParserFunction> sinkFloatingFunction(CSSParserFunction*);
CSSParserValue& sinkFloatingValue(CSSParserValue&);
MediaQuerySet* createMediaQuerySet();
StyleRuleBase* createImportRule(const CSSParserString&, MediaQuerySet*);
StyleKeyframe* createKeyframe(CSSParserValueList*);
StyleRuleKeyframes* createKeyframesRule(const String&, PassOwnPtrWillBeRawPtr<WillBeHeapVector<RefPtrWillBeMember<StyleKeyframe> > >, bool isPrefixed);
typedef WillBeHeapVector<RefPtrWillBeMember<StyleRuleBase> > RuleList;
StyleRuleBase* createMediaRule(MediaQuerySet*, RuleList*);
RuleList* createRuleList();
RuleList* appendRule(RuleList*, StyleRuleBase*);
StyleRuleBase* createStyleRule(Vector<OwnPtr<CSSParserSelector> >* selectors);
StyleRuleBase* createFontFaceRule();
StyleRuleBase* createPageRule(PassOwnPtr<CSSParserSelector> pageSelector);
StyleRuleBase* createMarginAtRule(CSSSelector::MarginBoxType);
StyleRuleBase* createSupportsRule(bool conditionIsSupported, RuleList*);
void markSupportsRuleHeaderStart();
void markSupportsRuleHeaderEnd();
PassRefPtrWillBeRawPtr<CSSRuleSourceData> popSupportsRuleData();
StyleRuleBase* createHostRule(RuleList* rules);
void startDeclarationsForMarginBox();
void endDeclarationsForMarginBox();
MediaQueryExp* createFloatingMediaQueryExp(const AtomicString&, CSSParserValueList*);
PassOwnPtrWillBeRawPtr<MediaQueryExp> sinkFloatingMediaQueryExp(MediaQueryExp*);
WillBeHeapVector<OwnPtrWillBeMember<MediaQueryExp> >* createFloatingMediaQueryExpList();
PassOwnPtrWillBeRawPtr<WillBeHeapVector<OwnPtrWillBeMember<MediaQueryExp> > > sinkFloatingMediaQueryExpList(WillBeHeapVector<OwnPtrWillBeMember<MediaQueryExp> >*);
MediaQuery* createFloatingMediaQuery(MediaQuery::Restrictor, const AtomicString&, PassOwnPtrWillBeRawPtr<WillBeHeapVector<OwnPtrWillBeMember<MediaQueryExp> > >);
MediaQuery* createFloatingMediaQuery(PassOwnPtrWillBeRawPtr<WillBeHeapVector<OwnPtrWillBeMember<MediaQueryExp> > >);
MediaQuery* createFloatingNotAllQuery();
PassOwnPtrWillBeRawPtr<MediaQuery> sinkFloatingMediaQuery(MediaQuery*);
WillBeHeapVector<RefPtrWillBeMember<StyleKeyframe> >* createFloatingKeyframeVector();
PassOwnPtrWillBeRawPtr<WillBeHeapVector<RefPtrWillBeMember<StyleKeyframe> > > sinkFloatingKeyframeVector(WillBeHeapVector<RefPtrWillBeMember<StyleKeyframe> >*);
void addNamespace(const AtomicString& prefix, const AtomicString& uri);
QualifiedName determineNameInNamespace(const AtomicString& prefix, const AtomicString& localName);
CSSParserSelector* rewriteSpecifiersWithElementName(const AtomicString& namespacePrefix, const AtomicString& elementName, CSSParserSelector*, bool isNamespacePlaceholder = false);
CSSParserSelector* rewriteSpecifiersWithElementNameForCustomPseudoElement(const QualifiedName& tag, const AtomicString& elementName, CSSParserSelector* specifiers, bool tagIsForNamespaceRule);
CSSParserSelector* rewriteSpecifiersWithElementNameForContentPseudoElement(const QualifiedName& tag, const AtomicString& elementName, CSSParserSelector* specifiers, bool tagIsForNamespaceRule);
CSSParserSelector* rewriteSpecifiersWithNamespaceIfNeeded(CSSParserSelector*);
CSSParserSelector* rewriteSpecifiers(CSSParserSelector*, CSSParserSelector*);
CSSParserSelector* rewriteSpecifiersForShadowDistributed(CSSParserSelector* specifiers, CSSParserSelector* distributedPseudoElementSelector);
void invalidBlockHit();
Vector<OwnPtr<CSSParserSelector> >* reusableSelectorVector() { return &m_reusableSelectorVector; }
void clearProperties();
PassRefPtr<ImmutableStylePropertySet> createStylePropertySet();
CSSParserContext m_context;
bool m_important;
CSSPropertyID m_id;
RawPtrWillBeMember<StyleSheetContents> m_styleSheet;
RefPtrWillBeMember<StyleRuleBase> m_rule;
RefPtrWillBeMember<StyleKeyframe> m_keyframe;
RefPtrWillBeMember<MediaQuerySet> m_mediaList;
OwnPtr<CSSParserValueList> m_valueList;
bool m_supportsCondition;
WillBeHeapVector<CSSProperty, 256> m_parsedProperties;
CSSSelectorList* m_selectorListForParseSelector;
unsigned m_numParsedPropertiesBeforeMarginBox;
bool m_hadSyntacticallyValidCSSRule;
bool m_logErrors;
bool m_ignoreErrors;
AtomicString m_defaultNamespace;
// tokenizer methods and data
CSSParserObserver* m_observer;
// Local functions which just call into CSSParserObserver if non-null.
void startRule();
void endRule(bool valid);
void startRuleHeader(CSSRuleSourceData::Type);
void endRuleHeader();
void startSelector();
void endSelector();
void startRuleBody();
void startProperty();
void endProperty(bool isImportantFound, bool isPropertyParsed, CSSParserError = NoCSSError);
void startEndUnknownRule();
void endInvalidRuleHeader();
void reportError(const CSSParserLocation&, CSSParserError = GeneralCSSError);
void resumeErrorLogging() { m_ignoreErrors = false; }
void setLocationLabel(const CSSParserLocation& location) { m_locationLabel = location; }
const CSSParserLocation& lastLocationLabel() const { return m_locationLabel; }
void tokenToLowerCase(CSSParserString& token);
void markViewportRuleBodyStart() { m_inViewport = true; }
void markViewportRuleBodyEnd() { m_inViewport = false; }
StyleRuleBase* createViewportRule();
CSSParserLocation currentLocation() { return m_tokenizer.currentLocation(); }
private:
class StyleDeclarationScope {
STACK_ALLOCATED();
WTF_MAKE_NONCOPYABLE(StyleDeclarationScope);
public:
StyleDeclarationScope(BisonCSSParser* parser, const StylePropertySet* declaration)
: m_parser(parser)
, m_mode(declaration->cssParserMode())
{
if (isCSSViewportParsingEnabledForMode(m_mode)) {
ASSERT(!m_parser->inViewport());
m_parser->markViewportRuleBodyStart();
}
}
~StyleDeclarationScope()
{
if (isCSSViewportParsingEnabledForMode(m_mode))
m_parser->markViewportRuleBodyEnd();
}
private:
BisonCSSParser* m_parser;
CSSParserMode m_mode;
};
inline void ensureLineEndings();
void setStyleSheet(StyleSheetContents* styleSheet) { m_styleSheet = styleSheet; }
bool inViewport() const { return m_inViewport; }
void recheckAtKeyword(const UChar* str, int len);
template<unsigned prefixLength, unsigned suffixLength>
inline void setupParser(const char (&prefix)[prefixLength], const String& string, const char (&suffix)[suffixLength])
{
setupParser(prefix, prefixLength - 1, string, suffix, suffixLength - 1);
}
void setupParser(const char* prefix, unsigned prefixLength, const String&, const char* suffix, unsigned suffixLength);
bool parseValue(MutableStylePropertySet*, CSSPropertyID, const String&, bool important, StyleSheetContents* contextStyleSheet);
PassRefPtr<ImmutableStylePropertySet> parseDeclaration(const String&, StyleSheetContents* contextStyleSheet);
bool parseColor(const String&);
const String* m_source;
TextPosition m_startPosition;
CSSRuleSourceData::Type m_ruleHeaderType;
unsigned m_ruleHeaderStartOffset;
int m_ruleHeaderStartLineNumber;
OwnPtr<Vector<unsigned> > m_lineEndings;
bool m_ruleHasHeader;
bool m_allowImportRules;
bool m_allowNamespaceDeclarations;
bool m_inViewport;
CSSParserLocation m_locationLabel;
WillBeHeapVector<RefPtrWillBeMember<StyleRuleBase> > m_parsedRules;
WillBeHeapVector<RefPtrWillBeMember<StyleKeyframe> > m_parsedKeyframes;
WillBeHeapVector<RefPtrWillBeMember<MediaQuerySet> > m_parsedMediaQuerySets;
WillBeHeapVector<OwnPtrWillBeMember<RuleList> > m_parsedRuleLists;
Vector<CSSParserSelector*> m_floatingSelectors;
Vector<Vector<OwnPtr<CSSParserSelector> >*> m_floatingSelectorVectors;
Vector<CSSParserValueList*> m_floatingValueLists;
Vector<CSSParserFunction*> m_floatingFunctions;
OwnPtrWillBeMember<MediaQuery> m_floatingMediaQuery;
OwnPtrWillBeMember<MediaQueryExp> m_floatingMediaQueryExp;
OwnPtrWillBeMember<WillBeHeapVector<OwnPtrWillBeMember<MediaQueryExp> > > m_floatingMediaQueryExpList;
OwnPtrWillBeMember<WillBeHeapVector<RefPtrWillBeMember<StyleKeyframe> > > m_floatingKeyframeVector;
Vector<OwnPtr<CSSParserSelector> > m_reusableSelectorVector;
OwnPtrWillBeMember<RuleSourceDataList> m_supportsRuleDataStack;
bool isLoggingErrors();
void logError(const String& message, const CSSParserLocation&);
CSSTokenizer m_tokenizer;
friend class TransformOperationInfo;
friend class FilterOperationInfo;
};
inline int cssyylex(void* yylval, BisonCSSParser* parser)
{
return parser->m_tokenizer.lex(yylval);
}
bool isValidNthToken(const CSSParserString&);
} // namespace WebCore
#endif // BisonCSSParser_h
|