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

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

Issue 7942004: Consolidate/cleanup event cracking code; single out GdkEvents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge removal of compact nav. Created 9 years, 2 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
« no previous file with comments | « views/events/event_x.cc ('k') | views/ime/input_method_gtk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 #include "ui/base/touch/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 21 matching lines...) Expand all
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) 50 #if defined(USE_XI2_MT)
51 case XI_TouchBegin: 51 case XI_TouchBegin:
52 case XI_TouchEnd: 52 case XI_TouchEnd:
53 case XI_TouchUpdate: { 53 case XI_TouchUpdate: {
54 Event::FromNativeEvent2 from_native; 54 Event::FromNativeEvent2 from_native;
55 55
56 // Hide the cursor when a touch event comes in. 56 // Hide the cursor when a touch event comes in.
57 TouchFactory::GetInstance()->SetCursorVisible(false, false); 57 ui::TouchFactory::GetInstance()->SetCursorVisible(false, false);
58 58
59 // If the TouchEvent is processed by |widget|, then return. 59 // If the TouchEvent is processed by |widget|, then return.
60 TouchEvent touch(xev, from_native); 60 TouchEvent touch(xev, from_native);
61 if (widget->OnTouchEvent(touch) != ui::TOUCH_STATUS_UNKNOWN) 61 if (widget->OnTouchEvent(touch) != ui::TOUCH_STATUS_UNKNOWN)
62 return true; 62 return true;
63 63
64 // We do not want to generate a mouse event for an unprocessed touch 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 65 // event here. That is already done by the gesture manager in
66 // RootView::OnTouchEvent. 66 // RootView::OnTouchEvent.
67 return false; 67 return false;
68 } 68 }
69 #endif 69 #endif
70 case XI_ButtonPress: 70 case XI_ButtonPress:
71 case XI_ButtonRelease: 71 case XI_ButtonRelease:
72 case XI_Motion: { 72 case XI_Motion: {
73 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(cookie->data); 73 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(cookie->data);
74 Event::FromNativeEvent2 from_native;
75 74
76 // Scrolling the wheel generates press/release events with button id's 4 75 // Scrolling the wheel generates press/release events with button id's 4
77 // and 5. In case of a wheelscroll, we do not want to show the cursor. 76 // and 5. In case of a wheelscroll, we do not want to show the cursor.
78 if (xievent->detail == 4 || xievent->detail == 5) { 77 if (xievent->detail == 4 || xievent->detail == 5) {
79 MouseWheelEvent wheelev(xev, from_native); 78 MouseWheelEvent wheelev(xev);
80 return widget->OnMouseEvent(wheelev); 79 return widget->OnMouseEvent(wheelev);
81 } 80 }
82 81
83 // Is the event coming from a touch device? 82 // Is the event coming from a touch device?
84 if (TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid)) { 83 if (ui::TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid)) {
85 // Hide the cursor when a touch event comes in. 84 // Hide the cursor when a touch event comes in.
86 TouchFactory::GetInstance()->SetCursorVisible(false, false); 85 ui::TouchFactory::GetInstance()->SetCursorVisible(false, false);
87 86
88 // With XInput 2.0, XI_ButtonPress and XI_ButtonRelease events are 87 // With XInput 2.0, XI_ButtonPress and XI_ButtonRelease events are
89 // ignored, as XI_Motion events contain enough data to detect finger 88 // ignored, as XI_Motion events contain enough data to detect finger
90 // press and release. See more notes in TouchFactory::TouchParam. 89 // press and release. See more notes in TouchFactory::TouchParam.
91 if (cookie->evtype == XI_ButtonPress || 90 if (cookie->evtype == XI_ButtonPress ||
92 cookie->evtype == XI_ButtonRelease) 91 cookie->evtype == XI_ButtonRelease)
93 return false; 92 return false;
94 93
95 // If the TouchEvent is processed by |widget|, then return. Otherwise 94 // If the TouchEvent is processed by |widget|, then return. Otherwise
96 // let it fall through so it can be used as a MouseEvent, if desired. 95 // let it fall through so it can be used as a MouseEvent, if desired.
97 TouchEvent touch(xev, from_native); 96 TouchEvent touch(xev);
98 if (widget->OnTouchEvent(touch) != ui::TOUCH_STATUS_UNKNOWN) 97 if (widget->OnTouchEvent(touch) != ui::TOUCH_STATUS_UNKNOWN)
99 return true; 98 return true;
100 99
101 // We do not want to generate a mouse event for an unprocessed touch 100 // We do not want to generate a mouse event for an unprocessed touch
102 // event here. That is already done by the gesture manager in 101 // event here. That is already done by the gesture manager in
103 // RootView::OnTouchEvent. 102 // RootView::OnTouchEvent.
104 return false; 103 return false;
105 } else { 104 } else {
106 MouseEvent mouseev(xev, from_native); 105 MouseEvent mouseev(xev);
107 106
108 // Show the cursor. Start a timer to hide the cursor after a delay on 107 // Show the cursor. Start a timer to hide the cursor after a delay on
109 // move (not drag) events, or if the only button pressed is released. 108 // move (not drag) events, or if the only button pressed is released.
110 bool start_timer = mouseev.type() == ui::ET_MOUSE_MOVED; 109 bool start_timer = mouseev.type() == ui::ET_MOUSE_MOVED;
111 start_timer |= mouseev.type() == ui::ET_MOUSE_RELEASED && 110 start_timer |= mouseev.type() == ui::ET_MOUSE_RELEASED &&
112 (mouseev.IsOnlyLeftMouseButton() || 111 (mouseev.IsOnlyLeftMouseButton() ||
113 mouseev.IsOnlyMiddleMouseButton() || 112 mouseev.IsOnlyMiddleMouseButton() ||
114 mouseev.IsOnlyRightMouseButton()); 113 mouseev.IsOnlyRightMouseButton());
115 TouchFactory::GetInstance()->SetCursorVisible(true, start_timer); 114 ui::TouchFactory::GetInstance()->SetCursorVisible(true, start_timer);
116 115
117 return widget->OnMouseEvent(mouseev); 116 return widget->OnMouseEvent(mouseev);
118 } 117 }
119 } 118 }
120 } 119 }
121 return false; 120 return false;
122 } 121 }
123 122
124 bool DispatchXEvent(XEvent* xev) { 123 bool DispatchXEvent(XEvent* xev) {
125 GdkDisplay* gdisp = gdk_display_get_default(); 124 GdkDisplay* gdisp = gdk_display_get_default();
126 XID xwindow = xev->xany.window; 125 XID xwindow = xev->xany.window;
127 126
128 if (xev->type == GenericEvent) { 127 if (xev->type == GenericEvent) {
129 if (!TouchFactory::GetInstance()->ShouldProcessXI2Event(xev)) 128 if (!ui::TouchFactory::GetInstance()->ShouldProcessXI2Event(xev))
130 return true; // Consume the event. 129 return true; // Consume the event.
131 130
132 XGenericEventCookie* cookie = &xev->xcookie; 131 XGenericEventCookie* cookie = &xev->xcookie;
133 if (cookie->evtype == XI_HierarchyChanged) { 132 if (cookie->evtype == XI_HierarchyChanged) {
134 TouchFactory::GetInstance()->UpdateDeviceList(cookie->display); 133 ui::TouchFactory::GetInstance()->UpdateDeviceList(cookie->display);
135 return true; 134 return true;
136 } 135 }
137 136
138 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(cookie->data); 137 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(cookie->data);
139 xwindow = xiev->event; 138 xwindow = xiev->event;
140 } 139 }
141 140
142 GdkWindow* gwind = gdk_window_lookup_for_display(gdisp, xwindow); 141 GdkWindow* gwind = gdk_window_lookup_for_display(gdisp, xwindow);
143 Widget* widget = FindWidgetForGdkWindow(gwind); 142 Widget* widget = FindWidgetForGdkWindow(gwind);
144 if (widget) { 143 if (widget) {
145 Event::FromNativeEvent2 from_native;
146 switch (xev->type) { 144 switch (xev->type) {
147 case KeyPress: 145 case KeyPress:
148 case KeyRelease: { 146 case KeyRelease: {
149 KeyEvent keyev(xev, from_native); 147 KeyEvent keyev(xev);
150 InputMethod* ime = widget->GetInputMethod(); 148 InputMethod* ime = widget->GetInputMethod();
151 // Always dispatch key events to the input method first, to make sure 149 // Always dispatch key events to the input method first, to make sure
152 // that the input method's hotkeys work all time. 150 // that the input method's hotkeys work all time.
153 if (ime) { 151 if (ime) {
154 ime->DispatchKeyEvent(keyev); 152 ime->DispatchKeyEvent(keyev);
155 return true; 153 return true;
156 } 154 }
157 return widget->OnKeyEvent(keyev); 155 return widget->OnKeyEvent(keyev);
158 } 156 }
159 case ButtonPress: 157 case ButtonPress:
160 case ButtonRelease: 158 case ButtonRelease:
161 if (xev->xbutton.button == 4 || xev->xbutton.button == 5) { 159 if (xev->xbutton.button == 4 || xev->xbutton.button == 5) {
162 // Scrolling the wheel triggers button press/release events. 160 // Scrolling the wheel triggers button press/release events.
163 MouseWheelEvent wheelev(xev, from_native); 161 MouseWheelEvent wheelev(xev);
164 return widget->OnMouseEvent(wheelev); 162 return widget->OnMouseEvent(wheelev);
165 } 163 }
166 // fallthrough 164 // fallthrough
167 case MotionNotify: { 165 case MotionNotify: {
168 MouseEvent mouseev(xev, from_native); 166 MouseEvent mouseev(xev);
169 return widget->OnMouseEvent(mouseev); 167 return widget->OnMouseEvent(mouseev);
170 } 168 }
171 169
172 case GenericEvent: { 170 case GenericEvent: {
173 return DispatchX2Event(widget, xev); 171 return DispatchX2Event(widget, xev);
174 } 172 }
175 } 173 }
176 } 174 }
177 175
178 return false; 176 return false;
179 } 177 }
180 178
181 void SetTouchDeviceList(std::vector<unsigned int>& devices) { 179 void SetTouchDeviceList(std::vector<unsigned int>& devices) {
182 TouchFactory::GetInstance()->SetTouchDeviceList(devices); 180 ui::TouchFactory::GetInstance()->SetTouchDeviceList(devices);
183 } 181 }
184 182
185 AcceleratorHandler::AcceleratorHandler() {} 183 AcceleratorHandler::AcceleratorHandler() {}
186 184
187 base::MessagePumpDispatcher::DispatchStatus 185 base::MessagePumpDispatcher::DispatchStatus
188 AcceleratorHandler::Dispatch(XEvent* xev) { 186 AcceleratorHandler::Dispatch(XEvent* xev) {
189 return DispatchXEvent(xev) ? 187 return DispatchXEvent(xev) ?
190 base::MessagePumpDispatcher::EVENT_PROCESSED : 188 base::MessagePumpDispatcher::EVENT_PROCESSED :
191 base::MessagePumpDispatcher::EVENT_IGNORED; 189 base::MessagePumpDispatcher::EVENT_IGNORED;
192 } 190 }
193 191
194 } // namespace views 192 } // namespace views
OLDNEW
« no previous file with comments | « views/events/event_x.cc ('k') | views/ime/input_method_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698