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

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: esprehn comments 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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 previous_(nullptr), 288 previous_(nullptr),
289 next_(nullptr) { 289 next_(nullptr) {
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 if (!HasRareData() && !data_.node_layout_data_->IsSharedEmptyData())
299 // this condition (we cannot directly access it here.) 299 delete data_.node_layout_data_;
300 CHECK(HasRareData() || !GetLayoutObject());
301 InstanceCounters::DecrementNodeCounter(); 300 InstanceCounters::DecrementNodeCounter();
302 } 301 }
303 302
304 NodeRareData* Node::RareData() const { 303 NodeRareData* Node::RareData() const {
305 SECURITY_DCHECK(HasRareData()); 304 SECURITY_DCHECK(HasRareData());
306 return static_cast<NodeRareData*>(data_.rare_data_); 305 return static_cast<NodeRareData*>(data_.rare_data_);
307 } 306 }
308 307
309 NodeRareData& Node::EnsureRareData() { 308 NodeRareData& Node::EnsureRareData() {
310 if (HasRareData()) 309 if (HasRareData())
311 return *RareData(); 310 return *RareData();
312 311
313 if (IsElementNode()) 312 if (IsElementNode())
314 data_.rare_data_ = ElementRareData::Create(data_.layout_object_); 313 data_.rare_data_ = ElementRareData::Create(data_.node_layout_data_);
315 else 314 else
316 data_.rare_data_ = NodeRareData::Create(data_.layout_object_); 315 data_.rare_data_ = NodeRareData::Create(data_.node_layout_data_);
317 316
318 DCHECK(data_.rare_data_); 317 DCHECK(data_.rare_data_);
319 SetFlag(kHasRareDataFlag); 318 SetFlag(kHasRareDataFlag);
320 ScriptWrappableVisitor::WriteBarrier(this, RareData()); 319 ScriptWrappableVisitor::WriteBarrier(this, RareData());
321 return *RareData(); 320 return *RareData();
322 } 321 }
323 322
324 Node* Node::ToNode() { 323 Node* Node::ToNode() {
325 return this; 324 return this;
326 } 325 }
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 node = NodeTraversal::NextPostOrder(*node); 581 node = NodeTraversal::NextPostOrder(*node);
583 } 582 }
584 } 583 }
585 584
586 LayoutBox* Node::GetLayoutBox() const { 585 LayoutBox* Node::GetLayoutBox() const {
587 LayoutObject* layout_object = this->GetLayoutObject(); 586 LayoutObject* layout_object = this->GetLayoutObject();
588 return layout_object && layout_object->IsBox() ? ToLayoutBox(layout_object) 587 return layout_object && layout_object->IsBox() ? ToLayoutBox(layout_object)
589 : nullptr; 588 : nullptr;
590 } 589 }
591 590
591 void Node::SetLayoutObject(LayoutObject* layout_object) {
592 NodeLayoutData* node_layout_data = HasRareData()
593 ? data_.rare_data_->GetNodeLayoutData()
594 : data_.node_layout_data_;
595
596 // Already pointing to a non empty NodeLayoutData so just set the pointer to
597 // the new LayoutObject.
598 if (!node_layout_data->IsSharedEmptyData()) {
599 node_layout_data->SetLayoutObject(layout_object);
600 return;
601 }
602
603 if (!layout_object)
604 return;
605
606 // Swap the NodeLayoutData to point to a new NodeLayoutData instead of the
607 // static SharedEmptyData instance.
608 node_layout_data = new NodeLayoutData(layout_object);
609 if (HasRareData())
610 data_.rare_data_->SetNodeLayoutData(node_layout_data);
611 else
612 data_.node_layout_data_ = node_layout_data;
613 }
614
592 LayoutBoxModelObject* Node::GetLayoutBoxModelObject() const { 615 LayoutBoxModelObject* Node::GetLayoutBoxModelObject() const {
593 LayoutObject* layout_object = this->GetLayoutObject(); 616 LayoutObject* layout_object = this->GetLayoutObject();
594 return layout_object && layout_object->IsBoxModelObject() 617 return layout_object && layout_object->IsBoxModelObject()
595 ? ToLayoutBoxModelObject(layout_object) 618 ? ToLayoutBoxModelObject(layout_object)
596 : nullptr; 619 : nullptr;
597 } 620 }
598 621
599 LayoutRect Node::BoundingBox() const { 622 LayoutRect Node::BoundingBox() const {
600 if (GetLayoutObject()) 623 if (GetLayoutObject())
601 return LayoutRect(GetLayoutObject()->AbsoluteBoundingBoxRect()); 624 return LayoutRect(GetLayoutObject()->AbsoluteBoundingBoxRect());
(...skipping 1938 matching lines...) Expand 10 before | Expand all | Expand 10 after
2540 if (node) { 2563 if (node) {
2541 std::stringstream stream; 2564 std::stringstream stream;
2542 node->PrintNodePathTo(stream); 2565 node->PrintNodePathTo(stream);
2543 LOG(INFO) << stream.str(); 2566 LOG(INFO) << stream.str();
2544 } else { 2567 } else {
2545 LOG(INFO) << "Cannot showNodePath for <null>"; 2568 LOG(INFO) << "Cannot showNodePath for <null>";
2546 } 2569 }
2547 } 2570 }
2548 2571
2549 #endif 2572 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/Node.h ('k') | third_party/WebKit/Source/core/dom/NodeRareData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698