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

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: Fix GdkEvent init, NativeWidgetGtk casting, and Get[Unmodified]Character checks. 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
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/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 18 matching lines...) Expand all
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_ButtonPress:
51 case XI_ButtonRelease: 51 case XI_ButtonRelease:
52 case XI_Motion: { 52 case XI_Motion: {
53 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(cookie->data); 53 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(cookie->data);
54 Event::FromNativeEvent2 from_native;
55 54
56 // Scrolling the wheel generates press/release events with button id's 4 55 // 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. 56 // and 5. In case of a wheelscroll, we do not want to show the cursor.
58 if (xievent->detail == 4 || xievent->detail == 5) { 57 if (xievent->detail == 4 || xievent->detail == 5) {
59 MouseWheelEvent wheelev(xev, from_native); 58 MouseWheelEvent wheelev(xev);
60 return widget->OnMouseEvent(wheelev); 59 return widget->OnMouseEvent(wheelev);
61 } 60 }
62 61
63 // Is the event coming from a touch device? 62 // Is the event coming from a touch device?
64 if (TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid)) { 63 if (ui::TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid)) {
65 // Hide the cursor when a touch event comes in. 64 // Hide the cursor when a touch event comes in.
66 TouchFactory::GetInstance()->SetCursorVisible(false, false); 65 ui::TouchFactory::GetInstance()->SetCursorVisible(false, false);
67 66
68 // With XInput 2.0, XI_ButtonPress and XI_ButtonRelease events are 67 // With XInput 2.0, XI_ButtonPress and XI_ButtonRelease events are
69 // ignored, as XI_Motion events contain enough data to detect finger 68 // ignored, as XI_Motion events contain enough data to detect finger
70 // press and release. See more notes in TouchFactory::TouchParam. 69 // press and release. See more notes in TouchFactory::TouchParam.
71 if (cookie->evtype == XI_ButtonPress || 70 if (cookie->evtype == XI_ButtonPress ||
72 cookie->evtype == XI_ButtonRelease) 71 cookie->evtype == XI_ButtonRelease)
73 return false; 72 return false;
74 73
75 // If the TouchEvent is processed by |root|, then return. Otherwise let 74 // 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. 75 // it fall through so it can be used as a MouseEvent, if desired.
77 TouchEvent touch(xev, from_native); 76 TouchEvent touch(xev);
78 if (widget->OnTouchEvent(touch) != ui::TOUCH_STATUS_UNKNOWN) 77 if (widget->OnTouchEvent(touch) != ui::TOUCH_STATUS_UNKNOWN)
79 return true; 78 return true;
80 79
81 // We do not want to generate a mouse event for an unprocessed touch 80 // 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 81 // event here. That is already done by the gesture manager in
83 // RootView::OnTouchEvent. 82 // RootView::OnTouchEvent.
84 return false; 83 return false;
85 } else { 84 } else {
86 MouseEvent mouseev(xev, from_native); 85 MouseEvent mouseev(xev);
87 86
88 // Show the cursor. Start a timer to hide the cursor after a delay on 87 // 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. 88 // move (not drag) events, or if the only button pressed is released.
90 bool start_timer = mouseev.type() == ui::ET_MOUSE_MOVED; 89 bool start_timer = mouseev.type() == ui::ET_MOUSE_MOVED;
91 start_timer |= mouseev.type() == ui::ET_MOUSE_RELEASED && 90 start_timer |= mouseev.type() == ui::ET_MOUSE_RELEASED &&
92 (mouseev.IsOnlyLeftMouseButton() || 91 (mouseev.IsOnlyLeftMouseButton() ||
93 mouseev.IsOnlyMiddleMouseButton() || 92 mouseev.IsOnlyMiddleMouseButton() ||
94 mouseev.IsOnlyRightMouseButton()); 93 mouseev.IsOnlyRightMouseButton());
95 TouchFactory::GetInstance()->SetCursorVisible(true, start_timer); 94 ui::TouchFactory::GetInstance()->SetCursorVisible(true, start_timer);
96 95
97 return widget->OnMouseEvent(mouseev); 96 return widget->OnMouseEvent(mouseev);
98 } 97 }
99 } 98 }
100 } 99 }
101 return false; 100 return false;
102 } 101 }
103 102
104 bool DispatchXEvent(XEvent* xev) { 103 bool DispatchXEvent(XEvent* xev) {
105 GdkDisplay* gdisp = gdk_display_get_default(); 104 GdkDisplay* gdisp = gdk_display_get_default();
106 XID xwindow = xev->xany.window; 105 XID xwindow = xev->xany.window;
107 106
108 if (xev->type == GenericEvent) { 107 if (xev->type == GenericEvent) {
109 if (!TouchFactory::GetInstance()->ShouldProcessXI2Event(xev)) 108 if (!ui::TouchFactory::GetInstance()->ShouldProcessXI2Event(xev))
110 return true; // Consume the event. 109 return true; // Consume the event.
111 110
112 XGenericEventCookie* cookie = &xev->xcookie; 111 XGenericEventCookie* cookie = &xev->xcookie;
113 if (cookie->evtype == XI_HierarchyChanged) { 112 if (cookie->evtype == XI_HierarchyChanged) {
114 TouchFactory::GetInstance()->UpdateDeviceList(cookie->display); 113 ui::TouchFactory::GetInstance()->UpdateDeviceList(cookie->display);
115 return true; 114 return true;
116 } 115 }
117 116
118 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(cookie->data); 117 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(cookie->data);
119 xwindow = xiev->event; 118 xwindow = xiev->event;
120 } 119 }
121 120
122 GdkWindow* gwind = gdk_window_lookup_for_display(gdisp, xwindow); 121 GdkWindow* gwind = gdk_window_lookup_for_display(gdisp, xwindow);
123 Widget* widget = FindWidgetForGdkWindow(gwind); 122 Widget* widget = FindWidgetForGdkWindow(gwind);
124 if (widget) { 123 if (widget) {
125 Event::FromNativeEvent2 from_native;
126 switch (xev->type) { 124 switch (xev->type) {
127 case KeyPress: 125 case KeyPress:
128 case KeyRelease: { 126 case KeyRelease: {
129 KeyEvent keyev(xev, from_native); 127 KeyEvent keyev(xev);
130 InputMethod* ime = widget->GetInputMethod(); 128 InputMethod* ime = widget->GetInputMethod();
131 // Always dispatch key events to the input method first, to make sure 129 // Always dispatch key events to the input method first, to make sure
132 // that the input method's hotkeys work all time. 130 // that the input method's hotkeys work all time.
133 if (ime) { 131 if (ime) {
134 ime->DispatchKeyEvent(keyev); 132 ime->DispatchKeyEvent(keyev);
135 return true; 133 return true;
136 } 134 }
137 return widget->OnKeyEvent(keyev); 135 return widget->OnKeyEvent(keyev);
138 } 136 }
139 case ButtonPress: 137 case ButtonPress:
140 case ButtonRelease: 138 case ButtonRelease:
141 if (xev->xbutton.button == 4 || xev->xbutton.button == 5) { 139 if (xev->xbutton.button == 4 || xev->xbutton.button == 5) {
142 // Scrolling the wheel triggers button press/release events. 140 // Scrolling the wheel triggers button press/release events.
143 MouseWheelEvent wheelev(xev, from_native); 141 MouseWheelEvent wheelev(xev);
144 return widget->OnMouseEvent(wheelev); 142 return widget->OnMouseEvent(wheelev);
145 } 143 }
146 // fallthrough 144 // fallthrough
147 case MotionNotify: { 145 case MotionNotify: {
148 MouseEvent mouseev(xev, from_native); 146 MouseEvent mouseev(xev);
149 return widget->OnMouseEvent(mouseev); 147 return widget->OnMouseEvent(mouseev);
150 } 148 }
151 149
152 case GenericEvent: { 150 case GenericEvent: {
153 return DispatchX2Event(widget, xev); 151 return DispatchX2Event(widget, xev);
154 } 152 }
155 } 153 }
156 } 154 }
157 155
158 return false; 156 return false;
159 } 157 }
160 158
161 void SetTouchDeviceList(std::vector<unsigned int>& devices) { 159 void SetTouchDeviceList(std::vector<unsigned int>& devices) {
162 TouchFactory::GetInstance()->SetTouchDeviceList(devices); 160 ui::TouchFactory::GetInstance()->SetTouchDeviceList(devices);
163 } 161 }
164 162
165 AcceleratorHandler::AcceleratorHandler() {} 163 AcceleratorHandler::AcceleratorHandler() {}
166 164
167 base::MessagePumpDispatcher::DispatchStatus 165 base::MessagePumpDispatcher::DispatchStatus
168 AcceleratorHandler::Dispatch(XEvent* xev) { 166 AcceleratorHandler::Dispatch(XEvent* xev) {
169 return DispatchXEvent(xev) ? 167 return DispatchXEvent(xev) ?
170 base::MessagePumpDispatcher::EVENT_PROCESSED : 168 base::MessagePumpDispatcher::EVENT_PROCESSED :
171 base::MessagePumpDispatcher::EVENT_IGNORED; 169 base::MessagePumpDispatcher::EVENT_IGNORED;
172 } 170 }
173 171
174 } // namespace views 172 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698