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

Last change on this file was 294007, checked in by Brent Fulgham, 3 years ago

Remove abandoned CSSDeferredParser implementation and feature flag
https://bugs.webkit.org/show_bug.cgi?id=240244

Reviewed by Antti Koivisto.

This patch rolls out the abandoned CSSDeferredParser implementation added in Bug 165743.

Source/WebCore:

  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • css/CSSKeyframesRule.cpp:

(WebCore::StyleRuleKeyframes::keyframes const):
(WebCore::StyleRuleKeyframes::wrapperAppendKeyframe):
(WebCore::StyleRuleKeyframes::wrapperRemoveKeyframe):
(WebCore::StyleRuleKeyframes::findKeyframeIndex const):
(WebCore::StyleRuleKeyframes::parseDeferredRulesIfNeeded const): Deleted.

  • css/CSSKeyframesRule.h:
  • css/StyleProperties.cpp:

(WebCore::MutableStyleProperties::MutableStyleProperties):
(WebCore::StyleProperties::PropertyReference::cssText const):
(WebCore::DeferredStyleProperties::create): Deleted.
(WebCore::DeferredStyleProperties::DeferredStyleProperties): Deleted.
(WebCore::DeferredStyleProperties::parseDeferredProperties): Deleted.

  • css/StyleProperties.h:

(WebCore::StylePropertiesBase::deref const):
(isType):

  • css/StyleRule.cpp:

(WebCore::StyleRule::properties const):
(WebCore::StyleRuleGroup::childRules const):
(WebCore::StyleRuleGroup::wrapperInsertRule):
(WebCore::StyleRuleGroup::wrapperRemoveRule):
(WebCore::DeferredStyleGroupRuleList::DeferredStyleGroupRuleList): Deleted.
(WebCore::DeferredStyleGroupRuleList::parseDeferredRules): Deleted.
(WebCore::DeferredStyleGroupRuleList::parseDeferredKeyframes): Deleted.
(WebCore::StyleRuleGroup::parseDeferredRulesIfNeeded const): Deleted.

  • css/StyleRule.h:

(WebCore::StyleRule::propertiesWithoutDeferredParsing const): Deleted.
(WebCore::StyleRuleGroup::childRulesWithoutDeferredParsing const): Deleted.

  • css/StyleSheetContents.cpp:

(WebCore::StyleSheetContents::parseAuthorStyleSheet):
(WebCore::StyleSheetContents::parseString):
(WebCore::traverseRulesInVector):
(WebCore::StyleSheetContents::traverseSubresources const):

  • css/parser/CSSDeferredParser.cpp: Removed.
  • css/parser/CSSDeferredParser.h: Removed.
  • css/parser/CSSParser.cpp:

(WebCore::CSSParser::parseSheet):

  • css/parser/CSSParser.h:
  • css/parser/CSSParserContext.cpp:

(WebCore::operator==):
(WebCore::add):

  • css/parser/CSSParserContext.h:
  • css/parser/CSSParserImpl.cpp:

(WebCore::CSSParserImpl::CSSParserImpl):
(WebCore::CSSParserImpl::parseStyleSheet):
(WebCore::CSSParserImpl::consumeMediaRule):
(WebCore::CSSParserImpl::consumeSupportsRule):
(WebCore::CSSParserImpl::consumeKeyframesRule):
(WebCore::CSSParserImpl::consumeLayerRule):
(WebCore::CSSParserImpl::consumeContainerRule):
(WebCore::CSSParserImpl::consumeStyleRule):
(WebCore::CSSParserImpl::createDeferredStyleProperties): Deleted.
(WebCore::CSSParserImpl::parseDeferredDeclaration): Deleted.
(WebCore::CSSParserImpl::parseDeferredRuleList): Deleted.
(WebCore::CSSParserImpl::parseDeferredKeyframeList): Deleted.
(WebCore::CSSParserImpl::adoptTokenizerEscapedStrings): Deleted.

  • css/parser/CSSParserImpl.h:

(WebCore::CSSParserImpl::tokenizer const):
(WebCore::CSSParserImpl::deferredParser const): Deleted.

  • style/ElementRuleCollector.cpp:

(WebCore::Style::ElementRuleCollector::collectMatchingRulesForList):

  • style/StyleInvalidator.cpp:

(WebCore::Style::shouldDirtyAllStyle):

  • testing/Internals.cpp:

(WebCore::deferredStyleRulesCountForList): Deleted.
(WebCore::Internals::deferredStyleRulesCount): Deleted.
(WebCore::deferredGroupRulesCountForList): Deleted.
(WebCore::Internals::deferredGroupRulesCount): Deleted.
(WebCore::deferredKeyframesRulesCountForList): Deleted.
(WebCore::Internals::deferredKeyframesRulesCount): Deleted.

  • testing/Internals.h:
  • testing/Internals.idl:

Source/WebKit:

  • UIProcess/API/C/WKPreferences.cpp:

(WKPreferencesSetDeferredCSSParserEnabled): Deleted.
(WKPreferencesGetDeferredCSSParserEnabled): Deleted.

  • UIProcess/API/C/WKPreferencesRefPrivate.h:

Source/WTF:

  • Scripts/Preferences/WebPreferences.yaml:

LayoutTests:

  • fast/css/deferred-parsing/dynamic-external-style-expected.txt: Removed.
  • fast/css/deferred-parsing/dynamic-external-style.html: Removed.
  • fast/css/deferred-parsing/dynamic-style-in-document-expected.txt: Removed.
  • fast/css/deferred-parsing/dynamic-style-in-document.html: Removed.
  • fast/css/deferred-parsing/hover-test-expected.txt: Removed.
  • fast/css/deferred-parsing/hover-test.html: Removed.
  • fast/css/deferred-parsing/keyframes-rule-expected.txt: Removed.
  • fast/css/deferred-parsing/keyframes-rule.html: Removed.
  • fast/css/deferred-parsing/media-print-expected.txt: Removed.
  • fast/css/deferred-parsing/media-print.html: Removed.
  • fast/css/deferred-parsing/nth-of-type-expected.txt: Removed.
  • fast/css/deferred-parsing/nth-of-type.html: Removed.
  • fast/css/deferred-parsing/resources/basic-sheet.css: Removed.
  • fast/css/deferred-parsing/simple-external-style-expected.txt: Removed.
  • fast/css/deferred-parsing/simple-external-style.html: Removed.
  • fast/css/deferred-parsing/simple-style-in-document-expected.txt: Removed.
  • fast/css/deferred-parsing/simple-style-in-document.html: Removed.
  • fast/css/deferred-parsing/supports-rule-expected.txt: Removed.
  • fast/css/deferred-parsing/supports-rule.html: Removed.
  • platform/ios-wk2/TestExpectations:
  • platform/ios/TestExpectations:
  • Property svn:eol-style set to native
File size: 10.0 KB
Line 
1/*
2 * Copyright (C) 2003 Lars Knoll ([email protected])
3 * Copyright (C) 2005 Allan Sandfeld Jensen ([email protected])
4 * Copyright (C) 2004-2022 Apple Inc. All rights reserved.
5 * Copyright (C) 2007 Nicholas Shanks <[email protected]>
6 * Copyright (C) 2008 Eric Seidel <[email protected]>
7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
8 * Copyright (C) 2012, 2013 Adobe Systems Incorporated. All rights reserved.
9 * Copyright (C) 2012 Intel Corporation. All rights reserved.
10 * Copyright (C) 2014 Google Inc. All rights reserved.
11 *
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
16 *
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
21 *
22 * You should have received a copy of the GNU Library General Public License
23 * along with this library; see the file COPYING.LIB. If not, write to
24 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 * Boston, MA 02110-1301, USA.
26 */
27
28#include "config.h"
29#include "CSSParser.h"
30
31#include "CSSCustomPropertyValue.h"
32#include "CSSKeyframeRule.h"
33#include "CSSParserFastPaths.h"
34#include "CSSParserImpl.h"
35#include "CSSParserTokenRange.h"
36#include "CSSPendingSubstitutionValue.h"
37#include "CSSPropertyParser.h"
38#include "CSSPropertyParserHelpers.h"
39#include "CSSSelectorParser.h"
40#include "CSSSupportsParser.h"
41#include "CSSTokenizer.h"
42#include "CSSValuePool.h"
43#include "CSSVariableData.h"
44#include "CSSVariableReferenceValue.h"
45#include "Document.h"
46#include "Element.h"
47#include "Page.h"
48#include "RenderStyle.h"
49#include "RenderTheme.h"
50#include "Settings.h"
51#include "StyleBuilder.h"
52#include "StyleColor.h"
53#include "StyleResolver.h"
54#include "StyleRule.h"
55#include "StyleSheetContents.h"
56#include <wtf/NeverDestroyed.h>
57#include <wtf/text/StringBuilder.h>
58
59namespace WebCore {
60
61CSSParser::CSSParser(const CSSParserContext& context)
62 : m_context(context)
63{
64}
65
66CSSParser::~CSSParser() = default;
67
68void CSSParser::parseSheet(StyleSheetContents& sheet, const String& string)
69{
70 return CSSParserImpl::parseStyleSheet(string, m_context, sheet);
71}
72
73void CSSParser::parseSheetForInspector(const CSSParserContext& context, StyleSheetContents* sheet, const String& string, CSSParserObserver& observer)
74{
75 return CSSParserImpl::parseStyleSheetForInspector(string, context, sheet, observer);
76}
77
78RefPtr<StyleRuleBase> CSSParser::parseRule(const CSSParserContext& context, StyleSheetContents* sheet, const String& string)
79{
80 return CSSParserImpl::parseRule(string, context, sheet, CSSParserImpl::AllowImportRules);
81}
82
83RefPtr<StyleRuleKeyframe> CSSParser::parseKeyframeRule(const String& string)
84{
85 RefPtr<StyleRuleBase> keyframe = CSSParserImpl::parseRule(string, m_context, nullptr, CSSParserImpl::KeyframeRules);
86 return downcast<StyleRuleKeyframe>(keyframe.get());
87}
88
89bool CSSParser::parseSupportsCondition(const String& condition)
90{
91 CSSParserImpl parser(m_context, condition);
92 if (!parser.tokenizer())
93 return false;
94 return CSSSupportsParser::supportsCondition(parser.tokenizer()->tokenRange(), parser, CSSSupportsParser::ForWindowCSS) == CSSSupportsParser::Supported;
95}
96
97Color CSSParser::parseColor(const String& string, const CSSParserContext& context)
98{
99 bool strict = !isQuirksModeBehavior(context.mode);
100 if (auto color = CSSParserFastPaths::parseSimpleColor(string, strict))
101 return *color;
102 auto value = parseSingleValue(CSSPropertyColor, string, context);
103 if (!is<CSSPrimitiveValue>(value))
104 return { };
105 auto& primitiveValue = downcast<CSSPrimitiveValue>(*value);
106 if (!primitiveValue.isRGBColor())
107 return { };
108 return primitiveValue.color();
109}
110
111Color CSSParser::parseColorWithoutContext(const String& string, bool strict)
112{
113 if (auto color = CSSParserFastPaths::parseSimpleColor(string, strict))
114 return *color;
115 // FIXME: Unclear why we want to ignore the boolean argument "strict" and always pass strictCSSParserContext here.
116 auto value = parseSingleValue(CSSPropertyColor, string, strictCSSParserContext());
117 if (!is<CSSPrimitiveValue>(value))
118 return { };
119 auto& primitiveValue = downcast<CSSPrimitiveValue>(*value);
120 if (!primitiveValue.isRGBColor())
121 return { };
122 return primitiveValue.color();
123}
124
125Color CSSParser::parseSystemColor(StringView string)
126{
127 auto keyword = cssValueKeywordID(string);
128 if (!StyleColor::isSystemColorKeyword(keyword))
129 return { };
130 return RenderTheme::singleton().systemColor(keyword, { });
131}
132
133std::optional<SRGBA<uint8_t>> CSSParser::parseNamedColor(StringView string)
134{
135 return CSSParserFastPaths::parseNamedColor(string);
136}
137
138std::optional<SRGBA<uint8_t>> CSSParser::parseHexColor(StringView string)
139{
140 return CSSParserFastPaths::parseHexColor(string);
141}
142
143RefPtr<CSSValue> CSSParser::parseSingleValue(CSSPropertyID propertyID, const String& string, const CSSParserContext& context)
144{
145 if (string.isEmpty())
146 return nullptr;
147 if (auto value = CSSParserFastPaths::maybeParseValue(propertyID, string, context))
148 return value;
149 CSSTokenizer tokenizer(string);
150 return CSSPropertyParser::parseSingleValue(propertyID, tokenizer.tokenRange(), context);
151}
152
153CSSParser::ParseResult CSSParser::parseValue(MutableStyleProperties& declaration, CSSPropertyID propertyID, const String& string, bool important, const CSSParserContext& context)
154{
155 ASSERT(!string.isEmpty());
156 if (auto value = CSSParserFastPaths::maybeParseValue(propertyID, string, context))
157 return declaration.addParsedProperty(CSSProperty(propertyID, WTFMove(value), important)) ? CSSParser::ParseResult::Changed : CSSParser::ParseResult::Unchanged;
158 CSSParser parser(context);
159 return parser.parseValue(declaration, propertyID, string, important);
160}
161
162CSSParser::ParseResult CSSParser::parseCustomPropertyValue(MutableStyleProperties& declaration, const AtomString& propertyName, const String& string, bool important, const CSSParserContext& context)
163{
164 return CSSParserImpl::parseCustomPropertyValue(&declaration, propertyName, string, important, context);
165}
166
167CSSParser::ParseResult CSSParser::parseValue(MutableStyleProperties& declaration, CSSPropertyID propertyID, const String& string, bool important)
168{
169 return CSSParserImpl::parseValue(&declaration, propertyID, string, important, m_context);
170}
171
172std::optional<CSSSelectorList> CSSParser::parseSelector(const String& string)
173{
174 return parseCSSSelector(CSSTokenizer(string).tokenRange(), m_context, nullptr);
175}
176
177Ref<ImmutableStyleProperties> CSSParser::parseInlineStyleDeclaration(const String& string, const Element* element)
178{
179 return CSSParserImpl::parseInlineStyleDeclaration(string, element);
180}
181
182bool CSSParser::parseDeclaration(MutableStyleProperties& declaration, const String& string)
183{
184 return CSSParserImpl::parseDeclarationList(&declaration, string, m_context);
185}
186
187void CSSParser::parseDeclarationForInspector(const CSSParserContext& context, const String& string, CSSParserObserver& observer)
188{
189 CSSParserImpl::parseDeclarationListForInspector(string, context, observer);
190}
191
192RefPtr<CSSValue> CSSParser::parseValueWithVariableReferences(CSSPropertyID propID, const CSSValue& value, Style::BuilderState& builderState)
193{
194 ASSERT((propID == CSSPropertyCustom && value.isCustomPropertyValue()) || (propID != CSSPropertyCustom && !value.isCustomPropertyValue()));
195
196 if (is<CSSPendingSubstitutionValue>(value)) {
197 // FIXME: Should have a resolvedShorthands cache to stop this from being done over and over for each longhand value.
198 auto& substitution = downcast<CSSPendingSubstitutionValue>(value);
199
200 auto shorthandID = substitution.shorthandPropertyId();
201
202 auto resolvedData = substitution.shorthandValue().resolveVariableReferences(builderState);
203 if (!resolvedData)
204 return nullptr;
205
206 ParsedPropertyVector parsedProperties;
207 if (!CSSPropertyParser::parseValue(shorthandID, false, resolvedData->tokens(), substitution.shorthandValue().context(), parsedProperties, StyleRuleType::Style))
208 return nullptr;
209
210 for (auto& property : parsedProperties) {
211 if (property.id() == propID)
212 return property.value();
213 }
214
215 return nullptr;
216 }
217
218 if (value.isVariableReferenceValue()) {
219 const CSSVariableReferenceValue& valueWithReferences = downcast<CSSVariableReferenceValue>(value);
220 auto resolvedData = valueWithReferences.resolveVariableReferences(builderState);
221 if (!resolvedData)
222 return nullptr;
223 return CSSPropertyParser::parseSingleValue(propID, resolvedData->tokens(), valueWithReferences.context());
224 }
225
226 const auto& customPropValue = downcast<CSSCustomPropertyValue>(value);
227 const auto& valueWithReferences = std::get<Ref<CSSVariableReferenceValue>>(customPropValue.value()).get();
228
229 auto& name = downcast<CSSCustomPropertyValue>(value).name();
230 auto* registered = builderState.document().getCSSRegisteredCustomPropertySet().get(name);
231 auto& syntax = registered ? registered->syntax : "*"_s;
232 auto resolvedData = valueWithReferences.resolveVariableReferences(builderState);
233 if (!resolvedData)
234 return nullptr;
235
236 // FIXME handle REM cycles.
237 HashSet<CSSPropertyID> dependencies;
238 CSSPropertyParser::collectParsedCustomPropertyValueDependencies(syntax, false, dependencies, resolvedData->tokens(), valueWithReferences.context());
239
240 for (auto id : dependencies)
241 builderState.builder().applyProperty(id);
242
243 return CSSPropertyParser::parseTypedCustomPropertyValue(AtomString { name }, syntax, resolvedData->tokens(), builderState, valueWithReferences.context());
244}
245
246Vector<double> CSSParser::parseKeyframeKeyList(const String& selector)
247{
248 return CSSParserImpl::parseKeyframeKeyList(selector);
249}
250
251}
Note: See TracBrowser for help on using the repository browser.