no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / layout / painting / HitTestInfo.cpp
blob872773c32f8ceee4af8c895329c618e22ed9e05d
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"
9 #include "mozilla/StaticPtr.h"
10 #include "mozilla/webrender/WebRenderAPI.h"
11 #include "nsDisplayList.h"
12 #include "nsIFrame.h"
13 #include "mozilla/layers/ScrollableLayerGuid.h"
15 using namespace mozilla::gfx;
17 namespace mozilla {
19 static StaticAutoPtr<const HitTestInfo> gEmptyHitTestInfo;
21 const HitTestInfo& HitTestInfo::Empty() {
22 if (!gEmptyHitTestInfo) {
23 gEmptyHitTestInfo = new HitTestInfo();
26 return *gEmptyHitTestInfo;
29 void HitTestInfo::Shutdown() { gEmptyHitTestInfo = nullptr; }
31 using ViewID = layers::ScrollableLayerGuid::ViewID;
33 ViewID HitTestInfo::GetViewId(wr::DisplayListBuilder& aBuilder,
34 const ActiveScrolledRoot* aASR) const {
35 if (mScrollTarget) {
36 return *mScrollTarget;
39 Maybe<ViewID> fixedTarget = aBuilder.GetContainingFixedPosScrollTarget(aASR);
41 if (fixedTarget) {
42 return *fixedTarget;
45 if (aASR) {
46 return aASR->GetViewId();
49 return layers::ScrollableLayerGuid::NULL_SCROLL_ID;
52 void HitTestInfo::Initialize(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame) {
53 if (!aBuilder->BuildCompositorHitTestInfo()) {
54 return;
57 mInfo = aFrame->GetCompositorHitTestInfo(aBuilder);
58 if (mInfo != gfx::CompositorHitTestInvisibleToHit) {
59 mArea = aFrame->GetCompositorHitTestArea(aBuilder);
60 InitializeScrollTarget(aBuilder);
64 void HitTestInfo::InitializeScrollTarget(nsDisplayListBuilder* aBuilder) {
65 if (aBuilder->GetCurrentScrollbarDirection().isSome()) {
66 // In the case of scrollbar frames, we use the scrollbar's target
67 // scrollframe instead of the scrollframe with which the scrollbar actually
68 // moves.
69 MOZ_ASSERT(Info().contains(CompositorHitTestFlags::eScrollbar));
70 mScrollTarget = Some(aBuilder->GetCurrentScrollbarTarget());
74 } // namespace mozilla