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" | |
10 | 9 |
11 namespace content { | 10 namespace content { |
12 namespace { | 11 namespace { |
13 | 12 |
14 TouchHandleOrientation ToTouchHandleOrientation(cc::SelectionBoundType type) { | 13 TouchHandleOrientation ToTouchHandleOrientation(cc::SelectionBoundType type) { |
15 switch (type) { | 14 switch (type) { |
16 case cc::SELECTION_BOUND_LEFT: | 15 case cc::SELECTION_BOUND_LEFT: |
17 return TOUCH_HANDLE_LEFT; | 16 return TOUCH_HANDLE_LEFT; |
18 case cc::SELECTION_BOUND_RIGHT: | 17 case cc::SELECTION_BOUND_RIGHT: |
19 return TOUCH_HANDLE_RIGHT; | 18 return TOUCH_HANDLE_RIGHT; |
(...skipping 19 matching lines...) Expand all Loading... |
39 start_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED), | 38 start_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED), |
40 end_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED), | 39 end_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED), |
41 is_insertion_active_(false), | 40 is_insertion_active_(false), |
42 activate_insertion_automatically_(false), | 41 activate_insertion_automatically_(false), |
43 is_selection_active_(false), | 42 is_selection_active_(false), |
44 activate_selection_automatically_(false), | 43 activate_selection_automatically_(false), |
45 selection_empty_(false), | 44 selection_empty_(false), |
46 selection_editable_(false), | 45 selection_editable_(false), |
47 temporarily_hidden_(false) { | 46 temporarily_hidden_(false) { |
48 DCHECK(client_); | 47 DCHECK(client_); |
49 HideAndDisallowShowingAutomatically(); | 48 HideAndDisallowShowingAutomatically(); // XXX: needed? |
50 } | 49 } |
51 | 50 |
52 TouchSelectionController::~TouchSelectionController() { | 51 TouchSelectionController::~TouchSelectionController() { |
53 } | 52 } |
54 | 53 |
55 void TouchSelectionController::OnSelectionBoundsChanged( | 54 void TouchSelectionController::OnSelectionBoundsChanged( |
56 const cc::ViewportSelectionBound& start, | 55 const cc::ViewportSelectionBound& start, |
57 const cc::ViewportSelectionBound& end) { | 56 const cc::ViewportSelectionBound& end) { |
58 if (!activate_selection_automatically_ && | 57 if (!activate_selection_automatically_ && |
59 !activate_insertion_automatically_) { | 58 !activate_insertion_automatically_) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 | 195 |
197 if (is_selection_active_) { | 196 if (is_selection_active_) { |
198 bool needs_animate = start_selection_handle_->Animate(frame_time); | 197 bool needs_animate = start_selection_handle_->Animate(frame_time); |
199 needs_animate |= end_selection_handle_->Animate(frame_time); | 198 needs_animate |= end_selection_handle_->Animate(frame_time); |
200 return needs_animate; | 199 return needs_animate; |
201 } | 200 } |
202 | 201 |
203 return false; | 202 return false; |
204 } | 203 } |
205 | 204 |
| 205 void TouchSelectionController::ActivateSelection( |
| 206 const cc::ViewportSelectionBound& start, |
| 207 const cc::ViewportSelectionBound& end) { |
| 208 if (start.edge_bottom != end.edge_bottom) { |
| 209 ShowSelectionHandlesAutomatically(); |
| 210 OnSelectionBoundsChanged(start, end); |
| 211 } |
| 212 } |
| 213 |
206 void TouchSelectionController::OnHandleDragBegin(const TouchHandle& handle) { | 214 void TouchSelectionController::OnHandleDragBegin(const TouchHandle& handle) { |
207 if (&handle == insertion_handle_.get()) { | 215 if (&handle == insertion_handle_.get()) { |
208 client_->OnSelectionEvent(INSERTION_DRAG_STARTED, handle.position()); | 216 client_->OnSelectionEvent(INSERTION_DRAG_STARTED, handle.position()); |
209 return; | 217 return; |
210 } | 218 } |
211 | 219 |
212 gfx::PointF base, extent; | 220 gfx::PointF base, extent; |
213 if (&handle == start_selection_handle_.get()) { | 221 if (&handle == start_selection_handle_.get()) { |
214 base = end_selection_handle_->position() + GetEndLineOffset(); | 222 base = end_selection_handle_->position() + GetEndLineOffset(); |
215 extent = start_selection_handle_->position() + GetStartLineOffset(); | 223 extent = start_selection_handle_->position() + GetStartLineOffset(); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 client_->OnSelectionEvent(INSERTION_MOVED, position); | 307 client_->OnSelectionEvent(INSERTION_MOVED, position); |
300 | 308 |
301 insertion_handle_->SetVisible(GetStartVisible(), | 309 insertion_handle_->SetVisible(GetStartVisible(), |
302 GetAnimationStyle(was_active)); | 310 GetAnimationStyle(was_active)); |
303 insertion_handle_->SetPosition(position); | 311 insertion_handle_->SetPosition(position); |
304 } | 312 } |
305 | 313 |
306 void TouchSelectionController::OnSelectionChanged() { | 314 void TouchSelectionController::OnSelectionChanged() { |
307 DeactivateInsertion(); | 315 DeactivateInsertion(); |
308 | 316 |
309 if (!activate_selection_automatically_) | 317 if (!activate_selection_automatically_) // XXX: needed? |
310 return; | 318 return; |
311 | 319 |
312 const bool was_active = is_selection_active_; | 320 const bool was_active = is_selection_active_; |
313 ActivateSelection(); | 321 ActivateSelection(); |
314 | 322 |
315 const TouchHandle::AnimationStyle animation = GetAnimationStyle(was_active); | 323 const TouchHandle::AnimationStyle animation = GetAnimationStyle(was_active); |
316 start_selection_handle_->SetVisible(GetStartVisible(), animation); | 324 start_selection_handle_->SetVisible(GetStartVisible(), animation); |
317 end_selection_handle_->SetVisible(GetEndVisible(), animation); | 325 end_selection_handle_->SetVisible(GetEndVisible(), animation); |
318 | 326 |
319 start_selection_handle_->SetPosition(GetStartPosition()); | 327 start_selection_handle_->SetPosition(GetStartPosition()); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 } | 422 } |
415 | 423 |
416 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle( | 424 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle( |
417 bool was_active) const { | 425 bool was_active) const { |
418 return was_active && client_->SupportsAnimation() | 426 return was_active && client_->SupportsAnimation() |
419 ? TouchHandle::ANIMATION_SMOOTH | 427 ? TouchHandle::ANIMATION_SMOOTH |
420 : TouchHandle::ANIMATION_NONE; | 428 : TouchHandle::ANIMATION_NONE; |
421 } | 429 } |
422 | 430 |
423 } // namespace content | 431 } // namespace content |
OLD | NEW |