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 BezelController(aura::Window* container); | |
sadrul
2014/07/22 21:53:19
explicit
mfomitchev
2014/07/22 22:22:01
Done.
| |
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 // Defines the effective bezel width. | |
67 static const float kBezelWidth; | |
68 | |
69 static const float kScrollPositionNone; | |
oshima
2014/07/22 21:30:46
move these to anonymous namespace.
mfomitchev
2014/07/22 22:22:01
Done.
| |
70 | |
71 // Calculates the distance from |position| to the |bezel|. | |
72 float GetDistance(const gfx::PointF& position, Bezel bezel); | |
73 | |
74 // |scroll_position| only needs to be passed in the scrolling state | |
75 void SetState(State state, const gfx::PointF& scroll_position); | |
76 | |
77 // Returns the bezel corresponding to the |location| or BEZEL_NONE if the | |
78 // location is outside of the bezel area. | |
79 Bezel GetBezel(const gfx::PointF& location); | |
80 | |
81 bool ShouldProcessGesture(ui::EventType event_type); | |
82 | |
83 // ui::EventHandler overrides | |
84 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE; | |
85 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | |
86 | |
87 aura::Window* container_; | |
88 | |
89 int num_fingers_down_; | |
90 State state_; | |
91 | |
92 // The bezel where the current bezel scroll was started. | |
93 Bezel scroll_bezel_; | |
94 | |
95 // Responsible for handling gestures started from the left and right bezels. | |
96 // Not owned. | |
97 ScrollDelegate* left_right_delegate_; | |
98 | |
99 DISALLOW_COPY_AND_ASSIGN(BezelController); | |
100 }; | |
101 | |
102 } // namespace athena | |
103 | |
104 #endif // ATHENA_WM_BEZEL_CONTROLLER_H_ | |
OLD | NEW |