|
Lines 82-120
Ref<ScrollingStateNode> ScrollingStateTree::createNode(ScrollingNodeType nodeTyp
a/Source/WebCore/page/scrolling/ScrollingStateTree.cpp_sec1
|
| 82 |
return ScrollingStateFixedNode::create(*this, nodeID); |
82 |
return ScrollingStateFixedNode::create(*this, nodeID); |
| 83 |
} |
83 |
} |
| 84 |
|
84 |
|
| 85 |
bool ScrollingStateTree::nodeTypeAndParentMatch(ScrollingStateNode& node, ScrollingNodeType nodeType, ScrollingStateNode* parentNode) const |
85 |
bool ScrollingStateTree::nodeTypeAndParentMatch(ScrollingStateNode& node, ScrollingNodeType nodeType, ScrollingNodeID parentID) const |
| 86 |
{ |
86 |
{ |
| 87 |
if (node.nodeType() != nodeType) |
87 |
if (node.nodeType() != nodeType) |
| 88 |
return false; |
88 |
return false; |
| 89 |
|
89 |
|
| 90 |
return node.parent() == parentNode; |
90 |
auto* parent = stateNodeForID(parentID); |
|
|
91 |
if (!parent) |
| 92 |
return true; |
| 93 |
|
| 94 |
return node.parent() == parent; |
| 91 |
} |
95 |
} |
| 92 |
|
96 |
|
| 93 |
ScrollingNodeID ScrollingStateTree::attachNode(ScrollingNodeType nodeType, ScrollingNodeID newNodeID, ScrollingNodeID parentID, size_t childIndex) |
97 |
ScrollingNodeID ScrollingStateTree::attachNode(ScrollingNodeType nodeType, ScrollingNodeID newNodeID, ScrollingNodeID parentID) |
| 94 |
{ |
98 |
{ |
| 95 |
ASSERT(newNodeID); |
99 |
ASSERT(newNodeID); |
| 96 |
|
100 |
|
| 97 |
if (auto* node = stateNodeForID(newNodeID)) { |
101 |
if (auto* node = stateNodeForID(newNodeID)) { |
| 98 |
auto* parent = stateNodeForID(parentID); |
102 |
if (nodeTypeAndParentMatch(*node, nodeType, parentID)) |
| 99 |
if (nodeTypeAndParentMatch(*node, nodeType, parent)) { |
|
|
| 100 |
if (!parentID) |
| 101 |
return newNodeID; |
| 102 |
|
| 103 |
size_t currentIndex = parent->indexOfChild(*node); |
| 104 |
if (currentIndex == childIndex) |
| 105 |
return newNodeID; |
| 106 |
|
| 107 |
ASSERT(currentIndex != notFound); |
| 108 |
Ref<ScrollingStateNode> protectedNode(*node); |
| 109 |
parent->children()->remove(currentIndex); |
| 110 |
|
| 111 |
if (childIndex == notFound) |
| 112 |
parent->appendChild(WTFMove(protectedNode)); |
| 113 |
else |
| 114 |
parent->insertChild(WTFMove(protectedNode), childIndex); |
| 115 |
|
| 116 |
return newNodeID; |
103 |
return newNodeID; |
| 117 |
} |
|
|
| 118 |
|
104 |
|
| 119 |
#if ENABLE(ASYNC_SCROLLING) |
105 |
#if ENABLE(ASYNC_SCROLLING) |
| 120 |
// If the type has changed, we need to destroy and recreate the node with a new ID. |
106 |
// If the type has changed, we need to destroy and recreate the node with a new ID. |
|
Lines 128-134
ScrollingNodeID ScrollingStateTree::attachNode(ScrollingNodeType nodeType, Scrol
a/Source/WebCore/page/scrolling/ScrollingStateTree.cpp_sec2
|
| 128 |
|
114 |
|
| 129 |
ScrollingStateNode* newNode = nullptr; |
115 |
ScrollingStateNode* newNode = nullptr; |
| 130 |
if (!parentID) { |
116 |
if (!parentID) { |
| 131 |
ASSERT(!childIndex || childIndex == notFound); |
|
|
| 132 |
// If we're resetting the root node, we should clear the HashMap and destroy the current children. |
117 |
// If we're resetting the root node, we should clear the HashMap and destroy the current children. |
| 133 |
clear(); |
118 |
clear(); |
| 134 |
|
119 |
|
|
Lines 137-168
ScrollingNodeID ScrollingStateTree::attachNode(ScrollingNodeType nodeType, Scrol
a/Source/WebCore/page/scrolling/ScrollingStateTree.cpp_sec3
|
| 137 |
m_hasNewRootStateNode = true; |
122 |
m_hasNewRootStateNode = true; |
| 138 |
} else { |
123 |
} else { |
| 139 |
auto* parent = stateNodeForID(parentID); |
124 |
auto* parent = stateNodeForID(parentID); |
| 140 |
if (!parent) { |
125 |
if (!parent) |
| 141 |
ASSERT_NOT_REACHED(); |
|
|
| 142 |
return 0; |
126 |
return 0; |
| 143 |
} |
|
|
| 144 |
|
127 |
|
| 145 |
if (nodeType == SubframeScrollingNode && parentID) { |
128 |
if (nodeType == SubframeScrollingNode && parentID) { |
| 146 |
if (auto orphanedNode = m_orphanedSubframeNodes.take(newNodeID)) { |
129 |
if (auto orphanedNode = m_orphanedSubframeNodes.take(newNodeID)) { |
| 147 |
newNode = orphanedNode.get(); |
130 |
newNode = orphanedNode.get(); |
| 148 |
if (childIndex == notFound) |
131 |
parent->appendChild(orphanedNode.releaseNonNull()); |
| 149 |
parent->appendChild(orphanedNode.releaseNonNull()); |
|
|
| 150 |
else |
| 151 |
parent->insertChild(orphanedNode.releaseNonNull(), childIndex); |
| 152 |
} |
132 |
} |
| 153 |
} |
133 |
} |
| 154 |
|
134 |
|
| 155 |
if (!newNode) { |
135 |
if (!newNode) { |
| 156 |
auto stateNode = createNode(nodeType, newNodeID); |
136 |
auto stateNode = createNode(nodeType, newNodeID); |
| 157 |
newNode = stateNode.ptr(); |
137 |
newNode = stateNode.ptr(); |
| 158 |
if (childIndex == notFound) |
138 |
parent->appendChild(WTFMove(stateNode)); |
| 159 |
parent->appendChild(WTFMove(stateNode)); |
|
|
| 160 |
else |
| 161 |
parent->insertChild(WTFMove(stateNode), childIndex); |
| 162 |
} |
139 |
} |
| 163 |
} |
140 |
} |
| 164 |
|
141 |
|
| 165 |
addNode(*newNode); |
142 |
m_stateNodeMap.set(newNodeID, newNode); |
| 166 |
m_nodesRemovedSinceLastCommit.remove(newNodeID); |
143 |
m_nodesRemovedSinceLastCommit.remove(newNodeID); |
| 167 |
return newNodeID; |
144 |
return newNodeID; |
| 168 |
} |
145 |
} |