summaryrefslogtreecommitdiffstats
path: root/webkit/glue/editor_client_impl.cc
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-27 18:45:26 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-27 18:45:26 +0000
commit36e401c9419d17274a4d36da091ad7cb161ca750 (patch)
tree41ac830cff1d4edde1d60a5b13fa355ace02d970 /webkit/glue/editor_client_impl.cc
parent9bd47420c0bc5ce8688f7a2b5fdf9676fa7788a9 (diff)
downloadchromium_src-36e401c9419d17274a4d36da091ad7cb161ca750.zip
chromium_src-36e401c9419d17274a4d36da091ad7cb161ca750.tar.gz
chromium_src-36e401c9419d17274a4d36da091ad7cb161ca750.tar.bz2
Changed the behavior of the form autofill popup.
There are 3 ways to bring up the form autofill: 1 - start typing some text in a form text field 2 - press key down/up when the focus is on a form text field 3 - click an already focused form text field In all these cases, our current behavior is to show the form autofill only if the caret is at the end of the text field. Other browsers' behavior: IE shows the autofill popup in all 3 cases regardless of the caret position FF shows the autofill popup regardless of the caret position for case 2 and 3 but not 1. Safari never shows an autofill popup for cases 2 and 3, it shows the autofill popup for case 1 only if the caret is at the end. This CL changes our behavior to be like FF. Also this CL now lets the default processing of key up/down events happen in the case where we are showing an autofill. We were preventing default handling as it moves the caret. Since were showing the autofill in a posted task and we would check that the caret was at the end, this would prevent the autofill from showing. Now that we don't enforce the caret at the end condition with key up/down presses, we can let the default handling move the caret. BUG=6437 TEST=See description of 3 scenarios above. Make sure our behavior matches FF's. Also test that password autocomplete still works. Review URL: http://codereview.chromium.org/45067 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12681 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/editor_client_impl.cc')
-rw-r--r--webkit/glue/editor_client_impl.cc57
1 files changed, 32 insertions, 25 deletions
diff --git a/webkit/glue/editor_client_impl.cc b/webkit/glue/editor_client_impl.cc
index 6f2bdf1..e48ebf5 100644
--- a/webkit/glue/editor_client_impl.cc
+++ b/webkit/glue/editor_client_impl.cc
@@ -634,13 +634,7 @@ void EditorClientImpl::handleKeyboardEvent(WebCore::KeyboardEvent* evt) {
if (evt->keyCode() == WebCore::VKEY_DOWN ||
evt->keyCode() == WebCore::VKEY_UP) {
DCHECK(evt->target()->toNode());
- if (ShowAutofillForNode(evt->target()->toNode())) {
- // We will show an autofill popup. Let's return so we don't handle the
- // event. The handling could change the caret position, preventing the
- // popup from showing (since the actual showing is delayed, see
- // DoAutofill).
- return;
- }
+ ShowAutofillForNode(evt->target()->toNode());
}
if (handleEditingKeyboardEvent(evt))
@@ -667,19 +661,22 @@ void EditorClientImpl::textFieldDidEndEditing(WebCore::Element*) {
void EditorClientImpl::textDidChangeInTextField(WebCore::Element* element) {
DCHECK(element->hasLocalName(WebCore::HTMLNames::inputTag));
- Autofill(static_cast<WebCore::HTMLInputElement*>(element), false);
+ // Note that we only show the autofill popup in this case if the caret is at
+ // the end. This matches FireFox and Safari but not IE.
+ Autofill(static_cast<WebCore::HTMLInputElement*>(element), false, true);
}
bool EditorClientImpl::ShowAutofillForNode(WebCore::Node* node) {
WebCore::HTMLInputElement* input_element =
webkit_glue::NodeToHTMLInputElement(node);
if (input_element)
- return Autofill(input_element, true);
+ return Autofill(input_element, true, false);
return false;
}
bool EditorClientImpl::Autofill(WebCore::HTMLInputElement* input_element,
- bool autofill_on_empty_value) {
+ bool autofill_on_empty_value,
+ bool requires_caret_at_end) {
// Cancel any pending DoAutofill calls.
autofill_factory_.RevokeAll();
@@ -697,29 +694,39 @@ bool EditorClientImpl::Autofill(WebCore::HTMLInputElement* input_element,
if (input_element->value().length() > kMaximumTextSizeForAutofill)
return false;
- // We post a task for doing the autofill as the caret position is not set
- // properly at this point ( http://bugs.webkit.org/show_bug.cgi?id=16976)
- // and we need it to determine whether or not to trigger autofill.
- std::wstring value = webkit_glue::StringToStdWString(input_element->value());
- MessageLoop::current()->PostTask(
- FROM_HERE,
- autofill_factory_.NewRunnableMethod(&EditorClientImpl::DoAutofill,
- input_element,
- autofill_on_empty_value,
- backspace_pressed_));
+ if (!requires_caret_at_end) {
+ DoAutofill(input_element, autofill_on_empty_value,
+ false, backspace_pressed_);
+ } else {
+ // We post a task for doing the autofill as the caret position is not set
+ // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) and
+ // we need it to determine whether or not to trigger autofill.
+ std::wstring value =
+ webkit_glue::StringToStdWString(input_element->value());
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ autofill_factory_.NewRunnableMethod(&EditorClientImpl::DoAutofill,
+ input_element,
+ autofill_on_empty_value,
+ true,
+ backspace_pressed_));
+ }
return true;
}
void EditorClientImpl::DoAutofill(WebCore::HTMLInputElement* input_element,
bool autofill_on_empty_value,
+ bool requires_caret_at_end,
bool backspace) {
std::wstring value = webkit_glue::StringToStdWString(input_element->value());
- // Only autofill when there is some text and the caret is at the end.
- bool caret_at_end =
- input_element->selectionStart() == input_element->selectionEnd() &&
- input_element->selectionEnd() == static_cast<int>(value.length());
- if ((!autofill_on_empty_value && value.empty()) || !caret_at_end) {
+ // Enforce autofill_on_empty_value and caret_at_end.
+ bool is_caret_at_end = requires_caret_at_end ?
+ input_element->selectionStart() == input_element->selectionEnd() &&
+ input_element->selectionEnd() == static_cast<int>(value.length()) :
+ true; // When |requires_caret_at_end| is false, just pretend we are at
+ // the end.
+ if ((!autofill_on_empty_value && value.empty()) || !is_caret_at_end) {
web_view_->HideAutoCompletePopup();
return;
}