| 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 "ui/touch_selection/touch_handle.h" | 5 #include "ui/touch_selection/touch_handle.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 namespace ui { | 9 namespace ui { |
| 10 | 10 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 std::min(kMaxTouchMajorForHitTesting, event.GetTouchMajor())) * 0.5f; | 145 std::min(kMaxTouchMajorForHitTesting, event.GetTouchMajor())) * 0.5f; |
| 146 if (!RectIntersectsCircle(drawable_->GetVisibleBounds(), | 146 if (!RectIntersectsCircle(drawable_->GetVisibleBounds(), |
| 147 touch_point, | 147 touch_point, |
| 148 touch_radius)) { | 148 touch_radius)) { |
| 149 EndDrag(); | 149 EndDrag(); |
| 150 return false; | 150 return false; |
| 151 } | 151 } |
| 152 touch_down_position_ = touch_point; | 152 touch_down_position_ = touch_point; |
| 153 touch_to_focus_offset_ = position_ - touch_down_position_; | 153 touch_to_focus_offset_ = position_ - touch_down_position_; |
| 154 touch_down_time_ = event.GetEventTime(); | 154 touch_down_time_ = event.GetEventTime(); |
| 155 BeginDrag(); | 155 BeginDrag(event.GetEventTime()); |
| 156 } break; | 156 } break; |
| 157 | 157 |
| 158 case MotionEvent::ACTION_MOVE: { | 158 case MotionEvent::ACTION_MOVE: { |
| 159 gfx::PointF touch_move_position(event.GetX(), event.GetY()); | 159 gfx::PointF touch_move_position(event.GetX(), event.GetY()); |
| 160 if (is_drag_within_tap_region_) { | 160 if (is_drag_within_tap_region_) { |
| 161 const float tap_slop = client_->GetTapSlop(); | 161 const float tap_slop = client_->GetTapSlop(); |
| 162 is_drag_within_tap_region_ = | 162 is_drag_within_tap_region_ = |
| 163 (touch_move_position - touch_down_position_).LengthSquared() < | 163 (touch_move_position - touch_down_position_).LengthSquared() < |
| 164 tap_slop * tap_slop; | 164 tap_slop * tap_slop; |
| 165 } | 165 } |
| 166 | 166 |
| 167 // Note that we signal drag update even if we're inside the tap region, | 167 // Note that we signal drag update even if we're inside the tap region, |
| 168 // as there are cases where characters are narrower than the slop length. | 168 // as there are cases where characters are narrower than the slop length. |
| 169 client_->OnHandleDragUpdate(*this, | 169 client_->OnHandleDragUpdate(*this, |
| 170 touch_move_position + touch_to_focus_offset_); | 170 touch_move_position + touch_to_focus_offset_, |
| 171 event.GetEventTime()); |
| 171 } break; | 172 } break; |
| 172 | 173 |
| 173 case MotionEvent::ACTION_UP: { | 174 case MotionEvent::ACTION_UP: { |
| 174 if (is_drag_within_tap_region_ && | 175 if (is_drag_within_tap_region_ && |
| 175 (event.GetEventTime() - touch_down_time_) < | 176 (event.GetEventTime() - touch_down_time_) < |
| 176 client_->GetTapTimeout()) { | 177 client_->GetTapTimeout()) { |
| 177 client_->OnHandleTapped(*this); | 178 client_->OnHandleTapped(*this); |
| 178 } | 179 } |
| 179 | 180 |
| 180 EndDrag(); | 181 EndDrag(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 204 SetAlpha(is_visible_ ? u : 1.f - u); | 205 SetAlpha(is_visible_ ? u : 1.f - u); |
| 205 | 206 |
| 206 if (u >= 1.f) { | 207 if (u >= 1.f) { |
| 207 EndFade(); | 208 EndFade(); |
| 208 return false; | 209 return false; |
| 209 } | 210 } |
| 210 | 211 |
| 211 return true; | 212 return true; |
| 212 } | 213 } |
| 213 | 214 |
| 214 void TouchHandle::BeginDrag() { | 215 void TouchHandle::BeginDrag(base::TimeTicks event_time) { |
| 215 DCHECK(enabled_); | 216 DCHECK(enabled_); |
| 216 if (is_dragging_) | 217 if (is_dragging_) |
| 217 return; | 218 return; |
| 218 EndFade(); | 219 EndFade(); |
| 219 is_dragging_ = true; | 220 is_dragging_ = true; |
| 220 is_drag_within_tap_region_ = true; | 221 is_drag_within_tap_region_ = true; |
| 221 client_->OnHandleDragBegin(*this); | 222 client_->OnHandleDragBegin(*this, event_time); |
| 222 } | 223 } |
| 223 | 224 |
| 224 void TouchHandle::EndDrag() { | 225 void TouchHandle::EndDrag() { |
| 225 DCHECK(enabled_); | 226 DCHECK(enabled_); |
| 226 if (!is_dragging_) | 227 if (!is_dragging_) |
| 227 return; | 228 return; |
| 228 | 229 |
| 229 is_dragging_ = false; | 230 is_dragging_ = false; |
| 230 is_drag_within_tap_region_ = false; | 231 is_drag_within_tap_region_ = false; |
| 231 client_->OnHandleDragEnd(*this); | 232 client_->OnHandleDragEnd(*this); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 272 |
| 272 void TouchHandle::SetAlpha(float alpha) { | 273 void TouchHandle::SetAlpha(float alpha) { |
| 273 alpha = std::max(0.f, std::min(1.f, alpha)); | 274 alpha = std::max(0.f, std::min(1.f, alpha)); |
| 274 if (alpha_ == alpha) | 275 if (alpha_ == alpha) |
| 275 return; | 276 return; |
| 276 alpha_ = alpha; | 277 alpha_ = alpha; |
| 277 drawable_->SetAlpha(alpha); | 278 drawable_->SetAlpha(alpha); |
| 278 } | 279 } |
| 279 | 280 |
| 280 } // namespace ui | 281 } // namespace ui |
| OLD | NEW |