Bug 855975 part.5 Move nsWindow::DispatchKeyEvent() to widget::NativeKey::DispatchKeyEvent() r=jimm

This commit is contained in:
Masayuki Nakano 2013-05-29 15:34:47 +09:00
parent 06784d3861
commit bdba6b134a
4 changed files with 50 additions and 23 deletions

View File

@ -17,8 +17,12 @@
#include "WidgetUtils.h"
#include "WinUtils.h"
#include "nsWindowDbg.h"
#include "nsServiceManagerUtils.h"
#include "nsIDOMKeyEvent.h"
#include "nsIIdleServiceInternal.h"
#include "npapi.h"
#include <windows.h>
#include <winuser.h>
@ -665,11 +669,30 @@ NativeKey::InitKeyEvent(nsKeyEvent& aKeyEvent,
aModKeyState.InitInputEvent(aKeyEvent);
}
bool
NativeKey::DispatchKeyEvent(nsKeyEvent& aKeyEvent,
const MSG* aMsgSentToPlugin) const
{
KeyboardLayout::NotifyIdleServiceOfUserActivity();
NPEvent pluginEvent;
if (aMsgSentToPlugin &&
mWidget->GetInputContext().mIMEState.mEnabled == IMEState::PLUGIN) {
pluginEvent.event = aMsgSentToPlugin->message;
pluginEvent.wParam = aMsgSentToPlugin->wParam;
pluginEvent.lParam = aMsgSentToPlugin->lParam;
aKeyEvent.pluginEvent = static_cast<void*>(&pluginEvent);
}
return mWidget->DispatchWindowEvent(&aKeyEvent);
}
/*****************************************************************************
* mozilla::widget::KeyboardLayout
*****************************************************************************/
KeyboardLayout* KeyboardLayout::sInstance = nullptr;
nsIIdleServiceInternal* KeyboardLayout::sIdleService = nullptr;
// static
KeyboardLayout*
@ -677,6 +700,10 @@ KeyboardLayout::GetInstance()
{
if (!sInstance) {
sInstance = new KeyboardLayout();
nsCOMPtr<nsIIdleServiceInternal> idleService =
do_GetService("@mozilla.org/widget/idleservice;1");
// The refcount will be decreased at shutting down.
sIdleService = idleService.forget().get();
}
return sInstance;
}
@ -687,6 +714,14 @@ KeyboardLayout::Shutdown()
{
delete sInstance;
sInstance = nullptr;
NS_IF_RELEASE(sIdleService);
}
// static
void
KeyboardLayout::NotifyIdleServiceOfUserActivity()
{
sIdleService->ResetIdleTimeOut(0);
}
KeyboardLayout::KeyboardLayout() :

View File

@ -34,6 +34,7 @@
#define VK_OEM_102 0xE2
#define VK_OEM_CLEAR 0xFE
class nsIIdleServiceInternal;
struct nsModifierKeyState;
namespace mozilla {
@ -323,6 +324,13 @@ public:
InitKeyEvent(aKeyEvent, mModKeyState);
}
/**
* Dispatches the key event. Returns true if the event is consumed.
* Otherwise, false.
*/
bool DispatchKeyEvent(nsKeyEvent& aKeyEvent,
const MSG* aMsgSentToPlugin = nullptr) const;
private:
nsRefPtr<nsWindowBase> mWidget;
HKL mKeyboardLayout;
@ -369,6 +377,7 @@ private:
~KeyboardLayout();
static KeyboardLayout* sInstance;
static nsIIdleServiceInternal* sIdleService;
struct DeadKeyTableListEntry
{
@ -421,6 +430,7 @@ private:
public:
static KeyboardLayout* GetInstance();
static void Shutdown();
static void NotifyIdleServiceOfUserActivity();
static bool IsPrintableCharKey(uint8_t aVirtualKey);

View File

@ -3615,22 +3615,6 @@ bool nsWindow::DispatchWindowEvent(nsGUIEvent* event, nsEventStatus &aStatus) {
return ConvertStatus(aStatus);
}
bool nsWindow::DispatchKeyEvent(nsKeyEvent& aKeyEvent,
const MSG *aMsgSentToPlugin)
{
UserActivity();
NPEvent pluginEvent;
if (aMsgSentToPlugin && PluginHasFocus()) {
pluginEvent.event = aMsgSentToPlugin->message;
pluginEvent.wParam = aMsgSentToPlugin->wParam;
pluginEvent.lParam = aMsgSentToPlugin->lParam;
aKeyEvent.pluginEvent = (void *)&pluginEvent;
}
return DispatchWindowEvent(&aKeyEvent);
}
bool nsWindow::DispatchCommandEvent(uint32_t aEventCommand)
{
nsCOMPtr<nsIAtom> command;
@ -6458,7 +6442,7 @@ LRESULT nsWindow::OnKeyDown(const MSG &aMsg,
nsKeyEvent keydownEvent(true, NS_KEY_DOWN, this);
keydownEvent.keyCode = DOMKeyCode;
nativeKey.InitKeyEvent(keydownEvent);
noDefault = DispatchKeyEvent(keydownEvent, &aMsg);
noDefault = nativeKey.DispatchKeyEvent(keydownEvent, &aMsg);
if (aEventDispatched) {
*aEventDispatched = true;
}
@ -6783,14 +6767,14 @@ LRESULT nsWindow::OnKeyDown(const MSG &aMsg,
keypressEvent.charCode = uniChar;
keypressEvent.alternativeCharCodes.AppendElements(altArray);
nativeKey.InitKeyEvent(keypressEvent, modKeyState);
DispatchKeyEvent(keypressEvent, nullptr);
nativeKey.DispatchKeyEvent(keypressEvent);
}
} else {
nsKeyEvent keypressEvent(true, NS_KEY_PRESS, this);
keypressEvent.mFlags.Union(extraFlags);
keypressEvent.keyCode = DOMKeyCode;
nativeKey.InitKeyEvent(keypressEvent, aModKeyState);
DispatchKeyEvent(keypressEvent, nullptr);
nativeKey.DispatchKeyEvent(keypressEvent);
}
return noDefault;
@ -6818,7 +6802,7 @@ LRESULT nsWindow::OnKeyUp(const MSG &aMsg,
// of IME.
keyupEvent.mFlags.mDefaultPrevented =
(aMsg.wParam == VK_MENU && aMsg.message != WM_SYSKEYUP);
return DispatchKeyEvent(keyupEvent, &aMsg);
return nativeKey.DispatchKeyEvent(keyupEvent, &aMsg);
}
// OnChar
@ -6903,7 +6887,7 @@ LRESULT nsWindow::OnChar(const MSG &aMsg,
keypressEvent.keyCode = aNativeKey.GetDOMKeyCode();
}
aNativeKey.InitKeyEvent(keypressEvent, modKeyState);
bool result = DispatchKeyEvent(keypressEvent, &aMsg);
bool result = aNativeKey.DispatchKeyEvent(keypressEvent, &aMsg);
if (aEventDispatched)
*aEventDispatched = true;
return result;

View File

@ -195,8 +195,6 @@ public:
int16_t aButton = nsMouseEvent::eLeftButton,
uint16_t aInputSource = nsIDOMMouseEvent::MOZ_SOURCE_MOUSE);
virtual bool DispatchWindowEvent(nsGUIEvent*event, nsEventStatus &aStatus);
virtual bool DispatchKeyEvent(nsKeyEvent& aKeyEvent,
const MSG *aMsgSentToPlugin);
void DispatchPendingEvents();
bool DispatchPluginEvent(UINT aMessage,
WPARAM aWParam,