Bug 1687263: part 4) Defer and in some cases avoid removing spellchecking-ranges...
[gecko.git] / layout / painting / HitTestInfo.cpp
blob7eab218e9fcaa406c5d28830566817cd707f76ac
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"
10 #include "nsIFrame.h"
12 namespace mozilla {
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 {
33 if (mScrollTarget) {
34 return *mScrollTarget;
37 Maybe<ViewID> fixedTarget = aBuilder.GetContainingFixedPosScrollTarget(aASR);
39 if (fixedTarget) {
40 return *fixedTarget;
43 if (aASR) {
44 return aASR->GetViewId();
47 return ScrollableLayerGuid::NULL_SCROLL_ID;
50 void HitTestInfo::Initialize(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame) {
51 if (!aBuilder->BuildCompositorHitTestInfo()) {
52 return;
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
66 // moves.
67 MOZ_ASSERT(Info().contains(CompositorHitTestFlags::eScrollbar));
68 mScrollTarget = Some(aBuilder->GetCurrentScrollbarTarget());
72 } // namespace mozilla