Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" | 5 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 #include <gdk/gdk.h> | 8 #include <gdk/gdk.h> |
| 9 #include <gdk/gdkkeysyms.h> | 9 #include <gdk/gdkkeysyms.h> |
| 10 #include <gdk/gdkx.h> | 10 #include <gdk/gdkx.h> |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 g_signal_connect(widget, "expose-event", | 56 g_signal_connect(widget, "expose-event", |
| 57 G_CALLBACK(ExposeEvent), host_view); | 57 G_CALLBACK(ExposeEvent), host_view); |
| 58 g_signal_connect(widget, "key-press-event", | 58 g_signal_connect(widget, "key-press-event", |
| 59 G_CALLBACK(KeyPressReleaseEvent), host_view); | 59 G_CALLBACK(KeyPressReleaseEvent), host_view); |
| 60 g_signal_connect(widget, "key-release-event", | 60 g_signal_connect(widget, "key-release-event", |
| 61 G_CALLBACK(KeyPressReleaseEvent), host_view); | 61 G_CALLBACK(KeyPressReleaseEvent), host_view); |
| 62 g_signal_connect(widget, "focus-in-event", | 62 g_signal_connect(widget, "focus-in-event", |
| 63 G_CALLBACK(OnFocusIn), host_view); | 63 G_CALLBACK(OnFocusIn), host_view); |
| 64 g_signal_connect(widget, "focus-out-event", | 64 g_signal_connect(widget, "focus-out-event", |
| 65 G_CALLBACK(OnFocusOut), host_view); | 65 G_CALLBACK(OnFocusOut), host_view); |
| 66 g_signal_connect(widget, "grab-notify", | |
| 67 G_CALLBACK(OnGrabNotify), host_view); | |
| 66 g_signal_connect(widget, "button-press-event", | 68 g_signal_connect(widget, "button-press-event", |
| 67 G_CALLBACK(ButtonPressReleaseEvent), host_view); | 69 G_CALLBACK(ButtonPressReleaseEvent), host_view); |
| 68 g_signal_connect(widget, "button-release-event", | 70 g_signal_connect(widget, "button-release-event", |
| 69 G_CALLBACK(ButtonPressReleaseEvent), host_view); | 71 G_CALLBACK(ButtonPressReleaseEvent), host_view); |
| 70 g_signal_connect(widget, "motion-notify-event", | 72 g_signal_connect(widget, "motion-notify-event", |
| 71 G_CALLBACK(MouseMoveEvent), host_view); | 73 G_CALLBACK(MouseMoveEvent), host_view); |
| 72 g_signal_connect(widget, "scroll-event", | 74 g_signal_connect(widget, "scroll-event", |
| 73 G_CALLBACK(MouseScrollEvent), host_view); | 75 G_CALLBACK(MouseScrollEvent), host_view); |
| 74 | 76 |
| 75 // Create a GtkIMContext instance and attach its signal handlers. | 77 // Create a GtkIMContext instance and attach its signal handlers. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 host_view->GetRenderWidgetHost()->ForwardKeyboardEvent(wke); | 149 host_view->GetRenderWidgetHost()->ForwardKeyboardEvent(wke); |
| 148 } | 150 } |
| 149 } | 151 } |
| 150 | 152 |
| 151 // We return TRUE because we did handle the event. If it turns out webkit | 153 // We return TRUE because we did handle the event. If it turns out webkit |
| 152 // can't handle the event, we'll deal with it in | 154 // can't handle the event, we'll deal with it in |
| 153 // RenderView::UnhandledKeyboardEvent(). | 155 // RenderView::UnhandledKeyboardEvent(). |
| 154 return TRUE; | 156 return TRUE; |
| 155 } | 157 } |
| 156 | 158 |
| 159 // WARNING: OnGrabNotify relies on the fact this function doesn't try to | |
| 160 // dereference |focus|. | |
| 157 static gboolean OnFocusIn(GtkWidget* widget, GdkEventFocus* focus, | 161 static gboolean OnFocusIn(GtkWidget* widget, GdkEventFocus* focus, |
| 158 RenderWidgetHostViewGtk* host_view) { | 162 RenderWidgetHostViewGtk* host_view) { |
| 159 int x, y; | 163 int x, y; |
| 160 gtk_widget_get_pointer(widget, &x, &y); | 164 gtk_widget_get_pointer(widget, &x, &y); |
| 161 // http://crbug.com/13389 | 165 // http://crbug.com/13389 |
| 162 // If the cursor is in the render view, fake a mouse move event so that | 166 // If the cursor is in the render view, fake a mouse move event so that |
| 163 // webkit updates its state. Otherwise webkit might think the cursor is | 167 // webkit updates its state. Otherwise webkit might think the cursor is |
| 164 // somewhere it's not. | 168 // somewhere it's not. |
| 165 if (x >= 0 && y >= 0 && x < widget->allocation.width && | 169 if (x >= 0 && y >= 0 && x < widget->allocation.width && |
| 166 y < widget->allocation.height) { | 170 y < widget->allocation.height) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 184 // attach this GtkIMContext object to this window. | 188 // attach this GtkIMContext object to this window. |
| 185 // We should call gtk_im_context_set_client_window() only when this window | 189 // We should call gtk_im_context_set_client_window() only when this window |
| 186 // gain (or release) the window focus because an immodule may reset its | 190 // gain (or release) the window focus because an immodule may reset its |
| 187 // internal status when processing this function. | 191 // internal status when processing this function. |
| 188 gtk_im_context_focus_in(host_view->im_context_); | 192 gtk_im_context_focus_in(host_view->im_context_); |
| 189 gtk_im_context_set_client_window(host_view->im_context_, | 193 gtk_im_context_set_client_window(host_view->im_context_, |
| 190 host_view->native_view()->window); | 194 host_view->native_view()->window); |
| 191 return FALSE; | 195 return FALSE; |
| 192 } | 196 } |
| 193 | 197 |
| 198 // WARNING: OnGrabNotify relies on the fact this function doesn't try to | |
| 199 // dereference |focus|. | |
| 194 static gboolean OnFocusOut(GtkWidget* widget, GdkEventFocus* focus, | 200 static gboolean OnFocusOut(GtkWidget* widget, GdkEventFocus* focus, |
| 195 RenderWidgetHostViewGtk* host_view) { | 201 RenderWidgetHostViewGtk* host_view) { |
| 196 // Whenever we lose focus, set the cursor back to that of our parent window, | 202 // Whenever we lose focus, set the cursor back to that of our parent window, |
| 197 // which should be the default arrow. | 203 // which should be the default arrow. |
| 198 gdk_window_set_cursor(widget->window, NULL); | 204 gdk_window_set_cursor(widget->window, NULL); |
| 199 // If we are showing a context menu, maintain the illusion that webkit has | 205 // If we are showing a context menu, maintain the illusion that webkit has |
| 200 // focus. | 206 // focus. |
| 201 if (!host_view->is_showing_context_menu_) | 207 if (!host_view->is_showing_context_menu_) |
| 202 host_view->GetRenderWidgetHost()->Blur(); | 208 host_view->GetRenderWidgetHost()->Blur(); |
| 203 | 209 |
| 204 // Notify the GtkIMContext object of this focus-in event and | 210 // Notify the GtkIMContext object of this focus-in event and |
| 205 // detach this GtkIMContext object from this window. | 211 // detach this GtkIMContext object from this window. |
| 206 gtk_im_context_focus_out(host_view->im_context_); | 212 gtk_im_context_focus_out(host_view->im_context_); |
| 207 gtk_im_context_set_client_window(host_view->im_context_, NULL); | 213 gtk_im_context_set_client_window(host_view->im_context_, NULL); |
| 208 return FALSE; | 214 return FALSE; |
| 209 } | 215 } |
| 210 | 216 |
| 217 // Called when we are shadowed or unshadowed by a keyboard grab (which will | |
| 218 // occur for activatable popups, such as dropdown menus). Popup windows do not | |
| 219 // take focus, so we never get a focus out or focus in event when they are | |
| 220 // shown, and must rely on this signal instead. | |
| 221 static void OnGrabNotify(GtkWidget* widget, gboolean was_grabbed, | |
| 222 RenderWidgetHostViewGtk* host_view) { | |
| 223 if (was_grabbed) | |
|
Evan Stade
2009/07/11 01:14:06
this check seems backward, but is not
| |
| 224 OnFocusIn(widget, NULL, host_view); | |
| 225 else | |
| 226 OnFocusOut(widget, NULL, host_view); | |
| 227 } | |
| 228 | |
| 211 static gboolean ButtonPressReleaseEvent( | 229 static gboolean ButtonPressReleaseEvent( |
| 212 GtkWidget* widget, GdkEventButton* event, | 230 GtkWidget* widget, GdkEventButton* event, |
| 213 RenderWidgetHostViewGtk* host_view) { | 231 RenderWidgetHostViewGtk* host_view) { |
| 214 if (!(event->button == 1 || event->button == 2 || event->button == 3)) | 232 if (!(event->button == 1 || event->button == 2 || event->button == 3)) |
| 215 return FALSE; // We do not forward any other buttons to the renderer. | 233 return FALSE; // We do not forward any other buttons to the renderer. |
| 216 | 234 |
| 217 // We want to translate the coordinates of events that do not originate | 235 // We want to translate the coordinates of events that do not originate |
| 218 // from this widget to be relative to the top left of the widget. | 236 // from this widget to be relative to the top left of the widget. |
| 219 GtkWidget* event_widget = gtk_get_event_widget( | 237 GtkWidget* event_widget = gtk_get_event_widget( |
| 220 reinterpret_cast<GdkEvent*>(event)); | 238 reinterpret_cast<GdkEvent*>(event)); |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 708 } | 726 } |
| 709 | 727 |
| 710 gfx::PluginWindowHandle RenderWidgetHostViewGtk::CreatePluginContainer() { | 728 gfx::PluginWindowHandle RenderWidgetHostViewGtk::CreatePluginContainer() { |
| 711 return plugin_container_manager_.CreatePluginContainer(); | 729 return plugin_container_manager_.CreatePluginContainer(); |
| 712 } | 730 } |
| 713 | 731 |
| 714 void RenderWidgetHostViewGtk::DestroyPluginContainer( | 732 void RenderWidgetHostViewGtk::DestroyPluginContainer( |
| 715 gfx::PluginWindowHandle container) { | 733 gfx::PluginWindowHandle container) { |
| 716 plugin_container_manager_.DestroyPluginContainer(container); | 734 plugin_container_manager_.DestroyPluginContainer(container); |
| 717 } | 735 } |
| OLD | NEW |