OLD | NEW |
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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 break; | 166 break; |
167 } | 167 } |
168 return false; | 168 return false; |
169 } | 169 } |
170 | 170 |
171 InsertionPoint* ElementShadow::findInsertionPointFor(const Node* key) const | 171 InsertionPoint* ElementShadow::findInsertionPointFor(const Node* key) const |
172 { | 172 { |
173 return m_nodeToInsertionPoint.get(key); | 173 return m_nodeToInsertionPoint.get(key); |
174 } | 174 } |
175 | 175 |
176 void ElementShadow::populate(Node* node, Vector<Node*>& pool) | 176 void ElementShadow::populate(Node* node, Vector<Node*, 32>& pool) |
177 { | 177 { |
178 if (!isActiveInsertionPoint(node)) { | 178 if (!isActiveInsertionPoint(node)) { |
179 pool.append(node); | 179 pool.append(node); |
180 return; | 180 return; |
181 } | 181 } |
182 | 182 |
183 InsertionPoint* insertionPoint = toInsertionPoint(node); | 183 InsertionPoint* insertionPoint = toInsertionPoint(node); |
184 if (insertionPoint->hasDistribution()) { | 184 if (insertionPoint->hasDistribution()) { |
185 for (size_t i = 0; i < insertionPoint->size(); ++i) | 185 for (size_t i = 0; i < insertionPoint->size(); ++i) |
186 pool.append(insertionPoint->at(i)); | 186 pool.append(insertionPoint->at(i)); |
187 } else { | 187 } else { |
188 for (Node* fallbackNode = insertionPoint->firstChild(); fallbackNode; fa
llbackNode = fallbackNode->nextSibling()) | 188 for (Node* fallbackNode = insertionPoint->firstChild(); fallbackNode; fa
llbackNode = fallbackNode->nextSibling()) |
189 pool.append(fallbackNode); | 189 pool.append(fallbackNode); |
190 } | 190 } |
191 } | 191 } |
192 | 192 |
193 void ElementShadow::distribute() | 193 void ElementShadow::distribute() |
194 { | 194 { |
195 Vector<Node*> pool; | 195 Vector<Node*, 32> pool; |
196 for (Node* node = host()->firstChild(); node; node = node->nextSibling()) | 196 for (Node* node = host()->firstChild(); node; node = node->nextSibling()) |
197 populate(node, pool); | 197 populate(node, pool); |
198 | 198 |
199 host()->setNeedsStyleRecalc(); | 199 host()->setNeedsStyleRecalc(); |
200 | 200 |
201 Vector<bool> distributed(pool.size()); | 201 Vector<bool> distributed; |
202 distributed.fill(false); | 202 distributed.fill(false, pool.size()); |
203 | 203 |
204 Vector<HTMLShadowElement*, 8> activeShadowInsertionPoints; | 204 Vector<HTMLShadowElement*, 32> activeShadowInsertionPoints; |
205 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow
Root()) { | 205 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow
Root()) { |
206 HTMLShadowElement* firstActiveShadowInsertionPoint = 0; | 206 HTMLShadowElement* firstActiveShadowInsertionPoint = 0; |
207 | 207 |
208 const Vector<RefPtr<InsertionPoint> >& insertionPoints = root->childInse
rtionPoints(); | 208 const Vector<RefPtr<InsertionPoint> >& insertionPoints = root->childInse
rtionPoints(); |
209 for (size_t i = 0; i < insertionPoints.size(); ++i) { | 209 for (size_t i = 0; i < insertionPoints.size(); ++i) { |
210 InsertionPoint* point = insertionPoints[i].get(); | 210 InsertionPoint* point = insertionPoints[i].get(); |
211 if (!point->isActive()) | 211 if (!point->isActive()) |
212 continue; | 212 continue; |
213 | 213 |
214 if (isHTMLShadowElement(point)) { | 214 if (isHTMLShadowElement(point)) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 246 |
247 // Detach all nodes that were not distributed and have a renderer. | 247 // Detach all nodes that were not distributed and have a renderer. |
248 for (size_t i = 0; i < pool.size(); ++i) { | 248 for (size_t i = 0; i < pool.size(); ++i) { |
249 if (distributed[i]) | 249 if (distributed[i]) |
250 continue; | 250 continue; |
251 if (pool[i]->renderer()) | 251 if (pool[i]->renderer()) |
252 pool[i]->lazyReattachIfAttached(); | 252 pool[i]->lazyReattachIfAttached(); |
253 } | 253 } |
254 } | 254 } |
255 | 255 |
256 void ElementShadow::distributeSelectionsTo(InsertionPoint* insertionPoint, const
Vector<Node*>& pool, Vector<bool>& distributed) | 256 void ElementShadow::distributeSelectionsTo(InsertionPoint* insertionPoint, const
Vector<Node*, 32>& pool, Vector<bool>& distributed) |
257 { | 257 { |
258 ContentDistribution distribution; | 258 ContentDistribution distribution; |
259 | 259 |
260 for (size_t i = 0; i < pool.size(); ++i) { | 260 for (size_t i = 0; i < pool.size(); ++i) { |
261 if (distributed[i]) | 261 if (distributed[i]) |
262 continue; | 262 continue; |
263 | 263 |
264 if (isHTMLContentElement(insertionPoint) && !toHTMLContentElement(insert
ionPoint)->canSelectNode(pool, i)) | 264 if (isHTMLContentElement(insertionPoint) && !toHTMLContentElement(insert
ionPoint)->canSelectNode(pool, i)) |
265 continue; | 265 continue; |
266 | 266 |
267 Node* child = pool[i]; | 267 Node* child = pool[i]; |
268 distribution.append(child); | 268 distribution.append(child); |
269 m_nodeToInsertionPoint.add(child, insertionPoint); | 269 m_nodeToInsertionPoint.add(child, insertionPoint); |
270 distributed[i] = true; | 270 distributed[i] = true; |
271 } | 271 } |
272 | 272 |
273 insertionPoint->setDistribution(distribution); | 273 insertionPoint->setDistribution(distribution); |
274 } | 274 } |
275 | 275 |
276 void ElementShadow::distributeNodeChildrenTo(InsertionPoint* insertionPoint, Con
tainerNode* containerNode) | 276 void ElementShadow::distributeNodeChildrenTo(InsertionPoint* insertionPoint, Con
tainerNode* containerNode) |
277 { | 277 { |
278 ContentDistribution distribution; | 278 ContentDistribution distribution; |
279 for (Node* node = containerNode->firstChild(); node; node = node->nextSiblin
g()) { | 279 for (Node* node = containerNode->firstChild(); node; node = node->nextSiblin
g()) { |
280 if (isActiveInsertionPoint(node)) { | 280 if (isActiveInsertionPoint(node)) { |
281 InsertionPoint* innerInsertionPoint = toInsertionPoint(node); | 281 InsertionPoint* innerInsertionPoint = toInsertionPoint(node); |
282 if (innerInsertionPoint->hasDistribution()) { | 282 if (innerInsertionPoint->hasDistribution()) { |
283 for (size_t i = 0; i < innerInsertionPoint->size(); ++i) { | 283 for (size_t i = 0; i < innerInsertionPoint->size(); ++i) { |
284 distribution.append(innerInsertionPoint->at(i)); | 284 Node* nodeToAdd = innerInsertionPoint->at(i); |
285 m_nodeToInsertionPoint.add(innerInsertionPoint->at(i), inser
tionPoint); | 285 distribution.append(nodeToAdd); |
| 286 m_nodeToInsertionPoint.add(nodeToAdd, insertionPoint); |
286 } | 287 } |
287 } else { | 288 } else { |
288 for (Node* child = innerInsertionPoint->firstChild(); child; chi
ld = child->nextSibling()) { | 289 for (Node* child = innerInsertionPoint->firstChild(); child; chi
ld = child->nextSibling()) { |
289 distribution.append(child); | 290 distribution.append(child); |
290 m_nodeToInsertionPoint.add(child, insertionPoint); | 291 m_nodeToInsertionPoint.add(child, insertionPoint); |
291 } | 292 } |
292 } | 293 } |
293 } else { | 294 } else { |
294 distribution.append(node); | 295 distribution.append(node); |
295 m_nodeToInsertionPoint.add(node, insertionPoint); | 296 m_nodeToInsertionPoint.add(node, insertionPoint); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 | 348 |
348 void ElementShadow::clearDistribution() | 349 void ElementShadow::clearDistribution() |
349 { | 350 { |
350 m_nodeToInsertionPoint.clear(); | 351 m_nodeToInsertionPoint.clear(); |
351 | 352 |
352 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow
Root()) | 353 for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadow
Root()) |
353 root->setInsertionPoint(0); | 354 root->setInsertionPoint(0); |
354 } | 355 } |
355 | 356 |
356 } // namespace | 357 } // namespace |
OLD | NEW |