summaryrefslogtreecommitdiffstats
path: root/ui/views/touchui
diff options
context:
space:
mode:
authorvarunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-01 03:18:39 +0000
committervarunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-01 03:18:39 +0000
commit5331978b75a104235ac98eb3be9e7e176994ab8e (patch)
treeaefed5446e6ce6e0d7386e6d4350df874442c83c /ui/views/touchui
parentb24df959055631ff52b47097053948f597eb0a0c (diff)
downloadchromium_src-5331978b75a104235ac98eb3be9e7e176994ab8e.zip
chromium_src-5331978b75a104235ac98eb3be9e7e176994ab8e.tar.gz
chromium_src-5331978b75a104235ac98eb3be9e7e176994ab8e.tar.bz2
Touch selection: The touch selection handle widget should only hit test on the
touchable part so that the event fall through when touching on the cursor line. BUG=236396 R=sadrul@chromium.org Review URL: https://codereview.chromium.org/14553002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@197555 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views/touchui')
-rw-r--r--ui/views/touchui/touch_selection_controller_impl.cc28
-rw-r--r--ui/views/touchui/touch_selection_controller_impl_unittest.cc33
2 files changed, 57 insertions, 4 deletions
diff --git a/ui/views/touchui/touch_selection_controller_impl.cc b/ui/views/touchui/touch_selection_controller_impl.cc
index e5f3fba..a527b1a 100644
--- a/ui/views/touchui/touch_selection_controller_impl.cc
+++ b/ui/views/touchui/touch_selection_controller_impl.cc
@@ -8,6 +8,7 @@
#include "grit/ui_strings.h"
#include "ui/base/ui_base_switches_util.h"
#include "ui/gfx/canvas.h"
+#include "ui/gfx/path.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/screen.h"
#include "ui/gfx/size.h"
@@ -35,13 +36,16 @@ struct Circle {
};
// Creates a widget to host SelectionHandleView.
-views::Widget* CreateTouchSelectionPopupWidget(gfx::NativeView context) {
+views::Widget* CreateTouchSelectionPopupWidget(
+ gfx::NativeView context,
+ views::WidgetDelegate* widget_delegate) {
views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_TOOLTIP);
params.can_activate = false;
params.transparent = true;
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.context = context;
+ params.delegate = widget_delegate;
widget->Init(params);
#if defined(USE_AURA)
SetShadowType(widget->GetNativeView(), views::corewm::SHADOW_TYPE_NONE);
@@ -77,13 +81,14 @@ gfx::Rect GetHandleBoundsFromCursor(const gfx::Rect& cursor) {
namespace views {
// A View that displays the text selection handle.
-class TouchSelectionControllerImpl::EditingHandleView : public View {
+class TouchSelectionControllerImpl::EditingHandleView
+ : public views::WidgetDelegateView {
public:
explicit EditingHandleView(TouchSelectionControllerImpl* controller,
gfx::NativeView context)
: controller_(controller),
cursor_height_(0) {
- widget_.reset(CreateTouchSelectionPopupWidget(context));
+ widget_.reset(CreateTouchSelectionPopupWidget(context, this));
widget_->SetContentsView(this);
widget_->SetAlwaysOnTop(true);
@@ -96,7 +101,22 @@ class TouchSelectionControllerImpl::EditingHandleView : public View {
int cursor_height() const { return cursor_height_; }
- // Overridden from View:
+ // Overridden from views::WidgetDelegateView:
+ virtual bool WidgetHasHitTestMask() const OVERRIDE {
+ return true;
+ }
+
+ virtual void GetWidgetHitTestMask(gfx::Path* mask) const OVERRIDE {
+ mask->addCircle(SkIntToScalar(kSelectionHandleRadius),
+ SkIntToScalar(kSelectionHandleRadius + cursor_height_),
+ SkIntToScalar(kSelectionHandleRadius));
+ }
+
+ virtual void DeleteDelegate() OVERRIDE {
+ // We are owned and deleted by TouchSelectionController.
+ }
+
+ // Overridden from views::View:
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
Circle circle = {kSelectionHandleRadius, gfx::Point(kSelectionHandleRadius,
kSelectionHandleRadius + cursor_height_),
diff --git a/ui/views/touchui/touch_selection_controller_impl_unittest.cc b/ui/views/touchui/touch_selection_controller_impl_unittest.cc
index 78a8236..25fc0f1 100644
--- a/ui/views/touchui/touch_selection_controller_impl_unittest.cc
+++ b/ui/views/touchui/touch_selection_controller_impl_unittest.cc
@@ -15,6 +15,11 @@
#include "ui/views/touchui/touch_selection_controller_impl.h"
#include "ui/views/widget/widget.h"
+#if defined(USE_AURA)
+#include "ui/aura/test/event_generator.h"
+#include "ui/aura/window.h"
+#endif
+
namespace views {
class TouchSelectionControllerImplTest : public ViewsTestBase {
@@ -51,8 +56,10 @@ class TouchSelectionControllerImplTest : public ViewsTestBase {
textfield_view_ = static_cast<NativeTextfieldViews*>(
textfield_->GetNativeWrapperForTesting());
+ textfield_->SetBoundsRect(params.bounds);
textfield_view_->SetBoundsRect(params.bounds);
textfield_->set_id(1);
+ widget_->Show();
DCHECK(textfield_view_);
textfield_->RequestFocus();
@@ -403,4 +410,30 @@ TEST_F(TouchSelectionControllerImplTest, SelectRectInBidiCallbackTest) {
VERIFY_HANDLE_POSITIONS(false);
}
+#if defined(USE_AURA)
+TEST_F(TouchSelectionControllerImplTest,
+ DoubleTapInTextfieldWithCursorHandleShouldSelectWord) {
+ CreateTextfield();
+ textfield_->SetText(ASCIIToUTF16("some text"));
+ aura::test::EventGenerator generator(
+ textfield_->GetWidget()->GetNativeView()->GetRootWindow());
+
+ // Tap the textfield to invoke touch selection.
+ generator.GestureTapAt(gfx::Point(10, 10));
+
+ // Cursor handle should be visible.
+ EXPECT_FALSE(textfield_->HasSelection());
+ VERIFY_HANDLE_POSITIONS(false);
+
+ // Double tap on the cursor handle position. We want to check that the cursor
+ // handle is not eating the event and that the event is falling through to the
+ // textfield.
+ gfx::Point cursor_pos = GetCursorHandlePosition();
+ generator.GestureTapAt(cursor_pos);
+ generator.GestureTapAt(cursor_pos);
+ EXPECT_TRUE(textfield_->HasSelection());
+ VERIFY_HANDLE_POSITIONS(false);
+}
+#endif
+
} // namespace views