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

Side by Side Diff: sky/engine/core/dom/shadow/ElementShadow.cpp

Issue 759663003: Only allow one shadowRoot. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: ojan review. Created 6 years 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
« no previous file with comments | « sky/engine/core/dom/shadow/ElementShadow.h ('k') | sky/engine/core/dom/shadow/InsertionPoint.h » ('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) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Neither the name of Google Inc. nor the names of its 10 * * Neither the name of Google Inc. nor the names of its
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 m_nodes[i]->lazyReattachIfAttached(); 122 m_nodes[i]->lazyReattachIfAttached();
123 } 123 }
124 } 124 }
125 125
126 PassOwnPtr<ElementShadow> ElementShadow::create() 126 PassOwnPtr<ElementShadow> ElementShadow::create()
127 { 127 {
128 return adoptPtr(new ElementShadow()); 128 return adoptPtr(new ElementShadow());
129 } 129 }
130 130
131 ElementShadow::ElementShadow() 131 ElementShadow::ElementShadow()
132 : m_needsDistributionRecalc(false) 132 : m_shadowRoot(0)
133 , m_needsDistributionRecalc(false)
133 , m_needsSelectFeatureSet(false) 134 , m_needsSelectFeatureSet(false)
134 { 135 {
135 } 136 }
136 137
137 ElementShadow::~ElementShadow() 138 ElementShadow::~ElementShadow()
138 { 139 {
139 #if !ENABLE(OILPAN) 140 removeDetachedShadowRoot();
140 removeDetachedShadowRoots();
141 #endif
142 } 141 }
143 142
144 ShadowRoot& ElementShadow::addShadowRoot(Element& shadowHost) 143 ShadowRoot& ElementShadow::addShadowRoot(Element& shadowHost)
145 { 144 {
146 EventDispatchForbiddenScope assertNoEventDispatch; 145 EventDispatchForbiddenScope assertNoEventDispatch;
147 ScriptForbiddenScope forbidScript; 146 ScriptForbiddenScope forbidScript;
148 147
149 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow Root()) 148 ASSERT(!m_shadowRoot);
150 root->lazyReattachIfAttached();
151 149
152 RefPtr<ShadowRoot> shadowRoot = ShadowRoot::create(shadowHost.document()); 150 RefPtr<ShadowRoot> shadowRoot = ShadowRoot::create(shadowHost.document());
153 shadowRoot->setParentOrShadowHostNode(&shadowHost); 151 shadowRoot->setParentOrShadowHostNode(&shadowHost);
154 shadowRoot->setParentTreeScope(shadowHost.treeScope()); 152 shadowRoot->setParentTreeScope(shadowHost.treeScope());
155 m_shadowRoots.push(shadowRoot.get()); 153 m_shadowRoot = shadowRoot.get();
154
156 setNeedsDistributionRecalc(); 155 setNeedsDistributionRecalc();
157 156
158 shadowRoot->insertedInto(&shadowHost); 157 shadowRoot->insertedInto(&shadowHost);
159 158
160 return *shadowRoot; 159 return *shadowRoot;
161 } 160 }
162 161
163 #if !ENABLE(OILPAN) 162 void ElementShadow::removeDetachedShadowRoot()
164 void ElementShadow::removeDetachedShadowRoots()
165 { 163 {
166 // Dont protect this ref count. 164 // Dont protect this ref count.
167 Element* shadowHost = host(); 165 Element* shadowHost = host();
168 ASSERT(shadowHost); 166 ASSERT(shadowHost);
169 167
170 while (RefPtr<ShadowRoot> oldRoot = m_shadowRoots.head()) { 168 if (RefPtr<ShadowRoot> oldRoot = m_shadowRoot) {
171 shadowHost->document().removeFocusedElementOfSubtree(oldRoot.get()); 169 shadowHost->document().removeFocusedElementOfSubtree(oldRoot.get());
172 m_shadowRoots.removeHead(); 170 m_shadowRoot = 0;
173 oldRoot->setParentOrShadowHostNode(0); 171 oldRoot->setParentOrShadowHostNode(0);
174 oldRoot->setParentTreeScope(shadowHost->document()); 172 oldRoot->setParentTreeScope(shadowHost->document());
175 oldRoot->setPrev(0);
176 oldRoot->setNext(0);
177 } 173 }
178 } 174 }
179 #endif
180 175
181 void ElementShadow::attach(const Node::AttachContext& context) 176 void ElementShadow::attach(const Node::AttachContext& context)
182 { 177 {
178 if (!m_shadowRoot)
179 return;
180
181 ASSERT(m_shadowRoot->needsAttach());
182
183 Node::AttachContext childrenContext(context); 183 Node::AttachContext childrenContext(context);
184 childrenContext.resolvedStyle = 0; 184 childrenContext.resolvedStyle = 0;
185 185 m_shadowRoot->attach(childrenContext);
186 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow Root()) {
187 if (root->needsAttach())
188 root->attach(childrenContext);
189 }
190 } 186 }
191 187
192 void ElementShadow::detach(const Node::AttachContext& context) 188 void ElementShadow::detach(const Node::AttachContext& context)
193 { 189 {
190 if (!m_shadowRoot)
191 return;
192
194 Node::AttachContext childrenContext(context); 193 Node::AttachContext childrenContext(context);
195 childrenContext.resolvedStyle = 0; 194 childrenContext.resolvedStyle = 0;
196 195 m_shadowRoot->detach(childrenContext);
197 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow Root())
198 root->detach(childrenContext);
199 } 196 }
200 197
201 void ElementShadow::setNeedsDistributionRecalc() 198 void ElementShadow::setNeedsDistributionRecalc()
202 { 199 {
203 if (m_needsDistributionRecalc) 200 if (m_needsDistributionRecalc)
204 return; 201 return;
205 m_needsDistributionRecalc = true; 202 m_needsDistributionRecalc = true;
206 host()->markAncestorsWithChildNeedsDistributionRecalc(); 203 host()->markAncestorsWithChildNeedsDistributionRecalc();
207 clearDistribution(); 204 clearDistribution();
208 } 205 }
209 206
210 bool ElementShadow::hasSameStyles(const ElementShadow* other) const 207 bool ElementShadow::hasSameStyles(const ElementShadow* other) const
211 { 208 {
212 ShadowRoot* root = youngestShadowRoot(); 209 ShadowRoot* root = m_shadowRoot;
213 ShadowRoot* otherRoot = other->youngestShadowRoot(); 210 ShadowRoot* otherRoot = other->shadowRoot();
214 while (root || otherRoot) { 211 if (root || otherRoot) {
215 if (!root || !otherRoot) 212 if (!root || !otherRoot)
216 return false; 213 return false;
217 214
218 StyleSheetList* list = root->styleSheets(); 215 StyleSheetList* list = root->styleSheets();
219 StyleSheetList* otherList = otherRoot->styleSheets(); 216 StyleSheetList* otherList = otherRoot->styleSheets();
220 217
221 if (list->length() != otherList->length()) 218 if (list->length() != otherList->length())
222 return false; 219 return false;
223 220
224 for (size_t i = 0; i < list->length(); i++) { 221 for (size_t i = 0; i < list->length(); i++) {
225 if (toCSSStyleSheet(list->item(i))->contents() != toCSSStyleSheet(ot herList->item(i))->contents()) 222 if (toCSSStyleSheet(list->item(i))->contents() != toCSSStyleSheet(ot herList->item(i))->contents())
226 return false; 223 return false;
227 } 224 }
228 root = root->olderShadowRoot();
229 otherRoot = otherRoot->olderShadowRoot();
230 } 225 }
231 226
232 return true; 227 return true;
233 } 228 }
234 229
235 const InsertionPoint* ElementShadow::finalDestinationInsertionPointFor(const Nod e* key) const 230 const InsertionPoint* ElementShadow::finalDestinationInsertionPointFor(const Nod e* key) const
236 { 231 {
237 ASSERT(key && !key->document().childNeedsDistributionRecalc()); 232 ASSERT(key && !key->document().childNeedsDistributionRecalc());
238 NodeToDestinationInsertionPoints::const_iterator it = m_nodeToInsertionPoint s.find(key); 233 NodeToDestinationInsertionPoints::const_iterator it = m_nodeToInsertionPoint s.find(key);
239 return it == m_nodeToInsertionPoints.end() ? 0: it->value.last().get(); 234 return it == m_nodeToInsertionPoints.end() ? 0: it->value.last().get();
240 } 235 }
241 236
242 const DestinationInsertionPoints* ElementShadow::destinationInsertionPointsFor(c onst Node* key) const 237 const DestinationInsertionPoints* ElementShadow::destinationInsertionPointsFor(c onst Node* key) const
243 { 238 {
244 ASSERT(key && !key->document().childNeedsDistributionRecalc()); 239 ASSERT(key && !key->document().childNeedsDistributionRecalc());
245 NodeToDestinationInsertionPoints::const_iterator it = m_nodeToInsertionPoint s.find(key); 240 NodeToDestinationInsertionPoints::const_iterator it = m_nodeToInsertionPoint s.find(key);
246 return it == m_nodeToInsertionPoints.end() ? 0: &it->value; 241 return it == m_nodeToInsertionPoints.end() ? 0: &it->value;
247 } 242 }
248 243
249 void ElementShadow::distribute() 244 void ElementShadow::distribute()
250 { 245 {
251 host()->setNeedsStyleRecalc(SubtreeStyleChange); 246 host()->setNeedsStyleRecalc(SubtreeStyleChange);
252 DistributionPool pool(*host()); 247 DistributionPool pool(*host());
253 248
254 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow Root()) { 249 if (ShadowRoot* root = shadowRoot()) {
255 const Vector<RefPtr<InsertionPoint> >& insertionPoints = root->descendan tInsertionPoints(); 250 const Vector<RefPtr<InsertionPoint> >& insertionPoints = root->descendan tInsertionPoints();
256 for (size_t i = 0; i < insertionPoints.size(); ++i) { 251 for (size_t i = 0; i < insertionPoints.size(); ++i) {
257 InsertionPoint* point = insertionPoints[i].get(); 252 InsertionPoint* point = insertionPoints[i].get();
258 if (!point->isActive()) 253 if (!point->isActive())
259 continue; 254 continue;
260 pool.distributeTo(point, this); 255 pool.distributeTo(point, this);
261 if (ElementShadow* shadow = shadowWhereNodeCanBeDistributed(*point)) 256 if (ElementShadow* shadow = shadowWhereNodeCanBeDistributed(*point))
262 shadow->setNeedsDistributionRecalc(); 257 shadow->setNeedsDistributionRecalc();
263 } 258 }
264 } 259 }
265 } 260 }
266 261
267 void ElementShadow::didDistributeNode(const Node* node, InsertionPoint* insertio nPoint) 262 void ElementShadow::didDistributeNode(const Node* node, InsertionPoint* insertio nPoint)
268 { 263 {
269 NodeToDestinationInsertionPoints::AddResult result = m_nodeToInsertionPoints .add(node, DestinationInsertionPoints()); 264 NodeToDestinationInsertionPoints::AddResult result = m_nodeToInsertionPoints .add(node, DestinationInsertionPoints());
270 result.storedValue->value.append(insertionPoint); 265 result.storedValue->value.append(insertionPoint);
271 } 266 }
272 267
273 const SelectRuleFeatureSet& ElementShadow::ensureSelectFeatureSet() 268 const SelectRuleFeatureSet& ElementShadow::ensureSelectFeatureSet()
274 { 269 {
275 if (!m_needsSelectFeatureSet) 270 if (!m_needsSelectFeatureSet)
276 return m_selectFeatures; 271 return m_selectFeatures;
277 272
278 m_selectFeatures.clear(); 273 m_selectFeatures.clear();
279 for (ShadowRoot* root = oldestShadowRoot(); root; root = root->youngerShadow Root()) 274 if (ShadowRoot* root = shadowRoot())
280 collectSelectFeatureSetFrom(*root); 275 collectSelectFeatureSetFrom(*root);
281 m_needsSelectFeatureSet = false; 276 m_needsSelectFeatureSet = false;
282 return m_selectFeatures; 277 return m_selectFeatures;
283 } 278 }
284 279
285 void ElementShadow::collectSelectFeatureSetFrom(ShadowRoot& root) 280 void ElementShadow::collectSelectFeatureSetFrom(ShadowRoot& root)
286 { 281 {
287 if (!root.containsShadowRoots() && !root.containsContentElements()) 282 if (!root.containsShadowRoots() && !root.containsContentElements())
288 return; 283 return;
289 284
(...skipping 19 matching lines...) Expand all
309 } 304 }
310 setNeedsDistributionRecalc(); 305 setNeedsDistributionRecalc();
311 } 306 }
312 307
313 void ElementShadow::clearDistribution() 308 void ElementShadow::clearDistribution()
314 { 309 {
315 m_nodeToInsertionPoints.clear(); 310 m_nodeToInsertionPoints.clear();
316 } 311 }
317 312
318 } // namespace 313 } // namespace
OLDNEW
« no previous file with comments | « sky/engine/core/dom/shadow/ElementShadow.h ('k') | sky/engine/core/dom/shadow/InsertionPoint.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698