void EventPath::retargetTouch(TouchEventContext::TouchListType touchListType, const Touch& touch) { EventTarget* eventTarget = touch.target(); if (!eventTarget) return; Node* targetNode = eventTarget->toNode(); if (!targetNode) return; RelatedNodeRetargeter retargeter(*targetNode, *m_path[0]->node()); TreeScope* previousTreeScope = nullptr; for (auto& context : m_path) { Node& currentTarget = *context->node(); TreeScope& currentTreeScope = currentTarget.treeScope(); if (UNLIKELY(previousTreeScope && ¤tTreeScope != previousTreeScope)) retargeter.moveToNewTreeScope(previousTreeScope, currentTreeScope); Node* currentRelatedNode = retargeter.currentNode(currentTarget); downcast<TouchEventContext>(*context).touchList(touchListType)->append(touch.cloneWithNewTarget(currentRelatedNode)); previousTreeScope = ¤tTreeScope; } }