diff options
Diffstat (limited to 'views/touchui')
-rw-r--r-- | views/touchui/gesture_manager.cc | 62 | ||||
-rw-r--r-- | views/touchui/gesture_manager.h | 54 |
2 files changed, 116 insertions, 0 deletions
diff --git a/views/touchui/gesture_manager.cc b/views/touchui/gesture_manager.cc new file mode 100644 index 0000000..7123519 --- /dev/null +++ b/views/touchui/gesture_manager.cc @@ -0,0 +1,62 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "views/touchui/gesture_manager.h" +#ifndef NDEBUG +#include <iostream> +#endif + +#include "base/logging.h" +#include "views/event.h" +#include "views/view.h" + +namespace views { + +GestureManager::~GestureManager() { +} + +GestureManager* GestureManager::Get() { + return Singleton<GestureManager>::get(); +} + +bool GestureManager::ProcessTouchEventForGesture(const TouchEvent& event, + View* source, + bool previouslyHandled) { + // TODO(rjkroege): A realistic version of the GestureManager will + // appear in a subsequent CL. This interim version permits verifying that the + // event distirbution code works by turning all touch inputs into + // mouse approximations. + bool handled = false; + if (event.GetType() == Event::ET_TOUCH_PRESSED) { + DLOG(INFO) << "GestureManager::ProcessTouchEventForGesture: " << + "TouchPressed\n"; + MouseEvent mouse_event(Event::ET_MOUSE_PRESSED, event.x(), event.y(), + event.GetFlags()); + source->OnMousePressed(mouse_event); + handled = true; + } else if (event.GetType() == Event::ET_TOUCH_RELEASED) { + DLOG(INFO) << "GestureManager::ProcessTouchEventForGesture: " << + "TouchReleased\n"; + MouseEvent mouse_event(Event::ET_MOUSE_RELEASED, event.x(), event.y(), + event.GetFlags()); + source->OnMouseReleased(mouse_event, false); + handled = true; + } else if (event.GetType() == Event::ET_TOUCH_MOVED) { + DLOG(INFO) << "GestureManager::ProcessTouchEventForGesture: " << + "TouchMotion\n"; + MouseEvent mouse_event(Event::ET_MOUSE_DRAGGED, event.x(), event.y(), + event.GetFlags()); + source->OnMouseDragged(mouse_event); + handled = true; + } else { + DLOG(INFO) << "GestureManager::ProcessTouchEventForGesture: " << + "unhandled event\n"; + } + return handled; +} + +GestureManager::GestureManager() { +} + +} // namespace views diff --git a/views/touchui/gesture_manager.h b/views/touchui/gesture_manager.h new file mode 100644 index 0000000..2b905d3 --- /dev/null +++ b/views/touchui/gesture_manager.h @@ -0,0 +1,54 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef VIEWS_TOUCHUI_GESTURE_MANAGER_H_ +#define VIEWS_TOUCHUI_GESTURE_MANAGER_H_ +#pragma once + +#include "base/singleton.h" + +namespace views { +class View; +class TouchEvent; + + +// A GestureManager singleton detects gestures occurring in the +// incoming feed of touch events across all of the RootViews in +// the system. In response to a given touch event, the GestureManager +// updates its internal state and optionally dispatches synthetic +// events to the invoking view. +// +class GestureManager { + public: + virtual ~GestureManager(); + + static GestureManager* Get(); + + // Invoked for each touch event that could contribute to the current gesture. + // Takes the event and the View that originated it and which will also + // be the target of any generated synthetic event. Finally, handled + // specifies if the event was actually handled explicitly by a view so that + // GestureManager state can correctly reflect events that are handled + // already. + // Returns true if the event resulted in firing a synthetic event. + virtual bool ProcessTouchEventForGesture(const TouchEvent& event, + View* source, + bool previouslyHandled); + + // TODO(rjkroege): Write the remainder of this class. + // It will appear in a subsequent CL. + + protected: + GestureManager(); + + private: + friend struct DefaultSingletonTraits<GestureManager>; + + DISALLOW_COPY_AND_ASSIGN(GestureManager); +}; + + +} // namespace views + +#endif // VIEWS_TOUCHUI_GESTURE_MANAGER_H_ |