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

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: First Draft 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 (suggestions_options_index_ == list_index ||
33 host->Send(new AutofillMsg_SelectAutofillSuggestionAtIndex( 35 suggestions_clear_index_ == list_index)
Ilya Sherman 2012/02/04 04:10:52 nit: This is probably fine as is, but I think we u
csharp 2012/02/07 22:30:58 Done.
34 host->routing_id(), 36 return;
35 listIndex)); 37
38 FillAutofillFormData(unique_id, true);
36 } 39 }
37 40
38 void AutofillExternalDelegate::OnQuery(int query_id, 41 void AutofillExternalDelegate::OnQuery(int query_id,
39 const webkit::forms::FormData& form, 42 const webkit::forms::FormData& form,
40 const webkit::forms::FormField& field, 43 const webkit::forms::FormField& field,
41 const gfx::Rect& bounds, 44 const gfx::Rect& bounds,
42 bool display_warning_if_disabled) { 45 bool display_warning_if_disabled) {
46 autofill_query_form_ = form;
43 autofill_query_field_ = field; 47 autofill_query_field_ = field;
44 display_warning_if_disabled_ = display_warning_if_disabled; 48 display_warning_if_disabled_ = display_warning_if_disabled;
45 autofill_query_id_ = query_id; 49 autofill_query_id_ = query_id;
46 50
47 OnQueryPlatformSpecific(query_id, form, field, bounds); 51 OnQueryPlatformSpecific(query_id, form, field, bounds);
48 } 52 }
49 53
50 void AutofillExternalDelegate::DidEndTextFieldEditing() {
51 has_shown_autofill_popup_for_current_edit_ = false;
52 }
53
54 void AutofillExternalDelegate::OnSuggestionsReturned( 54 void AutofillExternalDelegate::OnSuggestionsReturned(
55 int query_id, 55 int query_id,
56 const std::vector<string16>& values, 56 const std::vector<string16>& values,
57 const std::vector<string16>& labels, 57 const std::vector<string16>& labels,
58 const std::vector<string16>& icons, 58 const std::vector<string16>& icons,
59 const std::vector<int>& unique_ids) { 59 const std::vector<int>& unique_ids) {
60 if (query_id != autofill_query_id_) 60 if (query_id != autofill_query_id_)
61 return; 61 return;
62 62
63 if (values.empty()) { 63 if (values.empty()) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } 103 }
104 104
105 // The form has been auto-filled, so give the user the chance to clear the 105 // The form has been auto-filled, so give the user the chance to clear the
106 // form. Append the 'Clear form' menu item. 106 // form. Append the 'Clear form' menu item.
107 if (has_autofill_item && 107 if (has_autofill_item &&
108 autofill_query_field_.is_autofilled) { 108 autofill_query_field_.is_autofilled) {
109 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM)); 109 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM));
110 l.push_back(string16()); 110 l.push_back(string16());
111 i.push_back(string16()); 111 i.push_back(string16());
112 ids.push_back(0); 112 ids.push_back(0);
113 suggestions_clear_index_ = v.size() - 1;
113 separator_index = v.size() - 1; 114 separator_index = v.size() - 1;
114 } 115 }
115 116
116 if (has_autofill_item) { 117 if (has_autofill_item) {
117 // Append the 'Chrome Autofill options' menu item; 118 // Append the 'Chrome Autofill options' menu item;
118 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS_POPUP)); 119 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS_POPUP));
119 l.push_back(string16()); 120 l.push_back(string16());
120 i.push_back(string16()); 121 i.push_back(string16());
121 ids.push_back(0); 122 ids.push_back(0);
123 suggestions_options_index_ = v.size() - 1;
122 separator_index = values.size(); 124 separator_index = values.size();
123 } 125 }
124 126
125 // Send to display. 127 // Send to display.
126 if (!v.empty() && autofill_query_field_.is_focusable) 128 if (!v.empty() && autofill_query_field_.is_focusable)
127 ApplyAutofillSuggestions(v, l, i, ids, separator_index); 129 ApplyAutofillSuggestions(v, l, i, ids, separator_index);
128 130
129 tab_contents_wrapper_->autofill_manager()->OnDidShowAutofillSuggestions( 131 tab_contents_wrapper_->autofill_manager()->OnDidShowAutofillSuggestions(
130 has_autofill_item && !has_shown_autofill_popup_for_current_edit_); 132 has_autofill_item && !has_shown_autofill_popup_for_current_edit_);
131 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item; 133 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item;
132 } 134 }
133 135
136 void AutofillExternalDelegate::DidEndTextFieldEditing() {
137 has_shown_autofill_popup_for_current_edit_ = false;
138 }
139
140 void AutofillExternalDelegate::didAcceptAutofillSuggestions(string16 value,
141 int unique_id,
142 unsigned index) {
143 // TODO(csharp): Add the password autofill manager.
144 // if (password_autofill_manager_->DidAcceptAutofillSuggestion(node, value))
145 // return;
146
147 if (suggestions_options_index_ != -1 &&
148 index == static_cast<unsigned>(suggestions_options_index_)) {
149 // User selected 'Autofill Options'.
150 autofill_manager_->OnShowAutofillDialog();
151 } else if (suggestions_clear_index_ != -1 &&
152 index == static_cast<unsigned>(suggestions_clear_index_)) {
153 // User selected 'Clear form'.
154 RenderViewHost* host =
155 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
156 host->Send(new AutofillMsg_ClearForm(host->routing_id()));
157 } else if (!unique_id) {
158 // User selected an Autocomplete entry, so we fill directly.
159 RenderViewHost* host =
160 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
161 host->Send(new AutofillMsg_SetNodeText(
162 host->routing_id(),
163 value));
164 } else {
165 FillAutofillFormData(unique_id, false);
166 }
Ilya Sherman 2012/02/04 04:10:52 Have you verified that this behaves correctly in t
csharp 2012/02/07 22:30:58 I had forgotten about the warning message case. Ad
167
168 HideAutofillPopup();
169 }
170
171 void AutofillExternalDelegate::ClearAutofillSelection() {
172 RenderViewHost* host =
173 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
174 host->Send(new AutofillMsg_ClearAutofillSelection(host->routing_id()));
175 }
176
177 void AutofillExternalDelegate::HideAutofillPopup() {
178 suggestions_clear_index_ = -1;
179 suggestions_options_index_ = -1;
180
181 HideAutofillPopupInternal();
182 }
183
184 void AutofillExternalDelegate::FillAutofillFormData(int unique_id,
185 bool is_preview) {
186 RenderViewHost* host =
187 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
188
189 if (is_preview) {
190 host->Send(new AutofillMsg_SetAutofillActionPreview(
191 host->routing_id()));
192 } else {
193 host->Send(new AutofillMsg_SetAutofillActionFill(
194 host->routing_id()));
195 }
196
197 // Fill the values for the whole form.
198 autofill_manager_->OnFillAutofillFormData(autofill_query_id_,
199 autofill_query_form_,
200 autofill_query_field_,
201 unique_id);
202 }
134 203
135 // Add a "!defined(OS_YOUROS) for each platform that implements this 204 // Add a "!defined(OS_YOUROS) for each platform that implements this
136 // in an autofill_external_delegate_YOUROS.cc. Currently there are 205 // in an autofill_external_delegate_YOUROS.cc. Currently there are
137 // none, so all platforms use the default. 206 // none, so all platforms use the default.
138 207
139 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK) 208 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK)
140 209
141 AutofillExternalDelegate* AutofillExternalDelegate::Create( 210 AutofillExternalDelegate* AutofillExternalDelegate::Create(
142 TabContentsWrapper*, AutofillManager*) { 211 TabContentsWrapper*, AutofillManager*) {
143 return NULL; 212 return NULL;
144 } 213 }
145 214
146 #endif 215 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698