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

Side by Side Diff: third_party/WebKit/Source/core/dom/Node.cpp

Issue 2814603002: Move LayoutObject to satellite NodeLayoutData that hangs from a Node. (Closed)
Patch Set: Post lgtm review Created 3 years, 8 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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
6 * rights reserved. 6 * rights reserved.
7 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 7 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
8 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. 8 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved.
9 * (http://www.torchmobile.com/) 9 * (http://www.torchmobile.com/)
10 * 10 *
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 DCHECK(tree_scope_ || type == kCreateDocument || type == kCreateShadowRoot); 290 DCHECK(tree_scope_ || type == kCreateDocument || type == kCreateShadowRoot);
291 #if !defined(NDEBUG) || (defined(DUMP_NODE_STATISTICS) && DUMP_NODE_STATISTICS) 291 #if !defined(NDEBUG) || (defined(DUMP_NODE_STATISTICS) && DUMP_NODE_STATISTICS)
292 TrackForDebugging(); 292 TrackForDebugging();
293 #endif 293 #endif
294 InstanceCounters::IncrementNodeCounter(); 294 InstanceCounters::IncrementNodeCounter();
295 } 295 }
296 296
297 Node::~Node() { 297 Node::~Node() {
298 // With Oilpan, the rare data finalizer also asserts for 298 // With Oilpan, the rare data finalizer also asserts for
299 // this condition (we cannot directly access it here.) 299 // this condition (we cannot directly access it here.)
300 CHECK(HasRareData() || !GetLayoutObject()); 300 CHECK(HasRareData() || !GetLayoutObject());
esprehn 2017/04/13 22:02:49 You can remove this CHECK and the comment now, the
nainar 2017/04/13 22:28:16 Done.
301 if (!HasRareData() && !data_.node_layout_data_->IsSharedEmptyData())
302 delete data_.node_layout_data_;
301 InstanceCounters::DecrementNodeCounter(); 303 InstanceCounters::DecrementNodeCounter();
302 } 304 }
303 305
304 NodeRareData* Node::RareData() const { 306 NodeRareData* Node::RareData() const {
305 SECURITY_DCHECK(HasRareData()); 307 SECURITY_DCHECK(HasRareData());
306 return static_cast<NodeRareData*>(data_.rare_data_); 308 return static_cast<NodeRareData*>(data_.rare_data_);
307 } 309 }
308 310
309 NodeRareData& Node::EnsureRareData() { 311 NodeRareData& Node::EnsureRareData() {
310 if (HasRareData()) 312 if (HasRareData())
311 return *RareData(); 313 return *RareData();
312 314
313 if (IsElementNode()) 315 if (IsElementNode())
314 data_.rare_data_ = ElementRareData::Create(data_.layout_object_); 316 data_.rare_data_ = ElementRareData::Create(data_.node_layout_data_);
315 else 317 else
316 data_.rare_data_ = NodeRareData::Create(data_.layout_object_); 318 data_.rare_data_ = NodeRareData::Create(data_.node_layout_data_);
317 319
318 DCHECK(data_.rare_data_); 320 DCHECK(data_.rare_data_);
319 SetFlag(kHasRareDataFlag); 321 SetFlag(kHasRareDataFlag);
320 ScriptWrappableVisitor::WriteBarrier(this, RareData()); 322 ScriptWrappableVisitor::WriteBarrier(this, RareData());
321 return *RareData(); 323 return *RareData();
322 } 324 }
323 325
324 Node* Node::ToNode() { 326 Node* Node::ToNode() {
325 return this; 327 return this;
326 } 328 }
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 node = NodeTraversal::NextPostOrder(*node); 584 node = NodeTraversal::NextPostOrder(*node);
583 } 585 }
584 } 586 }
585 587
586 LayoutBox* Node::GetLayoutBox() const { 588 LayoutBox* Node::GetLayoutBox() const {
587 LayoutObject* layout_object = this->GetLayoutObject(); 589 LayoutObject* layout_object = this->GetLayoutObject();
588 return layout_object && layout_object->IsBox() ? ToLayoutBox(layout_object) 590 return layout_object && layout_object->IsBox() ? ToLayoutBox(layout_object)
589 : nullptr; 591 : nullptr;
590 } 592 }
591 593
594 void Node::SetLayoutObject(LayoutObject* layout_object) {
595 NodeLayoutData* node_layout_data = HasRareData()
596 ? data_.rare_data_->GetNodeLayoutData()
597 : data_.node_layout_data_;
598
599 // Already pointing to a non empty NodeLayoutData so just set the pointer to
600 // // the new LayoutObject.
esprehn 2017/04/13 22:02:49 extra //
nainar 2017/04/13 22:28:16 I can't even. git cl format broke this I guess. Do
601 if (!node_layout_data->IsSharedEmptyData()) {
602 node_layout_data->SetLayoutObject(layout_object);
603 return;
604 }
605
606 if (!layout_object)
607 return;
608
609 // Swap the NodeLayoutData to point to a new NodeLayoutData instead of the //
esprehn 2017/04/13 22:02:49 extra //
nainar 2017/04/13 22:28:16 Done.
610 // static SharedEmptyData instance.
611 node_layout_data = new NodeLayoutData(layout_object);
612 if (HasRareData())
613 data_.rare_data_->SetNodeLayoutData(node_layout_data);
614 else
615 data_.node_layout_data_ = node_layout_data;
616 }
617
592 LayoutBoxModelObject* Node::GetLayoutBoxModelObject() const { 618 LayoutBoxModelObject* Node::GetLayoutBoxModelObject() const {
593 LayoutObject* layout_object = this->GetLayoutObject(); 619 LayoutObject* layout_object = this->GetLayoutObject();
594 return layout_object && layout_object->IsBoxModelObject() 620 return layout_object && layout_object->IsBoxModelObject()
595 ? ToLayoutBoxModelObject(layout_object) 621 ? ToLayoutBoxModelObject(layout_object)
596 : nullptr; 622 : nullptr;
597 } 623 }
598 624
599 LayoutRect Node::BoundingBox() const { 625 LayoutRect Node::BoundingBox() const {
600 if (GetLayoutObject()) 626 if (GetLayoutObject())
601 return LayoutRect(GetLayoutObject()->AbsoluteBoundingBoxRect()); 627 return LayoutRect(GetLayoutObject()->AbsoluteBoundingBoxRect());
(...skipping 1938 matching lines...) Expand 10 before | Expand all | Expand 10 after
2540 if (node) { 2566 if (node) {
2541 std::stringstream stream; 2567 std::stringstream stream;
2542 node->PrintNodePathTo(stream); 2568 node->PrintNodePathTo(stream);
2543 LOG(INFO) << stream.str(); 2569 LOG(INFO) << stream.str();
2544 } else { 2570 } else {
2545 LOG(INFO) << "Cannot showNodePath for <null>"; 2571 LOG(INFO) << "Cannot showNodePath for <null>";
2546 } 2572 }
2547 } 2573 }
2548 2574
2549 #endif 2575 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698