| 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 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 } // namespace | 40 } // namespace |
| 41 | 41 |
| 42 bool DispatchX2Event(Widget* widget, XEvent* xev) { | 42 bool DispatchX2Event(Widget* widget, XEvent* xev) { |
| 43 XGenericEventCookie* cookie = &xev->xcookie; | 43 XGenericEventCookie* cookie = &xev->xcookie; |
| 44 switch (cookie->evtype) { | 44 switch (cookie->evtype) { |
| 45 case XI_KeyPress: | 45 case XI_KeyPress: |
| 46 case XI_KeyRelease: { | 46 case XI_KeyRelease: { |
| 47 // TODO(sad): We don't capture XInput2 events from keyboard yet. | 47 // TODO(sad): We don't capture XInput2 events from keyboard yet. |
| 48 break; | 48 break; |
| 49 } | 49 } |
| 50 case XI_ButtonPress: | 50 case XI_TouchBegin: |
| 51 case XI_ButtonRelease: | 51 case XI_TouchEnd: |
| 52 case XI_Motion: { | 52 case XI_TouchUpdate: { |
| 53 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(cookie->data); | 53 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(cookie->data); |
| 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 | |
| 57 // and 5. In case of a wheelscroll, we do not want to show the cursor. | |
| 58 if (xievent->detail == 4 || xievent->detail == 5) { | |
| 59 MouseWheelEvent wheelev(xev, from_native); | |
| 60 return widget->OnMouseEvent(wheelev); | |
| 61 } | |
| 62 | |
| 63 // Is the event coming from a touch device? | 56 // Is the event coming from a touch device? |
| 64 if (TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid)) { | 57 if (TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid)) { |
| 65 // Hide the cursor when a touch event comes in. | 58 // Hide the cursor when a touch event comes in. |
| 66 TouchFactory::GetInstance()->SetCursorVisible(false, false); | 59 TouchFactory::GetInstance()->SetCursorVisible(false, false); |
| 67 | 60 |
| 68 // With XInput 2.0, XI_ButtonPress and XI_ButtonRelease events are | |
| 69 // ignored, as XI_Motion events contain enough data to detect finger | |
| 70 // press and release. See more notes in TouchFactory::TouchParam. | |
| 71 if (cookie->evtype == XI_ButtonPress || | |
| 72 cookie->evtype == XI_ButtonRelease) | |
| 73 return false; | |
| 74 | |
| 75 // If the TouchEvent is processed by |root|, then return. Otherwise let | 61 // 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. | 62 // it fall through so it can be used as a MouseEvent, if desired. |
| 77 TouchEvent touch(xev, from_native); | 63 TouchEvent touch(xev, from_native); |
| 78 if (widget->OnTouchEvent(touch) != ui::TOUCH_STATUS_UNKNOWN) | 64 if (widget->OnTouchEvent(touch) != ui::TOUCH_STATUS_UNKNOWN) |
| 79 return true; | 65 return true; |
| 80 | 66 |
| 81 // We do not want to generate a mouse event for an unprocessed touch | 67 // 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 | 68 // event here. That is already done by the gesture manager in |
| 83 // RootView::OnTouchEvent. | 69 // RootView::OnTouchEvent. |
| 84 return false; | 70 return false; |
| 85 } else { | 71 } else { |
| 86 MouseEvent mouseev(xev, from_native); | 72 return false; |
| 87 | |
| 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. | |
| 90 bool start_timer = mouseev.type() == ui::ET_MOUSE_MOVED; | |
| 91 start_timer |= mouseev.type() == ui::ET_MOUSE_RELEASED && | |
| 92 (mouseev.IsOnlyLeftMouseButton() || | |
| 93 mouseev.IsOnlyMiddleMouseButton() || | |
| 94 mouseev.IsOnlyRightMouseButton()); | |
| 95 TouchFactory::GetInstance()->SetCursorVisible(true, start_timer); | |
| 96 | |
| 97 return widget->OnMouseEvent(mouseev); | |
| 98 } | 73 } |
| 99 } | 74 } |
| 100 } | 75 } |
| 101 return false; | 76 return false; |
| 102 } | 77 } |
| 103 | 78 |
| 104 bool DispatchXEvent(XEvent* xev) { | 79 bool DispatchXEvent(XEvent* xev) { |
| 105 GdkDisplay* gdisp = gdk_display_get_default(); | 80 GdkDisplay* gdisp = gdk_display_get_default(); |
| 106 XID xwindow = xev->xany.window; | 81 XID xwindow = xev->xany.window; |
| 107 | 82 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 AcceleratorHandler::AcceleratorHandler() {} | 140 AcceleratorHandler::AcceleratorHandler() {} |
| 166 | 141 |
| 167 base::MessagePumpDispatcher::DispatchStatus | 142 base::MessagePumpDispatcher::DispatchStatus |
| 168 AcceleratorHandler::Dispatch(XEvent* xev) { | 143 AcceleratorHandler::Dispatch(XEvent* xev) { |
| 169 return DispatchXEvent(xev) ? | 144 return DispatchXEvent(xev) ? |
| 170 base::MessagePumpDispatcher::EVENT_PROCESSED : | 145 base::MessagePumpDispatcher::EVENT_PROCESSED : |
| 171 base::MessagePumpDispatcher::EVENT_IGNORED; | 146 base::MessagePumpDispatcher::EVENT_IGNORED; |
| 172 } | 147 } |
| 173 | 148 |
| 174 } // namespace views | 149 } // namespace views |
| OLD | NEW |