summaryrefslogtreecommitdiffstats
path: root/views/touchui
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-07 01:54:52 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-07 01:54:52 +0000
commitc4cc2991721b4558a8035764a2fbfc12fc95e001 (patch)
treefab0b118ecc1299770a69ebe99ed55bb3922b8f2 /views/touchui
parent896e326f078a8218d58f7937ba3319ea495eb50f (diff)
downloadchromium_src-c4cc2991721b4558a8035764a2fbfc12fc95e001.zip
chromium_src-c4cc2991721b4558a8035764a2fbfc12fc95e001.tar.gz
chromium_src-c4cc2991721b4558a8035764a2fbfc12fc95e001.tar.bz2
touchui: Fine-tune selection-controller visibility.
This makes two changes: + Makes sure the selection bound has a minimum size before the controller is made visible. + Delays updating the touch-selection controller a little bit to account for the erroneous selection-change messages from webkit. BUG=none TEST=manually Review URL: http://codereview.chromium.org/7778039 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99894 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/touchui')
-rw-r--r--views/touchui/touch_selection_controller_impl.cc16
1 files changed, 14 insertions, 2 deletions
diff --git a/views/touchui/touch_selection_controller_impl.cc b/views/touchui/touch_selection_controller_impl.cc
index a34b6be..c53dafa 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),