Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: Source/core/css/parser/CSSParser.cpp

Issue 1196533002: Clean up fast path CSS color parsing (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Source/core/css/parser/CSSParserFastPaths.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "core/css/parser/CSSParser.h" 6 #include "core/css/parser/CSSParser.h"
7 7
8 #include "core/css/CSSKeyframeRule.h" 8 #include "core/css/CSSKeyframeRule.h"
9 #include "core/css/StyleColor.h" 9 #include "core/css/StyleColor.h"
10 #include "core/css/StylePropertySet.h" 10 #include "core/css/StylePropertySet.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 CSSTokenizer::Scope scope(condition); 105 CSSTokenizer::Scope scope(condition);
106 CSSParserImpl parser(strictCSSParserContext()); 106 CSSParserImpl parser(strictCSSParserContext());
107 return CSSSupportsParser::supportsCondition(scope.tokenRange(), parser) == C SSSupportsParser::Supported; 107 return CSSSupportsParser::supportsCondition(scope.tokenRange(), parser) == C SSSupportsParser::Supported;
108 } 108 }
109 109
110 bool CSSParser::parseColor(RGBA32& color, const String& string, bool strict) 110 bool CSSParser::parseColor(RGBA32& color, const String& string, bool strict)
111 { 111 {
112 if (string.isEmpty()) 112 if (string.isEmpty())
113 return false; 113 return false;
114 114
115 // First try creating a color specified by name, rgba(), rgb() or "#" syntax . 115 // The regular color parsers don't resolve all named colors, so explicitly
116 if (CSSParserFastPaths::parseColorAsRGBA32(color, string, !strict)) 116 // handle these first.
117 Color namedColor;
118 if (namedColor.setNamedColor(string)) {
119 color = namedColor.rgb();
117 return true; 120 return true;
121 }
118 122
119 // In case the fast-path parser didn't understand the color, try the full pa rser. 123 RefPtrWillBeRawPtr<CSSValue> value = CSSParserFastPaths::parseColor(string, !strict);
120 RefPtrWillBeRawPtr<MutableStylePropertySet> stylePropertySet = MutableStyleP ropertySet::create(); 124 // TODO(timloh): Why is this always strict mode?
121 // FIXME: The old CSS parser is only working in strict mode ignoring the str ict parameter. 125 if (!value)
122 // It needs to be investigated why. 126 value = parseSingleValue(CSSPropertyColor, string, strictCSSParserContex t());
123 if (!parseValue(stylePropertySet.get(), CSSPropertyColor, string, false, str ictCSSParserContext()))
124 return false;
125 127
126 RefPtrWillBeRawPtr<CSSValue> value = stylePropertySet->getPropertyCSSValue(C SSPropertyColor);
127 if (!value || !value->isPrimitiveValue()) 128 if (!value || !value->isPrimitiveValue())
128 return false; 129 return false;
129 130
130 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value.get()); 131 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value.get());
131 if (!primitiveValue->isRGBColor()) 132 if (!primitiveValue->isRGBColor())
132 return false; 133 return false;
133 134
134 color = primitiveValue->getRGBA32Value(); 135 color = primitiveValue->getRGBA32Value();
135 return true; 136 return true;
136 } 137 }
(...skipping 29 matching lines...) Expand all
166 builder.appendLiteral(" : "); 167 builder.appendLiteral(" : ");
167 builder.append(propertyValue); 168 builder.append(propertyValue);
168 builder.appendLiteral("; }"); 169 builder.appendLiteral("; }");
169 RefPtrWillBeRawPtr<StyleRuleBase> rule = parseRule(context, builder.toString ()); 170 RefPtrWillBeRawPtr<StyleRuleBase> rule = parseRule(context, builder.toString ());
170 if (!rule || !rule->isFontFaceRule()) 171 if (!rule || !rule->isFontFaceRule())
171 return nullptr; 172 return nullptr;
172 return toStyleRuleFontFace(rule.get())->properties().getPropertyCSSValue(pro pertyID); 173 return toStyleRuleFontFace(rule.get())->properties().getPropertyCSSValue(pro pertyID);
173 } 174 }
174 175
175 } // namespace blink 176 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/core/css/parser/CSSParserFastPaths.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698