summaryrefslogtreecommitdiffstats
path: root/views/focus
diff options
context:
space:
mode:
authorrjkroege@google.com <rjkroege@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-26 18:43:18 +0000
committerrjkroege@google.com <rjkroege@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-26 18:43:18 +0000
commitb2f7ac4583b968d0c20ea8f6c4110aeb6882699a (patch)
tree7bcf1278af056ab056221da0ee01e81851e9ebde /views/focus
parentbd2b41afb25b648e3f77dce87064971f63894a7f (diff)
downloadchromium_src-b2f7ac4583b968d0c20ea8f6c4110aeb6882699a.zip
chromium_src-b2f7ac4583b968d0c20ea8f6c4110aeb6882699a.tar.gz
chromium_src-b2f7ac4583b968d0c20ea8f6c4110aeb6882699a.tar.bz2
touchui: Directly process key and mouse events.
Capture the keyboard and mouse events directly from X, create a corresponding views::Event out of it, and send it to the associated RootView. Includes Chad's (wyck) function FindRootViewForGdkEvent (from #3704005) slightly modified (called FindRootViewForGdkWindow). BUG=None TEST=Click/Keypress events in a webpage should work correctly. Review URL: http://codereview.chromium.org/3801011 Patch from Sadrul Chowdhury <sadrul@chromium.org>. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63916 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/focus')
-rw-r--r--views/focus/accelerator_handler.h9
-rw-r--r--views/focus/accelerator_handler_gtk.cc3
-rw-r--r--views/focus/accelerator_handler_touch.cc91
3 files changed, 89 insertions, 14 deletions
diff --git a/views/focus/accelerator_handler.h b/views/focus/accelerator_handler.h
index 3726d96..088f3f1 100644
--- a/views/focus/accelerator_handler.h
+++ b/views/focus/accelerator_handler.h
@@ -18,6 +18,12 @@
namespace views {
+#if defined(TOUCH_UI)
+// Dispatch an XEvent to the RootView. Return true if the event was dispatched
+// and handled, false otherwise.
+bool DispatchXEvent(XEvent* xevent);
+#endif
+
// This class delegates the key messages to the associated FocusManager class
// for the window that is receiving these messages for accelerator processing.
class AcceleratorHandler : public MessageLoopForUI::Dispatcher {
@@ -29,6 +35,9 @@ class AcceleratorHandler : public MessageLoopForUI::Dispatcher {
virtual bool Dispatch(const MSG& msg);
#else
virtual bool Dispatch(GdkEvent* event);
+#if defined(TOUCH_UI)
+ virtual bool Dispatch(XEvent* xev);
+#endif
#endif
private:
diff --git a/views/focus/accelerator_handler_gtk.cc b/views/focus/accelerator_handler_gtk.cc
index a45aa83..f1dc140 100644
--- a/views/focus/accelerator_handler_gtk.cc
+++ b/views/focus/accelerator_handler_gtk.cc
@@ -2,10 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "views/focus/accelerator_handler.h"
+
#include <gtk/gtk.h>
#include "views/accelerator.h"
-#include "views/focus/accelerator_handler.h"
#include "views/focus/focus_manager.h"
#include "views/widget/widget_gtk.h"
diff --git a/views/focus/accelerator_handler_touch.cc b/views/focus/accelerator_handler_touch.cc
index ddcdc04..9473600 100644
--- a/views/focus/accelerator_handler_touch.cc
+++ b/views/focus/accelerator_handler_touch.cc
@@ -2,31 +2,96 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "views/focus/accelerator_handler.h"
+
#include <gtk/gtk.h>
+#include <X11/Xlib.h>
#include "views/accelerator.h"
-#include "views/focus/accelerator_handler.h"
+#include "views/event.h"
#include "views/focus/focus_manager.h"
-#include "views/touchui/touch_event_dispatcher_gtk.h"
+#include "views/widget/root_view.h"
#include "views/widget/widget_gtk.h"
namespace views {
-AcceleratorHandler::AcceleratorHandler() {}
+namespace {
-bool AcceleratorHandler::Dispatch(GdkEvent* event) {
- // The logic for handling keyboard accelerators has been moved into
- // WidgetGtk::OnKeyEvent handler (views/widget/widget_gtk.cc).
+RootView* FindRootViewForGdkWindow(GdkWindow* gdk_window) {
+ gpointer data = NULL;
+ gdk_window_get_user_data(gdk_window, &data);
+ GtkWidget* gtk_widget = reinterpret_cast<GtkWidget*>(data);
+ if (!gtk_widget || !GTK_IS_WIDGET(gtk_widget)) {
+ DLOG(WARNING) << "no GtkWidget found for that GdkWindow";
+ return NULL;
+ }
+ WidgetGtk* widget_gtk = WidgetGtk::GetViewForNative(gtk_widget);
+
+ if (!widget_gtk) {
+ DLOG(WARNING) << "no WidgetGtk found for that GtkWidget";
+ return NULL;
+ }
+ return widget_gtk->GetRootView();
+}
+
+} // namespace
+
+bool DispatchXEvent(XEvent* xev) {
+ GdkDisplay* gdisp = gdk_display_get_default();
+ GdkWindow* gwind = gdk_window_lookup_for_display(gdisp, xev->xany.window);
+
+ if (RootView* root = FindRootViewForGdkWindow(gwind)) {
+ switch (xev->type) {
+ case KeyPress:
+ case KeyRelease: {
+ KeyEvent keyev(xev);
- // TODO(wyck): Hijack TouchUI events at other calls to gtk_main_do_event.
- // There are more places where we call gtk_main_do_event.
- // In particular: the message pump itself, and the menu controller,
- // as well as native_menu_gtk.
- // This function contains the most important one important one, though.
- if (!DispatchEventForTouchUIGtk(event))
- gtk_main_do_event(event);
+ // If it's a keypress, check to see if it triggers an accelerator.
+ if (xev->type == KeyPress) {
+ FocusManager* focus_manager = root->GetFocusManager();
+ if (focus_manager && !focus_manager->OnKeyEvent(keyev))
+ return true;
+ }
+ return root->ProcessKeyEvent(keyev);
+ }
+
+ case ButtonPress:
+ case ButtonRelease: {
+ MouseEvent mouseev(xev);
+ if (xev->type == ButtonPress) {
+ return root->OnMousePressed(mouseev);
+ } else {
+ root->OnMouseReleased(mouseev, false);
+ return true; // Assume the event has been processed to make sure we
+ // don't process it twice.
+ }
+ }
+
+ case MotionNotify: {
+ MouseEvent mouseev(xev);
+ if (mouseev.GetType() == Event::ET_MOUSE_DRAGGED) {
+ return root->OnMouseDragged(mouseev);
+ } else {
+ root->OnMouseMoved(mouseev);
+ return true;
+ }
+ }
+ }
+ }
+
+ return false;
+}
+
+AcceleratorHandler::AcceleratorHandler() {}
+
+bool AcceleratorHandler::Dispatch(GdkEvent* event) {
+ gtk_main_do_event(event);
return true;
}
+bool AcceleratorHandler::Dispatch(XEvent* xev) {
+ return DispatchXEvent(xev);
+}
+
} // namespace views