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

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

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

Powered by Google App Engine
This is Rietveld 408576698