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

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: Created 8 years, 11 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/generated_resources.h" 13 #include "grit/generated_resources.h"
14 #include "ui/base/l10n/l10n_util.h" 14 #include "ui/base/l10n/l10n_util.h"
15 15
16 AutofillExternalDelegate::~AutofillExternalDelegate() { 16 AutofillExternalDelegate::~AutofillExternalDelegate() {
17 } 17 }
18 18
19 AutofillExternalDelegate::AutofillExternalDelegate( 19 AutofillExternalDelegate::AutofillExternalDelegate(
20 TabContentsWrapper* tab_contents_wrapper, 20 TabContentsWrapper* tab_contents_wrapper,
21 AutofillManager* autofill_manager) 21 AutofillManager* autofill_manager)
22 : tab_contents_wrapper_(tab_contents_wrapper), 22 : tab_contents_wrapper_(tab_contents_wrapper),
23 autofill_manager_(autofill_manager), 23 autofill_manager_(autofill_manager),
24 autofill_query_id_(0), 24 autofill_query_id_(0),
25 display_warning_if_disabled_(false), 25 display_warning_if_disabled_(false),
26 has_shown_autofill_popup_for_current_edit_(false) { 26 has_shown_autofill_popup_for_current_edit_(false) {
27 } 27 }
28 28
29 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int listIndex) { 29 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id,
30 int list_index) {
31 if (suggestions_options_index_ == list_index ||
32 suggestions_clear_index_ == list_index)
33 return;
34
30 RenderViewHost* host = 35 RenderViewHost* host =
31 tab_contents_wrapper_->web_contents()->GetRenderViewHost(); 36 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
32 host->Send(new AutofillMsg_SelectAutofillSuggestionAtIndex( 37 host->Send(new AutofillMsg_SetAutofillActionPreview(
33 host->routing_id(), 38 host->routing_id()));
34 listIndex)); 39
40 // Fill the values for the whole form.
41 autofill_manager_->OnFillAutofillFormData(autofill_query_id_,
42 autofill_query_form_,
43 autofill_query_field_,
44 unique_id);
35 } 45 }
36 46
37 void AutofillExternalDelegate::OnQuery(int query_id, 47 void AutofillExternalDelegate::OnQuery(int query_id,
38 const webkit::forms::FormData& form, 48 const webkit::forms::FormData& form,
39 const webkit::forms::FormField& field, 49 const webkit::forms::FormField& field,
40 const gfx::Rect& bounds, 50 const gfx::Rect& bounds,
41 bool display_warning_if_disabled) { 51 bool display_warning_if_disabled) {
52 autofill_query_form_ = form;
42 autofill_query_field_ = field; 53 autofill_query_field_ = field;
43 display_warning_if_disabled_ = display_warning_if_disabled; 54 display_warning_if_disabled_ = display_warning_if_disabled;
44 autofill_query_id_ = query_id; 55 autofill_query_id_ = query_id;
45 56
46 OnQueryPlatformSpecific(query_id, form, field, bounds); 57 OnQueryPlatformSpecific(query_id, form, field, bounds);
47 } 58 }
48 59
49 void AutofillExternalDelegate::DidEndTextFieldEditing() { 60 void AutofillExternalDelegate::DidEndTextFieldEditing() {
50 has_shown_autofill_popup_for_current_edit_ = false; 61 has_shown_autofill_popup_for_current_edit_ = false;
51 } 62 }
52 63
64 void AutofillExternalDelegate::didAcceptAutofillSuggestions(string16 value,
65 int unique_id,
66 unsigned index) {
67 HideAutofillPopup();
68
69 // TODO(csharp): Add the password autofill manager.
70 //if (password_autofill_manager_->DidAcceptAutofillSuggestion(node, value))
71 // return;
72
73 if (suggestions_options_index_ != -1 &&
74 index == static_cast<unsigned>(suggestions_options_index_)) {
75 // User selected 'Autofill Options'.
76 autofill_manager_->OnShowAutofillDialog();
77 } else if (suggestions_clear_index_ != -1 &&
78 index == static_cast<unsigned>(suggestions_clear_index_)) {
79 // User selected 'Clear form'.
80 RenderViewHost* host =
81 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
82 host->Send(new AutofillMsg_ClearForm(host->routing_id()));
83
84 } else if (!unique_id) {
85 // User selected an Autocomplete entry, so we fill directly.
86 RenderViewHost* host =
87 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
88 host->Send(new AutofillMsg_SetNodeText(
89 host->routing_id(),
90 value));
91 } else {
92 RenderViewHost* host =
93 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
94 host->Send(new AutofillMsg_SetAutofillActionFill(
95 host->routing_id()));
96
97 // Fill the values for the whole form.
98 autofill_manager_->OnFillAutofillFormData(autofill_query_id_,
99 autofill_query_form_,
100 autofill_query_field_,
101 unique_id);
102 }
103
104 suggestions_clear_index_ = -1;
105 suggestions_options_index_ = -1;
106 }
107
53 void AutofillExternalDelegate::OnSuggestionsReturned( 108 void AutofillExternalDelegate::OnSuggestionsReturned(
54 int query_id, 109 int query_id,
55 const std::vector<string16>& values, 110 const std::vector<string16>& values,
56 const std::vector<string16>& labels, 111 const std::vector<string16>& labels,
57 const std::vector<string16>& icons, 112 const std::vector<string16>& icons,
58 const std::vector<int>& unique_ids) { 113 const std::vector<int>& unique_ids) {
59 if (query_id != autofill_query_id_) 114 if (query_id != autofill_query_id_)
60 return; 115 return;
61 116
62 if (values.empty()) { 117 if (values.empty()) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } 157 }
103 158
104 // The form has been auto-filled, so give the user the chance to clear the 159 // The form has been auto-filled, so give the user the chance to clear the
105 // form. Append the 'Clear form' menu item. 160 // form. Append the 'Clear form' menu item.
106 if (has_autofill_item && 161 if (has_autofill_item &&
107 autofill_query_field_.is_autofilled) { 162 autofill_query_field_.is_autofilled) {
108 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM)); 163 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM));
109 l.push_back(string16()); 164 l.push_back(string16());
110 i.push_back(string16()); 165 i.push_back(string16());
111 ids.push_back(0); 166 ids.push_back(0);
167 suggestions_clear_index_ = v.size() - 1;
112 separator_index = v.size() - 1; 168 separator_index = v.size() - 1;
113 } 169 }
114 170
115 if (has_autofill_item) { 171 if (has_autofill_item) {
116 // Append the 'Chrome Autofill options' menu item; 172 // Append the 'Chrome Autofill options' menu item;
117 v.push_back(l10n_util::GetStringFUTF16(IDS_AUTOFILL_OPTIONS_POPUP, 173 v.push_back(l10n_util::GetStringFUTF16(IDS_AUTOFILL_OPTIONS_POPUP,
118 WideToUTF16(chrome::kBrowserAppName))); 174 WideToUTF16(chrome::kBrowserAppName)));
119 l.push_back(string16()); 175 l.push_back(string16());
120 i.push_back(string16()); 176 i.push_back(string16());
121 ids.push_back(0); 177 ids.push_back(0);
178 suggestions_options_index_ = v.size() - 1;
122 separator_index = values.size(); 179 separator_index = values.size();
123 } 180 }
124 181
125 // Send to display. 182 // Send to display.
126 if (!v.empty() && autofill_query_field_.is_focusable) 183 if (!v.empty() && autofill_query_field_.is_focusable)
127 ApplyAutofillSuggestions(v, l, i, ids, separator_index); 184 ApplyAutofillSuggestions(v, l, i, ids, separator_index);
128 185
129 tab_contents_wrapper_->autofill_manager()->OnDidShowAutofillSuggestions( 186 tab_contents_wrapper_->autofill_manager()->OnDidShowAutofillSuggestions(
130 has_autofill_item && !has_shown_autofill_popup_for_current_edit_); 187 has_autofill_item && !has_shown_autofill_popup_for_current_edit_);
131 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item; 188 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item;
132 } 189 }
133 190
134 191
135 // Add a "!defined(OS_YOUROS) for each platform that implements this 192 // Add a "!defined(OS_YOUROS) for each platform that implements this
136 // in an autofill_external_delegate_YOUROS.cc. Currently there are 193 // in an autofill_external_delegate_YOUROS.cc. Currently there are
137 // none, so all platforms use the default. 194 // none, so all platforms use the default.
138 195
139 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK) 196 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK)
140 197
141 AutofillExternalDelegate* AutofillExternalDelegate::Create( 198 AutofillExternalDelegate* AutofillExternalDelegate::Create(
142 TabContentsWrapper*, AutofillManager*) { 199 TabContentsWrapper*, AutofillManager*) {
143 return NULL; 200 return NULL;
144 } 201 }
145 202
146 #endif 203 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698