зеркало из https://github.com/mozilla/pjs.git
Bug 742036 - Part 3: Pass Android's native keycodes to Flash plugin using nsGUIEvent::pluginEvent. r=masayuki,blassey a=blocking-fennec
--HG-- extra : rebase_source : 0cedf764055dba59a8c55a468b5a6dc60e20dbae
This commit is contained in:
Родитель
97134923fc
Коммит
45c01ae248
|
@ -53,6 +53,7 @@ include $(topsrcdir)/config/config.mk
|
|||
include $(topsrcdir)/ipc/chromium/chromium-config.mk
|
||||
|
||||
EXPORTS = \
|
||||
ANPKeyCodes.h \
|
||||
android_npapi.h \
|
||||
$(NULL)
|
||||
|
||||
|
|
|
@ -125,7 +125,6 @@ static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
|
|||
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
#include "ANPBase.h"
|
||||
#include "android_npapi.h"
|
||||
#include "AndroidBridge.h"
|
||||
#include "AndroidMediaLayer.h"
|
||||
using namespace mozilla::dom;
|
||||
|
@ -2717,32 +2716,12 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const nsGUIEvent& anEvent)
|
|||
{
|
||||
const nsKeyEvent& keyEvent = static_cast<const nsKeyEvent&>(anEvent);
|
||||
LOG("Firing NS_KEY_EVENT %d %d\n", keyEvent.keyCode, keyEvent.charCode);
|
||||
|
||||
int modifiers = 0;
|
||||
if (keyEvent.isShift)
|
||||
modifiers |= kShift_ANPKeyModifier;
|
||||
if (keyEvent.isAlt)
|
||||
modifiers |= kAlt_ANPKeyModifier;
|
||||
|
||||
ANPEvent event;
|
||||
event.inSize = sizeof(ANPEvent);
|
||||
event.eventType = kKey_ANPEventType;
|
||||
event.data.key.nativeCode = keyEvent.keyCode;
|
||||
event.data.key.virtualCode = keyEvent.charCode;
|
||||
event.data.key.modifiers = modifiers;
|
||||
event.data.key.repeatCount = 0;
|
||||
event.data.key.unichar = 0;
|
||||
switch (anEvent.message)
|
||||
{
|
||||
case NS_KEY_DOWN:
|
||||
event.data.key.action = kDown_ANPKeyAction;
|
||||
mInstance->HandleEvent(&event, nsnull);
|
||||
break;
|
||||
|
||||
case NS_KEY_UP:
|
||||
event.data.key.action = kUp_ANPKeyAction;
|
||||
mInstance->HandleEvent(&event, nsnull);
|
||||
break;
|
||||
// pluginEvent is initialized by nsWindow::InitKeyEvent().
|
||||
ANPEvent* pluginEvent = reinterpret_cast<ANPEvent*>(keyEvent.pluginEvent);
|
||||
if (pluginEvent) {
|
||||
MOZ_ASSERT(pluginEvent->inSize == sizeof(ANPEvent));
|
||||
MOZ_ASSERT(pluginEvent->eventType == kKey_ANPEventType);
|
||||
mInstance->HandleEvent(pluginEvent, nsnull);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,6 +77,7 @@ using mozilla::unused;
|
|||
#include "nsTArray.h"
|
||||
|
||||
#include "AndroidBridge.h"
|
||||
#include "android_npapi.h"
|
||||
|
||||
#include "imgIEncoder.h"
|
||||
|
||||
|
@ -1707,21 +1708,63 @@ static unsigned int ConvertAndroidKeyCodeToDOMKeyCode(int androidKeyCode)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsWindow::InitKeyEvent(nsKeyEvent& event, AndroidGeckoEvent& key)
|
||||
static void InitPluginEvent(ANPEvent* pluginEvent, ANPKeyActions keyAction,
|
||||
AndroidGeckoEvent& key)
|
||||
{
|
||||
event.keyCode = ConvertAndroidKeyCodeToDOMKeyCode(key.KeyCode());
|
||||
int androidKeyCode = key.KeyCode();
|
||||
PRUint32 domKeyCode = ConvertAndroidKeyCodeToDOMKeyCode(androidKeyCode);
|
||||
|
||||
int modifiers = 0;
|
||||
if (key.IsAltPressed())
|
||||
modifiers |= kAlt_ANPKeyModifier;
|
||||
if (key.IsShiftPressed())
|
||||
modifiers |= kShift_ANPKeyModifier;
|
||||
|
||||
pluginEvent->inSize = sizeof(ANPEvent);
|
||||
pluginEvent->eventType = kKey_ANPEventType;
|
||||
pluginEvent->data.key.action = keyAction;
|
||||
pluginEvent->data.key.nativeCode = androidKeyCode;
|
||||
pluginEvent->data.key.virtualCode = domKeyCode;
|
||||
pluginEvent->data.key.unichar = key.UnicodeChar();
|
||||
pluginEvent->data.key.modifiers = modifiers;
|
||||
pluginEvent->data.key.repeatCount = key.RepeatCount();
|
||||
}
|
||||
|
||||
void
|
||||
nsWindow::InitKeyEvent(nsKeyEvent& event, AndroidGeckoEvent& key,
|
||||
ANPEvent* pluginEvent)
|
||||
{
|
||||
int androidKeyCode = key.KeyCode();
|
||||
PRUint32 domKeyCode = ConvertAndroidKeyCodeToDOMKeyCode(androidKeyCode);
|
||||
|
||||
if (event.message == NS_KEY_PRESS) {
|
||||
// Android gives us \n, so filter out some control characters.
|
||||
if (event.message == NS_KEY_PRESS &&
|
||||
key.UnicodeChar() >= ' ') {
|
||||
event.charCode = key.UnicodeChar();
|
||||
if (key.UnicodeChar())
|
||||
event.keyCode = 0;
|
||||
event.isChar = (key.UnicodeChar() >= ' ');
|
||||
event.charCode = event.isChar ? key.UnicodeChar() : 0;
|
||||
event.keyCode = (event.charCode > 0) ? 0 : domKeyCode;
|
||||
event.pluginEvent = NULL;
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
if (event.message != NS_KEY_DOWN && event.message != NS_KEY_UP) {
|
||||
ALOG("InitKeyEvent: unexpected event.message %d", event.message);
|
||||
}
|
||||
event.isShift = !!(key.MetaState() & AndroidKeyEvent::META_SHIFT_ON);
|
||||
#endif // DEBUG
|
||||
|
||||
// Flash will want a pluginEvent for keydown and keyup events.
|
||||
ANPKeyActions action = event.message == NS_KEY_DOWN
|
||||
? kDown_ANPKeyAction
|
||||
: kUp_ANPKeyAction;
|
||||
InitPluginEvent(pluginEvent, action, key);
|
||||
|
||||
event.isChar = false;
|
||||
event.charCode = 0;
|
||||
event.keyCode = domKeyCode;
|
||||
event.pluginEvent = pluginEvent;
|
||||
}
|
||||
|
||||
event.isShift = key.IsShiftPressed();
|
||||
event.isControl = gMenu;
|
||||
event.isAlt = !!(key.MetaState() & AndroidKeyEvent::META_ALT_ON);
|
||||
event.isAlt = key.IsAltPressed();
|
||||
event.isMeta = false;
|
||||
event.time = key.Time();
|
||||
|
||||
|
@ -1764,7 +1807,8 @@ nsWindow::HandleSpecialKey(AndroidGeckoEvent *ae)
|
|||
switch (keyCode) {
|
||||
case AndroidKeyEvent::KEYCODE_BACK: {
|
||||
nsKeyEvent pressEvent(true, NS_KEY_PRESS, this);
|
||||
InitKeyEvent(pressEvent, *ae);
|
||||
ANPEvent pluginEvent;
|
||||
InitKeyEvent(pressEvent, *ae, &pluginEvent);
|
||||
DispatchEvent(&pressEvent);
|
||||
return;
|
||||
}
|
||||
|
@ -1834,7 +1878,8 @@ nsWindow::OnKeyEvent(AndroidGeckoEvent *ae)
|
|||
|
||||
nsEventStatus status;
|
||||
nsKeyEvent event(true, msg, this);
|
||||
InitKeyEvent(event, *ae);
|
||||
ANPEvent pluginEvent;
|
||||
InitKeyEvent(event, *ae, &pluginEvent);
|
||||
DispatchEvent(&event, status);
|
||||
|
||||
if (Destroyed())
|
||||
|
@ -1843,7 +1888,7 @@ nsWindow::OnKeyEvent(AndroidGeckoEvent *ae)
|
|||
return;
|
||||
|
||||
nsKeyEvent pressEvent(true, NS_KEY_PRESS, this);
|
||||
InitKeyEvent(pressEvent, *ae);
|
||||
InitKeyEvent(pressEvent, *ae, &pluginEvent);
|
||||
if (status == nsEventStatus_eConsumeNoDefault) {
|
||||
pressEvent.flags |= NS_EVENT_FLAG_NO_DEFAULT;
|
||||
}
|
||||
|
@ -1971,7 +2016,8 @@ nsWindow::OnIMEEvent(AndroidGeckoEvent *ae)
|
|||
{
|
||||
ALOGIME("IME: IME_DELETE_TEXT");
|
||||
nsKeyEvent event(true, NS_KEY_PRESS, this);
|
||||
InitEvent(event, nsnull);
|
||||
ANPEvent pluginEvent;
|
||||
InitKeyEvent(event, *ae, &pluginEvent);
|
||||
event.keyCode = NS_VK_BACK;
|
||||
DispatchEvent(&event);
|
||||
}
|
||||
|
|
|
@ -51,6 +51,8 @@
|
|||
class gfxASurface;
|
||||
class nsIdleService;
|
||||
|
||||
struct ANPEvent;
|
||||
|
||||
namespace mozilla {
|
||||
class AndroidGeckoEvent;
|
||||
class AndroidKeyEvent;
|
||||
|
@ -231,7 +233,8 @@ protected:
|
|||
static void LogWindow(nsWindow *win, int index, int indent);
|
||||
|
||||
private:
|
||||
void InitKeyEvent(nsKeyEvent& event, mozilla::AndroidGeckoEvent& key);
|
||||
void InitKeyEvent(nsKeyEvent& event, mozilla::AndroidGeckoEvent& key,
|
||||
ANPEvent* pluginEvent);
|
||||
bool DispatchMultitouchEvent(nsTouchEvent &event,
|
||||
mozilla::AndroidGeckoEvent *ae);
|
||||
void DispatchMotionEvent(nsInputEvent &event,
|
||||
|
|
Загрузка…
Ссылка в новой задаче