bdakin | 5d6edd4 | 2006-10-02 23:15:31 +0000 | [diff] [blame] | 1 | /* |
bdakin | 5d6edd4 | 2006-10-02 23:15:31 +0000 | [diff] [blame] | 2 | * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) |
darin | b5a0e3d | 2007-01-10 00:08:18 +0000 | [diff] [blame] | 3 | * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. |
bdakin | 5d6edd4 | 2006-10-02 23:15:31 +0000 | [diff] [blame] | 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Library General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Library General Public License for more details. |
| 14 | * |
| 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 |
ddkilzer | c8eccec | 2007-09-26 02:29:57 +0000 | [diff] [blame] | 17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 | * Boston, MA 02110-1301, USA. |
bdakin | 5d6edd4 | 2006-10-02 23:15:31 +0000 | [diff] [blame] | 19 | * |
| 20 | */ |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 21 | |
weinig | 1497a7e | 2006-10-26 20:23:55 +0000 | [diff] [blame] | 22 | #ifndef CounterNode_h |
| 23 | #define CounterNode_h |
bdakin | 5d6edd4 | 2006-10-02 23:15:31 +0000 | [diff] [blame] | 24 | |
barraclough@apple.com | d218c2d | 2010-08-10 00:38:14 +0000 | [diff] [blame] | 25 | #include <wtf/Forward.h> |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 26 | #include <wtf/Noncopyable.h> |
jschuh@chromium.org | e94df97 | 2010-09-30 20:31:45 +0000 | [diff] [blame] | 27 | #include <wtf/RefCounted.h> |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 28 | |
| 29 | // This implements a counter tree that is used for finding parents in counters() lookup, |
| 30 | // and for propagating count changes when nodes are added or removed. |
| 31 | |
| 32 | // Parents represent unique counters and their scope, which are created either explicitly |
| 33 | // by "counter-reset" style rules or implicitly by referring to a counter that is not in scope. |
| 34 | // Such nodes are tagged as "reset" nodes, although they are not all due to "counter-reset". |
| 35 | |
| 36 | // Not that render tree children are often counter tree siblings due to counter scoping rules. |
bdakin | 5d6edd4 | 2006-10-02 23:15:31 +0000 | [diff] [blame] | 37 | |
| 38 | namespace WebCore { |
| 39 | |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 40 | class RenderObject; |
carol.szabo@nokia.com | 7cf0a55 | 2011-03-23 00:04:58 +0000 | [diff] [blame] | 41 | class RenderCounter; |
bdakin | 5d6edd4 | 2006-10-02 23:15:31 +0000 | [diff] [blame] | 42 | |
jschuh@chromium.org | e94df97 | 2010-09-30 20:31:45 +0000 | [diff] [blame] | 43 | class CounterNode : public RefCounted<CounterNode> { |
bdakin | 5d6edd4 | 2006-10-02 23:15:31 +0000 | [diff] [blame] | 44 | public: |
jschuh@chromium.org | e94df97 | 2010-09-30 20:31:45 +0000 | [diff] [blame] | 45 | static PassRefPtr<CounterNode> create(RenderObject*, bool isReset, int value); |
carol.szabo@nokia.com | d7917f7 | 2011-03-24 02:25:06 +0000 | [diff] [blame] | 46 | ~CounterNode(); |
eric@webkit.org | d8ca5e1 | 2009-12-21 20:11:47 +0000 | [diff] [blame] | 47 | bool actsAsReset() const { return m_hasResetType || !m_parent; } |
| 48 | bool hasResetType() const { return m_hasResetType; } |
bdakin | 5d6edd4 | 2006-10-02 23:15:31 +0000 | [diff] [blame] | 49 | int value() const { return m_value; } |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 50 | int countInParent() const { return m_countInParent; } |
carol.szabo@nokia.com | 7cf0a55 | 2011-03-23 00:04:58 +0000 | [diff] [blame] | 51 | RenderObject* owner() const { return m_owner; } |
| 52 | void addRenderer(RenderCounter*); |
| 53 | void removeRenderer(RenderCounter*); |
| 54 | |
| 55 | // Invalidates the text in the renderers of this counter, if any. |
| 56 | void resetRenderers(); |
bdakin | 5d6edd4 | 2006-10-02 23:15:31 +0000 | [diff] [blame] | 57 | |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 58 | CounterNode* parent() const { return m_parent; } |
| 59 | CounterNode* previousSibling() const { return m_previousSibling; } |
| 60 | CounterNode* nextSibling() const { return m_nextSibling; } |
| 61 | CounterNode* firstChild() const { return m_firstChild; } |
| 62 | CounterNode* lastChild() const { return m_lastChild; } |
eric@webkit.org | 0248271 | 2009-11-13 20:21:44 +0000 | [diff] [blame] | 63 | CounterNode* lastDescendant() const; |
| 64 | CounterNode* previousInPreOrder() const; |
| 65 | CounterNode* nextInPreOrder(const CounterNode* stayWithin = 0) const; |
| 66 | CounterNode* nextInPreOrderAfterChildren(const CounterNode* stayWithin = 0) const; |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 67 | |
eric@webkit.org | 0248271 | 2009-11-13 20:21:44 +0000 | [diff] [blame] | 68 | void insertAfter(CounterNode* newChild, CounterNode* beforeChild, const AtomicString& identifier); |
eric@webkit.org | d8ca5e1 | 2009-12-21 20:11:47 +0000 | [diff] [blame] | 69 | |
| 70 | // identifier must match the identifier of this counter. |
carol.szabo@nokia.com | 7cf0a55 | 2011-03-23 00:04:58 +0000 | [diff] [blame] | 71 | void removeChild(CounterNode*); |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 72 | |
| 73 | private: |
jschuh@chromium.org | e94df97 | 2010-09-30 20:31:45 +0000 | [diff] [blame] | 74 | CounterNode(RenderObject*, bool isReset, int value); |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 75 | int computeCountInParent() const; |
eric@webkit.org | d8ca5e1 | 2009-12-21 20:11:47 +0000 | [diff] [blame] | 76 | // Invalidates the text in the renderer of this counter, if any, |
| 77 | // and in the renderers of all descendants of this counter, if any. |
carol.szabo@nokia.com | 7cf0a55 | 2011-03-23 00:04:58 +0000 | [diff] [blame] | 78 | void resetThisAndDescendantsRenderers(); |
| 79 | void recount(); |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 80 | |
eric@webkit.org | d8ca5e1 | 2009-12-21 20:11:47 +0000 | [diff] [blame] | 81 | bool m_hasResetType; |
bdakin | 5d6edd4 | 2006-10-02 23:15:31 +0000 | [diff] [blame] | 82 | int m_value; |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 83 | int m_countInParent; |
carol.szabo@nokia.com | 7cf0a55 | 2011-03-23 00:04:58 +0000 | [diff] [blame] | 84 | RenderObject* m_owner; |
| 85 | RenderCounter* m_rootRenderer; |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 86 | |
| 87 | CounterNode* m_parent; |
| 88 | CounterNode* m_previousSibling; |
| 89 | CounterNode* m_nextSibling; |
| 90 | CounterNode* m_firstChild; |
| 91 | CounterNode* m_lastChild; |
bdakin | 5d6edd4 | 2006-10-02 23:15:31 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | } // namespace WebCore |
| 95 | |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 96 | #ifndef NDEBUG |
| 97 | // Outside the WebCore namespace for ease of invocation from gdb. |
carol.szabo@nokia.com | 02635bf | 2011-02-05 00:28:57 +0000 | [diff] [blame] | 98 | void showCounterTree(const WebCore::CounterNode*); |
darin | ec37548 | 2007-01-06 01:36:24 +0000 | [diff] [blame] | 99 | #endif |
| 100 | |
bdakin | 5d6edd4 | 2006-10-02 23:15:31 +0000 | [diff] [blame] | 101 | #endif // CounterNode_h |