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

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

Issue 10073018: Add Delete Support to New Autofill UI (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 8 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/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 "chrome/browser/autofill/autofill_external_delegate.h" 8 #include "chrome/browser/autofill/autofill_external_delegate.h"
9 #include "content/public/browser/web_contents.h" 9 #include "content/public/browser/web_contents.h"
10 #include "content/public/browser/navigation_controller.h" 10 #include "content/public/browser/navigation_controller.h"
11 #include "content/public/browser/notification_service.h" 11 #include "content/public/browser/notification_service.h"
12 #include "content/public/browser/notification_source.h" 12 #include "content/public/browser/notification_source.h"
13 #include "content/public/browser/notification_types.h" 13 #include "content/public/browser/notification_types.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h"
15
16 using WebKit::WebAutofillClient;
14 17
15 namespace { 18 namespace {
16 19
17 // Used to indicate that no line is currently selected by the user. 20 // Used to indicate that no line is currently selected by the user.
18 const int kNoSelection = -1; 21 const int kNoSelection = -1;
19 22
20 } // end namespace 23 } // end namespace
21 24
22 AutofillPopupView::AutofillPopupView( 25 AutofillPopupView::AutofillPopupView(
23 content::WebContents* web_contents, 26 content::WebContents* web_contents,
24 AutofillExternalDelegate* external_delegate) 27 AutofillExternalDelegate* external_delegate)
25 : external_delegate_(external_delegate), 28 : external_delegate_(external_delegate),
26 separator_index_(0),
27 selected_line_(kNoSelection) { 29 selected_line_(kNoSelection) {
28 if (!web_contents) 30 if (!web_contents)
29 return; 31 return;
30 32
31 registrar_.Add(this, 33 registrar_.Add(this,
32 content::NOTIFICATION_WEB_CONTENTS_HIDDEN, 34 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
33 content::Source<content::WebContents>(web_contents)); 35 content::Source<content::WebContents>(web_contents));
34 registrar_.Add( 36 registrar_.Add(
35 this, 37 this,
36 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 38 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
37 content::Source<content::NavigationController>( 39 content::Source<content::NavigationController>(
38 &(web_contents->GetController()))); 40 &(web_contents->GetController())));
39 } 41 }
40 42
41 AutofillPopupView::~AutofillPopupView() {} 43 AutofillPopupView::~AutofillPopupView() {}
42 44
43 void AutofillPopupView::Hide() { 45 void AutofillPopupView::Hide() {
44 HideInternal(); 46 HideInternal();
45 47
46 external_delegate_->ClearPreviewedForm(); 48 external_delegate_->ClearPreviewedForm();
47 } 49 }
48 50
49 void AutofillPopupView::Show(const std::vector<string16>& autofill_values, 51 void AutofillPopupView::Show(const std::vector<string16>& autofill_values,
50 const std::vector<string16>& autofill_labels, 52 const std::vector<string16>& autofill_labels,
51 const std::vector<string16>& autofill_icons, 53 const std::vector<string16>& autofill_icons,
52 const std::vector<int>& autofill_unique_ids, 54 const std::vector<int>& autofill_unique_ids) {
53 int separator_index) {
54 autofill_values_ = autofill_values; 55 autofill_values_ = autofill_values;
55 autofill_labels_ = autofill_labels; 56 autofill_labels_ = autofill_labels;
56 autofill_icons_ = autofill_icons; 57 autofill_icons_ = autofill_icons;
57 autofill_unique_ids_ = autofill_unique_ids; 58 autofill_unique_ids_ = autofill_unique_ids;
58 59
59 separator_index_ = separator_index;
60
61 ShowInternal(); 60 ShowInternal();
62 } 61 }
63 62
64 void AutofillPopupView::SetSelectedLine(int selected_line) { 63 void AutofillPopupView::SetSelectedLine(int selected_line) {
65 if (selected_line_ == selected_line) 64 if (selected_line_ == selected_line)
66 return; 65 return;
67 66
68 if (selected_line_ != kNoSelection) 67 if (selected_line_ != kNoSelection)
69 InvalidateRow(selected_line_); 68 InvalidateRow(selected_line_);
70 69
71 if (selected_line != kNoSelection) 70 if (selected_line != kNoSelection)
72 InvalidateRow(selected_line); 71 InvalidateRow(selected_line);
73 72
74 selected_line_ = selected_line; 73 selected_line_ = selected_line;
75 74
76 if (selected_line_ != kNoSelection) { 75 if (selected_line_ != kNoSelection) {
77 external_delegate_->SelectAutofillSuggestionAtIndex( 76 external_delegate_->SelectAutofillSuggestionAtIndex(
78 autofill_unique_ids_[selected_line_], 77 autofill_unique_ids_[selected_line_]);
79 selected_line);
80 } 78 }
81 } 79 }
82 80
83 void AutofillPopupView::SelectNextLine() { 81 void AutofillPopupView::SelectNextLine() {
84 int new_selected_line = selected_line_ + 1; 82 int new_selected_line = selected_line_ + 1;
85 83
86 if (new_selected_line == static_cast<int>(autofill_values_.size())) 84 if (new_selected_line == static_cast<int>(autofill_values_.size()))
87 new_selected_line = 0; 85 new_selected_line = 0;
88 86
89 SetSelectedLine(new_selected_line); 87 SetSelectedLine(new_selected_line);
(...skipping 18 matching lines...) Expand all
108 return external_delegate()->DidAcceptAutofillSuggestions( 106 return external_delegate()->DidAcceptAutofillSuggestions(
109 autofill_values_[selected_line_], 107 autofill_values_[selected_line_],
110 autofill_unique_ids_[selected_line_], 108 autofill_unique_ids_[selected_line_],
111 selected_line_); 109 selected_line_);
112 } 110 }
113 111
114 bool AutofillPopupView::RemoveSelectedLine() { 112 bool AutofillPopupView::RemoveSelectedLine() {
115 if (selected_line_ == kNoSelection) 113 if (selected_line_ == kNoSelection)
116 return false; 114 return false;
117 115
118 // TODO(csharp) add removal code. 116 DCHECK_GE(selected_line_, 0);
119 return false; 117 DCHECK_LT(selected_line_, static_cast<int>(autofill_values_.size()));
118
119 if (!CanDelete(autofill_unique_ids_[selected_line_]))
120 return false;
121
122 if (autofill_unique_ids_[selected_line_] > 0) {
123 external_delegate()->RemoveAutofillProfileOrCreditCard(
124 autofill_unique_ids_[selected_line_]);
125 } else {
126 external_delegate()->RemoveAutocompleteEntry(
127 autofill_values_[selected_line_]);
128 }
129
130 // Remove the deleted element.
131 autofill_values_.erase(autofill_values_.begin() + selected_line_);
132 autofill_labels_.erase(autofill_labels_.begin() + selected_line_);
133 autofill_icons_.erase(autofill_icons_.begin() + selected_line_);
134 autofill_unique_ids_.erase(autofill_unique_ids_.begin() + selected_line_);
135
136 // Resize the popup.
137 ResizePopup();
138
139 SetSelectedLine(kNoSelection);
140
141 // Hide the popup if all the Autofill entries are gone.
142 if (autofill_values_.size() == 0 || !CanDelete(autofill_unique_ids_[0]))
Ilya Sherman 2012/04/24 20:08:12 I don't think this check will quite make sense onc
csharp 2012/04/25 15:05:09 Done.
143 Hide();
144
145 return true;
146 }
147
148 bool AutofillPopupView::IsSeparatorIndex(int index) {
149 return (index > 0 && autofill_unique_ids_[index - 1] >= 0 &&
150 autofill_unique_ids_[index] < 0);
Ilya Sherman 2012/04/24 20:08:12 Hmm, why isn't this just "return autofill_unique_i
csharp 2012/04/25 15:05:09 WebAutofillClient::MenuItemIDsperator is only set
151 }
152
153 bool AutofillPopupView::CanDelete(int id) {
154 return id != WebAutofillClient::MenuItemIDWarningMessage &&
155 id != WebAutofillClient::MenuItemIDClearForm &&
156 id != WebAutofillClient::MenuItemIDAutofillOptions;
Ilya Sherman 2012/04/24 20:08:12 Since the full set of ids might grow over time, it
csharp 2012/04/25 15:05:09 Done.
120 } 157 }
121 158
122 void AutofillPopupView::Observe(int type, 159 void AutofillPopupView::Observe(int type,
123 const content::NotificationSource& source, 160 const content::NotificationSource& source,
124 const content::NotificationDetails& details) { 161 const content::NotificationDetails& details) {
125 if (type == content::NOTIFICATION_WEB_CONTENTS_HIDDEN 162 if (type == content::NOTIFICATION_WEB_CONTENTS_HIDDEN
126 || type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) 163 || type == content::NOTIFICATION_NAV_ENTRY_COMMITTED)
127 Hide(); 164 Hide();
128 } 165 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_popup_view.h ('k') | chrome/browser/autofill/autofill_popup_view_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698