2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
3 * Copyright (C) 2012 Apple Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above
10 * copyright notice, this list of conditions and the following
12 * 2. Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
26 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #ifndef CSSParserMode_h
32 #define CSSParserMode_h
34 #include "platform/weborigin/KURL.h"
35 #include "platform/weborigin/Referrer.h"
41 // Must not grow beyond 3 bits, due to packing in StylePropertySet.
45 // HTML attributes are parsed in quirks mode but also allows internal properties and values.
47 // SVG attributes are parsed in quirks mode but rules differ slightly.
49 // @viewport rules are parsed in standards mode but CSSOM modifications (via StylePropertySet)
50 // must call parseViewportProperties so needs a special mode.
52 // User agent stylesheets are parsed in standards mode but also allows internal properties and values.
56 inline bool isQuirksModeBehavior(CSSParserMode mode)
58 return mode == HTMLQuirksMode; // || mode == HTMLAttributeMode;
61 inline bool isUASheetBehavior(CSSParserMode mode)
63 return mode == UASheetMode;
66 inline bool isInternalPropertyAndValueParsingEnabledForMode(CSSParserMode mode)
68 return mode == HTMLAttributeMode || mode == UASheetMode;
71 inline bool isUnitLessLengthParsingEnabledForMode(CSSParserMode mode)
73 return mode == HTMLQuirksMode || mode == HTMLAttributeMode || mode == SVGAttributeMode;
76 inline bool isCSSViewportParsingEnabledForMode(CSSParserMode mode)
78 return mode == CSSViewportRuleMode;
81 inline bool isSVGNumberParsingEnabledForMode(CSSParserMode mode)
83 return mode == SVGAttributeMode;
86 inline bool isUseCounterEnabledForMode(CSSParserMode mode)
88 // We don't count the UA style sheet in our statistics.
89 return mode != UASheetMode;
94 class CSSParserContext {
95 WTF_MAKE_FAST_ALLOCATED;
97 CSSParserContext(CSSParserMode, UseCounter*);
98 // FIXME: We shouldn't need the UseCounter argument as we could infer it from the Document
99 // but some callers want to disable use counting (e.g. the WebInspector).
100 CSSParserContext(const Document&, UseCounter*, const KURL& baseURL = KURL(), const String& charset = emptyString());
101 // FIXME: This constructor shouldn't exist if we properly piped the UseCounter through the CSS
102 // subsystem. Currently the UseCounter life time is too crazy and we need a way to override it.
103 CSSParserContext(const CSSParserContext&, UseCounter*);
105 bool operator==(const CSSParserContext&) const;
106 bool operator!=(const CSSParserContext& other) const { return !(*this == other); }
108 CSSParserMode mode() const { return m_mode; }
109 const KURL& baseURL() const { return m_baseURL; }
110 const String& charset() const { return m_charset; }
111 const Referrer& referrer() const { return m_referrer; }
112 bool isHTMLDocument() const { return m_isHTMLDocument; }
114 // This quirk is to maintain compatibility with Android apps built on
115 // the Android SDK prior to and including version 18. Presumably, this
116 // can be removed any time after 2015. See http://crbug.com/277157.
117 bool useLegacyBackgroundSizeShorthandBehavior() const { return m_useLegacyBackgroundSizeShorthandBehavior; }
119 // FIXME: These setters shouldn't exist, however the current lifetime of CSSParserContext
120 // is not well understood and thus we sometimes need to override these fields.
121 void setMode(CSSParserMode mode) { m_mode = mode; }
122 void setBaseURL(const KURL& baseURL) { m_baseURL = baseURL; }
123 void setCharset(const String& charset) { m_charset = charset; }
124 void setReferrer(const Referrer& referrer) { m_referrer = referrer; }
126 KURL completeURL(const String& url) const;
128 UseCounter* useCounter() const { return m_useCounter; }
133 CSSParserMode m_mode;
135 bool m_isHTMLDocument;
136 bool m_useLegacyBackgroundSizeShorthandBehavior;
138 UseCounter* m_useCounter;
141 const CSSParserContext& strictCSSParserContext();
145 #endif // CSSParserMode_h