OLD | NEW |
---|---|
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 "chrome/browser/autofill/autofill_popup_view.h" | 5 #include "chrome/browser/autofill/autofill_popup_view.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/utf_string_conversions.h" | |
8 #include "chrome/browser/autofill/autofill_external_delegate.h" | 9 #include "chrome/browser/autofill/autofill_external_delegate.h" |
9 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
10 #include "content/public/browser/navigation_controller.h" | 11 #include "content/public/browser/navigation_controller.h" |
11 #include "content/public/browser/notification_service.h" | 12 #include "content/public/browser/notification_service.h" |
12 #include "content/public/browser/notification_source.h" | 13 #include "content/public/browser/notification_source.h" |
13 #include "content/public/browser/notification_types.h" | 14 #include "content/public/browser/notification_types.h" |
15 #include "grit/webkit_resources.h" | |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" |
15 | 17 |
16 using WebKit::WebAutofillClient; | 18 using WebKit::WebAutofillClient; |
17 | 19 |
18 namespace { | 20 namespace { |
19 | 21 |
20 // Used to indicate that no line is currently selected by the user. | 22 // Used to indicate that no line is currently selected by the user. |
21 const int kNoSelection = -1; | 23 const int kNoSelection = -1; |
22 | 24 |
25 struct DataResource { | |
26 const char* name; | |
27 int id; | |
28 }; | |
29 | |
30 const DataResource kDataResources[] = { | |
31 { "americanExpressCC", IDR_AUTOFILL_CC_AMEX }, | |
32 { "dinersCC", IDR_AUTOFILL_CC_DINERS }, | |
33 { "discoverCC", IDR_AUTOFILL_CC_DISCOVER }, | |
34 { "genericCC", IDR_AUTOFILL_CC_GENERIC }, | |
35 { "jcbCC", IDR_AUTOFILL_CC_JCB }, | |
36 { "masterCardCC", IDR_AUTOFILL_CC_MASTERCARD }, | |
37 { "soloCC", IDR_AUTOFILL_CC_SOLO }, | |
38 { "visaCC", IDR_AUTOFILL_CC_VISA }, | |
39 }; | |
40 | |
23 } // end namespace | 41 } // end namespace |
24 | 42 |
25 AutofillPopupView::AutofillPopupView( | 43 AutofillPopupView::AutofillPopupView( |
26 content::WebContents* web_contents, | 44 content::WebContents* web_contents, |
27 AutofillExternalDelegate* external_delegate) | 45 AutofillExternalDelegate* external_delegate) |
28 : external_delegate_(external_delegate), | 46 : external_delegate_(external_delegate), |
29 selected_line_(kNoSelection) { | 47 selected_line_(kNoSelection) { |
30 if (!web_contents) | 48 if (!web_contents) |
31 return; | 49 return; |
32 | 50 |
(...skipping 17 matching lines...) Expand all Loading... | |
50 | 68 |
51 void AutofillPopupView::Show(const std::vector<string16>& autofill_values, | 69 void AutofillPopupView::Show(const std::vector<string16>& autofill_values, |
52 const std::vector<string16>& autofill_labels, | 70 const std::vector<string16>& autofill_labels, |
53 const std::vector<string16>& autofill_icons, | 71 const std::vector<string16>& autofill_icons, |
54 const std::vector<int>& autofill_unique_ids) { | 72 const std::vector<int>& autofill_unique_ids) { |
55 autofill_values_ = autofill_values; | 73 autofill_values_ = autofill_values; |
56 autofill_labels_ = autofill_labels; | 74 autofill_labels_ = autofill_labels; |
57 autofill_icons_ = autofill_icons; | 75 autofill_icons_ = autofill_icons; |
58 autofill_unique_ids_ = autofill_unique_ids; | 76 autofill_unique_ids_ = autofill_unique_ids; |
59 | 77 |
78 has_icons_ = false; | |
79 for (size_t i = 0; i < autofill_icons_.size(); ++i) { | |
80 if (autofill_icons_[i] != string16()) | |
Ilya Sherman
2012/05/11 22:12:17
nit: if (!autofill_icons()[i].empty())
csharp
2012/05/14 14:19:03
Done.
| |
81 has_icons_ = true; | |
Ilya Sherman
2012/05/11 22:12:17
nit: You can add a break; stmt here as well
csharp
2012/05/14 14:19:03
Done.
| |
82 } | |
83 | |
84 | |
60 ShowInternal(); | 85 ShowInternal(); |
61 } | 86 } |
62 | 87 |
63 void AutofillPopupView::SetSelectedLine(int selected_line) { | 88 void AutofillPopupView::SetSelectedLine(int selected_line) { |
64 if (selected_line_ == selected_line) | 89 if (selected_line_ == selected_line) |
65 return; | 90 return; |
66 | 91 |
67 if (selected_line_ != kNoSelection) | 92 if (selected_line_ != kNoSelection) |
68 InvalidateRow(selected_line_); | 93 InvalidateRow(selected_line_); |
69 | 94 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 return true; | 169 return true; |
145 } | 170 } |
146 | 171 |
147 bool AutofillPopupView::IsSeparatorIndex(int index) { | 172 bool AutofillPopupView::IsSeparatorIndex(int index) { |
148 // TODO(csharp): Use WebAutofillClient::MenuItemIDSeparator instead. | 173 // TODO(csharp): Use WebAutofillClient::MenuItemIDSeparator instead. |
149 // http://crbug.com/125001 | 174 // http://crbug.com/125001 |
150 return (index > 0 && autofill_unique_ids_[index - 1] >= 0 && | 175 return (index > 0 && autofill_unique_ids_[index - 1] >= 0 && |
151 autofill_unique_ids_[index] < 0); | 176 autofill_unique_ids_[index] < 0); |
152 } | 177 } |
153 | 178 |
179 int AutofillPopupView::GetIconResourceID(const string16& resource_name) { | |
180 std::string name = UTF16ToUTF8(resource_name); | |
csharp
2012/05/11 19:26:37
I'm not sure how to best do the comparison between
Ilya Sherman
2012/05/11 22:12:17
You can use a char16 pointer for the string consta
csharp
2012/05/14 14:19:03
K, I'll just use ASCIIToUTF16 to up the constants
| |
181 | |
182 for (size_t i = 0; i < arraysize(kDataResources); ++i) { | |
183 if (!strcmp(name.c_str(), kDataResources[i].name)) | |
Ilya Sherman
2012/05/11 22:12:17
nit: Please use std::string's or string16's operat
csharp
2012/05/14 14:19:03
Done.
| |
184 return kDataResources[i].id; | |
185 } | |
186 | |
187 return -1; | |
188 } | |
189 | |
154 bool AutofillPopupView::CanDelete(int id) { | 190 bool AutofillPopupView::CanDelete(int id) { |
155 return id > 0 || | 191 return id > 0 || |
156 id == WebAutofillClient::MenuItemIDAutocompleteEntry || | 192 id == WebAutofillClient::MenuItemIDAutocompleteEntry || |
157 id == WebAutofillClient::MenuItemIDPasswordEntry; | 193 id == WebAutofillClient::MenuItemIDPasswordEntry; |
158 } | 194 } |
159 | 195 |
160 bool AutofillPopupView::HasAutofillEntries() { | 196 bool AutofillPopupView::HasAutofillEntries() { |
161 return autofill_values_.size() != 0 && | 197 return autofill_values_.size() != 0 && |
162 (autofill_unique_ids_[0] > 0 || | 198 (autofill_unique_ids_[0] > 0 || |
163 autofill_unique_ids_[0] == | 199 autofill_unique_ids_[0] == |
164 WebAutofillClient::MenuItemIDAutocompleteEntry || | 200 WebAutofillClient::MenuItemIDAutocompleteEntry || |
165 autofill_unique_ids_[0] == WebAutofillClient::MenuItemIDPasswordEntry || | 201 autofill_unique_ids_[0] == WebAutofillClient::MenuItemIDPasswordEntry || |
166 autofill_unique_ids_[0] == WebAutofillClient::MenuItemIDDataListEntry); | 202 autofill_unique_ids_[0] == WebAutofillClient::MenuItemIDDataListEntry); |
167 } | 203 } |
168 | 204 |
169 void AutofillPopupView::Observe(int type, | 205 void AutofillPopupView::Observe(int type, |
170 const content::NotificationSource& source, | 206 const content::NotificationSource& source, |
171 const content::NotificationDetails& details) { | 207 const content::NotificationDetails& details) { |
172 if (type == content::NOTIFICATION_WEB_CONTENTS_HIDDEN | 208 if (type == content::NOTIFICATION_WEB_CONTENTS_HIDDEN |
173 || type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) | 209 || type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) |
174 Hide(); | 210 Hide(); |
175 } | 211 } |
OLD | NEW |