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 "content/browser/renderer_host/input/touch_handle.h" | 5 #include "ui/touch_selection/touch_handle.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 namespace content { | 9 namespace ui { |
10 | 10 |
11 namespace { | 11 namespace { |
12 | 12 |
13 // Maximum duration of a fade sequence. | 13 // Maximum duration of a fade sequence. |
14 const double kFadeDurationMs = 200; | 14 const double kFadeDurationMs = 200; |
15 | 15 |
16 // Maximum amount of travel for a fade sequence. This avoids handle "ghosting" | 16 // Maximum amount of travel for a fade sequence. This avoids handle "ghosting" |
17 // when the handle is moving rapidly while the fade is active. | 17 // when the handle is moving rapidly while the fade is active. |
18 const double kFadeDistanceSquared = 20.f * 20.f; | 18 const double kFadeDistanceSquared = 20.f * 20.f; |
19 | 19 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 return; | 106 return; |
107 } | 107 } |
108 DCHECK_EQ(deferred_orientation_, TOUCH_HANDLE_ORIENTATION_UNDEFINED); | 108 DCHECK_EQ(deferred_orientation_, TOUCH_HANDLE_ORIENTATION_UNDEFINED); |
109 if (orientation_ == orientation) | 109 if (orientation_ == orientation) |
110 return; | 110 return; |
111 | 111 |
112 orientation_ = orientation; | 112 orientation_ = orientation; |
113 drawable_->SetOrientation(orientation); | 113 drawable_->SetOrientation(orientation); |
114 } | 114 } |
115 | 115 |
116 bool TouchHandle::WillHandleTouchEvent(const ui::MotionEvent& event) { | 116 bool TouchHandle::WillHandleTouchEvent(const MotionEvent& event) { |
117 if (!enabled_) | 117 if (!enabled_) |
118 return false; | 118 return false; |
119 | 119 |
120 if (!is_dragging_ && event.GetAction() != ui::MotionEvent::ACTION_DOWN) | 120 if (!is_dragging_ && event.GetAction() != MotionEvent::ACTION_DOWN) |
121 return false; | 121 return false; |
122 | 122 |
123 switch (event.GetAction()) { | 123 switch (event.GetAction()) { |
124 case ui::MotionEvent::ACTION_DOWN: { | 124 case MotionEvent::ACTION_DOWN: { |
125 if (!is_visible_) | 125 if (!is_visible_) |
126 return false; | 126 return false; |
127 const float touch_size = std::max( | 127 const float touch_size = std::max( |
128 kMinTouchMajorForHitTesting, | 128 kMinTouchMajorForHitTesting, |
129 std::min(kMaxTouchMajorForHitTesting, event.GetTouchMajor())); | 129 std::min(kMaxTouchMajorForHitTesting, event.GetTouchMajor())); |
130 const gfx::RectF touch_rect(event.GetX() - touch_size * .5f, | 130 const gfx::RectF touch_rect(event.GetX() - touch_size * .5f, |
131 event.GetY() - touch_size * .5f, | 131 event.GetY() - touch_size * .5f, |
132 touch_size, | 132 touch_size, |
133 touch_size); | 133 touch_size); |
134 if (!drawable_->IntersectsWith(touch_rect)) | 134 if (!drawable_->IntersectsWith(touch_rect)) |
135 return false; | 135 return false; |
136 touch_down_position_ = gfx::PointF(event.GetX(), event.GetY()); | 136 touch_down_position_ = gfx::PointF(event.GetX(), event.GetY()); |
137 touch_to_focus_offset_ = position_ - touch_down_position_; | 137 touch_to_focus_offset_ = position_ - touch_down_position_; |
138 touch_down_time_ = event.GetEventTime(); | 138 touch_down_time_ = event.GetEventTime(); |
139 BeginDrag(); | 139 BeginDrag(); |
140 } break; | 140 } break; |
141 | 141 |
142 case ui::MotionEvent::ACTION_MOVE: { | 142 case MotionEvent::ACTION_MOVE: { |
143 gfx::PointF touch_move_position(event.GetX(), event.GetY()); | 143 gfx::PointF touch_move_position(event.GetX(), event.GetY()); |
144 if (is_drag_within_tap_region_) { | 144 if (is_drag_within_tap_region_) { |
145 const float tap_slop = client_->GetTapSlop(); | 145 const float tap_slop = client_->GetTapSlop(); |
146 is_drag_within_tap_region_ = | 146 is_drag_within_tap_region_ = |
147 (touch_move_position - touch_down_position_).LengthSquared() < | 147 (touch_move_position - touch_down_position_).LengthSquared() < |
148 tap_slop * tap_slop; | 148 tap_slop * tap_slop; |
149 } | 149 } |
150 | 150 |
151 // Note that we signal drag update even if we're inside the tap region, | 151 // Note that we signal drag update even if we're inside the tap region, |
152 // as there are cases where characters are narrower than the slop length. | 152 // as there are cases where characters are narrower than the slop length. |
153 client_->OnHandleDragUpdate(*this, | 153 client_->OnHandleDragUpdate(*this, |
154 touch_move_position + touch_to_focus_offset_); | 154 touch_move_position + touch_to_focus_offset_); |
155 } break; | 155 } break; |
156 | 156 |
157 case ui::MotionEvent::ACTION_UP: { | 157 case MotionEvent::ACTION_UP: { |
158 if (is_drag_within_tap_region_ && | 158 if (is_drag_within_tap_region_ && |
159 (event.GetEventTime() - touch_down_time_) < | 159 (event.GetEventTime() - touch_down_time_) < |
160 client_->GetTapTimeout()) { | 160 client_->GetTapTimeout()) { |
161 client_->OnHandleTapped(*this); | 161 client_->OnHandleTapped(*this); |
162 } | 162 } |
163 | 163 |
164 EndDrag(); | 164 EndDrag(); |
165 } break; | 165 } break; |
166 | 166 |
167 case ui::MotionEvent::ACTION_CANCEL: | 167 case MotionEvent::ACTION_CANCEL: |
168 EndDrag(); | 168 EndDrag(); |
169 break; | 169 break; |
170 | 170 |
171 default: | 171 default: |
172 break; | 172 break; |
173 }; | 173 }; |
174 return true; | 174 return true; |
175 } | 175 } |
176 | 176 |
177 bool TouchHandle::Animate(base::TimeTicks frame_time) { | 177 bool TouchHandle::Animate(base::TimeTicks frame_time) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 } | 254 } |
255 | 255 |
256 void TouchHandle::SetAlpha(float alpha) { | 256 void TouchHandle::SetAlpha(float alpha) { |
257 alpha = std::max(0.f, std::min(1.f, alpha)); | 257 alpha = std::max(0.f, std::min(1.f, alpha)); |
258 if (alpha_ == alpha) | 258 if (alpha_ == alpha) |
259 return; | 259 return; |
260 alpha_ = alpha; | 260 alpha_ = alpha; |
261 drawable_->SetAlpha(alpha); | 261 drawable_->SetAlpha(alpha); |
262 } | 262 } |
263 | 263 |
264 } // namespace content | 264 } // namespace ui |
OLD | NEW |