Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: views/touchui/touch_selection_controller_impl.cc

Issue 7778039: touchui: Fine-tune selection-controller visibility. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/renderer_host/render_widget_host_view_views.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 27 matching lines...) Expand all
71 circle.radius * 2, 74 circle.radius * 2,
72 circle.radius * 2); 75 circle.radius * 2);
73 SkRect rect; 76 SkRect rect;
74 rect.set(SkIntToScalar(bounds.x()), SkIntToScalar(bounds.y()), 77 rect.set(SkIntToScalar(bounds.x()), SkIntToScalar(bounds.y()),
75 SkIntToScalar(bounds.right()), SkIntToScalar(bounds.bottom())); 78 SkIntToScalar(bounds.right()), SkIntToScalar(bounds.bottom()));
76 SkScalar radius = SkIntToScalar(circle.radius); 79 SkScalar radius = SkIntToScalar(circle.radius);
77 path.addRoundRect(rect, radius, radius); 80 path.addRoundRect(rect, radius, radius);
78 canvas->AsCanvasSkia()->drawPath(path, paint); 81 canvas->AsCanvasSkia()->drawPath(path, paint);
79 } 82 }
80 83
84 // The points may not match exactly, since the selection range computation may
85 // introduce some floating point errors. So check for a minimum size to decide
86 // whether or not there is any selection.
87 bool IsEmptySelection(const gfx::Point& p1, const gfx::Point& p2) {
88 int delta_x = p2.x() - p1.x();
89 int delta_y = p2.y() - p1.y();
90 return (abs(delta_x) < kMinSelectionSize && abs(delta_y) < kMinSelectionSize);
91 }
92
81 } // namespace 93 } // namespace
82 94
83 namespace views { 95 namespace views {
84 96
85 // A View that displays the text selection handle. 97 // A View that displays the text selection handle.
86 class TouchSelectionControllerImpl::SelectionHandleView : public View { 98 class TouchSelectionControllerImpl::SelectionHandleView : public View {
87 public: 99 public:
88 SelectionHandleView(TouchSelectionControllerImpl* controller) 100 SelectionHandleView(TouchSelectionControllerImpl* controller)
89 : controller_(controller) { 101 : controller_(controller) {
90 widget_.reset(CreateTouchSelectionPopupWidget()); 102 widget_.reset(CreateTouchSelectionPopupWidget());
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 if (dragging_handle_) { 283 if (dragging_handle_) {
272 // We need to reposition only the selection handle that is being dragged. 284 // 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 285 // 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 286 // will always be at the end of selection, while the other handle will be at
275 // the start. 287 // the start.
276 dragging_handle_->SetScreenPosition(screen_pos_2); 288 dragging_handle_->SetScreenPosition(screen_pos_2);
277 } else { 289 } else {
278 UpdateContextMenu(p1, p2); 290 UpdateContextMenu(p1, p2);
279 291
280 // Check if there is any selection at all. 292 // Check if there is any selection at all.
281 if (screen_pos_1 == screen_pos_2) { 293 if (IsEmptySelection(screen_pos_2, screen_pos_1)) {
282 selection_handle_1_->SetVisible(false); 294 selection_handle_1_->SetVisible(false);
283 selection_handle_2_->SetVisible(false); 295 selection_handle_2_->SetVisible(false);
284 return; 296 return;
285 } 297 }
286 298
287 if (client_view_->bounds().Contains(p1)) { 299 if (client_view_->bounds().Contains(p1)) {
288 selection_handle_1_->SetScreenPosition(screen_pos_1); 300 selection_handle_1_->SetScreenPosition(screen_pos_1);
289 selection_handle_1_->SetVisible(true); 301 selection_handle_1_->SetVisible(true);
290 } else { 302 } else {
291 selection_handle_1_->SetVisible(false); 303 selection_handle_1_->SetVisible(false);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 context_menu_->SetScreenPosition(menu_pos); 391 context_menu_->SetScreenPosition(menu_pos);
380 context_menu_->SetVisible(true); 392 context_menu_->SetVisible(true);
381 } 393 }
382 394
383 void TouchSelectionControllerImpl::UpdateContextMenu(const gfx::Point& p1, 395 void TouchSelectionControllerImpl::UpdateContextMenu(const gfx::Point& p1,
384 const gfx::Point& p2) { 396 const gfx::Point& p2) {
385 // Hide context menu to be shown when the timer fires. 397 // Hide context menu to be shown when the timer fires.
386 HideContextMenu(); 398 HideContextMenu();
387 399
388 // If there is selection, we restart the context menu timer. 400 // If there is selection, we restart the context menu timer.
389 if (p1 != p2) { 401 if (!IsEmptySelection(p1, p2)) {
390 context_menu_timer_.Start( 402 context_menu_timer_.Start(
391 FROM_HERE, 403 FROM_HERE,
392 base::TimeDelta::FromMilliseconds(kContextMenuTimoutMs), 404 base::TimeDelta::FromMilliseconds(kContextMenuTimoutMs),
393 this, 405 this,
394 &TouchSelectionControllerImpl::ContextMenuTimerFired); 406 &TouchSelectionControllerImpl::ContextMenuTimerFired);
395 } 407 }
396 } 408 }
397 409
398 void TouchSelectionControllerImpl::HideContextMenu() { 410 void TouchSelectionControllerImpl::HideContextMenu() {
399 context_menu_->SetVisible(false); 411 context_menu_->SetVisible(false);
(...skipping 15 matching lines...) Expand all
415 bool TouchSelectionControllerImpl::IsSelectionHandle2Visible() { 427 bool TouchSelectionControllerImpl::IsSelectionHandle2Visible() {
416 return selection_handle_2_->IsVisible(); 428 return selection_handle_2_->IsVisible();
417 } 429 }
418 430
419 TouchSelectionController* TouchSelectionController::create( 431 TouchSelectionController* TouchSelectionController::create(
420 TouchSelectionClientView* client_view) { 432 TouchSelectionClientView* client_view) {
421 return new TouchSelectionControllerImpl(client_view); 433 return new TouchSelectionControllerImpl(client_view);
422 } 434 }
423 435
424 } // namespace views 436 } // namespace views
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/render_widget_host_view_views.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698