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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 } | 135 } |
136 | 136 |
137 ElementShadow::ElementShadow() | 137 ElementShadow::ElementShadow() |
138 : m_needsDistributionRecalc(false) | 138 : m_needsDistributionRecalc(false) |
139 , m_needsSelectFeatureSet(false) | 139 , m_needsSelectFeatureSet(false) |
140 { | 140 { |
141 } | 141 } |
142 | 142 |
143 ElementShadow::~ElementShadow() | 143 ElementShadow::~ElementShadow() |
144 { | 144 { |
145 #if !ENABLE(OILPAN) | |
146 removeDetachedShadowRoots(); | |
147 #endif | |
148 } | 145 } |
149 | 146 |
150 ShadowRoot& ElementShadow::addShadowRoot(Element& shadowHost, ShadowRootType typ
e) | 147 ShadowRoot& ElementShadow::addShadowRoot(Element& shadowHost, ShadowRootType typ
e) |
151 { | 148 { |
152 EventDispatchForbiddenScope assertNoEventDispatch; | 149 EventDispatchForbiddenScope assertNoEventDispatch; |
153 ScriptForbiddenScope forbidScript; | 150 ScriptForbiddenScope forbidScript; |
154 | 151 |
155 if (type == ShadowRootType::V0) { | 152 if (type == ShadowRootType::V0) { |
156 if (m_shadowRoots.isEmpty()) { | 153 if (m_shadowRoots.isEmpty()) { |
157 shadowHost.willAddFirstAuthorShadowRoot(); | 154 shadowHost.willAddFirstAuthorShadowRoot(); |
(...skipping 18 matching lines...) Expand all Loading... |
176 | 173 |
177 shadowRoot->insertedInto(&shadowHost); | 174 shadowRoot->insertedInto(&shadowHost); |
178 shadowHost.setChildNeedsStyleRecalc(); | 175 shadowHost.setChildNeedsStyleRecalc(); |
179 shadowHost.setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTraci
ng::create(StyleChangeReason::Shadow)); | 176 shadowHost.setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTraci
ng::create(StyleChangeReason::Shadow)); |
180 | 177 |
181 InspectorInstrumentation::didPushShadowRoot(&shadowHost, shadowRoot); | 178 InspectorInstrumentation::didPushShadowRoot(&shadowHost, shadowRoot); |
182 | 179 |
183 return *shadowRoot; | 180 return *shadowRoot; |
184 } | 181 } |
185 | 182 |
186 #if !ENABLE(OILPAN) | |
187 void ElementShadow::removeDetachedShadowRoots() | |
188 { | |
189 // Dont protect this ref count. | |
190 Element* shadowHost = host(); | |
191 DCHECK(shadowHost); | |
192 | |
193 while (ShadowRoot* oldRoot = m_shadowRoots.head()) { | |
194 InspectorInstrumentation::willPopShadowRoot(shadowHost, oldRoot); | |
195 shadowHost->document().removeFocusedElementOfSubtree(oldRoot); | |
196 m_shadowRoots.removeHead(); | |
197 oldRoot->setParentOrShadowHostNode(0); | |
198 oldRoot->setParentTreeScope(shadowHost->document()); | |
199 oldRoot->setPrev(0); | |
200 oldRoot->setNext(0); | |
201 } | |
202 } | |
203 #endif | |
204 | |
205 void ElementShadow::attach(const Node::AttachContext& context) | 183 void ElementShadow::attach(const Node::AttachContext& context) |
206 { | 184 { |
207 Node::AttachContext childrenContext(context); | 185 Node::AttachContext childrenContext(context); |
208 childrenContext.resolvedStyle = 0; | 186 childrenContext.resolvedStyle = 0; |
209 | 187 |
210 for (ShadowRoot* root = &youngestShadowRoot(); root; root = root->olderShado
wRoot()) { | 188 for (ShadowRoot* root = &youngestShadowRoot(); root; root = root->olderShado
wRoot()) { |
211 if (root->needsAttach()) | 189 if (root->needsAttach()) |
212 root->attach(childrenContext); | 190 root->attach(childrenContext); |
213 } | 191 } |
214 } | 192 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 return true; | 234 return true; |
257 } | 235 } |
258 | 236 |
259 const InsertionPoint* ElementShadow::finalDestinationInsertionPointFor(const Nod
e* key) const | 237 const InsertionPoint* ElementShadow::finalDestinationInsertionPointFor(const Nod
e* key) const |
260 { | 238 { |
261 DCHECK(key); | 239 DCHECK(key); |
262 #if DCHECK_IS_ON() | 240 #if DCHECK_IS_ON() |
263 DCHECK(!key->needsDistributionRecalc()); | 241 DCHECK(!key->needsDistributionRecalc()); |
264 #endif | 242 #endif |
265 NodeToDestinationInsertionPoints::const_iterator it = m_nodeToInsertionPoint
s.find(key); | 243 NodeToDestinationInsertionPoints::const_iterator it = m_nodeToInsertionPoint
s.find(key); |
266 #if ENABLE(OILPAN) | 244 return it == m_nodeToInsertionPoints.end() ? nullptr : it->value->last(); |
267 return it == m_nodeToInsertionPoints.end() ? nullptr : it->value->last().get
(); | |
268 #else | |
269 return it == m_nodeToInsertionPoints.end() ? nullptr : it->value.last().get(
); | |
270 #endif | |
271 } | 245 } |
272 | 246 |
273 const DestinationInsertionPoints* ElementShadow::destinationInsertionPointsFor(c
onst Node* key) const | 247 const DestinationInsertionPoints* ElementShadow::destinationInsertionPointsFor(c
onst Node* key) const |
274 { | 248 { |
275 DCHECK(key); | 249 DCHECK(key); |
276 #if DCHECK_IS_ON() | 250 #if DCHECK_IS_ON() |
277 DCHECK(!key->needsDistributionRecalc()); | 251 DCHECK(!key->needsDistributionRecalc()); |
278 #endif | 252 #endif |
279 NodeToDestinationInsertionPoints::const_iterator it = m_nodeToInsertionPoint
s.find(key); | 253 NodeToDestinationInsertionPoints::const_iterator it = m_nodeToInsertionPoint
s.find(key); |
280 #if ENABLE(OILPAN) | 254 return it == m_nodeToInsertionPoints.end() ? nullptr : it->value; |
281 return it == m_nodeToInsertionPoints.end() ? nullptr : it->value.get(); | |
282 #else | |
283 return it == m_nodeToInsertionPoints.end() ? nullptr : &it->value; | |
284 #endif | |
285 } | 255 } |
286 | 256 |
287 void ElementShadow::distribute() | 257 void ElementShadow::distribute() |
288 { | 258 { |
289 if (isV1()) | 259 if (isV1()) |
290 youngestShadowRoot().distributeV1(); | 260 youngestShadowRoot().distributeV1(); |
291 else | 261 else |
292 distributeV0(); | 262 distributeV0(); |
293 } | 263 } |
294 | 264 |
295 void ElementShadow::distributeV0() | 265 void ElementShadow::distributeV0() |
296 { | 266 { |
297 HeapVector<Member<HTMLShadowElement>, 32> shadowInsertionPoints; | 267 HeapVector<Member<HTMLShadowElement>, 32> shadowInsertionPoints; |
298 DistributionPool pool(*host()); | 268 DistributionPool pool(*host()); |
299 | 269 |
300 for (ShadowRoot* root = &youngestShadowRoot(); root; root = root->olderShado
wRoot()) { | 270 for (ShadowRoot* root = &youngestShadowRoot(); root; root = root->olderShado
wRoot()) { |
301 HTMLShadowElement* shadowInsertionPoint = 0; | 271 HTMLShadowElement* shadowInsertionPoint = 0; |
302 const HeapVector<Member<InsertionPoint>>& insertionPoints = root->descen
dantInsertionPoints(); | 272 const HeapVector<Member<InsertionPoint>>& insertionPoints = root->descen
dantInsertionPoints(); |
303 for (size_t i = 0; i < insertionPoints.size(); ++i) { | 273 for (size_t i = 0; i < insertionPoints.size(); ++i) { |
304 InsertionPoint* point = insertionPoints[i].get(); | 274 InsertionPoint* point = insertionPoints[i]; |
305 if (!point->isActive()) | 275 if (!point->isActive()) |
306 continue; | 276 continue; |
307 if (isHTMLShadowElement(*point)) { | 277 if (isHTMLShadowElement(*point)) { |
308 DCHECK(!shadowInsertionPoint); | 278 DCHECK(!shadowInsertionPoint); |
309 shadowInsertionPoint = toHTMLShadowElement(point); | 279 shadowInsertionPoint = toHTMLShadowElement(point); |
310 shadowInsertionPoints.append(shadowInsertionPoint); | 280 shadowInsertionPoints.append(shadowInsertionPoint); |
311 } else { | 281 } else { |
312 pool.distributeTo(point, this); | 282 pool.distributeTo(point, this); |
313 if (ElementShadow* shadow = shadowWhereNodeCanBeDistributed(*poi
nt)) | 283 if (ElementShadow* shadow = shadowWhereNodeCanBeDistributed(*poi
nt)) |
314 shadow->setNeedsDistributionRecalc(); | 284 shadow->setNeedsDistributionRecalc(); |
(...skipping 15 matching lines...) Expand all Loading... |
330 root->olderShadowRoot()->setShadowInsertionPointOfYoungerShadowRoot(
shadowInsertionPoint); | 300 root->olderShadowRoot()->setShadowInsertionPointOfYoungerShadowRoot(
shadowInsertionPoint); |
331 } | 301 } |
332 if (ElementShadow* shadow = shadowWhereNodeCanBeDistributed(*shadowInser
tionPoint)) | 302 if (ElementShadow* shadow = shadowWhereNodeCanBeDistributed(*shadowInser
tionPoint)) |
333 shadow->setNeedsDistributionRecalc(); | 303 shadow->setNeedsDistributionRecalc(); |
334 } | 304 } |
335 InspectorInstrumentation::didPerformElementShadowDistribution(host()); | 305 InspectorInstrumentation::didPerformElementShadowDistribution(host()); |
336 } | 306 } |
337 | 307 |
338 void ElementShadow::didDistributeNode(const Node* node, InsertionPoint* insertio
nPoint) | 308 void ElementShadow::didDistributeNode(const Node* node, InsertionPoint* insertio
nPoint) |
339 { | 309 { |
340 #if ENABLE(OILPAN) | |
341 NodeToDestinationInsertionPoints::AddResult result = m_nodeToInsertionPoints
.add(node, nullptr); | 310 NodeToDestinationInsertionPoints::AddResult result = m_nodeToInsertionPoints
.add(node, nullptr); |
342 if (result.isNewEntry) | 311 if (result.isNewEntry) |
343 result.storedValue->value = new DestinationInsertionPoints(); | 312 result.storedValue->value = new DestinationInsertionPoints; |
344 result.storedValue->value->append(insertionPoint); | 313 result.storedValue->value->append(insertionPoint); |
345 #else | |
346 NodeToDestinationInsertionPoints::AddResult result = m_nodeToInsertionPoints
.add(node, DestinationInsertionPoints()); | |
347 result.storedValue->value.append(insertionPoint); | |
348 #endif | |
349 } | 314 } |
350 | 315 |
351 const SelectRuleFeatureSet& ElementShadow::ensureSelectFeatureSet() | 316 const SelectRuleFeatureSet& ElementShadow::ensureSelectFeatureSet() |
352 { | 317 { |
353 if (!m_needsSelectFeatureSet) | 318 if (!m_needsSelectFeatureSet) |
354 return m_selectFeatures; | 319 return m_selectFeatures; |
355 | 320 |
356 m_selectFeatures.clear(); | 321 m_selectFeatures.clear(); |
357 for (ShadowRoot* root = oldestShadowRoot(); root; root = root->youngerShadow
Root()) | 322 for (ShadowRoot* root = oldestShadowRoot(); root; root = root->youngerShadow
Root()) |
358 collectSelectFeatureSetFrom(*root); | 323 collectSelectFeatureSetFrom(*root); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 { | 362 { |
398 visitor->trace(m_nodeToInsertionPoints); | 363 visitor->trace(m_nodeToInsertionPoints); |
399 visitor->trace(m_selectFeatures); | 364 visitor->trace(m_selectFeatures); |
400 // Shadow roots are linked with previous and next pointers which are traced. | 365 // Shadow roots are linked with previous and next pointers which are traced. |
401 // It is therefore enough to trace one of the shadow roots here and the | 366 // It is therefore enough to trace one of the shadow roots here and the |
402 // rest will be traced from there. | 367 // rest will be traced from there. |
403 visitor->trace(m_shadowRoots.head()); | 368 visitor->trace(m_shadowRoots.head()); |
404 } | 369 } |
405 | 370 |
406 } // namespace blink | 371 } // namespace blink |
OLD | NEW |