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_selection_controller.h" | 5 #include "content/browser/renderer_host/input/touch_selection_controller.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "third_party/WebKit/public/web/WebInputEvent.h" | 9 #include "third_party/WebKit/public/web/WebInputEvent.h" |
10 | 10 |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 202 |
203 return false; | 203 return false; |
204 } | 204 } |
205 | 205 |
206 void TouchSelectionController::OnHandleDragBegin(const TouchHandle& handle) { | 206 void TouchSelectionController::OnHandleDragBegin(const TouchHandle& handle) { |
207 if (&handle == insertion_handle_.get()) { | 207 if (&handle == insertion_handle_.get()) { |
208 client_->OnSelectionEvent(INSERTION_DRAG_STARTED, handle.position()); | 208 client_->OnSelectionEvent(INSERTION_DRAG_STARTED, handle.position()); |
209 return; | 209 return; |
210 } | 210 } |
211 | 211 |
| 212 gfx::PointF base, extent; |
212 if (&handle == start_selection_handle_.get()) { | 213 if (&handle == start_selection_handle_.get()) { |
213 fixed_handle_position_ = | 214 base = end_selection_handle_->position() + GetEndLineOffset(); |
214 end_selection_handle_->position() + GetEndLineOffset(); | 215 extent = start_selection_handle_->position() + GetStartLineOffset(); |
215 } else { | 216 } else { |
216 fixed_handle_position_ = | 217 base = start_selection_handle_->position() + GetStartLineOffset(); |
217 start_selection_handle_->position() + GetStartLineOffset(); | 218 extent = end_selection_handle_->position() + GetEndLineOffset(); |
218 } | 219 } |
| 220 |
| 221 // When moving the handle we want to move only the extent point. Before doing |
| 222 // so we must make sure that the base point is set correctly. |
| 223 client_->SelectBetweenCoordinates(base, extent); |
| 224 |
219 client_->OnSelectionEvent(SELECTION_DRAG_STARTED, handle.position()); | 225 client_->OnSelectionEvent(SELECTION_DRAG_STARTED, handle.position()); |
220 } | 226 } |
221 | 227 |
222 void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle, | 228 void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle, |
223 const gfx::PointF& position) { | 229 const gfx::PointF& position) { |
224 // As the position corresponds to the bottom left point of the selection | 230 // As the position corresponds to the bottom left point of the selection |
225 // bound, offset it by half the corresponding line height. | 231 // bound, offset it by half the corresponding line height. |
226 gfx::Vector2dF line_offset = &handle == end_selection_handle_.get() | 232 gfx::Vector2dF line_offset = &handle == end_selection_handle_.get() |
227 ? GetStartLineOffset() | 233 ? GetStartLineOffset() |
228 : GetEndLineOffset(); | 234 : GetEndLineOffset(); |
229 gfx::PointF line_position = position + line_offset; | 235 gfx::PointF line_position = position + line_offset; |
230 if (&handle == insertion_handle_.get()) { | 236 if (&handle == insertion_handle_.get()) { |
231 client_->MoveCaret(line_position); | 237 client_->MoveCaret(line_position); |
232 } else { | 238 } else { |
233 client_->SelectBetweenCoordinates(fixed_handle_position_, line_position); | 239 client_->MoveRangeSelectionExtent(line_position); |
234 } | 240 } |
235 } | 241 } |
236 | 242 |
237 void TouchSelectionController::OnHandleDragEnd(const TouchHandle& handle) { | 243 void TouchSelectionController::OnHandleDragEnd(const TouchHandle& handle) { |
238 if (&handle != insertion_handle_.get()) | 244 if (&handle != insertion_handle_.get()) |
239 client_->OnSelectionEvent(SELECTION_DRAG_STOPPED, handle.position()); | 245 client_->OnSelectionEvent(SELECTION_DRAG_STOPPED, handle.position()); |
240 } | 246 } |
241 | 247 |
242 void TouchSelectionController::OnHandleTapped(const TouchHandle& handle) { | 248 void TouchSelectionController::OnHandleTapped(const TouchHandle& handle) { |
243 if (insertion_handle_ && &handle == insertion_handle_.get()) | 249 if (insertion_handle_ && &handle == insertion_handle_.get()) |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 } | 414 } |
409 | 415 |
410 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle( | 416 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle( |
411 bool was_active) const { | 417 bool was_active) const { |
412 return was_active && client_->SupportsAnimation() | 418 return was_active && client_->SupportsAnimation() |
413 ? TouchHandle::ANIMATION_SMOOTH | 419 ? TouchHandle::ANIMATION_SMOOTH |
414 : TouchHandle::ANIMATION_NONE; | 420 : TouchHandle::ANIMATION_NONE; |
415 } | 421 } |
416 | 422 |
417 } // namespace content | 423 } // namespace content |
OLD | NEW |