| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) | 2 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) |
| 3 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. | 3 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
| 14 * | 14 * |
| 15 * You should have received a copy of the GNU Library General Public License | 15 * You should have received a copy of the GNU Library General Public License |
| 16 * along with this library; see the file COPYING.LIB. If not, write to | 16 * along with this library; see the file COPYING.LIB. If not, write to |
| 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
| 19 * | 19 * |
| 20 */ | 20 */ |
| 21 | 21 |
| 22 #ifndef CounterNode_h | 22 #ifndef CounterNode_h |
| 23 #define CounterNode_h | 23 #define CounterNode_h |
| 24 | 24 |
| 25 #include <wtf/Forward.h> | 25 #include <wtf/Forward.h> |
| 26 #include <wtf/Noncopyable.h> | 26 #include <wtf/Noncopyable.h> |
| 27 #include <wtf/RefCounted.h> |
| 27 | 28 |
| 28 // This implements a counter tree that is used for finding parents in counters()
lookup, | 29 // This implements a counter tree that is used for finding parents in counters()
lookup, |
| 29 // and for propagating count changes when nodes are added or removed. | 30 // and for propagating count changes when nodes are added or removed. |
| 30 | 31 |
| 31 // Parents represent unique counters and their scope, which are created either e
xplicitly | 32 // Parents represent unique counters and their scope, which are created either e
xplicitly |
| 32 // by "counter-reset" style rules or implicitly by referring to a counter that i
s not in scope. | 33 // by "counter-reset" style rules or implicitly by referring to a counter that i
s not in scope. |
| 33 // Such nodes are tagged as "reset" nodes, although they are not all due to "cou
nter-reset". | 34 // Such nodes are tagged as "reset" nodes, although they are not all due to "cou
nter-reset". |
| 34 | 35 |
| 35 // Not that render tree children are often counter tree siblings due to counter
scoping rules. | 36 // Not that render tree children are often counter tree siblings due to counter
scoping rules. |
| 36 | 37 |
| 37 namespace WebCore { | 38 namespace WebCore { |
| 38 | 39 |
| 39 class RenderObject; | 40 class RenderObject; |
| 40 | 41 |
| 41 class CounterNode : public Noncopyable { | 42 class CounterNode : public RefCounted<CounterNode> { |
| 42 public: | 43 public: |
| 43 CounterNode(RenderObject*, bool isReset, int value); | 44 static PassRefPtr<CounterNode> create(RenderObject*, bool isReset, int value
); |
| 44 | 45 |
| 45 bool actsAsReset() const { return m_hasResetType || !m_parent; } | 46 bool actsAsReset() const { return m_hasResetType || !m_parent; } |
| 46 bool hasResetType() const { return m_hasResetType; } | 47 bool hasResetType() const { return m_hasResetType; } |
| 47 int value() const { return m_value; } | 48 int value() const { return m_value; } |
| 48 int countInParent() const { return m_countInParent; } | 49 int countInParent() const { return m_countInParent; } |
| 49 RenderObject* renderer() const { return m_renderer; } | 50 RenderObject* renderer() const { return m_renderer; } |
| 50 | 51 |
| 51 CounterNode* parent() const { return m_parent; } | 52 CounterNode* parent() const { return m_parent; } |
| 52 CounterNode* previousSibling() const { return m_previousSibling; } | 53 CounterNode* previousSibling() const { return m_previousSibling; } |
| 53 CounterNode* nextSibling() const { return m_nextSibling; } | 54 CounterNode* nextSibling() const { return m_nextSibling; } |
| 54 CounterNode* firstChild() const { return m_firstChild; } | 55 CounterNode* firstChild() const { return m_firstChild; } |
| 55 CounterNode* lastChild() const { return m_lastChild; } | 56 CounterNode* lastChild() const { return m_lastChild; } |
| 56 CounterNode* lastDescendant() const; | 57 CounterNode* lastDescendant() const; |
| 57 CounterNode* previousInPreOrder() const; | 58 CounterNode* previousInPreOrder() const; |
| 58 CounterNode* nextInPreOrder(const CounterNode* stayWithin = 0) const; | 59 CounterNode* nextInPreOrder(const CounterNode* stayWithin = 0) const; |
| 59 CounterNode* nextInPreOrderAfterChildren(const CounterNode* stayWithin = 0)
const; | 60 CounterNode* nextInPreOrderAfterChildren(const CounterNode* stayWithin = 0)
const; |
| 60 | 61 |
| 61 void insertAfter(CounterNode* newChild, CounterNode* beforeChild, const Atom
icString& identifier); | 62 void insertAfter(CounterNode* newChild, CounterNode* beforeChild, const Atom
icString& identifier); |
| 62 | 63 |
| 63 // identifier must match the identifier of this counter. | 64 // identifier must match the identifier of this counter. |
| 64 void removeChild(CounterNode*, const AtomicString& identifier); | 65 void removeChild(CounterNode*, const AtomicString& identifier); |
| 65 | 66 |
| 66 private: | 67 private: |
| 68 CounterNode(RenderObject*, bool isReset, int value); |
| 67 int computeCountInParent() const; | 69 int computeCountInParent() const; |
| 68 void recount(const AtomicString& identifier); | 70 void recount(const AtomicString& identifier); |
| 69 | 71 |
| 70 // Invalidates the text in the renderer of this counter, if any. | 72 // Invalidates the text in the renderer of this counter, if any. |
| 71 // identifier must match the identifier of this counter. | 73 // identifier must match the identifier of this counter. |
| 72 void resetRenderer(const AtomicString& identifier) const; | 74 void resetRenderer(const AtomicString& identifier) const; |
| 73 | 75 |
| 74 // Invalidates the text in the renderer of this counter, if any, | 76 // Invalidates the text in the renderer of this counter, if any, |
| 75 // and in the renderers of all descendants of this counter, if any. | 77 // and in the renderers of all descendants of this counter, if any. |
| 76 // identifier must match the identifier of this counter. | 78 // identifier must match the identifier of this counter. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 89 }; | 91 }; |
| 90 | 92 |
| 91 } // namespace WebCore | 93 } // namespace WebCore |
| 92 | 94 |
| 93 #ifndef NDEBUG | 95 #ifndef NDEBUG |
| 94 // Outside the WebCore namespace for ease of invocation from gdb. | 96 // Outside the WebCore namespace for ease of invocation from gdb. |
| 95 void showTree(const WebCore::CounterNode*); | 97 void showTree(const WebCore::CounterNode*); |
| 96 #endif | 98 #endif |
| 97 | 99 |
| 98 #endif // CounterNode_h | 100 #endif // CounterNode_h |
| OLD | NEW |