Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: views/focus/accelerator_handler_touch.cc

Issue 7792094: touchui: support XInput2 MT (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: update patch set according to comment #12 Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 #if defined(USE_XI2_MT)
51 case XI_TouchBegin:
52 case XI_TouchEnd:
53 case XI_TouchUpdate: {
54 Event::FromNativeEvent2 from_native;
55
56 // Hide the cursor when a touch event comes in.
57 TouchFactory::GetInstance()->SetCursorVisible(false, false);
58
59 // If the TouchEvent is processed by |widget|, then return.
60 TouchEvent touch(xev, from_native);
61 if (widget->OnTouchEvent(touch) != ui::TOUCH_STATUS_UNKNOWN)
62 return true;
63
64 // We do not want to generate a mouse event for an unprocessed touch
65 // event here. That is already done by the gesture manager in
66 // RootView::OnTouchEvent.
67 return false;
68 }
sadrul 2011/09/12 16:20:38 I think you should just #endif here, and let the e
ningxin.hu 2011/09/13 00:51:08 It's a good idea. Thanks for the comment. I used
50 case XI_ButtonPress: 69 case XI_ButtonPress:
51 case XI_ButtonRelease: 70 case XI_ButtonRelease:
52 case XI_Motion: { 71 case XI_Motion: {
72 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(cookie->data);
73 Event::FromNativeEvent2 from_native;
74
75 // Scrolling the wheel generates press/release events with button id's 4
76 // and 5. In case of a wheelscroll, we do not want to show the cursor.
77 if (xievent->detail == 4 || xievent->detail == 5) {
78 MouseWheelEvent wheelev(xev, from_native);
79 return widget->OnMouseEvent(wheelev);
80 }
81
82 MouseEvent mouseev(xev, from_native);
83
84 // Show the cursor. Start a timer to hide the cursor after a delay on
85 // move (not drag) events, or if the only button pressed is released.
86 bool start_timer = mouseev.type() == ui::ET_MOUSE_MOVED;
87 start_timer |= mouseev.type() == ui::ET_MOUSE_RELEASED &&
88 (mouseev.IsOnlyLeftMouseButton() ||
89 mouseev.IsOnlyMiddleMouseButton() ||
90 mouseev.IsOnlyRightMouseButton());
91 TouchFactory::GetInstance()->SetCursorVisible(true, start_timer);
92
93 return widget->OnMouseEvent(mouseev);
94 }
95 #else
96 case XI_ButtonPress:
97 case XI_ButtonRelease:
98 case XI_Motion: {
53 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(cookie->data); 99 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(cookie->data);
54 Event::FromNativeEvent2 from_native; 100 Event::FromNativeEvent2 from_native;
55 101
56 // Scrolling the wheel generates press/release events with button id's 4 102 // 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. 103 // and 5. In case of a wheelscroll, we do not want to show the cursor.
58 if (xievent->detail == 4 || xievent->detail == 5) { 104 if (xievent->detail == 4 || xievent->detail == 5) {
59 MouseWheelEvent wheelev(xev, from_native); 105 MouseWheelEvent wheelev(xev, from_native);
60 return widget->OnMouseEvent(wheelev); 106 return widget->OnMouseEvent(wheelev);
61 } 107 }
62 108
63 // Is the event coming from a touch device? 109 // Is the event coming from a touch device?
64 if (TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid)) { 110 if (TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid)) {
65 // Hide the cursor when a touch event comes in. 111 // Hide the cursor when a touch event comes in.
66 TouchFactory::GetInstance()->SetCursorVisible(false, false); 112 TouchFactory::GetInstance()->SetCursorVisible(false, false);
67 113
68 // With XInput 2.0, XI_ButtonPress and XI_ButtonRelease events are 114 // With XInput 2.0, XI_ButtonPress and XI_ButtonRelease events are
69 // ignored, as XI_Motion events contain enough data to detect finger 115 // ignored, as XI_Motion events contain enough data to detect finger
70 // press and release. See more notes in TouchFactory::TouchParam. 116 // press and release. See more notes in TouchFactory::TouchParam.
71 if (cookie->evtype == XI_ButtonPress || 117 if (cookie->evtype == XI_ButtonPress ||
72 cookie->evtype == XI_ButtonRelease) 118 cookie->evtype == XI_ButtonRelease)
73 return false; 119 return false;
74 120
75 // If the TouchEvent is processed by |root|, then return. Otherwise let 121 // If the TouchEvent is processed by |widget|, then return. Otherwise
76 // it fall through so it can be used as a MouseEvent, if desired. 122 // let it fall through so it can be used as a MouseEvent, if desired.
sadrul 2011/09/12 16:20:38 Thanks!
ningxin.hu 2011/09/13 00:51:08 My pleasure.
77 TouchEvent touch(xev, from_native); 123 TouchEvent touch(xev, from_native);
78 if (widget->OnTouchEvent(touch) != ui::TOUCH_STATUS_UNKNOWN) 124 if (widget->OnTouchEvent(touch) != ui::TOUCH_STATUS_UNKNOWN)
79 return true; 125 return true;
80 126
81 // We do not want to generate a mouse event for an unprocessed touch 127 // 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 128 // event here. That is already done by the gesture manager in
83 // RootView::OnTouchEvent. 129 // RootView::OnTouchEvent.
84 return false; 130 return false;
85 } else { 131 } else {
86 MouseEvent mouseev(xev, from_native); 132 MouseEvent mouseev(xev, from_native);
87 133
88 // Show the cursor. Start a timer to hide the cursor after a delay on 134 // 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. 135 // move (not drag) events, or if the only button pressed is released.
90 bool start_timer = mouseev.type() == ui::ET_MOUSE_MOVED; 136 bool start_timer = mouseev.type() == ui::ET_MOUSE_MOVED;
91 start_timer |= mouseev.type() == ui::ET_MOUSE_RELEASED && 137 start_timer |= mouseev.type() == ui::ET_MOUSE_RELEASED &&
92 (mouseev.IsOnlyLeftMouseButton() || 138 (mouseev.IsOnlyLeftMouseButton() ||
93 mouseev.IsOnlyMiddleMouseButton() || 139 mouseev.IsOnlyMiddleMouseButton() ||
94 mouseev.IsOnlyRightMouseButton()); 140 mouseev.IsOnlyRightMouseButton());
95 TouchFactory::GetInstance()->SetCursorVisible(true, start_timer); 141 TouchFactory::GetInstance()->SetCursorVisible(true, start_timer);
96 142
97 return widget->OnMouseEvent(mouseev); 143 return widget->OnMouseEvent(mouseev);
98 } 144 }
99 } 145 }
146 #endif // defined(USE_XI2_MT)
sadrul 2011/09/12 16:20:38 Two-blank spaces before '//' comments.
ningxin.hu 2011/09/13 00:51:08 Thanks. Will correct it.
100 } 147 }
101 return false; 148 return false;
102 } 149 }
103 150
104 bool DispatchXEvent(XEvent* xev) { 151 bool DispatchXEvent(XEvent* xev) {
105 GdkDisplay* gdisp = gdk_display_get_default(); 152 GdkDisplay* gdisp = gdk_display_get_default();
106 XID xwindow = xev->xany.window; 153 XID xwindow = xev->xany.window;
107 154
108 if (xev->type == GenericEvent) { 155 if (xev->type == GenericEvent) {
109 if (!TouchFactory::GetInstance()->ShouldProcessXI2Event(xev)) 156 if (!TouchFactory::GetInstance()->ShouldProcessXI2Event(xev))
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 AcceleratorHandler::AcceleratorHandler() {} 212 AcceleratorHandler::AcceleratorHandler() {}
166 213
167 base::MessagePumpDispatcher::DispatchStatus 214 base::MessagePumpDispatcher::DispatchStatus
168 AcceleratorHandler::Dispatch(XEvent* xev) { 215 AcceleratorHandler::Dispatch(XEvent* xev) {
169 return DispatchXEvent(xev) ? 216 return DispatchXEvent(xev) ?
170 base::MessagePumpDispatcher::EVENT_PROCESSED : 217 base::MessagePumpDispatcher::EVENT_PROCESSED :
171 base::MessagePumpDispatcher::EVENT_IGNORED; 218 base::MessagePumpDispatcher::EVENT_IGNORED;
172 } 219 }
173 220
174 } // namespace views 221 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698