Commit 01a07364 authored by csharp@chromium.org's avatar csharp@chromium.org

[Autofill] Handle the Tab Key in the new UI

The tab key accepts the selected element and always
moves the cursor to the next field.

BUG=230328

Review URL: https://chromiumcodereview.appspot.com/13912016

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195343 0039d316-1c4b-4281-b951-d872f2087c98
parent 10b71583
......@@ -587,6 +587,31 @@ IN_PROC_BROWSER_TEST_F(AutofillTest, MAYBE_AutofillViaDownArrow) {
ExpectFilledTestForm();
}
IN_PROC_BROWSER_TEST_F(AutofillTest, AutofillSelectViaTab) {
CreateTestProfile();
// Load the test page.
ASSERT_NO_FATAL_FAILURE(ui_test_utils::NavigateToURL(browser(),
GURL(std::string(kDataURIPrefix) + kTestFormString)));
// Focus a fillable field.
FocusFirstNameField();
// Press the down arrow to initiate Autofill and wait for the popup to be
// shown.
SendKeyToPageAndWait(ui::VKEY_DOWN);
// Press the down arrow to select the suggestion and preview the autofilled
// form.
SendKeyToPopupAndWait(ui::VKEY_DOWN);
// Press tab to accept the autofill suggestions.
SendKeyToPopupAndWait(ui::VKEY_TAB);
// The form should be filled.
ExpectFilledTestForm();
}
// http://crbug.com/150084
#if defined(OS_MACOSX)
#define MAYBE_OnChangeAfterAutofill OnChangeAfterAutofill
......
......@@ -210,6 +210,12 @@ bool AutofillPopupControllerImpl::HandleKeyPressEvent(
case ui::VKEY_DELETE:
return (event.modifiers & content::NativeWebKeyboardEvent::ShiftKey) &&
RemoveSelectedLine();
case ui::VKEY_TAB:
// A tab press should cause the highlighted line to be selected, but still
// return false so the tab key press propagates and changes the cursor
// location.
AcceptSelectedLine();
return false;
case ui::VKEY_RETURN:
return AcceptSelectedLine();
default:
......
......@@ -1241,15 +1241,14 @@ void RenderWidgetHostImpl::ForwardTouchEvent(
}
void RenderWidgetHostImpl::AddKeyboardListener(KeyboardListener* listener) {
keyboard_listeners_.push_back(listener);
keyboard_listeners_.AddObserver(listener);
}
void RenderWidgetHostImpl::RemoveKeyboardListener(
KeyboardListener* listener) {
// Ensure that the element is actually in the list.
DCHECK(std::find(keyboard_listeners_.begin(), keyboard_listeners_.end(),
listener) != keyboard_listeners_.end());
keyboard_listeners_.remove(listener);
// Ensure that the element is actually an observer.
DCHECK(keyboard_listeners_.HasObserver(listener));
keyboard_listeners_.RemoveObserver(listener);
}
void RenderWidgetHostImpl::GetWebScreenInfo(WebKit::WebScreenInfo* result) {
......@@ -2205,9 +2204,10 @@ bool RenderWidgetHostImpl::KeyPressListenersHandleEvent(
if (event.skip_in_browser || event.type != WebKeyboardEvent::RawKeyDown)
return false;
for (std::list<KeyboardListener*>::iterator it = keyboard_listeners_.begin();
it != keyboard_listeners_.end(); ++it) {
if ((*it)->HandleKeyPressEvent(event))
ObserverList<KeyboardListener>::Iterator it(keyboard_listeners_);
KeyboardListener* listener;
while ((listener = it.GetNext()) != NULL) {
if (listener->HandleKeyPressEvent(event))
return true;
}
......
......@@ -17,6 +17,7 @@
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/process_util.h"
#include "base/string16.h"
#include "base/time.h"
......@@ -777,7 +778,7 @@ class CONTENT_EXPORT RenderWidgetHostImpl : virtual public RenderWidgetHost,
base::TimeTicks input_event_start_time_;
// Keyboard event listeners.
std::list<KeyboardListener*> keyboard_listeners_;
ObserverList<KeyboardListener> keyboard_listeners_;
// If true, then we should repaint when restoring even if we have a
// backingstore. This flag is set to true if we receive a paint message
......
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