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