MockHitTester.cpp (2965B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "MockHitTester.h" 8 #include "TreeTraversal.h" 9 #include "apz/src/APZCTreeManager.h" 10 #include "apz/src/AsyncPanZoomController.h" 11 #include "mozilla/gfx/CompositorHitTestInfo.h" 12 #include "mozilla/layers/ScrollableLayerGuid.h" 13 14 namespace mozilla::layers { 15 16 IAPZHitTester::HitTestResult MockHitTester::GetAPZCAtPoint( 17 const ScreenPoint& aHitTestPoint, 18 const RecursiveMutexAutoLock& aProofOfTreeLock) { 19 MOZ_ASSERT(!mQueuedResults.empty()); 20 HitTestResult result = std::move(mQueuedResults.front()); 21 mQueuedResults.pop(); 22 return result; 23 } 24 25 void MockHitTester::QueueHitResult(ScrollableLayerGuid aGuid, 26 gfx::CompositorHitTestInfo aHitInfo) { 27 RefPtr<HitTestingTreeNode> node = 28 GetTargetNode(aGuid, ScrollableLayerGuid::EqualsIgnoringPresShell); 29 MOZ_ASSERT(node); 30 AsyncPanZoomController* apzc = node->GetApzc(); 31 MOZ_ASSERT(apzc); 32 HitTestResult result; 33 result.mTargetApzc = apzc; 34 result.mHitResult = aHitInfo; 35 result.mLayersId = aGuid.mLayersId; 36 mQueuedResults.push(std::move(result)); 37 } 38 39 void MockHitTester::QueueScrollbarThumbHitResult( 40 ScrollableLayerGuid::ViewID aScrollId, ScrollDirection aDirection) { 41 RecursiveMutexAutoLock lock(GetTreeLock()); 42 LayersId layersId = GetRootLayersId(); // currently this is all the tests use 43 // First find the scrolalble node, to get the APZC. 44 RefPtr<HitTestingTreeNode> scrollableNode = 45 GetTargetNode(ScrollableLayerGuid(layersId, 0, aScrollId), 46 ScrollableLayerGuid::EqualsIgnoringPresShell); 47 MOZ_ASSERT(scrollableNode); 48 AsyncPanZoomController* apzc = scrollableNode->GetApzc(); 49 MOZ_ASSERT(apzc); 50 51 // Now find the scroll thumb node. 52 RefPtr<HitTestingTreeNode> scrollThumbNode = 53 BreadthFirstSearch<ReverseIterator>( 54 GetRootNode(), [&](HitTestingTreeNode* aNode) { 55 return aNode->GetLayersId() == layersId && 56 aNode->IsScrollThumbNode() && 57 aNode->GetScrollbarDirection() == aDirection && 58 aNode->GetScrollTargetId() == aScrollId; 59 }); 60 MOZ_ASSERT(scrollThumbNode); 61 62 HitTestResult result; 63 result.mTargetApzc = apzc; 64 result.mHitResult = {gfx::CompositorHitTestFlags::eVisibleToHitTest, 65 gfx::CompositorHitTestFlags::eScrollbarThumb}; 66 if (aDirection == ScrollDirection::eVertical) { 67 result.mHitResult += gfx::CompositorHitTestFlags::eScrollbarVertical; 68 } 69 InitializeHitTestingTreeNodeAutoLock(result.mScrollbarNode, lock, 70 scrollThumbNode); 71 mQueuedResults.push(std::move(result)); 72 } 73 74 } // namespace mozilla::layers