| 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "third_party/WebKit/public/web/WebInputEvent.h" | 8 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 9 | 9 |
| 10 namespace content { | 10 namespace content { |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 bool needs_animate = start_selection_handle_->Animate(frame_time); | 177 bool needs_animate = start_selection_handle_->Animate(frame_time); |
| 178 needs_animate |= end_selection_handle_->Animate(frame_time); | 178 needs_animate |= end_selection_handle_->Animate(frame_time); |
| 179 return needs_animate; | 179 return needs_animate; |
| 180 } | 180 } |
| 181 | 181 |
| 182 return false; | 182 return false; |
| 183 } | 183 } |
| 184 | 184 |
| 185 void TouchSelectionController::OnHandleDragBegin(const TouchHandle& handle) { | 185 void TouchSelectionController::OnHandleDragBegin(const TouchHandle& handle) { |
| 186 if (&handle == insertion_handle_.get()) { | 186 if (&handle == insertion_handle_.get()) { |
| 187 client_->OnSelectionEvent(INSERTION_DRAG_STARTED, GetStartPosition()); | 187 client_->OnSelectionEvent(INSERTION_DRAG_STARTED, handle.position()); |
| 188 return; | 188 return; |
| 189 } | 189 } |
| 190 | 190 |
| 191 if (&handle == start_selection_handle_.get()) { | 191 if (&handle == start_selection_handle_.get()) { |
| 192 fixed_handle_position_ = end_selection_handle_->position() - | 192 fixed_handle_position_ = end_selection_handle_->position() - |
| 193 gfx::Vector2dF(0, GetEndLineHeight() / 2.f); | 193 gfx::Vector2dF(0, GetEndLineHeight() / 2.f); |
| 194 } else { | 194 } else { |
| 195 fixed_handle_position_ = start_selection_handle_->position() - | 195 fixed_handle_position_ = start_selection_handle_->position() - |
| 196 gfx::Vector2dF(0, GetStartLineHeight() / 2.f); | 196 gfx::Vector2dF(0, GetStartLineHeight() / 2.f); |
| 197 } | 197 } |
| 198 client_->OnSelectionEvent(SELECTION_DRAG_STARTED, handle.position()); |
| 198 } | 199 } |
| 199 | 200 |
| 200 void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle, | 201 void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle, |
| 201 const gfx::PointF& position) { | 202 const gfx::PointF& position) { |
| 202 // As the position corresponds to the bottom left point of the selection | 203 // As the position corresponds to the bottom left point of the selection |
| 203 // bound, offset it by half the corresponding line height. | 204 // bound, offset it by half the corresponding line height. |
| 204 float half_line_height = &handle == end_selection_handle_.get() | 205 float half_line_height = &handle == end_selection_handle_.get() |
| 205 ? GetEndLineHeight() / 2.f | 206 ? GetEndLineHeight() / 2.f |
| 206 : GetStartLineHeight() / 2.f; | 207 : GetStartLineHeight() / 2.f; |
| 207 gfx::PointF line_position = position - gfx::Vector2dF(0, half_line_height); | 208 gfx::PointF line_position = position - gfx::Vector2dF(0, half_line_height); |
| 208 if (&handle == insertion_handle_.get()) { | 209 if (&handle == insertion_handle_.get()) { |
| 209 client_->MoveCaret(line_position); | 210 client_->MoveCaret(line_position); |
| 210 } else { | 211 } else { |
| 211 client_->SelectBetweenCoordinates(fixed_handle_position_, line_position); | 212 client_->SelectBetweenCoordinates(fixed_handle_position_, line_position); |
| 212 } | 213 } |
| 213 } | 214 } |
| 214 | 215 |
| 215 void TouchSelectionController::OnHandleDragEnd(const TouchHandle& handle) { | 216 void TouchSelectionController::OnHandleDragEnd(const TouchHandle& handle) { |
| 217 if (&handle != insertion_handle_.get()) |
| 218 client_->OnSelectionEvent(SELECTION_DRAG_STOPPED, handle.position()); |
| 216 } | 219 } |
| 217 | 220 |
| 218 void TouchSelectionController::OnHandleTapped(const TouchHandle& handle) { | 221 void TouchSelectionController::OnHandleTapped(const TouchHandle& handle) { |
| 219 if (insertion_handle_ && &handle == insertion_handle_.get()) | 222 if (insertion_handle_ && &handle == insertion_handle_.get()) |
| 220 client_->OnSelectionEvent(INSERTION_TAPPED, GetStartPosition()); | 223 client_->OnSelectionEvent(INSERTION_TAPPED, handle.position()); |
| 221 } | 224 } |
| 222 | 225 |
| 223 void TouchSelectionController::SetNeedsAnimate() { | 226 void TouchSelectionController::SetNeedsAnimate() { |
| 224 client_->SetNeedsAnimate(); | 227 client_->SetNeedsAnimate(); |
| 225 } | 228 } |
| 226 | 229 |
| 227 scoped_ptr<TouchHandleDrawable> TouchSelectionController::CreateDrawable() { | 230 scoped_ptr<TouchHandleDrawable> TouchSelectionController::CreateDrawable() { |
| 228 return client_->CreateDrawable(); | 231 return client_->CreateDrawable(); |
| 229 } | 232 } |
| 230 | 233 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 } | 377 } |
| 375 | 378 |
| 376 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle( | 379 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle( |
| 377 bool was_active) const { | 380 bool was_active) const { |
| 378 return was_active && client_->SupportsAnimation() | 381 return was_active && client_->SupportsAnimation() |
| 379 ? TouchHandle::ANIMATION_SMOOTH | 382 ? TouchHandle::ANIMATION_SMOOTH |
| 380 : TouchHandle::ANIMATION_NONE; | 383 : TouchHandle::ANIMATION_NONE; |
| 381 } | 384 } |
| 382 | 385 |
| 383 } // namespace content | 386 } // namespace content |
| OLD | NEW |