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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 { | 47 { |
48 setHasCustomStyleCallbacks(); | 48 setHasCustomStyleCallbacks(); |
49 } | 49 } |
50 | 50 |
51 InsertionPoint::~InsertionPoint() | 51 InsertionPoint::~InsertionPoint() |
52 { | 52 { |
53 } | 53 } |
54 | 54 |
55 void InsertionPoint::setDistributedNodes(DistributedNodes& distributedNodes) | 55 void InsertionPoint::setDistributedNodes(DistributedNodes& distributedNodes) |
56 { | 56 { |
57 if (shouldUseFallbackElements()) { | |
58 for (Node* child = firstChild(); child; child = child->nextSibling()) | |
59 child->lazyReattachIfAttached(); | |
60 } | |
61 | |
62 // Attempt not to reattach nodes that would be distributed to the exact same | 57 // Attempt not to reattach nodes that would be distributed to the exact same |
63 // location by comparing the old and new distributions. | 58 // location by comparing the old and new distributions. |
64 | 59 |
65 size_t i = 0; | 60 size_t i = 0; |
66 size_t j = 0; | 61 size_t j = 0; |
67 | 62 |
68 for ( ; i < m_distributedNodes.size() && j < distributedNodes.size(); ++i, +
+j) { | 63 for ( ; i < m_distributedNodes.size() && j < distributedNodes.size(); ++i, +
+j) { |
69 if (m_distributedNodes.size() < distributedNodes.size()) { | 64 if (m_distributedNodes.size() < distributedNodes.size()) { |
70 // If the new distribution is larger than the old one, reattach all
nodes in | 65 // If the new distribution is larger than the old one, reattach all
nodes in |
71 // the new distribution that were inserted. | 66 // the new distribution that were inserted. |
72 for ( ; j < distributedNodes.size() && m_distributedNodes.at(i) != d
istributedNodes.at(j); ++j) | 67 for ( ; j < distributedNodes.size() && m_distributedNodes.at(i) != d
istributedNodes.at(j); ++j) |
73 distributedNodes.at(j)->lazyReattachIfAttached(); | 68 distributedNodes.at(j)->lazyReattachIfAttached(); |
| 69 if (j == distributedNodes.size()) |
| 70 break; |
74 } else if (m_distributedNodes.size() > distributedNodes.size()) { | 71 } else if (m_distributedNodes.size() > distributedNodes.size()) { |
75 // 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 in |
76 // the old distribution that were removed. | 73 // the old distribution that were removed. |
77 for ( ; i < m_distributedNodes.size() && m_distributedNodes.at(i) !=
distributedNodes.at(j); ++i) | 74 for ( ; i < m_distributedNodes.size() && m_distributedNodes.at(i) !=
distributedNodes.at(j); ++i) |
78 m_distributedNodes.at(i)->lazyReattachIfAttached(); | 75 m_distributedNodes.at(i)->lazyReattachIfAttached(); |
| 76 if (i == m_distributedNodes.size()) |
| 77 break; |
79 } else if (m_distributedNodes.at(i) != distributedNodes.at(j)) { | 78 } else if (m_distributedNodes.at(i) != distributedNodes.at(j)) { |
80 // If both distributions are the same length reattach both old and n
ew. | 79 // If both distributions are the same length reattach both old and n
ew. |
81 m_distributedNodes.at(i)->lazyReattachIfAttached(); | 80 m_distributedNodes.at(i)->lazyReattachIfAttached(); |
82 distributedNodes.at(j)->lazyReattachIfAttached(); | 81 distributedNodes.at(j)->lazyReattachIfAttached(); |
83 } | 82 } |
84 } | 83 } |
85 | 84 |
86 // If we hit the end of either list above we need to reattach all remaining
nodes. | 85 // If we hit the end of either list above we need to reattach all remaining
nodes. |
87 | 86 |
88 for ( ; i < m_distributedNodes.size(); ++i) | 87 for ( ; i < m_distributedNodes.size(); ++i) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 } | 122 } |
124 | 123 |
125 void InsertionPoint::willRecalcStyle(StyleRecalcChange change) | 124 void InsertionPoint::willRecalcStyle(StyleRecalcChange change) |
126 { | 125 { |
127 if (change < Inherit && styleChangeType() < SubtreeStyleChange) | 126 if (change < Inherit && styleChangeType() < SubtreeStyleChange) |
128 return; | 127 return; |
129 for (size_t i = 0; i < m_distributedNodes.size(); ++i) | 128 for (size_t i = 0; i < m_distributedNodes.size(); ++i) |
130 m_distributedNodes.at(i)->setNeedsStyleRecalc(SubtreeStyleChange, StyleC
hangeReasonForTracing::create(StyleChangeReason::PropagateInheritChangeToDistrib
utedNodes)); | 129 m_distributedNodes.at(i)->setNeedsStyleRecalc(SubtreeStyleChange, StyleC
hangeReasonForTracing::create(StyleChangeReason::PropagateInheritChangeToDistrib
utedNodes)); |
131 } | 130 } |
132 | 131 |
133 bool InsertionPoint::shouldUseFallbackElements() const | |
134 { | |
135 return isActive() && !hasDistribution(); | |
136 } | |
137 | |
138 bool InsertionPoint::canBeActive() const | 132 bool InsertionPoint::canBeActive() const |
139 { | 133 { |
140 ShadowRoot* shadowRoot = containingShadowRoot(); | 134 ShadowRoot* shadowRoot = containingShadowRoot(); |
141 if (!shadowRoot) | 135 if (!shadowRoot) |
142 return false; | 136 return false; |
143 if (shadowRoot->isV1()) | 137 if (shadowRoot->isV1()) |
144 return false; | 138 return false; |
145 return !Traversal<InsertionPoint>::firstAncestor(*this); | 139 return !Traversal<InsertionPoint>::firstAncestor(*this); |
146 } | 140 } |
147 | 141 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 if (!insertionPoints) | 286 if (!insertionPoints) |
293 return; | 287 return; |
294 for (size_t i = 0; i < insertionPoints->size(); ++i) | 288 for (size_t i = 0; i < insertionPoints->size(); ++i) |
295 results.append(insertionPoints->at(i).get()); | 289 results.append(insertionPoints->at(i).get()); |
296 ASSERT(current != insertionPoints->last().get()); | 290 ASSERT(current != insertionPoints->last().get()); |
297 current = insertionPoints->last().get(); | 291 current = insertionPoints->last().get(); |
298 } | 292 } |
299 } | 293 } |
300 | 294 |
301 } // namespace blink | 295 } // namespace blink |
OLD | NEW |