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

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

Issue 21006006: Add forEach() to CSSVariablesMap (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Generator & test nits Created 7 years, 4 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 * Copyright (C) 2013 Intel Corporation. All rights reserved. 5 * Copyright (C) 2013 Intel Corporation. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 return indexOfShorthandForLonghand(prefixedShorthand, matchingShorthandsForL onghand(prefixingVariant)); 277 return indexOfShorthandForLonghand(prefixedShorthand, matchingShorthandsForL onghand(prefixingVariant));
278 } 278 }
279 279
280 bool MutableStylePropertySet::setVariableValue(const AtomicString& name, const S tring& value, bool important) 280 bool MutableStylePropertySet::setVariableValue(const AtomicString& name, const S tring& value, bool important)
281 { 281 {
282 ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled()); 282 ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
283 if (value.isEmpty()) 283 if (value.isEmpty())
284 return removeVariable(name); 284 return removeVariable(name);
285 285
286 size_t index = findVariableIndex(name); 286 size_t index = findVariableIndex(name);
287 if (index != notFound) { 287 if (index == notFound) {
288 CSSValue* cssValue = m_propertyVector.at(index).value(); 288 VariablesIterators* iterators = activeVariablesIterators();
289 if (iterators) {
290 VariablesIterators::iterator end = iterators->end();
291 for (VariablesIterators::iterator it = iterators->begin(); it != end ; ++it)
292 (*it)->addedVariable(name);
293 }
294 } else {
295 const CSSValue* cssValue = m_propertyVector.at(index).value();
289 if (toCSSVariableValue(cssValue)->value() == value) 296 if (toCSSVariableValue(cssValue)->value() == value)
290 return false; 297 return false;
291 } 298 }
292 299
293 CSSProperty property(CSSPropertyVariable, CSSVariableValue::create(name, val ue), important); 300 CSSProperty property(CSSPropertyVariable, CSSVariableValue::create(name, val ue), important);
294 if (index == notFound) 301 if (index == notFound)
295 m_propertyVector.append(property); 302 m_propertyVector.append(property);
296 else 303 else
297 m_propertyVector.at(index) = property; 304 m_propertyVector.at(index) = property;
298 return true; 305 return true;
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 removeProperty(propertiesToRemove[i]); 552 removeProperty(propertiesToRemove[i]);
546 } 553 }
547 554
548 bool MutableStylePropertySet::removeVariable(const AtomicString& name) 555 bool MutableStylePropertySet::removeVariable(const AtomicString& name)
549 { 556 {
550 ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled()); 557 ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
551 size_t index = findVariableIndex(name); 558 size_t index = findVariableIndex(name);
552 if (index == notFound) 559 if (index == notFound)
553 return false; 560 return false;
554 m_propertyVector.remove(index); 561 m_propertyVector.remove(index);
562 VariablesIterators* iterators = activeVariablesIterators();
563 if (iterators) {
564 VariablesIterators::iterator end = iterators->end();
565 for (VariablesIterators::iterator it = iterators->begin(); it != end; ++ it)
566 (*it)->removedVariable(name);
567 }
555 return true; 568 return true;
556 } 569 }
557 570
558 bool MutableStylePropertySet::clearVariables() 571 bool MutableStylePropertySet::clearVariables()
559 { 572 {
560 ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled()); 573 ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
561 CSSPropertyID variablesId = CSSPropertyVariable; 574 CSSPropertyID variablesId = CSSPropertyVariable;
562 return removePropertiesInSet(&variablesId, 1); 575 bool removed = removePropertiesInSet(&variablesId, 1);
576 if (removed) {
577 VariablesIterators* iterators = activeVariablesIterators();
578 if (iterators) {
579 VariablesIterators::iterator end = iterators->end();
580 for (VariablesIterators::iterator it = iterators->begin(); it != end ; ++it)
581 (*it)->clearedVariables();
582 }
583 }
584 return removed;
585 }
586
587 PassRefPtr<MutableStylePropertySet::VariablesIterator> MutableStylePropertySet:: VariablesIterator::create(MutableStylePropertySet* propertySet)
588 {
589 ASSERT(RuntimeEnabledFeatures::cssVariablesEnabled());
590 RefPtr<VariablesIterator> iterator = adoptRef(new VariablesIterator(property Set));
591 const size_t propertyCount = propertySet->propertyCount();
592 size_t variableCount = 0;
593 iterator->m_remainingNames.resize(propertyCount);
594 for (int i = propertyCount; i--;) {
595 const PropertyReference& property = propertySet->propertyAt(i);
596 if (property.id() == CSSPropertyVariable)
597 iterator->m_remainingNames[variableCount++] = toCSSVariableValue(pro perty.value())->name();
598 }
599 iterator->m_remainingNames.shrink(variableCount);
600
601 MutableStylePropertySet::VariablesIteratorsMap* map = MutableStylePropertySe t::activeVariablesIteratorsMap();
602 if (map->contains(propertySet))
603 map->find(propertySet)->value.append(iterator);
604 else
605 map->add(propertySet, VariablesIterators()).iterator->value.append(itera tor);
606
607 return iterator.release();
608 }
609
610 void MutableStylePropertySet::VariablesIterator::addedVariable(const AtomicStrin g& name)
611 {
612 ASSERT(!m_remainingNames.contains(name));
613 ASSERT(!m_newNames.contains(name));
614 m_newNames.append(name);
615 }
616
617 void MutableStylePropertySet::VariablesIterator::removedVariable(const AtomicStr ing& name)
618 {
619 size_t index = m_remainingNames.find(name);
620 if (index != notFound)
621 m_remainingNames.remove(index);
622 index = m_newNames.find(name);
623 if (index != notFound)
624 m_newNames.remove(index);
625 }
626
627 void MutableStylePropertySet::VariablesIterator::clearedVariables()
628 {
629 m_remainingNames.clear();
630 m_newNames.clear();
631 }
632
633 void MutableStylePropertySet::VariablesIterator::advance()
634 {
635 if (!atEnd())
636 m_remainingNames.removeLast();
637 if (!m_newNames.isEmpty()) {
638 m_remainingNames.appendVector(m_newNames);
639 m_newNames.clear();
640 }
641 }
642
643 MutableStylePropertySet::VariablesIterator::~VariablesIterator()
644 {
645 MutableStylePropertySet::VariablesIterators& iterators = MutableStylePropert ySet::activeVariablesIteratorsMap()->find(m_propertySet.get())->value;
646 iterators.remove(iterators.reverseFind(this));
647 }
648
649 MutableStylePropertySet::VariablesIterators* MutableStylePropertySet::activeVari ablesIterators()
650 {
651 VariablesIteratorsMap* map = activeVariablesIteratorsMap();
652 VariablesIteratorsMap::iterator it = map->find(this);
653 if (it == map->end())
654 return 0;
655 return &it->value;
656 }
657
658 MutableStylePropertySet::VariablesIteratorsMap* MutableStylePropertySet::activeV ariablesIteratorsMap()
659 {
660 DEFINE_STATIC_LOCAL(VariablesIteratorsMap, map, ());
661 return &map;
563 } 662 }
564 663
565 PassRefPtr<MutableStylePropertySet> StylePropertySet::mutableCopy() const 664 PassRefPtr<MutableStylePropertySet> StylePropertySet::mutableCopy() const
566 { 665 {
567 return adoptRef(new MutableStylePropertySet(*this)); 666 return adoptRef(new MutableStylePropertySet(*this));
568 } 667 }
569 668
570 PassRefPtr<MutableStylePropertySet> StylePropertySet::copyPropertiesInSet(const Vector<CSSPropertyID>& properties) const 669 PassRefPtr<MutableStylePropertySet> StylePropertySet::copyPropertiesInSet(const Vector<CSSPropertyID>& properties) const
571 { 670 {
572 Vector<CSSProperty, 256> list; 671 Vector<CSSProperty, 256> list;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 PassRefPtr<MutableStylePropertySet> MutableStylePropertySet::create(CSSParserMod e cssParserMode) 726 PassRefPtr<MutableStylePropertySet> MutableStylePropertySet::create(CSSParserMod e cssParserMode)
628 { 727 {
629 return adoptRef(new MutableStylePropertySet(cssParserMode)); 728 return adoptRef(new MutableStylePropertySet(cssParserMode));
630 } 729 }
631 730
632 PassRefPtr<MutableStylePropertySet> MutableStylePropertySet::create(const CSSPro perty* properties, unsigned count) 731 PassRefPtr<MutableStylePropertySet> MutableStylePropertySet::create(const CSSPro perty* properties, unsigned count)
633 { 732 {
634 return adoptRef(new MutableStylePropertySet(properties, count)); 733 return adoptRef(new MutableStylePropertySet(properties, count));
635 } 734 }
636 735
736 MutableStylePropertySet::~MutableStylePropertySet()
737 {
738 activeVariablesIteratorsMap()->remove(this);
739 }
740
637 String StylePropertySet::PropertyReference::cssName() const 741 String StylePropertySet::PropertyReference::cssName() const
638 { 742 {
639 if (id() == CSSPropertyVariable) { 743 if (id() == CSSPropertyVariable) {
640 if (!propertyValue()->isVariableValue()) 744 if (!propertyValue()->isVariableValue())
641 return emptyString(); // Should not happen, but if it does, avoid a bad cast. 745 return emptyString(); // Should not happen, but if it does, avoid a bad cast.
642 return "var-" + toCSSVariableValue(propertyValue())->name(); 746 return "var-" + toCSSVariableValue(propertyValue())->name();
643 } 747 }
644 return getPropertyNameString(id()); 748 return getPropertyNameString(id());
645 } 749 }
646 750
647 String StylePropertySet::PropertyReference::cssText() const 751 String StylePropertySet::PropertyReference::cssText() const
648 { 752 {
649 StringBuilder result; 753 StringBuilder result;
650 result.append(cssName()); 754 result.append(cssName());
651 result.appendLiteral(": "); 755 result.appendLiteral(": ");
652 result.append(propertyValue()->cssText()); 756 result.append(propertyValue()->cssText());
653 if (isImportant()) 757 if (isImportant())
654 result.appendLiteral(" !important"); 758 result.appendLiteral(" !important");
655 result.append(';'); 759 result.append(';');
656 return result.toString(); 760 return result.toString();
657 } 761 }
658 762
659 763
660 } // namespace WebCore 764 } // namespace WebCore
OLDNEW
« Source/bindings/scripts/code_generator_v8.py ('K') | « Source/core/css/StylePropertySet.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698