| 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 24 matching lines...) Expand all Loading... |
| 35 m_countInParent(0), | 35 m_countInParent(0), |
| 36 m_owner(o), | 36 m_owner(o), |
| 37 m_rootLayoutObject(nullptr), | 37 m_rootLayoutObject(nullptr), |
| 38 m_parent(nullptr), | 38 m_parent(nullptr), |
| 39 m_previousSibling(nullptr), | 39 m_previousSibling(nullptr), |
| 40 m_nextSibling(nullptr), | 40 m_nextSibling(nullptr), |
| 41 m_firstChild(nullptr), | 41 m_firstChild(nullptr), |
| 42 m_lastChild(nullptr) {} | 42 m_lastChild(nullptr) {} |
| 43 | 43 |
| 44 CounterNode::~CounterNode() { | 44 CounterNode::~CounterNode() { |
| 45 // Ideally this would be an assert and this would never be reached. In reality
this happens a lot | 45 // Ideally this would be an assert and this would never be reached. In reality |
| 46 // so we need to handle these cases. The node is still connected to the tree s
o we need to detach it. | 46 // this happens a lot so we need to handle these cases. The node is still |
| 47 // connected to the tree so we need to detach it. |
| 47 if (m_parent || m_previousSibling || m_nextSibling || m_firstChild || | 48 if (m_parent || m_previousSibling || m_nextSibling || m_firstChild || |
| 48 m_lastChild) { | 49 m_lastChild) { |
| 49 CounterNode* oldParent = nullptr; | 50 CounterNode* oldParent = nullptr; |
| 50 CounterNode* oldPreviousSibling = nullptr; | 51 CounterNode* oldPreviousSibling = nullptr; |
| 51 // Instead of calling removeChild() we do this safely as the tree is likely
broken if we get here. | 52 // Instead of calling removeChild() we do this safely as the tree is likely |
| 53 // broken if we get here. |
| 52 if (m_parent) { | 54 if (m_parent) { |
| 53 if (m_parent->m_firstChild == this) | 55 if (m_parent->m_firstChild == this) |
| 54 m_parent->m_firstChild = m_nextSibling; | 56 m_parent->m_firstChild = m_nextSibling; |
| 55 if (m_parent->m_lastChild == this) | 57 if (m_parent->m_lastChild == this) |
| 56 m_parent->m_lastChild = m_previousSibling; | 58 m_parent->m_lastChild = m_previousSibling; |
| 57 oldParent = m_parent; | 59 oldParent = m_parent; |
| 58 m_parent = nullptr; | 60 m_parent = nullptr; |
| 59 } | 61 } |
| 60 if (m_previousSibling) { | 62 if (m_previousSibling) { |
| 61 if (m_previousSibling->m_nextSibling == this) | 63 if (m_previousSibling->m_nextSibling == this) |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 value->m_nextForSameCounter = nullptr; | 197 value->m_nextForSameCounter = nullptr; |
| 196 value->m_counterNode = nullptr; | 198 value->m_counterNode = nullptr; |
| 197 return; | 199 return; |
| 198 } | 200 } |
| 199 previous = iterator; | 201 previous = iterator; |
| 200 } | 202 } |
| 201 ASSERT_NOT_REACHED(); | 203 ASSERT_NOT_REACHED(); |
| 202 } | 204 } |
| 203 | 205 |
| 204 void CounterNode::resetLayoutObjects() { | 206 void CounterNode::resetLayoutObjects() { |
| 205 while (m_rootLayoutObject) | 207 while (m_rootLayoutObject) { |
| 206 m_rootLayoutObject | 208 // This makes m_rootLayoutObject point to the next layoutObject if any since |
| 207 ->invalidate(); // This makes m_rootLayoutObject point to the next layo
utObject if any since it disconnects the m_rootLayoutObject from this. | 209 // it disconnects the m_rootLayoutObject from this. |
| 210 m_rootLayoutObject->invalidate(); |
| 211 } |
| 208 } | 212 } |
| 209 | 213 |
| 210 void CounterNode::resetThisAndDescendantsLayoutObjects() { | 214 void CounterNode::resetThisAndDescendantsLayoutObjects() { |
| 211 CounterNode* node = this; | 215 CounterNode* node = this; |
| 212 do { | 216 do { |
| 213 node->resetLayoutObjects(); | 217 node->resetLayoutObjects(); |
| 214 node = node->nextInPreOrder(this); | 218 node = node->nextInPreOrder(this); |
| 215 } while (node); | 219 } while (node); |
| 216 } | 220 } |
| 217 | 221 |
| 218 void CounterNode::recount() { | 222 void CounterNode::recount() { |
| 219 for (CounterNode* node = this; node; node = node->m_nextSibling) { | 223 for (CounterNode* node = this; node; node = node->m_nextSibling) { |
| 220 int oldCount = node->m_countInParent; | 224 int oldCount = node->m_countInParent; |
| 221 int newCount = node->computeCountInParent(); | 225 int newCount = node->computeCountInParent(); |
| 222 if (oldCount == newCount) | 226 if (oldCount == newCount) |
| 223 break; | 227 break; |
| 224 node->m_countInParent = newCount; | 228 node->m_countInParent = newCount; |
| 225 node->resetThisAndDescendantsLayoutObjects(); | 229 node->resetThisAndDescendantsLayoutObjects(); |
| 226 } | 230 } |
| 227 } | 231 } |
| 228 | 232 |
| 229 void CounterNode::insertAfter(CounterNode* newChild, | 233 void CounterNode::insertAfter(CounterNode* newChild, |
| 230 CounterNode* refChild, | 234 CounterNode* refChild, |
| 231 const AtomicString& identifier) { | 235 const AtomicString& identifier) { |
| 232 ASSERT(newChild); | 236 ASSERT(newChild); |
| 233 ASSERT(!newChild->m_parent); | 237 ASSERT(!newChild->m_parent); |
| 234 ASSERT(!newChild->m_previousSibling); | 238 ASSERT(!newChild->m_previousSibling); |
| 235 ASSERT(!newChild->m_nextSibling); | 239 ASSERT(!newChild->m_nextSibling); |
| 236 // If the refChild is not our child we can not complete the request. This hard
ens against bugs in LayoutCounter. | 240 // If the refChild is not our child we can not complete the request. This |
| 237 // When layoutObjects are reparented it may request that we insert counter nod
es improperly. | 241 // hardens against bugs in LayoutCounter. |
| 242 // When layoutObjects are reparented it may request that we insert counter |
| 243 // nodes improperly. |
| 238 if (refChild && refChild->m_parent != this) | 244 if (refChild && refChild->m_parent != this) |
| 239 return; | 245 return; |
| 240 | 246 |
| 241 if (newChild->m_hasResetType) { | 247 if (newChild->m_hasResetType) { |
| 242 while (m_lastChild != refChild) | 248 while (m_lastChild != refChild) |
| 243 LayoutCounter::destroyCounterNode(m_lastChild->owner(), identifier); | 249 LayoutCounter::destroyCounterNode(m_lastChild->owner(), identifier); |
| 244 } | 250 } |
| 245 | 251 |
| 246 CounterNode* next; | 252 CounterNode* next; |
| 247 | 253 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 266 } | 272 } |
| 267 | 273 |
| 268 if (!newChild->m_firstChild || newChild->m_hasResetType) { | 274 if (!newChild->m_firstChild || newChild->m_hasResetType) { |
| 269 newChild->m_countInParent = newChild->computeCountInParent(); | 275 newChild->m_countInParent = newChild->computeCountInParent(); |
| 270 newChild->resetThisAndDescendantsLayoutObjects(); | 276 newChild->resetThisAndDescendantsLayoutObjects(); |
| 271 if (next) | 277 if (next) |
| 272 next->recount(); | 278 next->recount(); |
| 273 return; | 279 return; |
| 274 } | 280 } |
| 275 | 281 |
| 276 // The code below handles the case when a formerly root increment counter is l
oosing its root position | 282 // The code below handles the case when a formerly root increment counter is |
| 277 // and therefore its children become next siblings. | 283 // loosing its root position and therefore its children become next siblings. |
| 278 CounterNode* last = newChild->m_lastChild; | 284 CounterNode* last = newChild->m_lastChild; |
| 279 CounterNode* first = newChild->m_firstChild; | 285 CounterNode* first = newChild->m_firstChild; |
| 280 | 286 |
| 281 if (first) { | 287 if (first) { |
| 282 ASSERT(last); | 288 ASSERT(last); |
| 283 newChild->m_nextSibling = first; | 289 newChild->m_nextSibling = first; |
| 284 if (m_lastChild == newChild) | 290 if (m_lastChild == newChild) |
| 285 m_lastChild = last; | 291 m_lastChild = last; |
| 286 | 292 |
| 287 first->m_previousSibling = newChild; | 293 first->m_previousSibling = newChild; |
| 288 | 294 |
| 289 // The case when the original next sibling of the inserted node becomes a ch
ild of | 295 // The case when the original next sibling of the inserted node becomes a |
| 290 // one of the former children of the inserted node is not handled as it is b
elieved | 296 // child of one of the former children of the inserted node is not handled |
| 291 // to be impossible since: | 297 // as it is believed to be impossible since: |
| 292 // 1. if the increment counter node lost it's root position as a result of a
nother | 298 // 1. if the increment counter node lost it's root position as a result of |
| 293 // counter node being created, it will be inserted as the last child so n
ext is null. | 299 // another counter node being created, it will be inserted as the last |
| 294 // 2. if the increment counter node lost it's root position as a result of a
layoutObject being | 300 // child so next is null. |
| 295 // inserted into the document's layout tree, all its former children coun
ters are attached | 301 // 2. if the increment counter node lost it's root position as a result of a |
| 296 // to children of the inserted layoutObject and hence cannot be in scope
for counter nodes | 302 // layoutObject being inserted into the document's layout tree, all its |
| 297 // attached to layoutObjects that were already in the document's layout t
ree. | 303 // former children counters are attached to children of the inserted |
| 304 // layoutObject and hence cannot be in scope for counter nodes attached |
| 305 // to layoutObjects that were already in the document's layout tree. |
| 298 last->m_nextSibling = next; | 306 last->m_nextSibling = next; |
| 299 if (next) { | 307 if (next) { |
| 300 ASSERT(next->m_previousSibling == newChild); | 308 ASSERT(next->m_previousSibling == newChild); |
| 301 next->m_previousSibling = last; | 309 next->m_previousSibling = last; |
| 302 } else { | 310 } else { |
| 303 m_lastChild = last; | 311 m_lastChild = last; |
| 304 } | 312 } |
| 305 for (next = first;; next = next->m_nextSibling) { | 313 for (next = first;; next = next->m_nextSibling) { |
| 306 next->m_parent = this; | 314 next->m_parent = this; |
| 307 if (last == next) | 315 if (last == next) |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 #ifndef NDEBUG | 382 #ifndef NDEBUG |
| 375 | 383 |
| 376 void showCounterTree(const blink::CounterNode* counter) { | 384 void showCounterTree(const blink::CounterNode* counter) { |
| 377 if (counter) | 385 if (counter) |
| 378 showTreeAndMark(counter); | 386 showTreeAndMark(counter); |
| 379 else | 387 else |
| 380 fprintf(stderr, "Cannot showCounterTree for (nil).\n"); | 388 fprintf(stderr, "Cannot showCounterTree for (nil).\n"); |
| 381 } | 389 } |
| 382 | 390 |
| 383 #endif | 391 #endif |
| OLD | NEW |