Skip to content

Commit 4476ce0

Browse files
committedMar 28, 2023
Bug 1824986 - Use element more in popup manager code. r=mstange
We know these are elements, take advantage of that. Depends on D173836 Differential Revision: https://phabricator.services.mozilla.com/D173837
1 parent 5f3509e commit 4476ce0

7 files changed

+119
-120
lines changed
 

‎layout/xul/nsMenuPopupFrame.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1710,7 +1710,7 @@ void nsMenuPopupFrame::PerformMove(const Rects& aRects) {
17101710
mUsedScreenRect = aRects.mUsedRect;
17111711
if (!HasAnyStateBits(NS_FRAME_FIRST_REFLOW) && !mPendingPositionedEvent) {
17121712
mPendingPositionedEvent =
1713-
nsXULPopupPositionedEvent::DispatchIfNeeded(mContent);
1713+
nsXULPopupPositionedEvent::DispatchIfNeeded(mContent->AsElement());
17141714
}
17151715
}
17161716

@@ -2411,7 +2411,7 @@ void nsMenuPopupFrame::CheckForAnchorChange(nsRect& aRect) {
24112411
if (pm) {
24122412
// As the caller will be iterating over the open popups, hide
24132413
// asyncronously.
2414-
pm->HidePopup(mContent,
2414+
pm->HidePopup(mContent->AsElement(),
24152415
{HidePopupOption::DeselectMenu, HidePopupOption::Async});
24162416
}
24172417

‎layout/xul/nsXULPopupManager.cpp

+72-84
Large diffs are not rendered by default.

‎layout/xul/nsXULPopupManager.h

+39-29
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class KeyboardEvent;
6464
class UIEvent;
6565
class XULButtonElement;
6666
class XULMenuBarElement;
67+
class XULPopupElement;
6768
} // namespace dom
6869
} // namespace mozilla
6970

@@ -189,10 +190,13 @@ extern const nsNavigationDirection DirectionFromKeyCodeTable[2][6];
189190

190191
// Used to hold information about a popup that is about to be opened.
191192
struct PendingPopup {
192-
PendingPopup(nsIContent* aPopup, mozilla::dom::Event* aEvent);
193+
using Element = mozilla::dom::Element;
194+
using Event = mozilla::dom::Event;
193195

194-
const RefPtr<nsIContent> mPopup;
195-
const RefPtr<mozilla::dom::Event> mEvent;
196+
PendingPopup(Element* aPopup, Event* aEvent);
197+
198+
const RefPtr<Element> mPopup;
199+
const RefPtr<Event> mEvent;
196200

197201
// Device pixels relative to the showing popup's presshell's
198202
// root prescontext's root frame.
@@ -252,7 +256,7 @@ class nsMenuChainItem {
252256

253257
MOZ_COUNTED_DTOR(nsMenuChainItem)
254258

255-
nsIContent* Content();
259+
mozilla::dom::XULPopupElement* Element();
256260
nsMenuPopupFrame* Frame() { return mFrame; }
257261
PopupType GetPopupType() { return mPopupType; }
258262
bool IsNoAutoHide() { return mNoAutoHide; }
@@ -279,10 +283,11 @@ class nsMenuChainItem {
279283
// this class is used for dispatching popuphiding events asynchronously.
280284
class nsXULPopupHidingEvent : public mozilla::Runnable {
281285
using PopupType = mozilla::widget::PopupType;
286+
using Element = mozilla::dom::Element;
282287

283288
public:
284-
nsXULPopupHidingEvent(nsIContent* aPopup, nsIContent* aNextPopup,
285-
nsIContent* aLastPopup, PopupType aPopupType,
289+
nsXULPopupHidingEvent(Element* aPopup, Element* aNextPopup,
290+
Element* aLastPopup, PopupType aPopupType,
286291
HidePopupOptions aOptions)
287292
: mozilla::Runnable("nsXULPopupHidingEvent"),
288293
mPopup(aPopup),
@@ -298,17 +303,19 @@ class nsXULPopupHidingEvent : public mozilla::Runnable {
298303
NS_IMETHOD Run() override;
299304

300305
private:
301-
nsCOMPtr<nsIContent> mPopup;
302-
nsCOMPtr<nsIContent> mNextPopup;
303-
nsCOMPtr<nsIContent> mLastPopup;
306+
nsCOMPtr<Element> mPopup;
307+
nsCOMPtr<Element> mNextPopup;
308+
nsCOMPtr<Element> mLastPopup;
304309
PopupType mPopupType;
305310
HidePopupOptions mOptions;
306311
};
307312

308313
// this class is used for dispatching popuppositioned events asynchronously.
309314
class nsXULPopupPositionedEvent : public mozilla::Runnable {
315+
using Element = mozilla::dom::Element;
316+
310317
public:
311-
explicit nsXULPopupPositionedEvent(nsIContent* aPopup)
318+
explicit nsXULPopupPositionedEvent(Element* aPopup)
312319
: mozilla::Runnable("nsXULPopupPositionedEvent"), mPopup(aPopup) {
313320
MOZ_ASSERT(aPopup);
314321
}
@@ -317,16 +324,18 @@ class nsXULPopupPositionedEvent : public mozilla::Runnable {
317324

318325
// Asynchronously dispatch a popuppositioned event at aPopup if this is a
319326
// panel that should receieve such events. Return true if the event was sent.
320-
static bool DispatchIfNeeded(nsIContent* aPopup);
327+
static bool DispatchIfNeeded(Element* aPopup);
321328

322329
private:
323-
const nsCOMPtr<nsIContent> mPopup;
330+
const nsCOMPtr<Element> mPopup;
324331
};
325332

326333
// this class is used for dispatching menu command events asynchronously.
327334
class nsXULMenuCommandEvent : public mozilla::Runnable {
335+
using Element = mozilla::dom::Element;
336+
328337
public:
329-
nsXULMenuCommandEvent(mozilla::dom::Element* aMenu, bool aIsTrusted,
338+
nsXULMenuCommandEvent(Element* aMenu, bool aIsTrusted,
330339
mozilla::Modifiers aModifiers, bool aUserInput,
331340
bool aFlipChecked, int16_t aButton)
332341
: mozilla::Runnable("nsXULMenuCommandEvent"),
@@ -348,7 +357,7 @@ class nsXULMenuCommandEvent : public mozilla::Runnable {
348357
}
349358

350359
private:
351-
RefPtr<mozilla::dom::Element> mMenu;
360+
RefPtr<Element> mMenu;
352361

353362
mozilla::Modifiers mModifiers;
354363
int16_t mButton;
@@ -369,6 +378,7 @@ class nsXULPopupManager final : public nsIDOMEventListener,
369378
friend class TransitionEnder;
370379

371380
using PopupType = mozilla::widget::PopupType;
381+
using Element = mozilla::dom::Element;
372382

373383
NS_DECL_ISUPPORTS
374384
NS_DECL_NSIOBSERVER
@@ -457,7 +467,7 @@ class nsXULPopupManager final : public nsIDOMEventListener,
457467
*
458468
* This fires the popupshowing event synchronously.
459469
*/
460-
void ShowPopup(nsIContent* aPopup, nsIContent* aAnchorContent,
470+
void ShowPopup(Element* aPopup, nsIContent* aAnchorContent,
461471
const nsAString& aPosition, int32_t aXPos, int32_t aYPos,
462472
bool aIsContextMenu, bool aAttributesOverride,
463473
bool aSelectFirstItem, mozilla::dom::Event* aTriggerEvent);
@@ -472,14 +482,14 @@ class nsXULPopupManager final : public nsIDOMEventListener,
472482
* offset from aXPos/aYPos to ensure that it is not under the mouse
473483
* cursor.
474484
*/
475-
void ShowPopupAtScreen(nsIContent* aPopup, int32_t aXPos, int32_t aYPos,
485+
void ShowPopupAtScreen(Element* aPopup, int32_t aXPos, int32_t aYPos,
476486
bool aIsContextMenu,
477487
mozilla::dom::Event* aTriggerEvent);
478488

479489
/* Open a popup anchored at a screen rectangle specified by aRect.
480490
* The remaining arguments are similar to ShowPopup.
481491
*/
482-
void ShowPopupAtScreenRect(nsIContent* aPopup, const nsAString& aPosition,
492+
void ShowPopupAtScreenRect(Element* aPopup, const nsAString& aPosition,
483493
const nsIntRect& aRect, bool aIsContextMenu,
484494
bool aAttributesOverride,
485495
mozilla::dom::Event* aTriggerEvent);
@@ -494,14 +504,14 @@ class nsXULPopupManager final : public nsIDOMEventListener,
494504
* TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230)
495505
*/
496506
MOZ_CAN_RUN_SCRIPT_BOUNDARY bool ShowPopupAsNativeMenu(
497-
nsIContent* aPopup, int32_t aXPos, int32_t aYPos, bool aIsContextMenu,
507+
Element* aPopup, int32_t aXPos, int32_t aYPos, bool aIsContextMenu,
498508
mozilla::dom::Event* aTriggerEvent);
499509

500510
/**
501511
* Open a tooltip at a specific screen position specified by aXPos and aYPos,
502512
* measured in device pixels. This fires the popupshowing event synchronously.
503513
*/
504-
void ShowTooltipAtScreen(nsIContent* aPopup, nsIContent* aTriggerContent,
514+
void ShowTooltipAtScreen(Element* aPopup, nsIContent* aTriggerContent,
505515
const mozilla::LayoutDeviceIntPoint&);
506516

507517
/*
@@ -510,8 +520,8 @@ class nsXULPopupManager final : public nsIDOMEventListener,
510520
* aLastPopup - optional popup to close last when hiding a chain of menus.
511521
* If null, then all popups will be closed.
512522
*/
513-
void HidePopup(nsIContent* aPopup, HidePopupOptions,
514-
nsIContent* aLastPopup = nullptr);
523+
void HidePopup(Element* aPopup, HidePopupOptions,
524+
Element* aLastPopup = nullptr);
515525

516526
/*
517527
* Hide the popup of a <menu>.
@@ -566,7 +576,7 @@ class nsXULPopupManager final : public nsIDOMEventListener,
566576
/**
567577
* Return true if the popup for the supplied content node is open.
568578
*/
569-
bool IsPopupOpen(nsIContent* aPopup);
579+
bool IsPopupOpen(Element* aPopup);
570580

571581
/**
572582
* Return the frame for the topmost open popup of a given type, or null if
@@ -642,7 +652,7 @@ class nsXULPopupManager final : public nsIDOMEventListener,
642652
* changes attributes on the children of aPopup, and deals only with the
643653
* content of the popup, not the frames.
644654
*/
645-
void UpdateMenuItems(nsIContent* aPopup);
655+
void UpdateMenuItems(Element* aPopup);
646656

647657
/**
648658
* Stop the timer which hides a popup after a delay, started by a previous
@@ -737,13 +747,13 @@ class nsXULPopupManager final : public nsIDOMEventListener,
737747
MOZ_CAN_RUN_SCRIPT void HideOpenMenusBeforeExecutingMenu(CloseMenuMode aMode);
738748

739749
// callbacks for ShowPopup and HidePopup as events may be done asynchronously
740-
MOZ_CAN_RUN_SCRIPT void ShowPopupCallback(nsIContent* aPopup,
750+
MOZ_CAN_RUN_SCRIPT void ShowPopupCallback(Element* aPopup,
741751
nsMenuPopupFrame* aPopupFrame,
742752
bool aIsContextMenu,
743753
bool aSelectFirstItem);
744754
MOZ_CAN_RUN_SCRIPT void HidePopupCallback(
745-
nsIContent* aPopup, nsMenuPopupFrame* aPopupFrame, nsIContent* aNextPopup,
746-
nsIContent* aLastPopup, PopupType aPopupType, HidePopupOptions);
755+
Element* aPopup, nsMenuPopupFrame* aPopupFrame, Element* aNextPopup,
756+
Element* aLastPopup, PopupType aPopupType, HidePopupOptions);
747757

748758
/**
749759
* Trigger frame construction and reflow in the popup, fire a popupshowing
@@ -779,8 +789,8 @@ class nsXULPopupManager final : public nsIDOMEventListener,
779789
* at.
780790
*/
781791
MOZ_CAN_RUN_SCRIPT_BOUNDARY
782-
void FirePopupHidingEvent(nsIContent* aPopup, nsIContent* aNextPopup,
783-
nsIContent* aLastPopup, nsPresContext* aPresContext,
792+
void FirePopupHidingEvent(Element* aPopup, Element* aNextPopup,
793+
Element* aLastPopup, nsPresContext* aPresContext,
784794
PopupType aPopupType, HidePopupOptions aOptions);
785795

786796
/**
@@ -843,7 +853,7 @@ class nsXULPopupManager final : public nsIDOMEventListener,
843853
nsIDocShellTreeItem* aExpected);
844854

845855
// Finds a chain item in mPopups.
846-
nsMenuChainItem* FindPopup(nsIContent* aPopup) const;
856+
nsMenuChainItem* FindPopup(Element* aPopup) const;
847857

848858
// the document the key event listener is attached to
849859
nsCOMPtr<mozilla::dom::EventTarget> mKeyListener;

‎layout/xul/nsXULTooltipListener.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ void nsXULTooltipListener::LaunchTooltip() {
472472
}
473473

474474
nsresult nsXULTooltipListener::HideTooltip() {
475-
if (nsCOMPtr<nsIContent> currentTooltip = do_QueryReferent(mCurrentTooltip)) {
475+
if (nsCOMPtr<Element> currentTooltip = do_QueryReferent(mCurrentTooltip)) {
476476
if (nsXULPopupManager* pm = nsXULPopupManager::GetInstance()) {
477477
pm->HidePopup(currentTooltip, {});
478478
}

‎view/nsView.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,8 @@ void nsView::DynamicToolbarOffsetChanged(ScreenIntCoord aOffset) {
10511051
bool nsView::RequestWindowClose(nsIWidget* aWidget) {
10521052
if (mFrame && IsPopupWidget(aWidget) && mFrame->IsMenuPopupFrame()) {
10531053
if (nsXULPopupManager* pm = nsXULPopupManager::GetInstance()) {
1054-
pm->HidePopup(mFrame->GetContent(), {HidePopupOption::DeselectMenu});
1054+
pm->HidePopup(mFrame->GetContent()->AsElement(),
1055+
{HidePopupOption::DeselectMenu});
10551056
return true;
10561057
}
10571058
}
@@ -1124,7 +1125,7 @@ void nsView::RequestRepaint() {
11241125
bool nsView::ShouldNotBeVisible() {
11251126
if (mFrame && mFrame->IsMenuPopupFrame()) {
11261127
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
1127-
return !pm || !pm->IsPopupOpen(mFrame->GetContent());
1128+
return !pm || !pm->IsPopupOpen(mFrame->GetContent()->AsElement());
11281129
}
11291130

11301131
return false;

‎widget/nsBaseDragService.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ nsresult nsBaseDragService::DrawDrag(nsINode* aDOMNode,
854854

855855
nsIFrame* frame = content->GetPrimaryFrame();
856856
if (frame && frame->IsMenuPopupFrame()) {
857-
mDragPopup = content;
857+
mDragPopup = content->AsElement();
858858
}
859859
}
860860

‎widget/nsBaseDragService.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class nsBaseDragService : public nsIDragService, public nsIDragSession {
191191

192192
// set if the image in mImage is a popup. If this case, the popup will be
193193
// opened and moved instead of using a drag image.
194-
nsCOMPtr<nsIContent> mDragPopup;
194+
nsCOMPtr<mozilla::dom::Element> mDragPopup;
195195

196196
// the screen position where drag gesture occurred, used for positioning the
197197
// drag image.

0 commit comments

Comments
 (0)
Failed to load comments.