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 28 matching lines...) Expand all Loading... |
39 start_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED), | 39 start_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED), |
40 end_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED), | 40 end_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED), |
41 is_insertion_active_(false), | 41 is_insertion_active_(false), |
42 activate_insertion_automatically_(false), | 42 activate_insertion_automatically_(false), |
43 is_selection_active_(false), | 43 is_selection_active_(false), |
44 activate_selection_automatically_(false), | 44 activate_selection_automatically_(false), |
45 selection_empty_(false), | 45 selection_empty_(false), |
46 selection_editable_(false), | 46 selection_editable_(false), |
47 temporarily_hidden_(false) { | 47 temporarily_hidden_(false) { |
48 DCHECK(client_); | 48 DCHECK(client_); |
49 HideAndDisallowShowingAutomatically(); | 49 HideAndDisallowShowingAutomatically(); // XXX: needed? |
50 } | 50 } |
51 | 51 |
52 TouchSelectionController::~TouchSelectionController() { | 52 TouchSelectionController::~TouchSelectionController() { |
53 } | 53 } |
54 | 54 |
55 void TouchSelectionController::OnSelectionBoundsChanged( | 55 void TouchSelectionController::OnSelectionBoundsChanged( |
56 const cc::ViewportSelectionBound& start, | 56 const cc::ViewportSelectionBound& start, |
57 const cc::ViewportSelectionBound& end) { | 57 const cc::ViewportSelectionBound& end) { |
58 if (!activate_selection_automatically_ && | 58 if (!activate_selection_automatically_ && |
59 !activate_insertion_automatically_) { | 59 !activate_insertion_automatically_) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 | 196 |
197 if (is_selection_active_) { | 197 if (is_selection_active_) { |
198 bool needs_animate = start_selection_handle_->Animate(frame_time); | 198 bool needs_animate = start_selection_handle_->Animate(frame_time); |
199 needs_animate |= end_selection_handle_->Animate(frame_time); | 199 needs_animate |= end_selection_handle_->Animate(frame_time); |
200 return needs_animate; | 200 return needs_animate; |
201 } | 201 } |
202 | 202 |
203 return false; | 203 return false; |
204 } | 204 } |
205 | 205 |
| 206 void TouchSelectionController::ActivateSelection( |
| 207 const cc::ViewportSelectionBound& start, |
| 208 const cc::ViewportSelectionBound& end) { |
| 209 if (start.edge_bottom != end.edge_bottom) { |
| 210 ShowSelectionHandlesAutomatically(); |
| 211 OnSelectionBoundsChanged(start, end); |
| 212 } |
| 213 } |
| 214 |
206 void TouchSelectionController::OnHandleDragBegin(const TouchHandle& handle) { | 215 void TouchSelectionController::OnHandleDragBegin(const TouchHandle& handle) { |
207 if (&handle == insertion_handle_.get()) { | 216 if (&handle == insertion_handle_.get()) { |
208 client_->OnSelectionEvent(INSERTION_DRAG_STARTED, handle.position()); | 217 client_->OnSelectionEvent(INSERTION_DRAG_STARTED, handle.position()); |
209 return; | 218 return; |
210 } | 219 } |
211 | 220 |
212 if (&handle == start_selection_handle_.get()) { | 221 if (&handle == start_selection_handle_.get()) { |
213 fixed_handle_position_ = | 222 fixed_handle_position_ = |
214 end_selection_handle_->position() + GetEndLineOffset(); | 223 end_selection_handle_->position() + GetEndLineOffset(); |
215 } else { | 224 } else { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 client_->OnSelectionEvent(INSERTION_MOVED, position); | 302 client_->OnSelectionEvent(INSERTION_MOVED, position); |
294 | 303 |
295 insertion_handle_->SetVisible(GetStartVisible(), | 304 insertion_handle_->SetVisible(GetStartVisible(), |
296 GetAnimationStyle(was_active)); | 305 GetAnimationStyle(was_active)); |
297 insertion_handle_->SetPosition(position); | 306 insertion_handle_->SetPosition(position); |
298 } | 307 } |
299 | 308 |
300 void TouchSelectionController::OnSelectionChanged() { | 309 void TouchSelectionController::OnSelectionChanged() { |
301 DeactivateInsertion(); | 310 DeactivateInsertion(); |
302 | 311 |
303 if (!activate_selection_automatically_) | 312 if (!activate_selection_automatically_) // XXX: needed? |
304 return; | 313 return; |
305 | 314 |
306 const bool was_active = is_selection_active_; | 315 const bool was_active = is_selection_active_; |
307 ActivateSelection(); | 316 ActivateSelection(); |
308 | 317 |
309 const TouchHandle::AnimationStyle animation = GetAnimationStyle(was_active); | 318 const TouchHandle::AnimationStyle animation = GetAnimationStyle(was_active); |
310 start_selection_handle_->SetVisible(GetStartVisible(), animation); | 319 start_selection_handle_->SetVisible(GetStartVisible(), animation); |
311 end_selection_handle_->SetVisible(GetEndVisible(), animation); | 320 end_selection_handle_->SetVisible(GetEndVisible(), animation); |
312 | 321 |
313 start_selection_handle_->SetPosition(GetStartPosition()); | 322 start_selection_handle_->SetPosition(GetStartPosition()); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 } | 417 } |
409 | 418 |
410 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle( | 419 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle( |
411 bool was_active) const { | 420 bool was_active) const { |
412 return was_active && client_->SupportsAnimation() | 421 return was_active && client_->SupportsAnimation() |
413 ? TouchHandle::ANIMATION_SMOOTH | 422 ? TouchHandle::ANIMATION_SMOOTH |
414 : TouchHandle::ANIMATION_NONE; | 423 : TouchHandle::ANIMATION_NONE; |
415 } | 424 } |
416 | 425 |
417 } // namespace content | 426 } // namespace content |
OLD | NEW |