OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/touchui/touch_selection_controller_impl.h" | 5 #include "views/touchui/touch_selection_controller_impl.h" |
6 | 6 |
7 #include "base/time.h" | 7 #include "base/time.h" |
8 #include "grit/ui_strings.h" | 8 #include "grit/ui_strings.h" |
9 #include "ui/base/l10n/l10n_util.h" | 9 #include "ui/base/l10n/l10n_util.h" |
10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 // Constants defining the visual attributes of selection handles | 27 // Constants defining the visual attributes of selection handles |
28 const int kSelectionHandleRadius = 10; | 28 const int kSelectionHandleRadius = 10; |
29 const int kSelectionHandleCursorHeight = 10; | 29 const int kSelectionHandleCursorHeight = 10; |
30 const int kSelectionHandleAlpha = 0x7F; | 30 const int kSelectionHandleAlpha = 0x7F; |
31 const SkColor kSelectionHandleColor = | 31 const SkColor kSelectionHandleColor = |
32 SkColorSetA(SK_ColorBLUE, kSelectionHandleAlpha); | 32 SkColorSetA(SK_ColorBLUE, kSelectionHandleAlpha); |
33 | 33 |
| 34 // The minimum selection size to trigger selection controller. |
| 35 const int kMinSelectionSize = 4; |
| 36 |
34 const int kContextMenuCommands[] = {IDS_APP_CUT, | 37 const int kContextMenuCommands[] = {IDS_APP_CUT, |
35 IDS_APP_COPY, | 38 IDS_APP_COPY, |
36 // TODO(varunjain): PASTE is acting funny due to some gtk clipboard issue. | 39 // TODO(varunjain): PASTE is acting funny due to some gtk clipboard issue. |
37 // Uncomment the following when that is fixed. | 40 // Uncomment the following when that is fixed. |
38 // IDS_APP_PASTE, | 41 // IDS_APP_PASTE, |
39 IDS_APP_DELETE, | 42 IDS_APP_DELETE, |
40 IDS_APP_SELECT_ALL}; | 43 IDS_APP_SELECT_ALL}; |
41 const int kContextMenuPadding = 2; | 44 const int kContextMenuPadding = 2; |
42 const int kContextMenuTimoutMs = 1000; | 45 const int kContextMenuTimoutMs = 1000; |
43 const int kContextMenuVerticalOffset = 10; | 46 const int kContextMenuVerticalOffset = 10; |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 | 275 |
273 if (dragging_handle_) { | 276 if (dragging_handle_) { |
274 // We need to reposition only the selection handle that is being dragged. | 277 // We need to reposition only the selection handle that is being dragged. |
275 // The other handle stays the same. Also, the selection handle being dragged | 278 // The other handle stays the same. Also, the selection handle being dragged |
276 // will always be at the end of selection, while the other handle will be at | 279 // will always be at the end of selection, while the other handle will be at |
277 // the start. | 280 // the start. |
278 dragging_handle_->SetScreenPosition(screen_pos_2); | 281 dragging_handle_->SetScreenPosition(screen_pos_2); |
279 } else { | 282 } else { |
280 UpdateContextMenu(p1, p2); | 283 UpdateContextMenu(p1, p2); |
281 | 284 |
282 // Check if there is any selection at all. | 285 // Check if there is any selection at all. The points may not match exactly, |
283 if (screen_pos_1 == screen_pos_2) { | 286 // since the selection range computation may introduce some floating point |
| 287 // errors. So check for a minimum size to decide whether or not there is any |
| 288 // selection. |
| 289 int delta_x = screen_pos_2.x() - screen_pos_1.x(); |
| 290 int delta_y = screen_pos_2.y() - screen_pos_1.y(); |
| 291 if (abs(delta_x) < kMinSelectionSize && abs(delta_y) < kMinSelectionSize) { |
284 selection_handle_1_->SetVisible(false); | 292 selection_handle_1_->SetVisible(false); |
285 selection_handle_2_->SetVisible(false); | 293 selection_handle_2_->SetVisible(false); |
286 return; | 294 return; |
287 } | 295 } |
288 | 296 |
289 if (client_view_->bounds().Contains(p1)) { | 297 if (client_view_->bounds().Contains(p1)) { |
290 selection_handle_1_->SetScreenPosition(screen_pos_1); | 298 selection_handle_1_->SetScreenPosition(screen_pos_1); |
291 selection_handle_1_->SetVisible(true); | 299 selection_handle_1_->SetVisible(true); |
292 } else { | 300 } else { |
293 selection_handle_1_->SetVisible(false); | 301 selection_handle_1_->SetVisible(false); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 bool TouchSelectionControllerImpl::IsSelectionHandle2Visible() { | 423 bool TouchSelectionControllerImpl::IsSelectionHandle2Visible() { |
416 return selection_handle_2_->IsVisible(); | 424 return selection_handle_2_->IsVisible(); |
417 } | 425 } |
418 | 426 |
419 TouchSelectionController* TouchSelectionController::create( | 427 TouchSelectionController* TouchSelectionController::create( |
420 TouchSelectionClientView* client_view) { | 428 TouchSelectionClientView* client_view) { |
421 return new TouchSelectionControllerImpl(client_view); | 429 return new TouchSelectionControllerImpl(client_view); |
422 } | 430 } |
423 | 431 |
424 } // namespace views | 432 } // namespace views |
OLD | NEW |