Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit f3bcf4c

Browse files
Bug 1547418 - Make CapturingContentInfo a private struct of PresShell and move APIs for it from nsIPresShell to PresShell r=smaug
`CapturingContentInfo` struct is used only in `PresShell.cpp` so that we can make it a private struct of `PresShell` if we move all users of them, i.e., API to access them, from `nsIPresShell` to `PresShell`. Differential Revision: https://phabricator.services.mozilla.com/D29111 --HG-- extra : moz-landing-system : lando
1 parent 415f015 commit f3bcf4c

21 files changed

Lines changed: 108 additions & 104 deletions

dom/base/Document.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3676,7 +3676,7 @@ Element* Document::GetCurrentScript() {
36763676
void Document::ReleaseCapture() const {
36773677
// only release the capture if the caller can access it. This prevents a
36783678
// page from stopping a scrollbar grab for example.
3679-
nsCOMPtr<nsINode> node = nsIPresShell::GetCapturingContent();
3679+
nsCOMPtr<nsINode> node = PresShell::GetCapturingContent();
36803680
if (node && nsContentUtils::CanCallerAccess(node)) {
36813681
PresShell::ReleaseCapturingContent();
36823682
}

dom/base/Element.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ class Element : public FragmentOrElement {
11751175
// If there is already an active capture, ignore this request. This would
11761176
// occur if a splitter, frame resizer, etc had already captured and we don't
11771177
// want to override those.
1178-
if (!nsIPresShell::GetCapturingContent()) {
1178+
if (!PresShell::GetCapturingContent()) {
11791179
PresShell::SetCapturingContent(
11801180
this, CaptureFlags::PreventDragStart |
11811181
(aRetargetToElement ? CaptureFlags::RetargetToElement
@@ -1192,7 +1192,7 @@ class Element : public FragmentOrElement {
11921192
}
11931193

11941194
void ReleaseCapture() {
1195-
if (nsIPresShell::GetCapturingContent() == this) {
1195+
if (PresShell::GetCapturingContent() == this) {
11961196
PresShell::ReleaseCapturingContent();
11971197
}
11981198
}

dom/base/Selection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class nsAutoScrollTimer final : public nsITimerCallback, public nsINamed {
163163
// stopped by the selection if the prescontext is destroyed.
164164
mPresContext = aPresContext;
165165

166-
mContent = nsIPresShell::GetCapturingContent();
166+
mContent = PresShell::GetCapturingContent();
167167

168168
if (!mTimer) {
169169
mTimer = NS_NewTimer(

dom/base/nsGlobalWindowOuter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6336,7 +6336,7 @@ void nsGlobalWindowOuter::EnterModalState() {
63366336
// Usually the activeESM check above does that, but there are cases when
63376337
// we don't have activeESM, or it is for different document.
63386338
Document* topDoc = topWin->GetExtantDoc();
6339-
nsIContent* capturingContent = nsIPresShell::GetCapturingContent();
6339+
nsIContent* capturingContent = PresShell::GetCapturingContent();
63406340
if (capturingContent && topDoc &&
63416341
nsContentUtils::ContentIsCrossDocDescendantOf(capturingContent, topDoc)) {
63426342
PresShell::ReleaseCapturingContent();

dom/events/EventStateManager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,7 @@ void EventStateManager::GenerateDragGesture(nsPresContext* aPresContext,
17571757
}
17581758

17591759
// If non-native code is capturing the mouse don't start a drag.
1760-
if (nsIPresShell::IsMouseCapturePreventingDrag()) {
1760+
if (PresShell::IsMouseCapturePreventingDrag()) {
17611761
StopTrackingDragGesture();
17621762
return;
17631763
}
@@ -3035,7 +3035,7 @@ nsresult EventStateManager::PostHandleEvent(nsPresContext* aPresContext,
30353035
// mousemove/mouseup events will continue to be dispatched to this element
30363036
// and therefore forwarded to the child.
30373037
if (aEvent->HasBeenPostedToRemoteProcess() &&
3038-
!nsIPresShell::GetCapturingContent()) {
3038+
!PresShell::GetCapturingContent()) {
30393039
if (nsIContent* content =
30403040
mCurrentTarget ? mCurrentTarget->GetContent() : nullptr) {
30413041
PresShell::SetCapturingContent(content, CaptureFlags::None);
@@ -6290,7 +6290,7 @@ AutoHandlingUserInputStatePusher::~AutoHandlingUserInputStatePusher() {
62906290
}
62916291
EventStateManager::StopHandlingUserInput(mMessage);
62926292
if (mMessage == eMouseDown) {
6293-
nsIPresShell::AllowMouseCapture(false);
6293+
PresShell::AllowMouseCapture(false);
62946294
}
62956295
if (NeedsToResetFocusManagerMouseButtonHandlingState()) {
62966296
nsFocusManager* fm = nsFocusManager::GetFocusManager();

dom/html/HTMLInputElement.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3428,7 +3428,7 @@ void HTMLInputElement::StartRangeThumbDrag(WidgetGUIEvent* aEvent) {
34283428
void HTMLInputElement::FinishRangeThumbDrag(WidgetGUIEvent* aEvent) {
34293429
MOZ_ASSERT(mIsDraggingRange);
34303430

3431-
if (nsIPresShell::GetCapturingContent() == this) {
3431+
if (PresShell::GetCapturingContent() == this) {
34323432
PresShell::ReleaseCapturingContent();
34333433
}
34343434
if (aEvent) {
@@ -3443,7 +3443,7 @@ void HTMLInputElement::CancelRangeThumbDrag(bool aIsForUserEvent) {
34433443
MOZ_ASSERT(mIsDraggingRange);
34443444

34453445
mIsDraggingRange = false;
3446-
if (nsIPresShell::GetCapturingContent() == this) {
3446+
if (PresShell::GetCapturingContent() == this) {
34473447
PresShell::ReleaseCapturingContent();
34483448
}
34493449
if (aIsForUserEvent) {
@@ -3512,7 +3512,7 @@ void HTMLInputElement::StartNumberControlSpinnerSpin() {
35123512

35133513
void HTMLInputElement::StopNumberControlSpinnerSpin(SpinnerStopState aState) {
35143514
if (mNumberControlSpinnerIsSpinning) {
3515-
if (nsIPresShell::GetCapturingContent() == this) {
3515+
if (PresShell::GetCapturingContent() == this) {
35163516
PresShell::ReleaseCapturingContent();
35173517
}
35183518

@@ -4183,7 +4183,7 @@ void HTMLInputElement::PostHandleEventForRangeThumb(
41834183
if (mIsDraggingRange) {
41844184
break;
41854185
}
4186-
if (nsIPresShell::GetCapturingContent()) {
4186+
if (PresShell::GetCapturingContent()) {
41874187
break; // don't start drag if someone else is already capturing
41884188
}
41894189
WidgetInputEvent* inputEvent = aVisitor.mEvent->AsInputEvent();
@@ -4212,7 +4212,7 @@ void HTMLInputElement::PostHandleEventForRangeThumb(
42124212
if (!mIsDraggingRange) {
42134213
break;
42144214
}
4215-
if (nsIPresShell::GetCapturingContent() != this) {
4215+
if (PresShell::GetCapturingContent() != this) {
42164216
// Someone else grabbed capture.
42174217
CancelRangeThumbDrag();
42184218
break;

dom/plugins/base/nsPluginInstanceOwner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1809,7 +1809,7 @@ static NPCocoaEventType CocoaEventTypeForEvent(const WidgetGUIEvent& anEvent,
18091809
// We don't know via information on events from the widget code whether or
18101810
// not we're dragging. The widget code just generates mouse move events
18111811
// from native drag events. If anybody is capturing, this is a drag event.
1812-
if (nsIPresShell::GetCapturingContent()) {
1812+
if (PresShell::GetCapturingContent()) {
18131813
return NPCocoaEventMouseDragged;
18141814
}
18151815

layout/base/PresShell.cpp

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,7 @@ using namespace mozilla::layout;
212212
using PaintFrameFlags = nsLayoutUtils::PaintFrameFlags;
213213
typedef ScrollableLayerGuid::ViewID ViewID;
214214

215-
CapturingContentInfo nsIPresShell::gCaptureInfo = {
216-
false /* mAllowed */, false /* mPointerLock */,
217-
false /* mRetargetToElement */, false /* mPreventDrag */};
215+
PresShell::CapturingContentInfo PresShell::sCapturingContentInfo;
218216

219217
// RangePaintInfo is used to paint ranges to offscreen buffers
220218
struct RangePaintInfo {
@@ -2442,7 +2440,8 @@ void PresShell::MaybeReleaseCapturingContent() {
24422440
if (frameSelection) {
24432441
frameSelection->SetDragState(false);
24442442
}
2445-
if (gCaptureInfo.mContent && gCaptureInfo.mContent->OwnerDoc() == mDocument) {
2443+
if (sCapturingContentInfo.mContent &&
2444+
sCapturingContentInfo.mContent->OwnerDoc() == mDocument) {
24462445
PresShell::ReleaseCapturingContent();
24472446
}
24482447
}
@@ -3710,22 +3709,22 @@ void nsIPresShell::DispatchSynthMouseMove(WidgetGUIEvent* aEvent) {
37103709
}
37113710

37123711
void PresShell::ClearMouseCaptureOnView(nsView* aView) {
3713-
if (gCaptureInfo.mContent) {
3712+
if (sCapturingContentInfo.mContent) {
37143713
if (aView) {
37153714
// if a view was specified, ensure that the captured content is within
37163715
// this view.
3717-
nsIFrame* frame = gCaptureInfo.mContent->GetPrimaryFrame();
3716+
nsIFrame* frame = sCapturingContentInfo.mContent->GetPrimaryFrame();
37183717
if (frame) {
37193718
nsView* view = frame->GetClosestView();
37203719
// if there is no view, capturing won't be handled any more, so
37213720
// just release the capture.
37223721
if (view) {
37233722
do {
37243723
if (view == aView) {
3725-
gCaptureInfo.mContent = nullptr;
3724+
sCapturingContentInfo.mContent = nullptr;
37263725
// the view containing the captured content likely disappeared so
37273726
// disable capture for now.
3728-
gCaptureInfo.mAllowed = false;
3727+
sCapturingContentInfo.mAllowed = false;
37293728
break;
37303729
}
37313730

@@ -3737,38 +3736,38 @@ void PresShell::ClearMouseCaptureOnView(nsView* aView) {
37373736
}
37383737
}
37393738

3740-
gCaptureInfo.mContent = nullptr;
3739+
sCapturingContentInfo.mContent = nullptr;
37413740
}
37423741

37433742
// disable mouse capture until the next mousedown as a dialog has opened
37443743
// or a drag has started. Otherwise, someone could start capture during
37453744
// the modal dialog or drag.
3746-
gCaptureInfo.mAllowed = false;
3745+
sCapturingContentInfo.mAllowed = false;
37473746
}
37483747

3749-
void nsIPresShell::ClearMouseCapture(nsIFrame* aFrame) {
3750-
if (!gCaptureInfo.mContent) {
3751-
gCaptureInfo.mAllowed = false;
3748+
void PresShell::ClearMouseCapture(nsIFrame* aFrame) {
3749+
if (!sCapturingContentInfo.mContent) {
3750+
sCapturingContentInfo.mAllowed = false;
37523751
return;
37533752
}
37543753

37553754
// null frame argument means clear the capture
37563755
if (!aFrame) {
3757-
gCaptureInfo.mContent = nullptr;
3758-
gCaptureInfo.mAllowed = false;
3756+
sCapturingContentInfo.mContent = nullptr;
3757+
sCapturingContentInfo.mAllowed = false;
37593758
return;
37603759
}
37613760

3762-
nsIFrame* capturingFrame = gCaptureInfo.mContent->GetPrimaryFrame();
3761+
nsIFrame* capturingFrame = sCapturingContentInfo.mContent->GetPrimaryFrame();
37633762
if (!capturingFrame) {
3764-
gCaptureInfo.mContent = nullptr;
3765-
gCaptureInfo.mAllowed = false;
3763+
sCapturingContentInfo.mContent = nullptr;
3764+
sCapturingContentInfo.mAllowed = false;
37663765
return;
37673766
}
37683767

37693768
if (nsLayoutUtils::IsAncestorFrameCrossDoc(aFrame, capturingFrame)) {
3770-
gCaptureInfo.mContent = nullptr;
3771-
gCaptureInfo.mAllowed = false;
3769+
sCapturingContentInfo.mContent = nullptr;
3770+
sCapturingContentInfo.mAllowed = false;
37723771
}
37733772
}
37743773

@@ -6133,27 +6132,28 @@ void PresShell::Paint(nsView* aViewToPaint, const nsRegion& aDirtyRegion,
61336132
void PresShell::SetCapturingContent(nsIContent* aContent, CaptureFlags aFlags) {
61346133
// If capture was set for pointer lock, don't unlock unless we are coming
61356134
// out of pointer lock explicitly.
6136-
if (!aContent && gCaptureInfo.mPointerLock &&
6135+
if (!aContent && sCapturingContentInfo.mPointerLock &&
61376136
!(aFlags & CaptureFlags::PointerLock)) {
61386137
return;
61396138
}
61406139

6141-
gCaptureInfo.mContent = nullptr;
6140+
sCapturingContentInfo.mContent = nullptr;
61426141

61436142
// only set capturing content if allowed or the
61446143
// CaptureFlags::IgnoreAllowedState or CaptureFlags::PointerLock are used.
6145-
if ((aFlags & CaptureFlags::IgnoreAllowedState) || gCaptureInfo.mAllowed ||
6146-
(aFlags & CaptureFlags::PointerLock)) {
6144+
if ((aFlags & CaptureFlags::IgnoreAllowedState) ||
6145+
sCapturingContentInfo.mAllowed || (aFlags & CaptureFlags::PointerLock)) {
61476146
if (aContent) {
6148-
gCaptureInfo.mContent = aContent;
6147+
sCapturingContentInfo.mContent = aContent;
61496148
}
61506149
// CaptureFlags::PointerLock is the same as
61516150
// CaptureFlags::RetargetToElement & CaptureFlags::IgnoreAllowedState.
6152-
gCaptureInfo.mRetargetToElement =
6151+
sCapturingContentInfo.mRetargetToElement =
61536152
!!(aFlags & CaptureFlags::RetargetToElement) ||
61546153
!!(aFlags & CaptureFlags::PointerLock);
6155-
gCaptureInfo.mPreventDrag = !!(aFlags & CaptureFlags::PreventDragStart);
6156-
gCaptureInfo.mPointerLock = !!(aFlags & CaptureFlags::PointerLock);
6154+
sCapturingContentInfo.mPreventDrag =
6155+
!!(aFlags & CaptureFlags::PreventDragStart);
6156+
sCapturingContentInfo.mPointerLock = !!(aFlags & CaptureFlags::PointerLock);
61576157
}
61586158
}
61596159

@@ -6674,7 +6674,7 @@ nsresult PresShell::EventHandler::HandleEventUsingCoordinates(
66746674
// capture retargeting is being used, no frame was found or the frame's
66756675
// content is not a descendant of the capturing content.
66766676
if (capturingContent && !pointerCapturingContent &&
6677-
(gCaptureInfo.mRetargetToElement ||
6677+
(PresShell::sCapturingContentInfo.mRetargetToElement ||
66786678
!eventTargetData.mFrame->GetContent() ||
66796679
!nsContentUtils::ContentIsCrossDocDescendantOf(
66806680
eventTargetData.mFrame->GetContent(), capturingContent))) {
@@ -7013,7 +7013,7 @@ nsIContent* PresShell::EventHandler::GetCapturingContentFor(
70137013
return (aGUIEvent->mClass == ePointerEventClass ||
70147014
aGUIEvent->mClass == eWheelEventClass ||
70157015
aGUIEvent->HasMouseEventMessage())
7016-
? nsIPresShell::GetCapturingContent()
7016+
? PresShell::GetCapturingContent()
70177017
: nullptr;
70187018
}
70197019

@@ -7378,7 +7378,7 @@ PresShell::EventHandler::ComputeRootFrameToHandleEventWithCapturingContent(
73787378
return aRootFrameToHandleEvent;
73797379
}
73807380

7381-
if (gCaptureInfo.mRetargetToElement) {
7381+
if (PresShell::sCapturingContentInfo.mRetargetToElement) {
73827382
*aIsCaptureRetargeted = true;
73837383
return aRootFrameToHandleEvent;
73847384
}
@@ -7847,7 +7847,7 @@ bool PresShell::EventHandler::PrepareToDispatchEvent(
78477847
GetPresContext() &&
78487848
GetPresContext()->EventStateManager() ==
78497849
EventStateManager::GetActiveEventStateManager();
7850-
nsIPresShell::AllowMouseCapture(allowCapture);
7850+
PresShell::AllowMouseCapture(allowCapture);
78517851
*aIsUserInteraction = false;
78527852
return true;
78537853
}
@@ -7924,7 +7924,7 @@ void PresShell::EventHandler::FinalizeHandlingEvent(WidgetEvent* aEvent) {
79247924
PresShell::ReleaseCapturingContent();
79257925
return;
79267926
case eMouseMove:
7927-
nsIPresShell::AllowMouseCapture(false);
7927+
PresShell::AllowMouseCapture(false);
79287928
return;
79297929
case eDrag:
79307930
case eDragEnd:
@@ -8263,7 +8263,7 @@ void PresShell::EventHandler::DispatchTouchEventToDOM(
82638263
}
82648264

82658265
Document* doc = content->OwnerDoc();
8266-
nsIContent* capturingContent = nsIPresShell::GetCapturingContent();
8266+
nsIContent* capturingContent = PresShell::GetCapturingContent();
82678267
if (capturingContent) {
82688268
if (capturingContent->OwnerDoc() != doc) {
82698269
// Wrong document, don't dispatch anything.

layout/base/PresShell.h

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,34 @@ class PresShell final : public nsIPresShell,
7373

7474
static bool AccessibleCaretEnabled(nsIDocShell* aDocShell);
7575

76+
/**
77+
* Return the active content currently capturing the mouse if any.
78+
*/
79+
static nsIContent* GetCapturingContent() {
80+
return sCapturingContentInfo.mContent;
81+
}
82+
83+
/**
84+
* Allow or disallow mouse capturing.
85+
*/
86+
static void AllowMouseCapture(bool aAllowed) {
87+
sCapturingContentInfo.mAllowed = aAllowed;
88+
}
89+
90+
/**
91+
* Returns true if there is an active mouse capture that wants to prevent
92+
* drags.
93+
*/
94+
static bool IsMouseCapturePreventingDrag() {
95+
return sCapturingContentInfo.mPreventDrag && sCapturingContentInfo.mContent;
96+
}
97+
98+
static void ClearMouseCaptureOnView(nsView* aView);
99+
100+
// If a frame in the subtree rooted at aFrame is capturing the mouse then
101+
// clears that capture.
102+
static void ClearMouseCapture(nsIFrame* aFrame);
103+
76104
void Init(Document*, nsPresContext*, nsViewManager*);
77105
void Destroy() override;
78106

@@ -238,7 +266,6 @@ class PresShell final : public nsIPresShell,
238266
*/
239267
void ScheduleViewManagerFlush(PaintType aType = PaintType::Default);
240268

241-
void ClearMouseCaptureOnView(nsView* aView) override;
242269
bool IsVisible() override;
243270
void SuppressDisplayport(bool aEnabled) override;
244271
void RespectDisplayportSuppression(bool aEnabled) override;
@@ -1550,6 +1577,8 @@ class PresShell final : public nsIPresShell,
15501577
// details for the scroll operation, see ScrollIntoViewData above.
15511578
nsCOMPtr<nsIContent> mContentToScrollTo;
15521579

1580+
TimeStamp mLastOSWake;
1581+
15531582
// The focus sequence number of the last processed input event
15541583
uint64_t mAPZFocusSequenceNumber;
15551584
// The focus information needed for async keyboard scrolling
@@ -1597,9 +1626,23 @@ class PresShell final : public nsIPresShell,
15971626
// Whether mForceUseLegacyNonPrimaryDispatch is initialised.
15981627
bool mInitializedWithClickEventDispatchingBlacklist : 1;
15991628

1600-
static bool sDisableNonTestMouseEvents;
1629+
struct CapturingContentInfo final {
1630+
CapturingContentInfo()
1631+
: mAllowed(false),
1632+
mPointerLock(false),
1633+
mRetargetToElement(false),
1634+
mPreventDrag(false) {}
1635+
1636+
// capture should only be allowed during a mousedown event
1637+
StaticRefPtr<nsIContent> mContent;
1638+
bool mAllowed;
1639+
bool mPointerLock;
1640+
bool mRetargetToElement;
1641+
bool mPreventDrag;
1642+
};
1643+
static CapturingContentInfo sCapturingContentInfo;
16011644

1602-
TimeStamp mLastOSWake;
1645+
static bool sDisableNonTestMouseEvents;
16031646

16041647
static bool sProcessInteractable;
16051648
};

0 commit comments

Comments
 (0)