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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/renderer_host/render_widget_host_view_views.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: views/touchui/touch_selection_controller_impl.cc
diff --git a/views/touchui/touch_selection_controller_impl.cc b/views/touchui/touch_selection_controller_impl.cc
index a34b6becf097497ac9e3270643ed1b98d65adef3..c53dafa23f6baa86764aaa87a2896c1822ae55e6 100644
--- a/views/touchui/touch_selection_controller_impl.cc
+++ b/views/touchui/touch_selection_controller_impl.cc
@@ -31,6 +31,9 @@ const int kSelectionHandleAlpha = 0x7F;
const SkColor kSelectionHandleColor =
SkColorSetA(SK_ColorBLUE, kSelectionHandleAlpha);
+// The minimum selection size to trigger selection controller.
+const int kMinSelectionSize = 4;
+
const int kContextMenuCommands[] = {IDS_APP_CUT,
IDS_APP_COPY,
// TODO(varunjain): PASTE is acting funny due to some gtk clipboard issue.
@@ -78,6 +81,15 @@ void PaintCircle(const Circle& circle, gfx::Canvas* canvas) {
canvas->AsCanvasSkia()->drawPath(path, paint);
}
+// The points may not match exactly, since the selection range computation may
+// introduce some floating point errors. So check for a minimum size to decide
+// whether or not there is any selection.
+bool IsEmptySelection(const gfx::Point& p1, const gfx::Point& p2) {
+ int delta_x = p2.x() - p1.x();
+ int delta_y = p2.y() - p1.y();
+ return (abs(delta_x) < kMinSelectionSize && abs(delta_y) < kMinSelectionSize);
+}
+
} // namespace
namespace views {
@@ -278,7 +290,7 @@ void TouchSelectionControllerImpl::SelectionChanged(const gfx::Point& p1,
UpdateContextMenu(p1, p2);
// Check if there is any selection at all.
- if (screen_pos_1 == screen_pos_2) {
+ if (IsEmptySelection(screen_pos_2, screen_pos_1)) {
selection_handle_1_->SetVisible(false);
selection_handle_2_->SetVisible(false);
return;
@@ -386,7 +398,7 @@ void TouchSelectionControllerImpl::UpdateContextMenu(const gfx::Point& p1,
HideContextMenu();
// If there is selection, we restart the context menu timer.
- if (p1 != p2) {
+ if (!IsEmptySelection(p1, p2)) {
context_menu_timer_.Start(
FROM_HERE,
base::TimeDelta::FromMilliseconds(kContextMenuTimoutMs),
« 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