[android] handle menu and search keys android2
authorAlex Pakhotin <apakhotin@mozilla.com>
Tue, 27 Apr 2010 14:13:18 -0700
branchandroid2
changeset 40366 1af28380fc88
parent 40365 8bf8459416d0
child 40367 b0ba4c9e3708
push id95
push usermwu@mozilla.com
push date2010-04-27 21:15 +0000
milestone1.9.3a4pre
[android] handle menu and search keys
widget/src/android/nsWindow.cpp
widget/src/android/nsWindow.h
widget/src/xpwidgets/nsWidgetAtomList.h
--- a/widget/src/android/nsWindow.cpp
+++ b/widget/src/android/nsWindow.cpp
@@ -37,16 +37,17 @@
 
 #include <android/log.h>
 
 #include "nsWindow.h"
 
 #include "nsIDeviceContext.h"
 #include "nsIRenderingContext.h"
 
+#include "nsWidgetAtoms.h"
 #include "nsWidgetsCID.h"
 #include "nsGfxCIID.h"
 
 #include "gfxImageSurface.h"
 #include "gfxContext.h"
 
 #include "nsTArray.h"
 
@@ -1363,16 +1364,43 @@ nsWindow::InitKeyEvent(nsKeyEvent& event
     event.isShift = gLeftShift || gRightShift;
     event.isControl = PR_FALSE;
     event.isAlt = PR_FALSE;
     event.isMeta = PR_FALSE;
     event.time = key.Time();
 }
 
 void
+nsWindow::HandleSpecialKey(AndroidGeckoEvent *ae)
+{
+    nsCOMPtr<nsIAtom> command;
+    switch (ae->KeyCode()) {
+    case AndroidKeyEvent::KEYCODE_MENU:
+        command = nsWidgetAtoms::Menu;
+        break;
+    case AndroidKeyEvent::KEYCODE_SEARCH:
+        command = nsWidgetAtoms::Search;
+        break;
+    case AndroidKeyEvent::KEYCODE_VOLUME_UP:
+        command = nsWidgetAtoms::VolumeUp;
+        break;
+    case AndroidKeyEvent::KEYCODE_VOLUME_DOWN:
+        command = nsWidgetAtoms::VolumeDown;
+        break;
+    default:
+        ALOG("Unknown special key code!");
+        return;
+    }
+    nsCommandEvent event(PR_TRUE, nsWidgetAtoms::onAppCommand, command, this);
+
+    InitEvent(event);
+    DispatchEvent(&event);
+}
+
+void
 nsWindow::OnKeyEvent(AndroidGeckoEvent *ae)
 {
     PRUint32 msg;
     switch (ae->Action()) {
     case AndroidKeyEvent::ACTION_DOWN:
         msg = NS_KEY_DOWN;
         break;
     case AndroidKeyEvent::ACTION_UP:
@@ -1402,16 +1430,25 @@ nsWindow::OnKeyEvent(AndroidGeckoEvent *
         gLeftAlt = isDown;
         break;
     case AndroidKeyEvent::KEYCODE_ALT_RIGHT:
         gRightAlt = isDown;
         break;
     case AndroidKeyEvent::KEYCODE_SYM:
         gSym = isDown;
         break;
+    case AndroidKeyEvent::KEYCODE_MENU:
+    case AndroidKeyEvent::KEYCODE_SEARCH:
+    case AndroidKeyEvent::KEYCODE_VOLUME_UP:
+    case AndroidKeyEvent::KEYCODE_VOLUME_DOWN:
+        if (!isDown) {
+            HandleSpecialKey(ae);
+            return;
+        }
+        break;
     }
 
     nsKeyEvent event(PR_TRUE, msg, this);
     InitKeyEvent(event, *ae);
     if (event.charCode)
         event.keyCode = 0;
     DispatchEvent(&event);
 
--- a/widget/src/android/nsWindow.h
+++ b/widget/src/android/nsWindow.h
@@ -170,11 +170,12 @@ protected:
     nsWindow* mParent;
 
     static void DumpWindows();
     static void DumpWindows(const nsTArray<nsWindow*>& wins, int indent = 0);
     static void LogWindow(nsWindow *win, int index, int indent);
 
 private:
     void InitKeyEvent(nsKeyEvent& event, mozilla::AndroidGeckoEvent& key);
+    void HandleSpecialKey(mozilla::AndroidGeckoEvent *ae);
 };
 
 #endif /* NSWNIDOW_H_ */
--- a/widget/src/xpwidgets/nsWidgetAtomList.h
+++ b/widget/src/xpwidgets/nsWidgetAtomList.h
@@ -82,16 +82,17 @@ WIDGET_ATOM(vertical, "vertical")
 WIDGET_ATOM(id, "id")
 WIDGET_ATOM(image, "image")
 WIDGET_ATOM(input, "input")
 WIDGET_ATOM(indeterminate, "indeterminate")
 WIDGET_ATOM(key, "key") // The key element / attribute
 WIDGET_ATOM(label, "label")
 WIDGET_ATOM(max, "max")
 WIDGET_ATOM(maxpos, "maxpos")
+WIDGET_ATOM(Menu, "Menu") // AppCommand to open a menu
 WIDGET_ATOM(menu, "menu") // Represents an XP menu
 WIDGET_ATOM(menuitem, "menuitem") // Represents an XP menu item
 WIDGET_ATOM(menupopup, "menupopup") // The XP menu's children.
 WIDGET_ATOM(menuseparator, "menuseparator")  // Divider between menu items
 WIDGET_ATOM(menuFrame, "MenuFrame")
 WIDGET_ATOM(minpos, "minpos")
 WIDGET_ATOM(mode, "mode")
 WIDGET_ATOM(modifiers, "modifiers") // The modifiers attribute
@@ -119,9 +120,11 @@ WIDGET_ATOM(state, "state")
 WIDGET_ATOM(step, "step")
 WIDGET_ATOM(Stop, "Stop")
 WIDGET_ATOM(_true, "true")
 WIDGET_ATOM(tab, "tab")
 WIDGET_ATOM(tree, "tree")
 WIDGET_ATOM(treecolpicker, "treecolpicker")
 WIDGET_ATOM(type, "type")
 WIDGET_ATOM(value, "value")
+WIDGET_ATOM(VolumeUp, "VolumeUp")
+WIDGET_ATOM(VolumeDown, "VolumeDown")