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

Side by Side Diff: Source/core/css/StylePropertySet.cpp

Issue 18311002: Partial implementation of CSSVariablesMap for CSS Variables CSSOM (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased webexposed tests Created 7 years, 5 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 | Annotate | Revision Log
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, 2013 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights 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/StylePropertySet.h" 23 #include "core/css/StylePropertySet.h"
24 24
25 #include "RuntimeEnabledFeatures.h"
25 #include "core/css/CSSParser.h" 26 #include "core/css/CSSParser.h"
26 #include "core/css/CSSValuePool.h" 27 #include "core/css/CSSValuePool.h"
27 #include "core/css/CSSVariableValue.h" 28 #include "core/css/CSSVariableValue.h"
28 #include "core/css/PropertySetCSSStyleDeclaration.h" 29 #include "core/css/PropertySetCSSStyleDeclaration.h"
29 #include "core/css/StylePropertySerializer.h" 30 #include "core/css/StylePropertySerializer.h"
30 #include "core/css/StylePropertyShorthand.h" 31 #include "core/css/StylePropertyShorthand.h"
31 #include "core/css/StyleSheetContents.h" 32 #include "core/css/StyleSheetContents.h"
32 #include "core/page/RuntimeCSSEnabled.h" 33 #include "core/page/RuntimeCSSEnabled.h"
33 #include "wtf/MemoryInstrumentationVector.h" 34 #include "wtf/MemoryInstrumentationVector.h"
34 #include "wtf/text/StringBuilder.h" 35 #include "wtf/text/StringBuilder.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 } 125 }
125 126
126 PassRefPtr<CSSValue> StylePropertySet::getPropertyCSSValue(CSSPropertyID propert yID) const 127 PassRefPtr<CSSValue> StylePropertySet::getPropertyCSSValue(CSSPropertyID propert yID) const
127 { 128 {
128 int foundPropertyIndex = findPropertyIndex(propertyID); 129 int foundPropertyIndex = findPropertyIndex(propertyID);
129 if (foundPropertyIndex == -1) 130 if (foundPropertyIndex == -1)
130 return 0; 131 return 0;
131 return propertyAt(foundPropertyIndex).value(); 132 return propertyAt(foundPropertyIndex).value();
132 } 133 }
133 134
135 unsigned StylePropertySet::variableCount() const
esprehn 2013/07/04 02:48:52 Why is this needed? Your getComputedStyle one look
alancutter (OOO until 2018) 2013/07/04 06:18:14 In the StylePropertySet the CSS Variable propertie
136 {
137 ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
138 unsigned count = 0;
139 for (unsigned i = 0; i < propertyCount(); ++i) {
140 if (propertyAt(i).id() == CSSPropertyVariable)
141 count++;
142 }
143 return count;
144 }
145
146 String StylePropertySet::variableValue(const AtomicString& name) const
147 {
148 ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
149 size_t index = findVariableIndex(name);
150 if (index == notFound)
151 return String();
152 return static_cast<CSSVariableValue*>(propertyAt(index).value())->value();
153 }
154
134 bool MutableStylePropertySet::removeShorthandProperty(CSSPropertyID propertyID) 155 bool MutableStylePropertySet::removeShorthandProperty(CSSPropertyID propertyID)
135 { 156 {
136 StylePropertyShorthand shorthand = shorthandForProperty(propertyID); 157 StylePropertyShorthand shorthand = shorthandForProperty(propertyID);
137 if (!shorthand.length()) 158 if (!shorthand.length())
138 return false; 159 return false;
139 160
140 bool ret = removePropertiesInSet(shorthand.properties(), shorthand.length()) ; 161 bool ret = removePropertiesInSet(shorthand.properties(), shorthand.length()) ;
141 162
142 CSSPropertyID prefixingVariant = prefixingVariantForPropertyId(propertyID); 163 CSSPropertyID prefixingVariant = prefixingVariantForPropertyId(propertyID);
143 if (prefixingVariant == propertyID) 164 if (prefixingVariant == propertyID)
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 279
259 unsigned getIndexInShorthandVectorForPrefixingVariant(const CSSProperty& propert y, CSSPropertyID prefixingVariant) 280 unsigned getIndexInShorthandVectorForPrefixingVariant(const CSSProperty& propert y, CSSPropertyID prefixingVariant)
260 { 281 {
261 if (!property.isSetFromShorthand()) 282 if (!property.isSetFromShorthand())
262 return 0; 283 return 0;
263 284
264 CSSPropertyID prefixedShorthand = prefixingVariantForPropertyId(property.sho rthandID()); 285 CSSPropertyID prefixedShorthand = prefixingVariantForPropertyId(property.sho rthandID());
265 return indexOfShorthandForLonghand(prefixedShorthand, matchingShorthandsForL onghand(prefixingVariant)); 286 return indexOfShorthandForLonghand(prefixedShorthand, matchingShorthandsForL onghand(prefixingVariant));
266 } 287 }
267 288
289 bool MutableStylePropertySet::setVariableValue(const AtomicString& name, const S tring& value, ExceptionCode&, bool important)
290 {
291 ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
292 if (value.isEmpty())
293 return removeVariable(name);
294
295 size_t index = findVariableIndex(name);
296 if (index != notFound) {
297 CSSValue* cssValue = m_propertyVector.at(index).value();
298 ASSERT(cssValue && cssValue->isVariableValue());
299 if (static_cast<CSSVariableValue*>(cssValue)->value() == value)
300 return false;
301 }
302
303 CSSProperty property(CSSPropertyVariable, CSSVariableValue::create(name, val ue), important);
304 if (index == notFound)
305 m_propertyVector.append(property);
306 else
307 m_propertyVector.at(index) = property;
308 return true;
309 }
310
268 void MutableStylePropertySet::appendPrefixingVariantProperty(const CSSProperty& property) 311 void MutableStylePropertySet::appendPrefixingVariantProperty(const CSSProperty& property)
269 { 312 {
270 m_propertyVector.append(property); 313 m_propertyVector.append(property);
271 CSSPropertyID prefixingVariant = prefixingVariantForPropertyId(property.id() ); 314 CSSPropertyID prefixingVariant = prefixingVariantForPropertyId(property.id() );
272 if (prefixingVariant == property.id()) 315 if (prefixingVariant == property.id())
273 return; 316 return;
274 317
275 m_propertyVector.append(CSSProperty(prefixingVariant, property.value(), prop erty.isImportant(), property.isSetFromShorthand(), getIndexInShorthandVectorForP refixingVariant(property, prefixingVariant), property.metadata().m_implicit)); 318 m_propertyVector.append(CSSProperty(prefixingVariant, property.value(), prop erty.isImportant(), property.isSetFromShorthand(), getIndexInShorthandVectorForP refixingVariant(property, prefixingVariant), property.metadata().m_implicit));
276 } 319 }
277 320
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 newProperties.append(property); 478 newProperties.append(property);
436 } 479 }
437 480
438 bool changed = newProperties.size() != m_propertyVector.size(); 481 bool changed = newProperties.size() != m_propertyVector.size();
439 m_propertyVector = newProperties; 482 m_propertyVector = newProperties;
440 return changed; 483 return changed;
441 } 484 }
442 485
443 int StylePropertySet::findPropertyIndex(CSSPropertyID propertyID) const 486 int StylePropertySet::findPropertyIndex(CSSPropertyID propertyID) const
444 { 487 {
488 // CSS variables share the same property ID, findVariableIndex() should be u sed for variables instead.
489 ASSERT(propertyID != CSSPropertyVariable);
445 for (int n = propertyCount() - 1 ; n >= 0; --n) { 490 for (int n = propertyCount() - 1 ; n >= 0; --n) {
446 if (propertyID == propertyAt(n).id()) { 491 if (propertyID == propertyAt(n).id()) {
447 // Only enabled properties should be part of the style. 492 // Only enabled properties should be part of the style.
448 ASSERT(RuntimeCSSEnabled::isCSSPropertyEnabled(propertyID)); 493 ASSERT(RuntimeCSSEnabled::isCSSPropertyEnabled(propertyID));
449 return n; 494 return n;
450 } 495 }
451 } 496 }
452 return -1; 497 return -1;
453 } 498 }
454 499
500 size_t StylePropertySet::findVariableIndex(const AtomicString& name) const
501 {
502 ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
503 for (int i = propertyCount() - 1; i >= 0; --i) {
504 const PropertyReference& property = propertyAt(i);
505 if (property.id() == CSSPropertyVariable && static_cast<const CSSVariabl eValue*>(property.value())->name() == name)
506 return i;
507 }
508 return notFound;
509 }
510
455 CSSProperty* MutableStylePropertySet::findCSSPropertyWithID(CSSPropertyID proper tyID) 511 CSSProperty* MutableStylePropertySet::findCSSPropertyWithID(CSSPropertyID proper tyID)
456 { 512 {
457 int foundPropertyIndex = findPropertyIndex(propertyID); 513 int foundPropertyIndex = findPropertyIndex(propertyID);
458 if (foundPropertyIndex == -1) 514 if (foundPropertyIndex == -1)
459 return 0; 515 return 0;
460 return &m_propertyVector.at(foundPropertyIndex); 516 return &m_propertyVector.at(foundPropertyIndex);
461 } 517 }
462 518
463 bool StylePropertySet::propertyMatches(CSSPropertyID propertyID, const CSSValue* propertyValue) const 519 bool StylePropertySet::propertyMatches(CSSPropertyID propertyID, const CSSValue* propertyValue) const
464 { 520 {
(...skipping 24 matching lines...) Expand all
489 for (unsigned i = 0; i < size; ++i) { 545 for (unsigned i = 0; i < size; ++i) {
490 PropertyReference property = propertyAt(i); 546 PropertyReference property = propertyAt(i);
491 if (style->cssPropertyMatches(property.id(), property.value())) 547 if (style->cssPropertyMatches(property.id(), property.value()))
492 propertiesToRemove.append(property.id()); 548 propertiesToRemove.append(property.id());
493 } 549 }
494 // FIXME: This should use mass removal. 550 // FIXME: This should use mass removal.
495 for (unsigned i = 0; i < propertiesToRemove.size(); ++i) 551 for (unsigned i = 0; i < propertiesToRemove.size(); ++i)
496 removeProperty(propertiesToRemove[i]); 552 removeProperty(propertiesToRemove[i]);
497 } 553 }
498 554
555 bool MutableStylePropertySet::removeVariable(const AtomicString& name)
556 {
557 ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
558 size_t index = findVariableIndex(name);
559 if (index == notFound)
560 return false;
561 m_propertyVector.remove(index);
562 return true;
563 }
564
565 bool MutableStylePropertySet::clearVariables()
566 {
567 ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
568 bool removed = false;
569 size_t i = 0;
570 while (i < propertyCount()) {
571 if (propertyAt(i).id() == CSSPropertyVariable) {
572 removed = true;
573 m_propertyVector.remove(i);
574 } else {
575 i++;
576 }
577 }
578 return removed;
579 }
580
499 PassRefPtr<MutableStylePropertySet> StylePropertySet::mutableCopy() const 581 PassRefPtr<MutableStylePropertySet> StylePropertySet::mutableCopy() const
500 { 582 {
501 return adoptRef(new MutableStylePropertySet(*this)); 583 return adoptRef(new MutableStylePropertySet(*this));
502 } 584 }
503 585
504 PassRefPtr<MutableStylePropertySet> StylePropertySet::copyPropertiesInSet(const Vector<CSSPropertyID>& properties) const 586 PassRefPtr<MutableStylePropertySet> StylePropertySet::copyPropertiesInSet(const Vector<CSSPropertyID>& properties) const
505 { 587 {
506 Vector<CSSProperty, 256> list; 588 Vector<CSSProperty, 256> list;
507 list.reserveInitialCapacity(properties.size()); 589 list.reserveInitialCapacity(properties.size());
508 for (unsigned i = 0; i < properties.size(); ++i) { 590 for (unsigned i = 0; i < properties.size(); ++i) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 result.appendLiteral(": "); 686 result.appendLiteral(": ");
605 result.append(propertyValue()->cssText()); 687 result.append(propertyValue()->cssText());
606 if (isImportant()) 688 if (isImportant())
607 result.appendLiteral(" !important"); 689 result.appendLiteral(" !important");
608 result.append(';'); 690 result.append(';');
609 return result.toString(); 691 return result.toString();
610 } 692 }
611 693
612 694
613 } // namespace WebCore 695 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698