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

Side by Side Diff: third_party/WebKit/Source/core/css/PropertySetCSSStyleDeclaration.cpp

Issue 1405293012: [Variables] Enable get/setProperty and similar APIs from the CSSOM (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use static_assert. Created 5 years 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 /* 1 /*
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r ights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r ights reserved.
4 * Copyright (C) 2011 Research In Motion Limited. All rights reserved. 4 * Copyright (C) 2011 Research In Motion Limited. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
11 * This library is distributed in the hope that it will be useful, 11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details. 14 * Library General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU Library General Public License 16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to 17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA. 19 * Boston, MA 02110-1301, USA.
20 */ 20 */
21 21
22 #include "config.h" 22 #include "config.h"
23 #include "core/css/PropertySetCSSStyleDeclaration.h" 23 #include "core/css/PropertySetCSSStyleDeclaration.h"
24 24
25 #include "bindings/core/v8/ExceptionState.h" 25 #include "bindings/core/v8/ExceptionState.h"
26 #include "core/HTMLNames.h" 26 #include "core/HTMLNames.h"
27 #include "core/css/CSSCustomPropertyDeclaration.h"
27 #include "core/css/CSSKeyframesRule.h" 28 #include "core/css/CSSKeyframesRule.h"
28 #include "core/css/CSSStyleSheet.h" 29 #include "core/css/CSSStyleSheet.h"
29 #include "core/css/StylePropertySet.h" 30 #include "core/css/StylePropertySet.h"
31 #include "core/css/parser/CSSVariableParser.h"
30 #include "core/dom/Element.h" 32 #include "core/dom/Element.h"
31 #include "core/dom/MutationObserverInterestGroup.h" 33 #include "core/dom/MutationObserverInterestGroup.h"
32 #include "core/dom/MutationRecord.h" 34 #include "core/dom/MutationRecord.h"
33 #include "core/dom/StyleEngine.h" 35 #include "core/dom/StyleEngine.h"
34 #include "core/inspector/InspectorInstrumentation.h" 36 #include "core/inspector/InspectorInstrumentation.h"
35 #include "platform/RuntimeEnabledFeatures.h" 37 #include "platform/RuntimeEnabledFeatures.h"
36 38
37 namespace blink { 39 namespace blink {
38 40
39 namespace { 41 namespace {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 145
144 unsigned AbstractPropertySetCSSStyleDeclaration::length() const 146 unsigned AbstractPropertySetCSSStyleDeclaration::length() const
145 { 147 {
146 return propertySet().propertyCount(); 148 return propertySet().propertyCount();
147 } 149 }
148 150
149 String AbstractPropertySetCSSStyleDeclaration::item(unsigned i) const 151 String AbstractPropertySetCSSStyleDeclaration::item(unsigned i) const
150 { 152 {
151 if (i >= propertySet().propertyCount()) 153 if (i >= propertySet().propertyCount())
152 return ""; 154 return "";
153 return getPropertyName(propertySet().propertyAt(i).id()); 155 StylePropertySet::PropertyReference property = propertySet().propertyAt(i);
156 if (RuntimeEnabledFeatures::cssVariablesEnabled() && property.id() == CSSPro pertyVariable)
157 return toCSSCustomPropertyDeclaration(property.value())->name();
158 return getPropertyName(property.id());
154 } 159 }
155 160
156 String AbstractPropertySetCSSStyleDeclaration::cssText() const 161 String AbstractPropertySetCSSStyleDeclaration::cssText() const
157 { 162 {
158 return propertySet().asText(); 163 return propertySet().asText();
159 } 164 }
160 165
161 void AbstractPropertySetCSSStyleDeclaration::setCSSText(const String& text, Exce ptionState&) 166 void AbstractPropertySetCSSStyleDeclaration::setCSSText(const String& text, Exce ptionState&)
162 { 167 {
163 StyleAttributeMutationScope mutationScope(this); 168 StyleAttributeMutationScope mutationScope(this);
164 willMutate(); 169 willMutate();
165 170
166 propertySet().parseDeclarationList(text, contextStyleSheet()); 171 propertySet().parseDeclarationList(text, contextStyleSheet());
167 172
168 didMutate(PropertyChanged); 173 didMutate(PropertyChanged);
169 174
170 mutationScope.enqueueMutationRecord(); 175 mutationScope.enqueueMutationRecord();
171 } 176 }
172 177
173 String AbstractPropertySetCSSStyleDeclaration::getPropertyValue(const String &pr opertyName) 178 String AbstractPropertySetCSSStyleDeclaration::getPropertyValue(const String& pr opertyName)
174 { 179 {
175 CSSPropertyID propertyID = cssPropertyID(propertyName); 180 CSSPropertyID propertyID = cssPropertyID(propertyName);
176 if (!propertyID) 181 if (!propertyID) {
177 return String(); 182 if (!RuntimeEnabledFeatures::cssVariablesEnabled() || !CSSVariableParser ::isValidVariableName(propertyName))
183 return String();
184 return propertySet().getPropertyValue(AtomicString(propertyName));
185 }
178 return propertySet().getPropertyValue(propertyID); 186 return propertySet().getPropertyValue(propertyID);
179 } 187 }
180 188
181 String AbstractPropertySetCSSStyleDeclaration::getPropertyPriority(const String& propertyName) 189 String AbstractPropertySetCSSStyleDeclaration::getPropertyPriority(const String& propertyName)
182 { 190 {
191 bool important = false;
183 CSSPropertyID propertyID = cssPropertyID(propertyName); 192 CSSPropertyID propertyID = cssPropertyID(propertyName);
184 if (!propertyID) 193 if (!propertyID) {
185 return String(); 194 if (!RuntimeEnabledFeatures::cssVariablesEnabled() || !CSSVariableParser ::isValidVariableName(propertyName))
186 return propertySet().propertyIsImportant(propertyID) ? "important" : ""; 195 return String();
196 important = propertySet().propertyIsImportant(AtomicString(propertyName) );
197 } else {
198 important = propertySet().propertyIsImportant(propertyID);
199 }
200 return important ? "important" : "";
187 } 201 }
188 202
189 String AbstractPropertySetCSSStyleDeclaration::getPropertyShorthand(const String & propertyName) 203 String AbstractPropertySetCSSStyleDeclaration::getPropertyShorthand(const String & propertyName)
190 { 204 {
191 CSSPropertyID propertyID = cssPropertyID(propertyName); 205 CSSPropertyID propertyID = cssPropertyID(propertyName);
206
207 // Custom properties don't have shorthands, so we can ignore them here.
192 if (!propertyID) 208 if (!propertyID)
193 return String(); 209 return String();
194 CSSPropertyID shorthandID = propertySet().getPropertyShorthand(propertyID); 210 CSSPropertyID shorthandID = propertySet().getPropertyShorthand(propertyID);
195 if (!shorthandID) 211 if (!shorthandID)
196 return String(); 212 return String();
197 return getPropertyNameString(shorthandID); 213 return getPropertyNameString(shorthandID);
198 } 214 }
199 215
200 bool AbstractPropertySetCSSStyleDeclaration::isPropertyImplicit(const String& pr opertyName) 216 bool AbstractPropertySetCSSStyleDeclaration::isPropertyImplicit(const String& pr opertyName)
201 { 217 {
202 CSSPropertyID propertyID = cssPropertyID(propertyName); 218 CSSPropertyID propertyID = cssPropertyID(propertyName);
219
220 // Custom properties don't have shorthands, so we can ignore them here.
203 if (!propertyID) 221 if (!propertyID)
204 return false; 222 return false;
205 return propertySet().isPropertyImplicit(propertyID); 223 return propertySet().isPropertyImplicit(propertyID);
206 } 224 }
207 225
208 void AbstractPropertySetCSSStyleDeclaration::setProperty(const String& propertyN ame, const String& value, const String& priority, ExceptionState& exceptionState ) 226 void AbstractPropertySetCSSStyleDeclaration::setProperty(const String& propertyN ame, const String& value, const String& priority, ExceptionState& exceptionState )
209 { 227 {
210 CSSPropertyID propertyID = unresolvedCSSPropertyID(propertyName); 228 CSSPropertyID propertyID = unresolvedCSSPropertyID(propertyName);
211 if (!propertyID) 229 if (!propertyID) {
212 return; 230 if (!RuntimeEnabledFeatures::cssVariablesEnabled() || !CSSVariableParser ::isValidVariableName(propertyName))
231 return;
232 propertyID = CSSPropertyVariable;
233 }
213 234
214 bool important = equalIgnoringCase(priority, "important"); 235 bool important = equalIgnoringCase(priority, "important");
215 if (!important && !priority.isEmpty()) 236 if (!important && !priority.isEmpty())
216 return; 237 return;
217 238
218 setPropertyInternal(propertyID, value, important, exceptionState); 239 setPropertyInternal(propertyID, propertyName, value, important, exceptionSta te);
219 } 240 }
220 241
221 String AbstractPropertySetCSSStyleDeclaration::removeProperty(const String& prop ertyName, ExceptionState& exceptionState) 242 String AbstractPropertySetCSSStyleDeclaration::removeProperty(const String& prop ertyName, ExceptionState& exceptionState)
222 { 243 {
244 CSSPropertyID propertyID = cssPropertyID(propertyName);
245 if (!propertyID) {
246 if (!RuntimeEnabledFeatures::cssVariablesEnabled() || !CSSVariableParser ::isValidVariableName(propertyName))
247 return String();
248 propertyID = CSSPropertyVariable;
249 }
250
223 StyleAttributeMutationScope mutationScope(this); 251 StyleAttributeMutationScope mutationScope(this);
224 CSSPropertyID propertyID = cssPropertyID(propertyName);
225 if (!propertyID)
226 return String();
227
228 willMutate(); 252 willMutate();
229 253
230 String result; 254 String result;
231 bool changed = propertySet().removeProperty(propertyID, &result); 255 bool changed = false;
256 if (propertyID == CSSPropertyVariable)
257 changed = propertySet().removeProperty(AtomicString(propertyName), &resu lt);
258 else
259 changed = propertySet().removeProperty(propertyID, &result);
232 260
233 didMutate(changed ? PropertyChanged : NoChanges); 261 didMutate(changed ? PropertyChanged : NoChanges);
234 262
235 if (changed) 263 if (changed)
236 mutationScope.enqueueMutationRecord(); 264 mutationScope.enqueueMutationRecord();
237 return result; 265 return result;
238 } 266 }
239 267
240 PassRefPtrWillBeRawPtr<CSSValue> AbstractPropertySetCSSStyleDeclaration::getProp ertyCSSValueInternal(CSSPropertyID propertyID) 268 PassRefPtrWillBeRawPtr<CSSValue> AbstractPropertySetCSSStyleDeclaration::getProp ertyCSSValueInternal(CSSPropertyID propertyID)
241 { 269 {
242 return propertySet().getPropertyCSSValue(propertyID); 270 return propertySet().getPropertyCSSValue(propertyID);
243 } 271 }
244 272
245 String AbstractPropertySetCSSStyleDeclaration::getPropertyValueInternal(CSSPrope rtyID propertyID) 273 String AbstractPropertySetCSSStyleDeclaration::getPropertyValueInternal(CSSPrope rtyID propertyID)
246 { 274 {
247 return propertySet().getPropertyValue(propertyID); 275 return propertySet().getPropertyValue(propertyID);
248 } 276 }
249 277
250 void AbstractPropertySetCSSStyleDeclaration::setPropertyInternal(CSSPropertyID u nresolvedProperty, const String& value, bool important, ExceptionState&) 278 void AbstractPropertySetCSSStyleDeclaration::setPropertyInternal(CSSPropertyID u nresolvedProperty, const String& customPropertyName, const String& value, bool i mportant, ExceptionState&)
251 { 279 {
252 StyleAttributeMutationScope mutationScope(this); 280 StyleAttributeMutationScope mutationScope(this);
253 willMutate(); 281 willMutate();
254 282
255 bool changed = propertySet().setProperty(unresolvedProperty, value, importan t, contextStyleSheet()); 283 bool changed = false;
284 if (unresolvedProperty == CSSPropertyVariable)
285 changed = propertySet().setProperty(AtomicString(customPropertyName), va lue, important, contextStyleSheet());
286 else
287 changed = propertySet().setProperty(unresolvedProperty, value, important , contextStyleSheet());
256 288
257 didMutate(changed ? PropertyChanged : NoChanges); 289 didMutate(changed ? PropertyChanged : NoChanges);
258 290
259 if (!changed) 291 if (!changed)
260 return; 292 return;
261 293
262 Element* parent = parentElement(); 294 Element* parent = parentElement();
263 if (parent && parent->inActiveDocument() && parent->document().styleResolver ()) 295 if (parent && parent->inActiveDocument() && parent->document().styleResolver ())
264 parent->document().styleEngine().attributeChangedForElement(HTMLNames::s tyleAttr, *parent); 296 parent->document().styleEngine().attributeChangedForElement(HTMLNames::s tyleAttr, *parent);
265 mutationScope.enqueueMutationRecord(); 297 mutationScope.enqueueMutationRecord();
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 } 417 }
386 #endif 418 #endif
387 419
388 DEFINE_TRACE(InlineCSSStyleDeclaration) 420 DEFINE_TRACE(InlineCSSStyleDeclaration)
389 { 421 {
390 visitor->trace(m_parentElement); 422 visitor->trace(m_parentElement);
391 AbstractPropertySetCSSStyleDeclaration::trace(visitor); 423 AbstractPropertySetCSSStyleDeclaration::trace(visitor);
392 } 424 }
393 425
394 } // namespace blink 426 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698