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
This commit is contained in:
Masayuki Nakano 2018-07-30 12:20:47 +00:00
parent 11bdeb280a
commit 6da4b51b7b
5 changed files with 34 additions and 13 deletions

View file

@ -15,8 +15,7 @@ CommandEvent::CommandEvent(EventTarget* aOwner,
nsPresContext* aPresContext, nsPresContext* aPresContext,
WidgetCommandEvent* aEvent) WidgetCommandEvent* aEvent)
: Event(aOwner, aPresContext, : Event(aOwner, aPresContext,
aEvent ? aEvent : aEvent ? aEvent : new WidgetCommandEvent())
new WidgetCommandEvent(false, nullptr, nullptr, nullptr))
{ {
mEvent->mTime = PR_Now(); mEvent->mTime = PR_Now();
if (aEvent) { if (aEvent) {

View file

@ -11,6 +11,7 @@
#include "mozilla/BasicEvents.h" #include "mozilla/BasicEvents.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsAtom.h" #include "nsAtom.h"
#include "nsGkAtoms.h"
#include "nsITransferable.h" #include "nsITransferable.h"
namespace mozilla { namespace mozilla {
@ -106,6 +107,7 @@ class WidgetCommandEvent : public WidgetGUIEvent
public: public:
virtual WidgetCommandEvent* AsCommandEvent() override { return this; } virtual WidgetCommandEvent* AsCommandEvent() override { return this; }
protected:
WidgetCommandEvent(bool aIsTrusted, nsAtom* aEventType, WidgetCommandEvent(bool aIsTrusted, nsAtom* aEventType,
nsAtom* aCommand, nsIWidget* aWidget) nsAtom* aCommand, nsIWidget* aWidget)
: WidgetGUIEvent(aIsTrusted, eUnidentifiedEvent, aWidget, : WidgetGUIEvent(aIsTrusted, eUnidentifiedEvent, aWidget,
@ -115,6 +117,25 @@ public:
mSpecifiedEventType = aEventType; 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 virtual WidgetEvent* Duplicate() const override
{ {
MOZ_ASSERT(mClass == eCommandEventClass, MOZ_ASSERT(mClass == eCommandEventClass,

View file

@ -2933,8 +2933,8 @@ bool
nsWindow::DispatchCommandEvent(nsAtom* aCommand) nsWindow::DispatchCommandEvent(nsAtom* aCommand)
{ {
nsEventStatus status; nsEventStatus status;
WidgetCommandEvent event(true, nsGkAtoms::onAppCommand, aCommand, this); WidgetCommandEvent appCommandEvent(true, aCommand, this);
DispatchEvent(&event, status); DispatchEvent(&appCommandEvent, status);
return TRUE; return TRUE;
} }

View file

@ -2146,16 +2146,17 @@ NativeKey::DispatchCommandEvent(uint32_t aEventCommand) const
"event", this)); "event", this));
return false; return false;
} }
WidgetCommandEvent commandEvent(true, nsGkAtoms::onAppCommand, WidgetCommandEvent appCommandEvent(true, command, mWidget);
command, mWidget);
mWidget->InitEvent(commandEvent); mWidget->InitEvent(appCommandEvent);
MOZ_LOG(sNativeKeyLogger, LogLevel::Info, MOZ_LOG(sNativeKeyLogger, LogLevel::Info,
("%p NativeKey::DispatchCommandEvent(), dispatching %s command event...", ("%p NativeKey::DispatchCommandEvent(), dispatching "
"%s app command event...",
this, nsAtomCString(command).get())); this, nsAtomCString(command).get()));
bool ok = mWidget->DispatchWindowEvent(&commandEvent) || mWidget->Destroyed(); bool ok =
mWidget->DispatchWindowEvent(&appCommandEvent) || mWidget->Destroyed();
MOZ_LOG(sNativeKeyLogger, LogLevel::Info, MOZ_LOG(sNativeKeyLogger, LogLevel::Info,
("%p NativeKey::DispatchCommandEvent(), dispatched command event, " ("%p NativeKey::DispatchCommandEvent(), dispatched app command event, "
"result=%s, mWidget->Destroyed()=%s", "result=%s, mWidget->Destroyed()=%s",
this, GetBoolName(ok), GetBoolName(mWidget->Destroyed()))); this, GetBoolName(ok), GetBoolName(mWidget->Destroyed())));
return ok; return ok;

View file

@ -1415,10 +1415,10 @@ MouseScrollHandler::Device::Elantech::HandleKeyMessage(nsWindowBase* aWidget,
"%s command event", "%s command event",
aWParam == VK_NEXT ? "Forward" : "Back")); aWParam == VK_NEXT ? "Forward" : "Back"));
WidgetCommandEvent commandEvent(true, nsGkAtoms::onAppCommand, WidgetCommandEvent appCommandEvent(true,
(aWParam == VK_NEXT) ? nsGkAtoms::Forward : nsGkAtoms::Back, aWidget); (aWParam == VK_NEXT) ? nsGkAtoms::Forward : nsGkAtoms::Back, aWidget);
InitEvent(aWidget, commandEvent); InitEvent(aWidget, appCommandEvent);
aWidget->DispatchWindowEvent(&commandEvent); aWidget->DispatchWindowEvent(&appCommandEvent);
} }
else { else {
MOZ_LOG(gMouseScrollLog, LogLevel::Info, MOZ_LOG(gMouseScrollLog, LogLevel::Info,