Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: Source/core/layout/CounterNode.cpp

Issue 1162383003: C++11: Replace 0 with nullptr where applicable in layout code. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add one more file. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/layout/CounterNode.h ('k') | Source/core/layout/FloatingObjects.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 17 matching lines...) Expand all
28 #include <stdio.h> 28 #include <stdio.h>
29 #endif 29 #endif
30 30
31 namespace blink { 31 namespace blink {
32 32
33 CounterNode::CounterNode(LayoutObject& o, bool hasResetType, int value) 33 CounterNode::CounterNode(LayoutObject& o, bool hasResetType, int value)
34 : m_hasResetType(hasResetType) 34 : m_hasResetType(hasResetType)
35 , m_value(value) 35 , m_value(value)
36 , m_countInParent(0) 36 , m_countInParent(0)
37 , m_owner(o) 37 , m_owner(o)
38 , m_rootLayoutObject(0) 38 , m_rootLayoutObject(nullptr)
39 , m_parent(0) 39 , m_parent(nullptr)
40 , m_previousSibling(0) 40 , m_previousSibling(nullptr)
41 , m_nextSibling(0) 41 , m_nextSibling(nullptr)
42 , m_firstChild(0) 42 , m_firstChild(nullptr)
43 , m_lastChild(0) 43 , m_lastChild(nullptr)
44 { 44 {
45 } 45 }
46 46
47 CounterNode::~CounterNode() 47 CounterNode::~CounterNode()
48 { 48 {
49 // Ideally this would be an assert and this would never be reached. In reali ty this happens a lot 49 // Ideally this would be an assert and this would never be reached. In reali ty this happens a lot
50 // so we need to handle these cases. The node is still connected to the tree so we need to detach it. 50 // so we need to handle these cases. The node is still connected to the tree so we need to detach it.
51 if (m_parent || m_previousSibling || m_nextSibling || m_firstChild || m_last Child) { 51 if (m_parent || m_previousSibling || m_nextSibling || m_firstChild || m_last Child) {
52 CounterNode* oldParent = 0; 52 CounterNode* oldParent = nullptr;
53 CounterNode* oldPreviousSibling = 0; 53 CounterNode* oldPreviousSibling = nullptr;
54 // Instead of calling removeChild() we do this safely as the tree is lik ely broken if we get here. 54 // Instead of calling removeChild() we do this safely as the tree is lik ely broken if we get here.
55 if (m_parent) { 55 if (m_parent) {
56 if (m_parent->m_firstChild == this) 56 if (m_parent->m_firstChild == this)
57 m_parent->m_firstChild = m_nextSibling; 57 m_parent->m_firstChild = m_nextSibling;
58 if (m_parent->m_lastChild == this) 58 if (m_parent->m_lastChild == this)
59 m_parent->m_lastChild = m_previousSibling; 59 m_parent->m_lastChild = m_previousSibling;
60 oldParent = m_parent; 60 oldParent = m_parent;
61 m_parent = 0; 61 m_parent = nullptr;
62 } 62 }
63 if (m_previousSibling) { 63 if (m_previousSibling) {
64 if (m_previousSibling->m_nextSibling == this) 64 if (m_previousSibling->m_nextSibling == this)
65 m_previousSibling->m_nextSibling = m_nextSibling; 65 m_previousSibling->m_nextSibling = m_nextSibling;
66 oldPreviousSibling = m_previousSibling; 66 oldPreviousSibling = m_previousSibling;
67 m_previousSibling = 0; 67 m_previousSibling = nullptr;
68 } 68 }
69 if (m_nextSibling) { 69 if (m_nextSibling) {
70 if (m_nextSibling->m_previousSibling == this) 70 if (m_nextSibling->m_previousSibling == this)
71 m_nextSibling->m_previousSibling = oldPreviousSibling; 71 m_nextSibling->m_previousSibling = oldPreviousSibling;
72 m_nextSibling = 0; 72 m_nextSibling = nullptr;
73 } 73 }
74 if (m_firstChild) { 74 if (m_firstChild) {
75 // The node's children are reparented to the old parent. 75 // The node's children are reparented to the old parent.
76 for (CounterNode* child = m_firstChild; child; ) { 76 for (CounterNode* child = m_firstChild; child; ) {
77 CounterNode* nextChild = child->m_nextSibling; 77 CounterNode* nextChild = child->m_nextSibling;
78 CounterNode* nextSibling = 0; 78 CounterNode* nextSibling = nullptr;
79 child->m_parent = oldParent; 79 child->m_parent = oldParent;
80 if (oldPreviousSibling) { 80 if (oldPreviousSibling) {
81 nextSibling = oldPreviousSibling->m_nextSibling; 81 nextSibling = oldPreviousSibling->m_nextSibling;
82 child->m_previousSibling = oldPreviousSibling; 82 child->m_previousSibling = oldPreviousSibling;
83 oldPreviousSibling->m_nextSibling = child; 83 oldPreviousSibling->m_nextSibling = child;
84 child->m_nextSibling = nextSibling; 84 child->m_nextSibling = nextSibling;
85 nextSibling->m_previousSibling = child; 85 nextSibling->m_previousSibling = child;
86 oldPreviousSibling = child; 86 oldPreviousSibling = child;
87 } 87 }
88 child = nextChild; 88 child = nextChild;
89 } 89 }
90 } 90 }
91 } 91 }
92 resetLayoutObjects(); 92 resetLayoutObjects();
93 } 93 }
94 94
95 PassRefPtr<CounterNode> CounterNode::create(LayoutObject& owner, bool hasResetTy pe, int value) 95 PassRefPtr<CounterNode> CounterNode::create(LayoutObject& owner, bool hasResetTy pe, int value)
96 { 96 {
97 return adoptRef(new CounterNode(owner, hasResetType, value)); 97 return adoptRef(new CounterNode(owner, hasResetType, value));
98 } 98 }
99 99
100 CounterNode* CounterNode::nextInPreOrderAfterChildren(const CounterNode* stayWit hin) const 100 CounterNode* CounterNode::nextInPreOrderAfterChildren(const CounterNode* stayWit hin) const
101 { 101 {
102 if (this == stayWithin) 102 if (this == stayWithin)
103 return 0; 103 return nullptr;
104 104
105 const CounterNode* current = this; 105 const CounterNode* current = this;
106 CounterNode* next = current->m_nextSibling; 106 CounterNode* next = current->m_nextSibling;
107 for (; !next; next = current->m_nextSibling) { 107 for (; !next; next = current->m_nextSibling) {
108 current = current->m_parent; 108 current = current->m_parent;
109 if (!current || current == stayWithin) 109 if (!current || current == stayWithin)
110 return 0; 110 return nullptr;
111 } 111 }
112 return next; 112 return next;
113 } 113 }
114 114
115 CounterNode* CounterNode::nextInPreOrder(const CounterNode* stayWithin) const 115 CounterNode* CounterNode::nextInPreOrder(const CounterNode* stayWithin) const
116 { 116 {
117 if (CounterNode* next = m_firstChild) 117 if (CounterNode* next = m_firstChild)
118 return next; 118 return next;
119 119
120 return nextInPreOrderAfterChildren(stayWithin); 120 return nextInPreOrderAfterChildren(stayWithin);
121 } 121 }
122 122
123 CounterNode* CounterNode::lastDescendant() const 123 CounterNode* CounterNode::lastDescendant() const
124 { 124 {
125 CounterNode* last = m_lastChild; 125 CounterNode* last = m_lastChild;
126 if (!last) 126 if (!last)
127 return 0; 127 return nullptr;
128 128
129 while (CounterNode* lastChild = last->m_lastChild) 129 while (CounterNode* lastChild = last->m_lastChild)
130 last = lastChild; 130 last = lastChild;
131 131
132 return last; 132 return last;
133 } 133 }
134 134
135 CounterNode* CounterNode::previousInPreOrder() const 135 CounterNode* CounterNode::previousInPreOrder() const
136 { 136 {
137 CounterNode* previous = m_previousSibling; 137 CounterNode* previous = m_previousSibling;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 void CounterNode::removeLayoutObject(LayoutCounter* value) 184 void CounterNode::removeLayoutObject(LayoutCounter* value)
185 { 185 {
186 if (!value) { 186 if (!value) {
187 ASSERT_NOT_REACHED(); 187 ASSERT_NOT_REACHED();
188 return; 188 return;
189 } 189 }
190 if (value->m_counterNode && value->m_counterNode != this) { 190 if (value->m_counterNode && value->m_counterNode != this) {
191 ASSERT_NOT_REACHED(); 191 ASSERT_NOT_REACHED();
192 value->m_counterNode->removeLayoutObject(value); 192 value->m_counterNode->removeLayoutObject(value);
193 } 193 }
194 LayoutCounter* previous = 0; 194 LayoutCounter* previous = nullptr;
195 for (LayoutCounter* iterator = m_rootLayoutObject; iterator; iterator = iter ator->m_nextForSameCounter) { 195 for (LayoutCounter* iterator = m_rootLayoutObject; iterator; iterator = iter ator->m_nextForSameCounter) {
196 if (iterator == value) { 196 if (iterator == value) {
197 if (previous) 197 if (previous)
198 previous->m_nextForSameCounter = value->m_nextForSameCounter; 198 previous->m_nextForSameCounter = value->m_nextForSameCounter;
199 else 199 else
200 m_rootLayoutObject = value->m_nextForSameCounter; 200 m_rootLayoutObject = value->m_nextForSameCounter;
201 value->m_nextForSameCounter = 0; 201 value->m_nextForSameCounter = nullptr;
202 value->m_counterNode = 0; 202 value->m_counterNode = nullptr;
203 return; 203 return;
204 } 204 }
205 previous = iterator; 205 previous = iterator;
206 } 206 }
207 ASSERT_NOT_REACHED(); 207 ASSERT_NOT_REACHED();
208 } 208 }
209 209
210 void CounterNode::resetLayoutObjects() 210 void CounterNode::resetLayoutObjects()
211 { 211 {
212 while (m_rootLayoutObject) 212 while (m_rootLayoutObject)
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 next->m_previousSibling = last; 308 next->m_previousSibling = last;
309 } else { 309 } else {
310 m_lastChild = last; 310 m_lastChild = last;
311 } 311 }
312 for (next = first; ; next = next->m_nextSibling) { 312 for (next = first; ; next = next->m_nextSibling) {
313 next->m_parent = this; 313 next->m_parent = this;
314 if (last == next) 314 if (last == next)
315 break; 315 break;
316 } 316 }
317 } 317 }
318 newChild->m_firstChild = 0; 318 newChild->m_firstChild = nullptr;
319 newChild->m_lastChild = 0; 319 newChild->m_lastChild = nullptr;
320 newChild->m_countInParent = newChild->computeCountInParent(); 320 newChild->m_countInParent = newChild->computeCountInParent();
321 newChild->resetLayoutObjects(); 321 newChild->resetLayoutObjects();
322 first->recount(); 322 first->recount();
323 } 323 }
324 324
325 void CounterNode::removeChild(CounterNode* oldChild) 325 void CounterNode::removeChild(CounterNode* oldChild)
326 { 326 {
327 ASSERT(oldChild); 327 ASSERT(oldChild);
328 ASSERT(!oldChild->m_firstChild); 328 ASSERT(!oldChild->m_firstChild);
329 ASSERT(!oldChild->m_lastChild); 329 ASSERT(!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 = 0; 334 oldChild->m_nextSibling = nullptr;
335 oldChild->m_previousSibling = 0; 335 oldChild->m_previousSibling = nullptr;
336 oldChild->m_parent = 0; 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 ASSERT(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;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 381
382 void showCounterTree(const blink::CounterNode* counter) 382 void showCounterTree(const blink::CounterNode* counter)
383 { 383 {
384 if (counter) 384 if (counter)
385 showTreeAndMark(counter); 385 showTreeAndMark(counter);
386 else 386 else
387 fprintf(stderr, "Cannot showCounterTree for (nil).\n"); 387 fprintf(stderr, "Cannot showCounterTree for (nil).\n");
388 } 388 }
389 389
390 #endif 390 #endif
OLDNEW
« no previous file with comments | « Source/core/layout/CounterNode.h ('k') | Source/core/layout/FloatingObjects.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698