Bug 1446710. Get rid of nsIDOMXULCommandEvent. r=qdot

MozReview-Commit-ID: C2C6oWtagG3
This commit is contained in:
Boris Zbarsky 2018-03-19 15:50:37 -04:00
Родитель 5c19641a68
Коммит d05e564049
11 изменённых файлов: 69 добавлений и 152 удалений

Просмотреть файл

@ -6715,8 +6715,12 @@ nsContentUtils::DispatchXULCommand(nsIContent* aTarget,
RefPtr<XULCommandEvent> 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;

Просмотреть файл

@ -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.
*/

Просмотреть файл

@ -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

Просмотреть файл

@ -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<nsIDOMEvent> 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

Просмотреть файл

@ -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<JSObject*> 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() {}

Просмотреть файл

@ -11,7 +11,6 @@ XPIDL_SOURCES += [
'nsIDOMXULButtonElement.idl',
'nsIDOMXULCheckboxElement.idl',
'nsIDOMXULCommandDispatcher.idl',
'nsIDOMXULCommandEvent.idl',
'nsIDOMXULContainerElement.idl',
'nsIDOMXULControlElement.idl',
'nsIDOMXULDescriptionElement.idl',

Просмотреть файл

@ -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);
};

Просмотреть файл

@ -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,

Просмотреть файл

@ -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<nsIDOMXULCommandEvent> commandEvent =
do_QueryInterface(domEvent);
RefPtr<XULCommandEvent> 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<nsIDOMXULCommandEvent> 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.

Просмотреть файл

@ -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<dom::Event> event =
doc->CreateEvent(NS_LITERAL_STRING("xulcommandevent"),
dom::CallerType::System, rv);
nsCOMPtr<nsIDOMXULCommandEvent> command = do_QueryObject(event);
RefPtr<dom::XULCommandEvent> 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);

Просмотреть файл

@ -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),
};