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 ui { |
| 19 class EventTarget; |
| 20 } |
| 21 |
| 22 namespace athena { |
| 23 |
| 24 // Responsible for detecting bezel gestures and notifying the delegate(s) |
| 25 // subscribed to them. |
| 26 class BezelController : public ui::EventHandler { |
| 27 public: |
| 28 enum Bezel { BEZEL_NONE, BEZEL_LEFT, BEZEL_RIGHT, BEZEL_TOP, BEZEL_BOTTOM }; |
| 29 |
| 30 // Responsible for handling scroll gestures initiated from the bezel. |
| 31 // Two touch points are need to perform the bezel scroll gesture from |
| 32 // the left and right bezel. |
| 33 class ScrollDelegate { |
| 34 public: |
| 35 virtual ~ScrollDelegate() {} |
| 36 |
| 37 // Beginning of a bezel scroll gesture started from the |bezel|. |
| 38 virtual void ScrollBegin(Bezel bezel, float delta) = 0; |
| 39 |
| 40 // End of the current bezel scroll |
| 41 virtual void ScrollEnd() = 0; |
| 42 |
| 43 // Update of the scroll position for the currently active bezel scroll. |
| 44 virtual void ScrollUpdate(float delta) = 0; |
| 45 |
| 46 // Should return false if the delegate isn't going to react to the scroll |
| 47 // events. |
| 48 virtual bool CanScroll() = 0; |
| 49 }; |
| 50 |
| 51 explicit BezelController(aura::Window* container); |
| 52 virtual ~BezelController() {} |
| 53 |
| 54 // Set the delegate to handle the gestures from left and right bezels. |
| 55 // Two touch points are need to perform the bezel scroll gesture from |
| 56 // the left and right bezel. |
| 57 void set_left_right_delegate(ScrollDelegate* delegate) { |
| 58 left_right_delegate_ = delegate; |
| 59 } |
| 60 |
| 61 private: |
| 62 enum State { |
| 63 NONE, |
| 64 IGNORE_CURRENT_SCROLL, |
| 65 BEZEL_GESTURE_STARTED, |
| 66 BEZEL_SCROLLING_ONE_FINGER, |
| 67 BEZEL_SCROLLING_TWO_FINGERS, |
| 68 }; |
| 69 |
| 70 // Calculates the distance from |position| to the |bezel|. |
| 71 float GetDistance(const gfx::PointF& position, Bezel bezel); |
| 72 |
| 73 // |scroll_position| only needs to be passed in the scrolling state |
| 74 void SetState(State state, const gfx::PointF& scroll_position); |
| 75 |
| 76 // Returns the bezel corresponding to the |location| or BEZEL_NONE if the |
| 77 // location is outside of the bezel area. |
| 78 Bezel GetBezel(const gfx::PointF& location); |
| 79 |
| 80 // ui::EventHandler overrides |
| 81 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
| 82 |
| 83 aura::Window* container_; |
| 84 |
| 85 State state_; |
| 86 |
| 87 // The bezel where the currently active scroll was started. |
| 88 Bezel scroll_bezel_; |
| 89 |
| 90 // The target of the bezel scroll gesture. Used to filter out other gestures |
| 91 // when the bezel scroll is in progress. |
| 92 ui::EventTarget* scroll_target_; |
| 93 |
| 94 // Responsible for handling gestures started from the left and right bezels. |
| 95 // Not owned. |
| 96 ScrollDelegate* left_right_delegate_; |
| 97 |
| 98 DISALLOW_COPY_AND_ASSIGN(BezelController); |
| 99 }; |
| 100 |
| 101 } // namespace athena |
| 102 |
| 103 #endif // ATHENA_WM_BEZEL_CONTROLLER_H_ |
OLD | NEW |