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

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,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 if (selected_line_ != kNoSelection) 71 if (selected_line_ != kNoSelection)
69 InvalidateRow(selected_line_); 72 InvalidateRow(selected_line_);
70 73
71 if (selected_line != kNoSelection) 74 if (selected_line != kNoSelection)
72 InvalidateRow(selected_line); 75 InvalidateRow(selected_line);
73 76
74 selected_line_ = selected_line; 77 selected_line_ = selected_line;
75 78
76 if (selected_line_ != kNoSelection) { 79 if (selected_line_ != kNoSelection) {
77 external_delegate_->SelectAutofillSuggestionAtIndex( 80 external_delegate_->SelectAutofillSuggestionAtIndex(
78 autofill_unique_ids_[selected_line_], 81 autofill_unique_ids_[selected_line_]);
79 selected_line);
80 } 82 }
81 } 83 }
82 84
83 void AutofillPopupView::SelectNextLine() { 85 void AutofillPopupView::SelectNextLine() {
84 int new_selected_line = selected_line_ + 1; 86 int new_selected_line = selected_line_ + 1;
85 87
86 if (new_selected_line == static_cast<int>(autofill_values_.size())) 88 if (new_selected_line == static_cast<int>(autofill_values_.size()))
87 new_selected_line = 0; 89 new_selected_line = 0;
88 90
89 SetSelectedLine(new_selected_line); 91 SetSelectedLine(new_selected_line);
(...skipping 15 matching lines...) Expand all
105 DCHECK_GE(selected_line_, 0); 107 DCHECK_GE(selected_line_, 0);
106 DCHECK_LT(selected_line_, static_cast<int>(autofill_values_.size())); 108 DCHECK_LT(selected_line_, static_cast<int>(autofill_values_.size()));
107 109
108 return external_delegate()->DidAcceptAutofillSuggestions( 110 return external_delegate()->DidAcceptAutofillSuggestions(
109 autofill_values_[selected_line_], 111 autofill_values_[selected_line_],
110 autofill_unique_ids_[selected_line_], 112 autofill_unique_ids_[selected_line_],
111 selected_line_); 113 selected_line_);
112 } 114 }
113 115
114 bool AutofillPopupView::RemoveSelectedLine() { 116 bool AutofillPopupView::RemoveSelectedLine() {
115 if (selected_line_ == kNoSelection) 117 if (selected_line_ == kNoSelection ||
118 (separator_index_ != -1 && separator_index_ <= selected_line_))
116 return false; 119 return false;
117 120
118 // TODO(csharp) add removal code. 121 DCHECK_GE(selected_line_, 0);
119 return false; 122 DCHECK_LT(selected_line_, static_cast<int>(autofill_values_.size()));
123
124 // Don't remove warnings
125 if (autofill_unique_ids_[selected_line_] ==
126 WebAutofillClient::MenuItemIDWarningMessage)
127 return false;
128
129 if (autofill_unique_ids_[selected_line_] > 0) {
130 external_delegate()->RemoveAutofillProfileOrCreditCard(
131 autofill_unique_ids_[selected_line_]);
132 } else {
133 external_delegate()->RemoveAutocompleteEntry(
134 autofill_values_[selected_line_]);
135 }
136
137 // Decrease the separator since there is one less entry above it.
138 --separator_index_;
139
140 // Remove the deleted element.
141 autofill_values_.erase(autofill_values_.begin() + selected_line_);
142 autofill_labels_.erase(autofill_labels_.begin() + selected_line_);
143 autofill_icons_.erase(autofill_icons_.begin() + selected_line_);
144 autofill_unique_ids_.erase(autofill_unique_ids_.begin() + selected_line_);
145
146 // Resize the popup.
147 ResizePopup();
148
149 SetSelectedLine(kNoSelection);
150
151 // Hide the popup if all the Autofill entries are gone.
152 if (autofill_values_.size() == 0 || separator_index_ == 0)
153 Hide();
154
155 return true;
120 } 156 }
121 157
122 void AutofillPopupView::Observe(int type, 158 void AutofillPopupView::Observe(int type,
123 const content::NotificationSource& source, 159 const content::NotificationSource& source,
124 const content::NotificationDetails& details) { 160 const content::NotificationDetails& details) {
125 if (type == content::NOTIFICATION_WEB_CONTENTS_HIDDEN 161 if (type == content::NOTIFICATION_WEB_CONTENTS_HIDDEN
126 || type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) 162 || type == content::NOTIFICATION_NAV_ENTRY_COMMITTED)
127 Hide(); 163 Hide();
128 } 164 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698