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

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

Issue 6675005: Integrate the new input method API for Views into Chromium. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix trybot failures. Created 9 years, 9 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 #if defined(HAVE_XINPUT2) 9 #if defined(HAVE_XINPUT2)
10 #include <X11/extensions/XInput2.h> 10 #include <X11/extensions/XInput2.h>
11 #else 11 #else
12 #include <X11/Xlib.h> 12 #include <X11/Xlib.h>
13 #endif 13 #endif
14 14
15 #include "views/accelerator.h" 15 #include "views/accelerator.h"
16 #include "views/events/event.h" 16 #include "views/events/event.h"
17 #include "views/focus/focus_manager.h" 17 #include "views/focus/focus_manager.h"
18 #include "views/ime/input_method.h"
18 #include "views/touchui/touch_factory.h" 19 #include "views/touchui/touch_factory.h"
19 #include "views/widget/root_view.h" 20 #include "views/widget/root_view.h"
20 #include "views/widget/widget_gtk.h" 21 #include "views/widget/widget_gtk.h"
21 22
22 namespace views { 23 namespace views {
23 24
24 namespace { 25 namespace {
25 26
26 RootView* FindRootViewForGdkWindow(GdkWindow* gdk_window) { 27 Widget* FindWidgetForGdkWindow(GdkWindow* gdk_window) {
27 gpointer data = NULL; 28 gpointer data = NULL;
28 gdk_window_get_user_data(gdk_window, &data); 29 gdk_window_get_user_data(gdk_window, &data);
29 GtkWidget* gtk_widget = reinterpret_cast<GtkWidget*>(data); 30 GtkWidget* gtk_widget = reinterpret_cast<GtkWidget*>(data);
30 if (!gtk_widget || !GTK_IS_WIDGET(gtk_widget)) { 31 if (!gtk_widget || !GTK_IS_WIDGET(gtk_widget)) {
31 DLOG(WARNING) << "no GtkWidget found for that GdkWindow"; 32 DLOG(WARNING) << "no GtkWidget found for that GdkWindow";
32 return NULL; 33 return NULL;
33 } 34 }
34 NativeWidget* widget = NativeWidget::GetNativeWidgetForNativeView(gtk_widget); 35 NativeWidget* widget = NativeWidget::GetNativeWidgetForNativeView(gtk_widget);
35 36
36 if (!widget) { 37 if (!widget) {
37 DLOG(WARNING) << "no WidgetGtk found for that GtkWidget"; 38 DLOG(WARNING) << "no WidgetGtk found for that GtkWidget";
38 return NULL; 39 return NULL;
39 } 40 }
40 return widget->GetWidget()->GetRootView(); 41 return widget->GetWidget();
41 } 42 }
42 43
43 #if defined(HAVE_XINPUT2) 44 #if defined(HAVE_XINPUT2)
44 bool X2EventIsTouchEvent(XEvent* xev) { 45 bool X2EventIsTouchEvent(XEvent* xev) {
45 // TODO(sad): Determine if the captured event is a touch-event. 46 // TODO(sad): Determine if the captured event is a touch-event.
46 XGenericEventCookie* cookie = &xev->xcookie; 47 XGenericEventCookie* cookie = &xev->xcookie;
47 switch (cookie->evtype) { 48 switch (cookie->evtype) {
48 case XI_ButtonPress: 49 case XI_ButtonPress:
49 case XI_ButtonRelease: 50 case XI_ButtonRelease:
50 case XI_Motion: { 51 case XI_Motion: {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 #if defined(HAVE_XINPUT2) 157 #if defined(HAVE_XINPUT2)
157 if (xev->type == GenericEvent) { 158 if (xev->type == GenericEvent) {
158 XGenericEventCookie* cookie = &xev->xcookie; 159 XGenericEventCookie* cookie = &xev->xcookie;
159 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(cookie->data); 160 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(cookie->data);
160 xwindow = xiev->event; 161 xwindow = xiev->event;
161 } 162 }
162 #endif 163 #endif
163 164
164 GdkWindow* gwind = gdk_window_lookup_for_display(gdisp, xwindow); 165 GdkWindow* gwind = gdk_window_lookup_for_display(gdisp, xwindow);
165 166
166 if (RootView* root = FindRootViewForGdkWindow(gwind)) { 167 if (Widget* widget = FindWidgetForGdkWindow(gwind)) {
Ben Goodger (Google) 2011/03/22 20:49:30 Can you pull this out to the line above... Widget
James Su 2011/03/22 22:35:39 Done.
168 RootView* root = widget->GetRootView();
167 switch (xev->type) { 169 switch (xev->type) {
168 case KeyPress: 170 case KeyPress:
169 case KeyRelease: { 171 case KeyRelease: {
170 Event::FromNativeEvent2 from_native; 172 Event::FromNativeEvent2 from_native;
171 KeyEvent keyev(xev, from_native); 173 KeyEvent keyev(xev, from_native);
174 InputMethod* ime = widget->GetInputMethod();
175 // Only dispatch the key event to the input method if the focused view
176 // supports text input, then we can safely return true to prevent the
177 // event from being dispatched to Gtk native widgets.
178 // TODO(suzhe): remove it after getting rid of Gtk.
179 if (ime &&
180 widget->GetFocusManager()->GetFocusedView()->GetTextInputClient()) {
181 ime->DispatchKeyEvent(keyev);
182 return true;
183 }
172 return root->ProcessKeyEvent(keyev); 184 return root->ProcessKeyEvent(keyev);
173 } 185 }
174 186
175 case ButtonPress: 187 case ButtonPress:
176 case ButtonRelease: { 188 case ButtonRelease: {
177 if (xev->xbutton.button == 4 || xev->xbutton.button == 5) { 189 if (xev->xbutton.button == 4 || xev->xbutton.button == 5) {
178 // Scrolling the wheel triggers button press/release events. 190 // Scrolling the wheel triggers button press/release events.
179 Event::FromNativeEvent2 from_native; 191 Event::FromNativeEvent2 from_native;
180 MouseWheelEvent wheelev(xev, from_native); 192 MouseWheelEvent wheelev(xev, from_native);
181 return root->OnMouseWheel(wheelev); 193 return root->OnMouseWheel(wheelev);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 240 }
229 241
230 base::MessagePumpGlibXDispatcher::DispatchStatus 242 base::MessagePumpGlibXDispatcher::DispatchStatus
231 AcceleratorHandler::DispatchX(XEvent* xev) { 243 AcceleratorHandler::DispatchX(XEvent* xev) {
232 return DispatchXEvent(xev) ? 244 return DispatchXEvent(xev) ?
233 base::MessagePumpGlibXDispatcher::EVENT_PROCESSED : 245 base::MessagePumpGlibXDispatcher::EVENT_PROCESSED :
234 base::MessagePumpGlibXDispatcher::EVENT_IGNORED; 246 base::MessagePumpGlibXDispatcher::EVENT_IGNORED;
235 } 247 }
236 248
237 } // namespace views 249 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/textfield/textfield_views_model_unittest.cc ('k') | views/focus/focus_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698