| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 | 10 |
| (...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 return; | 876 return; |
| 877 } | 877 } |
| 878 gtk_window_set_focus(GTK_WINDOW(GetNativeView()), NULL); | 878 gtk_window_set_focus(GTK_WINDOW(GetNativeView()), NULL); |
| 879 } | 879 } |
| 880 | 880 |
| 881 bool WidgetGtk::HandleKeyboardEvent(GdkEventKey* event) { | 881 bool WidgetGtk::HandleKeyboardEvent(GdkEventKey* event) { |
| 882 if (!focus_manager_) | 882 if (!focus_manager_) |
| 883 return false; | 883 return false; |
| 884 | 884 |
| 885 KeyEvent key(event); | 885 KeyEvent key(event); |
| 886 int key_code = key.GetKeyCode(); | 886 int key_code = key.key_code(); |
| 887 bool handled = false; | 887 bool handled = false; |
| 888 | 888 |
| 889 // Always reset |should_handle_menu_key_release_| unless we are handling a | 889 // Always reset |should_handle_menu_key_release_| unless we are handling a |
| 890 // VKEY_MENU key release event. It ensures that VKEY_MENU accelerator can only | 890 // VKEY_MENU key release event. It ensures that VKEY_MENU accelerator can only |
| 891 // be activated when handling a VKEY_MENU key release event which is preceded | 891 // be activated when handling a VKEY_MENU key release event which is preceded |
| 892 // by an unhandled VKEY_MENU key press event. | 892 // by an unhandled VKEY_MENU key press event. |
| 893 if (key_code != ui::VKEY_MENU || event->type != GDK_KEY_RELEASE) | 893 if (key_code != ui::VKEY_MENU || event->type != GDK_KEY_RELEASE) |
| 894 should_handle_menu_key_release_ = false; | 894 should_handle_menu_key_release_ = false; |
| 895 | 895 |
| 896 if (event->type == GDK_KEY_PRESS) { | 896 if (event->type == GDK_KEY_PRESS) { |
| 897 // VKEY_MENU is triggered by key release event. | 897 // VKEY_MENU is triggered by key release event. |
| 898 // FocusManager::OnKeyEvent() returns false when the key has been consumed. | 898 // FocusManager::OnKeyEvent() returns false when the key has been consumed. |
| 899 if (key_code != ui::VKEY_MENU) | 899 if (key_code != ui::VKEY_MENU) |
| 900 handled = !focus_manager_->OnKeyEvent(key); | 900 handled = !focus_manager_->OnKeyEvent(key); |
| 901 else | 901 else |
| 902 should_handle_menu_key_release_ = true; | 902 should_handle_menu_key_release_ = true; |
| 903 } else if (key_code == ui::VKEY_MENU && should_handle_menu_key_release_ && | 903 } else if (key_code == ui::VKEY_MENU && should_handle_menu_key_release_ && |
| 904 (key.GetFlags() & ~Event::EF_ALT_DOWN) == 0) { | 904 (key.flags() & ~Event::EF_ALT_DOWN) == 0) { |
| 905 // Trigger VKEY_MENU when only this key is pressed and released, and both | 905 // Trigger VKEY_MENU when only this key is pressed and released, and both |
| 906 // press and release events are not handled by others. | 906 // press and release events are not handled by others. |
| 907 Accelerator accelerator(ui::VKEY_MENU, false, false, false); | 907 Accelerator accelerator(ui::VKEY_MENU, false, false, false); |
| 908 handled = focus_manager_->ProcessAccelerator(accelerator); | 908 handled = focus_manager_->ProcessAccelerator(accelerator); |
| 909 } | 909 } |
| 910 | 910 |
| 911 return handled; | 911 return handled; |
| 912 } | 912 } |
| 913 | 913 |
| 914 // static | 914 // static |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1167 return false; | 1167 return false; |
| 1168 } | 1168 } |
| 1169 | 1169 |
| 1170 gboolean WidgetGtk::OnKeyEvent(GtkWidget* widget, GdkEventKey* event) { | 1170 gboolean WidgetGtk::OnKeyEvent(GtkWidget* widget, GdkEventKey* event) { |
| 1171 KeyEvent key(event); | 1171 KeyEvent key(event); |
| 1172 | 1172 |
| 1173 // Always reset |should_handle_menu_key_release_| unless we are handling a | 1173 // Always reset |should_handle_menu_key_release_| unless we are handling a |
| 1174 // VKEY_MENU key release event. It ensures that VKEY_MENU accelerator can only | 1174 // VKEY_MENU key release event. It ensures that VKEY_MENU accelerator can only |
| 1175 // be activated when handling a VKEY_MENU key release event which is preceded | 1175 // be activated when handling a VKEY_MENU key release event which is preceded |
| 1176 // by an unhandled VKEY_MENU key press event. See also HandleKeyboardEvent(). | 1176 // by an unhandled VKEY_MENU key press event. See also HandleKeyboardEvent(). |
| 1177 if (key.GetKeyCode() != ui::VKEY_MENU || event->type != GDK_KEY_RELEASE) | 1177 if (key.key_code() != ui::VKEY_MENU || event->type != GDK_KEY_RELEASE) |
| 1178 should_handle_menu_key_release_ = false; | 1178 should_handle_menu_key_release_ = false; |
| 1179 | 1179 |
| 1180 bool handled = false; | 1180 bool handled = false; |
| 1181 | 1181 |
| 1182 // Dispatch the key event to View hierarchy first. | 1182 // Dispatch the key event to View hierarchy first. |
| 1183 handled = root_view_->ProcessKeyEvent(key); | 1183 handled = root_view_->ProcessKeyEvent(key); |
| 1184 | 1184 |
| 1185 // Dispatch the key event to native GtkWidget hierarchy. | 1185 // Dispatch the key event to native GtkWidget hierarchy. |
| 1186 // To prevent GtkWindow from handling the key event as a keybinding, we need | 1186 // To prevent GtkWindow from handling the key event as a keybinding, we need |
| 1187 // to bypass GtkWindow's default key event handler and dispatch the event | 1187 // to bypass GtkWindow's default key event handler and dispatch the event |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1659 GtkWindow* window = GTK_WINDOW(element->data); | 1659 GtkWindow* window = GTK_WINDOW(element->data); |
| 1660 DCHECK(window); | 1660 DCHECK(window); |
| 1661 RootView *root_view = FindRootView(window); | 1661 RootView *root_view = FindRootView(window); |
| 1662 if (root_view) | 1662 if (root_view) |
| 1663 root_view->NotifyLocaleChanged(); | 1663 root_view->NotifyLocaleChanged(); |
| 1664 } | 1664 } |
| 1665 g_list_free(window_list); | 1665 g_list_free(window_list); |
| 1666 } | 1666 } |
| 1667 | 1667 |
| 1668 } // namespace views | 1668 } // namespace views |
| OLD | NEW |