Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(441)

Side by Side Diff: chrome/browser/autofill/autofill_external_delegate.cc

Issue 9235072: Adding Mouse Support for new GTK Autofill (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixing problem with autofillAgent browser tests Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/utf_string_conversions.h" 5 #include "base/utf_string_conversions.h"
6 #include "chrome/browser/autofill/autofill_external_delegate.h" 6 #include "chrome/browser/autofill/autofill_external_delegate.h"
7 #include "chrome/browser/autofill/autofill_manager.h" 7 #include "chrome/browser/autofill/autofill_manager.h"
8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 8 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
9 #include "chrome/common/autofill_messages.h" 9 #include "chrome/common/autofill_messages.h"
10 #include "chrome/common/chrome_constants.h" 10 #include "chrome/common/chrome_constants.h"
11 #include "content/browser/renderer_host/render_view_host.h" 11 #include "content/browser/renderer_host/render_view_host.h"
12 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
13 #include "grit/chromium_strings.h" 13 #include "grit/chromium_strings.h"
14 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
15 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
16 16
17 AutofillExternalDelegate::~AutofillExternalDelegate() { 17 AutofillExternalDelegate::~AutofillExternalDelegate() {
18 } 18 }
19 19
20 AutofillExternalDelegate::AutofillExternalDelegate( 20 AutofillExternalDelegate::AutofillExternalDelegate(
21 TabContentsWrapper* tab_contents_wrapper, 21 TabContentsWrapper* tab_contents_wrapper,
22 AutofillManager* autofill_manager) 22 AutofillManager* autofill_manager)
23 : tab_contents_wrapper_(tab_contents_wrapper), 23 : tab_contents_wrapper_(tab_contents_wrapper),
24 autofill_manager_(autofill_manager), 24 autofill_manager_(autofill_manager),
25 autofill_query_id_(0), 25 autofill_query_id_(0),
26 display_warning_if_disabled_(false), 26 display_warning_if_disabled_(false),
27 has_shown_autofill_popup_for_current_edit_(false) { 27 has_shown_autofill_popup_for_current_edit_(false),
28 suggestions_clear_index_(-1),
29 suggestions_options_index_(-1) {
28 } 30 }
29 31
30 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int listIndex) { 32 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id,
31 RenderViewHost* host = 33 int list_index) {
32 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); 34 if (list_index == suggestions_options_index_ ||
33 host->Send(new AutofillMsg_SelectAutofillSuggestionAtIndex( 35 list_index == suggestions_clear_index_ ||
34 host->routing_id(), 36 unique_id == -1)
35 listIndex)); 37 return;
38
39 FillAutofillFormData(unique_id, true);
36 } 40 }
37 41
38 void AutofillExternalDelegate::OnQuery(int query_id, 42 void AutofillExternalDelegate::OnQuery(int query_id,
39 const webkit::forms::FormData& form, 43 const webkit::forms::FormData& form,
40 const webkit::forms::FormField& field, 44 const webkit::forms::FormField& field,
41 const gfx::Rect& bounds, 45 const gfx::Rect& bounds,
42 bool display_warning_if_disabled) { 46 bool display_warning_if_disabled) {
47 autofill_query_form_ = form;
43 autofill_query_field_ = field; 48 autofill_query_field_ = field;
44 display_warning_if_disabled_ = display_warning_if_disabled; 49 display_warning_if_disabled_ = display_warning_if_disabled;
45 autofill_query_id_ = query_id; 50 autofill_query_id_ = query_id;
46 51
47 OnQueryPlatformSpecific(query_id, form, field, bounds); 52 OnQueryPlatformSpecific(query_id, form, field, bounds);
48 } 53 }
49 54
50 void AutofillExternalDelegate::DidEndTextFieldEditing() {
51 has_shown_autofill_popup_for_current_edit_ = false;
52 }
53
54 void AutofillExternalDelegate::OnSuggestionsReturned( 55 void AutofillExternalDelegate::OnSuggestionsReturned(
55 int query_id, 56 int query_id,
56 const std::vector<string16>& values, 57 const std::vector<string16>& values,
57 const std::vector<string16>& labels, 58 const std::vector<string16>& labels,
58 const std::vector<string16>& icons, 59 const std::vector<string16>& icons,
59 const std::vector<int>& unique_ids) { 60 const std::vector<int>& unique_ids) {
60 if (query_id != autofill_query_id_) 61 if (query_id != autofill_query_id_)
61 return; 62 return;
62 63
63 if (values.empty()) { 64 if (values.empty()) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } 104 }
104 105
105 // The form has been auto-filled, so give the user the chance to clear the 106 // The form has been auto-filled, so give the user the chance to clear the
106 // form. Append the 'Clear form' menu item. 107 // form. Append the 'Clear form' menu item.
107 if (has_autofill_item && 108 if (has_autofill_item &&
108 autofill_query_field_.is_autofilled) { 109 autofill_query_field_.is_autofilled) {
109 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM)); 110 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM));
110 l.push_back(string16()); 111 l.push_back(string16());
111 i.push_back(string16()); 112 i.push_back(string16());
112 ids.push_back(0); 113 ids.push_back(0);
114 suggestions_clear_index_ = v.size() - 1;
113 separator_index = v.size() - 1; 115 separator_index = v.size() - 1;
114 } 116 }
115 117
116 if (has_autofill_item) { 118 if (has_autofill_item) {
117 // Append the 'Chrome Autofill options' menu item; 119 // Append the 'Chrome Autofill options' menu item;
118 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS_POPUP)); 120 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS_POPUP));
119 l.push_back(string16()); 121 l.push_back(string16());
120 i.push_back(string16()); 122 i.push_back(string16());
121 ids.push_back(0); 123 ids.push_back(0);
124 suggestions_options_index_ = v.size() - 1;
122 separator_index = values.size(); 125 separator_index = values.size();
123 } 126 }
124 127
125 // Send to display. 128 // Send to display.
126 if (!v.empty() && autofill_query_field_.is_focusable) 129 if (!v.empty() && autofill_query_field_.is_focusable)
127 ApplyAutofillSuggestions(v, l, i, ids, separator_index); 130 ApplyAutofillSuggestions(v, l, i, ids, separator_index);
128 131
129 tab_contents_wrapper_->autofill_manager()->OnDidShowAutofillSuggestions( 132 tab_contents_wrapper_->autofill_manager()->OnDidShowAutofillSuggestions(
130 has_autofill_item && !has_shown_autofill_popup_for_current_edit_); 133 has_autofill_item && !has_shown_autofill_popup_for_current_edit_);
131 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item; 134 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item;
132 } 135 }
133 136
137 void AutofillExternalDelegate::DidEndTextFieldEditing() {
138 has_shown_autofill_popup_for_current_edit_ = false;
139 }
140
141 void AutofillExternalDelegate::DidAcceptAutofillSuggestions(string16 value,
142 int unique_id,
143 unsigned index) {
144 // If the selected element is a warning we don't want to do anything.
145 if (unique_id < 0)
146 return;
147
148 // TODO(csharp): Add the password autofill manager.
149 // if (password_autofill_manager_->DidAcceptAutofillSuggestion(node, value))
150 // return;
151
152 if (suggestions_options_index_ != -1 &&
153 index == static_cast<unsigned>(suggestions_options_index_)) {
154 // User selected 'Autofill Options'.
155 autofill_manager_->OnShowAutofillDialog();
156 } else if (suggestions_clear_index_ != -1 &&
157 index == static_cast<unsigned>(suggestions_clear_index_)) {
158 // User selected 'Clear form'.
159 RenderViewHost* host =
160 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
161 host->Send(new AutofillMsg_ClearForm(host->routing_id()));
162 } else if (!unique_id) {
163 // User selected an Autocomplete entry, so we fill directly.
164 RenderViewHost* host =
165 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
166 host->Send(new AutofillMsg_SetNodeText(
167 host->routing_id(),
168 value));
169 } else {
170 FillAutofillFormData(unique_id, false);
171 }
172
173 HideAutofillPopup();
174 }
175
176 void AutofillExternalDelegate::ClearPreviewedForm() {
177 RenderViewHost* host =
178 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
179 host->Send(new AutofillMsg_ClearPreviewedForm(host->routing_id()));
180 }
181
182 void AutofillExternalDelegate::HideAutofillPopup() {
183 suggestions_clear_index_ = -1;
184 suggestions_options_index_ = -1;
185
186 HideAutofillPopupInternal();
187 }
188
189 void AutofillExternalDelegate::FillAutofillFormData(int unique_id,
190 bool is_preview) {
191 RenderViewHost* host =
192 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
193
194 if (is_preview) {
195 host->Send(new AutofillMsg_SetAutofillActionPreview(
196 host->routing_id()));
197 } else {
198 host->Send(new AutofillMsg_SetAutofillActionFill(
199 host->routing_id()));
200 }
201
202 // Fill the values for the whole form.
203 autofill_manager_->OnFillAutofillFormData(autofill_query_id_,
204 autofill_query_form_,
205 autofill_query_field_,
206 unique_id);
207 }
134 208
135 // Add a "!defined(OS_YOUROS) for each platform that implements this 209 // Add a "!defined(OS_YOUROS) for each platform that implements this
136 // in an autofill_external_delegate_YOUROS.cc. Currently there are 210 // in an autofill_external_delegate_YOUROS.cc. Currently there are
137 // none, so all platforms use the default. 211 // none, so all platforms use the default.
138 212
139 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK) 213 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK)
140 214
141 AutofillExternalDelegate* AutofillExternalDelegate::Create( 215 AutofillExternalDelegate* AutofillExternalDelegate::Create(
142 TabContentsWrapper*, AutofillManager*) { 216 TabContentsWrapper*, AutofillManager*) {
143 return NULL; 217 return NULL;
144 } 218 }
145 219
146 #endif 220 #endif
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_external_delegate.h ('k') | chrome/browser/autofill/autofill_external_delegate_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698