Chromium Code Reviews| 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 "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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 DCHECK_GE(selected_line_, 0); | 108 DCHECK_GE(selected_line_, 0); |
| 106 DCHECK_LT(selected_line_, static_cast<int>(autofill_values_.size())); | 109 DCHECK_LT(selected_line_, static_cast<int>(autofill_values_.size())); |
| 107 | 110 |
| 108 return external_delegate()->DidAcceptAutofillSuggestions( | 111 return external_delegate()->DidAcceptAutofillSuggestions( |
| 109 autofill_values_[selected_line_], | 112 autofill_values_[selected_line_], |
| 110 autofill_unique_ids_[selected_line_], | 113 autofill_unique_ids_[selected_line_], |
| 111 selected_line_); | 114 selected_line_); |
| 112 } | 115 } |
| 113 | 116 |
| 114 bool AutofillPopupView::RemoveSelectedLine() { | 117 bool AutofillPopupView::RemoveSelectedLine() { |
| 115 if (selected_line_ == kNoSelection) | 118 if (selected_line_ == kNoSelection || |
| 119 (separator_index_ != -1 && separator_index_ <= selected_line_)) | |
| 116 return false; | 120 return false; |
| 117 | 121 |
| 118 // TODO(csharp) add removal code. | 122 DCHECK_GE(selected_line_, 0); |
| 119 return false; | 123 DCHECK_LT(selected_line_, static_cast<int>(autofill_values_.size())); |
| 124 | |
| 125 // Don't remove warnings | |
| 126 if (autofill_unique_ids_[selected_line_] == | |
| 127 WebAutofillClient::MenuItemIDWarningMessage) | |
| 128 return false; | |
| 129 | |
| 130 if (autofill_unique_ids_[selected_line_] > 0) { | |
| 131 external_delegate()->RemoveAutofillProfileOrCreditCard( | |
| 132 autofill_unique_ids_[selected_line_]); | |
| 133 } else { | |
| 134 external_delegate()->RemoveAutocompleteEntry( | |
| 135 autofill_values_[selected_line_]); | |
| 136 } | |
| 137 | |
| 138 // Decrease the separator since there is one less entry above it. | |
| 139 --separator_index_; | |
|
Ilya Sherman
2012/04/19 21:01:57
Do we still need the separator index here, or can
csharp
2012/04/20 15:03:18
The only reason to keep the separator index is so
Ilya Sherman
2012/04/20 21:30:48
In order to support DataList entries -- which is w
csharp
2012/04/24 14:18:48
Done.
| |
| 140 | |
| 141 // Remove the deleted element. | |
| 142 autofill_values_.erase(autofill_values_.begin() + selected_line_); | |
| 143 autofill_labels_.erase(autofill_labels_.begin() + selected_line_); | |
| 144 autofill_icons_.erase(autofill_icons_.begin() + selected_line_); | |
| 145 autofill_unique_ids_.erase(autofill_unique_ids_.begin() + selected_line_); | |
| 146 | |
| 147 // Resize the popup. | |
| 148 ResizePopup(); | |
| 149 | |
| 150 SetSelectedLine(kNoSelection); | |
| 151 | |
| 152 // Hide the popup if all the Autofill entries are gone. | |
| 153 if (autofill_values_.size() == 0 || separator_index_ == 0) | |
| 154 Hide(); | |
| 155 | |
| 156 return true; | |
| 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 } |
| OLD | NEW |