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

Side by Side Diff: Source/core/css/analyzer/DescendantInvalidationSet.cpp

Issue 199633020: Move all style invalidation code into the css/invalidation directory. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Merge. Created 6 years, 9 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
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "config.h"
32 #include "core/css/analyzer/DescendantInvalidationSet.h"
33
34 #include "core/css/resolver/StyleResolver.h"
35 #include "core/dom/Element.h"
36
37 namespace WebCore {
38
39 DescendantInvalidationSet::DescendantInvalidationSet()
40 : m_allDescendantsMightBeInvalid(false)
41 {
42 }
43
44 void DescendantInvalidationSet::combine(const DescendantInvalidationSet& other)
45 {
46 // No longer bother combining data structures, since the whole subtree is de emed invalid.
47 if (wholeSubtreeInvalid())
48 return;
49
50 if (other.wholeSubtreeInvalid()) {
51 setWholeSubtreeInvalid();
52 return;
53 }
54
55 if (other.m_classes) {
56 HashSet<AtomicString>::const_iterator end = other.m_classes->end();
57 for (HashSet<AtomicString>::const_iterator it = other.m_classes->begin() ; it != end; ++it)
58 addClass(*it);
59 }
60
61 if (other.m_ids) {
62 HashSet<AtomicString>::const_iterator end = other.m_ids->end();
63 for (HashSet<AtomicString>::const_iterator it = other.m_ids->begin(); it != end; ++it)
64 addId(*it);
65 }
66
67 if (other.m_tagNames) {
68 HashSet<AtomicString>::const_iterator end = other.m_tagNames->end();
69 for (HashSet<AtomicString>::const_iterator it = other.m_tagNames->begin( ); it != end; ++it)
70 addTagName(*it);
71 }
72
73 if (other.m_attributes) {
74 HashSet<AtomicString>::const_iterator end = other.m_attributes->end();
75 for (HashSet<AtomicString>::const_iterator it = other.m_attributes->begi n(); it != end; ++it)
76 addAttribute(*it);
77 }
78 }
79
80 HashSet<AtomicString>& DescendantInvalidationSet::ensureClassSet()
81 {
82 if (!m_classes)
83 m_classes = adoptPtr(new HashSet<AtomicString>);
84 return *m_classes;
85 }
86
87 HashSet<AtomicString>& DescendantInvalidationSet::ensureIdSet()
88 {
89 if (!m_ids)
90 m_ids = adoptPtr(new HashSet<AtomicString>);
91 return *m_ids;
92 }
93
94 HashSet<AtomicString>& DescendantInvalidationSet::ensureTagNameSet()
95 {
96 if (!m_tagNames)
97 m_tagNames = adoptPtr(new HashSet<AtomicString>);
98 return *m_tagNames;
99 }
100
101 HashSet<AtomicString>& DescendantInvalidationSet::ensureAttributeSet()
102 {
103 if (!m_attributes)
104 m_attributes = adoptPtr(new HashSet<AtomicString>);
105 return *m_attributes;
106 }
107
108 void DescendantInvalidationSet::addClass(const AtomicString& className)
109 {
110 if (wholeSubtreeInvalid())
111 return;
112 ensureClassSet().add(className);
113 }
114
115 void DescendantInvalidationSet::addId(const AtomicString& id)
116 {
117 if (wholeSubtreeInvalid())
118 return;
119 ensureIdSet().add(id);
120 }
121
122 void DescendantInvalidationSet::addTagName(const AtomicString& tagName)
123 {
124 if (wholeSubtreeInvalid())
125 return;
126 ensureTagNameSet().add(tagName);
127 }
128
129 void DescendantInvalidationSet::addAttribute(const AtomicString& attribute)
130 {
131 if (wholeSubtreeInvalid())
132 return;
133 ensureAttributeSet().add(attribute);
134 }
135
136 void DescendantInvalidationSet::getClasses(Vector<AtomicString>& classes) const
137 {
138 if (!m_classes)
139 return;
140 for (HashSet<AtomicString>::const_iterator it = m_classes->begin(); it != m_ classes->end(); ++it)
141 classes.append(*it);
142 }
143
144 void DescendantInvalidationSet::getAttributes(Vector<AtomicString>& attributes) const
145 {
146 if (!m_attributes)
147 return;
148 for (HashSet<AtomicString>::const_iterator it = m_attributes->begin(); it != m_attributes->end(); ++it)
149 attributes.append(*it);
150 }
151
152 void DescendantInvalidationSet::setWholeSubtreeInvalid()
153 {
154 if (m_allDescendantsMightBeInvalid)
155 return;
156
157 m_allDescendantsMightBeInvalid = true;
158 m_classes = nullptr;
159 m_ids = nullptr;
160 m_tagNames = nullptr;
161 m_attributes = nullptr;
162 }
163
164 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/css/analyzer/DescendantInvalidationSet.h ('k') | Source/core/css/analyzer/DescendantInvalidationSetTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698