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

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

Issue 2814603002: Move LayoutObject to satellite NodeLayoutData that hangs from a Node. (Closed)
Patch Set: Review's 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-2011, 2014 Apple Inc. All rights reserved. 5 * Copyright (C) 2004-2011, 2014 Apple Inc. All rights reserved.
6 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. 6 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved.
7 * (http://www.torchmobile.com/) 7 * (http://www.torchmobile.com/)
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 class Event; 50 class Event;
51 class ExceptionState; 51 class ExceptionState;
52 class GetRootNodeOptions; 52 class GetRootNodeOptions;
53 class HTMLQualifiedName; 53 class HTMLQualifiedName;
54 class HTMLSlotElement; 54 class HTMLSlotElement;
55 class IntRect; 55 class IntRect;
56 class EventDispatchHandlingState; 56 class EventDispatchHandlingState;
57 class NodeList; 57 class NodeList;
58 class NodeListsNodeData; 58 class NodeListsNodeData;
59 class NodeOrString; 59 class NodeOrString;
60 class NodeLayoutData;
60 class NodeRareData; 61 class NodeRareData;
61 class QualifiedName; 62 class QualifiedName;
62 class RegisteredEventListener; 63 class RegisteredEventListener;
63 class LayoutBox; 64 class LayoutBox;
64 class LayoutBoxModelObject; 65 class LayoutBoxModelObject;
65 class LayoutObject; 66 class LayoutObject;
66 class ComputedStyle; 67 class ComputedStyle;
67 class SVGQualifiedName; 68 class SVGQualifiedName;
68 class ShadowRoot; 69 class ShadowRoot;
69 template <typename NodeType> 70 template <typename NodeType>
(...skipping 21 matching lines...) Expand all
91 kFailed = 3 << kNodeCustomElementShift, 92 kFailed = 3 << kNodeCustomElementShift,
92 93
93 kNotDefinedFlag = 2 << kNodeCustomElementShift, 94 kNotDefinedFlag = 2 << kNodeCustomElementShift,
94 }; 95 };
95 96
96 enum class SlotChangeType { 97 enum class SlotChangeType {
97 kInitial, 98 kInitial,
98 kChained, 99 kChained,
99 }; 100 };
100 101
102 class NodeLayoutData {
103 public:
104 explicit NodeLayoutData(LayoutObject* layout_object)
105 : layout_object_(layout_object) {}
106 LayoutObject* GetLayoutObject() const { return layout_object_; }
107 void SetLayoutObject(LayoutObject* layout_object) {
108 DCHECK_NE(&SharedEmptyData(), this);
109 layout_object_ = layout_object;
110 }
111 static NodeLayoutData& SharedEmptyData() {
112 static NodeLayoutData& shared_empty_data_ = *new NodeLayoutData(nullptr);
esprehn 2017/04/13 18:41:08 DEFINE_STATIC_LOCAL(NodeLayoutData, shared_empty_d
nainar 2017/04/13 20:21:03 Done.
113 return shared_empty_data_;
114 }
115 bool IsSharedEmptyData() { return this == &SharedEmptyData(); }
116
117 private:
118 LayoutObject* layout_object_;
119 };
120
101 class NodeRareDataBase { 121 class NodeRareDataBase {
102 public: 122 public:
103 LayoutObject* GetLayoutObject() const { return layout_object_; } 123 NodeLayoutData* GetNodeLayoutData() const { return node_layout_data_; }
104 void SetLayoutObject(LayoutObject* layout_object) { 124 void SetNodeLayoutData(NodeLayoutData* node_layout_data) {
105 layout_object_ = layout_object; 125 DCHECK(node_layout_data);
126 node_layout_data_ = node_layout_data;
106 } 127 }
107 128
108 protected: 129 protected:
109 NodeRareDataBase(LayoutObject* layout_object) 130 NodeRareDataBase(NodeLayoutData* node_layout_data)
110 : layout_object_(layout_object) {} 131 : node_layout_data_(node_layout_data) {}
132 ~NodeRareDataBase() {
133 if (node_layout_data_ && !node_layout_data_->IsSharedEmptyData())
134 delete node_layout_data_;
135 }
111 136
112 protected: 137 protected:
113 // LayoutObjects are fully owned by their DOM node. See LayoutObject's 138 NodeLayoutData* node_layout_data_;
114 // LIFETIME documentation section.
115 LayoutObject* layout_object_;
116 }; 139 };
117 140
118 class Node; 141 class Node;
119 WILL_NOT_BE_EAGERLY_TRACED_CLASS(Node); 142 WILL_NOT_BE_EAGERLY_TRACED_CLASS(Node);
120 143
121 // This class represents a DOM node in the DOM tree. 144 // This class represents a DOM node in the DOM tree.
122 // https://dom.spec.whatwg.org/#interface-node 145 // https://dom.spec.whatwg.org/#interface-node
123 class CORE_EXPORT Node : public EventTarget { 146 class CORE_EXPORT Node : public EventTarget {
124 DEFINE_WRAPPERTYPEINFO(); 147 DEFINE_WRAPPERTYPEINFO();
125 friend class TreeScope; 148 friend class TreeScope;
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 virtual bool CanStartSelection() const; 584 virtual bool CanStartSelection() const;
562 585
563 // --------------------------------------------------------------------------- -- 586 // --------------------------------------------------------------------------- --
564 // Integration with layout tree 587 // Integration with layout tree
565 588
566 // As layoutObject() includes a branch you should avoid calling it repeatedly 589 // As layoutObject() includes a branch you should avoid calling it repeatedly
567 // in hot code paths. 590 // in hot code paths.
568 // Note that if a Node has a layoutObject, it's parentNode is guaranteed to 591 // Note that if a Node has a layoutObject, it's parentNode is guaranteed to
569 // have one as well. 592 // have one as well.
570 LayoutObject* GetLayoutObject() const { 593 LayoutObject* GetLayoutObject() const {
571 return HasRareData() ? data_.rare_data_->GetLayoutObject() 594 return HasRareData()
572 : data_.layout_object_; 595 ? data_.rare_data_->GetNodeLayoutData()->GetLayoutObject()
596 : data_.node_layout_data_->GetLayoutObject();
573 } 597 }
574 void SetLayoutObject(LayoutObject* layout_object) { 598 void SetLayoutObject(LayoutObject*);
575 if (HasRareData())
576 data_.rare_data_->SetLayoutObject(layout_object);
577 else
578 data_.layout_object_ = layout_object;
579 }
580
581 // Use these two methods with caution. 599 // Use these two methods with caution.
582 LayoutBox* GetLayoutBox() const; 600 LayoutBox* GetLayoutBox() const;
583 LayoutBoxModelObject* GetLayoutBoxModelObject() const; 601 LayoutBoxModelObject* GetLayoutBoxModelObject() const;
584 602
585 struct AttachContext { 603 struct AttachContext {
586 STACK_ALLOCATED(); 604 STACK_ALLOCATED();
587 ComputedStyle* resolved_style = nullptr; 605 ComputedStyle* resolved_style = nullptr;
588 bool performing_reattach = false; 606 bool performing_reattach = false;
589 bool clear_invalidation = false; 607 bool clear_invalidation = false;
590 608
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 const HeapHashSet<TraceWrapperMember<MutationObserverRegistration>>* 941 const HeapHashSet<TraceWrapperMember<MutationObserverRegistration>>*
924 TransientMutationObserverRegistry(); 942 TransientMutationObserverRegistry();
925 943
926 uint32_t node_flags_; 944 uint32_t node_flags_;
927 Member<ContainerNode> parent_or_shadow_host_node_; 945 Member<ContainerNode> parent_or_shadow_host_node_;
928 Member<TreeScope> tree_scope_; 946 Member<TreeScope> tree_scope_;
929 Member<Node> previous_; 947 Member<Node> previous_;
930 Member<Node> next_; 948 Member<Node> next_;
931 // When a node has rare data we move the layoutObject into the rare data. 949 // When a node has rare data we move the layoutObject into the rare data.
932 union DataUnion { 950 union DataUnion {
933 DataUnion() : layout_object_(nullptr) {} 951 DataUnion() : node_layout_data_(&NodeLayoutData::SharedEmptyData()) {}
934 // LayoutObjects are fully owned by their DOM node. See LayoutObject's 952 // LayoutObjects are fully owned by their DOM node. See LayoutObject's
935 // LIFETIME documentation section. 953 // LIFETIME documentation section.
936 LayoutObject* layout_object_; 954 NodeLayoutData* node_layout_data_;
937 NodeRareDataBase* rare_data_; 955 NodeRareDataBase* rare_data_;
938 } data_; 956 } data_;
939 }; 957 };
940 958
941 inline void Node::SetParentOrShadowHostNode(ContainerNode* parent) { 959 inline void Node::SetParentOrShadowHostNode(ContainerNode* parent) {
942 DCHECK(IsMainThread()); 960 DCHECK(IsMainThread());
943 parent_or_shadow_host_node_ = parent; 961 parent_or_shadow_host_node_ = parent;
944 ScriptWrappableVisitor::WriteBarrier( 962 ScriptWrappableVisitor::WriteBarrier(
945 this, reinterpret_cast<Node*>(parent_or_shadow_host_node_.Get())); 963 this, reinterpret_cast<Node*>(parent_or_shadow_host_node_.Get()));
946 } 964 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 } // namespace blink 1017 } // namespace blink
1000 1018
1001 #ifndef NDEBUG 1019 #ifndef NDEBUG
1002 // Outside the WebCore namespace for ease of invocation from gdb. 1020 // Outside the WebCore namespace for ease of invocation from gdb.
1003 void showNode(const blink::Node*); 1021 void showNode(const blink::Node*);
1004 void showTree(const blink::Node*); 1022 void showTree(const blink::Node*);
1005 void showNodePath(const blink::Node*); 1023 void showNodePath(const blink::Node*);
1006 #endif 1024 #endif
1007 1025
1008 #endif // Node_h 1026 #endif // Node_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698