| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ui/views/touchui/touch_selection_controller_impl.h" | 5 #include "ui/views/touchui/touch_selection_controller_impl.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "grit/ui_strings.h" | 9 #include "grit/ui_strings.h" |
| 10 #include "ui/base/ui_base_switches.h" | 10 #include "ui/base/ui_base_switches.h" |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 238 |
| 239 if (client_view_->GetBounds().Contains(r2.origin())) { | 239 if (client_view_->GetBounds().Contains(r2.origin())) { |
| 240 selection_handle_2_->SetSelectionRectInScreen(screen_rect_2); | 240 selection_handle_2_->SetSelectionRectInScreen(screen_rect_2); |
| 241 selection_handle_2_->SetVisible(true); | 241 selection_handle_2_->SetVisible(true); |
| 242 } else { | 242 } else { |
| 243 selection_handle_2_->SetVisible(false); | 243 selection_handle_2_->SetVisible(false); |
| 244 } | 244 } |
| 245 } | 245 } |
| 246 } | 246 } |
| 247 | 247 |
| 248 bool TouchSelectionControllerImpl::IsHandleDragInProgress() { |
| 249 return !!dragging_handle_; |
| 250 } |
| 251 |
| 248 void TouchSelectionControllerImpl::SetDraggingHandle( | 252 void TouchSelectionControllerImpl::SetDraggingHandle( |
| 249 EditingHandleView* handle) { | 253 EditingHandleView* handle) { |
| 250 dragging_handle_ = handle; | 254 dragging_handle_ = handle; |
| 251 if (dragging_handle_) | 255 if (dragging_handle_) |
| 252 HideContextMenu(); | 256 HideContextMenu(); |
| 253 else | 257 else |
| 254 StartContextMenuTimer(); | 258 StartContextMenuTimer(); |
| 255 } | 259 } |
| 256 | 260 |
| 257 void TouchSelectionControllerImpl::SelectionHandleDragged( | 261 void TouchSelectionControllerImpl::SelectionHandleDragged( |
| 258 const gfx::Point& drag_pos) { | 262 const gfx::Point& drag_pos) { |
| 259 // We do not want to show the context menu while dragging. | 263 // We do not want to show the context menu while dragging. |
| 260 HideContextMenu(); | 264 HideContextMenu(); |
| 261 | 265 |
| 262 DCHECK(dragging_handle_); | 266 DCHECK(dragging_handle_); |
| 263 | 267 |
| 268 gfx::Point offset_drag_pos(drag_pos.x(), |
| 269 drag_pos.y() - dragging_handle_->cursor_height() / 2 - |
| 270 2 * kSelectionHandleRadius); |
| 271 ConvertPointToClientView(dragging_handle_, &offset_drag_pos); |
| 264 if (dragging_handle_ == cursor_handle_.get()) { | 272 if (dragging_handle_ == cursor_handle_.get()) { |
| 265 gfx::Point p(drag_pos.x() + kSelectionHandleRadius, drag_pos.y()); | 273 client_view_->MoveCaretTo(offset_drag_pos); |
| 266 ConvertPointToClientView(dragging_handle_, &p); | |
| 267 client_view_->MoveCaretTo(p); | |
| 268 return; | 274 return; |
| 269 } | 275 } |
| 270 | 276 |
| 271 // Find the stationary selection handle. | 277 // Find the stationary selection handle. |
| 272 EditingHandleView* fixed_handle = selection_handle_1_.get(); | 278 EditingHandleView* fixed_handle = selection_handle_1_.get(); |
| 273 if (fixed_handle == dragging_handle_) | 279 if (fixed_handle == dragging_handle_) |
| 274 fixed_handle = selection_handle_2_.get(); | 280 fixed_handle = selection_handle_2_.get(); |
| 275 | 281 |
| 276 // Find selection end points in client_view's coordinate system. | 282 // Find selection end points in client_view's coordinate system. |
| 277 gfx::Point p1(drag_pos.x() + kSelectionHandleRadius, drag_pos.y()); | |
| 278 ConvertPointToClientView(dragging_handle_, &p1); | |
| 279 | |
| 280 gfx::Point p2(kSelectionHandleRadius, fixed_handle->cursor_height() / 2); | 283 gfx::Point p2(kSelectionHandleRadius, fixed_handle->cursor_height() / 2); |
| 281 ConvertPointToClientView(fixed_handle, &p2); | 284 ConvertPointToClientView(fixed_handle, &p2); |
| 282 | 285 |
| 283 // Instruct client_view to select the region between p1 and p2. The position | 286 // Instruct client_view to select the region between p1 and p2. The position |
| 284 // of |fixed_handle| is the start and that of |dragging_handle| is the end | 287 // of |fixed_handle| is the start and that of |dragging_handle| is the end |
| 285 // of selection. | 288 // of selection. |
| 286 client_view_->SelectRect(p2, p1); | 289 client_view_->SelectRect(p2, offset_drag_pos); |
| 287 } | 290 } |
| 288 | 291 |
| 289 void TouchSelectionControllerImpl::ConvertPointToClientView( | 292 void TouchSelectionControllerImpl::ConvertPointToClientView( |
| 290 EditingHandleView* source, gfx::Point* point) { | 293 EditingHandleView* source, gfx::Point* point) { |
| 291 View::ConvertPointToScreen(source, point); | 294 View::ConvertPointToScreen(source, point); |
| 292 client_view_->ConvertPointFromScreen(point); | 295 client_view_->ConvertPointFromScreen(point); |
| 293 } | 296 } |
| 294 | 297 |
| 295 bool TouchSelectionControllerImpl::IsCommandIdEnabled(int command_id) const { | 298 bool TouchSelectionControllerImpl::IsCommandIdEnabled(int command_id) const { |
| 296 return client_view_->IsCommandIdEnabled(command_id); | 299 return client_view_->IsCommandIdEnabled(command_id); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 ui::TouchEditable* client_view) { | 418 ui::TouchEditable* client_view) { |
| 416 #if defined(OS_CHROMEOS) | 419 #if defined(OS_CHROMEOS) |
| 417 if (CommandLine::ForCurrentProcess()->HasSwitch( | 420 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 418 switches::kEnableTouchEditing)) | 421 switches::kEnableTouchEditing)) |
| 419 return new views::TouchSelectionControllerImpl(client_view); | 422 return new views::TouchSelectionControllerImpl(client_view); |
| 420 #endif | 423 #endif |
| 421 return NULL; | 424 return NULL; |
| 422 } | 425 } |
| 423 | 426 |
| 424 } // namespace views | 427 } // namespace views |
| OLD | NEW |