|
Lines 57-71
static CounterMaps& counterMaps()
a/Source/WebCore/rendering/RenderCounter.cpp_sec1
|
| 57 |
return staticCounterMaps; |
57 |
return staticCounterMaps; |
| 58 |
} |
58 |
} |
| 59 |
|
59 |
|
|
|
60 |
static Element* ancestorStyleContainmentObject(const Element& element) |
| 61 |
{ |
| 62 |
for (Element* ancestor = element.parentElement(); ancestor; ancestor = ancestor->parentElement()) { |
| 63 |
if (auto* style = ancestor->existingComputedStyle()) { |
| 64 |
if (style->containsStyle()) |
| 65 |
return ancestor; |
| 66 |
} |
| 67 |
} |
| 68 |
return nullptr; |
| 69 |
} |
| 70 |
|
| 60 |
// This function processes the renderer tree in the order of the DOM tree |
71 |
// This function processes the renderer tree in the order of the DOM tree |
| 61 |
// including pseudo elements as defined in CSS 2.1. |
72 |
// including pseudo elements as defined in CSS 2.1. |
| 62 |
static RenderElement* previousInPreOrder(const RenderElement& renderer) |
73 |
static RenderElement* previousInPreOrder(const RenderElement& renderer) |
| 63 |
{ |
74 |
{ |
| 64 |
ASSERT(renderer.element()); |
75 |
ASSERT(renderer.element()); |
| 65 |
Element* previous = ElementTraversal::previousIncludingPseudo(*renderer.element()); |
76 |
Element* previous = ElementTraversal::previousIncludingPseudo(*renderer.element()); |
| 66 |
while (previous && !previous->renderer()) |
77 |
Element* styleContainAncestor = ancestorStyleContainmentObject(*renderer.element()); |
| 67 |
previous = ElementTraversal::previousIncludingPseudo(*previous); |
78 |
while (true) { |
| 68 |
return previous ? previous->renderer() : 0; |
79 |
while (previous && !previous->renderer() && !previous->hasDisplayContents()) |
|
|
80 |
previous = ElementTraversal::previousIncludingPseudo(*previous); |
| 81 |
if (!previous) |
| 82 |
return nullptr; |
| 83 |
Element* previousStyleContainAncestor = ancestorStyleContainmentObject(*previous); |
| 84 |
if (previousStyleContainAncestor == styleContainAncestor) |
| 85 |
return previous->renderer(); |
| 86 |
if (!previousStyleContainAncestor) |
| 87 |
return nullptr; |
| 88 |
previous = previousStyleContainAncestor; |
| 89 |
} |
| 69 |
} |
90 |
} |
| 70 |
|
91 |
|
| 71 |
static inline Element* parentOrPseudoHostElement(const RenderElement& renderer) |
92 |
static inline Element* parentOrPseudoHostElement(const RenderElement& renderer) |
|
Lines 78-84
static inline Element* parentOrPseudoHostElement(const RenderElement& renderer)
a/Source/WebCore/rendering/RenderCounter.cpp_sec2
|
| 78 |
static Element* previousSiblingOrParentElement(const Element& element) |
99 |
static Element* previousSiblingOrParentElement(const Element& element) |
| 79 |
{ |
100 |
{ |
| 80 |
if (auto* previous = ElementTraversal::pseudoAwarePreviousSibling(element)) { |
101 |
if (auto* previous = ElementTraversal::pseudoAwarePreviousSibling(element)) { |
| 81 |
while (previous && !previous->renderer()) |
102 |
while (previous && !previous->renderer() && !previous->hasDisplayContents()) |
| 82 |
previous = ElementTraversal::pseudoAwarePreviousSibling(*previous); |
103 |
previous = ElementTraversal::pseudoAwarePreviousSibling(*previous); |
| 83 |
|
104 |
|
| 84 |
if (previous) |
105 |
if (previous) |
|
Lines 96-101
static Element* previousSiblingOrParentElement(const Element& element)
a/Source/WebCore/rendering/RenderCounter.cpp_sec3
|
| 96 |
auto* parent = element.parentElement(); |
117 |
auto* parent = element.parentElement(); |
| 97 |
if (parent && !parent->renderer()) |
118 |
if (parent && !parent->renderer()) |
| 98 |
parent = previousSiblingOrParentElement(*parent); |
119 |
parent = previousSiblingOrParentElement(*parent); |
|
|
120 |
if (parent && parent->renderer() && parent->renderer()->style().containsStyle()) |
| 121 |
return nullptr; |
| 99 |
return parent; |
122 |
return parent; |
| 100 |
} |
123 |
} |
| 101 |
|
124 |
|
|
Lines 335-341
static CounterNode* makeCounterNode(RenderElement& renderer, const AtomString& i
a/Source/WebCore/rendering/RenderCounter.cpp_sec4
|
| 335 |
maps.add(&renderer, makeUnique<CounterMap>()).iterator->value->add(identifier, newNode.copyRef()); |
358 |
maps.add(&renderer, makeUnique<CounterMap>()).iterator->value->add(identifier, newNode.copyRef()); |
| 336 |
renderer.setHasCounterNodeMap(true); |
359 |
renderer.setHasCounterNodeMap(true); |
| 337 |
|
360 |
|
| 338 |
if (newNode->parent()) |
361 |
if (newNode->parent() || shouldApplyStyleContainment(renderer)) |
| 339 |
return newNode.ptr(); |
362 |
return newNode.ptr(); |
| 340 |
|
363 |
|
| 341 |
// Check if some nodes that were previously root nodes should become children of this node now. |
364 |
// Check if some nodes that were previously root nodes should become children of this node now. |
|
Lines 343-349
static CounterNode* makeCounterNode(RenderElement& renderer, const AtomString& i
a/Source/WebCore/rendering/RenderCounter.cpp_sec5
|
| 343 |
auto* stayWithin = parentOrPseudoHostElement(renderer); |
366 |
auto* stayWithin = parentOrPseudoHostElement(renderer); |
| 344 |
bool skipDescendants = false; |
367 |
bool skipDescendants = false; |
| 345 |
while ((currentRenderer = nextInPreOrder(*currentRenderer, stayWithin, skipDescendants))) { |
368 |
while ((currentRenderer = nextInPreOrder(*currentRenderer, stayWithin, skipDescendants))) { |
| 346 |
skipDescendants = false; |
369 |
skipDescendants = shouldApplyStyleContainment(*currentRenderer); |
| 347 |
if (!currentRenderer->hasCounterNodeMap()) |
370 |
if (!currentRenderer->hasCounterNodeMap()) |
| 348 |
continue; |
371 |
continue; |
| 349 |
auto* currentCounter = maps.find(currentRenderer)->value->get(identifier); |
372 |
auto* currentCounter = maps.find(currentRenderer)->value->get(identifier); |
|
Lines 549-556
void RenderCounter::rendererSubtreeAttached(RenderElement& renderer)
a/Source/WebCore/rendering/RenderCounter.cpp_sec6
|
| 549 |
element = renderer.generatingElement(); |
572 |
element = renderer.generatingElement(); |
| 550 |
if (element && !element->renderer()) |
573 |
if (element && !element->renderer()) |
| 551 |
return; // No need to update if the parent is not attached yet |
574 |
return; // No need to update if the parent is not attached yet |
|
|
575 |
bool crossedBoundary = false; |
| 552 |
for (RenderObject* descendant = &renderer; descendant; descendant = descendant->nextInPreOrder(&renderer)) { |
576 |
for (RenderObject* descendant = &renderer; descendant; descendant = descendant->nextInPreOrder(&renderer)) { |
| 553 |
if (is<RenderElement>(*descendant)) |
577 |
crossedBoundary |= shouldApplyStyleContainment(*descendant); |
|
|
578 |
if (crossedBoundary && is<RenderElement>(*descendant)) |
| 554 |
updateCounters(downcast<RenderElement>(*descendant)); |
579 |
updateCounters(downcast<RenderElement>(*descendant)); |
| 555 |
} |
580 |
} |
| 556 |
} |
581 |
} |