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

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

Issue 1164573002: CSSValue Immediates: Change CSSValue to an object instead of a pointer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Some small fixes to (hopefully) fix some broken tests 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
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 if (observer) 45 if (observer)
46 return CSSParserImpl::parseStyleSheetForInspector(text, context, *observ er); 46 return CSSParserImpl::parseStyleSheetForInspector(text, context, *observ er);
47 return CSSParserImpl::parseStyleSheet(text, context, styleSheet); 47 return CSSParserImpl::parseStyleSheet(text, context, styleSheet);
48 } 48 }
49 49
50 bool CSSParser::parseValue(MutableStylePropertySet* declaration, CSSPropertyID u nresolvedProperty, const String& string, bool important, CSSParserMode parserMod e, StyleSheetContents* styleSheet) 50 bool CSSParser::parseValue(MutableStylePropertySet* declaration, CSSPropertyID u nresolvedProperty, const String& string, bool important, CSSParserMode parserMod e, StyleSheetContents* styleSheet)
51 { 51 {
52 if (string.isEmpty()) 52 if (string.isEmpty())
53 return false; 53 return false;
54 CSSPropertyID resolvedProperty = resolveCSSPropertyID(unresolvedProperty); 54 CSSPropertyID resolvedProperty = resolveCSSPropertyID(unresolvedProperty);
55 RefPtrWillBeRawPtr<CSSValue> value = CSSParserFastPaths::maybeParseValue(res olvedProperty, string, parserMode); 55 NullableCSSValue value = CSSParserFastPaths::maybeParseValue(resolvedPropert y, string, parserMode);
56 if (value) 56 if (value)
57 return declaration->setProperty(CSSProperty(resolvedProperty, value.rele ase(), important)); 57 return declaration->setProperty(CSSProperty(resolvedProperty, *value, im portant));
58 CSSParserContext context(parserMode, 0); 58 CSSParserContext context(parserMode, 0);
59 if (styleSheet) { 59 if (styleSheet) {
60 context = styleSheet->parserContext(); 60 context = styleSheet->parserContext();
61 context.setMode(parserMode); 61 context.setMode(parserMode);
62 } 62 }
63 return parseValue(declaration, unresolvedProperty, string, important, contex t); 63 return parseValue(declaration, unresolvedProperty, string, important, contex t);
64 } 64 }
65 65
66 bool CSSParser::parseValue(MutableStylePropertySet* declaration, CSSPropertyID u nresolvedProperty, const String& string, bool important, const CSSParserContext& context) 66 bool CSSParser::parseValue(MutableStylePropertySet* declaration, CSSPropertyID u nresolvedProperty, const String& string, bool important, const CSSParserContext& context)
67 { 67 {
68 return CSSParserImpl::parseValue(declaration, unresolvedProperty, string, im portant, context); 68 return CSSParserImpl::parseValue(declaration, unresolvedProperty, string, im portant, context);
69 } 69 }
70 70
71 PassRefPtrWillBeRawPtr<CSSValue> CSSParser::parseSingleValue(CSSPropertyID prope rtyID, const String& string, const CSSParserContext& context) 71 NullableCSSValue CSSParser::parseSingleValue(CSSPropertyID propertyID, const Str ing& string, const CSSParserContext& context)
72 { 72 {
73 if (string.isEmpty()) 73 if (string.isEmpty())
74 return nullptr; 74 return nullptr;
75 if (RefPtrWillBeRawPtr<CSSValue> value = CSSParserFastPaths::maybeParseValue (propertyID, string, context.mode())) 75 if (NullableCSSValue value = CSSParserFastPaths::maybeParseValue(propertyID, string, context.mode()))
76 return value; 76 return value;
77 RefPtrWillBeRawPtr<MutableStylePropertySet> stylePropertySet = MutableStyleP ropertySet::create(); 77 RefPtrWillBeRawPtr<MutableStylePropertySet> stylePropertySet = MutableStyleP ropertySet::create();
78 bool changed = parseValue(stylePropertySet.get(), propertyID, string, false, context); 78 bool changed = parseValue(stylePropertySet.get(), propertyID, string, false, context);
79 ASSERT_UNUSED(changed, changed == stylePropertySet->hasProperty(propertyID)) ; 79 ASSERT_UNUSED(changed, changed == stylePropertySet->hasProperty(propertyID)) ;
80 return stylePropertySet->getPropertyCSSValue(propertyID); 80 return stylePropertySet->getPropertyCSSValue(propertyID);
81 } 81 }
82 82
83 PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> CSSParser::parseInlineStyleDec laration(const String& styleString, Element* element) 83 PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> CSSParser::parseInlineStyleDec laration(const String& styleString, Element* element)
84 { 84 {
85 return CSSParserImpl::parseInlineStyleDeclaration(styleString, element); 85 return CSSParserImpl::parseInlineStyleDeclaration(styleString, element);
(...skipping 26 matching lines...) Expand all
112 if (CSSPropertyParser::fastParseColor(color, string, strict)) 112 if (CSSPropertyParser::fastParseColor(color, string, strict))
113 return true; 113 return true;
114 114
115 // In case the fast-path parser didn't understand the color, try the full pa rser. 115 // In case the fast-path parser didn't understand the color, try the full pa rser.
116 RefPtrWillBeRawPtr<MutableStylePropertySet> stylePropertySet = MutableStyleP ropertySet::create(); 116 RefPtrWillBeRawPtr<MutableStylePropertySet> stylePropertySet = MutableStyleP ropertySet::create();
117 // FIXME: The old CSS parser is only working in strict mode ignoring the str ict parameter. 117 // FIXME: The old CSS parser is only working in strict mode ignoring the str ict parameter.
118 // It needs to be investigated why. 118 // It needs to be investigated why.
119 if (!parseValue(stylePropertySet.get(), CSSPropertyColor, string, false, str ictCSSParserContext())) 119 if (!parseValue(stylePropertySet.get(), CSSPropertyColor, string, false, str ictCSSParserContext()))
120 return false; 120 return false;
121 121
122 RefPtrWillBeRawPtr<CSSValue> value = stylePropertySet->getPropertyCSSValue(C SSPropertyColor); 122 NullableCSSValue value = stylePropertySet->getPropertyCSSValue(CSSPropertyCo lor);
123 if (!value || !value->isPrimitiveValue()) 123 if (!value || !value->isPrimitiveValue())
124 return false; 124 return false;
125 125
126 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value.get()); 126 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
127 if (!primitiveValue->isRGBColor()) 127 if (!primitiveValue->isRGBColor())
128 return false; 128 return false;
129 129
130 color = primitiveValue->getRGBA32Value(); 130 color = primitiveValue->getRGBA32Value();
131 return true; 131 return true;
132 } 132 }
133 133
134 StyleColor CSSParser::colorFromRGBColorString(const String& string) 134 StyleColor CSSParser::colorFromRGBColorString(const String& string)
135 { 135 {
136 // FIXME: Rework css parser so it is more SVG aware. 136 // FIXME: Rework css parser so it is more SVG aware.
(...skipping 10 matching lines...) Expand all
147 cssColor.init(colorString); 147 cssColor.init(colorString);
148 CSSValueID id = cssValueKeywordID(cssColor); 148 CSSValueID id = cssValueKeywordID(cssColor);
149 if (!CSSPropertyParser::isSystemColor(id)) 149 if (!CSSPropertyParser::isSystemColor(id))
150 return false; 150 return false;
151 151
152 Color parsedColor = LayoutTheme::theme().systemColor(id); 152 Color parsedColor = LayoutTheme::theme().systemColor(id);
153 color = parsedColor.rgb(); 153 color = parsedColor.rgb();
154 return true; 154 return true;
155 } 155 }
156 156
157 PassRefPtrWillBeRawPtr<CSSValue> CSSParser::parseFontFaceDescriptor(CSSPropertyI D propertyID, const String& propertyValue, const CSSParserContext& context) 157 NullableCSSValue CSSParser::parseFontFaceDescriptor(CSSPropertyID propertyID, co nst String& propertyValue, const CSSParserContext& context)
158 { 158 {
159 StringBuilder builder; 159 StringBuilder builder;
160 builder.appendLiteral("@font-face { "); 160 builder.appendLiteral("@font-face { ");
161 builder.append(getPropertyNameString(propertyID)); 161 builder.append(getPropertyNameString(propertyID));
162 builder.appendLiteral(" : "); 162 builder.appendLiteral(" : ");
163 builder.append(propertyValue); 163 builder.append(propertyValue);
164 builder.appendLiteral("; }"); 164 builder.appendLiteral("; }");
165 RefPtrWillBeRawPtr<StyleRuleBase> rule = parseRule(context, builder.toString ()); 165 RefPtrWillBeRawPtr<StyleRuleBase> rule = parseRule(context, builder.toString ());
166 if (!rule || !rule->isFontFaceRule()) 166 if (!rule || !rule->isFontFaceRule())
167 return nullptr; 167 return nullptr;
168 return toStyleRuleFontFace(rule.get())->properties().getPropertyCSSValue(pro pertyID); 168 return toStyleRuleFontFace(rule.get())->properties().getPropertyCSSValue(pro pertyID);
169 } 169 }
170 170
171 } // namespace blink 171 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698