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:
Chris Peterson 2012-04-19 10:49:31 -07:00
Родитель 97134923fc
Коммит 45c01ae248
4 изменённых файлов: 74 добавлений и 45 удалений

Просмотреть файл

@ -53,6 +53,7 @@ include $(topsrcdir)/config/config.mk
include $(topsrcdir)/ipc/chromium/chromium-config.mk include $(topsrcdir)/ipc/chromium/chromium-config.mk
EXPORTS = \ EXPORTS = \
ANPKeyCodes.h \
android_npapi.h \ android_npapi.h \
$(NULL) $(NULL)

Просмотреть файл

@ -125,7 +125,6 @@ static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
#ifdef MOZ_WIDGET_ANDROID #ifdef MOZ_WIDGET_ANDROID
#include "ANPBase.h" #include "ANPBase.h"
#include "android_npapi.h"
#include "AndroidBridge.h" #include "AndroidBridge.h"
#include "AndroidMediaLayer.h" #include "AndroidMediaLayer.h"
using namespace mozilla::dom; using namespace mozilla::dom;
@ -2717,33 +2716,13 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const nsGUIEvent& anEvent)
{ {
const nsKeyEvent& keyEvent = static_cast<const nsKeyEvent&>(anEvent); const nsKeyEvent& keyEvent = static_cast<const nsKeyEvent&>(anEvent);
LOG("Firing NS_KEY_EVENT %d %d\n", keyEvent.keyCode, keyEvent.charCode); LOG("Firing NS_KEY_EVENT %d %d\n", keyEvent.keyCode, keyEvent.charCode);
// pluginEvent is initialized by nsWindow::InitKeyEvent().
int modifiers = 0; ANPEvent* pluginEvent = reinterpret_cast<ANPEvent*>(keyEvent.pluginEvent);
if (keyEvent.isShift) if (pluginEvent) {
modifiers |= kShift_ANPKeyModifier; MOZ_ASSERT(pluginEvent->inSize == sizeof(ANPEvent));
if (keyEvent.isAlt) MOZ_ASSERT(pluginEvent->eventType == kKey_ANPEventType);
modifiers |= kAlt_ANPKeyModifier; mInstance->HandleEvent(pluginEvent, nsnull);
}
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;
}
} }
} }
rv = nsEventStatus_eConsumeNoDefault; rv = nsEventStatus_eConsumeNoDefault;

Просмотреть файл

@ -77,6 +77,7 @@ using mozilla::unused;
#include "nsTArray.h" #include "nsTArray.h"
#include "AndroidBridge.h" #include "AndroidBridge.h"
#include "android_npapi.h"
#include "imgIEncoder.h" #include "imgIEncoder.h"
@ -1707,21 +1708,63 @@ static unsigned int ConvertAndroidKeyCodeToDOMKeyCode(int androidKeyCode)
} }
} }
void static void InitPluginEvent(ANPEvent* pluginEvent, ANPKeyActions keyAction,
nsWindow::InitKeyEvent(nsKeyEvent& event, AndroidGeckoEvent& key) AndroidGeckoEvent& key)
{ {
event.keyCode = ConvertAndroidKeyCodeToDOMKeyCode(key.KeyCode()); int androidKeyCode = key.KeyCode();
PRUint32 domKeyCode = ConvertAndroidKeyCodeToDOMKeyCode(androidKeyCode);
// Android gives us \n, so filter out some control characters. int modifiers = 0;
if (event.message == NS_KEY_PRESS && if (key.IsAltPressed())
key.UnicodeChar() >= ' ') { modifiers |= kAlt_ANPKeyModifier;
event.charCode = key.UnicodeChar(); if (key.IsShiftPressed())
if (key.UnicodeChar()) modifiers |= kShift_ANPKeyModifier;
event.keyCode = 0;
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.
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);
}
#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.MetaState() & AndroidKeyEvent::META_SHIFT_ON);
event.isShift = key.IsShiftPressed();
event.isControl = gMenu; event.isControl = gMenu;
event.isAlt = !!(key.MetaState() & AndroidKeyEvent::META_ALT_ON); event.isAlt = key.IsAltPressed();
event.isMeta = false; event.isMeta = false;
event.time = key.Time(); event.time = key.Time();
@ -1764,7 +1807,8 @@ nsWindow::HandleSpecialKey(AndroidGeckoEvent *ae)
switch (keyCode) { switch (keyCode) {
case AndroidKeyEvent::KEYCODE_BACK: { case AndroidKeyEvent::KEYCODE_BACK: {
nsKeyEvent pressEvent(true, NS_KEY_PRESS, this); nsKeyEvent pressEvent(true, NS_KEY_PRESS, this);
InitKeyEvent(pressEvent, *ae); ANPEvent pluginEvent;
InitKeyEvent(pressEvent, *ae, &pluginEvent);
DispatchEvent(&pressEvent); DispatchEvent(&pressEvent);
return; return;
} }
@ -1834,7 +1878,8 @@ nsWindow::OnKeyEvent(AndroidGeckoEvent *ae)
nsEventStatus status; nsEventStatus status;
nsKeyEvent event(true, msg, this); nsKeyEvent event(true, msg, this);
InitKeyEvent(event, *ae); ANPEvent pluginEvent;
InitKeyEvent(event, *ae, &pluginEvent);
DispatchEvent(&event, status); DispatchEvent(&event, status);
if (Destroyed()) if (Destroyed())
@ -1843,7 +1888,7 @@ nsWindow::OnKeyEvent(AndroidGeckoEvent *ae)
return; return;
nsKeyEvent pressEvent(true, NS_KEY_PRESS, this); nsKeyEvent pressEvent(true, NS_KEY_PRESS, this);
InitKeyEvent(pressEvent, *ae); InitKeyEvent(pressEvent, *ae, &pluginEvent);
if (status == nsEventStatus_eConsumeNoDefault) { if (status == nsEventStatus_eConsumeNoDefault) {
pressEvent.flags |= NS_EVENT_FLAG_NO_DEFAULT; pressEvent.flags |= NS_EVENT_FLAG_NO_DEFAULT;
} }
@ -1968,10 +2013,11 @@ nsWindow::OnIMEEvent(AndroidGeckoEvent *ae)
} }
return; return;
case AndroidGeckoEvent::IME_DELETE_TEXT: case AndroidGeckoEvent::IME_DELETE_TEXT:
{ {
ALOGIME("IME: IME_DELETE_TEXT"); ALOGIME("IME: IME_DELETE_TEXT");
nsKeyEvent event(true, NS_KEY_PRESS, this); nsKeyEvent event(true, NS_KEY_PRESS, this);
InitEvent(event, nsnull); ANPEvent pluginEvent;
InitKeyEvent(event, *ae, &pluginEvent);
event.keyCode = NS_VK_BACK; event.keyCode = NS_VK_BACK;
DispatchEvent(&event); DispatchEvent(&event);
} }

Просмотреть файл

@ -51,6 +51,8 @@
class gfxASurface; class gfxASurface;
class nsIdleService; class nsIdleService;
struct ANPEvent;
namespace mozilla { namespace mozilla {
class AndroidGeckoEvent; class AndroidGeckoEvent;
class AndroidKeyEvent; class AndroidKeyEvent;
@ -231,7 +233,8 @@ protected:
static void LogWindow(nsWindow *win, int index, int indent); static void LogWindow(nsWindow *win, int index, int indent);
private: private:
void InitKeyEvent(nsKeyEvent& event, mozilla::AndroidGeckoEvent& key); void InitKeyEvent(nsKeyEvent& event, mozilla::AndroidGeckoEvent& key,
ANPEvent* pluginEvent);
bool DispatchMultitouchEvent(nsTouchEvent &event, bool DispatchMultitouchEvent(nsTouchEvent &event,
mozilla::AndroidGeckoEvent *ae); mozilla::AndroidGeckoEvent *ae);
void DispatchMotionEvent(nsInputEvent &event, void DispatchMotionEvent(nsInputEvent &event,