diff --git a/addon-sdk/source/test/addons/private-browsing-supported/sidebar/utils.js b/addon-sdk/source/test/addons/private-browsing-supported/sidebar/utils.js index 5fbe18ba48e2..6154719457fc 100644 --- a/addon-sdk/source/test/addons/private-browsing-supported/sidebar/utils.js +++ b/addon-sdk/source/test/addons/private-browsing-supported/sidebar/utils.js @@ -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; diff --git a/addon-sdk/source/test/sidebar/utils.js b/addon-sdk/source/test/sidebar/utils.js index 4b3a26417155..ffe7b9c7e2d7 100644 --- a/addon-sdk/source/test/sidebar/utils.js +++ b/addon-sdk/source/test/sidebar/utils.js @@ -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; diff --git a/browser/base/content/browser-gestureSupport.js b/browser/base/content/browser-gestureSupport.js index 01577e202254..4f0c7b0ee54b 100644 --- a/browser/base/content/browser-gestureSupport.js +++ b/browser/base/content/browser-gestureSupport.js @@ -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); } diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 28be8c1eb2c8..8b4b8abe8743 100755 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -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 diff --git a/browser/components/customizableui/CustomizableWidgets.jsm b/browser/components/customizableui/CustomizableWidgets.jsm index 9035ad806ef5..263c40e3ad4f 100644 --- a/browser/components/customizableui/CustomizableWidgets.jsm +++ b/browser/components/customizableui/CustomizableWidgets.jsm @@ -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); }); } diff --git a/browser/components/preferences/in-content-new/tests/browser_applications_selection.js b/browser/components/preferences/in-content-new/tests/browser_applications_selection.js index 325517da5a36..67d8cec75c73 100644 --- a/browser/components/preferences/in-content-new/tests/browser_applications_selection.js +++ b/browser/components/preferences/in-content-new/tests/browser_applications_selection.js @@ -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. diff --git a/browser/components/preferences/in-content-new/tests/browser_change_app_handler.js b/browser/components/preferences/in-content-new/tests/browser_change_app_handler.js index f4eddba1c9fc..fe969f8a6a02 100644 --- a/browser/components/preferences/in-content-new/tests/browser_change_app_handler.js +++ b/browser/components/preferences/in-content-new/tests/browser_change_app_handler.js @@ -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; diff --git a/browser/components/preferences/in-content/tests/browser_applications_selection.js b/browser/components/preferences/in-content/tests/browser_applications_selection.js index 9b7503c98d12..9c7aa20f7bd9 100644 --- a/browser/components/preferences/in-content/tests/browser_applications_selection.js +++ b/browser/components/preferences/in-content/tests/browser_applications_selection.js @@ -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. diff --git a/browser/components/preferences/in-content/tests/browser_change_app_handler.js b/browser/components/preferences/in-content/tests/browser_change_app_handler.js index dd9081073f1a..3adae269e1ae 100644 --- a/browser/components/preferences/in-content/tests/browser_change_app_handler.js +++ b/browser/components/preferences/in-content/tests/browser_change_app_handler.js @@ -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; diff --git a/devtools/client/performance/test/helpers/input-utils.js b/devtools/client/performance/test/helpers/input-utils.js index 180091d076aa..ce109ac38fe2 100644 --- a/devtools/client/performance/test/helpers/input-utils.js +++ b/devtools/client/performance/test/helpers/input-utils.js @@ -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); }; diff --git a/devtools/client/webaudioeditor/test/head.js b/devtools/client/webaudioeditor/test/head.js index 098c1e000c38..56b67b2a70f6 100644 --- a/devtools/client/webaudioeditor/test/head.js +++ b/devtools/client/webaudioeditor/test/head.js @@ -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); } diff --git a/devtools/client/webconsole/test/browser_webconsole_bug_601667_filter_buttons.js b/devtools/client/webconsole/test/browser_webconsole_bug_601667_filter_buttons.js index 6dae0a7b7ea3..6823e3ce7f35 100644 --- a/devtools/client/webconsole/test/browser_webconsole_bug_601667_filter_buttons.js +++ b/devtools/client/webconsole/test/browser_webconsole_bug_601667_filter_buttons.js @@ -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); } diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 13a0bc588fe2..7a903e9cd9ce 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -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; diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index 4b0d862385d4..029ebe804f1e 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -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); diff --git a/dom/events/XULCommandEvent.cpp b/dom/events/XULCommandEvent.cpp index 5084588b47c3..ba9337fcfe4b 100644 --- a/dom/events/XULCommandEvent.cpp +++ b/dom/events/XULCommandEvent.cpp @@ -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; } diff --git a/dom/events/XULCommandEvent.h b/dom/events/XULCommandEvent.h index ea5e85a75fe1..083f72c9182a 100644 --- a/dom/events/XULCommandEvent.h +++ b/dom/events/XULCommandEvent.h @@ -40,6 +40,7 @@ public: bool CtrlKey(); bool ShiftKey(); bool MetaKey(); + uint16_t InputSource(); already_AddRefed 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 mSourceEvent; + uint16_t mInputSource; }; } // namespace dom diff --git a/dom/interfaces/xul/nsIDOMXULCommandEvent.idl b/dom/interfaces/xul/nsIDOMXULCommandEvent.idl index c32a9e47d3f3..320f3633e410 100644 --- a/dom/interfaces/xul/nsIDOMXULCommandEvent.idl +++ b/dom/interfaces/xul/nsIDOMXULCommandEvent.idl @@ -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); }; diff --git a/dom/webidl/XULCommandEvent.webidl b/dom/webidl/XULCommandEvent.webidl index 72dc3802ee86..a652a4f2b1c2 100644 --- a/dom/webidl/XULCommandEvent.webidl +++ b/dom/webidl/XULCommandEvent.webidl @@ -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); }; diff --git a/dom/xul/nsXULElement.cpp b/dom/xul/nsXULElement.cpp index 36d97a9d2872..88a6fd4f55f6 100644 --- a/dom/xul/nsXULElement.cpp +++ b/dom/xul/nsXULElement.cpp @@ -1255,6 +1255,7 @@ nsXULElement::DispatchXULCommand(const EventChainVisitor& aVisitor, // sourceEvent will be the original command event that we're // handling. nsCOMPtr 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"); } diff --git a/dom/xul/test/test_bug1290965.xul b/dom/xul/test/test_bug1290965.xul index 8701b55be5e5..613a4a2e4a60 100644 --- a/dom/xul/test/test_bug1290965.xul +++ b/dom/xul/test/test_bug1290965.xul @@ -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); }); diff --git a/layout/xul/nsButtonBoxFrame.cpp b/layout/xul/nsButtonBoxFrame.cpp index eefb0ab1d3fd..037c62dbb326 100644 --- a/layout/xul/nsButtonBoxFrame.cpp +++ b/layout/xul/nsButtonBoxFrame.cpp @@ -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); } } diff --git a/layout/xul/nsResizerFrame.cpp b/layout/xul/nsResizerFrame.cpp index 6a8f69912a7b..097dfed1a796 100644 --- a/layout/xul/nsResizerFrame.cpp +++ b/layout/xul/nsResizerFrame.cpp @@ -533,6 +533,23 @@ nsResizerFrame::GetDirection() void nsResizerFrame::MouseClicked(WidgetMouseEvent* aEvent) { + 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, aEvent && aEvent->IsTrusted()); + nsContentUtils::DispatchXULCommand(mContent, isTrusted, nullptr, + nullptr, isControl, isAlt, + isShift, isMeta, inputSource); } diff --git a/layout/xul/nsTitleBarFrame.cpp b/layout/xul/nsTitleBarFrame.cpp index c0ca37df0258..4f948a34ba86 100644 --- a/layout/xul/nsTitleBarFrame.cpp +++ b/layout/xul/nsTitleBarFrame.cpp @@ -167,6 +167,23 @@ nsTitleBarFrame::HandleEvent(nsPresContext* aPresContext, void nsTitleBarFrame::MouseClicked(WidgetMouseEvent* aEvent) { + 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, aEvent && aEvent->IsTrusted()); + nsContentUtils::DispatchXULCommand(mContent, isTrusted, nullptr, + nullptr, isControl, isAlt, + isShift, isMeta, inputSource); } diff --git a/mobile/android/chrome/content/SelectHelper.js b/mobile/android/chrome/content/SelectHelper.js index bbb15ba47e1a..f3d61a1f16df 100644 --- a/mobile/android/chrome/content/SelectHelper.js +++ b/mobile/android/chrome/content/SelectHelper.js @@ -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); diff --git a/widget/cocoa/nsMenuUtilsX.mm b/widget/cocoa/nsMenuUtilsX.mm index 3e7b2a12ab17..4adb24f8f5f9 100644 --- a/widget/cocoa/nsMenuUtilsX.mm +++ b/widget/cocoa/nsMenuUtilsX.mm @@ -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);