| 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 #include <X11/extensions/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
| 10 | 10 |
| 11 #include "ui/base/touchui/touch_factory.h" |
| 11 #include "views/accelerator.h" | 12 #include "views/accelerator.h" |
| 12 #include "views/events/event.h" | 13 #include "views/events/event.h" |
| 13 #include "views/focus/focus_manager.h" | 14 #include "views/focus/focus_manager.h" |
| 14 #include "views/ime/input_method.h" | 15 #include "views/ime/input_method.h" |
| 15 #include "views/touchui/touch_factory.h" | |
| 16 #include "views/view.h" | 16 #include "views/view.h" |
| 17 #include "views/widget/native_widget.h" | 17 #include "views/widget/native_widget.h" |
| 18 | 18 |
| 19 namespace views { | 19 namespace views { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 Widget* FindWidgetForGdkWindow(GdkWindow* gdk_window) { | 23 Widget* FindWidgetForGdkWindow(GdkWindow* gdk_window) { |
| 24 gpointer data = NULL; | 24 gpointer data = NULL; |
| 25 gdk_window_get_user_data(gdk_window, &data); | 25 gdk_window_get_user_data(gdk_window, &data); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 54 Event::FromNativeEvent2 from_native; | 54 Event::FromNativeEvent2 from_native; |
| 55 | 55 |
| 56 // Scrolling the wheel generates press/release events with button id's 4 | 56 // Scrolling the wheel generates press/release events with button id's 4 |
| 57 // and 5. In case of a wheelscroll, we do not want to show the cursor. | 57 // and 5. In case of a wheelscroll, we do not want to show the cursor. |
| 58 if (xievent->detail == 4 || xievent->detail == 5) { | 58 if (xievent->detail == 4 || xievent->detail == 5) { |
| 59 MouseWheelEvent wheelev(xev, from_native); | 59 MouseWheelEvent wheelev(xev, from_native); |
| 60 return widget->OnMouseEvent(wheelev); | 60 return widget->OnMouseEvent(wheelev); |
| 61 } | 61 } |
| 62 | 62 |
| 63 // Is the event coming from a touch device? | 63 // Is the event coming from a touch device? |
| 64 if (TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid)) { | 64 if (ui::TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid)) { |
| 65 // Hide the cursor when a touch event comes in. | 65 // Hide the cursor when a touch event comes in. |
| 66 TouchFactory::GetInstance()->SetCursorVisible(false, false); | 66 ui::TouchFactory::GetInstance()->SetCursorVisible(false, false); |
| 67 | 67 |
| 68 // With XInput 2.0, XI_ButtonPress and XI_ButtonRelease events are | 68 // With XInput 2.0, XI_ButtonPress and XI_ButtonRelease events are |
| 69 // ignored, as XI_Motion events contain enough data to detect finger | 69 // ignored, as XI_Motion events contain enough data to detect finger |
| 70 // press and release. See more notes in TouchFactory::TouchParam. | 70 // press and release. See more notes in TouchFactory::TouchParam. |
| 71 if (cookie->evtype == XI_ButtonPress || | 71 if (cookie->evtype == XI_ButtonPress || |
| 72 cookie->evtype == XI_ButtonRelease) | 72 cookie->evtype == XI_ButtonRelease) |
| 73 return false; | 73 return false; |
| 74 | 74 |
| 75 // If the TouchEvent is processed by |root|, then return. Otherwise let | 75 // If the TouchEvent is processed by |root|, then return. Otherwise let |
| 76 // it fall through so it can be used as a MouseEvent, if desired. | 76 // it fall through so it can be used as a MouseEvent, if desired. |
| 77 TouchEvent touch(xev, from_native); | 77 TouchEvent touch(xev, from_native); |
| 78 if (widget->OnTouchEvent(touch) != ui::TOUCH_STATUS_UNKNOWN) | 78 if (widget->OnTouchEvent(touch) != ui::TOUCH_STATUS_UNKNOWN) |
| 79 return true; | 79 return true; |
| 80 | 80 |
| 81 // We do not want to generate a mouse event for an unprocessed touch | 81 // We do not want to generate a mouse event for an unprocessed touch |
| 82 // event here. That is already done by the gesture manager in | 82 // event here. That is already done by the gesture manager in |
| 83 // RootView::OnTouchEvent. | 83 // RootView::OnTouchEvent. |
| 84 return false; | 84 return false; |
| 85 } else { | 85 } else { |
| 86 MouseEvent mouseev(xev, from_native); | 86 MouseEvent mouseev(xev, from_native); |
| 87 | 87 |
| 88 // Show the cursor. Start a timer to hide the cursor after a delay on | 88 // Show the cursor. Start a timer to hide the cursor after a delay on |
| 89 // move (not drag) events, or if the only button pressed is released. | 89 // move (not drag) events, or if the only button pressed is released. |
| 90 bool start_timer = mouseev.type() == ui::ET_MOUSE_MOVED; | 90 bool start_timer = mouseev.type() == ui::ET_MOUSE_MOVED; |
| 91 start_timer |= mouseev.type() == ui::ET_MOUSE_RELEASED && | 91 start_timer |= mouseev.type() == ui::ET_MOUSE_RELEASED && |
| 92 (mouseev.IsOnlyLeftMouseButton() || | 92 (mouseev.IsOnlyLeftMouseButton() || |
| 93 mouseev.IsOnlyMiddleMouseButton() || | 93 mouseev.IsOnlyMiddleMouseButton() || |
| 94 mouseev.IsOnlyRightMouseButton()); | 94 mouseev.IsOnlyRightMouseButton()); |
| 95 TouchFactory::GetInstance()->SetCursorVisible(true, start_timer); | 95 ui::TouchFactory::GetInstance()->SetCursorVisible(true, start_timer); |
| 96 | 96 |
| 97 return widget->OnMouseEvent(mouseev); | 97 return widget->OnMouseEvent(mouseev); |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 return false; | 101 return false; |
| 102 } | 102 } |
| 103 | 103 |
| 104 bool DispatchXEvent(XEvent* xev) { | 104 bool DispatchXEvent(XEvent* xev) { |
| 105 GdkDisplay* gdisp = gdk_display_get_default(); | 105 GdkDisplay* gdisp = gdk_display_get_default(); |
| 106 XID xwindow = xev->xany.window; | 106 XID xwindow = xev->xany.window; |
| 107 | 107 |
| 108 if (xev->type == GenericEvent) { | 108 if (xev->type == GenericEvent) { |
| 109 if (!TouchFactory::GetInstance()->ShouldProcessXI2Event(xev)) | 109 if (!ui::TouchFactory::GetInstance()->ShouldProcessXI2Event(xev)) |
| 110 return true; // Consume the event. | 110 return true; // Consume the event. |
| 111 | 111 |
| 112 XGenericEventCookie* cookie = &xev->xcookie; | 112 XGenericEventCookie* cookie = &xev->xcookie; |
| 113 if (cookie->evtype == XI_HierarchyChanged) { | 113 if (cookie->evtype == XI_HierarchyChanged) { |
| 114 TouchFactory::GetInstance()->UpdateDeviceList(cookie->display); | 114 ui::TouchFactory::GetInstance()->UpdateDeviceList(cookie->display); |
| 115 return true; | 115 return true; |
| 116 } | 116 } |
| 117 | 117 |
| 118 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(cookie->data); | 118 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(cookie->data); |
| 119 xwindow = xiev->event; | 119 xwindow = xiev->event; |
| 120 } | 120 } |
| 121 | 121 |
| 122 GdkWindow* gwind = gdk_window_lookup_for_display(gdisp, xwindow); | 122 GdkWindow* gwind = gdk_window_lookup_for_display(gdisp, xwindow); |
| 123 Widget* widget = FindWidgetForGdkWindow(gwind); | 123 Widget* widget = FindWidgetForGdkWindow(gwind); |
| 124 if (widget) { | 124 if (widget) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 152 case GenericEvent: { | 152 case GenericEvent: { |
| 153 return DispatchX2Event(widget, xev); | 153 return DispatchX2Event(widget, xev); |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 | 157 |
| 158 return false; | 158 return false; |
| 159 } | 159 } |
| 160 | 160 |
| 161 void SetTouchDeviceList(std::vector<unsigned int>& devices) { | 161 void SetTouchDeviceList(std::vector<unsigned int>& devices) { |
| 162 TouchFactory::GetInstance()->SetTouchDeviceList(devices); | 162 ui::TouchFactory::GetInstance()->SetTouchDeviceList(devices); |
| 163 } | 163 } |
| 164 | 164 |
| 165 AcceleratorHandler::AcceleratorHandler() {} | 165 AcceleratorHandler::AcceleratorHandler() {} |
| 166 | 166 |
| 167 base::MessagePumpDispatcher::DispatchStatus | 167 base::MessagePumpDispatcher::DispatchStatus |
| 168 AcceleratorHandler::Dispatch(XEvent* xev) { | 168 AcceleratorHandler::Dispatch(XEvent* xev) { |
| 169 return DispatchXEvent(xev) ? | 169 return DispatchXEvent(xev) ? |
| 170 base::MessagePumpDispatcher::EVENT_PROCESSED : | 170 base::MessagePumpDispatcher::EVENT_PROCESSED : |
| 171 base::MessagePumpDispatcher::EVENT_IGNORED; | 171 base::MessagePumpDispatcher::EVENT_IGNORED; |
| 172 } | 172 } |
| 173 | 173 |
| 174 } // namespace views | 174 } // namespace views |
| OLD | NEW |