From 6da4b51b7bfe02280c921fa5eafc3706d3c60f82 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Mon, 30 Jul 2018 12:20:47 +0000 Subject: [PATCH] Bug 971462 - Hide event type from constructor of WidgetCommandEvent r=smaug The constructor of WidgetCommandEvent takes 2 nsAtom pointers. One is for specifying event type, the other is for specifying the command. The difference of these arguments are pretty unclear for other developers and the former argument is always nsGkAtoms::onAppCommand unless nullptr in C++ code. So, we can hide the former argument. Then, we should create another constructor for creating empty command event from constructor of dom::CommandEvent. Differential Revision: https://phabricator.services.mozilla.com/D2506 --HG-- extra : moz-landing-system : lando --- dom/events/CommandEvent.cpp | 3 +-- widget/MiscEvents.h | 21 +++++++++++++++++++++ widget/gtk/nsWindow.cpp | 4 ++-- widget/windows/KeyboardLayout.cpp | 13 +++++++------ widget/windows/WinMouseScrollHandler.cpp | 6 +++--- 5 files changed, 34 insertions(+), 13 deletions(-) diff --git a/dom/events/CommandEvent.cpp b/dom/events/CommandEvent.cpp index ddad7ed9a3b0..8742526aebeb 100644 --- a/dom/events/CommandEvent.cpp +++ b/dom/events/CommandEvent.cpp @@ -15,8 +15,7 @@ CommandEvent::CommandEvent(EventTarget* aOwner, nsPresContext* aPresContext, WidgetCommandEvent* aEvent) : Event(aOwner, aPresContext, - aEvent ? aEvent : - new WidgetCommandEvent(false, nullptr, nullptr, nullptr)) + aEvent ? aEvent : new WidgetCommandEvent()) { mEvent->mTime = PR_Now(); if (aEvent) { diff --git a/widget/MiscEvents.h b/widget/MiscEvents.h index 7a7fc8349701..7817492c01b2 100644 --- a/widget/MiscEvents.h +++ b/widget/MiscEvents.h @@ -11,6 +11,7 @@ #include "mozilla/BasicEvents.h" #include "nsCOMPtr.h" #include "nsAtom.h" +#include "nsGkAtoms.h" #include "nsITransferable.h" namespace mozilla { @@ -106,6 +107,7 @@ class WidgetCommandEvent : public WidgetGUIEvent public: virtual WidgetCommandEvent* AsCommandEvent() override { return this; } +protected: WidgetCommandEvent(bool aIsTrusted, nsAtom* aEventType, nsAtom* aCommand, nsIWidget* aWidget) : WidgetGUIEvent(aIsTrusted, eUnidentifiedEvent, aWidget, @@ -115,6 +117,25 @@ public: mSpecifiedEventType = aEventType; } +public: + /** + * Constructor to initialize an app command. This is the only case to + * initialize this class as a command in C++ stack. + */ + WidgetCommandEvent(bool aIsTrusted, nsAtom* aCommand, nsIWidget* aWidget) + : WidgetCommandEvent(aIsTrusted, nsGkAtoms::onAppCommand, + aCommand, aWidget) + { + } + + /** + * Constructor to initialize as internal event of dom::CommandEvent. + */ + WidgetCommandEvent() + : WidgetCommandEvent(false, nullptr, nullptr, nullptr) + { + } + virtual WidgetEvent* Duplicate() const override { MOZ_ASSERT(mClass == eCommandEventClass, diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp index cf8b9f9f0fc3..416db73a7401 100644 --- a/widget/gtk/nsWindow.cpp +++ b/widget/gtk/nsWindow.cpp @@ -2933,8 +2933,8 @@ bool nsWindow::DispatchCommandEvent(nsAtom* aCommand) { nsEventStatus status; - WidgetCommandEvent event(true, nsGkAtoms::onAppCommand, aCommand, this); - DispatchEvent(&event, status); + WidgetCommandEvent appCommandEvent(true, aCommand, this); + DispatchEvent(&appCommandEvent, status); return TRUE; } diff --git a/widget/windows/KeyboardLayout.cpp b/widget/windows/KeyboardLayout.cpp index 69e90feb289a..efe869113e4b 100644 --- a/widget/windows/KeyboardLayout.cpp +++ b/widget/windows/KeyboardLayout.cpp @@ -2146,16 +2146,17 @@ NativeKey::DispatchCommandEvent(uint32_t aEventCommand) const "event", this)); return false; } - WidgetCommandEvent commandEvent(true, nsGkAtoms::onAppCommand, - command, mWidget); + WidgetCommandEvent appCommandEvent(true, command, mWidget); - mWidget->InitEvent(commandEvent); + mWidget->InitEvent(appCommandEvent); MOZ_LOG(sNativeKeyLogger, LogLevel::Info, - ("%p NativeKey::DispatchCommandEvent(), dispatching %s command event...", + ("%p NativeKey::DispatchCommandEvent(), dispatching " + "%s app command event...", this, nsAtomCString(command).get())); - bool ok = mWidget->DispatchWindowEvent(&commandEvent) || mWidget->Destroyed(); + bool ok = + mWidget->DispatchWindowEvent(&appCommandEvent) || mWidget->Destroyed(); MOZ_LOG(sNativeKeyLogger, LogLevel::Info, - ("%p NativeKey::DispatchCommandEvent(), dispatched command event, " + ("%p NativeKey::DispatchCommandEvent(), dispatched app command event, " "result=%s, mWidget->Destroyed()=%s", this, GetBoolName(ok), GetBoolName(mWidget->Destroyed()))); return ok; diff --git a/widget/windows/WinMouseScrollHandler.cpp b/widget/windows/WinMouseScrollHandler.cpp index 104756e261e8..13b29fb03ec8 100644 --- a/widget/windows/WinMouseScrollHandler.cpp +++ b/widget/windows/WinMouseScrollHandler.cpp @@ -1415,10 +1415,10 @@ MouseScrollHandler::Device::Elantech::HandleKeyMessage(nsWindowBase* aWidget, "%s command event", aWParam == VK_NEXT ? "Forward" : "Back")); - WidgetCommandEvent commandEvent(true, nsGkAtoms::onAppCommand, + WidgetCommandEvent appCommandEvent(true, (aWParam == VK_NEXT) ? nsGkAtoms::Forward : nsGkAtoms::Back, aWidget); - InitEvent(aWidget, commandEvent); - aWidget->DispatchWindowEvent(&commandEvent); + InitEvent(aWidget, appCommandEvent); + aWidget->DispatchWindowEvent(&appCommandEvent); } else { MOZ_LOG(gMouseScrollLog, LogLevel::Info,