| 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/focus/accelerator_handler.h" | 5 #include "views/focus/accelerator_handler.h" |
| 6 | 6 |
| 7 #include <bitset> | 7 #include <bitset> |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 #if defined(HAVE_XINPUT2) | 9 #if defined(HAVE_XINPUT2) |
| 10 #include <X11/extensions/XInput2.h> | 10 #include <X11/extensions/XInput2.h> |
| 11 #else | 11 #else |
| 12 #include <X11/Xlib.h> | 12 #include <X11/Xlib.h> |
| 13 #endif | 13 #endif |
| 14 | 14 |
| 15 #include "views/accelerator.h" | 15 #include "views/accelerator.h" |
| 16 #include "views/events/event.h" | 16 #include "views/events/event.h" |
| 17 #include "views/focus/focus_manager.h" | 17 #include "views/focus/focus_manager.h" |
| 18 #include "views/ime/input_method.h" |
| 18 #include "views/touchui/touch_factory.h" | 19 #include "views/touchui/touch_factory.h" |
| 19 #include "views/widget/root_view.h" | 20 #include "views/widget/root_view.h" |
| 20 #include "views/widget/widget_gtk.h" | 21 #include "views/widget/widget_gtk.h" |
| 21 | 22 |
| 22 namespace views { | 23 namespace views { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 RootView* FindRootViewForGdkWindow(GdkWindow* gdk_window) { | 27 Widget* FindWidgetForGdkWindow(GdkWindow* gdk_window) { |
| 27 gpointer data = NULL; | 28 gpointer data = NULL; |
| 28 gdk_window_get_user_data(gdk_window, &data); | 29 gdk_window_get_user_data(gdk_window, &data); |
| 29 GtkWidget* gtk_widget = reinterpret_cast<GtkWidget*>(data); | 30 GtkWidget* gtk_widget = reinterpret_cast<GtkWidget*>(data); |
| 30 if (!gtk_widget || !GTK_IS_WIDGET(gtk_widget)) { | 31 if (!gtk_widget || !GTK_IS_WIDGET(gtk_widget)) { |
| 31 DLOG(WARNING) << "no GtkWidget found for that GdkWindow"; | 32 DLOG(WARNING) << "no GtkWidget found for that GdkWindow"; |
| 32 return NULL; | 33 return NULL; |
| 33 } | 34 } |
| 34 NativeWidget* widget = NativeWidget::GetNativeWidgetForNativeView(gtk_widget); | 35 NativeWidget* widget = NativeWidget::GetNativeWidgetForNativeView(gtk_widget); |
| 35 | 36 |
| 36 if (!widget) { | 37 if (!widget) { |
| 37 DLOG(WARNING) << "no WidgetGtk found for that GtkWidget"; | 38 DLOG(WARNING) << "no WidgetGtk found for that GtkWidget"; |
| 38 return NULL; | 39 return NULL; |
| 39 } | 40 } |
| 40 return widget->GetWidget()->GetRootView(); | 41 return widget->GetWidget(); |
| 41 } | 42 } |
| 42 | 43 |
| 43 #if defined(HAVE_XINPUT2) | 44 #if defined(HAVE_XINPUT2) |
| 44 bool X2EventIsTouchEvent(XEvent* xev) { | 45 bool X2EventIsTouchEvent(XEvent* xev) { |
| 45 // TODO(sad): Determine if the captured event is a touch-event. | 46 // TODO(sad): Determine if the captured event is a touch-event. |
| 46 XGenericEventCookie* cookie = &xev->xcookie; | 47 XGenericEventCookie* cookie = &xev->xcookie; |
| 47 switch (cookie->evtype) { | 48 switch (cookie->evtype) { |
| 48 case XI_ButtonPress: | 49 case XI_ButtonPress: |
| 49 case XI_ButtonRelease: | 50 case XI_ButtonRelease: |
| 50 case XI_Motion: { | 51 case XI_Motion: { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 156 |
| 156 #if defined(HAVE_XINPUT2) | 157 #if defined(HAVE_XINPUT2) |
| 157 if (xev->type == GenericEvent) { | 158 if (xev->type == GenericEvent) { |
| 158 XGenericEventCookie* cookie = &xev->xcookie; | 159 XGenericEventCookie* cookie = &xev->xcookie; |
| 159 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(cookie->data); | 160 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(cookie->data); |
| 160 xwindow = xiev->event; | 161 xwindow = xiev->event; |
| 161 } | 162 } |
| 162 #endif | 163 #endif |
| 163 | 164 |
| 164 GdkWindow* gwind = gdk_window_lookup_for_display(gdisp, xwindow); | 165 GdkWindow* gwind = gdk_window_lookup_for_display(gdisp, xwindow); |
| 165 | 166 Widget* widget = FindWidgetForGdkWindow(gwind); |
| 166 if (RootView* root = FindRootViewForGdkWindow(gwind)) { | 167 if (widget) { |
| 168 RootView* root = widget->GetRootView(); |
| 167 switch (xev->type) { | 169 switch (xev->type) { |
| 168 case KeyPress: | 170 case KeyPress: |
| 169 case KeyRelease: { | 171 case KeyRelease: { |
| 170 Event::FromNativeEvent2 from_native; | 172 Event::FromNativeEvent2 from_native; |
| 171 KeyEvent keyev(xev, from_native); | 173 KeyEvent keyev(xev, from_native); |
| 174 InputMethod* ime = widget->GetInputMethod(); |
| 175 // Always dispatch key events to the input method first, to make sure |
| 176 // that the input method's hotkeys work all time. |
| 177 if (ime) { |
| 178 ime->DispatchKeyEvent(keyev); |
| 179 return true; |
| 180 } |
| 172 return root->ProcessKeyEvent(keyev); | 181 return root->ProcessKeyEvent(keyev); |
| 173 } | 182 } |
| 174 | 183 |
| 175 case ButtonPress: | 184 case ButtonPress: |
| 176 case ButtonRelease: { | 185 case ButtonRelease: { |
| 177 if (xev->xbutton.button == 4 || xev->xbutton.button == 5) { | 186 if (xev->xbutton.button == 4 || xev->xbutton.button == 5) { |
| 178 // Scrolling the wheel triggers button press/release events. | 187 // Scrolling the wheel triggers button press/release events. |
| 179 Event::FromNativeEvent2 from_native; | 188 Event::FromNativeEvent2 from_native; |
| 180 MouseWheelEvent wheelev(xev, from_native); | 189 MouseWheelEvent wheelev(xev, from_native); |
| 181 return root->OnMouseWheel(wheelev); | 190 return root->OnMouseWheel(wheelev); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 } | 237 } |
| 229 | 238 |
| 230 base::MessagePumpGlibXDispatcher::DispatchStatus | 239 base::MessagePumpGlibXDispatcher::DispatchStatus |
| 231 AcceleratorHandler::DispatchX(XEvent* xev) { | 240 AcceleratorHandler::DispatchX(XEvent* xev) { |
| 232 return DispatchXEvent(xev) ? | 241 return DispatchXEvent(xev) ? |
| 233 base::MessagePumpGlibXDispatcher::EVENT_PROCESSED : | 242 base::MessagePumpGlibXDispatcher::EVENT_PROCESSED : |
| 234 base::MessagePumpGlibXDispatcher::EVENT_IGNORED; | 243 base::MessagePumpGlibXDispatcher::EVENT_IGNORED; |
| 235 } | 244 } |
| 236 | 245 |
| 237 } // namespace views | 246 } // namespace views |
| OLD | NEW |