OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "athena/wm/bezel_controller.h" | 5 #include "athena/wm/bezel_controller.h" |
6 | 6 |
7 #include "ui/aura/window.h" | 7 #include "ui/aura/window.h" |
8 #include "ui/events/event_handler.h" | 8 #include "ui/events/event_handler.h" |
9 #include "ui/gfx/display.h" | 9 #include "ui/gfx/display.h" |
10 #include "ui/gfx/geometry/point_conversions.h" | 10 #include "ui/gfx/geometry/point_conversions.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 DCHECK(bezel == BezelController::BEZEL_LEFT || | 39 DCHECK(bezel == BezelController::BEZEL_LEFT || |
40 bezel == BezelController::BEZEL_RIGHT); | 40 bezel == BezelController::BEZEL_RIGHT); |
41 // Convert location from window coordinates to screen coordinates. | 41 // Convert location from window coordinates to screen coordinates. |
42 gfx::Point point_in_screen(gfx::ToRoundedPoint(location)); | 42 gfx::Point point_in_screen(gfx::ToRoundedPoint(location)); |
43 wm::ConvertPointToScreen(window, &point_in_screen); | 43 wm::ConvertPointToScreen(window, &point_in_screen); |
44 return bezel == BezelController::BEZEL_LEFT | 44 return bezel == BezelController::BEZEL_LEFT |
45 ? point_in_screen.x() | 45 ? point_in_screen.x() |
46 : point_in_screen.x() - GetDisplay(window).bounds().width(); | 46 : point_in_screen.x() - GetDisplay(window).bounds().width(); |
47 } | 47 } |
48 | 48 |
| 49 // Returns the bezel corresponding to the |location| in |window| or BEZEL_NONE |
| 50 // if the location is outside of the bezel area. |
| 51 // Only implemented for LEFT and RIGHT bezels ATM. |
| 52 BezelController::Bezel GetBezel(const gfx::PointF& location, |
| 53 aura::Window* window) { |
| 54 int screen_width = GetDisplay(window).bounds().width(); |
| 55 gfx::Point point_in_screen(gfx::ToRoundedPoint(location)); |
| 56 wm::ConvertPointToScreen(window, &point_in_screen); |
| 57 if (point_in_screen.x() < kBezelWidth) |
| 58 return BezelController::BEZEL_LEFT; |
| 59 else if (point_in_screen.x() > screen_width - kBezelWidth) |
| 60 return BezelController::BEZEL_RIGHT; |
| 61 else |
| 62 return BezelController::BEZEL_NONE; |
| 63 } |
| 64 |
49 } // namespace | 65 } // namespace |
50 | 66 |
51 BezelController::BezelController(aura::Window* container) | 67 BezelController::BezelController(aura::Window* container) |
52 : container_(container), | 68 : container_(container), |
53 state_(NONE), | 69 state_(NONE), |
54 scroll_bezel_(BEZEL_NONE), | 70 scroll_bezel_(BEZEL_NONE), |
55 scroll_target_(NULL), | 71 scroll_target_(NULL), |
56 left_right_delegate_(NULL) { | 72 left_right_delegate_(NULL) { |
57 } | 73 } |
58 | 74 |
(...skipping 13 matching lines...) Expand all Loading... |
72 left_right_delegate_->ScrollBegin(scroll_bezel_, scroll_delta); | 88 left_right_delegate_->ScrollBegin(scroll_bezel_, scroll_delta); |
73 else if (state_ == BEZEL_SCROLLING_TWO_FINGERS) | 89 else if (state_ == BEZEL_SCROLLING_TWO_FINGERS) |
74 left_right_delegate_->ScrollEnd(); | 90 left_right_delegate_->ScrollEnd(); |
75 state_ = state; | 91 state_ = state; |
76 if (state == NONE) { | 92 if (state == NONE) { |
77 scroll_bezel_ = BEZEL_NONE; | 93 scroll_bezel_ = BEZEL_NONE; |
78 scroll_target_ = NULL; | 94 scroll_target_ = NULL; |
79 } | 95 } |
80 } | 96 } |
81 | 97 |
82 // Only implemented for LEFT and RIGHT bezels ATM. | |
83 BezelController::Bezel BezelController::GetBezel(const gfx::PointF& location) { | |
84 int screen_width = GetDisplay(container_).bounds().width(); | |
85 if (location.x() < kBezelWidth) { | |
86 return BEZEL_LEFT; | |
87 } else if (location.x() > screen_width - kBezelWidth) { | |
88 return BEZEL_RIGHT; | |
89 } else { | |
90 return BEZEL_NONE; | |
91 } | |
92 } | |
93 | |
94 void BezelController::OnGestureEvent(ui::GestureEvent* event) { | 98 void BezelController::OnGestureEvent(ui::GestureEvent* event) { |
95 // TODO(mfomitchev): Currently we aren't retargetting or consuming any of the | 99 // TODO(mfomitchev): Currently we aren't retargetting or consuming any of the |
96 // touch events. This means that content can prevent the generation of gesture | 100 // touch events. This means that content can prevent the generation of gesture |
97 // events and two-finger scroll won't work. Possible solution to this problem | 101 // events and two-finger scroll won't work. Possible solution to this problem |
98 // is hosting our own gesture recognizer or retargetting touch events at the | 102 // is hosting our own gesture recognizer or retargetting touch events at the |
99 // bezel. | 103 // bezel. |
100 | 104 |
101 if (!left_right_delegate_) | 105 if (!left_right_delegate_) |
102 return; | 106 return; |
103 | 107 |
104 ui::EventType type = event->type(); | 108 ui::EventType type = event->type(); |
105 if (!ShouldProcessGesture(type)) | 109 if (!ShouldProcessGesture(type)) |
106 return; | 110 return; |
107 | 111 |
108 if (scroll_target_ && event->target() != scroll_target_) | 112 if (scroll_target_ && event->target() != scroll_target_) |
109 return; | 113 return; |
110 | 114 |
111 const gfx::PointF& event_location = event->location_f(); | 115 const gfx::PointF& event_location = event->location_f(); |
112 const ui::GestureEventDetails& event_details = event->details(); | 116 const ui::GestureEventDetails& event_details = event->details(); |
113 int num_touch_points = event_details.touch_points(); | 117 int num_touch_points = event_details.touch_points(); |
114 float scroll_delta = kScrollDeltaNone; | 118 float scroll_delta = kScrollDeltaNone; |
| 119 aura::Window* target_window = static_cast<aura::Window*>(event->target()); |
115 if (scroll_bezel_ != BEZEL_NONE) { | 120 if (scroll_bezel_ != BEZEL_NONE) { |
116 aura::Window* target_window = static_cast<aura::Window*>(event->target()); | |
117 scroll_delta = GetDistance(event_location, target_window, scroll_bezel_); | 121 scroll_delta = GetDistance(event_location, target_window, scroll_bezel_); |
118 } | 122 } |
119 | 123 |
120 if (type == ui::ET_GESTURE_BEGIN) { | 124 if (type == ui::ET_GESTURE_BEGIN) { |
121 if (num_touch_points > 2) { | 125 if (num_touch_points > 2) { |
122 SetState(IGNORE_CURRENT_SCROLL); | 126 SetState(IGNORE_CURRENT_SCROLL); |
123 return; | 127 return; |
124 } | 128 } |
125 BezelController::Bezel event_bezel = GetBezel(event->location_f()); | 129 BezelController::Bezel event_bezel = |
| 130 GetBezel(event->location_f(), target_window); |
126 switch (state_) { | 131 switch (state_) { |
127 case NONE: | 132 case NONE: |
128 scroll_bezel_ = event_bezel; | 133 scroll_bezel_ = event_bezel; |
129 scroll_target_ = event->target(); | 134 scroll_target_ = event->target(); |
130 if (event_bezel != BEZEL_LEFT && event_bezel != BEZEL_RIGHT) | 135 if (event_bezel != BEZEL_LEFT && event_bezel != BEZEL_RIGHT) |
131 SetState(IGNORE_CURRENT_SCROLL); | 136 SetState(IGNORE_CURRENT_SCROLL); |
132 else | 137 else |
133 SetState(BEZEL_GESTURE_STARTED); | 138 SetState(BEZEL_GESTURE_STARTED); |
134 break; | 139 break; |
135 case IGNORE_CURRENT_SCROLL: | 140 case IGNORE_CURRENT_SCROLL: |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 if (state_ != BEZEL_SCROLLING_TWO_FINGERS) | 185 if (state_ != BEZEL_SCROLLING_TWO_FINGERS) |
181 return; | 186 return; |
182 | 187 |
183 left_right_delegate_->ScrollUpdate(scroll_delta); | 188 left_right_delegate_->ScrollUpdate(scroll_delta); |
184 if (left_right_delegate_->CanScroll()) | 189 if (left_right_delegate_->CanScroll()) |
185 event->SetHandled(); | 190 event->SetHandled(); |
186 } | 191 } |
187 } | 192 } |
188 | 193 |
189 } // namespace athena | 194 } // namespace athena |
OLD | NEW |