Chromium Code Reviews| 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 "athena/wm/coordinate_conversion.h" | |
| 7 #include "ui/aura/window.h" | 8 #include "ui/aura/window.h" |
| 8 #include "ui/events/event_handler.h" | 9 #include "ui/events/event_handler.h" |
| 9 | 10 |
| 10 namespace athena { | 11 namespace athena { |
| 11 namespace { | 12 namespace { |
| 12 | 13 |
| 13 // Using bezel swipes, the first touch that is registered is usually within | 14 // Using bezel swipes, the first touch that is registered is usually within |
| 14 // 5-10 pixels from the edge, but sometimes as far as 29 pixels away. | 15 // 5-10 pixels from the edge, but sometimes as far as 29 pixels away. |
| 15 // So setting this width fairly high for now. | 16 // So setting this width fairly high for now. |
| 16 const float kBezelWidth = 20.0f; | 17 const float kBezelWidth = 20.0f; |
| 17 | 18 |
| 18 const float kScrollPositionNone = -100; | 19 const float kScrollDeltaNone = 0; |
| 19 | 20 |
| 20 bool ShouldProcessGesture(ui::EventType event_type) { | 21 bool ShouldProcessGesture(ui::EventType event_type) { |
| 21 return event_type == ui::ET_GESTURE_SCROLL_UPDATE || | 22 return event_type == ui::ET_GESTURE_SCROLL_UPDATE || |
| 22 event_type == ui::ET_GESTURE_SCROLL_BEGIN || | 23 event_type == ui::ET_GESTURE_SCROLL_BEGIN || |
| 23 event_type == ui::ET_GESTURE_BEGIN || | 24 event_type == ui::ET_GESTURE_BEGIN || |
| 24 event_type == ui::ET_GESTURE_END; | 25 event_type == ui::ET_GESTURE_END; |
| 25 } | 26 } |
| 26 | 27 |
| 27 } // namespace | 28 } // namespace |
| 28 | 29 |
| 29 BezelController::BezelController(aura::Window* container) | 30 BezelController::BezelController(aura::Window* container) |
| 30 : container_(container), | 31 : container_(container), |
| 31 state_(NONE), | 32 state_(NONE), |
| 32 scroll_bezel_(BEZEL_NONE), | 33 scroll_bezel_(BEZEL_NONE), |
| 33 scroll_target_(NULL), | 34 scroll_target_(NULL), |
| 34 left_right_delegate_(NULL) { | 35 left_right_delegate_(NULL) { |
| 35 } | 36 } |
| 36 | 37 |
| 37 float BezelController::GetDistance(const gfx::PointF& position, | 38 float BezelController::GetDistance(const gfx::PointF& location, |
| 39 aura::Window* window, | |
| 38 BezelController::Bezel bezel) { | 40 BezelController::Bezel bezel) { |
| 39 DCHECK(bezel == BEZEL_LEFT || bezel == BEZEL_RIGHT); | 41 DCHECK(bezel == BEZEL_LEFT || bezel == BEZEL_RIGHT); |
| 42 // Convert location from window coordinates to screen coordinates. | |
| 43 gfx::Point point_in_screen(location.x(), location.y()); | |
|
Jun Mukai
2014/07/25 20:21:29
point_in_screen(location) would copy it.
mfomitchev
2014/07/25 23:27:38
Doesn't look like I can pass PointF to a Point con
Jun Mukai
2014/07/25 23:44:23
oops, missed your point. Well, in that case, consi
mfomitchev
2014/07/26 02:08:43
Cool, will do.
mfomitchev
2014/08/05 19:56:57
Done.
| |
| 44 ConvertPointToScreen(window, &point_in_screen); | |
| 40 return bezel == BEZEL_LEFT | 45 return bezel == BEZEL_LEFT |
| 41 ? position.x() | 46 ? point_in_screen.x() |
| 42 : position.x() - container_->GetBoundsInScreen().width(); | 47 : point_in_screen.x() - container_->GetBoundsInScreen().width(); |
|
Jun Mukai
2014/07/25 20:21:29
Not the thing in this CL, but should this be GetBo
mfomitchev
2014/07/25 23:27:38
Since this is a bezel gesture recognizer, I think
Jun Mukai
2014/07/25 23:44:23
I don't object to point_in_screen.x(). I'm saying
mfomitchev
2014/07/26 02:08:43
Yes, I understand. My point is that this is a beze
Jun Mukai
2014/07/26 20:30:37
+1 to use screen_width.
mfomitchev
2014/08/05 19:56:57
Done.
| |
| 43 } | 48 } |
| 44 | 49 |
| 45 void BezelController::SetState(BezelController::State state, | 50 void BezelController::SetState( |
| 46 const gfx::PointF& scroll_position) { | 51 BezelController::State state, float scroll_delta) { |
| 47 if (!left_right_delegate_ || state == state_) | 52 if (!left_right_delegate_ || state == state_) |
| 48 return; | 53 return; |
| 49 | 54 |
| 50 if (state == BEZEL_SCROLLING_TWO_FINGERS) { | 55 LOG(ERROR) << "\nBezelController::SetState, state=*** " << state << " ***"; |
| 51 float delta = GetDistance(scroll_position, scroll_bezel_); | 56 |
| 52 left_right_delegate_->ScrollBegin(scroll_bezel_, delta); | 57 if (state == BEZEL_SCROLLING_TWO_FINGERS) { |
| 53 } else if (state_ == BEZEL_SCROLLING_TWO_FINGERS) { | 58 left_right_delegate_->ScrollBegin(scroll_bezel_, scroll_delta); |
| 54 left_right_delegate_->ScrollEnd(); | 59 } else if (state_ == BEZEL_SCROLLING_TWO_FINGERS) { |
| 55 } | 60 left_right_delegate_->ScrollEnd(); |
| 61 } | |
|
Jun Mukai
2014/07/25 20:21:29
remove unnecessary indents
mfomitchev
2014/07/25 23:27:38
Done.
| |
| 56 state_ = state; | 62 state_ = state; |
| 57 if (state == NONE) { | 63 if (state == NONE) { |
| 58 scroll_bezel_ = BEZEL_NONE; | 64 scroll_bezel_ = BEZEL_NONE; |
| 59 scroll_target_ = NULL; | 65 scroll_target_ = NULL; |
| 60 } | 66 } |
| 61 } | 67 } |
| 62 | 68 |
| 63 // Only implemented for LEFT and RIGHT bezels ATM. | 69 // Only implemented for LEFT and RIGHT bezels ATM. |
| 64 BezelController::Bezel BezelController::GetBezel(const gfx::PointF& location) { | 70 BezelController::Bezel BezelController::GetBezel(const gfx::PointF& location) { |
| 65 if (location.x() < kBezelWidth) { | 71 if (location.x() < kBezelWidth) { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 85 ui::EventType type = event->type(); | 91 ui::EventType type = event->type(); |
| 86 if (!ShouldProcessGesture(type)) | 92 if (!ShouldProcessGesture(type)) |
| 87 return; | 93 return; |
| 88 | 94 |
| 89 if (scroll_target_ && event->target() != scroll_target_) | 95 if (scroll_target_ && event->target() != scroll_target_) |
| 90 return; | 96 return; |
| 91 | 97 |
| 92 const gfx::PointF& event_location = event->location_f(); | 98 const gfx::PointF& event_location = event->location_f(); |
| 93 const ui::GestureEventDetails& event_details = event->details(); | 99 const ui::GestureEventDetails& event_details = event->details(); |
| 94 int num_touch_points = event_details.touch_points(); | 100 int num_touch_points = event_details.touch_points(); |
| 101 float scroll_delta = kScrollDeltaNone; | |
| 102 if (scroll_bezel_ != BEZEL_NONE) { | |
| 103 aura::Window* target_window = static_cast<aura::Window*> (event->target()); | |
| 104 scroll_delta = GetDistance( | |
| 105 event_location, target_window, scroll_bezel_); | |
| 106 } | |
| 95 | 107 |
| 96 if (type == ui::ET_GESTURE_BEGIN) { | 108 if (type == ui::ET_GESTURE_BEGIN) { |
| 97 if (num_touch_points > 2) { | 109 if (num_touch_points > 2) { |
| 98 SetState(IGNORE_CURRENT_SCROLL, | 110 SetState(IGNORE_CURRENT_SCROLL, kScrollDeltaNone); |
| 99 gfx::Point(kScrollPositionNone, kScrollPositionNone)); | |
| 100 return; | 111 return; |
| 101 } | 112 } |
| 102 BezelController::Bezel event_bezel = GetBezel(event->location_f()); | 113 BezelController::Bezel event_bezel = GetBezel(event->location_f()); |
| 103 switch (state_) { | 114 switch (state_) { |
| 104 case NONE: | 115 case NONE: |
| 105 scroll_bezel_ = event_bezel; | 116 scroll_bezel_ = event_bezel; |
| 106 scroll_target_ = event->target(); | 117 scroll_target_ = event->target(); |
| 107 if (event_bezel != BEZEL_LEFT && event_bezel != BEZEL_RIGHT) { | 118 if (event_bezel != BEZEL_LEFT && event_bezel != BEZEL_RIGHT) |
| 108 SetState(IGNORE_CURRENT_SCROLL, | 119 SetState(IGNORE_CURRENT_SCROLL, kScrollDeltaNone); |
| 109 gfx::Point(kScrollPositionNone, kScrollPositionNone)); | 120 else |
| 110 } else { | 121 SetState(BEZEL_GESTURE_STARTED, kScrollDeltaNone); |
|
Jun Mukai
2014/07/25 20:21:29
I don't like using None all around. Can we make a
mfomitchev
2014/08/05 19:56:57
I've just created an overloaded SetState method th
Jun Mukai
2014/08/05 21:13:38
SGTM
| |
| 111 SetState(BEZEL_GESTURE_STARTED, event_location); | |
| 112 } | |
| 113 break; | 122 break; |
| 114 case IGNORE_CURRENT_SCROLL: | 123 case IGNORE_CURRENT_SCROLL: |
| 115 break; | 124 break; |
| 116 case BEZEL_GESTURE_STARTED: | 125 case BEZEL_GESTURE_STARTED: |
| 117 case BEZEL_SCROLLING_ONE_FINGER: | 126 case BEZEL_SCROLLING_ONE_FINGER: |
| 118 DCHECK_EQ(num_touch_points, 2); | 127 DCHECK_EQ(num_touch_points, 2); |
| 119 DCHECK(scroll_target_); | 128 DCHECK(scroll_target_); |
| 120 DCHECK_NE(scroll_bezel_, BEZEL_NONE); | 129 DCHECK_NE(scroll_bezel_, BEZEL_NONE); |
| 121 | 130 |
| 122 if (event_bezel != scroll_bezel_) { | 131 if (event_bezel != scroll_bezel_) { |
| 123 SetState(IGNORE_CURRENT_SCROLL, | 132 SetState(IGNORE_CURRENT_SCROLL, kScrollDeltaNone); |
| 124 gfx::Point(kScrollPositionNone, kScrollPositionNone)); | |
| 125 return; | 133 return; |
| 126 } | 134 } |
| 127 if (state_ == BEZEL_SCROLLING_ONE_FINGER) | 135 if (state_ == BEZEL_SCROLLING_ONE_FINGER) |
| 128 SetState(BEZEL_SCROLLING_TWO_FINGERS, event_location); | 136 SetState(BEZEL_SCROLLING_TWO_FINGERS, scroll_delta); |
| 129 break; | 137 break; |
| 130 case BEZEL_SCROLLING_TWO_FINGERS: | 138 case BEZEL_SCROLLING_TWO_FINGERS: |
| 131 // Should've exited above | 139 // Should've exited above |
| 132 NOTREACHED(); | 140 NOTREACHED(); |
| 133 break; | 141 break; |
| 134 } | 142 } |
| 135 } else if (type == ui::ET_GESTURE_END) { | 143 } else if (type == ui::ET_GESTURE_END) { |
| 136 if (state_ == NONE) | 144 if (state_ == NONE) |
| 137 return; | 145 return; |
| 138 | 146 |
| 139 CHECK(scroll_target_); | 147 CHECK(scroll_target_); |
| 140 if (num_touch_points == 1) { | 148 if (num_touch_points == 1) { |
| 141 SetState(NONE, gfx::Point(kScrollPositionNone, kScrollPositionNone)); | 149 SetState(NONE, kScrollDeltaNone); |
| 142 } else { | 150 } else { |
| 143 SetState(IGNORE_CURRENT_SCROLL, | 151 SetState(IGNORE_CURRENT_SCROLL, kScrollDeltaNone); |
| 144 gfx::Point(kScrollPositionNone, kScrollPositionNone)); | |
| 145 } | 152 } |
| 146 } else if (type == ui::ET_GESTURE_SCROLL_BEGIN) { | 153 } else if (type == ui::ET_GESTURE_SCROLL_BEGIN) { |
| 147 DCHECK(state_ == IGNORE_CURRENT_SCROLL || state_ == BEZEL_GESTURE_STARTED); | 154 DCHECK(state_ == IGNORE_CURRENT_SCROLL || state_ == BEZEL_GESTURE_STARTED); |
| 148 if (state_ != BEZEL_GESTURE_STARTED) | 155 if (state_ != BEZEL_GESTURE_STARTED) |
| 149 return; | 156 return; |
| 150 | 157 |
| 151 if (num_touch_points == 1) { | 158 if (num_touch_points == 1) { |
| 152 SetState(BEZEL_SCROLLING_ONE_FINGER, event_location); | 159 SetState(BEZEL_SCROLLING_ONE_FINGER, scroll_delta); |
| 153 return; | 160 return; |
| 154 } | 161 } |
| 155 | 162 |
| 156 DCHECK_EQ(num_touch_points, 2); | 163 DCHECK_EQ(num_touch_points, 2); |
| 157 SetState(BEZEL_SCROLLING_TWO_FINGERS, event_location); | 164 SetState(BEZEL_SCROLLING_TWO_FINGERS, scroll_delta); |
| 158 if (left_right_delegate_->CanScroll()) | 165 if (left_right_delegate_->CanScroll()) |
| 159 event->SetHandled(); | 166 event->SetHandled(); |
| 160 } else if (type == ui::ET_GESTURE_SCROLL_UPDATE) { | 167 } else if (type == ui::ET_GESTURE_SCROLL_UPDATE) { |
| 161 if (state_ != BEZEL_SCROLLING_TWO_FINGERS) | 168 if (state_ != BEZEL_SCROLLING_TWO_FINGERS) |
| 162 return; | 169 return; |
| 163 | 170 |
| 164 float scroll_delta = GetDistance(event_location, scroll_bezel_); | |
| 165 left_right_delegate_->ScrollUpdate(scroll_delta); | 171 left_right_delegate_->ScrollUpdate(scroll_delta); |
| 166 if (left_right_delegate_->CanScroll()) | 172 if (left_right_delegate_->CanScroll()) |
| 167 event->SetHandled(); | 173 event->SetHandled(); |
| 168 } | 174 } |
| 169 } | 175 } |
| 170 | 176 |
| 171 } // namespace athena | 177 } // namespace athena |
| OLD | NEW |