Bug 1134542 - Get rid of nsIDOMWindowUtils::sendKeyEvent() and nsIFrameLoader::sendCrossProcessKeyEvent() r?smaug
nsIDOMWindowUtils::sendKeyEvent() is already replaced with nsITextInputProcessor
for making callers set any attributes of KeyboardEvent and guaranteeing
consistency behavior with keyboard events caused by native key events. E.g.,
whether keypress event should be dispatched or not is automatically decided.
nsIFrameLoader::sendCrossProcessKeyEvent() is similart to
nsIDOMWindowUtils::sendKeyEvent() but it dispatches keyboard events in
child process directly. Currently, nsITextInputProcessor doesn't have this
feature but nobody wants/uses this feature. So, for removing actual
implementation of nsIDOMWindowUtils::sendKeyEvent(), i.e.,
nsContentUtils::SendKeyEvent(), which is shared by both
nsDOMWindowUtils::SendKeyEvent() and nsFrameLoader::SendCrossProcessKeyEvent(),
we should remove this unused API too. (FYI: it's implemented for old Fennec,
by
bug 553149.)
MozReview-Commit-ID: 9n0UVo8Me8k
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -8566,122 +8566,16 @@ nsContentUtils::GetViewToDispatchEvent(n
}
}
}
}
return nullptr;
}
nsresult
-nsContentUtils::SendKeyEvent(nsIWidget* aWidget,
- const nsAString& aType,
- int32_t aKeyCode,
- int32_t aCharCode,
- int32_t aModifiers,
- uint32_t aAdditionalFlags,
- bool* aDefaultActionTaken)
-{
- // get the widget to send the event to
- if (!aWidget)
- return NS_ERROR_FAILURE;
-
- EventMessage msg;
- if (aType.EqualsLiteral("keydown"))
- msg = eKeyDown;
- else if (aType.EqualsLiteral("keyup"))
- msg = eKeyUp;
- else if (aType.EqualsLiteral("keypress"))
- msg = eKeyPress;
- else
- return NS_ERROR_FAILURE;
-
- WidgetKeyboardEvent event(true, msg, aWidget);
- event.mModifiers = GetWidgetModifiers(aModifiers);
-
- if (msg == eKeyPress) {
- event.mKeyCode = aCharCode ? 0 : aKeyCode;
- event.mCharCode = aCharCode;
- } else {
- event.mKeyCode = aKeyCode;
- event.mCharCode = 0;
- }
-
- uint32_t locationFlag = (aAdditionalFlags &
- (nsIDOMWindowUtils::KEY_FLAG_LOCATION_STANDARD | nsIDOMWindowUtils::KEY_FLAG_LOCATION_LEFT |
- nsIDOMWindowUtils::KEY_FLAG_LOCATION_RIGHT | nsIDOMWindowUtils::KEY_FLAG_LOCATION_NUMPAD));
- switch (locationFlag) {
- case nsIDOMWindowUtils::KEY_FLAG_LOCATION_STANDARD:
- event.mLocation = eKeyLocationStandard;
- break;
- case nsIDOMWindowUtils::KEY_FLAG_LOCATION_LEFT:
- event.mLocation = eKeyLocationLeft;
- break;
- case nsIDOMWindowUtils::KEY_FLAG_LOCATION_RIGHT:
- event.mLocation = eKeyLocationRight;
- break;
- case nsIDOMWindowUtils::KEY_FLAG_LOCATION_NUMPAD:
- event.mLocation = eKeyLocationNumpad;
- break;
- default:
- if (locationFlag != 0) {
- return NS_ERROR_INVALID_ARG;
- }
- // If location flag isn't set, choose the location from keycode.
- switch (aKeyCode) {
- case nsIDOMKeyEvent::DOM_VK_NUMPAD0:
- case nsIDOMKeyEvent::DOM_VK_NUMPAD1:
- case nsIDOMKeyEvent::DOM_VK_NUMPAD2:
- case nsIDOMKeyEvent::DOM_VK_NUMPAD3:
- case nsIDOMKeyEvent::DOM_VK_NUMPAD4:
- case nsIDOMKeyEvent::DOM_VK_NUMPAD5:
- case nsIDOMKeyEvent::DOM_VK_NUMPAD6:
- case nsIDOMKeyEvent::DOM_VK_NUMPAD7:
- case nsIDOMKeyEvent::DOM_VK_NUMPAD8:
- case nsIDOMKeyEvent::DOM_VK_NUMPAD9:
- case nsIDOMKeyEvent::DOM_VK_MULTIPLY:
- case nsIDOMKeyEvent::DOM_VK_ADD:
- case nsIDOMKeyEvent::DOM_VK_SEPARATOR:
- case nsIDOMKeyEvent::DOM_VK_SUBTRACT:
- case nsIDOMKeyEvent::DOM_VK_DECIMAL:
- case nsIDOMKeyEvent::DOM_VK_DIVIDE:
- event.mLocation = eKeyLocationNumpad;
- break;
- case nsIDOMKeyEvent::DOM_VK_SHIFT:
- case nsIDOMKeyEvent::DOM_VK_CONTROL:
- case nsIDOMKeyEvent::DOM_VK_ALT:
- case nsIDOMKeyEvent::DOM_VK_META:
- event.mLocation = eKeyLocationLeft;
- break;
- default:
- event.mLocation = eKeyLocationStandard;
- break;
- }
- break;
- }
-
- event.mRefPoint = LayoutDeviceIntPoint(0, 0);
- event.mTime = PR_IntervalNow();
- if (!(aAdditionalFlags & nsIDOMWindowUtils::KEY_FLAG_NOT_SYNTHESIZED_FOR_TESTS)) {
- event.mFlags.mIsSynthesizedForTests = true;
- }
-
- if (aAdditionalFlags & nsIDOMWindowUtils::KEY_FLAG_PREVENT_DEFAULT) {
- event.PreventDefaultBeforeDispatch();
- }
-
- nsEventStatus status;
- nsresult rv = aWidget->DispatchEvent(&event, status);
- NS_ENSURE_SUCCESS(rv, rv);
-
- *aDefaultActionTaken = (status != nsEventStatus_eConsumeNoDefault);
-
- return NS_OK;
-}
-
-nsresult
nsContentUtils::SendMouseEvent(const nsCOMPtr<nsIPresShell>& aPresShell,
const nsAString& aType,
float aX,
float aY,
int32_t aButton,
int32_t aButtons,
int32_t aClickCount,
int32_t aModifiers,
@@ -10953,17 +10847,16 @@ nsContentUtils::IsMessageInputEvent(cons
case mozilla::dom::PBrowser::Msg_RealMouseButtonEvent__ID:
case mozilla::dom::PBrowser::Msg_RealKeyEvent__ID:
case mozilla::dom::PBrowser::Msg_MouseWheelEvent__ID:
case mozilla::dom::PBrowser::Msg_RealTouchEvent__ID:
case mozilla::dom::PBrowser::Msg_RealTouchMoveEvent__ID:
case mozilla::dom::PBrowser::Msg_RealDragEvent__ID:
case mozilla::dom::PBrowser::Msg_UpdateDimensions__ID:
case mozilla::dom::PBrowser::Msg_MouseEvent__ID:
- case mozilla::dom::PBrowser::Msg_KeyEvent__ID:
case mozilla::dom::PBrowser::Msg_SetDocShellIsActive__ID:
return true;
}
}
return false;
}
static const char* kUserInteractionInactive = "user-interaction-inactive";
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -2871,28 +2871,16 @@ public:
static int16_t GetButtonsFlagForButton(int32_t aButton);
static mozilla::LayoutDeviceIntPoint ToWidgetPoint(const mozilla::CSSPoint& aPoint,
const nsPoint& aOffset,
nsPresContext* aPresContext);
static nsView* GetViewToDispatchEvent(nsPresContext* aPresContext,
nsIPresShell** aPresShell);
/**
- * Synthesize a key event to the given widget
- * (see nsIDOMWindowUtils.sendKeyEvent).
- */
- static nsresult SendKeyEvent(nsIWidget* aWidget,
- const nsAString& aType,
- int32_t aKeyCode,
- int32_t aCharCode,
- int32_t aModifiers,
- uint32_t aAdditionalFlags,
- bool* aDefaultActionTaken);
-
- /**
* Synthesize a mouse event to the given widget
* (see nsIDOMWindowUtils.sendMouseEvent).
*/
static nsresult SendMouseEvent(const nsCOMPtr<nsIPresShell>& aPresShell,
const nsAString& aType,
float aX,
float aY,
int32_t aButton,
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -973,32 +973,16 @@ nsDOMWindowUtils::SendTouchEventCommon(c
}
nsresult rv = widget->DispatchEvent(&event, status);
*aPreventDefault = (status == nsEventStatus_eConsumeNoDefault);
return rv;
}
NS_IMETHODIMP
-nsDOMWindowUtils::SendKeyEvent(const nsAString& aType,
- int32_t aKeyCode,
- int32_t aCharCode,
- int32_t aModifiers,
- uint32_t aAdditionalFlags,
- bool* aDefaultActionTaken)
-{
- // get the widget to send the event to
- nsCOMPtr<nsIWidget> widget = GetWidget();
-
- return nsContentUtils::SendKeyEvent(widget, aType, aKeyCode, aCharCode,
- aModifiers, aAdditionalFlags,
- aDefaultActionTaken);
-}
-
-NS_IMETHODIMP
nsDOMWindowUtils::SendNativeKeyEvent(int32_t aNativeKeyboardLayout,
int32_t aNativeKeyCode,
int32_t aModifiers,
const nsAString& aCharacters,
const nsAString& aUnmodifiedCharacters,
nsIObserver* aObserver)
{
// get the widget to send the event to
--- a/dom/base/nsFrameLoader.cpp
+++ b/dom/base/nsFrameLoader.cpp
@@ -2925,45 +2925,16 @@ nsFrameLoader::ActivateFrameEvent(const
{
if (mRemoteBrowser) {
return mRemoteBrowser->SendActivateFrameEvent(nsString(aType), aCapture) ?
NS_OK : NS_ERROR_NOT_AVAILABLE;
}
return NS_ERROR_FAILURE;
}
-void
-nsFrameLoader::SendCrossProcessKeyEvent(const nsAString& aType,
- int32_t aKeyCode,
- int32_t aCharCode,
- int32_t aModifiers,
- bool aPreventDefault,
- ErrorResult& aRv)
-{
- nsresult rv = SendCrossProcessKeyEvent(aType, aKeyCode, aCharCode, aModifiers, aPreventDefault);
- if (NS_FAILED(rv)) {
- aRv.Throw(rv);
- }
-}
-
-NS_IMETHODIMP
-nsFrameLoader::SendCrossProcessKeyEvent(const nsAString& aType,
- int32_t aKeyCode,
- int32_t aCharCode,
- int32_t aModifiers,
- bool aPreventDefault)
-{
- if (mRemoteBrowser) {
- mRemoteBrowser->SendKeyEvent(aType, aKeyCode, aCharCode, aModifiers,
- aPreventDefault);
- return NS_OK;
- }
- return NS_ERROR_FAILURE;
-}
-
nsresult
nsFrameLoader::CreateStaticClone(nsIFrameLoader* aDest)
{
nsFrameLoader* dest = static_cast<nsFrameLoader*>(aDest);
dest->MaybeCreateDocShell();
NS_ENSURE_STATE(dest->mDocShell);
nsCOMPtr<nsIDocument> kungFuDeathGrip = dest->mDocShell->GetDocument();
--- a/dom/base/nsFrameLoader.h
+++ b/dom/base/nsFrameLoader.h
@@ -133,23 +133,16 @@ public:
float aX,
float aY,
int32_t aButton,
int32_t aClickCount,
int32_t aModifiers,
bool aIgnoreRootScrollFrame,
mozilla::ErrorResult& aRv);
- void SendCrossProcessKeyEvent(const nsAString& aType,
- int32_t aKeyCode,
- int32_t aCharCode,
- int32_t aModifiers,
- bool aPreventDefault,
- mozilla::ErrorResult& aRv);
-
void ActivateFrameEvent(const nsAString& aType,
bool aCapture,
mozilla::ErrorResult& aRv);
void RequestNotifyAfterRemotePaint(mozilla::ErrorResult& aRv);
void RequestFrameLoaderClose(mozilla::ErrorResult& aRv);
--- a/dom/base/nsIFrameLoader.idl
+++ b/dom/base/nsIFrameLoader.idl
@@ -106,25 +106,16 @@ interface nsIFrameLoader : nsISupports
* Activate event forwarding from client (remote frame) to parent.
*/
void activateFrameEvent(in AString aType, in boolean capture);
// Note, when frameloaders are swapped, also messageManagers are swapped.
readonly attribute nsIMessageSender messageManager;
/**
- * @see nsIDOMWindowUtils sendKeyEvent.
- */
- void sendCrossProcessKeyEvent(in AString aType,
- in long aKeyCode,
- in long aCharCode,
- in long aModifiers,
- [optional] in boolean aPreventDefault);
-
- /**
* Request that the next time a remote layer transaction has been
* received by the Compositor, a MozAfterRemoteFrame event be sent
* to the window.
*/
void requestNotifyAfterRemotePaint();
/**
* Close the window through the ownerElement.
--- a/dom/interfaces/base/nsIDOMWindowUtils.idl
+++ b/dom/interfaces/base/nsIDOMWindowUtils.idl
@@ -458,56 +458,16 @@ interface nsIDOMWindowUtils : nsISupport
in double aDeltaZ,
in unsigned long aDeltaMode,
in long aModifiers,
in long aLineOrPageDeltaX,
in long aLineOrPageDeltaY,
in unsigned long aOptions);
/**
- * Synthesize a key event to the window. The event types supported are:
- * keydown, keyup, keypress
- *
- * Key events generally end up being sent to the focused node.
- *
- * Cannot be accessed from unprivileged context (not content-accessible)
- * Will throw a DOM security error if called without chrome privileges.
- *
- * @param aType event type
- * @param aKeyCode key code
- * @param aCharCode character code
- * @param aModifiers modifiers pressed, using constants defined as MODIFIER_*
- * @param aAdditionalFlags special flags for the key event, see KEY_FLAG_*.
- *
- * @return false if the event had preventDefault() called on it,
- * true otherwise. In other words, true if and only if the
- * default action was taken.
- */
-
- // If this is set, preventDefault() the event before dispatch.
- const unsigned long KEY_FLAG_PREVENT_DEFAULT = 0x0001;
-
- // If this is set, the mIsSynthesizedForTests flag is set to false
- // on the key event. Otherwise it is true.
- const unsigned long KEY_FLAG_NOT_SYNTHESIZED_FOR_TESTS = 0x0002;
-
- // if one of these flags is set, the KeyboardEvent.location will be the value.
- // Otherwise, it will be computed from aKeyCode.
- const unsigned long KEY_FLAG_LOCATION_STANDARD = 0x0010;
- const unsigned long KEY_FLAG_LOCATION_LEFT = 0x0020;
- const unsigned long KEY_FLAG_LOCATION_RIGHT = 0x0040;
- const unsigned long KEY_FLAG_LOCATION_NUMPAD = 0x0080;
-
- boolean sendKeyEvent(in AString aType,
- in long aKeyCode,
- in long aCharCode,
- in long aModifiers,
- [optional] in unsigned long aAdditionalFlags);
-
- /**
* See nsIWidget::SynthesizeNativeKeyEvent
*
* Cannot be accessed from unprivileged context (not content-accessible)
* Will throw a DOM security error if called without chrome privileges.
*
* When you use this for tests, use the constants defined in NativeKeyCodes.js
*
* NOTE: The synthesized native event will be fired asynchronously, and upon
--- a/dom/ipc/PBrowser.ipdl
+++ b/dom/ipc/PBrowser.ipdl
@@ -705,25 +705,16 @@ child:
* We disable the input event queue when there is an active dnd session. We
* don't need support RealDragEvent with input priority.
*/
async RealDragEvent(WidgetDragEvent aEvent, uint32_t aDragAction,
uint32_t aDropEffect, nsCString aPrincipalURISpec);
async PluginEvent(WidgetPluginEvent aEvent);
- /**
- * @see nsIDOMWindowUtils sendKeyEvent.
- */
- async KeyEvent(nsString aType,
- int32_t aKeyCode,
- int32_t aCharCode,
- int32_t aModifiers,
- bool aPreventDefault);
-
prio(input) async CompositionEvent(WidgetCompositionEvent event);
async NormalPriorityCompositionEvent(WidgetCompositionEvent event);
prio(input) async SelectionEvent(WidgetSelectionEvent event);
async NormalPrioritySelectionEvent(WidgetSelectionEvent event);
/**
* Call PasteTransferable via a controller on the content process
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -2127,29 +2127,16 @@ TabChild::RecvRealKeyEvent(const WidgetK
mozilla::ipc::IPCResult
TabChild::RecvNormalPriorityRealKeyEvent(const WidgetKeyboardEvent& aEvent)
{
return RecvRealKeyEvent(aEvent);
}
mozilla::ipc::IPCResult
-TabChild::RecvKeyEvent(const nsString& aType,
- const int32_t& aKeyCode,
- const int32_t& aCharCode,
- const int32_t& aModifiers,
- const bool& aPreventDefault)
-{
- bool ignored = false;
- nsContentUtils::SendKeyEvent(mPuppetWidget, aType, aKeyCode, aCharCode,
- aModifiers, aPreventDefault, &ignored);
- return IPC_OK();
-}
-
-mozilla::ipc::IPCResult
TabChild::RecvCompositionEvent(const WidgetCompositionEvent& aEvent)
{
WidgetCompositionEvent localEvent(aEvent);
localEvent.mWidget = mPuppetWidget;
DispatchWidgetEventViaAPZ(localEvent);
Unused << SendOnEventNeedingAckHandled(aEvent.mMessage);
return IPC_OK();
}
--- a/dom/ipc/TabChild.h
+++ b/dom/ipc/TabChild.h
@@ -427,22 +427,16 @@ public:
const nsEventStatus& aApzResponse) override;
virtual mozilla::ipc::IPCResult
RecvNormalPriorityRealTouchMoveEvent(const WidgetTouchEvent& aEvent,
const ScrollableLayerGuid& aGuid,
const uint64_t& aInputBlockId,
const nsEventStatus& aApzResponse) override;
- virtual mozilla::ipc::IPCResult RecvKeyEvent(const nsString& aType,
- const int32_t& aKeyCode,
- const int32_t& aCharCode,
- const int32_t& aModifiers,
- const bool& aPreventDefault) override;
-
virtual mozilla::ipc::IPCResult RecvNativeSynthesisResponse(const uint64_t& aObserverId,
const nsCString& aResponse) override;
virtual mozilla::ipc::IPCResult RecvPluginEvent(const WidgetPluginEvent& aEvent) override;
virtual mozilla::ipc::IPCResult
RecvCompositionEvent(const mozilla::WidgetCompositionEvent& aEvent) override;
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -1099,30 +1099,16 @@ TabParent::SendMouseEvent(const nsAStrin
Unused << PBrowserParent::SendMouseEvent(nsString(aType), aX, aY,
aButton, aClickCount,
aModifiers,
aIgnoreRootScrollFrame);
}
}
void
-TabParent::SendKeyEvent(const nsAString& aType,
- int32_t aKeyCode,
- int32_t aCharCode,
- int32_t aModifiers,
- bool aPreventDefault)
-{
- if (mIsDestroyed || !mIsReadyToHandleInputEvents) {
- return;
- }
- Unused << PBrowserParent::SendKeyEvent(nsString(aType), aKeyCode, aCharCode,
- aModifiers, aPreventDefault);
-}
-
-void
TabParent::SendRealMouseEvent(WidgetMouseEvent& aEvent)
{
if (mIsDestroyed) {
return;
}
aEvent.mRefPoint += GetChildProcessOffset();
nsCOMPtr<nsIWidget> widget = GetWidget();
--- a/dom/ipc/TabParent.h
+++ b/dom/ipc/TabParent.h
@@ -424,20 +424,16 @@ public:
virtual mozilla::ipc::IPCResult
RecvClearNativeTouchSequence(const uint64_t& aObserverId) override;
void SendMouseEvent(const nsAString& aType, float aX, float aY,
int32_t aButton, int32_t aClickCount,
int32_t aModifiers, bool aIgnoreRootScrollFrame);
- void SendKeyEvent(const nsAString& aType, int32_t aKeyCode,
- int32_t aCharCode, int32_t aModifiers,
- bool aPreventDefault);
-
/**
* The following Send*Event() marks aEvent as posted to remote process if
* it succeeded. So, you can check the result with
* aEvent.HasBeenPostedToRemoteProcess().
*/
void SendRealMouseEvent(WidgetMouseEvent& aEvent);
void SendRealDragEvent(WidgetDragEvent& aEvent,
--- a/dom/ipc/test.xul
+++ b/dom/ipc/test.xul
@@ -68,28 +68,16 @@
document.getElementById('page').focus();
var frameLoader = document.getElementById('page').QueryInterface(Components.interfaces.nsIFrameLoaderOwner).frameLoader;
var x = parseInt(Math.random() * 100);
var y = parseInt(Math.random() * 100);
frameLoader.sendCrossProcessMouseEvent("mousedown", x, y, 0, 1, 0, false);
frameLoader.sendCrossProcessMouseEvent("mouseup", x, y, 0, 1, 0, false);
}
- function keyPress() {
- // First focus the remote frame, then dispatch click. This way remote frame gets focus before
- // mouse event.
- document.getElementById('page').focus();
- var frameLoader = document.getElementById('page').QueryInterface(Components.interfaces.nsIFrameLoaderOwner).frameLoader;
-
- var keyCode = Components.interfaces.nsIDOMKeyEvent.DOM_VK_A;
- frameLoader.sendCrossProcessKeyEvent("keydown", keyCode, 0, 0);
- frameLoader.sendCrossProcessKeyEvent("keypress", keyCode, 0, 0);
- frameLoader.sendCrossProcessKeyEvent("keyup", keyCode, 0, 0);
- }
-
function openWindow() {
window.open('chrome://global/content/test-ipc.xul', '_blank', 'chrome,resizable,width=800,height=800');
}
function closeWindow() {
window.close();
}
@@ -243,17 +231,16 @@
<toolbar id="controls">
<toolbarbutton label="Back"/>
<toolbarbutton label="Forward"/>
<textbox onchange="loadURL(this.value)" flex="1" id="URL"/>
</toolbar>
<toolbar>
<toolbarbutton onclick="restart()" label="Recover"/>
<toolbarbutton onclick="randomClick()" label="random click"/>
- <toolbarbutton onclick="keyPress()" label="key press"/>
<toolbarbutton onclick="messageSpeed()" label="test message handling speed"/>
<toolbarbutton onclick="listenerAddRemove()" label="test listener add/remove"/>
<toolbarbutton onclick="enableMozAfterPaint()" label="MozAfterPaint"/>
<toolbarbutton onclick="openWindow()" label="open new window"/>
<toolbarbutton onclick="closeWindow()" label="close this window"/>
</toolbar>
<toolbar><label value="Load a script (URL) to content process:"/>
<textbox flex="1" id="script"/><button
--- a/dom/webidl/FrameLoader.webidl
+++ b/dom/webidl/FrameLoader.webidl
@@ -102,26 +102,16 @@ interface FrameLoader {
*/
[Throws]
void activateFrameEvent(DOMString aType, boolean capture);
// Note, when frameloaders are swapped, also messageManagers are swapped.
readonly attribute nsIMessageSender? messageManager;
/**
- * @see nsIDOMWindowUtils sendKeyEvent.
- */
- [Throws]
- void sendCrossProcessKeyEvent(DOMString aType,
- long aKeyCode,
- long aCharCode,
- long aModifiers,
- optional boolean aPreventDefault = false);
-
- /**
* Request that the next time a remote layer transaction has been
* received by the Compositor, a MozAfterRemoteFrame event be sent
* to the window.
*/
[Throws]
void requestNotifyAfterRemotePaint();
/**