| 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 while (CounterNode* lastChild = previous->m_lastChild) | 138 while (CounterNode* lastChild = previous->m_lastChild) |
| 139 previous = lastChild; | 139 previous = lastChild; |
| 140 | 140 |
| 141 return previous; | 141 return previous; |
| 142 } | 142 } |
| 143 | 143 |
| 144 int CounterNode::computeCountInParent() const { | 144 int CounterNode::computeCountInParent() const { |
| 145 int increment = actsAsReset() ? 0 : m_value; | 145 int increment = actsAsReset() ? 0 : m_value; |
| 146 if (m_previousSibling) | 146 if (m_previousSibling) |
| 147 return m_previousSibling->m_countInParent + increment; | 147 return m_previousSibling->m_countInParent + increment; |
| 148 ASSERT(m_parent->m_firstChild == this); | 148 DCHECK_EQ(m_parent->m_firstChild, this); |
| 149 return m_parent->m_value + increment; | 149 return m_parent->m_value + increment; |
| 150 } | 150 } |
| 151 | 151 |
| 152 void CounterNode::addLayoutObject(LayoutCounter* value) { | 152 void CounterNode::addLayoutObject(LayoutCounter* value) { |
| 153 if (!value) { | 153 if (!value) { |
| 154 NOTREACHED(); | 154 NOTREACHED(); |
| 155 return; | 155 return; |
| 156 } | 156 } |
| 157 if (value->m_counterNode) { | 157 if (value->m_counterNode) { |
| 158 NOTREACHED(); | 158 NOTREACHED(); |
| 159 value->m_counterNode->removeLayoutObject(value); | 159 value->m_counterNode->removeLayoutObject(value); |
| 160 } | 160 } |
| 161 ASSERT(!value->m_nextForSameCounter); | 161 DCHECK(!value->m_nextForSameCounter); |
| 162 for (LayoutCounter* iterator = m_rootLayoutObject; iterator; | 162 for (LayoutCounter* iterator = m_rootLayoutObject; iterator; |
| 163 iterator = iterator->m_nextForSameCounter) { | 163 iterator = iterator->m_nextForSameCounter) { |
| 164 if (iterator == value) { | 164 if (iterator == value) { |
| 165 NOTREACHED(); | 165 NOTREACHED(); |
| 166 return; | 166 return; |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 value->m_nextForSameCounter = m_rootLayoutObject; | 169 value->m_nextForSameCounter = m_rootLayoutObject; |
| 170 m_rootLayoutObject = value; | 170 m_rootLayoutObject = value; |
| 171 if (value->m_counterNode != this) { | 171 if (value->m_counterNode != this) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 if (oldCount == newCount) | 226 if (oldCount == newCount) |
| 227 break; | 227 break; |
| 228 node->m_countInParent = newCount; | 228 node->m_countInParent = newCount; |
| 229 node->resetThisAndDescendantsLayoutObjects(); | 229 node->resetThisAndDescendantsLayoutObjects(); |
| 230 } | 230 } |
| 231 } | 231 } |
| 232 | 232 |
| 233 void CounterNode::insertAfter(CounterNode* newChild, | 233 void CounterNode::insertAfter(CounterNode* newChild, |
| 234 CounterNode* refChild, | 234 CounterNode* refChild, |
| 235 const AtomicString& identifier) { | 235 const AtomicString& identifier) { |
| 236 ASSERT(newChild); | 236 DCHECK(newChild); |
| 237 ASSERT(!newChild->m_parent); | 237 DCHECK(!newChild->m_parent); |
| 238 ASSERT(!newChild->m_previousSibling); | 238 DCHECK(!newChild->m_previousSibling); |
| 239 ASSERT(!newChild->m_nextSibling); | 239 DCHECK(!newChild->m_nextSibling); |
| 240 // If the refChild is not our child we can not complete the request. This | 240 // If the refChild is not our child we can not complete the request. This |
| 241 // hardens against bugs in LayoutCounter. | 241 // hardens against bugs in LayoutCounter. |
| 242 // When layoutObjects are reparented it may request that we insert counter | 242 // When layoutObjects are reparented it may request that we insert counter |
| 243 // nodes improperly. | 243 // nodes improperly. |
| 244 if (refChild && refChild->m_parent != this) | 244 if (refChild && refChild->m_parent != this) |
| 245 return; | 245 return; |
| 246 | 246 |
| 247 if (newChild->m_hasResetType) { | 247 if (newChild->m_hasResetType) { |
| 248 while (m_lastChild != refChild) | 248 while (m_lastChild != refChild) |
| 249 LayoutCounter::destroyCounterNode(m_lastChild->owner(), identifier); | 249 LayoutCounter::destroyCounterNode(m_lastChild->owner(), identifier); |
| 250 } | 250 } |
| 251 | 251 |
| 252 CounterNode* next; | 252 CounterNode* next; |
| 253 | 253 |
| 254 if (refChild) { | 254 if (refChild) { |
| 255 next = refChild->m_nextSibling; | 255 next = refChild->m_nextSibling; |
| 256 refChild->m_nextSibling = newChild; | 256 refChild->m_nextSibling = newChild; |
| 257 } else { | 257 } else { |
| 258 next = m_firstChild; | 258 next = m_firstChild; |
| 259 m_firstChild = newChild; | 259 m_firstChild = newChild; |
| 260 } | 260 } |
| 261 | 261 |
| 262 newChild->m_parent = this; | 262 newChild->m_parent = this; |
| 263 newChild->m_previousSibling = refChild; | 263 newChild->m_previousSibling = refChild; |
| 264 | 264 |
| 265 if (next) { | 265 if (next) { |
| 266 ASSERT(next->m_previousSibling == refChild); | 266 DCHECK_EQ(next->m_previousSibling, refChild); |
| 267 next->m_previousSibling = newChild; | 267 next->m_previousSibling = newChild; |
| 268 newChild->m_nextSibling = next; | 268 newChild->m_nextSibling = next; |
| 269 } else { | 269 } else { |
| 270 ASSERT(m_lastChild == refChild); | 270 DCHECK_EQ(m_lastChild, refChild); |
| 271 m_lastChild = newChild; | 271 m_lastChild = newChild; |
| 272 } | 272 } |
| 273 | 273 |
| 274 if (!newChild->m_firstChild || newChild->m_hasResetType) { | 274 if (!newChild->m_firstChild || newChild->m_hasResetType) { |
| 275 newChild->m_countInParent = newChild->computeCountInParent(); | 275 newChild->m_countInParent = newChild->computeCountInParent(); |
| 276 newChild->resetThisAndDescendantsLayoutObjects(); | 276 newChild->resetThisAndDescendantsLayoutObjects(); |
| 277 if (next) | 277 if (next) |
| 278 next->recount(); | 278 next->recount(); |
| 279 return; | 279 return; |
| 280 } | 280 } |
| 281 | 281 |
| 282 // The code below handles the case when a formerly root increment counter is | 282 // The code below handles the case when a formerly root increment counter is |
| 283 // loosing its root position and therefore its children become next siblings. | 283 // loosing its root position and therefore its children become next siblings. |
| 284 CounterNode* last = newChild->m_lastChild; | 284 CounterNode* last = newChild->m_lastChild; |
| 285 CounterNode* first = newChild->m_firstChild; | 285 CounterNode* first = newChild->m_firstChild; |
| 286 | 286 |
| 287 if (first) { | 287 if (first) { |
| 288 ASSERT(last); | 288 DCHECK(last); |
| 289 newChild->m_nextSibling = first; | 289 newChild->m_nextSibling = first; |
| 290 if (m_lastChild == newChild) | 290 if (m_lastChild == newChild) |
| 291 m_lastChild = last; | 291 m_lastChild = last; |
| 292 | 292 |
| 293 first->m_previousSibling = newChild; | 293 first->m_previousSibling = newChild; |
| 294 | 294 |
| 295 // The case when the original next sibling of the inserted node becomes a | 295 // The case when the original next sibling of the inserted node becomes a |
| 296 // child of one of the former children of the inserted node is not handled | 296 // child of one of the former children of the inserted node is not handled |
| 297 // as it is believed to be impossible since: | 297 // as it is believed to be impossible since: |
| 298 // 1. if the increment counter node lost it's root position as a result of | 298 // 1. if the increment counter node lost it's root position as a result of |
| 299 // another counter node being created, it will be inserted as the last | 299 // another counter node being created, it will be inserted as the last |
| 300 // child so next is null. | 300 // child so next is null. |
| 301 // 2. if the increment counter node lost it's root position as a result of a | 301 // 2. if the increment counter node lost it's root position as a result of a |
| 302 // layoutObject being inserted into the document's layout tree, all its | 302 // layoutObject being inserted into the document's layout tree, all its |
| 303 // former children counters are attached to children of the inserted | 303 // former children counters are attached to children of the inserted |
| 304 // layoutObject and hence cannot be in scope for counter nodes attached | 304 // layoutObject and hence cannot be in scope for counter nodes attached |
| 305 // to layoutObjects that were already in the document's layout tree. | 305 // to layoutObjects that were already in the document's layout tree. |
| 306 last->m_nextSibling = next; | 306 last->m_nextSibling = next; |
| 307 if (next) { | 307 if (next) { |
| 308 ASSERT(next->m_previousSibling == newChild); | 308 DCHECK_EQ(next->m_previousSibling, newChild); |
| 309 next->m_previousSibling = last; | 309 next->m_previousSibling = last; |
| 310 } else { | 310 } else { |
| 311 m_lastChild = last; | 311 m_lastChild = last; |
| 312 } | 312 } |
| 313 for (next = first;; next = next->m_nextSibling) { | 313 for (next = first;; next = next->m_nextSibling) { |
| 314 next->m_parent = this; | 314 next->m_parent = this; |
| 315 if (last == next) | 315 if (last == next) |
| 316 break; | 316 break; |
| 317 } | 317 } |
| 318 } | 318 } |
| 319 newChild->m_firstChild = nullptr; | 319 newChild->m_firstChild = nullptr; |
| 320 newChild->m_lastChild = nullptr; | 320 newChild->m_lastChild = nullptr; |
| 321 newChild->m_countInParent = newChild->computeCountInParent(); | 321 newChild->m_countInParent = newChild->computeCountInParent(); |
| 322 newChild->resetLayoutObjects(); | 322 newChild->resetLayoutObjects(); |
| 323 first->recount(); | 323 first->recount(); |
| 324 } | 324 } |
| 325 | 325 |
| 326 void CounterNode::removeChild(CounterNode* oldChild) { | 326 void CounterNode::removeChild(CounterNode* oldChild) { |
| 327 ASSERT(oldChild); | 327 DCHECK(oldChild); |
| 328 ASSERT(!oldChild->m_firstChild); | 328 DCHECK(!oldChild->m_firstChild); |
| 329 ASSERT(!oldChild->m_lastChild); | 329 DCHECK(!oldChild->m_lastChild); |
| 330 | 330 |
| 331 CounterNode* next = oldChild->m_nextSibling; | 331 CounterNode* next = oldChild->m_nextSibling; |
| 332 CounterNode* previous = oldChild->m_previousSibling; | 332 CounterNode* previous = oldChild->m_previousSibling; |
| 333 | 333 |
| 334 oldChild->m_nextSibling = nullptr; | 334 oldChild->m_nextSibling = nullptr; |
| 335 oldChild->m_previousSibling = nullptr; | 335 oldChild->m_previousSibling = nullptr; |
| 336 oldChild->m_parent = nullptr; | 336 oldChild->m_parent = nullptr; |
| 337 | 337 |
| 338 if (previous) { | 338 if (previous) { |
| 339 previous->m_nextSibling = next; | 339 previous->m_nextSibling = next; |
| 340 } else { | 340 } else { |
| 341 ASSERT(m_firstChild == oldChild); | 341 DCHECK_EQ(m_firstChild, oldChild); |
| 342 m_firstChild = next; | 342 m_firstChild = next; |
| 343 } | 343 } |
| 344 | 344 |
| 345 if (next) { | 345 if (next) { |
| 346 next->m_previousSibling = previous; | 346 next->m_previousSibling = previous; |
| 347 } else { | 347 } else { |
| 348 ASSERT(m_lastChild == oldChild); | 348 DCHECK_EQ(m_lastChild, oldChild); |
| 349 m_lastChild = previous; | 349 m_lastChild = previous; |
| 350 } | 350 } |
| 351 | 351 |
| 352 if (next) | 352 if (next) |
| 353 next->recount(); | 353 next->recount(); |
| 354 } | 354 } |
| 355 | 355 |
| 356 #ifndef NDEBUG | 356 #ifndef NDEBUG |
| 357 | 357 |
| 358 static void showTreeAndMark(const CounterNode* node) { | 358 static void showTreeAndMark(const CounterNode* node) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 382 #ifndef NDEBUG | 382 #ifndef NDEBUG |
| 383 | 383 |
| 384 void showCounterTree(const blink::CounterNode* counter) { | 384 void showCounterTree(const blink::CounterNode* counter) { |
| 385 if (counter) | 385 if (counter) |
| 386 showTreeAndMark(counter); | 386 showTreeAndMark(counter); |
| 387 else | 387 else |
| 388 fprintf(stderr, "Cannot showCounterTree for (nil).\n"); | 388 fprintf(stderr, "Cannot showCounterTree for (nil).\n"); |
| 389 } | 389 } |
| 390 | 390 |
| 391 #endif | 391 #endif |
| OLD | NEW |