Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(837)

Side by Side Diff: views/widget/widget_gtk.cc

Issue 6823055: Consolidate OnKeyEvent and InputMethod code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refactor X2Event handling, nix Windows InputMethodDelegate, etc. Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "views/widget/widget_gtk.h" 5 #include "views/widget/widget_gtk.h"
6 6
7 #include <gdk/gdk.h> 7 #include <gdk/gdk.h>
8 #include <gdk/gdkx.h> 8 #include <gdk/gdkx.h>
9 #include <X11/extensions/shape.h> 9 #include <X11/extensions/shape.h>
10 #include <X11/Xatom.h> 10 #include <X11/Xatom.h>
(...skipping 1262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 if (type_ == TYPE_CHILD) 1273 if (type_ == TYPE_CHILD)
1274 return false; 1274 return false;
1275 1275
1276 // Only top-level Widget should have an InputMethod instance. 1276 // Only top-level Widget should have an InputMethod instance.
1277 if (input_method_.get()) 1277 if (input_method_.get())
1278 input_method_->OnBlur(); 1278 input_method_->OnBlur();
1279 return false; 1279 return false;
1280 } 1280 }
1281 1281
1282 gboolean WidgetGtk::OnKeyEvent(GtkWidget* widget, GdkEventKey* event) { 1282 gboolean WidgetGtk::OnKeyEvent(GtkWidget* widget, GdkEventKey* event) {
1283 KeyEvent key(reinterpret_cast<NativeEvent>(event)); 1283 KeyEvent key_event(reinterpret_cast<NativeEvent>(event));
1284 if (input_method_.get()) 1284 delegate_->OnKeyEvent(key_event);
1285 input_method_->DispatchKeyEvent(key);
1286 else
1287 DispatchKeyEventPostIME(key);
1288
1289 // Returns true to prevent GtkWindow's default key event handler. 1285 // Returns true to prevent GtkWindow's default key event handler.
1290 return true; 1286 return true;
1291 } 1287 }
1292 1288
1293 gboolean WidgetGtk::OnQueryTooltip(GtkWidget* widget, 1289 gboolean WidgetGtk::OnQueryTooltip(GtkWidget* widget,
1294 gint x, 1290 gint x,
1295 gint y, 1291 gint y,
1296 gboolean keyboard_mode, 1292 gboolean keyboard_mode,
1297 GtkTooltip* tooltip) { 1293 GtkTooltip* tooltip) {
1298 return tooltip_manager_->ShowTooltip(x, y, keyboard_mode, tooltip); 1294 return tooltip_manager_->ShowTooltip(x, y, keyboard_mode, tooltip);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1358 1354
1359 RootView* WidgetGtk::CreateRootView() { 1355 RootView* WidgetGtk::CreateRootView() {
1360 return new RootView(this); 1356 return new RootView(this);
1361 } 1357 }
1362 1358
1363 gfx::AcceleratedWidget WidgetGtk::GetAcceleratedWidget() { 1359 gfx::AcceleratedWidget WidgetGtk::GetAcceleratedWidget() {
1364 DCHECK(window_contents_ && window_contents_->window); 1360 DCHECK(window_contents_ && window_contents_->window);
1365 return GDK_WINDOW_XID(window_contents_->window); 1361 return GDK_WINDOW_XID(window_contents_->window);
1366 } 1362 }
1367 1363
1368 void WidgetGtk::DispatchKeyEventPostIME(const KeyEvent& key) { 1364 bool WidgetGtk::DispatchKeyEventPostIME(const KeyEvent& key) {
1369 // Always reset |should_handle_menu_key_release_| unless we are handling a 1365 // Always reset |should_handle_menu_key_release_| unless we are handling a
1370 // VKEY_MENU key release event. It ensures that VKEY_MENU accelerator can only 1366 // VKEY_MENU key release event. It ensures that VKEY_MENU accelerator can only
1371 // be activated when handling a VKEY_MENU key release event which is preceded 1367 // be activated when handling a VKEY_MENU key release event which is preceded
1372 // by an unhandled VKEY_MENU key press event. See also HandleKeyboardEvent(). 1368 // by an unhandled VKEY_MENU key press event. See also HandleKeyboardEvent().
1373 if (key.key_code() != ui::VKEY_MENU || key.type() != ui::ET_KEY_RELEASED) 1369 if (key.key_code() != ui::VKEY_MENU || key.type() != ui::ET_KEY_RELEASED)
1374 should_handle_menu_key_release_ = false; 1370 should_handle_menu_key_release_ = false;
1375 1371
1376 bool handled = false; 1372 // Send the key event to View hierarchy first.
1377 1373 bool handled = GetRootView()->OnKeyEvent(key);
1378 // Dispatch the key event to View hierarchy first.
1379 handled = GetRootView()->ProcessKeyEvent(key);
1380 1374
1381 if (key.key_code() == ui::VKEY_PROCESSKEY || handled) 1375 if (key.key_code() == ui::VKEY_PROCESSKEY || handled)
1382 return; 1376 return true;
1383 1377
1384 // Dispatch the key event to native GtkWidget hierarchy. 1378 // Dispatch the key event to native GtkWidget hierarchy.
1385 // To prevent GtkWindow from handling the key event as a keybinding, we need 1379 // To prevent GtkWindow from handling the key event as a keybinding, we need
1386 // to bypass GtkWindow's default key event handler and dispatch the event 1380 // to bypass GtkWindow's default key event handler and dispatch the event
1387 // here. 1381 // here.
1388 GdkEventKey* event = reinterpret_cast<GdkEventKey*>(key.native_event()); 1382 GdkEventKey* event = reinterpret_cast<GdkEventKey*>(key.native_event());
1389 if (!handled && event && GTK_IS_WINDOW(widget_)) 1383 if (!handled && event && GTK_IS_WINDOW(widget_))
1390 handled = gtk_window_propagate_key_event(GTK_WINDOW(widget_), event); 1384 handled = gtk_window_propagate_key_event(GTK_WINDOW(widget_), event);
1391 1385
1392 // On Linux, in order to handle VKEY_MENU (Alt) accelerator key correctly and 1386 // On Linux, in order to handle VKEY_MENU (Alt) accelerator key correctly and
1393 // avoid issues like: http://crbug.com/40966 and http://crbug.com/49701, we 1387 // avoid issues like: http://crbug.com/40966 and http://crbug.com/49701, we
1394 // should only send the key event to the focus manager if it's not handled by 1388 // should only send the key event to the focus manager if it's not handled by
1395 // any View or native GtkWidget. 1389 // any View or native GtkWidget.
1396 // The flow is different when the focus is in a RenderWidgetHostViewGtk, which 1390 // The flow is different when the focus is in a RenderWidgetHostViewGtk, which
1397 // always consumes the key event and send it back to us later by calling 1391 // always consumes the key event and send it back to us later by calling
1398 // HandleKeyboardEvent() directly, if it's not handled by webkit. 1392 // HandleKeyboardEvent() directly, if it's not handled by webkit.
1399 if (!handled) 1393 if (!handled)
1400 handled = HandleKeyboardEvent(key); 1394 handled = HandleKeyboardEvent(key);
1401 1395
1402 // Dispatch the key event for bindings processing. 1396 // Dispatch the key event for bindings processing.
1403 if (!handled && event && GTK_IS_WINDOW(widget_)) 1397 if (!handled && event && GTK_IS_WINDOW(widget_))
1404 gtk_bindings_activate_event(GTK_OBJECT(widget_), event); 1398 handled = gtk_bindings_activate_event(GTK_OBJECT(widget_), event);
1399
1400 return handled;
1405 } 1401 }
1406 1402
1407 gboolean WidgetGtk::OnWindowPaint(GtkWidget* widget, GdkEventExpose* event) { 1403 gboolean WidgetGtk::OnWindowPaint(GtkWidget* widget, GdkEventExpose* event) {
1408 // Clear the background to be totally transparent. We don't need to 1404 // Clear the background to be totally transparent. We don't need to
1409 // paint the root view here as that is done by OnPaint. 1405 // paint the root view here as that is done by OnPaint.
1410 DCHECK(transparent_); 1406 DCHECK(transparent_);
1411 DrawTransparentBackground(widget, event); 1407 DrawTransparentBackground(widget, event);
1412 // The Keyboard layout view has a renderer that covers the entire 1408 // The Keyboard layout view has a renderer that covers the entire
1413 // window, which prevents OnPaint from being called on window_contents_, 1409 // window, which prevents OnPaint from being called on window_contents_,
1414 // so we need to remove the FREEZE_UPDATES property here. 1410 // so we need to remove the FREEZE_UPDATES property here.
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1735 1731
1736 NativeWidget* native_widget = GetNativeWidgetForNativeView(native_view); 1732 NativeWidget* native_widget = GetNativeWidgetForNativeView(native_view);
1737 if (native_widget) 1733 if (native_widget)
1738 children->insert(native_widget); 1734 children->insert(native_widget);
1739 gtk_container_foreach(GTK_CONTAINER(native_view), 1735 gtk_container_foreach(GTK_CONTAINER(native_view),
1740 EnumerateChildWidgetsForNativeWidgets, 1736 EnumerateChildWidgetsForNativeWidgets,
1741 reinterpret_cast<gpointer>(children)); 1737 reinterpret_cast<gpointer>(children));
1742 } 1738 }
1743 1739
1744 } // namespace views 1740 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698