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/. */
7 #include "HitTestInfo.h"
8 #include "mozilla/webrender/WebRenderAPI.h"
9 #include "nsDisplayList.h"
14 static const HitTestInfo
* gEmptyHitTestInfo
= nullptr;
16 const HitTestInfo
& HitTestInfo::Empty() {
17 if (gEmptyHitTestInfo
) {
18 gEmptyHitTestInfo
= new HitTestInfo();
21 return *gEmptyHitTestInfo
;
24 void HitTestInfo::Shutdown() {
25 delete gEmptyHitTestInfo
;
26 gEmptyHitTestInfo
= nullptr;
29 using ViewID
= layers::ScrollableLayerGuid::ViewID
;
31 ViewID
HitTestInfo::GetViewId(wr::DisplayListBuilder
& aBuilder
,
32 const ActiveScrolledRoot
* aASR
) const {
34 return *mScrollTarget
;
37 Maybe
<ViewID
> fixedTarget
= aBuilder
.GetContainingFixedPosScrollTarget(aASR
);
44 return aASR
->GetViewId();
47 return ScrollableLayerGuid::NULL_SCROLL_ID
;
50 void HitTestInfo::Initialize(nsDisplayListBuilder
* aBuilder
, nsIFrame
* aFrame
) {
51 if (!aBuilder
->BuildCompositorHitTestInfo()) {
55 mInfo
= aFrame
->GetCompositorHitTestInfo(aBuilder
);
56 if (mInfo
!= gfx::CompositorHitTestInvisibleToHit
) {
57 mArea
= aFrame
->GetCompositorHitTestArea(aBuilder
);
58 InitializeScrollTarget(aBuilder
);
62 void HitTestInfo::InitializeScrollTarget(nsDisplayListBuilder
* aBuilder
) {
63 if (aBuilder
->GetCurrentScrollbarDirection().isSome()) {
64 // In the case of scrollbar frames, we use the scrollbar's target
65 // scrollframe instead of the scrollframe with which the scrollbar actually
67 MOZ_ASSERT(Info().contains(CompositorHitTestFlags::eScrollbar
));
68 mScrollTarget
= Some(aBuilder
->GetCurrentScrollbarTarget());
72 } // namespace mozilla