OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef ATHENA_WM_BEZEL_CONTROLLER_H_ |
| 6 #define ATHENA_WM_BEZEL_CONTROLLER_H_ |
| 7 |
| 8 #include "ui/events/event_handler.h" |
| 9 |
| 10 namespace aura { |
| 11 class Window; |
| 12 } |
| 13 |
| 14 namespace gfx { |
| 15 class PointF; |
| 16 } |
| 17 |
| 18 namespace athena { |
| 19 |
| 20 // Responsible for detecting bezel gestures and notifying the delegate(s) |
| 21 // subscribed to them. |
| 22 class BezelController : public ui::EventHandler { |
| 23 public: |
| 24 enum Bezel { BEZEL_NONE, BEZEL_LEFT, BEZEL_RIGHT, BEZEL_TOP, BEZEL_BOTTOM }; |
| 25 |
| 26 // Responsible for handling scroll gestures initiated from the bezel. |
| 27 // Two touch points are need to perform the bezel scroll gesture from |
| 28 // the left and right bezel. |
| 29 class ScrollDelegate { |
| 30 public: |
| 31 virtual ~ScrollDelegate() {} |
| 32 |
| 33 // Beginning of a bezel scroll gesture started from the |bezel|. |
| 34 virtual void ScrollBegin(Bezel bezel, float delta) = 0; |
| 35 |
| 36 // End of the current bezel scroll |
| 37 virtual void ScrollEnd() = 0; |
| 38 |
| 39 // Update of the scroll position for the currently active bezel scroll. |
| 40 virtual void ScrollUpdate(float delta) = 0; |
| 41 |
| 42 // Should return false if the delegate isn't going to react to the scroll |
| 43 // events. |
| 44 virtual bool CanScroll() = 0; |
| 45 }; |
| 46 |
| 47 explicit BezelController(aura::Window* container); |
| 48 virtual ~BezelController() {} |
| 49 |
| 50 // Set the delegate to handle the gestures from left and right bezels. |
| 51 // Two touch points are need to perform the bezel scroll gesture from |
| 52 // the left and right bezel. |
| 53 void set_left_right_delegate(ScrollDelegate* delegate) { |
| 54 left_right_delegate_ = delegate; |
| 55 } |
| 56 |
| 57 private: |
| 58 enum State { |
| 59 NO_FINGERS_DOWN, |
| 60 IGNORE, |
| 61 BEZEL_GESTURE_STARTED, |
| 62 BEZEL_SCROLLING_ONE_FINGER, |
| 63 BEZEL_SCROLLING_TWO_FINGERS, |
| 64 }; |
| 65 |
| 66 // Calculates the distance from |position| to the |bezel|. |
| 67 float GetDistance(const gfx::PointF& position, Bezel bezel); |
| 68 |
| 69 // |scroll_position| only needs to be passed in the scrolling state |
| 70 void SetState(State state, const gfx::PointF& scroll_position); |
| 71 |
| 72 // Returns the bezel corresponding to the |location| or BEZEL_NONE if the |
| 73 // location is outside of the bezel area. |
| 74 Bezel GetBezel(const gfx::PointF& location); |
| 75 |
| 76 // ui::EventHandler overrides |
| 77 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE; |
| 78 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
| 79 |
| 80 aura::Window* container_; |
| 81 |
| 82 int num_fingers_down_; |
| 83 State state_; |
| 84 |
| 85 // The bezel where the current bezel scroll was started. |
| 86 Bezel scroll_bezel_; |
| 87 |
| 88 // Responsible for handling gestures started from the left and right bezels. |
| 89 // Not owned. |
| 90 ScrollDelegate* left_right_delegate_; |
| 91 |
| 92 DISALLOW_COPY_AND_ASSIGN(BezelController); |
| 93 }; |
| 94 |
| 95 } // namespace athena |
| 96 |
| 97 #endif // ATHENA_WM_BEZEL_CONTROLLER_H_ |
OLD | NEW |