Commit 6f6544eb authored by mohsen@chromium.org's avatar mohsen@chromium.org

No touch handles when Views textfield cannot get focused

Whenever a Views textfield is going to show touch handles, it should
first check that it has focus or not. If not, the handles should not be
shown. This might be because the textfield is disabled or it is
explicitly set to be non-focusable, among other reasons.

BUG=323956

Review URL: https://codereview.chromium.org/103293004

Cr-Commit-Position: refs/heads/master@{#289137}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289137 0039d316-1c4b-4281-b951-d872f2087c98
parent d76975bb
...@@ -1753,6 +1753,9 @@ void Textfield::RevealPasswordChar(int index) { ...@@ -1753,6 +1753,9 @@ void Textfield::RevealPasswordChar(int index) {
} }
void Textfield::CreateTouchSelectionControllerAndNotifyIt() { void Textfield::CreateTouchSelectionControllerAndNotifyIt() {
if (!HasFocus())
return;
if (!touch_selection_controller_) { if (!touch_selection_controller_) {
touch_selection_controller_.reset( touch_selection_controller_.reset(
ui::TouchSelectionController::create(this)); ui::TouchSelectionController::create(this));
......
...@@ -327,6 +327,29 @@ class TextfieldTest : public ViewsTestBase, public TextfieldController { ...@@ -327,6 +327,29 @@ class TextfieldTest : public ViewsTestBase, public TextfieldController {
textfield_->OnMouseReleased(release); textfield_->OnMouseReleased(release);
} }
// Simulates a complete tap.
void Tap(const gfx::Point& point) {
GestureEventForTest begin(
ui::ET_GESTURE_BEGIN, point.x(), point.y(), 0.0f, 0.0f);
textfield_->OnGestureEvent(&begin);
GestureEventForTest tap_down(
ui::ET_GESTURE_TAP_DOWN, point.x(), point.y(), 0.0f, 0.0f);
textfield_->OnGestureEvent(&tap_down);
GestureEventForTest show_press(
ui::ET_GESTURE_SHOW_PRESS, point.x(), point.y(), 0.0f, 0.0f);
textfield_->OnGestureEvent(&show_press);
GestureEventForTest tap(
ui::ET_GESTURE_TAP, point.x(), point.y(), 1.0f, 0.0f);
textfield_->OnGestureEvent(&tap);
GestureEventForTest end(
ui::ET_GESTURE_END, point.x(), point.y(), 0.0f, 0.0f);
textfield_->OnGestureEvent(&end);
}
void VerifyTextfieldContextMenuContents(bool textfield_has_selection, void VerifyTextfieldContextMenuContents(bool textfield_has_selection,
bool can_undo, bool can_undo,
ui::MenuModel* menu) { ui::MenuModel* menu) {
...@@ -1973,6 +1996,29 @@ TEST_F(TextfieldTest, TouchSelectionAndDraggingTest) { ...@@ -1973,6 +1996,29 @@ TEST_F(TextfieldTest, TouchSelectionAndDraggingTest) {
} }
#endif #endif
TEST_F(TextfieldTest, TouchSelectionInUnfocusableTextfield) {
CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing);
InitTextfield();
textfield_->SetText(ASCIIToUTF16("hello world"));
gfx::Point touch_point(GetCursorPositionX(2), 0);
// Disable textfield and tap on it. Touch text selection should not get
// activated.
textfield_->SetEnabled(false);
Tap(touch_point);
EXPECT_FALSE(test_api_->touch_selection_controller());
textfield_->SetEnabled(true);
// Make textfield unfocusable and tap on it. Touch text selection should not
// get activated.
textfield_->SetFocusable(false);
Tap(touch_point);
EXPECT_FALSE(textfield_->HasFocus());
EXPECT_FALSE(test_api_->touch_selection_controller());
textfield_->SetFocusable(true);
}
// Long_Press gesture in Textfield can initiate a drag and drop now. // Long_Press gesture in Textfield can initiate a drag and drop now.
TEST_F(TextfieldTest, TestLongPressInitiatesDragDrop) { TEST_F(TextfieldTest, TestLongPressInitiatesDragDrop) {
InitTextfield(); InitTextfield();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment