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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 gfx::Point screen_pos_2(p2); | 271 gfx::Point screen_pos_2(p2); |
269 View::ConvertPointToScreen(client_view_, &screen_pos_2); | 272 View::ConvertPointToScreen(client_view_, &screen_pos_2); |
270 | 273 |
271 if (dragging_handle_) { | 274 if (dragging_handle_) { |
272 // We need to reposition only the selection handle that is being dragged. | 275 // We need to reposition only the selection handle that is being dragged. |
273 // The other handle stays the same. Also, the selection handle being dragged | 276 // The other handle stays the same. Also, the selection handle being dragged |
274 // will always be at the end of selection, while the other handle will be at | 277 // will always be at the end of selection, while the other handle will be at |
275 // the start. | 278 // the start. |
276 dragging_handle_->SetScreenPosition(screen_pos_2); | 279 dragging_handle_->SetScreenPosition(screen_pos_2); |
277 } else { | 280 } else { |
278 UpdateContextMenu(p1, p2); | 281 UpdateContextMenu(p1, p2); |
sky
2011/09/06 17:43:27
Should this be moved to 194ish and around line 290
sadrul
2011/09/06 20:23:31
I do not think I understand: do you mean do the sa
sky
2011/09/06 20:33:36
I'm suggesting:
if (dragging_handle_) {
...
} e
sadrul
2011/09/06 20:36:51
Ah, I see. It looks like UpdateContextMenu already
| |
279 | 282 |
280 // Check if there is any selection at all. | 283 // Check if there is any selection at all. The points may not match exactly, |
281 if (screen_pos_1 == screen_pos_2) { | 284 // since the selection range computation may introduce some floating point |
285 // errors. So check for a minimum size to decide whether or not there is any | |
286 // selection. | |
287 int delta_x = screen_pos_2.x() - screen_pos_1.x(); | |
288 int delta_y = screen_pos_2.y() - screen_pos_1.y(); | |
289 if (abs(delta_x) < kMinSelectionSize && abs(delta_y) < kMinSelectionSize) { | |
282 selection_handle_1_->SetVisible(false); | 290 selection_handle_1_->SetVisible(false); |
283 selection_handle_2_->SetVisible(false); | 291 selection_handle_2_->SetVisible(false); |
284 return; | 292 return; |
285 } | 293 } |
286 | 294 |
287 if (client_view_->bounds().Contains(p1)) { | 295 if (client_view_->bounds().Contains(p1)) { |
288 selection_handle_1_->SetScreenPosition(screen_pos_1); | 296 selection_handle_1_->SetScreenPosition(screen_pos_1); |
289 selection_handle_1_->SetVisible(true); | 297 selection_handle_1_->SetVisible(true); |
290 } else { | 298 } else { |
291 selection_handle_1_->SetVisible(false); | 299 selection_handle_1_->SetVisible(false); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
413 bool TouchSelectionControllerImpl::IsSelectionHandle2Visible() { | 421 bool TouchSelectionControllerImpl::IsSelectionHandle2Visible() { |
414 return selection_handle_2_->IsVisible(); | 422 return selection_handle_2_->IsVisible(); |
415 } | 423 } |
416 | 424 |
417 TouchSelectionController* TouchSelectionController::create( | 425 TouchSelectionController* TouchSelectionController::create( |
418 TouchSelectionClientView* client_view) { | 426 TouchSelectionClientView* client_view) { |
419 return new TouchSelectionControllerImpl(client_view); | 427 return new TouchSelectionControllerImpl(client_view); |
420 } | 428 } |
421 | 429 |
422 } // namespace views | 430 } // namespace views |
OLD | NEW |