Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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().getCustomPropertyValue(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 { |
| 183 CSSPropertyID propertyID = cssPropertyID(propertyName); | 191 CSSPropertyID propertyID = cssPropertyID(propertyName); |
| 184 if (!propertyID) | 192 if (!propertyID) { |
| 185 return String(); | 193 if (!RuntimeEnabledFeatures::cssVariablesEnabled() || !CSSVariableParser ::isValidVariableName(propertyName)) |
| 194 return String(); | |
| 195 return propertySet().customPropertyIsImportant(AtomicString(propertyName )) ? "important" : ""; | |
| 196 } | |
| 186 return propertySet().propertyIsImportant(propertyID) ? "important" : ""; | 197 return propertySet().propertyIsImportant(propertyID) ? "important" : ""; |
| 187 } | 198 } |
| 188 | 199 |
| 189 String AbstractPropertySetCSSStyleDeclaration::getPropertyShorthand(const String & propertyName) | 200 String AbstractPropertySetCSSStyleDeclaration::getPropertyShorthand(const String & propertyName) |
| 190 { | 201 { |
| 191 CSSPropertyID propertyID = cssPropertyID(propertyName); | 202 CSSPropertyID propertyID = cssPropertyID(propertyName); |
| 203 | |
| 204 // Custom properties don't have shorthands, so we can ignore them here. | |
| 192 if (!propertyID) | 205 if (!propertyID) |
| 193 return String(); | 206 return String(); |
| 194 CSSPropertyID shorthandID = propertySet().getPropertyShorthand(propertyID); | 207 CSSPropertyID shorthandID = propertySet().getPropertyShorthand(propertyID); |
| 195 if (!shorthandID) | 208 if (!shorthandID) |
| 196 return String(); | 209 return String(); |
| 197 return getPropertyNameString(shorthandID); | 210 return getPropertyNameString(shorthandID); |
| 198 } | 211 } |
| 199 | 212 |
| 200 bool AbstractPropertySetCSSStyleDeclaration::isPropertyImplicit(const String& pr opertyName) | 213 bool AbstractPropertySetCSSStyleDeclaration::isPropertyImplicit(const String& pr opertyName) |
| 201 { | 214 { |
| 202 CSSPropertyID propertyID = cssPropertyID(propertyName); | 215 CSSPropertyID propertyID = cssPropertyID(propertyName); |
| 216 | |
| 217 // Custom properties don't have shorthands, so we can ignore them here. | |
| 203 if (!propertyID) | 218 if (!propertyID) |
| 204 return false; | 219 return false; |
| 205 return propertySet().isPropertyImplicit(propertyID); | 220 return propertySet().isPropertyImplicit(propertyID); |
| 206 } | 221 } |
| 207 | 222 |
| 208 void AbstractPropertySetCSSStyleDeclaration::setProperty(const String& propertyN ame, const String& value, const String& priority, ExceptionState& exceptionState ) | 223 void AbstractPropertySetCSSStyleDeclaration::setProperty(const String& propertyN ame, const String& value, const String& priority, ExceptionState& exceptionState ) |
| 209 { | 224 { |
| 210 CSSPropertyID propertyID = unresolvedCSSPropertyID(propertyName); | 225 CSSPropertyID propertyID = unresolvedCSSPropertyID(propertyName); |
| 211 if (!propertyID) | 226 if (!propertyID) { |
| 212 return; | 227 if (!RuntimeEnabledFeatures::cssVariablesEnabled() || !CSSVariableParser ::isValidVariableName(propertyName)) |
| 228 return; | |
| 229 propertyID = CSSPropertyVariable; | |
| 230 } | |
| 213 | 231 |
| 214 bool important = equalIgnoringCase(priority, "important"); | 232 bool important = equalIgnoringCase(priority, "important"); |
| 215 if (!important && !priority.isEmpty()) | 233 if (!important && !priority.isEmpty()) |
| 216 return; | 234 return; |
| 217 | 235 |
| 218 setPropertyInternal(propertyID, value, important, exceptionState); | 236 setPropertyInternal(propertyID, propertyName, value, important, exceptionSta te); |
| 219 } | 237 } |
| 220 | 238 |
| 221 String AbstractPropertySetCSSStyleDeclaration::removeProperty(const String& prop ertyName, ExceptionState& exceptionState) | 239 String AbstractPropertySetCSSStyleDeclaration::removeProperty(const String& prop ertyName, ExceptionState& exceptionState) |
| 222 { | 240 { |
| 241 CSSPropertyID propertyID = cssPropertyID(propertyName); | |
| 242 if (!propertyID) { | |
| 243 if (!RuntimeEnabledFeatures::cssVariablesEnabled() || !CSSVariableParser ::isValidVariableName(propertyName)) | |
| 244 return String(); | |
| 245 propertyID = CSSPropertyVariable; | |
| 246 } | |
| 247 | |
| 223 StyleAttributeMutationScope mutationScope(this); | 248 StyleAttributeMutationScope mutationScope(this); |
| 224 CSSPropertyID propertyID = cssPropertyID(propertyName); | |
| 225 if (!propertyID) | |
| 226 return String(); | |
| 227 | |
| 228 willMutate(); | 249 willMutate(); |
| 229 | 250 |
| 230 String result; | 251 String result; |
| 231 bool changed = propertySet().removeProperty(propertyID, &result); | 252 bool changed = propertyID != CSSPropertyVariable ? propertySet().removePrope rty(propertyID, &result) |
|
Timothy Loh
2015/11/14 02:21:05
since it's a ternary, I'd make the comparison an e
leviw_travelin_and_unemployed
2015/11/17 01:25:07
Done.
| |
| 253 : propertySet().removeCustomProperty(AtomicString(propertyName), &result ); | |
| 232 | 254 |
| 233 didMutate(changed ? PropertyChanged : NoChanges); | 255 didMutate(changed ? PropertyChanged : NoChanges); |
| 234 | 256 |
| 235 if (changed) | 257 if (changed) |
| 236 mutationScope.enqueueMutationRecord(); | 258 mutationScope.enqueueMutationRecord(); |
| 237 return result; | 259 return result; |
| 238 } | 260 } |
| 239 | 261 |
| 240 PassRefPtrWillBeRawPtr<CSSValue> AbstractPropertySetCSSStyleDeclaration::getProp ertyCSSValueInternal(CSSPropertyID propertyID) | 262 PassRefPtrWillBeRawPtr<CSSValue> AbstractPropertySetCSSStyleDeclaration::getProp ertyCSSValueInternal(CSSPropertyID propertyID) |
| 241 { | 263 { |
| 242 return propertySet().getPropertyCSSValue(propertyID); | 264 return propertySet().getPropertyCSSValue(propertyID); |
| 243 } | 265 } |
| 244 | 266 |
| 245 String AbstractPropertySetCSSStyleDeclaration::getPropertyValueInternal(CSSPrope rtyID propertyID) | 267 String AbstractPropertySetCSSStyleDeclaration::getPropertyValueInternal(CSSPrope rtyID propertyID) |
| 246 { | 268 { |
| 247 return propertySet().getPropertyValue(propertyID); | 269 return propertySet().getPropertyValue(propertyID); |
| 248 } | 270 } |
| 249 | 271 |
| 250 void AbstractPropertySetCSSStyleDeclaration::setPropertyInternal(CSSPropertyID u nresolvedProperty, const String& value, bool important, ExceptionState&) | 272 void AbstractPropertySetCSSStyleDeclaration::setPropertyInternal(CSSPropertyID u nresolvedProperty, const String& propertyName, const String& value, bool importa nt, ExceptionState&) |
| 251 { | 273 { |
| 252 StyleAttributeMutationScope mutationScope(this); | 274 StyleAttributeMutationScope mutationScope(this); |
| 253 willMutate(); | 275 willMutate(); |
| 254 | 276 |
| 255 bool changed = propertySet().setProperty(unresolvedProperty, value, importan t, contextStyleSheet()); | 277 bool changed = unresolvedProperty == CSSPropertyVariable ? propertySet().set CustomProperty(AtomicString(propertyName), value, important, contextStyleSheet() ) |
| 278 : propertySet().setProperty(unresolvedProperty, value, important, contex tStyleSheet()); | |
| 256 | 279 |
| 257 didMutate(changed ? PropertyChanged : NoChanges); | 280 didMutate(changed ? PropertyChanged : NoChanges); |
| 258 | 281 |
| 259 if (!changed) | 282 if (!changed) |
| 260 return; | 283 return; |
| 261 | 284 |
| 262 Element* parent = parentElement(); | 285 Element* parent = parentElement(); |
| 263 if (parent && parent->inActiveDocument() && parent->document().styleResolver ()) | 286 if (parent && parent->inActiveDocument() && parent->document().styleResolver ()) |
| 264 parent->document().styleEngine().attributeChangedForElement(HTMLNames::s tyleAttr, *parent); | 287 parent->document().styleEngine().attributeChangedForElement(HTMLNames::s tyleAttr, *parent); |
| 265 mutationScope.enqueueMutationRecord(); | 288 mutationScope.enqueueMutationRecord(); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 } | 408 } |
| 386 #endif | 409 #endif |
| 387 | 410 |
| 388 DEFINE_TRACE(InlineCSSStyleDeclaration) | 411 DEFINE_TRACE(InlineCSSStyleDeclaration) |
| 389 { | 412 { |
| 390 visitor->trace(m_parentElement); | 413 visitor->trace(m_parentElement); |
| 391 AbstractPropertySetCSSStyleDeclaration::trace(visitor); | 414 AbstractPropertySetCSSStyleDeclaration::trace(visitor); |
| 392 } | 415 } |
| 393 | 416 |
| 394 } // namespace blink | 417 } // namespace blink |
| OLD | NEW |