Index: athena/wm/bezel_controller.h |
diff --git a/athena/wm/bezel_controller.h b/athena/wm/bezel_controller.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e58e5924a2e95cfb65896d8fe9e7bade9b3f29e6 |
--- /dev/null |
+++ b/athena/wm/bezel_controller.h |
@@ -0,0 +1,107 @@ |
+// Copyright 2014 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 ATHENA_WM_BEZEL_CONTROLLER_H_ |
+#define ATHENA_WM_BEZEL_CONTROLLER_H_ |
+ |
+#include "ui/events/event_handler.h" |
+ |
+namespace aura { |
+class Window; |
+} |
+ |
+namespace gfx { |
+class PointF; |
+} |
+ |
+namespace athena { |
+ |
+// Responsible for detecting bezel gestures and notifying the delegate(s) |
+// subscribed to them. |
+class BezelController : public ui::EventHandler { |
+ public: |
+ enum Bezel { |
+ BEZEL_NONE, |
+ BEZEL_LEFT, |
+ BEZEL_RIGHT, |
+// BEZEL_TOP, |
+// BEZEL_BOTTOM |
Jun Mukai
2014/07/21 17:18:52
Uncomment-out them (it's okay unused at all), or j
mfomitchev
2014/07/21 17:31:47
Done.
|
+ }; |
+ |
+ // Responsible for handling scroll gestures initiated from the bezel. |
+ // Two touch points are need to perform the bezel scroll gesture from |
+ // the left and right bezel. |
+ class ScrollDelegate { |
+ public: |
+ virtual ~ScrollDelegate() {} |
+ |
+ // Beginning of a bezel scroll gesture started from the |bezel|. |
+ virtual void ScrollBegin(Bezel bezel, float delta) = 0; |
+ |
+ // End of the current bezel scroll |
+ virtual void ScrollEnd() = 0; |
+ |
+ // Update of the scroll position for the currently active bezel scroll. |
+ virtual void ScrollUpdate(float delta) = 0; |
+ |
+ // Should return false if the delegate isn't going to react to the scroll |
+ // events. |
+ virtual bool CanScroll() = 0; |
+ }; |
+ |
+ BezelController(aura::Window* container); |
+ virtual ~BezelController() {} |
+ |
+ // Set the delegate to handle the gestures from left and right bezels. |
+ // Two touch points are need to perform the bezel scroll gesture from |
+ // the left and right bezel. |
+ void set_left_right_delegate(ScrollDelegate* delegate) { |
+ left_right_delegate_ = delegate; |
+ } |
+ |
+ private: |
+ enum State { |
+ NO_FINGERS_DOWN, |
+ IGNORE, |
+ BEZEL_GESTURE_STARTED, |
+ BEZEL_SCROLLING_ONE_FINGER, |
+ BEZEL_SCROLLING_TWO_FINGERS, |
+ }; |
+ |
+ // Defines the effective bezel width. |
+ static const float kBezelWidth; |
+ |
+ static const gfx::PointF& kScrollPositionNone; |
+ |
+ // Calculates the distance from |position| to the |bezel|. |
+ float GetDistance(const gfx::PointF& position, Bezel bezel); |
+ |
+ // |scroll_position| only needs to be passed in the scrolling state |
+ void SetState(State state, const gfx::PointF& scroll_position); |
+ |
+ // Returns the bezel corresponding to the |location| or BEZEL_NONE if the |
+ // location is outside of the bezel area. |
+ Bezel GetBezel(const gfx::PointF& location); |
+ |
+ bool ShouldProcessGesture(ui::EventType event_type); |
+ |
+ // ui::EventHandler overrides |
+ virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE; |
+ virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
+ |
+ aura::Window* container_; |
+ |
+ int num_fingers_down_; |
+ State state_; |
+ |
+ // The bezel where the current bezel scroll was started. |
+ Bezel scroll_bezel_; |
+ |
+ // Responsible for handling gestures started from the left and right bezels. |
+ ScrollDelegate* left_right_delegate_; |
+}; |
+ |
+} // namespace athena |
+ |
+#endif // ATHENA_WM_BEZEL_CONTROLLER_H_ |