зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1371219 - Add an inputSource attribute to XULCommandEvent. r=smaug
In the frontend we need to know if XUL buttons in the toolbar were triggered by a touch event, so we're passing on the inputSource in the command event. MozReview-Commit-ID: DMvgZULk9hT --HG-- extra : rebase_source : c455c8ec77e439bf02c1e3e8d34a36e1fb5e3bd0
This commit is contained in:
Родитель
1eed2191e9
Коммит
3eac596d72
|
@ -44,7 +44,7 @@ function simulateCommand(ele) {
|
|||
let { document } = window;
|
||||
var evt = document.createEvent('XULCommandEvent');
|
||||
evt.initCommandEvent('command', true, true, window,
|
||||
0, false, false, false, false, null);
|
||||
0, false, false, false, false, null, 0);
|
||||
ele.dispatchEvent(evt);
|
||||
}
|
||||
exports.simulateCommand = simulateCommand;
|
||||
|
|
|
@ -51,7 +51,7 @@ function simulateCommand(ele) {
|
|||
let { document } = window;
|
||||
var evt = document.createEvent('XULCommandEvent');
|
||||
evt.initCommandEvent('command', true, true, window,
|
||||
0, false, false, false, false, null);
|
||||
0, false, false, false, false, null, 0);
|
||||
ele.dispatchEvent(evt);
|
||||
}
|
||||
exports.simulateCommand = simulateCommand;
|
||||
|
|
|
@ -334,7 +334,8 @@ var gGestureSupport = {
|
|||
let cmdEvent = document.createEvent("xulcommandevent");
|
||||
cmdEvent.initCommandEvent("command", true, true, window, 0,
|
||||
aEvent.ctrlKey, aEvent.altKey,
|
||||
aEvent.shiftKey, aEvent.metaKey, aEvent);
|
||||
aEvent.shiftKey, aEvent.metaKey,
|
||||
aEvent, aEvent.mozInputSource);
|
||||
node.dispatchEvent(cmdEvent);
|
||||
}
|
||||
|
||||
|
|
|
@ -380,7 +380,7 @@ const gClickAndHoldListenersOnElement = {
|
|||
let cmdEvent = document.createEvent("xulcommandevent");
|
||||
cmdEvent.initCommandEvent("command", true, true, window, 0,
|
||||
aEvent.ctrlKey, aEvent.altKey, aEvent.shiftKey,
|
||||
aEvent.metaKey, null);
|
||||
aEvent.metaKey, null, aEvent.mozInputSource);
|
||||
aEvent.currentTarget.dispatchEvent(cmdEvent);
|
||||
|
||||
// This is here to cancel the XUL default event
|
||||
|
|
|
@ -133,7 +133,7 @@ function fillSubviewFromMenuItems(aMenuItems, aSubview) {
|
|||
newEvent.initCommandEvent(
|
||||
event.type, event.bubbles, event.cancelable, event.view,
|
||||
event.detail, event.ctrlKey, event.altKey, event.shiftKey,
|
||||
event.metaKey, event.sourceEvent);
|
||||
event.metaKey, event.sourceEvent, 0);
|
||||
item.dispatchEvent(newEvent);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ add_task(async function selectInternalOptionForFeed() {
|
|||
|
||||
// Select the option.
|
||||
let cmdEvent = win.document.createEvent("xulcommandevent");
|
||||
cmdEvent.initCommandEvent("command", true, true, win, 0, false, false, false, false, null);
|
||||
cmdEvent.initCommandEvent("command", true, true, win, 0, false, false, false, false, null, 0);
|
||||
chooseItems[0].dispatchEvent(cmdEvent);
|
||||
|
||||
// Check that we display the correct result.
|
||||
|
|
|
@ -34,7 +34,7 @@ add_task(async function() {
|
|||
let chooseItem = list.firstChild.querySelector(".choose-app-item");
|
||||
let dialogLoadedPromise = promiseLoadSubDialog("chrome://global/content/appPicker.xul");
|
||||
let cmdEvent = win.document.createEvent("xulcommandevent");
|
||||
cmdEvent.initCommandEvent("command", true, true, win, 0, false, false, false, false, null);
|
||||
cmdEvent.initCommandEvent("command", true, true, win, 0, false, false, false, false, null, 0);
|
||||
chooseItem.dispatchEvent(cmdEvent);
|
||||
|
||||
let dialog = await dialogLoadedPromise;
|
||||
|
@ -63,7 +63,7 @@ add_task(async function() {
|
|||
|
||||
let manageItem = list.firstChild.querySelector(".manage-app-item");
|
||||
cmdEvent = win.document.createEvent("xulcommandevent");
|
||||
cmdEvent.initCommandEvent("command", true, true, win, 0, false, false, false, false, null);
|
||||
cmdEvent.initCommandEvent("command", true, true, win, 0, false, false, false, false, null, 0);
|
||||
manageItem.dispatchEvent(cmdEvent);
|
||||
|
||||
dialog = await dialogLoadedPromise;
|
||||
|
|
|
@ -38,7 +38,7 @@ add_task(async function selectInternalOptionForFeed() {
|
|||
|
||||
// Select the option.
|
||||
let cmdEvent = win.document.createEvent("xulcommandevent");
|
||||
cmdEvent.initCommandEvent("command", true, true, win, 0, false, false, false, false, null);
|
||||
cmdEvent.initCommandEvent("command", true, true, win, 0, false, false, false, false, null, 0);
|
||||
chooseItems[0].dispatchEvent(cmdEvent);
|
||||
|
||||
// Check that we display the correct result.
|
||||
|
|
|
@ -33,7 +33,7 @@ add_task(async function() {
|
|||
let chooseItem = list.firstChild.querySelector(".choose-app-item");
|
||||
let dialogLoadedPromise = promiseLoadSubDialog("chrome://global/content/appPicker.xul");
|
||||
let cmdEvent = win.document.createEvent("xulcommandevent");
|
||||
cmdEvent.initCommandEvent("command", true, true, win, 0, false, false, false, false, null);
|
||||
cmdEvent.initCommandEvent("command", true, true, win, 0, false, false, false, false, null, 0);
|
||||
chooseItem.dispatchEvent(cmdEvent);
|
||||
|
||||
let dialog = await dialogLoadedPromise;
|
||||
|
@ -62,7 +62,7 @@ add_task(async function() {
|
|||
|
||||
let manageItem = list.firstChild.querySelector(".manage-app-item");
|
||||
cmdEvent = win.document.createEvent("xulcommandevent");
|
||||
cmdEvent.initCommandEvent("command", true, true, win, 0, false, false, false, false, null);
|
||||
cmdEvent.initCommandEvent("command", true, true, win, 0, false, false, false, false, null, 0);
|
||||
manageItem.dispatchEvent(cmdEvent);
|
||||
|
||||
dialog = await dialogLoadedPromise;
|
||||
|
|
|
@ -11,7 +11,7 @@ exports.VERTICAL_AXIS = 2;
|
|||
exports.command = (node) => {
|
||||
let ev = node.ownerDocument.createEvent("XULCommandEvent");
|
||||
ev.initCommandEvent("command", true, true, node.ownerDocument.defaultView, 0, false,
|
||||
false, false, false, null);
|
||||
false, false, false, null, 0);
|
||||
node.dispatchEvent(ev);
|
||||
};
|
||||
|
||||
|
|
|
@ -363,7 +363,7 @@ function mouseOver(win, element) {
|
|||
|
||||
function command(button) {
|
||||
let ev = button.ownerDocument.createEvent("XULCommandEvent");
|
||||
ev.initCommandEvent("command", true, true, button.ownerDocument.defaultView, 0, false, false, false, false, null);
|
||||
ev.initCommandEvent("command", true, true, button.ownerDocument.defaultView, 0, false, false, false, false, null, 0);
|
||||
button.dispatchEvent(ev);
|
||||
}
|
||||
|
||||
|
|
|
@ -258,7 +258,7 @@ function altClickButton(node) {
|
|||
function chooseMenuItem(node) {
|
||||
let event = document.createEvent("XULCommandEvent");
|
||||
event.initCommandEvent("command", true, true, window, 0, false, false, false,
|
||||
false, null);
|
||||
false, null, 0);
|
||||
node.dispatchEvent(event);
|
||||
}
|
||||
|
||||
|
|
|
@ -6617,7 +6617,8 @@ nsContentUtils::DispatchXULCommand(nsIContent* aTarget,
|
|||
bool aCtrl,
|
||||
bool aAlt,
|
||||
bool aShift,
|
||||
bool aMeta)
|
||||
bool aMeta,
|
||||
uint16_t aInputSource)
|
||||
{
|
||||
NS_ENSURE_STATE(aTarget);
|
||||
nsIDocument* doc = aTarget->OwnerDoc();
|
||||
|
@ -6630,7 +6631,7 @@ nsContentUtils::DispatchXULCommand(nsIContent* aTarget,
|
|||
nullptr);
|
||||
xulCommand->InitCommandEvent(NS_LITERAL_STRING("command"), true, true,
|
||||
doc->GetInnerWindow(), 0, aCtrl, aAlt, aShift,
|
||||
aMeta, aSourceEvent);
|
||||
aMeta, aSourceEvent, aInputSource);
|
||||
|
||||
if (aShell) {
|
||||
nsEventStatus status = nsEventStatus_eIgnore;
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include "mozilla/Maybe.h"
|
||||
#include "nsIContentPolicy.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDOMMouseEvent.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsRFPService.h"
|
||||
|
||||
|
@ -1994,7 +1995,8 @@ public:
|
|||
bool aCtrl = false,
|
||||
bool aAlt = false,
|
||||
bool aShift = false,
|
||||
bool aMeta = false);
|
||||
bool aMeta = false,
|
||||
uint16_t inputSource = nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN);
|
||||
|
||||
static bool CheckMayLoad(nsIPrincipal* aPrincipal, nsIChannel* aChannel, bool aAllowIfInheritsPrincipal);
|
||||
|
||||
|
|
|
@ -92,6 +92,20 @@ XULCommandEvent::GetMetaKey(bool* aIsDown)
|
|||
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)
|
||||
{
|
||||
|
@ -111,7 +125,8 @@ XULCommandEvent::InitCommandEvent(const nsAString& aType,
|
|||
bool aAltKey,
|
||||
bool aShiftKey,
|
||||
bool aMetaKey,
|
||||
nsIDOMEvent* aSourceEvent)
|
||||
nsIDOMEvent* aSourceEvent,
|
||||
uint16_t aInputSource)
|
||||
{
|
||||
NS_ENSURE_TRUE(!mEvent->mFlags.mIsBeingDispatched, NS_OK);
|
||||
|
||||
|
@ -121,6 +136,7 @@ XULCommandEvent::InitCommandEvent(const nsAString& aType,
|
|||
mEvent->AsInputEvent()->InitBasicModifiers(aCtrlKey, aAltKey,
|
||||
aShiftKey, aMetaKey);
|
||||
mSourceEvent = aSourceEvent;
|
||||
mInputSource = aInputSource;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ public:
|
|||
bool CtrlKey();
|
||||
bool ShiftKey();
|
||||
bool MetaKey();
|
||||
uint16_t InputSource();
|
||||
|
||||
already_AddRefed<Event> GetSourceEvent()
|
||||
{
|
||||
|
@ -54,17 +55,19 @@ public:
|
|||
int32_t aDetail,
|
||||
bool aCtrlKey, bool aAltKey,
|
||||
bool aShiftKey, bool aMetaKey,
|
||||
Event* aSourceEvent)
|
||||
Event* aSourceEvent,
|
||||
uint16_t aInputSource)
|
||||
{
|
||||
InitCommandEvent(aType, aCanBubble, aCancelable, aView->AsInner(),
|
||||
aDetail, aCtrlKey, aAltKey, aShiftKey, aMetaKey,
|
||||
aSourceEvent);
|
||||
aSourceEvent, aInputSource);
|
||||
}
|
||||
|
||||
protected:
|
||||
~XULCommandEvent() {}
|
||||
|
||||
nsCOMPtr<nsIDOMEvent> mSourceEvent;
|
||||
uint16_t mInputSource;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
|
|
@ -23,6 +23,11 @@ interface nsIDOMXULCommandEvent : nsIDOMUIEvent
|
|||
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.
|
||||
|
@ -42,5 +47,6 @@ interface nsIDOMXULCommandEvent : nsIDOMUIEvent
|
|||
in boolean altKeyArg,
|
||||
in boolean shiftKeyArg,
|
||||
in boolean metaKeyArg,
|
||||
in nsIDOMEvent sourceEvent);
|
||||
in nsIDOMEvent sourceEvent,
|
||||
in unsigned short inputSource);
|
||||
};
|
||||
|
|
|
@ -12,6 +12,8 @@ interface XULCommandEvent : UIEvent
|
|||
readonly attribute boolean altKey;
|
||||
readonly attribute boolean metaKey;
|
||||
|
||||
readonly attribute unsigned short inputSource;
|
||||
|
||||
readonly attribute Event? sourceEvent;
|
||||
|
||||
void initCommandEvent(DOMString type,
|
||||
|
@ -23,5 +25,6 @@ interface XULCommandEvent : UIEvent
|
|||
optional boolean altKey = false,
|
||||
optional boolean shiftKey = false,
|
||||
optional boolean metaKey = false,
|
||||
optional Event? sourceEvent = null);
|
||||
optional Event? sourceEvent = null,
|
||||
optional unsigned short inputSource = 0);
|
||||
};
|
||||
|
|
|
@ -1255,6 +1255,7 @@ nsXULElement::DispatchXULCommand(const EventChainVisitor& aVisitor,
|
|||
// sourceEvent will be the original command event that we're
|
||||
// handling.
|
||||
nsCOMPtr<nsIDOMEvent> domEvent = aVisitor.mDOMEvent;
|
||||
uint16_t inputSource = nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN;
|
||||
while (domEvent) {
|
||||
Event* event = domEvent->InternalDOMEvent();
|
||||
NS_ENSURE_STATE(!SameCOMIdentity(event->GetOriginalTarget(),
|
||||
|
@ -1263,6 +1264,7 @@ nsXULElement::DispatchXULCommand(const EventChainVisitor& aVisitor,
|
|||
do_QueryInterface(domEvent);
|
||||
if (commandEvent) {
|
||||
commandEvent->GetSourceEvent(getter_AddRefs(domEvent));
|
||||
commandEvent->GetInputSource(&inputSource);
|
||||
} else {
|
||||
domEvent = nullptr;
|
||||
}
|
||||
|
@ -1276,7 +1278,8 @@ nsXULElement::DispatchXULCommand(const EventChainVisitor& aVisitor,
|
|||
orig->IsControl(),
|
||||
orig->IsAlt(),
|
||||
orig->IsShift(),
|
||||
orig->IsMeta());
|
||||
orig->IsMeta(),
|
||||
inputSource);
|
||||
} else {
|
||||
NS_WARNING("A XUL element is attached to a command that doesn't exist!\n");
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
let cmdEvent = document.createEvent("xulcommandevent");
|
||||
cmdEvent.initCommandEvent("command", true, true, window, 0,
|
||||
aEvent.ctrlKey, aEvent.altKey, aEvent.shiftKey,
|
||||
aEvent.metaKey, null);
|
||||
aEvent.metaKey, null, aEvent.mozInputSource);
|
||||
aEvent.currentTarget.dispatchEvent(cmdEvent);
|
||||
});
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
|||
let cmdEvent = document.createEvent("xulcommandevent");
|
||||
cmdEvent.initCommandEvent("command", true, true, window, 0,
|
||||
aEvent.ctrlKey, aEvent.altKey, aEvent.shiftKey,
|
||||
aEvent.metaKey, null);
|
||||
aEvent.metaKey, null, aEvent.mozInputSource);
|
||||
aEvent.currentTarget.dispatchEvent(cmdEvent);
|
||||
});
|
||||
|
||||
|
|
|
@ -211,12 +211,19 @@ nsButtonBoxFrame::DoMouseClick(WidgetGUIEvent* aEvent, bool aTrustEvent)
|
|||
bool isControl = false;
|
||||
bool isAlt = false;
|
||||
bool isMeta = false;
|
||||
uint16_t inputSource = nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN;
|
||||
|
||||
if(aEvent) {
|
||||
WidgetInputEvent* inputEvent = aEvent->AsInputEvent();
|
||||
isShift = inputEvent->IsShift();
|
||||
isControl = inputEvent->IsControl();
|
||||
isAlt = inputEvent->IsAlt();
|
||||
isMeta = inputEvent->IsMeta();
|
||||
|
||||
WidgetMouseEventBase* mouseEvent = aEvent->AsMouseEventBase();
|
||||
if (mouseEvent) {
|
||||
inputSource = mouseEvent->inputSource;
|
||||
}
|
||||
}
|
||||
|
||||
// Have the content handle the event, propagating it according to normal DOM rules.
|
||||
|
@ -226,6 +233,6 @@ nsButtonBoxFrame::DoMouseClick(WidgetGUIEvent* aEvent, bool aTrustEvent)
|
|||
aEvent ?
|
||||
aEvent->IsTrusted() : aTrustEvent,
|
||||
nullptr, shell,
|
||||
isControl, isAlt, isShift, isMeta);
|
||||
isControl, isAlt, isShift, isMeta, inputSource);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -533,6 +533,23 @@ nsResizerFrame::GetDirection()
|
|||
void
|
||||
nsResizerFrame::MouseClicked(WidgetMouseEvent* aEvent)
|
||||
{
|
||||
// Execute the oncommand event handler.
|
||||
nsContentUtils::DispatchXULCommand(mContent, aEvent && aEvent->IsTrusted());
|
||||
bool isTrusted = false;
|
||||
bool isShift = false;
|
||||
bool isControl = false;
|
||||
bool isAlt = false;
|
||||
bool isMeta = false;
|
||||
uint16_t inputSource = nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN;
|
||||
|
||||
if(aEvent) {
|
||||
isShift = aEvent->IsShift();
|
||||
isControl = aEvent->IsControl();
|
||||
isAlt = aEvent->IsAlt();
|
||||
isMeta = aEvent->IsMeta();
|
||||
inputSource = aEvent->inputSource;
|
||||
}
|
||||
|
||||
// Execute the oncommand event handler.
|
||||
nsContentUtils::DispatchXULCommand(mContent, isTrusted, nullptr,
|
||||
nullptr, isControl, isAlt,
|
||||
isShift, isMeta, inputSource);
|
||||
}
|
||||
|
|
|
@ -167,6 +167,23 @@ nsTitleBarFrame::HandleEvent(nsPresContext* aPresContext,
|
|||
void
|
||||
nsTitleBarFrame::MouseClicked(WidgetMouseEvent* aEvent)
|
||||
{
|
||||
// Execute the oncommand event handler.
|
||||
nsContentUtils::DispatchXULCommand(mContent, aEvent && aEvent->IsTrusted());
|
||||
bool isTrusted = false;
|
||||
bool isShift = false;
|
||||
bool isControl = false;
|
||||
bool isAlt = false;
|
||||
bool isMeta = false;
|
||||
uint16_t inputSource = nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN;
|
||||
|
||||
if(aEvent) {
|
||||
isShift = aEvent->IsShift();
|
||||
isControl = aEvent->IsControl();
|
||||
isAlt = aEvent->IsAlt();
|
||||
isMeta = aEvent->IsMeta();
|
||||
inputSource = aEvent->inputSource;
|
||||
}
|
||||
|
||||
// Execute the oncommand event handler.
|
||||
nsContentUtils::DispatchXULCommand(mContent, isTrusted, nullptr,
|
||||
nullptr, isControl, isAlt,
|
||||
isShift, isMeta, inputSource);
|
||||
}
|
||||
|
|
|
@ -154,7 +154,7 @@ var SelectHelper = {
|
|||
let win = element.ownerGlobal;
|
||||
let event = element.ownerDocument.createEvent("XULCommandEvent");
|
||||
event.initCommandEvent("command", true, true, element.defaultView, 0,
|
||||
false, false, false, false, null);
|
||||
false, false, false, false, null, 0);
|
||||
win.setTimeout(function() {
|
||||
element.dispatchEvent(event);
|
||||
}, 0);
|
||||
|
|
|
@ -40,7 +40,7 @@ void nsMenuUtilsX::DispatchCommandTo(nsIContent* aTargetContent)
|
|||
true, true,
|
||||
doc->GetInnerWindow(), 0,
|
||||
false, false, false,
|
||||
false, nullptr))) {
|
||||
false, nullptr, 0))) {
|
||||
event->SetTrusted(true);
|
||||
bool dummy;
|
||||
aTargetContent->DispatchEvent(event, &dummy);
|
||||
|
|
Загрузка…
Ссылка в новой задаче