Bug 1701108 - Split this assertion up into three assertions that are easier to understand. r=masayuki

Differential Revision: https://phabricator.services.mozilla.com/D109825
This commit is contained in:
Markus Stange 2021-03-26 02:06:53 +00:00
parent 403199a321
commit 53b0e331c3
2 changed files with 29 additions and 9 deletions

View File

@ -217,6 +217,10 @@ class WidgetMouseEvent : public WidgetMouseEventBase,
mUseLegacyNonPrimaryDispatch(false),
mClickEventPrevented(false) {}
#ifdef DEBUG
void AssertContextMenuEventButtonConsistency() const;
#endif
public:
virtual WidgetMouseEvent* AsMouseEvent() override { return this; }
@ -237,15 +241,7 @@ class WidgetMouseEvent : public WidgetMouseEventBase,
}
#ifdef DEBUG
virtual ~WidgetMouseEvent() {
NS_WARNING_ASSERTION(
mMessage != eContextMenu ||
(mButton == ((mContextMenuTrigger == eNormal)
? MouseButton::eSecondary
: MouseButton::ePrimary) &&
(mContextMenuTrigger != eControlClick || IsControl())),
"Wrong button set to eContextMenu event?");
}
virtual ~WidgetMouseEvent() { AssertContextMenuEventButtonConsistency(); }
#endif
virtual WidgetEvent* Duplicate() const override {

View File

@ -651,6 +651,30 @@ bool WidgetMouseEvent::IsMiddleClickPasteEnabled() {
return Preferences::GetBool("middlemouse.paste", false);
}
#ifdef DEBUG
void WidgetMouseEvent::AssertContextMenuEventButtonConsistency() const {
if (mMessage != eContextMenu) {
return;
}
if (mContextMenuTrigger == eNormal) {
NS_WARNING_ASSERTION(mButton == MouseButton::eSecondary,
"eContextMenu events with eNormal trigger should use "
"secondary mouse button");
} else {
NS_WARNING_ASSERTION(mButton == MouseButton::ePrimary,
"eContextMenu events with non-eNormal trigger should "
"use primary mouse button");
}
if (mContextMenuTrigger == eControlClick) {
NS_WARNING_ASSERTION(IsControl(),
"eContextMenu events with eControlClick trigger "
"should return true from IsControl()");
}
}
#endif
/******************************************************************************
* mozilla::WidgetDragEvent (MouseEvents.h)
******************************************************************************/