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

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 onto ToT, cleaned up includes 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
« no previous file with comments | « Source/core/css/StylePropertySet.h ('k') | Source/core/css/resolver/StyleResolver.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/text/StringBuilder.h" 34 #include "wtf/text/StringBuilder.h"
34 35
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 115 }
115 116
116 PassRefPtr<CSSValue> StylePropertySet::getPropertyCSSValue(CSSPropertyID propert yID) const 117 PassRefPtr<CSSValue> StylePropertySet::getPropertyCSSValue(CSSPropertyID propert yID) const
117 { 118 {
118 int foundPropertyIndex = findPropertyIndex(propertyID); 119 int foundPropertyIndex = findPropertyIndex(propertyID);
119 if (foundPropertyIndex == -1) 120 if (foundPropertyIndex == -1)
120 return 0; 121 return 0;
121 return propertyAt(foundPropertyIndex).value(); 122 return propertyAt(foundPropertyIndex).value();
122 } 123 }
123 124
125 unsigned StylePropertySet::variableCount() const
126 {
127 ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
128 unsigned count = 0;
129 for (unsigned i = 0; i < propertyCount(); ++i) {
130 if (propertyAt(i).id() == CSSPropertyVariable)
131 count++;
132 }
133 return count;
134 }
135
136 String StylePropertySet::variableValue(const AtomicString& name) const
137 {
138 ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
139 size_t index = findVariableIndex(name);
140 if (index == notFound)
141 return String();
142 return toCSSVariableValue(propertyAt(index).value())->value();
143 }
144
124 bool MutableStylePropertySet::removeShorthandProperty(CSSPropertyID propertyID) 145 bool MutableStylePropertySet::removeShorthandProperty(CSSPropertyID propertyID)
125 { 146 {
126 StylePropertyShorthand shorthand = shorthandForProperty(propertyID); 147 StylePropertyShorthand shorthand = shorthandForProperty(propertyID);
127 if (!shorthand.length()) 148 if (!shorthand.length())
128 return false; 149 return false;
129 150
130 bool ret = removePropertiesInSet(shorthand.properties(), shorthand.length()) ; 151 bool ret = removePropertiesInSet(shorthand.properties(), shorthand.length()) ;
131 152
132 CSSPropertyID prefixingVariant = prefixingVariantForPropertyId(propertyID); 153 CSSPropertyID prefixingVariant = prefixingVariantForPropertyId(propertyID);
133 if (prefixingVariant == propertyID) 154 if (prefixingVariant == propertyID)
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 269
249 unsigned getIndexInShorthandVectorForPrefixingVariant(const CSSProperty& propert y, CSSPropertyID prefixingVariant) 270 unsigned getIndexInShorthandVectorForPrefixingVariant(const CSSProperty& propert y, CSSPropertyID prefixingVariant)
250 { 271 {
251 if (!property.isSetFromShorthand()) 272 if (!property.isSetFromShorthand())
252 return 0; 273 return 0;
253 274
254 CSSPropertyID prefixedShorthand = prefixingVariantForPropertyId(property.sho rthandID()); 275 CSSPropertyID prefixedShorthand = prefixingVariantForPropertyId(property.sho rthandID());
255 return indexOfShorthandForLonghand(prefixedShorthand, matchingShorthandsForL onghand(prefixingVariant)); 276 return indexOfShorthandForLonghand(prefixedShorthand, matchingShorthandsForL onghand(prefixingVariant));
256 } 277 }
257 278
279 bool MutableStylePropertySet::setVariableValue(const AtomicString& name, const S tring& value, bool important)
280 {
281 ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
282 if (value.isEmpty())
283 return removeVariable(name);
284
285 size_t index = findVariableIndex(name);
286 if (index != notFound) {
287 CSSValue* cssValue = m_propertyVector.at(index).value();
288 if (toCSSVariableValue(cssValue)->value() == value)
289 return false;
290 }
291
292 CSSProperty property(CSSPropertyVariable, CSSVariableValue::create(name, val ue), important);
293 if (index == notFound)
294 m_propertyVector.append(property);
295 else
296 m_propertyVector.at(index) = property;
297 return true;
298 }
299
258 void MutableStylePropertySet::appendPrefixingVariantProperty(const CSSProperty& property) 300 void MutableStylePropertySet::appendPrefixingVariantProperty(const CSSProperty& property)
259 { 301 {
260 m_propertyVector.append(property); 302 m_propertyVector.append(property);
261 CSSPropertyID prefixingVariant = prefixingVariantForPropertyId(property.id() ); 303 CSSPropertyID prefixingVariant = prefixingVariantForPropertyId(property.id() );
262 if (prefixingVariant == property.id()) 304 if (prefixingVariant == property.id())
263 return; 305 return;
264 306
265 m_propertyVector.append(CSSProperty(prefixingVariant, property.value(), prop erty.isImportant(), property.isSetFromShorthand(), getIndexInShorthandVectorForP refixingVariant(property, prefixingVariant), property.metadata().m_implicit)); 307 m_propertyVector.append(CSSProperty(prefixingVariant, property.value(), prop erty.isImportant(), property.isSetFromShorthand(), getIndexInShorthandVectorForP refixingVariant(property, prefixingVariant), property.metadata().m_implicit));
266 } 308 }
267 309
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 for (int n = propertyCount() - 1 ; n >= 0; --n) { 480 for (int n = propertyCount() - 1 ; n >= 0; --n) {
439 if (propertyID == propertyAt(n).id()) { 481 if (propertyID == propertyAt(n).id()) {
440 // Only enabled properties should be part of the style. 482 // Only enabled properties should be part of the style.
441 ASSERT(RuntimeCSSEnabled::isCSSPropertyEnabled(propertyID)); 483 ASSERT(RuntimeCSSEnabled::isCSSPropertyEnabled(propertyID));
442 return n; 484 return n;
443 } 485 }
444 } 486 }
445 return -1; 487 return -1;
446 } 488 }
447 489
490 size_t StylePropertySet::findVariableIndex(const AtomicString& name) const
491 {
492 ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
493 for (int i = propertyCount() - 1; i >= 0; --i) {
494 const PropertyReference& property = propertyAt(i);
495 if (property.id() == CSSPropertyVariable && toCSSVariableValue(property. value())->name() == name)
496 return i;
497 }
498 return notFound;
499 }
500
448 CSSProperty* MutableStylePropertySet::findCSSPropertyWithID(CSSPropertyID proper tyID) 501 CSSProperty* MutableStylePropertySet::findCSSPropertyWithID(CSSPropertyID proper tyID)
449 { 502 {
450 int foundPropertyIndex = findPropertyIndex(propertyID); 503 int foundPropertyIndex = findPropertyIndex(propertyID);
451 if (foundPropertyIndex == -1) 504 if (foundPropertyIndex == -1)
452 return 0; 505 return 0;
453 return &m_propertyVector.at(foundPropertyIndex); 506 return &m_propertyVector.at(foundPropertyIndex);
454 } 507 }
455 508
456 bool StylePropertySet::propertyMatches(CSSPropertyID propertyID, const CSSValue* propertyValue) const 509 bool StylePropertySet::propertyMatches(CSSPropertyID propertyID, const CSSValue* propertyValue) const
457 { 510 {
(...skipping 24 matching lines...) Expand all
482 for (unsigned i = 0; i < size; ++i) { 535 for (unsigned i = 0; i < size; ++i) {
483 PropertyReference property = propertyAt(i); 536 PropertyReference property = propertyAt(i);
484 if (style->cssPropertyMatches(property.id(), property.value())) 537 if (style->cssPropertyMatches(property.id(), property.value()))
485 propertiesToRemove.append(property.id()); 538 propertiesToRemove.append(property.id());
486 } 539 }
487 // FIXME: This should use mass removal. 540 // FIXME: This should use mass removal.
488 for (unsigned i = 0; i < propertiesToRemove.size(); ++i) 541 for (unsigned i = 0; i < propertiesToRemove.size(); ++i)
489 removeProperty(propertiesToRemove[i]); 542 removeProperty(propertiesToRemove[i]);
490 } 543 }
491 544
545 bool MutableStylePropertySet::removeVariable(const AtomicString& name)
546 {
547 ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
548 size_t index = findVariableIndex(name);
549 if (index == notFound)
550 return false;
551 m_propertyVector.remove(index);
552 return true;
553 }
554
555 bool MutableStylePropertySet::clearVariables()
556 {
557 ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
558 CSSPropertyID variablesId = CSSPropertyVariable;
559 return removePropertiesInSet(&variablesId, 1);
560 }
561
492 PassRefPtr<MutableStylePropertySet> StylePropertySet::mutableCopy() const 562 PassRefPtr<MutableStylePropertySet> StylePropertySet::mutableCopy() const
493 { 563 {
494 return adoptRef(new MutableStylePropertySet(*this)); 564 return adoptRef(new MutableStylePropertySet(*this));
495 } 565 }
496 566
497 PassRefPtr<MutableStylePropertySet> StylePropertySet::copyPropertiesInSet(const Vector<CSSPropertyID>& properties) const 567 PassRefPtr<MutableStylePropertySet> StylePropertySet::copyPropertiesInSet(const Vector<CSSPropertyID>& properties) const
498 { 568 {
499 Vector<CSSProperty, 256> list; 569 Vector<CSSProperty, 256> list;
500 list.reserveInitialCapacity(properties.size()); 570 list.reserveInitialCapacity(properties.size());
501 for (unsigned i = 0; i < properties.size(); ++i) { 571 for (unsigned i = 0; i < properties.size(); ++i) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 } 627 }
558 628
559 PassRefPtr<MutableStylePropertySet> MutableStylePropertySet::create(const CSSPro perty* properties, unsigned count) 629 PassRefPtr<MutableStylePropertySet> MutableStylePropertySet::create(const CSSPro perty* properties, unsigned count)
560 { 630 {
561 return adoptRef(new MutableStylePropertySet(properties, count)); 631 return adoptRef(new MutableStylePropertySet(properties, count));
562 } 632 }
563 633
564 String StylePropertySet::PropertyReference::cssName() const 634 String StylePropertySet::PropertyReference::cssName() const
565 { 635 {
566 if (id() == CSSPropertyVariable) { 636 if (id() == CSSPropertyVariable) {
567 ASSERT(propertyValue()->isVariableValue());
568 if (!propertyValue()->isVariableValue()) 637 if (!propertyValue()->isVariableValue())
569 return emptyString(); // Should not happen, but if it does, avoid a bad cast. 638 return emptyString(); // Should not happen, but if it does, avoid a bad cast.
570 return "var-" + static_cast<const CSSVariableValue*>(propertyValue())->n ame(); 639 return "var-" + toCSSVariableValue(propertyValue())->name();
571 } 640 }
572 return getPropertyNameString(id()); 641 return getPropertyNameString(id());
573 } 642 }
574 643
575 String StylePropertySet::PropertyReference::cssText() const 644 String StylePropertySet::PropertyReference::cssText() const
576 { 645 {
577 StringBuilder result; 646 StringBuilder result;
578 result.append(cssName()); 647 result.append(cssName());
579 result.appendLiteral(": "); 648 result.appendLiteral(": ");
580 result.append(propertyValue()->cssText()); 649 result.append(propertyValue()->cssText());
581 if (isImportant()) 650 if (isImportant())
582 result.appendLiteral(" !important"); 651 result.appendLiteral(" !important");
583 result.append(';'); 652 result.append(';');
584 return result.toString(); 653 return result.toString();
585 } 654 }
586 655
587 656
588 } // namespace WebCore 657 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/css/StylePropertySet.h ('k') | Source/core/css/resolver/StyleResolver.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698