summaryrefslogtreecommitdiffstats
path: root/flash-78414-2.patch
blob: e82e3f1b853d942098ca72b290f54ffc0d6f4471 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
--- a/dom/plugins/base/nsPluginNativeWindowGtk2.cpp	Thu Oct 14 19:37:50 2010 +0200
+++ a/dom/plugins/base/nsPluginNativeWindowGtk2.cpp	Thu Oct 14 20:37:29 2010 +0200
@@ -43,16 +43,17 @@ 
  */
 
 #include "nsDebug.h"
 #include "nsPluginNativeWindow.h"
 #include "npapi.h"
 #include <gtk/gtk.h>
 #include <gdk/gdkx.h>
 #include <gdk/gdk.h>
+#include <gdk/gdkkeysyms.h>
 
 #if (MOZ_PLATFORM_MAEMO == 5)
 #define MOZ_COMPOSITED_PLUGINS
 #endif
 
 #ifdef MOZ_COMPOSITED_PLUGINS
 extern "C" {
 #include <X11/extensions/Xdamage.h>
@@ -231,16 +232,91 @@ nsresult nsPluginNativeWindowGtk2::CallS
   }
   else if (mPluginInstance)
     mPluginInstance->SetWindow(nsnull);
 
   SetPluginInstance(aPluginInstance);
   return NS_OK;
 }
 
+gboolean on_key_press(GtkWidget *window, GdkEventKey *pKey, gpointer data) {
+  GtkWidget *parent_widget;
+  gboolean combination_keypress = FALSE;
+  gboolean F1_to_F12 = FALSE;
+  gboolean plugin_text_edit_keys = FALSE;
+
+  /* Should the plugin or Firefox receive the key?
+   * 1. If it's a regular key, the plugin
+   * 2. If it's F1-F12, Firefox
+   * 3. If it's a common modifier key, not in a combination with another key, the plugin
+   * 4. If it's a common modifier key (except shift) in combination with another key, Firefox
+   * 5. If it's ctrl-z, ctrl-x, ctrl-c or ctrl-v, the plugin
+   */
+
+  /* Firefox priority keys:
+   *  F1 to F12
+   */
+  if (pKey->type == GDK_KEY_PRESS) {
+    switch (pKey->keyval)
+    {
+      /* Fallthrough */
+      case GDK_KEY_F1:
+      case GDK_KEY_F2:
+      case GDK_KEY_F3:
+      case GDK_KEY_F4:
+      case GDK_KEY_F5:
+      case GDK_KEY_F6:
+      case GDK_KEY_F7:
+      case GDK_KEY_F8:
+      case GDK_KEY_F9:
+      case GDK_KEY_F10:
+      case GDK_KEY_F11:
+      case GDK_KEY_F12: 
+        /* The keypress is F1-F12 */
+        F1_to_F12 = TRUE;
+        break;
+    }
+  }
+
+  /* This is not a single modifier-key keypress (like Ctrl by itself) */
+  if (pKey->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK)) {
+    /* This is a combination of a modifier and a keypress */
+    combination_keypress = TRUE;
+  }
+
+  /* Flash priority keys:
+   *  Ctrl-Z, Ctrl-X, Ctrl-C, Ctrl-V, Ctrl-A
+   */
+  if (combination_keypress) {
+    switch (pKey->keyval)
+    {
+      /* Fallthrough */
+      case GDK_KEY_z:
+      case GDK_KEY_x:
+      case GDK_KEY_c:
+      case GDK_KEY_v:
+      case GDK_KEY_a:
+        /* Yes, it's one of the plugin text editing keys */
+        plugin_text_edit_keys = TRUE;
+        break;
+    }
+  }
+
+  if (((!F1_to_F12) && (!combination_keypress)) || (plugin_text_edit_keys)) {
+    /* The plugin should receive this keypress */
+    return FALSE;
+  } else {
+    /* Change focus to the parent widget */
+    parent_widget = gtk_widget_get_parent(window);
+    gtk_widget_grab_focus(parent_widget);
+    /* The keypress will be handled by the parent widget (Firefox) */
+    return FALSE;
+  }
+}
+
 nsresult nsPluginNativeWindowGtk2::CreateXEmbedWindow() {
   NS_ASSERTION(!mSocketWidget,"Already created a socket widget!");
 
   GdkWindow *parent_win = gdk_window_lookup((XID)window);
   mSocketWidget = gtk_socket_new();
 
   //attach the socket to the container widget
   gtk_widget_set_parent_window(mSocketWidget, parent_win);
@@ -253,16 +329,19 @@ nsresult nsPluginNativeWindowGtk2::Creat
                    G_CALLBACK(plug_removed_cb), NULL);
 
   g_signal_connect(mSocketWidget, "unrealize",
                    G_CALLBACK(socket_unrealize_cb), NULL);
 
   g_signal_connect(mSocketWidget, "destroy",
                    G_CALLBACK(gtk_widget_destroyed), &mSocketWidget);
 
+  g_signal_connect(mSocketWidget, "key-press-event",
+                   G_CALLBACK(on_key_press), NULL);
+
   gpointer user_data = NULL;
   gdk_window_get_user_data(parent_win, &user_data);
 
   GtkContainer *container = GTK_CONTAINER(user_data);
   gtk_container_add(container, mSocketWidget);
   gtk_widget_realize(mSocketWidget);
 
   // The GtkSocket has a visible window, but the plugin's XEmbed plug will