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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 void InsertionPoint::setDistributedNodes(DistributedNodes& distributedNodes) { | 53 void InsertionPoint::setDistributedNodes(DistributedNodes& distributedNodes) { |
54 // Attempt not to reattach nodes that would be distributed to the exact same | 54 // Attempt not to reattach nodes that would be distributed to the exact same |
55 // location by comparing the old and new distributions. | 55 // location by comparing the old and new distributions. |
56 | 56 |
57 size_t i = 0; | 57 size_t i = 0; |
58 size_t j = 0; | 58 size_t j = 0; |
59 | 59 |
60 for (; i < m_distributedNodes.size() && j < distributedNodes.size(); | 60 for (; i < m_distributedNodes.size() && j < distributedNodes.size(); |
61 ++i, ++j) { | 61 ++i, ++j) { |
62 if (m_distributedNodes.size() < distributedNodes.size()) { | 62 if (m_distributedNodes.size() < distributedNodes.size()) { |
63 // If the new distribution is larger than the old one, reattach all nodes
in | 63 // If the new distribution is larger than the old one, reattach all nodes |
64 // the new distribution that were inserted. | 64 // in the new distribution that were inserted. |
65 for (; j < distributedNodes.size() && | 65 for (; j < distributedNodes.size() && |
66 m_distributedNodes.at(i) != distributedNodes.at(j); | 66 m_distributedNodes.at(i) != distributedNodes.at(j); |
67 ++j) | 67 ++j) |
68 distributedNodes.at(j)->lazyReattachIfAttached(); | 68 distributedNodes.at(j)->lazyReattachIfAttached(); |
69 if (j == distributedNodes.size()) | 69 if (j == distributedNodes.size()) |
70 break; | 70 break; |
71 } else if (m_distributedNodes.size() > distributedNodes.size()) { | 71 } else if (m_distributedNodes.size() > distributedNodes.size()) { |
72 // If the old distribution is larger than the new one, reattach all nodes
in | 72 // If the old distribution is larger than the new one, reattach all nodes |
73 // the old distribution that were removed. | 73 // in the old distribution that were removed. |
74 for (; i < m_distributedNodes.size() && | 74 for (; i < m_distributedNodes.size() && |
75 m_distributedNodes.at(i) != distributedNodes.at(j); | 75 m_distributedNodes.at(i) != distributedNodes.at(j); |
76 ++i) | 76 ++i) |
77 m_distributedNodes.at(i)->lazyReattachIfAttached(); | 77 m_distributedNodes.at(i)->lazyReattachIfAttached(); |
78 if (i == m_distributedNodes.size()) | 78 if (i == m_distributedNodes.size()) |
79 break; | 79 break; |
80 } else if (m_distributedNodes.at(i) != distributedNodes.at(j)) { | 80 } else if (m_distributedNodes.at(i) != distributedNodes.at(j)) { |
81 // If both distributions are the same length reattach both old and new. | 81 // If both distributions are the same length reattach both old and new. |
82 m_distributedNodes.at(i)->lazyReattachIfAttached(); | 82 m_distributedNodes.at(i)->lazyReattachIfAttached(); |
83 distributedNodes.at(j)->lazyReattachIfAttached(); | 83 distributedNodes.at(j)->lazyReattachIfAttached(); |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 // If we hit the end of either list above we need to reattach all remaining no
des. | 87 // If we hit the end of either list above we need to reattach all remaining |
| 88 // nodes. |
88 | 89 |
89 for (; i < m_distributedNodes.size(); ++i) | 90 for (; i < m_distributedNodes.size(); ++i) |
90 m_distributedNodes.at(i)->lazyReattachIfAttached(); | 91 m_distributedNodes.at(i)->lazyReattachIfAttached(); |
91 | 92 |
92 for (; j < distributedNodes.size(); ++j) | 93 for (; j < distributedNodes.size(); ++j) |
93 distributedNodes.at(j)->lazyReattachIfAttached(); | 94 distributedNodes.at(j)->lazyReattachIfAttached(); |
94 | 95 |
95 m_distributedNodes.swap(distributedNodes); | 96 m_distributedNodes.swap(distributedNodes); |
96 // Deallocate a Vector and a HashMap explicitly so that | 97 // Deallocate a Vector and a HashMap explicitly so that |
97 // Oilpan can recycle them without an intervening GC. | 98 // Oilpan can recycle them without an intervening GC. |
98 distributedNodes.clear(); | 99 distributedNodes.clear(); |
99 m_distributedNodes.shrinkToFit(); | 100 m_distributedNodes.shrinkToFit(); |
100 } | 101 } |
101 | 102 |
102 void InsertionPoint::attachLayoutTree(const AttachContext& context) { | 103 void InsertionPoint::attachLayoutTree(const AttachContext& context) { |
103 // We need to attach the distribution here so that they're inserted in the rig
ht order | 104 // We need to attach the distribution here so that they're inserted in the |
104 // otherwise the n^2 protection inside LayoutTreeBuilder will cause them to be | 105 // right order otherwise the n^2 protection inside LayoutTreeBuilder will |
105 // inserted in the wrong place later. This also lets distributed nodes benefit
from | 106 // cause them to be inserted in the wrong place later. This also lets |
106 // the n^2 protection. | 107 // distributed nodes benefit from the n^2 protection. |
107 for (size_t i = 0; i < m_distributedNodes.size(); ++i) { | 108 for (size_t i = 0; i < m_distributedNodes.size(); ++i) { |
108 if (m_distributedNodes.at(i)->needsAttach()) | 109 if (m_distributedNodes.at(i)->needsAttach()) |
109 m_distributedNodes.at(i)->attachLayoutTree(context); | 110 m_distributedNodes.at(i)->attachLayoutTree(context); |
110 } | 111 } |
111 | 112 |
112 HTMLElement::attachLayoutTree(context); | 113 HTMLElement::attachLayoutTree(context); |
113 } | 114 } |
114 | 115 |
115 void InsertionPoint::detachLayoutTree(const AttachContext& context) { | 116 void InsertionPoint::detachLayoutTree(const AttachContext& context) { |
116 for (size_t i = 0; i < m_distributedNodes.size(); ++i) | 117 for (size_t i = 0; i < m_distributedNodes.size(); ++i) |
(...skipping 30 matching lines...) Expand all Loading... |
147 | 148 |
148 bool InsertionPoint::isActive() const { | 149 bool InsertionPoint::isActive() const { |
149 if (!canBeActive()) | 150 if (!canBeActive()) |
150 return false; | 151 return false; |
151 ShadowRoot* shadowRoot = containingShadowRoot(); | 152 ShadowRoot* shadowRoot = containingShadowRoot(); |
152 DCHECK(shadowRoot); | 153 DCHECK(shadowRoot); |
153 if (!isHTMLShadowElement(*this) || | 154 if (!isHTMLShadowElement(*this) || |
154 shadowRoot->descendantShadowElementCount() <= 1) | 155 shadowRoot->descendantShadowElementCount() <= 1) |
155 return true; | 156 return true; |
156 | 157 |
157 // Slow path only when there are more than one shadow elements in a shadow tre
e. That should be a rare case. | 158 // Slow path only when there are more than one shadow elements in a shadow |
| 159 // tree. That should be a rare case. |
158 const HeapVector<Member<InsertionPoint>>& insertionPoints = | 160 const HeapVector<Member<InsertionPoint>>& insertionPoints = |
159 shadowRoot->descendantInsertionPoints(); | 161 shadowRoot->descendantInsertionPoints(); |
160 for (size_t i = 0; i < insertionPoints.size(); ++i) { | 162 for (size_t i = 0; i < insertionPoints.size(); ++i) { |
161 InsertionPoint* point = insertionPoints[i].get(); | 163 InsertionPoint* point = insertionPoints[i].get(); |
162 if (isHTMLShadowElement(*point)) | 164 if (isHTMLShadowElement(*point)) |
163 return point == this; | 165 return point == this; |
164 } | 166 } |
165 return true; | 167 return true; |
166 } | 168 } |
167 | 169 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 void InsertionPoint::removedFrom(ContainerNode* insertionPoint) { | 226 void InsertionPoint::removedFrom(ContainerNode* insertionPoint) { |
225 ShadowRoot* root = containingShadowRoot(); | 227 ShadowRoot* root = containingShadowRoot(); |
226 if (!root) | 228 if (!root) |
227 root = insertionPoint->containingShadowRoot(); | 229 root = insertionPoint->containingShadowRoot(); |
228 | 230 |
229 if (root) { | 231 if (root) { |
230 if (ElementShadow* rootOwner = root->owner()) | 232 if (ElementShadow* rootOwner = root->owner()) |
231 rootOwner->setNeedsDistributionRecalc(); | 233 rootOwner->setNeedsDistributionRecalc(); |
232 } | 234 } |
233 | 235 |
234 // host can be null when removedFrom() is called from ElementShadow destructor
. | 236 // host can be null when removedFrom() is called from ElementShadow |
| 237 // destructor. |
235 ElementShadow* rootOwner = root ? root->owner() : 0; | 238 ElementShadow* rootOwner = root ? root->owner() : 0; |
236 | 239 |
237 // Since this insertion point is no longer visible from the shadow subtree, it
need to clean itself up. | 240 // Since this insertion point is no longer visible from the shadow subtree, it |
| 241 // need to clean itself up. |
238 clearDistribution(); | 242 clearDistribution(); |
239 | 243 |
240 if (m_registeredWithShadowRoot && | 244 if (m_registeredWithShadowRoot && |
241 insertionPoint->treeScope().rootNode() == root) { | 245 insertionPoint->treeScope().rootNode() == root) { |
242 DCHECK(root); | 246 DCHECK(root); |
243 m_registeredWithShadowRoot = false; | 247 m_registeredWithShadowRoot = false; |
244 root->didRemoveInsertionPoint(this); | 248 root->didRemoveInsertionPoint(this); |
245 if (!root->isV1() && rootOwner) { | 249 if (!root->isV1() && rootOwner) { |
246 if (canAffectSelector()) | 250 if (canAffectSelector()) |
247 rootOwner->v0().willAffectSelector(); | 251 rootOwner->v0().willAffectSelector(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 if (!insertionPoints) | 296 if (!insertionPoints) |
293 return; | 297 return; |
294 for (size_t i = 0; i < insertionPoints->size(); ++i) | 298 for (size_t i = 0; i < insertionPoints->size(); ++i) |
295 results.append(insertionPoints->at(i).get()); | 299 results.append(insertionPoints->at(i).get()); |
296 DCHECK_NE(current, insertionPoints->last().get()); | 300 DCHECK_NE(current, insertionPoints->last().get()); |
297 current = insertionPoints->last().get(); | 301 current = insertionPoints->last().get(); |
298 } | 302 } |
299 } | 303 } |
300 | 304 |
301 } // namespace blink | 305 } // namespace blink |
OLD | NEW |