PassRefPtr<StringImpl> RenderCounter::originalText() const { if (!parent()) return 0; if (!m_counterNode) m_counterNode = counter(parent(), m_counter.identifier(), true); CounterNode* child = m_counterNode; int value = child->isReset() ? child->value() : child->countInParent(); String text = listMarkerText(m_counter.listStyle(), value); if (!m_counter.separator().isNull()) { if (!child->isReset()) child = child->parent(); while (CounterNode* parent = child->parent()) { text = listMarkerText(m_counter.listStyle(), child->countInParent()) + m_counter.separator() + text; child = parent; } } return text.impl(); }
static bool findPlaceForCounter(RenderObject* object, const AtomicString& counterName, bool isReset, CounterNode*& parent, CounterNode*& previousSibling) { // Find the appropriate previous sibling for insertion into the parent node // by searching in render tree order for a child of the counter. parent = 0; previousSibling = 0; RenderObject* resetCandidate = isReset ? object->parent() : previousSiblingOrParent(object); RenderObject* prevCounterCandidate = object; CounterNode* candidateCounter = 0; // When a reset counter is chosen as candidateCounter, we'll // decide the new node should be a child of the reset node or a // sibling or the reset node. This flag controls it. bool createChildForReset = true; while ((prevCounterCandidate = prevCounterCandidate->previousInPreOrder())) { CounterNode* c = counter(prevCounterCandidate, counterName, false); if (prevCounterCandidate == resetCandidate) { if (!candidateCounter) { candidateCounter = c; createChildForReset = true; } if (candidateCounter) { if (createChildForReset && candidateCounter->isReset()) { parent = candidateCounter; previousSibling = 0; } else { parent = candidateCounter->parent(); previousSibling = candidateCounter; } return true; } resetCandidate = previousSiblingOrParent(resetCandidate); } else if (c) { if (c->isReset()) { if (c->parent()) { // The new node may be the next sibling of this reset node. createChildForReset = false; candidateCounter = c; } else { createChildForReset = true; candidateCounter = 0; } } else if (!candidateCounter) { createChildForReset = true; candidateCounter = c; } } } return false; }
void RenderCounter::generateContent() { bool counters; counters = !m_counter->separator().isNull(); if(!m_counterNode) m_counterNode = getCounter(m_counter->identifier().string(), true, counters); int value = m_counterNode->count(); if(m_counterNode->isReset()) value = m_counterNode->value(); int total = value; if(m_counterNode->parent()) total = m_counterNode->parent()->total(); m_item = toListStyleType(value, total, (EListStyleType)m_counter->listStyle()); if(counters) { CounterNode *counter = m_counterNode->parent(); // we deliberately do not render the root counter-node while(counter->parent() && !(counter->isReset() && counter->parent()->isRoot())) { value = counter->count(); total = counter->parent()->total(); m_item = toListStyleType(value, total, (EListStyleType)m_counter->listStyle()) + m_counter->separator().string() + m_item; counter = counter->parent(); }; } }