diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-18 23:24:14 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-18 23:24:14 +0000 |
commit | db8635032b1f83436a072be14e425076a7bd8164 (patch) | |
tree | 8af2963301fafd66e4bfb7ff0a9f77ed0ad526d1 /webkit/glue/editor_client_impl.cc | |
parent | 217eae872ac412240854936ee20878636d555c53 (diff) | |
download | chromium_src-db8635032b1f83436a072be14e425076a7bd8164.zip chromium_src-db8635032b1f83436a072be14e425076a7bd8164.tar.gz chromium_src-db8635032b1f83436a072be14e425076a7bd8164.tar.bz2 |
We now show the form autofill when the user does any of these on a focused empty text-field:
- presses the up/down arrow key
- left-clicks it
The other browsers have that feature.
BUG=5130
TEST=See bug.
Review URL: http://codereview.chromium.org/14852
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7269 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/editor_client_impl.cc')
-rw-r--r-- | webkit/glue/editor_client_impl.cc | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/webkit/glue/editor_client_impl.cc b/webkit/glue/editor_client_impl.cc index 4daa74d..3d4e96f 100644 --- a/webkit/glue/editor_client_impl.cc +++ b/webkit/glue/editor_client_impl.cc @@ -575,7 +575,7 @@ const char* EditorClientImpl::interpretKeyEvent( } bool EditorClientImpl::handleEditingKeyboardEvent( - WebCore::KeyboardEvent* evt) { + WebCore::KeyboardEvent* evt) { const WebCore::PlatformKeyboardEvent* keyEvent = evt->keyEvent(); // do not treat this as text input if it's a system key event if (!keyEvent || keyEvent->isSystemKey()) @@ -627,6 +627,12 @@ bool EditorClientImpl::handleEditingKeyboardEvent( // void EditorClientImpl::handleKeyboardEvent(WebCore::KeyboardEvent* evt) { + if (evt->keyCode() == WebCore::VKEY_DOWN || + evt->keyCode() == WebCore::VKEY_UP) { + DCHECK(evt->target()->toNode()); + ShowAutofillForNode(evt->target()->toNode()); + } + if (handleEditingKeyboardEvent(evt)) evt->setDefaultHandled(); } @@ -651,13 +657,27 @@ void EditorClientImpl::textFieldDidEndEditing(WebCore::Element*) { void EditorClientImpl::textDidChangeInTextField(WebCore::Element* element) { DCHECK(element->hasLocalName(WebCore::HTMLNames::inputTag)); + Autofill(static_cast<WebCore::HTMLInputElement*>(element), false); +} + +void EditorClientImpl::ShowAutofillForNode(WebCore::Node* node) { + if (node->nodeType() == WebCore::Node::ELEMENT_NODE) { + WebCore::Element* element = static_cast<WebCore::Element*>(node); + if (element->hasLocalName(WebCore::HTMLNames::inputTag)) { + WebCore::HTMLInputElement* input_element = + static_cast<WebCore::HTMLInputElement*>(element); + if (input_element->value().isEmpty()) + Autofill(input_element, true); + } + } +} +void EditorClientImpl::Autofill(WebCore::HTMLInputElement* input_element, + bool autofill_on_empty_value) { // Cancel any pending DoAutofill calls. autofill_factory_.RevokeAll(); // Let's try to trigger autofill for that field, if applicable. - WebCore::HTMLInputElement* input_element = - static_cast<WebCore::HTMLInputElement*>(element); if (!input_element->isEnabled() || !input_element->isTextField() || input_element->isPasswordField() || !input_element->autoComplete()) { return; @@ -679,10 +699,12 @@ void EditorClientImpl::textDidChangeInTextField(WebCore::Element* element) { FROM_HERE, autofill_factory_.NewRunnableMethod(&EditorClientImpl::DoAutofill, input_element, + autofill_on_empty_value, backspace_pressed_)); } void EditorClientImpl::DoAutofill(WebCore::HTMLInputElement* input_element, + bool autofill_on_empty_value, bool backspace) { std::wstring value = webkit_glue::StringToStdWString(input_element->value()); @@ -690,7 +712,7 @@ void EditorClientImpl::DoAutofill(WebCore::HTMLInputElement* input_element, bool caret_at_end = input_element->selectionStart() == input_element->selectionEnd() && input_element->selectionEnd() == static_cast<int>(value.length()); - if (value.empty() || !caret_at_end) { + if ((!autofill_on_empty_value && value.empty()) || !caret_at_end) { web_view_->HideAutoCompletePopup(); return; } |