| OLD | NEW |
| 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 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 g_signal_connect(widget_, "map", | 608 g_signal_connect(widget_, "map", |
| 609 G_CALLBACK(&OnMapThunk), this); | 609 G_CALLBACK(&OnMapThunk), this); |
| 610 g_signal_connect(widget_, "hide", | 610 g_signal_connect(widget_, "hide", |
| 611 G_CALLBACK(&OnHideThunk), this); | 611 G_CALLBACK(&OnHideThunk), this); |
| 612 | 612 |
| 613 // Views/FocusManager (re)sets the focus to the root window, | 613 // Views/FocusManager (re)sets the focus to the root window, |
| 614 // so we need to connect signal handlers to the gtk window. | 614 // so we need to connect signal handlers to the gtk window. |
| 615 // See views::Views::Focus and views::FocusManager::ClearNativeFocus | 615 // See views::Views::Focus and views::FocusManager::ClearNativeFocus |
| 616 // for more details. | 616 // for more details. |
| 617 g_signal_connect(widget_, "key_press_event", | 617 g_signal_connect(widget_, "key_press_event", |
| 618 G_CALLBACK(&OnKeyEventThunk), this); | 618 G_CALLBACK(&OnEventKeyThunk), this); |
| 619 g_signal_connect(widget_, "key_release_event", | 619 g_signal_connect(widget_, "key_release_event", |
| 620 G_CALLBACK(&OnKeyEventThunk), this); | 620 G_CALLBACK(&OnEventKeyThunk), this); |
| 621 | 621 |
| 622 // Drag and drop. | 622 // Drag and drop. |
| 623 gtk_drag_dest_set(window_contents_, static_cast<GtkDestDefaults>(0), | 623 gtk_drag_dest_set(window_contents_, static_cast<GtkDestDefaults>(0), |
| 624 NULL, 0, GDK_ACTION_COPY); | 624 NULL, 0, GDK_ACTION_COPY); |
| 625 g_signal_connect(window_contents_, "drag_motion", | 625 g_signal_connect(window_contents_, "drag_motion", |
| 626 G_CALLBACK(&OnDragMotionThunk), this); | 626 G_CALLBACK(&OnDragMotionThunk), this); |
| 627 g_signal_connect(window_contents_, "drag_data_received", | 627 g_signal_connect(window_contents_, "drag_data_received", |
| 628 G_CALLBACK(&OnDragDataReceivedThunk), this); | 628 G_CALLBACK(&OnDragDataReceivedThunk), this); |
| 629 g_signal_connect(window_contents_, "drag_drop", | 629 g_signal_connect(window_contents_, "drag_drop", |
| 630 G_CALLBACK(&OnDragDropThunk), this); | 630 G_CALLBACK(&OnDragDropThunk), this); |
| (...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1284 | 1284 |
| 1285 if (type_ == TYPE_CHILD) | 1285 if (type_ == TYPE_CHILD) |
| 1286 return false; | 1286 return false; |
| 1287 | 1287 |
| 1288 // Only top-level Widget should have an InputMethod instance. | 1288 // Only top-level Widget should have an InputMethod instance. |
| 1289 if (input_method_.get()) | 1289 if (input_method_.get()) |
| 1290 input_method_->OnBlur(); | 1290 input_method_->OnBlur(); |
| 1291 return false; | 1291 return false; |
| 1292 } | 1292 } |
| 1293 | 1293 |
| 1294 gboolean WidgetGtk::OnKeyEvent(GtkWidget* widget, GdkEventKey* event) { | 1294 gboolean WidgetGtk::OnEventKey(GtkWidget* widget, GdkEventKey* event) { |
| 1295 KeyEvent key(reinterpret_cast<NativeEvent>(event)); | 1295 KeyEvent key(reinterpret_cast<NativeEvent>(event)); |
| 1296 if (input_method_.get()) | 1296 if (input_method_.get()) |
| 1297 input_method_->DispatchKeyEvent(key); | 1297 input_method_->DispatchKeyEvent(key); |
| 1298 else | 1298 else |
| 1299 DispatchKeyEventPostIME(key); | 1299 DispatchKeyEventPostIME(key); |
| 1300 | 1300 |
| 1301 // Returns true to prevent GtkWindow's default key event handler. | 1301 // Returns true to prevent GtkWindow's default key event handler. |
| 1302 return true; | 1302 return true; |
| 1303 } | 1303 } |
| 1304 | 1304 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1378 } | 1378 } |
| 1379 | 1379 |
| 1380 void WidgetGtk::DispatchKeyEventPostIME(const KeyEvent& key) { | 1380 void WidgetGtk::DispatchKeyEventPostIME(const KeyEvent& key) { |
| 1381 // Always reset |should_handle_menu_key_release_| unless we are handling a | 1381 // Always reset |should_handle_menu_key_release_| unless we are handling a |
| 1382 // VKEY_MENU key release event. It ensures that VKEY_MENU accelerator can only | 1382 // VKEY_MENU key release event. It ensures that VKEY_MENU accelerator can only |
| 1383 // be activated when handling a VKEY_MENU key release event which is preceded | 1383 // be activated when handling a VKEY_MENU key release event which is preceded |
| 1384 // by an unhandled VKEY_MENU key press event. See also HandleKeyboardEvent(). | 1384 // by an unhandled VKEY_MENU key press event. See also HandleKeyboardEvent(). |
| 1385 if (key.key_code() != ui::VKEY_MENU || key.type() != ui::ET_KEY_RELEASED) | 1385 if (key.key_code() != ui::VKEY_MENU || key.type() != ui::ET_KEY_RELEASED) |
| 1386 should_handle_menu_key_release_ = false; | 1386 should_handle_menu_key_release_ = false; |
| 1387 | 1387 |
| 1388 bool handled = false; | 1388 // Send the key event to View hierarchy first. |
| 1389 | 1389 bool handled = delegate_->OnKeyEvent(key); |
| 1390 // Dispatch the key event to View hierarchy first. | |
| 1391 handled = GetRootView()->ProcessKeyEvent(key); | |
| 1392 | 1390 |
| 1393 if (key.key_code() == ui::VKEY_PROCESSKEY || handled) | 1391 if (key.key_code() == ui::VKEY_PROCESSKEY || handled) |
| 1394 return; | 1392 return; |
| 1395 | 1393 |
| 1396 // Dispatch the key event to native GtkWidget hierarchy. | 1394 // Dispatch the key event to native GtkWidget hierarchy. |
| 1397 // To prevent GtkWindow from handling the key event as a keybinding, we need | 1395 // To prevent GtkWindow from handling the key event as a keybinding, we need |
| 1398 // to bypass GtkWindow's default key event handler and dispatch the event | 1396 // to bypass GtkWindow's default key event handler and dispatch the event |
| 1399 // here. | 1397 // here. |
| 1400 GdkEventKey* event = reinterpret_cast<GdkEventKey*>(key.native_event()); | 1398 GdkEventKey* event = reinterpret_cast<GdkEventKey*>(key.native_event()); |
| 1401 if (!handled && event && GTK_IS_WINDOW(widget_)) | 1399 if (!handled && event && GTK_IS_WINDOW(widget_)) |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1747 | 1745 |
| 1748 NativeWidget* native_widget = GetNativeWidgetForNativeView(native_view); | 1746 NativeWidget* native_widget = GetNativeWidgetForNativeView(native_view); |
| 1749 if (native_widget) | 1747 if (native_widget) |
| 1750 children->insert(native_widget); | 1748 children->insert(native_widget); |
| 1751 gtk_container_foreach(GTK_CONTAINER(native_view), | 1749 gtk_container_foreach(GTK_CONTAINER(native_view), |
| 1752 EnumerateChildWidgetsForNativeWidgets, | 1750 EnumerateChildWidgetsForNativeWidgets, |
| 1753 reinterpret_cast<gpointer>(children)); | 1751 reinterpret_cast<gpointer>(children)); |
| 1754 } | 1752 } |
| 1755 | 1753 |
| 1756 } // namespace views | 1754 } // namespace views |
| OLD | NEW |