diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 3d3e9efd28cd..3026b19a776b 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -6715,8 +6715,12 @@ nsContentUtils::DispatchXULCommand(nsIContent* aTarget, RefPtr xulCommand = new XULCommandEvent(doc, presContext, nullptr); xulCommand->InitCommandEvent(NS_LITERAL_STRING("command"), true, true, - doc->GetInnerWindow(), 0, aCtrl, aAlt, aShift, - aMeta, aSourceEvent, aInputSource); + nsGlobalWindowInner::Cast(doc->GetInnerWindow()), + 0, aCtrl, aAlt, aShift, + aMeta, + aSourceEvent ? + aSourceEvent->InternalDOMEvent() : nullptr, + aInputSource, IgnoreErrors()); if (aShell) { nsEventStatus status = nsEventStatus_eIgnore; diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index f0f51f494f87..2f19444f5dc4 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -2113,7 +2113,7 @@ public: /** * This method creates and dispatches "command" event, which implements - * nsIDOMXULCommandEvent. + * XULCommandEvent. * If aShell is not null, dispatching goes via * nsIPresShell::HandleDOMEventWithTarget. */ diff --git a/dom/events/Event.h b/dom/events/Event.h index 7e1b09c1ca33..cb1bcc0e630d 100755 --- a/dom/events/Event.h +++ b/dom/events/Event.h @@ -39,6 +39,7 @@ class ExtendableEvent; class KeyboardEvent; class TimeEvent; class WantsPopupControlCheck; +class XULCommandEvent; #define GENERATED_EVENT(EventClass_) class EventClass_; #include "mozilla/dom/GeneratedEventList.h" #undef GENERATED_EVENT @@ -132,6 +133,12 @@ public: return nullptr; } + // XULCommandEvent has a non-autogeneratable initCommandEvent. + virtual XULCommandEvent* AsXULCommandEvent() + { + return nullptr; + } + // nsIDOMEvent Interface NS_DECL_NSIDOMEVENT diff --git a/dom/events/XULCommandEvent.cpp b/dom/events/XULCommandEvent.cpp index c86b3124d2f8..97b451f9a61f 100644 --- a/dom/events/XULCommandEvent.cpp +++ b/dom/events/XULCommandEvent.cpp @@ -33,7 +33,6 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED(XULCommandEvent, UIEvent, mSourceEvent) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(XULCommandEvent) - NS_INTERFACE_MAP_ENTRY(nsIDOMXULCommandEvent) NS_INTERFACE_MAP_END_INHERITING(UIEvent) bool @@ -42,103 +41,54 @@ XULCommandEvent::AltKey() return mEvent->AsInputEvent()->IsAlt(); } -NS_IMETHODIMP -XULCommandEvent::GetAltKey(bool* aIsDown) -{ - NS_ENSURE_ARG_POINTER(aIsDown); - *aIsDown = AltKey(); - return NS_OK; -} - bool XULCommandEvent::CtrlKey() { return mEvent->AsInputEvent()->IsControl(); } -NS_IMETHODIMP -XULCommandEvent::GetCtrlKey(bool* aIsDown) -{ - NS_ENSURE_ARG_POINTER(aIsDown); - *aIsDown = CtrlKey(); - return NS_OK; -} - bool XULCommandEvent::ShiftKey() { return mEvent->AsInputEvent()->IsShift(); } -NS_IMETHODIMP -XULCommandEvent::GetShiftKey(bool* aIsDown) -{ - NS_ENSURE_ARG_POINTER(aIsDown); - *aIsDown = ShiftKey(); - return NS_OK; -} - bool XULCommandEvent::MetaKey() { return mEvent->AsInputEvent()->IsMeta(); } -NS_IMETHODIMP -XULCommandEvent::GetMetaKey(bool* aIsDown) -{ - NS_ENSURE_ARG_POINTER(aIsDown); - *aIsDown = MetaKey(); - return NS_OK; -} - uint16_t XULCommandEvent::InputSource() { return mInputSource; } -NS_IMETHODIMP -XULCommandEvent::GetInputSource(uint16_t* aInputSource) -{ - NS_ENSURE_ARG_POINTER(aInputSource); - *aInputSource = InputSource(); - return NS_OK; -} - -NS_IMETHODIMP -XULCommandEvent::GetSourceEvent(nsIDOMEvent** aSourceEvent) -{ - NS_ENSURE_ARG_POINTER(aSourceEvent); - nsCOMPtr event = GetSourceEvent(); - event.forget(aSourceEvent); - return NS_OK; -} - -NS_IMETHODIMP +void XULCommandEvent::InitCommandEvent(const nsAString& aType, bool aCanBubble, bool aCancelable, - mozIDOMWindow* aView, + nsGlobalWindowInner* aView, int32_t aDetail, bool aCtrlKey, bool aAltKey, bool aShiftKey, bool aMetaKey, - nsIDOMEvent* aSourceEvent, - uint16_t aInputSource) + Event* aSourceEvent, + uint16_t aInputSource, + ErrorResult& aRv) { - NS_ENSURE_TRUE(!mEvent->mFlags.mIsBeingDispatched, NS_OK); + if (NS_WARN_IF(mEvent->mFlags.mIsBeingDispatched)) { + return; + } - auto* view = nsGlobalWindowInner::Cast(nsPIDOMWindowInner::From(aView)); - UIEvent::InitUIEvent(aType, aCanBubble, aCancelable, view, aDetail); + UIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, aDetail); mEvent->AsInputEvent()->InitBasicModifiers(aCtrlKey, aAltKey, aShiftKey, aMetaKey); mSourceEvent = aSourceEvent; mInputSource = aInputSource; - - return NS_OK; } } // namespace dom diff --git a/dom/events/XULCommandEvent.h b/dom/events/XULCommandEvent.h index b8bf0fa31fa9..8741134fce2c 100644 --- a/dom/events/XULCommandEvent.h +++ b/dom/events/XULCommandEvent.h @@ -4,20 +4,18 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -// This class implements a XUL "command" event. See nsIDOMXULCommandEvent.idl +// This class implements a XUL "command" event. See XULCommandEvent.webidl #ifndef mozilla_dom_XULCommandEvent_h_ #define mozilla_dom_XULCommandEvent_h_ #include "mozilla/dom/UIEvent.h" #include "mozilla/dom/XULCommandEventBinding.h" -#include "nsIDOMXULCommandEvent.h" namespace mozilla { namespace dom { -class XULCommandEvent : public UIEvent, - public nsIDOMXULCommandEvent +class XULCommandEvent : public UIEvent { public: XULCommandEvent(EventTarget* aOwner, @@ -26,16 +24,17 @@ public: NS_DECL_ISUPPORTS_INHERITED NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XULCommandEvent, UIEvent) - NS_DECL_NSIDOMXULCOMMANDEVENT - - // Forward our inherited virtual methods to the base class - NS_FORWARD_TO_UIEVENT virtual JSObject* WrapObjectInternal(JSContext* aCx, JS::Handle aGivenProto) override { return XULCommandEventBinding::Wrap(aCx, this, aGivenProto); } + virtual XULCommandEvent* AsXULCommandEvent() override + { + return this; + } + bool AltKey(); bool CtrlKey(); bool ShiftKey(); @@ -56,12 +55,8 @@ public: bool aCtrlKey, bool aAltKey, bool aShiftKey, bool aMetaKey, Event* aSourceEvent, - uint16_t aInputSource) - { - InitCommandEvent(aType, aCanBubble, aCancelable, aView->AsInner(), - aDetail, aCtrlKey, aAltKey, aShiftKey, aMetaKey, - aSourceEvent, aInputSource); - } + uint16_t aInputSource, + ErrorResult& aRv); protected: ~XULCommandEvent() {} diff --git a/dom/interfaces/xul/moz.build b/dom/interfaces/xul/moz.build index d8822914be26..a05582e200c0 100644 --- a/dom/interfaces/xul/moz.build +++ b/dom/interfaces/xul/moz.build @@ -11,7 +11,6 @@ XPIDL_SOURCES += [ 'nsIDOMXULButtonElement.idl', 'nsIDOMXULCheckboxElement.idl', 'nsIDOMXULCommandDispatcher.idl', - 'nsIDOMXULCommandEvent.idl', 'nsIDOMXULContainerElement.idl', 'nsIDOMXULControlElement.idl', 'nsIDOMXULDescriptionElement.idl', diff --git a/dom/interfaces/xul/nsIDOMXULCommandEvent.idl b/dom/interfaces/xul/nsIDOMXULCommandEvent.idl deleted file mode 100644 index 320f3633e410..000000000000 --- a/dom/interfaces/xul/nsIDOMXULCommandEvent.idl +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et cindent: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** - * This interface is supported by command events, which are dispatched to - * XUL elements as a result of mouse or keyboard activation. - */ - -#include "nsIDOMUIEvent.idl" - -[builtinclass, uuid(564496b4-1174-48ec-927d-edeb66b86757)] -interface nsIDOMXULCommandEvent : nsIDOMUIEvent -{ - /** - * Command events support the same set of modifier keys as mouse and key - * events. - */ - readonly attribute boolean ctrlKey; - readonly attribute boolean shiftKey; - readonly attribute boolean altKey; - readonly attribute boolean metaKey; - - /** - * The input source, if this event was triggered by a mouse event. - */ - readonly attribute unsigned short inputSource; - - /** - * If the command event was redispatched because of a command= attribute - * on the original target, sourceEvent will be set to the original DOM Event. - * Otherwise, sourceEvent is null. - */ - readonly attribute nsIDOMEvent sourceEvent; - - /** - * Creates a new command event with the given attributes. - */ - void initCommandEvent(in DOMString typeArg, - in boolean canBubbleArg, - in boolean cancelableArg, - in mozIDOMWindow viewArg, - in long detailArg, - in boolean ctrlKeyArg, - in boolean altKeyArg, - in boolean shiftKeyArg, - in boolean metaKeyArg, - in nsIDOMEvent sourceEvent, - in unsigned short inputSource); -}; diff --git a/dom/webidl/XULCommandEvent.webidl b/dom/webidl/XULCommandEvent.webidl index a652a4f2b1c2..898f221ade82 100644 --- a/dom/webidl/XULCommandEvent.webidl +++ b/dom/webidl/XULCommandEvent.webidl @@ -4,18 +4,38 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ +/** + * This interface is supported by command events, which are dispatched to + * XUL elements as a result of mouse or keyboard activation. + */ [Func="IsChromeOrXBL"] interface XULCommandEvent : UIEvent { + /** + * Command events support the same set of modifier keys as mouse and key + * events. + */ readonly attribute boolean ctrlKey; readonly attribute boolean shiftKey; readonly attribute boolean altKey; readonly attribute boolean metaKey; + /** + * The input source, if this event was triggered by a mouse event. + */ readonly attribute unsigned short inputSource; + /** + * If the command event was redispatched because of a command= attribute + * on the original target, sourceEvent will be set to the original DOM Event. + * Otherwise, sourceEvent is null. + */ readonly attribute Event? sourceEvent; + /** + * Creates a new command event with the given attributes. + */ + [Throws] void initCommandEvent(DOMString type, optional boolean canBubble = false, optional boolean cancelable = false, diff --git a/dom/xul/nsXULElement.cpp b/dom/xul/nsXULElement.cpp index 814bf85cc5dd..9fd506e24898 100644 --- a/dom/xul/nsXULElement.cpp +++ b/dom/xul/nsXULElement.cpp @@ -84,7 +84,6 @@ #include "nsXULTooltipListener.h" #include "mozilla/EventDispatcher.h" #include "mozAutoDocUpdate.h" -#include "nsIDOMXULCommandEvent.h" #include "nsCCUncollectableMarker.h" #include "nsICSSDeclaration.h" #include "nsLayoutUtils.h" @@ -93,6 +92,7 @@ #include "mozilla/dom/BoxObject.h" #include "mozilla/dom/HTMLIFrameElement.h" #include "mozilla/dom/MutationEventBinding.h" +#include "mozilla/dom/XULCommandEvent.h" using namespace mozilla; using namespace mozilla::dom; @@ -1364,11 +1364,10 @@ nsXULElement::DispatchXULCommand(const EventChainVisitor& aVisitor, Event* event = domEvent->InternalDOMEvent(); NS_ENSURE_STATE(!SameCOMIdentity(event->GetOriginalTarget(), commandElt)); - nsCOMPtr commandEvent = - do_QueryInterface(domEvent); + RefPtr commandEvent = event->AsXULCommandEvent(); if (commandEvent) { - commandEvent->GetSourceEvent(getter_AddRefs(domEvent)); - commandEvent->GetInputSource(&inputSource); + domEvent = commandEvent->GetSourceEvent(); + inputSource = commandEvent->InputSource(); } else { domEvent = nullptr; } @@ -1406,12 +1405,11 @@ nsXULElement::GetEventTargetParent(EventChainPreVisitor& aVisitor) !IsXULElement(nsGkAtoms::command)) { // Check that we really have an xul command event. That will be handled // in a special way. - nsCOMPtr xulEvent = - do_QueryInterface(aVisitor.mDOMEvent); // See if we have a command elt. If so, we execute on the command // instead of on our content element. nsAutoString command; - if (xulEvent && + if (aVisitor.mDOMEvent && + aVisitor.mDOMEvent->InternalDOMEvent()->AsXULCommandEvent() && GetAttr(kNameSpaceID_None, nsGkAtoms::command, command) && !command.IsEmpty()) { // Stop building the event target chain for the original event. diff --git a/widget/cocoa/nsMenuUtilsX.mm b/widget/cocoa/nsMenuUtilsX.mm index 6cf069f8b4c3..98eb2a5c23a9 100644 --- a/widget/cocoa/nsMenuUtilsX.mm +++ b/widget/cocoa/nsMenuUtilsX.mm @@ -13,11 +13,12 @@ #include "nsCocoaUtils.h" #include "nsCocoaWindow.h" #include "nsGkAtoms.h" +#include "nsGlobalWindowInner.h" #include "nsIDocument.h" #include "nsIDOMDocument.h" -#include "nsIDOMXULCommandEvent.h" #include "nsPIDOMWindow.h" #include "nsQueryObject.h" +#include "mozilla/dom/XULCommandEvent.h" using namespace mozilla; @@ -27,20 +28,18 @@ void nsMenuUtilsX::DispatchCommandTo(nsIContent* aTargetContent) nsIDocument* doc = aTargetContent->OwnerDoc(); if (doc) { - ErrorResult rv; - RefPtr event = - doc->CreateEvent(NS_LITERAL_STRING("xulcommandevent"), - dom::CallerType::System, rv); - nsCOMPtr command = do_QueryObject(event); + RefPtr event = + new dom::XULCommandEvent(doc, doc->GetPresContext(), nullptr); + IgnoredErrorResult rv; + event->InitCommandEvent(NS_LITERAL_STRING("command"), + true, true, + nsGlobalWindowInner::Cast(doc->GetInnerWindow()), + 0, false, false, false, + false, nullptr, 0, rv); // FIXME: Should probably figure out how to init this with the actual // pressed keys, but this is a big old edge case anyway. -dwh - if (command && - NS_SUCCEEDED(command->InitCommandEvent(NS_LITERAL_STRING("command"), - true, true, - doc->GetInnerWindow(), 0, - false, false, false, - false, nullptr, 0))) { + if (!rv.Failed()) { event->SetTrusted(true); bool dummy; aTargetContent->DispatchEvent(event, &dummy); diff --git a/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp b/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp index 3c062b50816e..da7dfca23dcc 100644 --- a/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp +++ b/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp @@ -35,7 +35,6 @@ #include "nsIDOMUIEvent.h" #include "nsIDOMWheelEvent.h" #include "nsIDOMXMLDocument.h" -#include "nsIDOMXULCommandEvent.h" #include "nsIDOMXULElement.h" #include "nsIFrameLoader.h" #include "nsIListBoxObject.h" @@ -92,7 +91,6 @@ #include "mozilla/dom/WheelEventBinding.h" #include "mozilla/dom/XMLDocumentBinding.h" #include "mozilla/dom/XMLSerializerBinding.h" -#include "mozilla/dom/XULCommandEventBinding.h" #include "mozilla/dom/XULDocumentBinding.h" #include "mozilla/dom/XULElementBinding.h" @@ -183,7 +181,6 @@ const ComponentsInterfaceShimEntry kComponentsInterfaceShimMap[] = DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIWebBrowserPersistable, FrameLoader), DEFINE_SHIM(WheelEvent), DEFINE_SHIM(XMLDocument), - DEFINE_SHIM(XULCommandEvent), DEFINE_SHIM(XULElement), DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsISelection, Selection), };