HitTestInfo.cpp (2273B)
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 "HitTestInfo.h" 8 9 #include "mozilla/StaticPtr.h" 10 #include "mozilla/layers/ScrollableLayerGuid.h" 11 #include "mozilla/webrender/WebRenderAPI.h" 12 #include "nsDisplayList.h" 13 #include "nsIFrame.h" 14 15 using namespace mozilla::gfx; 16 17 namespace mozilla { 18 19 static StaticAutoPtr<const HitTestInfo> gEmptyHitTestInfo; 20 21 const HitTestInfo& HitTestInfo::Empty() { 22 if (!gEmptyHitTestInfo) { 23 gEmptyHitTestInfo = new HitTestInfo(); 24 } 25 26 return *gEmptyHitTestInfo; 27 } 28 29 void HitTestInfo::Shutdown() { gEmptyHitTestInfo = nullptr; } 30 31 using ViewID = layers::ScrollableLayerGuid::ViewID; 32 33 ViewID HitTestInfo::GetViewId(wr::DisplayListBuilder& aBuilder, 34 const ActiveScrolledRoot* aASR) const { 35 if (mScrollTarget) { 36 return *mScrollTarget; 37 } 38 39 Maybe<ViewID> fixedTarget = aBuilder.GetContainingFixedPosScrollTarget(aASR); 40 41 if (fixedTarget) { 42 return *fixedTarget; 43 } 44 45 // If the input ASR is non-null and we have a parent scroll ASR, return the 46 // view id from that ASR. 47 if (aASR) { 48 return aASR->GetNearestScrollASRViewId(); 49 } 50 51 return layers::ScrollableLayerGuid::NULL_SCROLL_ID; 52 } 53 54 void HitTestInfo::Initialize(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame) { 55 if (!aBuilder->BuildCompositorHitTestInfo()) { 56 return; 57 } 58 59 mInfo = aFrame->GetCompositorHitTestInfo(aBuilder); 60 if (mInfo != gfx::CompositorHitTestInvisibleToHit) { 61 mArea = aFrame->GetCompositorHitTestArea(aBuilder); 62 InitializeScrollTarget(aBuilder); 63 } 64 } 65 66 void HitTestInfo::InitializeScrollTarget(nsDisplayListBuilder* aBuilder) { 67 if (aBuilder->GetCurrentScrollbarDirection().isSome()) { 68 // In the case of scrollbar frames, we use the scrollbar's target 69 // scrollframe instead of the scrollframe with which the scrollbar actually 70 // moves. 71 MOZ_ASSERT(Info().contains(CompositorHitTestFlags::eScrollbar)); 72 mScrollTarget = Some(aBuilder->GetCurrentScrollbarTarget()); 73 } 74 } 75 76 } // namespace mozilla