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

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

Issue 21006006: Add forEach() to CSSVariablesMap (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase and review changes Created 7 years, 2 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/CSSVariablesMap.h ('k') | Source/core/css/CSSVariablesMap.idl » ('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 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 return String(); 48 return String();
49 } 49 }
50 50
51 bool CSSVariablesMap::has(const AtomicString& name) const 51 bool CSSVariablesMap::has(const AtomicString& name) const
52 { 52 {
53 if (m_styleDeclaration) 53 if (m_styleDeclaration)
54 return !get(name).isEmpty(); 54 return !get(name).isEmpty();
55 return false; 55 return false;
56 } 56 }
57 57
58 void CSSVariablesMap::set(const AtomicString& name, const String& value, Excepti onState& es) const 58 void CSSVariablesMap::set(const AtomicString& name, const String& value, Excepti onState& es)
59 { 59 {
60 if (m_styleDeclaration) 60 if (!m_styleDeclaration)
61 m_styleDeclaration->setVariableValue(name, value, es); 61 return;
62 if (m_styleDeclaration->setVariableValue(name, value, es)) {
63 Iterators::iterator end = m_activeIterators.end();
64 for (Iterators::iterator it = m_activeIterators.begin(); it != end; ++it )
65 (*it)->addedVariable(name);
66 }
62 } 67 }
63 68
64 bool CSSVariablesMap::remove(const AtomicString& name) const 69 bool CSSVariablesMap::remove(const AtomicString& name)
65 { 70 {
66 if (m_styleDeclaration) 71 if (!m_styleDeclaration)
67 return m_styleDeclaration->removeVariable(name); 72 return false;
73 if (m_styleDeclaration->removeVariable(name)) {
74 Iterators::iterator end = m_activeIterators.end();
75 for (Iterators::iterator it = m_activeIterators.begin(); it != end; ++it )
76 (*it)->removedVariable(name);
77 return true;
78 }
68 return false; 79 return false;
69 } 80 }
70 81
71 void CSSVariablesMap::clear(ExceptionState& es) const 82 void CSSVariablesMap::clear(ExceptionState& es)
72 { 83 {
73 if (m_styleDeclaration) 84 if (!m_styleDeclaration)
74 return m_styleDeclaration->clearVariables(es); 85 return;
86 if (m_styleDeclaration->clearVariables(es)) {
87 Iterators::iterator end = m_activeIterators.end();
88 for (Iterators::iterator it = m_activeIterators.begin(); it != end; ++it )
89 (*it)->clearedVariables();
90 }
91 }
92
93 void CSSVariablesMap::forEach(PassRefPtr<CSSVariablesMapForEachCallback> callbac k, ScriptValue& thisArg) const
94 {
95 forEach(callback, &thisArg);
96 }
97
98 void CSSVariablesMap::forEach(PassRefPtr<CSSVariablesMapForEachCallback> callbac k) const
99 {
100 forEach(callback, 0);
101 }
102
103 void CSSVariablesMap::forEach(PassRefPtr<CSSVariablesMapForEachCallback> callbac k, ScriptValue* thisArg) const
104 {
105 if (!m_styleDeclaration)
106 return;
107 RefPtr<CSSVariablesIterator> iterator = m_styleDeclaration->variablesIterato r();
108 m_activeIterators.append(iterator.get());
109 while (!iterator->atEnd()) {
110 String name = iterator->name();
111 String value = iterator->value();
112 if (thisArg)
113 callback->handleItem(*thisArg, value, name, const_cast<CSSVariablesM ap*>(this));
114 else
115 callback->handleItem(value, name, const_cast<CSSVariablesMap*>(this) );
116 iterator->advance();
117 }
118 ASSERT(m_activeIterators.last() == iterator.get());
119 m_activeIterators.removeLast();
75 } 120 }
76 121
77 } // namespace WebCore 122 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/css/CSSVariablesMap.h ('k') | Source/core/css/CSSVariablesMap.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698