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

Side by Side Diff: chrome/browser/ui/autofill/autofill_popup_controller_impl.cc

Issue 159853003: Moving the autofill enum from blink side to browser side (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: incorporated review comments Created 6 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 "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" 5 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/ui/autofill/autofill_popup_view.h" 12 #include "chrome/browser/ui/autofill/autofill_popup_view.h"
13 #include "chrome/browser/ui/autofill/popup_constants.h" 13 #include "chrome/browser/ui/autofill/popup_constants.h"
14 #include "components/autofill/core/browser/autofill_popup_delegate.h" 14 #include "components/autofill/core/browser/autofill_popup_delegate.h"
15 #include "components/autofill/core/common/autofill_enums.h"
15 #include "content/public/browser/native_web_keyboard_event.h" 16 #include "content/public/browser/native_web_keyboard_event.h"
16 #include "grit/webkit_resources.h" 17 #include "grit/webkit_resources.h"
17 #include "third_party/WebKit/public/web/WebAutofillClient.h"
18 #include "ui/base/resource/resource_bundle.h" 18 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/events/event.h" 19 #include "ui/events/event.h"
20 #include "ui/gfx/rect_conversions.h" 20 #include "ui/gfx/rect_conversions.h"
21 #include "ui/gfx/screen.h" 21 #include "ui/gfx/screen.h"
22 #include "ui/gfx/text_elider.h" 22 #include "ui/gfx/text_elider.h"
23 #include "ui/gfx/text_utils.h" 23 #include "ui/gfx/text_utils.h"
24 #include "ui/gfx/vector2d.h" 24 #include "ui/gfx/vector2d.h"
25 25
26 using base::WeakPtr; 26 using base::WeakPtr;
27 using blink::WebAutofillClient;
28 27
29 namespace autofill { 28 namespace autofill {
30 namespace { 29 namespace {
31 30
32 // Used to indicate that no line is currently selected by the user. 31 // Used to indicate that no line is currently selected by the user.
33 const int kNoSelection = -1; 32 const int kNoSelection = -1;
34 33
35 // The vertical height of each row in pixels. 34 // The vertical height of each row in pixels.
36 const size_t kRowHeight = 24; 35 const size_t kRowHeight = 24;
37 36
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 delegate_->OnPopupShown(); 181 delegate_->OnPopupShown();
183 controller_common_->RegisterKeyPressCallback(); 182 controller_common_->RegisterKeyPressCallback();
184 } 183 }
185 184
186 void AutofillPopupControllerImpl::UpdateDataListValues( 185 void AutofillPopupControllerImpl::UpdateDataListValues(
187 const std::vector<base::string16>& values, 186 const std::vector<base::string16>& values,
188 const std::vector<base::string16>& labels) { 187 const std::vector<base::string16>& labels) {
189 // Remove all the old data list values, which should always be at the top of 188 // Remove all the old data list values, which should always be at the top of
190 // the list if they are present. 189 // the list if they are present.
191 while (!identifiers_.empty() && 190 while (!identifiers_.empty() &&
192 identifiers_[0] == WebAutofillClient::MenuItemIDDataListEntry) { 191 identifiers_[0] == POPUP_ITEM_ID_DATALIST_ENTRY) {
193 names_.erase(names_.begin()); 192 names_.erase(names_.begin());
194 subtexts_.erase(subtexts_.begin()); 193 subtexts_.erase(subtexts_.begin());
195 icons_.erase(icons_.begin()); 194 icons_.erase(icons_.begin());
196 identifiers_.erase(identifiers_.begin()); 195 identifiers_.erase(identifiers_.begin());
197 } 196 }
198 197
199 // If there are no new data list values, exit (clearing the separator if there 198 // If there are no new data list values, exit (clearing the separator if there
200 // is one). 199 // is one).
201 if (values.empty()) { 200 if (values.empty()) {
202 if (!identifiers_.empty() && 201 if (!identifiers_.empty() && identifiers_[0] == POPUP_ITEM_ID_SEPERATOR) {
blundell 2014/02/13 16:10:58 nit: SEPARATOR
gnana 2014/02/14 09:02:06 Applied everywhere. Done.
203 identifiers_[0] == WebAutofillClient::MenuItemIDSeparator) {
204 names_.erase(names_.begin()); 202 names_.erase(names_.begin());
205 subtexts_.erase(subtexts_.begin()); 203 subtexts_.erase(subtexts_.begin());
206 icons_.erase(icons_.begin()); 204 icons_.erase(icons_.begin());
207 identifiers_.erase(identifiers_.begin()); 205 identifiers_.erase(identifiers_.begin());
208 } 206 }
209 207
210 // The popup contents have changed, so either update the bounds or hide it. 208 // The popup contents have changed, so either update the bounds or hide it.
211 if (HasSuggestions()) 209 if (HasSuggestions())
212 UpdateBoundsAndRedrawPopup(); 210 UpdateBoundsAndRedrawPopup();
213 else 211 else
214 Hide(); 212 Hide();
215 213
216 return; 214 return;
217 } 215 }
218 216
219 // Add a separator if there are any other values. 217 // Add a separator if there are any other values.
220 if (!identifiers_.empty() && 218 if (!identifiers_.empty() && identifiers_[0] != POPUP_ITEM_ID_SEPERATOR) {
221 identifiers_[0] != WebAutofillClient::MenuItemIDSeparator) {
222 names_.insert(names_.begin(), base::string16()); 219 names_.insert(names_.begin(), base::string16());
223 subtexts_.insert(subtexts_.begin(), base::string16()); 220 subtexts_.insert(subtexts_.begin(), base::string16());
224 icons_.insert(icons_.begin(), base::string16()); 221 icons_.insert(icons_.begin(), base::string16());
225 identifiers_.insert(identifiers_.begin(), 222 identifiers_.insert(identifiers_.begin(), POPUP_ITEM_ID_SEPERATOR);
226 WebAutofillClient::MenuItemIDSeparator);
227 } 223 }
228 224
229 225
230 names_.insert(names_.begin(), values.begin(), values.end()); 226 names_.insert(names_.begin(), values.begin(), values.end());
231 subtexts_.insert(subtexts_.begin(), labels.begin(), labels.end()); 227 subtexts_.insert(subtexts_.begin(), labels.begin(), labels.end());
232 228
233 // Add the values that are the same for all data list elements. 229 // Add the values that are the same for all data list elements.
234 icons_.insert(icons_.begin(), values.size(), base::string16()); 230 icons_.insert(icons_.begin(), values.size(), base::string16());
235 identifiers_.insert(identifiers_.begin(), 231 identifiers_.insert(
236 values.size(), 232 identifiers_.begin(), values.size(), POPUP_ITEM_ID_DATALIST_ENTRY);
237 WebAutofillClient::MenuItemIDDataListEntry);
238 233
239 UpdateBoundsAndRedrawPopup(); 234 UpdateBoundsAndRedrawPopup();
240 } 235 }
241 236
242 void AutofillPopupControllerImpl::Hide() { 237 void AutofillPopupControllerImpl::Hide() {
243 controller_common_->RemoveKeyPressCallback(); 238 controller_common_->RemoveKeyPressCallback();
244 if (delegate_.get()) 239 if (delegate_.get())
245 delegate_->OnPopupHidden(); 240 delegate_->OnPopupHidden();
246 241
247 if (view_) 242 if (view_)
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 return kDataResources[i].id; 332 return kDataResources[i].id;
338 } 333 }
339 334
340 return -1; 335 return -1;
341 } 336 }
342 337
343 bool AutofillPopupControllerImpl::CanDelete(size_t index) const { 338 bool AutofillPopupControllerImpl::CanDelete(size_t index) const {
344 // TODO(isherman): Native AddressBook suggestions on Mac and Android should 339 // TODO(isherman): Native AddressBook suggestions on Mac and Android should
345 // not be considered to be deleteable. 340 // not be considered to be deleteable.
346 int id = identifiers_[index]; 341 int id = identifiers_[index];
347 return id > 0 || 342 return id > 0 || id == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY ||
348 id == WebAutofillClient::MenuItemIDAutocompleteEntry || 343 id == POPUP_ITEM_ID_PASSWORD_ENTRY;
349 id == WebAutofillClient::MenuItemIDPasswordEntry;
350 } 344 }
351 345
352 bool AutofillPopupControllerImpl::IsWarning(size_t index) const { 346 bool AutofillPopupControllerImpl::IsWarning(size_t index) const {
353 return identifiers_[index] == WebAutofillClient::MenuItemIDWarningMessage; 347 return identifiers_[index] == POPUP_ITEM_ID_WARNING_MESSAGE;
354 } 348 }
355 349
356 gfx::Rect AutofillPopupControllerImpl::GetRowBounds(size_t index) { 350 gfx::Rect AutofillPopupControllerImpl::GetRowBounds(size_t index) {
357 int top = kPopupBorderThickness; 351 int top = kPopupBorderThickness;
358 for (size_t i = 0; i < index; ++i) { 352 for (size_t i = 0; i < index; ++i) {
359 top += GetRowHeightFromId(identifiers()[i]); 353 top += GetRowHeightFromId(identifiers()[i]);
360 } 354 }
361 355
362 return gfx::Rect( 356 return gfx::Rect(
363 kPopupBorderThickness, 357 kPopupBorderThickness,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 return icons_; 398 return icons_;
405 } 399 }
406 400
407 const std::vector<int>& AutofillPopupControllerImpl::identifiers() const { 401 const std::vector<int>& AutofillPopupControllerImpl::identifiers() const {
408 return identifiers_; 402 return identifiers_;
409 } 403 }
410 404
411 #if !defined(OS_ANDROID) 405 #if !defined(OS_ANDROID)
412 const gfx::FontList& AutofillPopupControllerImpl::GetNameFontListForRow( 406 const gfx::FontList& AutofillPopupControllerImpl::GetNameFontListForRow(
413 size_t index) const { 407 size_t index) const {
414 if (identifiers_[index] == WebAutofillClient::MenuItemIDWarningMessage) 408 if (identifiers_[index] == POPUP_ITEM_ID_WARNING_MESSAGE)
415 return warning_font_list_; 409 return warning_font_list_;
416 410
417 return name_font_list_; 411 return name_font_list_;
418 } 412 }
419 413
420 const gfx::FontList& AutofillPopupControllerImpl::subtext_font_list() const { 414 const gfx::FontList& AutofillPopupControllerImpl::subtext_font_list() const {
421 return subtext_font_list_; 415 return subtext_font_list_;
422 } 416 }
423 #endif 417 #endif
424 418
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 528
535 if (y <= current_height) 529 if (y <= current_height)
536 return i; 530 return i;
537 } 531 }
538 532
539 // The y value goes beyond the popup so stop the selection at the last line. 533 // The y value goes beyond the popup so stop the selection at the last line.
540 return identifiers().size() - 1; 534 return identifiers().size() - 1;
541 } 535 }
542 536
543 int AutofillPopupControllerImpl::GetRowHeightFromId(int identifier) const { 537 int AutofillPopupControllerImpl::GetRowHeightFromId(int identifier) const {
544 if (identifier == WebAutofillClient::MenuItemIDSeparator) 538 if (identifier == POPUP_ITEM_ID_SEPERATOR)
545 return kSeparatorHeight; 539 return kSeparatorHeight;
546 540
547 return kRowHeight; 541 return kRowHeight;
548 } 542 }
549 543
550 bool AutofillPopupControllerImpl::CanAccept(int id) { 544 bool AutofillPopupControllerImpl::CanAccept(int id) {
551 return id != WebAutofillClient::MenuItemIDSeparator && 545 return id != POPUP_ITEM_ID_SEPERATOR && id != POPUP_ITEM_ID_WARNING_MESSAGE;
552 id != WebAutofillClient::MenuItemIDWarningMessage;
553 } 546 }
554 547
555 bool AutofillPopupControllerImpl::HasSuggestions() { 548 bool AutofillPopupControllerImpl::HasSuggestions() {
556 return identifiers_.size() != 0 && 549 return identifiers_.size() != 0 &&
557 (identifiers_[0] > 0 || 550 (identifiers_[0] > 0 ||
558 identifiers_[0] == 551 identifiers_[0] == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY ||
559 WebAutofillClient::MenuItemIDAutocompleteEntry || 552 identifiers_[0] == POPUP_ITEM_ID_PASSWORD_ENTRY ||
560 identifiers_[0] == WebAutofillClient::MenuItemIDPasswordEntry || 553 identifiers_[0] == POPUP_ITEM_ID_DATALIST_ENTRY);
561 identifiers_[0] == WebAutofillClient::MenuItemIDDataListEntry);
562 } 554 }
563 555
564 void AutofillPopupControllerImpl::SetValues( 556 void AutofillPopupControllerImpl::SetValues(
565 const std::vector<base::string16>& names, 557 const std::vector<base::string16>& names,
566 const std::vector<base::string16>& subtexts, 558 const std::vector<base::string16>& subtexts,
567 const std::vector<base::string16>& icons, 559 const std::vector<base::string16>& icons,
568 const std::vector<int>& identifiers) { 560 const std::vector<int>& identifiers) {
569 names_ = names; 561 names_ = names;
570 full_names_ = names; 562 full_names_ = names;
571 subtexts_ = subtexts; 563 subtexts_ = subtexts;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 names_.clear(); 645 names_.clear();
654 subtexts_.clear(); 646 subtexts_.clear();
655 icons_.clear(); 647 icons_.clear();
656 identifiers_.clear(); 648 identifiers_.clear();
657 full_names_.clear(); 649 full_names_.clear();
658 650
659 selected_line_ = kNoSelection; 651 selected_line_ = kNoSelection;
660 } 652 }
661 653
662 } // namespace autofill 654 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698