summaryrefslogtreecommitdiff
path: root/Source/WebCore/rendering/RenderCounter.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/rendering/RenderCounter.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/rendering/RenderCounter.cpp')
-rw-r--r--Source/WebCore/rendering/RenderCounter.cpp249
1 files changed, 118 insertions, 131 deletions
diff --git a/Source/WebCore/rendering/RenderCounter.cpp b/Source/WebCore/rendering/RenderCounter.cpp
index 5faaf19f4..5f1467349 100644
--- a/Source/WebCore/rendering/RenderCounter.cpp
+++ b/Source/WebCore/rendering/RenderCounter.cpp
@@ -35,7 +35,7 @@
#include "RenderView.h"
#include <wtf/StdLibExtras.h>
-#ifndef NDEBUG
+#if ENABLE(TREE_DEBUGGING)
#include <stdio.h>
#endif
@@ -44,80 +44,79 @@ namespace WebCore {
using namespace HTMLNames;
typedef HashMap<AtomicString, RefPtr<CounterNode>> CounterMap;
-typedef HashMap<const RenderObject*, OwnPtr<CounterMap>> CounterMaps;
+typedef HashMap<const RenderElement*, std::unique_ptr<CounterMap>> CounterMaps;
-static CounterNode* makeCounterNode(RenderObject*, const AtomicString& identifier, bool alwaysCreateCounter);
+static CounterNode* makeCounterNode(RenderElement&, const AtomicString& identifier, bool alwaysCreateCounter);
static CounterMaps& counterMaps()
{
- DEFINE_STATIC_LOCAL(CounterMaps, staticCounterMaps, ());
+ static NeverDestroyed<CounterMaps> staticCounterMaps;
return staticCounterMaps;
}
// This function processes the renderer tree in the order of the DOM tree
// including pseudo elements as defined in CSS 2.1.
-static RenderObject* previousInPreOrder(const RenderObject* object)
+static RenderElement* previousInPreOrder(const RenderElement& renderer)
{
- Element* self = toElement(object->node());
- Element* previous = ElementTraversal::previousIncludingPseudo(self);
+ ASSERT(renderer.element());
+ Element* previous = ElementTraversal::previousIncludingPseudo(*renderer.element());
while (previous && !previous->renderer())
- previous = ElementTraversal::previousIncludingPseudo(previous);
+ previous = ElementTraversal::previousIncludingPseudo(*previous);
return previous ? previous->renderer() : 0;
}
-static inline Element* parentOrPseudoHostElement(const RenderObject* object)
+static inline Element* parentOrPseudoHostElement(const RenderElement& renderer)
{
- if (object->node()->isPseudoElement())
- return toPseudoElement(object->node())->hostElement();
- return toElement(object->node())->parentElement();
+ if (renderer.isPseudoElement())
+ return renderer.generatingElement();
+ return renderer.element() ? renderer.element()->parentElement() : nullptr;
}
// This function processes the renderer tree in the order of the DOM tree
// including pseudo elements as defined in CSS 2.1.
-static RenderObject* previousSiblingOrParent(const RenderObject* object)
+static RenderElement* previousSiblingOrParent(const RenderElement& renderer)
{
- Element* self = toElement(object->node());
- Element* previous = ElementTraversal::pseudoAwarePreviousSibling(self);
+ ASSERT(renderer.element());
+ Element* previous = ElementTraversal::pseudoAwarePreviousSibling(*renderer.element());
while (previous && !previous->renderer())
- previous = ElementTraversal::pseudoAwarePreviousSibling(previous);
+ previous = ElementTraversal::pseudoAwarePreviousSibling(*previous);
if (previous)
return previous->renderer();
- previous = parentOrPseudoHostElement(object);
- return previous ? previous->renderer() : 0;
+ previous = parentOrPseudoHostElement(renderer);
+ return previous ? previous->renderer() : nullptr;
}
-static inline bool areRenderersElementsSiblings(RenderObject* first, RenderObject* second)
+static inline bool areRenderersElementsSiblings(const RenderElement& first, const RenderElement& second)
{
return parentOrPseudoHostElement(first) == parentOrPseudoHostElement(second);
}
// This function processes the renderer tree in the order of the DOM tree
// including pseudo elements as defined in CSS 2.1.
-static RenderElement* nextInPreOrder(const RenderElement* element, const Element* stayWithin, bool skipDescendants = false)
+static RenderElement* nextInPreOrder(const RenderElement& renderer, const Element* stayWithin, bool skipDescendants = false)
{
- Element* self = element->element();
+ ASSERT(renderer.element());
+ Element& self = *renderer.element();
Element* next = skipDescendants ? ElementTraversal::nextIncludingPseudoSkippingChildren(self, stayWithin) : ElementTraversal::nextIncludingPseudo(self, stayWithin);
while (next && !next->renderer())
- next = skipDescendants ? ElementTraversal::nextIncludingPseudoSkippingChildren(next, stayWithin) : ElementTraversal::nextIncludingPseudo(next, stayWithin);
- return next ? next->renderer() : 0;
+ next = skipDescendants ? ElementTraversal::nextIncludingPseudoSkippingChildren(*next, stayWithin) : ElementTraversal::nextIncludingPseudo(*next, stayWithin);
+ return next ? next->renderer() : nullptr;
}
-static bool planCounter(RenderElement* object, const AtomicString& identifier, bool& isReset, int& value)
+static bool planCounter(RenderElement& renderer, const AtomicString& identifier, bool& isReset, int& value)
{
- ASSERT(object);
-
// We must have a generating node or else we cannot have a counter.
- Element* generatingElement = object->generatingElement();
+ Element* generatingElement = renderer.generatingElement();
if (!generatingElement)
return false;
- const RenderStyle& style = object->style();
+ const RenderStyle& style = renderer.style();
switch (style.styleType()) {
case NOPSEUDO:
// Sometimes elements have more then one renderer. Only the first one gets the counter
// LayoutTests/http/tests/css/counter-crash.html
- if (generatingElement->renderer() != object)
+ if (generatingElement->renderer() != &renderer)
return false;
break;
case BEFORE:
@@ -135,9 +134,9 @@ static bool planCounter(RenderElement* object, const AtomicString& identifier, b
}
if (identifier == "list-item") {
- if (object->isListItem()) {
- if (toRenderListItem(object)->hasExplicitValue()) {
- value = toRenderListItem(object)->explicitValue();
+ if (is<RenderListItem>(renderer)) {
+ if (downcast<RenderListItem>(renderer).hasExplicitValue()) {
+ value = downcast<RenderListItem>(renderer).explicitValue();
isReset = true;
return true;
}
@@ -145,13 +144,13 @@ static bool planCounter(RenderElement* object, const AtomicString& identifier, b
isReset = false;
return true;
}
- if (Element* e = object->element()) {
- if (e->hasTagName(olTag)) {
- value = toHTMLOListElement(e)->start();
+ if (Element* element = renderer.element()) {
+ if (is<HTMLOListElement>(*element)) {
+ value = downcast<HTMLOListElement>(*element).start();
isReset = true;
return true;
}
- if (e->hasTagName(ulTag) || e->hasTagName(menuTag) || e->hasTagName(dirTag)) {
+ if (element->hasTagName(ulTag) || element->hasTagName(menuTag) || element->hasTagName(dirTag)) {
value = 0;
isReset = true;
return true;
@@ -178,20 +177,20 @@ static bool planCounter(RenderElement* object, const AtomicString& identifier, b
// reset node.
// - Non-reset CounterNodes cannot have descendants.
-static bool findPlaceForCounter(RenderObject* counterOwner, const AtomicString& identifier, bool isReset, RefPtr<CounterNode>& parent, RefPtr<CounterNode>& previousSibling)
+static bool findPlaceForCounter(RenderElement& counterOwner, const AtomicString& identifier, bool isReset, RefPtr<CounterNode>& parent, RefPtr<CounterNode>& previousSibling)
{
// We cannot stop searching for counters with the same identifier before we also
// check this renderer, because it may affect the positioning in the tree of our counter.
- RenderObject* searchEndRenderer = previousSiblingOrParent(counterOwner);
+ RenderElement* searchEndRenderer = previousSiblingOrParent(counterOwner);
// We check renderers in preOrder from the renderer that our counter is attached to
// towards the begining of the document for counters with the same identifier as the one
// we are trying to find a place for. This is the next renderer to be checked.
- RenderObject* currentRenderer = previousInPreOrder(counterOwner);
- previousSibling = 0;
- RefPtr<CounterNode> previousSiblingProtector = 0;
+ RenderElement* currentRenderer = previousInPreOrder(counterOwner);
+ previousSibling = nullptr;
+ RefPtr<CounterNode> previousSiblingProtector;
while (currentRenderer) {
- CounterNode* currentCounter = makeCounterNode(currentRenderer, identifier, false);
+ CounterNode* currentCounter = makeCounterNode(*currentRenderer, identifier, false);
if (searchEndRenderer == currentRenderer) {
// We may be at the end of our search.
if (currentCounter) {
@@ -199,12 +198,12 @@ static bool findPlaceForCounter(RenderObject* counterOwner, const AtomicString&
if (previousSiblingProtector) { // But we already found another counter that we come after.
if (currentCounter->actsAsReset()) {
// We found a reset counter that is on a renderer that is a sibling of ours or a parent.
- if (isReset && areRenderersElementsSiblings(currentRenderer, counterOwner)) {
+ if (isReset && areRenderersElementsSiblings(*currentRenderer, counterOwner)) {
// We are also a reset counter and the previous reset was on a sibling renderer
// hence we are the next sibling of that counter if that reset is not a root or
// we are a root node if that reset is a root.
parent = currentCounter->parent();
- previousSibling = parent ? currentCounter : 0;
+ previousSibling = parent ? currentCounter : nullptr;
return parent;
}
// We are not a reset node or the previous reset must be on an ancestor of our owner renderer
@@ -214,13 +213,13 @@ static bool findPlaceForCounter(RenderObject* counterOwner, const AtomicString&
// In these cases the identified previousSibling will be invalid as its parent is different from
// our identified parent.
if (previousSiblingProtector->parent() != currentCounter)
- previousSiblingProtector = 0;
+ previousSiblingProtector = nullptr;
previousSibling = previousSiblingProtector.get();
return true;
}
// CurrentCounter, the counter at the EndSearchRenderer, is not reset.
- if (!isReset || !areRenderersElementsSiblings(currentRenderer, counterOwner)) {
+ if (!isReset || !areRenderersElementsSiblings(*currentRenderer, counterOwner)) {
// If the node we are placing is not reset or we have found a counter that is attached
// to an ancestor of the placed counter's owner renderer we know we are a sibling of that node.
if (currentCounter->parent() != previousSiblingProtector->parent())
@@ -236,7 +235,7 @@ static bool findPlaceForCounter(RenderObject* counterOwner, const AtomicString&
// previousSibling, and when we are a sibling of the end counter we must set previousSibling
// to currentCounter.
if (currentCounter->actsAsReset()) {
- if (isReset && areRenderersElementsSiblings(currentRenderer, counterOwner)) {
+ if (isReset && areRenderersElementsSiblings(*currentRenderer, counterOwner)) {
parent = currentCounter->parent();
previousSibling = currentCounter;
return parent;
@@ -245,7 +244,7 @@ static bool findPlaceForCounter(RenderObject* counterOwner, const AtomicString&
previousSibling = previousSiblingProtector.get();
return true;
}
- if (!isReset || !areRenderersElementsSiblings(currentRenderer, counterOwner)) {
+ if (!isReset || !areRenderersElementsSiblings(*currentRenderer, counterOwner)) {
parent = currentCounter->parent();
previousSibling = currentCounter;
return true;
@@ -257,7 +256,7 @@ static bool findPlaceForCounter(RenderObject* counterOwner, const AtomicString&
// good counter, or we are a reset node and the counter on the previous sibling
// of our owner renderer was not a reset counter.
// Set a new goal for the end of the search.
- searchEndRenderer = previousSiblingOrParent(currentRenderer);
+ searchEndRenderer = previousSiblingOrParent(*currentRenderer);
} else {
// We are searching descendants of a previous sibling of the renderer that the
// counter being placed is attached to.
@@ -270,12 +269,12 @@ static bool findPlaceForCounter(RenderObject* counterOwner, const AtomicString&
previousSiblingProtector = currentCounter;
// We are no longer interested in previous siblings of the currentRenderer or their children
// as counters they may have attached cannot be the previous sibling of the counter we are placing.
- currentRenderer = parentOrPseudoHostElement(currentRenderer)->renderer();
+ currentRenderer = parentOrPseudoHostElement(*currentRenderer)->renderer();
continue;
}
} else
previousSiblingProtector = currentCounter;
- currentRenderer = previousSiblingOrParent(currentRenderer);
+ currentRenderer = previousSiblingOrParent(*currentRenderer);
continue;
}
}
@@ -284,26 +283,17 @@ static bool findPlaceForCounter(RenderObject* counterOwner, const AtomicString&
// performance improvement would create more code duplication than is worthwhile in my oppinion and may further
// impede the readability of this already complex algorithm.
if (previousSiblingProtector)
- currentRenderer = previousSiblingOrParent(currentRenderer);
+ currentRenderer = previousSiblingOrParent(*currentRenderer);
else
- currentRenderer = previousInPreOrder(currentRenderer);
+ currentRenderer = previousInPreOrder(*currentRenderer);
}
return false;
}
-static CounterNode* makeCounterNode(RenderObject* object, const AtomicString& identifier, bool alwaysCreateCounter)
+static CounterNode* makeCounterNode(RenderElement& renderer, const AtomicString& identifier, bool alwaysCreateCounter)
{
- ASSERT(object);
-
- // Real text nodes don't have their own style so they can't have counters.
- // We can't even look at their styles or we'll see extra resets and increments!
- if (object->isText())
- return nullptr;
-
- RenderElement* element = toRenderElement(object);
-
- if (element->hasCounterNodeMap()) {
- if (CounterMap* nodeMap = counterMaps().get(element)) {
+ if (renderer.hasCounterNodeMap()) {
+ if (CounterMap* nodeMap = counterMaps().get(&renderer)) {
if (CounterNode* node = nodeMap->get(identifier))
return node;
}
@@ -311,21 +301,21 @@ static CounterNode* makeCounterNode(RenderObject* object, const AtomicString& id
bool isReset = false;
int value = 0;
- if (!planCounter(element, identifier, isReset, value) && !alwaysCreateCounter)
+ if (!planCounter(renderer, identifier, isReset, value) && !alwaysCreateCounter)
return nullptr;
- RefPtr<CounterNode> newParent = 0;
- RefPtr<CounterNode> newPreviousSibling = 0;
- RefPtr<CounterNode> newNode = CounterNode::create(element, isReset, value);
- if (findPlaceForCounter(element, identifier, isReset, newParent, newPreviousSibling))
- newParent->insertAfter(newNode.get(), newPreviousSibling.get(), identifier);
+ RefPtr<CounterNode> newParent;
+ RefPtr<CounterNode> newPreviousSibling;
+ RefPtr<CounterNode> newNode = CounterNode::create(renderer, isReset, value);
+ if (findPlaceForCounter(renderer, identifier, isReset, newParent, newPreviousSibling))
+ newParent->insertAfter(*newNode, newPreviousSibling.get(), identifier);
CounterMap* nodeMap;
- if (element->hasCounterNodeMap())
- nodeMap = counterMaps().get(element);
+ if (renderer.hasCounterNodeMap())
+ nodeMap = counterMaps().get(&renderer);
else {
nodeMap = new CounterMap;
- counterMaps().set(element, adoptPtr(nodeMap));
- element->setHasCounterNodeMap(true);
+ counterMaps().set(&renderer, std::unique_ptr<CounterMap>(nodeMap));
+ renderer.setHasCounterNodeMap(true);
}
nodeMap->set(identifier, newNode);
if (newNode->parent())
@@ -333,9 +323,9 @@ static CounterNode* makeCounterNode(RenderObject* object, const AtomicString& id
// Checking if some nodes that were previously counter tree root nodes
// should become children of this node now.
CounterMaps& maps = counterMaps();
- Element* stayWithin = parentOrPseudoHostElement(element);
+ Element* stayWithin = parentOrPseudoHostElement(renderer);
bool skipDescendants;
- for (RenderElement* currentRenderer = nextInPreOrder(element, stayWithin); currentRenderer; currentRenderer = nextInPreOrder(currentRenderer, stayWithin, skipDescendants)) {
+ for (RenderElement* currentRenderer = nextInPreOrder(renderer, stayWithin); currentRenderer; currentRenderer = nextInPreOrder(*currentRenderer, stayWithin, skipDescendants)) {
skipDescendants = false;
if (!currentRenderer->hasCounterNodeMap())
continue;
@@ -345,9 +335,9 @@ static CounterNode* makeCounterNode(RenderObject* object, const AtomicString& id
skipDescendants = true;
if (currentCounter->parent())
continue;
- if (stayWithin == parentOrPseudoHostElement(currentRenderer) && currentCounter->hasResetType())
+ if (stayWithin == parentOrPseudoHostElement(*currentRenderer) && currentCounter->hasResetType())
break;
- newNode->insertAfter(currentCounter, newNode->lastChild(), identifier);
+ newNode->insertAfter(*currentCounter, newNode->lastChild(), identifier);
}
return newNode.get();
}
@@ -355,23 +345,24 @@ static CounterNode* makeCounterNode(RenderObject* object, const AtomicString& id
RenderCounter::RenderCounter(Document& document, const CounterContent& counter)
: RenderText(document, emptyString())
, m_counter(counter)
- , m_counterNode(nullptr)
- , m_nextForSameCounter(0)
{
view().addRenderCounter();
}
RenderCounter::~RenderCounter()
{
- if (m_counterNode) {
- m_counterNode->removeRenderer(this);
- ASSERT(!m_counterNode);
- }
+ // Do not add any code here. Add it to willBeDestroyed() instead.
}
void RenderCounter::willBeDestroyed()
{
view().removeRenderCounter();
+
+ if (m_counterNode) {
+ m_counterNode->removeRenderer(*this);
+ ASSERT(!m_counterNode);
+ }
+
RenderText::willBeDestroyed();
}
@@ -399,7 +390,7 @@ String RenderCounter::originalText() const
break;
beforeAfterContainer = beforeAfterContainer->parent();
}
- makeCounterNode(beforeAfterContainer, m_counter.identifier(), true)->addRenderer(const_cast<RenderCounter*>(this));
+ makeCounterNode(*beforeAfterContainer, m_counter.identifier(), true)->addRenderer(const_cast<RenderCounter&>(*this));
ASSERT(m_counterNode);
}
CounterNode* child = m_counterNode;
@@ -436,37 +427,28 @@ void RenderCounter::computePreferredLogicalWidths(float lead)
SetLayoutNeededForbiddenScope layoutForbiddenScope(this, false);
#endif
- setTextInternal(originalText());
+ setRenderedText(originalText());
RenderText::computePreferredLogicalWidths(lead);
}
-void RenderCounter::invalidate()
-{
- m_counterNode->removeRenderer(this);
- ASSERT(!m_counterNode);
- if (documentBeingDestroyed())
- return;
- setNeedsLayoutAndPrefWidthsRecalc();
-}
-
static void destroyCounterNodeWithoutMapRemoval(const AtomicString& identifier, CounterNode* node)
{
CounterNode* previous;
for (RefPtr<CounterNode> child = node->lastDescendant(); child && child != node; child = previous) {
previous = child->previousInPreOrder();
- child->parent()->removeChild(child.get());
- ASSERT(counterMaps().get(child->owner())->get(identifier) == child);
- counterMaps().get(child->owner())->remove(identifier);
+ child->parent()->removeChild(*child);
+ ASSERT(counterMaps().get(&child->owner())->get(identifier) == child);
+ counterMaps().get(&child->owner())->remove(identifier);
}
if (CounterNode* parent = node->parent())
- parent->removeChild(node);
+ parent->removeChild(*node);
}
-void RenderCounter::destroyCounterNodes(RenderObject* owner)
+void RenderCounter::destroyCounterNodes(RenderElement& owner)
{
CounterMaps& maps = counterMaps();
- CounterMaps::iterator mapsIterator = maps.find(owner);
+ CounterMaps::iterator mapsIterator = maps.find(&owner);
if (mapsIterator == maps.end())
return;
CounterMap* map = mapsIterator->value.get();
@@ -475,12 +457,12 @@ void RenderCounter::destroyCounterNodes(RenderObject* owner)
destroyCounterNodeWithoutMapRemoval(it->key, it->value.get());
}
maps.remove(mapsIterator);
- owner->setHasCounterNodeMap(false);
+ owner.setHasCounterNodeMap(false);
}
-void RenderCounter::destroyCounterNode(RenderObject* owner, const AtomicString& identifier)
+void RenderCounter::destroyCounterNode(RenderElement& owner, const AtomicString& identifier)
{
- CounterMap* map = counterMaps().get(owner);
+ CounterMap* map = counterMaps().get(&owner);
if (!map)
return;
CounterMap::iterator mapIterator = map->find(identifier);
@@ -501,7 +483,7 @@ void RenderCounter::destroyCounterNode(RenderObject* owner, const AtomicString&
// map associated with a renderer, so there is no risk in leaking the map.
}
-void RenderCounter::rendererRemovedFromTree(RenderObject& renderer)
+void RenderCounter::rendererRemovedFromTree(RenderElement& renderer)
{
if (!renderer.view().hasRenderCounters())
return;
@@ -509,25 +491,26 @@ void RenderCounter::rendererRemovedFromTree(RenderObject& renderer)
if (!currentRenderer)
currentRenderer = &renderer;
while (true) {
- destroyCounterNodes(currentRenderer);
+ if (is<RenderElement>(*currentRenderer))
+ destroyCounterNodes(downcast<RenderElement>(*currentRenderer));
if (currentRenderer == &renderer)
break;
currentRenderer = currentRenderer->previousInPreOrder();
}
}
-static void updateCounters(RenderObject* renderer)
+static void updateCounters(RenderElement& renderer)
{
- const CounterDirectiveMap* directiveMap = renderer->style().counterDirectives();
+ const CounterDirectiveMap* directiveMap = renderer.style().counterDirectives();
if (!directiveMap)
return;
CounterDirectiveMap::const_iterator end = directiveMap->end();
- if (!renderer->hasCounterNodeMap()) {
+ if (!renderer.hasCounterNodeMap()) {
for (CounterDirectiveMap::const_iterator it = directiveMap->begin(); it != end; ++it)
makeCounterNode(renderer, it->key, false);
return;
}
- CounterMap* counterMap = counterMaps().get(renderer);
+ CounterMap* counterMap = counterMaps().get(&renderer);
ASSERT(counterMap);
for (CounterDirectiveMap::const_iterator it = directiveMap->begin(); it != end; ++it) {
RefPtr<CounterNode> node = counterMap->get(it->key);
@@ -535,8 +518,8 @@ static void updateCounters(RenderObject* renderer)
makeCounterNode(renderer, it->key, false);
continue;
}
- RefPtr<CounterNode> newParent = 0;
- RefPtr<CounterNode> newPreviousSibling = 0;
+ RefPtr<CounterNode> newParent;
+ RefPtr<CounterNode> newPreviousSibling;
findPlaceForCounter(renderer, it->key, node->hasResetType(), newParent, newPreviousSibling);
if (node != counterMap->get(it->key))
@@ -545,31 +528,33 @@ static void updateCounters(RenderObject* renderer)
if (newParent == parent && newPreviousSibling == node->previousSibling())
continue;
if (parent)
- parent->removeChild(node.get());
+ parent->removeChild(*node);
if (newParent)
- newParent->insertAfter(node.get(), newPreviousSibling.get(), it->key);
+ newParent->insertAfter(*node, newPreviousSibling.get(), it->key);
}
}
-void RenderCounter::rendererSubtreeAttached(RenderObject* renderer)
+void RenderCounter::rendererSubtreeAttached(RenderElement& renderer)
{
- if (!renderer->view().hasRenderCounters())
+ if (!renderer.view().hasRenderCounters())
return;
- Node* node = renderer->node();
- if (node && !node->isPseudoElement())
- node = node->parentNode();
+ Element* element = renderer.element();
+ if (element && !element->isPseudoElement())
+ element = element->parentElement();
else
- node = renderer->generatingNode();
- if (node && !node->renderer())
+ element = renderer.generatingElement();
+ if (element && !element->renderer())
return; // No need to update if the parent is not attached yet
- for (RenderObject* descendant = renderer; descendant; descendant = descendant->nextInPreOrder(renderer))
- updateCounters(descendant);
+ for (RenderObject* descendant = &renderer; descendant; descendant = descendant->nextInPreOrder(&renderer)) {
+ if (is<RenderElement>(*descendant))
+ updateCounters(downcast<RenderElement>(*descendant));
+ }
}
-void RenderCounter::rendererStyleChanged(RenderObject* renderer, const RenderStyle* oldStyle, const RenderStyle* newStyle)
+void RenderCounter::rendererStyleChanged(RenderElement& renderer, const RenderStyle* oldStyle, const RenderStyle* newStyle)
{
- Node* node = renderer->generatingNode();
- if (!node || !node->renderer())
+ Element* element = renderer.generatingElement();
+ if (!element || !element->renderer())
return; // cannot have generated content or if it can have, it will be handled during attaching
const CounterDirectiveMap* newCounterDirectives;
const CounterDirectiveMap* oldCounterDirectives;
@@ -595,7 +580,7 @@ void RenderCounter::rendererStyleChanged(RenderObject* renderer, const RenderSty
RenderCounter::destroyCounterNode(renderer, it->key);
}
} else {
- if (renderer->hasCounterNodeMap())
+ if (renderer.hasCounterNodeMap())
RenderCounter::destroyCounterNodes(renderer);
}
} else if (newStyle && (newCounterDirectives = newStyle->counterDirectives())) {
@@ -611,7 +596,7 @@ void RenderCounter::rendererStyleChanged(RenderObject* renderer, const RenderSty
} // namespace WebCore
-#ifndef NDEBUG
+#if ENABLE(TREE_DEBUGGING)
void showCounterRendererTree(const WebCore::RenderObject* renderer, const char* counterName)
{
@@ -623,13 +608,15 @@ void showCounterRendererTree(const WebCore::RenderObject* renderer, const char*
AtomicString identifier(counterName);
for (const WebCore::RenderObject* current = root; current; current = current->nextInPreOrder()) {
+ if (!is<WebCore::RenderElement>(*current))
+ continue;
fprintf(stderr, "%c", (current == renderer) ? '*' : ' ');
for (const WebCore::RenderObject* parent = current; parent && parent != root; parent = parent->parent())
fprintf(stderr, " ");
fprintf(stderr, "%p N:%p P:%p PS:%p NS:%p C:%p\n",
current, current->node(), current->parent(), current->previousSibling(),
- current->nextSibling(), current->hasCounterNodeMap() ?
- counterName ? WebCore::counterMaps().get(current)->get(identifier) : (WebCore::CounterNode*)1 : (WebCore::CounterNode*)0);
+ current->nextSibling(), downcast<WebCore::RenderElement>(*current).hasCounterNodeMap() ?
+ counterName ? WebCore::counterMaps().get(downcast<WebCore::RenderElement>(current))->get(identifier) : (WebCore::CounterNode*)1 : (WebCore::CounterNode*)0);
}
fflush(stderr);
}