Changeset 261028 in webkit
- Timestamp:
- May 1, 2020 3:16:19 PM (4 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r261025 r261028 1 2020-05-01 Daniel Bates <dabates@apple.com> 2 3 Change HitTestResult::NodeSet from set of RefPtrs to set of Refs 4 https://bugs.webkit.org/show_bug.cgi?id=211306 5 6 Reviewed by Simon Fraser. 7 8 HitTestResult::listBasedTestResult() never returns a set with nullptrs in it. 9 So, change the set declaration from ListHashSet<RefPtr<Node>> to ListHashSet<Ref<Node>>. 10 This way people are not tempted to unnecessarily null check the nodes in the set. 11 12 As I made this change to TreeScope::elementsFromPoint() I noticed that retargetToScope(), 13 which is called by it, returned a Node&. So, I changed it to return a Ref<Node>. That 14 required me to fix up caretRangeFromPoint(), which lead me to fix up nodeFromPoint() as well. 15 16 * dom/Document.cpp: 17 (WebCore::Document::caretRangeFromPoint): 18 * dom/EventPath.cpp: 19 (WebCore::RelatedNodeRetargeter::checkConsistency): 20 * dom/TreeScope.cpp: 21 (WebCore::TreeScope::retargetToScope const): 22 (WebCore::TreeScope::nodeFromPoint): 23 (WebCore::TreeScope::elementFromPoint): 24 (WebCore::TreeScope::elementsFromPoint): 25 * dom/TreeScope.h: 26 * page/Page.cpp: 27 (WebCore::Page::editableElementsInRect const): 28 * rendering/HitTestResult.cpp: 29 (WebCore::appendToNodeSet): 30 (WebCore::HitTestResult::HitTestResult): 31 (WebCore::HitTestResult::operator=): 32 (WebCore::HitTestResult::addNodeToListBasedTestResultCommon): 33 (WebCore::HitTestResult::append): 34 * rendering/HitTestResult.h: 35 * testing/Internals.cpp: 36 (WebCore::Internals::nodesFromRect const): 37 1 38 2020-05-01 Chris Dumez <cdumez@apple.com> 2 39 -
trunk/Source/WebCore/dom/Document.cpp
r261013 r261028 1513 1513 1514 1514 LayoutPoint localPoint; 1515 Node*node = nodeFromPoint(clientPoint, &localPoint);1515 auto node = nodeFromPoint(clientPoint, &localPoint); 1516 1516 if (!node) 1517 1517 return nullptr; 1518 1518 1519 RenderObject* renderer = node->renderer();1519 auto* renderer = node->renderer(); 1520 1520 if (!renderer) 1521 1521 return nullptr; 1522 PositionrangeCompliantPosition = renderer->positionForPoint(localPoint).parentAnchoredEquivalent();1522 auto rangeCompliantPosition = renderer->positionForPoint(localPoint).parentAnchoredEquivalent(); 1523 1523 if (rangeCompliantPosition.isNull()) 1524 1524 return nullptr; 1525 1525 1526 unsignedoffset = rangeCompliantPosition.offsetInContainerNode();1527 node = &retargetToScope(*rangeCompliantPosition.containerNode());1526 auto offset = rangeCompliantPosition.offsetInContainerNode(); 1527 node = retargetToScope(*rangeCompliantPosition.containerNode()); 1528 1528 if (node != rangeCompliantPosition.containerNode()) 1529 1529 offset = 0; 1530 1530 1531 return Range::create(*this, node , offset, node, offset);1531 return Range::create(*this, node.get(), offset, node.get(), offset); 1532 1532 } 1533 1533 -
trunk/Source/WebCore/dom/EventPath.cpp
r254087 r261028 452 452 return; 453 453 ASSERT(!currentTarget.isClosedShadowHidden(*m_retargetedRelatedNode)); 454 ASSERT(m_retargetedRelatedNode == ¤tTarget.treeScope().retargetToScope(m_relatedNode));454 ASSERT(m_retargetedRelatedNode == currentTarget.treeScope().retargetToScope(m_relatedNode).ptr()); 455 455 } 456 456 -
trunk/Source/WebCore/dom/TreeScope.cpp
r260707 r261028 181 181 182 182 183 Node&TreeScope::retargetToScope(Node& node) const183 Ref<Node> TreeScope::retargetToScope(Node& node) const 184 184 { 185 185 auto& scope = node.treeScope(); … … 197 197 ancestorScopes.append(currentScope); 198 198 199 size_ti = nodeTreeScopes.size();200 size_tj = ancestorScopes.size();199 auto i = nodeTreeScopes.size(); 200 auto j = ancestorScopes.size(); 201 201 while (i > 0 && j > 0 && nodeTreeScopes[i - 1] == ancestorScopes[j - 1]) { 202 202 --i; … … 208 208 return node; 209 209 210 ShadowRoot& shadowRootInLowestCommonTreeScope = downcast<ShadowRoot>(nodeTreeScopes[i - 1]->rootNode());210 auto& shadowRootInLowestCommonTreeScope = downcast<ShadowRoot>(nodeTreeScopes[i - 1]->rootNode()); 211 211 return *shadowRootInLowestCommonTreeScope.host(); 212 212 } … … 350 350 } 351 351 352 Node*TreeScope::nodeFromPoint(const LayoutPoint& clientPoint, LayoutPoint* localPoint)352 RefPtr<Node> TreeScope::nodeFromPoint(const LayoutPoint& clientPoint, LayoutPoint* localPoint) 353 353 { 354 354 auto absolutePoint = absolutePointIfNotClipped(documentScope(), clientPoint); … … 369 369 return nullptr; 370 370 371 Node* node = nodeFromPoint(LayoutPoint(clientX, clientY), nullptr);371 auto node = nodeFromPoint(LayoutPoint { clientX, clientY }, nullptr); 372 372 if (!node) 373 373 return nullptr; 374 374 375 node = &retargetToScope(*node);375 node = retargetToScope(*node); 376 376 while (!is<Element>(*node)) { 377 377 node = node->parentInComposedTree(); 378 378 if (!node) 379 379 break; 380 node = &retargetToScope(*node);381 } 382 383 return downcast<Element>(node);380 node = retargetToScope(*node); 381 } 382 383 return static_pointer_cast<Element>(node); 384 384 } 385 385 … … 400 400 documentScope().hitTest(hitType, result); 401 401 402 Node* lastNode = nullptr; 403 for (const auto& listBasedNode : result.listBasedTestResult()) { 404 Node* node = listBasedNode.get(); 405 node = &retargetToScope(*node); 406 while (!is<Element>(*node)) { 402 RefPtr<Node> lastNode; 403 auto& nodeSet = result.listBasedTestResult(); 404 elements.reserveInitialCapacity(nodeSet.size()); 405 for (auto& listBasedNode : nodeSet) { 406 RefPtr<Node> node = retargetToScope(listBasedNode); 407 while (!is<Element>(node)) { 407 408 node = node->parentInComposedTree(); 408 409 if (!node) 409 410 break; 410 node = &retargetToScope(*node);411 node = retargetToScope(*node); 411 412 } 412 413 … … 422 423 continue; 423 424 424 elements.append( downcast<Element>(node));425 elements.append(static_pointer_cast<Element>(node)); 425 426 lastNode = node; 426 427 } -
trunk/Source/WebCore/dom/TreeScope.h
r250708 r261028 77 77 78 78 // https://dom.spec.whatwg.org/#retarget 79 Node&retargetToScope(Node&) const;79 Ref<Node> retargetToScope(Node&) const; 80 80 81 81 WEBCORE_EXPORT Node* ancestorNodeInThisScope(Node*) const; … … 124 124 } 125 125 126 Node*nodeFromPoint(const LayoutPoint& clientPoint, LayoutPoint* localPoint);126 RefPtr<Node> nodeFromPoint(const LayoutPoint& clientPoint, LayoutPoint* localPoint); 127 127 128 128 private: -
trunk/Source/WebCore/page/Page.cpp
r261025 r261028 943 943 result.reserveInitialCapacity(nodeSet.size()); 944 944 for (auto& node : nodeSet) { 945 if (is<Element>(node) && isEditableTextInputElement(downcast<Element>( *node))) {946 ASSERT(searchRectInRootViewCoordinates.intersects(downcast<Element>( *node).clientRect()));947 result.uncheckedAppend( downcast<Element>(*node));945 if (is<Element>(node) && isEditableTextInputElement(downcast<Element>(node.get()))) { 946 ASSERT(searchRectInRootViewCoordinates.intersects(downcast<Element>(node.get()).clientRect())); 947 result.uncheckedAppend(static_reference_cast<Element>(node)); 948 948 } 949 949 } -
trunk/Source/WebCore/rendering/HitTestResult.cpp
r260725 r261028 55 55 using namespace HTMLNames; 56 56 57 static inline void appendToNodeSet(const HitTestResult::NodeSet& source, HitTestResult::NodeSet& destination) 58 { 59 for (auto& node : source) 60 destination.add(node.copyRef()); 61 } 62 57 63 HitTestResult::HitTestResult() = default; 58 64 … … 92 98 { 93 99 // Only copy the NodeSet in case of list hit test. 94 m_listBasedTestResult = other.m_listBasedTestResult ? makeUnique<NodeSet>(*other.m_listBasedTestResult) : nullptr; 100 if (other.m_listBasedTestResult) { 101 m_listBasedTestResult = makeUnique<NodeSet>(); 102 appendToNodeSet(*other.m_listBasedTestResult, *m_listBasedTestResult); 103 } 95 104 } 96 105 … … 109 118 110 119 // Only copy the NodeSet in case of list hit test. 111 m_listBasedTestResult = other.m_listBasedTestResult ? makeUnique<NodeSet>(*other.m_listBasedTestResult) : nullptr; 120 if (other.m_listBasedTestResult) { 121 m_listBasedTestResult = makeUnique<NodeSet>(); 122 appendToNodeSet(*other.m_listBasedTestResult, *m_listBasedTestResult); 123 } 112 124 113 125 return *this; … … 635 647 node = node->document().ancestorNodeInThisScope(node); 636 648 637 mutableListBasedTestResult().add( node);649 mutableListBasedTestResult().add(*node); 638 650 639 651 if (request.includesAllElementsUnderPoint()) … … 668 680 } 669 681 670 if (other.m_listBasedTestResult) { 671 NodeSet& set = mutableListBasedTestResult(); 672 for (const auto& node : *other.m_listBasedTestResult) 673 set.add(node.get()); 674 } 682 if (other.m_listBasedTestResult) 683 appendToNodeSet(*other.m_listBasedTestResult, mutableListBasedTestResult()); 675 684 } 676 685 -
trunk/Source/WebCore/rendering/HitTestResult.h
r258468 r261028 41 41 WTF_MAKE_FAST_ALLOCATED; 42 42 public: 43 using NodeSet = ListHashSet<Ref Ptr<Node>>;43 using NodeSet = ListHashSet<Ref<Node>>; 44 44 45 45 WEBCORE_EXPORT HitTestResult(); -
trunk/Source/WebCore/testing/Internals.cpp
r260848 r261028 2228 2228 HitTestResult result(point, topPadding, rightPadding, bottomPadding, leftPadding); 2229 2229 document.hitTest(request, result); 2230 const HitTestResult::NodeSet& nodeSet = result.listBasedTestResult(); 2231 Vector<Ref<Node>> matches; 2232 matches.reserveInitialCapacity(nodeSet.size()); 2233 for (auto& node : nodeSet) 2234 matches.uncheckedAppend(*node); 2235 2230 auto matches = WTF::map(result.listBasedTestResult(), [](const auto& node) { return node.copyRef(); }); 2236 2231 return RefPtr<NodeList> { StaticNodeList::create(WTFMove(matches)) }; 2237 2232 }
Note: See TracChangeset
for help on using the changeset viewer.