OLD | NEW |
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 void CSSParser::parseSheetForInspector(const CSSParserContext& context, StyleShe
etContents* styleSheet, const String& text, CSSParserObserver& observer) | 49 void CSSParser::parseSheetForInspector(const CSSParserContext& context, StyleShe
etContents* styleSheet, const String& text, CSSParserObserver& observer) |
50 { | 50 { |
51 return CSSParserImpl::parseStyleSheetForInspector(text, context, styleSheet,
observer); | 51 return CSSParserImpl::parseStyleSheetForInspector(text, context, styleSheet,
observer); |
52 } | 52 } |
53 | 53 |
54 bool CSSParser::parseValue(MutableStylePropertySet* declaration, CSSPropertyID u
nresolvedProperty, const String& string, bool important, CSSParserMode parserMod
e, StyleSheetContents* styleSheet) | 54 bool CSSParser::parseValue(MutableStylePropertySet* declaration, CSSPropertyID u
nresolvedProperty, const String& string, bool important, CSSParserMode parserMod
e, StyleSheetContents* styleSheet) |
55 { | 55 { |
56 if (string.isEmpty()) | 56 if (string.isEmpty()) |
57 return false; | 57 return false; |
58 CSSPropertyID resolvedProperty = resolveCSSPropertyID(unresolvedProperty); | 58 CSSPropertyID resolvedProperty = resolveCSSPropertyID(unresolvedProperty); |
59 RefPtrWillBeRawPtr<CSSValue> value = CSSParserFastPaths::maybeParseValue(res
olvedProperty, string, parserMode); | 59 NullableCSSValue value = CSSParserFastPaths::maybeParseValue(resolvedPropert
y, string, parserMode); |
60 if (value) | 60 if (value) |
61 return declaration->setProperty(CSSProperty(resolvedProperty, value.rele
ase(), important)); | 61 return declaration->setProperty(CSSProperty(resolvedProperty, *value, im
portant)); |
62 CSSParserContext context(parserMode, 0); | 62 CSSParserContext context(parserMode, 0); |
63 if (styleSheet) { | 63 if (styleSheet) { |
64 context = styleSheet->parserContext(); | 64 context = styleSheet->parserContext(); |
65 context.setMode(parserMode); | 65 context.setMode(parserMode); |
66 } | 66 } |
67 return parseValue(declaration, unresolvedProperty, string, important, contex
t); | 67 return parseValue(declaration, unresolvedProperty, string, important, contex
t); |
68 } | 68 } |
69 | 69 |
70 bool CSSParser::parseValue(MutableStylePropertySet* declaration, CSSPropertyID u
nresolvedProperty, const String& string, bool important, const CSSParserContext&
context) | 70 bool CSSParser::parseValue(MutableStylePropertySet* declaration, CSSPropertyID u
nresolvedProperty, const String& string, bool important, const CSSParserContext&
context) |
71 { | 71 { |
72 return CSSParserImpl::parseValue(declaration, unresolvedProperty, string, im
portant, context); | 72 return CSSParserImpl::parseValue(declaration, unresolvedProperty, string, im
portant, context); |
73 } | 73 } |
74 | 74 |
75 PassRefPtrWillBeRawPtr<CSSValue> CSSParser::parseSingleValue(CSSPropertyID prope
rtyID, const String& string, const CSSParserContext& context) | 75 NullableCSSValue CSSParser::parseSingleValue(CSSPropertyID propertyID, const Str
ing& string, const CSSParserContext& context) |
76 { | 76 { |
77 if (string.isEmpty()) | 77 if (string.isEmpty()) |
78 return nullptr; | 78 return nullptr; |
79 if (RefPtrWillBeRawPtr<CSSValue> value = CSSParserFastPaths::maybeParseValue
(propertyID, string, context.mode())) | 79 if (NullableCSSValue value = CSSParserFastPaths::maybeParseValue(propertyID,
string, context.mode())) |
80 return value; | 80 return value; |
81 RefPtrWillBeRawPtr<MutableStylePropertySet> stylePropertySet = MutableStyleP
ropertySet::create(); | 81 RefPtrWillBeRawPtr<MutableStylePropertySet> stylePropertySet = MutableStyleP
ropertySet::create(); |
82 bool changed = parseValue(stylePropertySet.get(), propertyID, string, false,
context); | 82 bool changed = parseValue(stylePropertySet.get(), propertyID, string, false,
context); |
83 ASSERT_UNUSED(changed, changed == stylePropertySet->hasProperty(propertyID))
; | 83 ASSERT_UNUSED(changed, changed == stylePropertySet->hasProperty(propertyID))
; |
84 return stylePropertySet->getPropertyCSSValue(propertyID); | 84 return stylePropertySet->getPropertyCSSValue(propertyID); |
85 } | 85 } |
86 | 86 |
87 PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> CSSParser::parseInlineStyleDec
laration(const String& styleString, Element* element) | 87 PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> CSSParser::parseInlineStyleDec
laration(const String& styleString, Element* element) |
88 { | 88 { |
89 return CSSParserImpl::parseInlineStyleDeclaration(styleString, element); | 89 return CSSParserImpl::parseInlineStyleDeclaration(styleString, element); |
(...skipping 23 matching lines...) Expand all Loading... |
113 return false; | 113 return false; |
114 | 114 |
115 // The regular color parsers don't resolve all named colors, so explicitly | 115 // The regular color parsers don't resolve all named colors, so explicitly |
116 // handle these first. | 116 // handle these first. |
117 Color namedColor; | 117 Color namedColor; |
118 if (namedColor.setNamedColor(string)) { | 118 if (namedColor.setNamedColor(string)) { |
119 color = namedColor.rgb(); | 119 color = namedColor.rgb(); |
120 return true; | 120 return true; |
121 } | 121 } |
122 | 122 |
123 RefPtrWillBeRawPtr<CSSValue> value = CSSParserFastPaths::parseColor(string,
!strict); | 123 NullableCSSValue value = CSSParserFastPaths::parseColor(string, !strict); |
124 // TODO(timloh): Why is this always strict mode? | 124 // TODO(timloh): Why is this always strict mode? |
125 if (!value) | 125 if (!value) |
126 value = parseSingleValue(CSSPropertyColor, string, strictCSSParserContex
t()); | 126 value = parseSingleValue(CSSPropertyColor, string, strictCSSParserContex
t()); |
127 | 127 |
128 if (!value || !value->isPrimitiveValue()) | 128 if (!value || !value->isPrimitiveValue()) |
129 return false; | 129 return false; |
130 | 130 |
131 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value.get()); | 131 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); |
132 if (!primitiveValue->isRGBColor()) | 132 if (!primitiveValue->isRGBColor()) |
133 return false; | 133 return false; |
134 | 134 |
135 color = primitiveValue->getRGBA32Value(); | 135 color = primitiveValue->getRGBA32Value(); |
136 return true; | 136 return true; |
137 } | 137 } |
138 | 138 |
139 StyleColor CSSParser::colorFromRGBColorString(const String& string) | 139 StyleColor CSSParser::colorFromRGBColorString(const String& string) |
140 { | 140 { |
141 // FIXME: Rework css parser so it is more SVG aware. | 141 // FIXME: Rework css parser so it is more SVG aware. |
(...skipping 10 matching lines...) Expand all Loading... |
152 cssColor.init(colorString); | 152 cssColor.init(colorString); |
153 CSSValueID id = cssValueKeywordID(cssColor); | 153 CSSValueID id = cssValueKeywordID(cssColor); |
154 if (!CSSPropertyParser::isSystemColor(id)) | 154 if (!CSSPropertyParser::isSystemColor(id)) |
155 return false; | 155 return false; |
156 | 156 |
157 Color parsedColor = LayoutTheme::theme().systemColor(id); | 157 Color parsedColor = LayoutTheme::theme().systemColor(id); |
158 color = parsedColor.rgb(); | 158 color = parsedColor.rgb(); |
159 return true; | 159 return true; |
160 } | 160 } |
161 | 161 |
162 PassRefPtrWillBeRawPtr<CSSValue> CSSParser::parseFontFaceDescriptor(CSSPropertyI
D propertyID, const String& propertyValue, const CSSParserContext& context) | 162 NullableCSSValue CSSParser::parseFontFaceDescriptor(CSSPropertyID propertyID, co
nst String& propertyValue, const CSSParserContext& context) |
163 { | 163 { |
164 StringBuilder builder; | 164 StringBuilder builder; |
165 builder.appendLiteral("@font-face { "); | 165 builder.appendLiteral("@font-face { "); |
166 builder.append(getPropertyNameString(propertyID)); | 166 builder.append(getPropertyNameString(propertyID)); |
167 builder.appendLiteral(" : "); | 167 builder.appendLiteral(" : "); |
168 builder.append(propertyValue); | 168 builder.append(propertyValue); |
169 builder.appendLiteral("; }"); | 169 builder.appendLiteral("; }"); |
170 RefPtrWillBeRawPtr<StyleRuleBase> rule = parseRule(context, nullptr, builder
.toString()); | 170 RefPtrWillBeRawPtr<StyleRuleBase> rule = parseRule(context, nullptr, builder
.toString()); |
171 if (!rule || !rule->isFontFaceRule()) | 171 if (!rule || !rule->isFontFaceRule()) |
172 return nullptr; | 172 return nullptr; |
173 return toStyleRuleFontFace(rule.get())->properties().getPropertyCSSValue(pro
pertyID); | 173 return toStyleRuleFontFace(rule.get())->properties().getPropertyCSSValue(pro
pertyID); |
174 } | 174 } |
175 | 175 |
176 } // namespace blink | 176 } // namespace blink |
OLD | NEW |