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, |
(...skipping 26 matching lines...) Expand all Loading... |
37 , m_parent(0) | 37 , m_parent(0) |
38 , m_previousSibling(0) | 38 , m_previousSibling(0) |
39 , m_nextSibling(0) | 39 , m_nextSibling(0) |
40 , m_firstChild(0) | 40 , m_firstChild(0) |
41 , m_lastChild(0) | 41 , m_lastChild(0) |
42 { | 42 { |
43 } | 43 } |
44 | 44 |
45 CounterNode::~CounterNode() | 45 CounterNode::~CounterNode() |
46 { | 46 { |
| 47 // Ideally this would be an assert and this would never be reached. In reali
ty this happens a lot |
| 48 // so we need to handle these cases. The node is still connected to the tree
so we need to detach it. |
| 49 if (m_parent || m_previousSibling || m_nextSibling || m_firstChild || m_last
Child) { |
| 50 CounterNode* oldParent = 0; |
| 51 CounterNode* oldPreviousSibling = 0; |
| 52 // Instead of calling removeChild() we do this safely as the tree is lik
ely broken if we get here. |
| 53 if (m_parent) { |
| 54 if (m_parent->m_firstChild == this) |
| 55 m_parent->m_firstChild = m_nextSibling; |
| 56 if (m_parent->m_lastChild == this) |
| 57 m_parent->m_lastChild = m_previousSibling; |
| 58 oldParent = m_parent; |
| 59 m_parent = 0; |
| 60 } |
| 61 if (m_previousSibling) { |
| 62 if (m_previousSibling->m_nextSibling == this) |
| 63 m_previousSibling->m_nextSibling = m_nextSibling; |
| 64 oldPreviousSibling = m_previousSibling; |
| 65 m_previousSibling = 0; |
| 66 } |
| 67 if (m_nextSibling) { |
| 68 if (m_nextSibling->m_previousSibling == this) |
| 69 m_nextSibling->m_previousSibling = oldPreviousSibling; |
| 70 m_nextSibling = 0; |
| 71 } |
| 72 if (m_firstChild) { |
| 73 // The node's children are reparented to the old parent. |
| 74 for (CounterNode* child = m_firstChild; child; ) { |
| 75 CounterNode* nextChild = child->m_nextSibling; |
| 76 CounterNode* nextSibling = 0; |
| 77 child->m_parent = oldParent; |
| 78 if (oldPreviousSibling) { |
| 79 nextSibling = oldPreviousSibling->m_nextSibling; |
| 80 child->m_previousSibling = oldPreviousSibling; |
| 81 oldPreviousSibling->m_nextSibling = child; |
| 82 child->m_nextSibling = nextSibling; |
| 83 nextSibling->m_previousSibling = child; |
| 84 oldPreviousSibling = child; |
| 85 } |
| 86 child = nextChild; |
| 87 } |
| 88 } |
| 89 } |
47 resetRenderers(); | 90 resetRenderers(); |
48 } | 91 } |
49 | 92 |
50 PassRefPtr<CounterNode> CounterNode::create(RenderObject* owner, bool hasResetTy
pe, int value) | 93 PassRefPtr<CounterNode> CounterNode::create(RenderObject* owner, bool hasResetTy
pe, int value) |
51 { | 94 { |
52 return adoptRef(new CounterNode(owner, hasResetType, value)); | 95 return adoptRef(new CounterNode(owner, hasResetType, value)); |
53 } | 96 } |
54 | 97 |
55 CounterNode* CounterNode::nextInPreOrderAfterChildren(const CounterNode* stayWit
hin) const | 98 CounterNode* CounterNode::nextInPreOrderAfterChildren(const CounterNode* stayWit
hin) const |
56 { | 99 { |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 | 365 |
323 #ifndef NDEBUG | 366 #ifndef NDEBUG |
324 | 367 |
325 void showCounterTree(const WebCore::CounterNode* counter) | 368 void showCounterTree(const WebCore::CounterNode* counter) |
326 { | 369 { |
327 if (counter) | 370 if (counter) |
328 showTreeAndMark(counter); | 371 showTreeAndMark(counter); |
329 } | 372 } |
330 | 373 |
331 #endif | 374 #endif |
OLD | NEW |