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/ui/autofill/autofill_popup_controller_impl.h" | 5 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/ui/autofill/autofill_popup_delegate.h" | 9 #include "chrome/browser/ui/autofill/autofill_popup_delegate.h" |
| 10 #include "chrome/browser/ui/autofill/autofill_popup_view.h" | 10 #include "chrome/browser/ui/autofill/autofill_popup_view.h" |
| 11 #include "content/public/browser/native_web_keyboard_event.h" | 11 #include "content/public/browser/native_web_keyboard_event.h" |
| 12 #include "grit/webkit_resources.h" | 12 #include "grit/webkit_resources.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" |
| 14 #include "ui/base/events/event.h" | 14 #include "ui/base/events/event.h" |
| 15 | 15 |
| 16 using WebKit::WebAutofillClient; | 16 using WebKit::WebAutofillClient; |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // 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. |
| 21 const int kNoSelection = -1; | 21 const int kNoSelection = -1; |
| 22 | 22 |
| 23 // Size difference between value text and label text in pixels. | 23 // Size difference between name and subtext in pixels. |
| 24 const int kLabelFontSizeDelta = -2; | 24 const int kLabelFontSizeDelta = -2; |
| 25 | 25 |
| 26 // The vertical height of each row in pixels. | 26 // The vertical height of each row in pixels. |
| 27 const size_t kRowHeight = 24; | 27 const size_t kRowHeight = 24; |
| 28 | 28 |
| 29 // The vertical height of a separator in pixels. | 29 // The vertical height of a separator in pixels. |
| 30 const size_t kSeparatorHeight = 1; | 30 const size_t kSeparatorHeight = 1; |
| 31 | 31 |
| 32 // The amount of minimum padding between the Autofill value and label in pixels. | 32 // The amount of minimum padding between the Autofill value and label in pixels. |
|
Ilya Sherman
2012/12/20 23:11:55
nit: Please update this comment.
Evan Stade
2012/12/20 23:15:01
Done.
| |
| 33 const size_t kLabelPadding = 15; | 33 const size_t kNamePadding = 15; |
| 34 | 34 |
| 35 // The maximum amount of characters to display from either the label or value. | 35 // The maximum amount of characters to display from either the name or subtext. |
| 36 const size_t kMaxTextLength = 15; | 36 const size_t kMaxTextLength = 15; |
| 37 | 37 |
| 38 #if !defined(OS_ANDROID) | 38 #if !defined(OS_ANDROID) |
| 39 const size_t kIconPadding = AutofillPopupView::kIconPadding; | 39 const size_t kIconPadding = AutofillPopupView::kIconPadding; |
| 40 const size_t kEndPadding = AutofillPopupView::kEndPadding; | 40 const size_t kEndPadding = AutofillPopupView::kEndPadding; |
| 41 const size_t kDeleteIconHeight = AutofillPopupView::kDeleteIconHeight; | 41 const size_t kDeleteIconHeight = AutofillPopupView::kDeleteIconHeight; |
| 42 const size_t kDeleteIconWidth = AutofillPopupView::kDeleteIconWidth; | 42 const size_t kDeleteIconWidth = AutofillPopupView::kDeleteIconWidth; |
| 43 const size_t kAutofillIconWidth = AutofillPopupView::kAutofillIconWidth; | 43 const size_t kAutofillIconWidth = AutofillPopupView::kAutofillIconWidth; |
| 44 #endif | 44 #endif |
| 45 | 45 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 gfx::NativeView container_view, | 87 gfx::NativeView container_view, |
| 88 const gfx::Rect& element_bounds) | 88 const gfx::Rect& element_bounds) |
| 89 : view_(NULL), | 89 : view_(NULL), |
| 90 delegate_(delegate), | 90 delegate_(delegate), |
| 91 container_view_(container_view), | 91 container_view_(container_view), |
| 92 element_bounds_(element_bounds), | 92 element_bounds_(element_bounds), |
| 93 selected_line_(kNoSelection), | 93 selected_line_(kNoSelection), |
| 94 delete_icon_hovered_(false), | 94 delete_icon_hovered_(false), |
| 95 is_hiding_(false) { | 95 is_hiding_(false) { |
| 96 #if !defined(OS_ANDROID) | 96 #if !defined(OS_ANDROID) |
| 97 label_font_ = value_font_.DeriveFont(kLabelFontSizeDelta); | 97 subtext_font_ = name_font_.DeriveFont(kLabelFontSizeDelta); |
| 98 #endif | 98 #endif |
| 99 } | 99 } |
| 100 | 100 |
| 101 AutofillPopupControllerImpl::~AutofillPopupControllerImpl() { | 101 AutofillPopupControllerImpl::~AutofillPopupControllerImpl() { |
| 102 if (delegate_) | 102 if (delegate_) |
| 103 delegate_->ControllerDestroyed(); | 103 delegate_->ControllerDestroyed(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void AutofillPopupControllerImpl::Show( | 106 void AutofillPopupControllerImpl::Show( |
| 107 const std::vector<string16>& autofill_values, | 107 const std::vector<string16>& names, |
| 108 const std::vector<string16>& autofill_labels, | 108 const std::vector<string16>& subtexts, |
| 109 const std::vector<string16>& autofill_icons, | 109 const std::vector<string16>& icons, |
| 110 const std::vector<int>& autofill_unique_ids) { | 110 const std::vector<int>& identifiers) { |
| 111 autofill_values_ = autofill_values; | 111 names_ = names; |
| 112 autofill_labels_ = autofill_labels; | 112 subtexts_ = subtexts; |
| 113 autofill_icons_ = autofill_icons; | 113 icons_ = icons; |
| 114 autofill_unique_ids_ = autofill_unique_ids; | 114 identifiers_ = identifiers; |
| 115 | 115 |
| 116 #if !defined(OS_ANDROID) | 116 #if !defined(OS_ANDROID) |
| 117 // Android displays the long text with ellipsis using the view attributes. | 117 // Android displays the long text with ellipsis using the view attributes. |
| 118 | 118 |
| 119 // TODO(csharp): Fix crbug.com/156163 and use better logic when clipping. | 119 // TODO(csharp): Fix crbug.com/156163 and use better logic when clipping. |
| 120 for (size_t i = 0; i < autofill_values_.size(); ++i) { | 120 for (size_t i = 0; i < names_.size(); ++i) { |
| 121 if (autofill_values_[i].length() > 15) | 121 if (names_[i].length() > 15) |
| 122 autofill_values_[i].erase(15); | 122 names_[i].erase(15); |
| 123 if (autofill_labels[i].length() > 15) | 123 if (subtexts[i].length() > 15) |
| 124 autofill_labels_[i].erase(15); | 124 subtexts_[i].erase(15); |
| 125 } | 125 } |
| 126 #endif | 126 #endif |
| 127 | 127 |
| 128 if (!view_) { | 128 if (!view_) { |
| 129 view_ = AutofillPopupView::Create(this); | 129 view_ = AutofillPopupView::Create(this); |
| 130 ShowView(); | 130 ShowView(); |
| 131 } else { | 131 } else { |
| 132 UpdateBoundsAndRedrawPopup(); | 132 UpdateBoundsAndRedrawPopup(); |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 | 135 |
| 136 void AutofillPopupControllerImpl::Hide() { | 136 void AutofillPopupControllerImpl::Hide() { |
| 137 delegate_ = NULL; | 137 delegate_ = NULL; |
| 138 HideInternal(); | 138 HideInternal(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void AutofillPopupControllerImpl::ViewDestroyed() { | 141 void AutofillPopupControllerImpl::ViewDestroyed() { |
| 142 delete this; | 142 delete this; |
| 143 } | 143 } |
| 144 | 144 |
| 145 void AutofillPopupControllerImpl::UpdateBoundsAndRedrawPopup() { | 145 void AutofillPopupControllerImpl::UpdateBoundsAndRedrawPopup() { |
| 146 #if !defined(OS_ANDROID) | 146 #if !defined(OS_ANDROID) |
| 147 popup_bounds_.set_width(GetPopupRequiredWidth()); | 147 popup_bounds_.set_width(GetPopupRequiredWidth()); |
| 148 popup_bounds_.set_height(GetPopupRequiredHeight()); | 148 popup_bounds_.set_height(GetPopupRequiredHeight()); |
| 149 #endif | 149 #endif |
| 150 | 150 |
| 151 view_->UpdateBoundsAndRedrawPopup(); | 151 view_->UpdateBoundsAndRedrawPopup(); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void AutofillPopupControllerImpl::SetSelectedPosition(int x, int y) { | 154 void AutofillPopupControllerImpl::MouseHovered(int x, int y) { |
| 155 int line = LineFromY(y); | 155 SetSelectedLine(LineFromY(y)); |
| 156 | |
| 157 SetSelectedLine(line); | |
| 158 | 156 |
| 159 bool delete_icon_hovered = DeleteIconIsUnder(x, y); | 157 bool delete_icon_hovered = DeleteIconIsUnder(x, y); |
| 160 if (delete_icon_hovered != delete_icon_hovered_) { | 158 if (delete_icon_hovered != delete_icon_hovered_) { |
| 161 delete_icon_hovered_ = delete_icon_hovered; | 159 delete_icon_hovered_ = delete_icon_hovered; |
| 162 InvalidateRow(selected_line()); | 160 InvalidateRow(selected_line()); |
| 163 } | 161 } |
| 164 } | 162 } |
| 165 | 163 |
| 166 bool AutofillPopupControllerImpl::AcceptAutofillSuggestion( | 164 void AutofillPopupControllerImpl::MouseClicked(int x, int y) { |
| 167 const string16& value, | 165 MouseHovered(x, y); |
| 168 int unique_id, | |
| 169 unsigned index) { | |
| 170 return delegate_->DidAcceptAutofillSuggestion(value, unique_id, index); | |
| 171 } | |
| 172 | 166 |
| 173 void AutofillPopupControllerImpl::AcceptSelectedPosition(int x, int y) { | 167 if (delete_icon_hovered_) |
| 174 DCHECK_EQ(selected_line(), LineFromY(y)); | |
| 175 | |
| 176 if (DeleteIconIsUnder(x, y)) | |
| 177 RemoveSelectedLine(); | 168 RemoveSelectedLine(); |
| 178 else | 169 else |
| 179 AcceptSelectedLine(); | 170 AcceptSelectedLine(); |
| 180 } | 171 } |
| 181 | 172 |
| 182 void AutofillPopupControllerImpl::ClearSelectedLine() { | 173 void AutofillPopupControllerImpl::MouseExitedPopup() { |
| 183 SetSelectedLine(kNoSelection); | 174 SetSelectedLine(kNoSelection); |
| 184 } | 175 } |
| 185 | 176 |
| 177 void AutofillPopupControllerImpl::AcceptSuggestion(size_t index) { | |
| 178 delegate_->DidAcceptSuggestion(names_[index], identifiers_[index]); | |
| 179 } | |
| 180 | |
| 186 int AutofillPopupControllerImpl::GetIconResourceID( | 181 int AutofillPopupControllerImpl::GetIconResourceID( |
| 187 const string16& resource_name) { | 182 const string16& resource_name) { |
| 188 for (size_t i = 0; i < arraysize(kDataResources); ++i) { | 183 for (size_t i = 0; i < arraysize(kDataResources); ++i) { |
| 189 if (resource_name == ASCIIToUTF16(kDataResources[i].name)) | 184 if (resource_name == ASCIIToUTF16(kDataResources[i].name)) |
| 190 return kDataResources[i].id; | 185 return kDataResources[i].id; |
| 191 } | 186 } |
| 192 | 187 |
| 193 return -1; | 188 return -1; |
| 194 } | 189 } |
| 195 | 190 |
| 196 bool AutofillPopupControllerImpl::CanDelete(int id) { | 191 bool AutofillPopupControllerImpl::CanDelete(size_t index) { |
| 192 int id = identifiers_[index]; | |
| 197 return id > 0 || | 193 return id > 0 || |
| 198 id == WebAutofillClient::MenuItemIDAutocompleteEntry || | 194 id == WebAutofillClient::MenuItemIDAutocompleteEntry || |
| 199 id == WebAutofillClient::MenuItemIDPasswordEntry; | 195 id == WebAutofillClient::MenuItemIDPasswordEntry; |
| 200 } | 196 } |
| 201 | 197 |
| 202 #if !defined(OS_ANDROID) | 198 #if !defined(OS_ANDROID) |
| 203 int AutofillPopupControllerImpl::GetPopupRequiredWidth() { | 199 int AutofillPopupControllerImpl::GetPopupRequiredWidth() { |
| 204 if (value_font_.platform_font() == NULL || | 200 if (name_font_.platform_font() == NULL || |
| 205 label_font_.platform_font() == NULL) { | 201 subtext_font_.platform_font() == NULL) { |
| 206 // We can't calculate the size of the popup if the fonts | 202 // We can't calculate the size of the popup if the fonts |
| 207 // aren't present. | 203 // aren't present. |
| 208 return 0; | 204 return 0; |
| 209 } | 205 } |
| 210 | 206 |
| 211 int popup_width = element_bounds().width(); | 207 int popup_width = element_bounds().width(); |
| 212 DCHECK_EQ(autofill_values().size(), autofill_labels().size()); | 208 DCHECK_EQ(names().size(), subtexts().size()); |
| 213 for (size_t i = 0; i < autofill_values().size(); ++i) { | 209 for (size_t i = 0; i < names().size(); ++i) { |
| 214 int row_size = kEndPadding + | 210 int row_size = kEndPadding + |
| 215 value_font_.GetStringWidth(autofill_values()[i]) + | 211 name_font_.GetStringWidth(names()[i]) + |
| 216 kLabelPadding + | 212 kNamePadding + |
| 217 label_font_.GetStringWidth(autofill_labels()[i]); | 213 subtext_font_.GetStringWidth(subtexts()[i]); |
| 218 | 214 |
| 219 // Add the Autofill icon size, if required. | 215 // Add the Autofill icon size, if required. |
| 220 if (!autofill_icons()[i].empty()) | 216 if (!icons()[i].empty()) |
| 221 row_size += kAutofillIconWidth + kIconPadding; | 217 row_size += kAutofillIconWidth + kIconPadding; |
| 222 | 218 |
| 223 // Add delete icon, if required. | 219 // Add delete icon, if required. |
| 224 if (CanDelete(autofill_unique_ids()[i])) | 220 if (CanDelete(i)) |
| 225 row_size += kDeleteIconWidth + kIconPadding; | 221 row_size += kDeleteIconWidth + kIconPadding; |
| 226 | 222 |
| 227 // Add the padding at the end | 223 // Add the padding at the end |
| 228 row_size += kEndPadding; | 224 row_size += kEndPadding; |
| 229 | 225 |
| 230 popup_width = std::max(popup_width, row_size); | 226 popup_width = std::max(popup_width, row_size); |
| 231 } | 227 } |
| 232 | 228 |
| 233 return popup_width; | 229 return popup_width; |
| 234 } | 230 } |
| 235 | 231 |
| 236 int AutofillPopupControllerImpl::GetPopupRequiredHeight() { | 232 int AutofillPopupControllerImpl::GetPopupRequiredHeight() { |
| 237 int popup_height = 0; | 233 int popup_height = 0; |
| 238 | 234 |
| 239 for (size_t i = 0; i < autofill_unique_ids().size(); ++i) { | 235 for (size_t i = 0; i < identifiers().size(); ++i) { |
| 240 popup_height += GetRowHeightFromId(autofill_unique_ids()[i]); | 236 popup_height += GetRowHeightFromId(identifiers()[i]); |
| 241 } | 237 } |
| 242 | 238 |
| 243 return popup_height; | 239 return popup_height; |
| 244 } | 240 } |
| 245 #endif // !defined(OS_ANDROID) | 241 #endif // !defined(OS_ANDROID) |
| 246 | 242 |
| 247 int AutofillPopupControllerImpl::GetRowHeightFromId(int unique_id) { | 243 gfx::Rect AutofillPopupControllerImpl::GetRowBounds(size_t index) { |
| 248 if (unique_id == WebAutofillClient::MenuItemIDSeparator) | |
| 249 return kSeparatorHeight; | |
| 250 | |
| 251 return kRowHeight; | |
| 252 } | |
| 253 | |
| 254 gfx::Rect AutofillPopupControllerImpl::GetRectForRow(size_t row, int width) { | |
| 255 int top = 0; | 244 int top = 0; |
| 256 for (size_t i = 0; i < row; ++i) { | 245 for (size_t i = 0; i < index; ++i) { |
| 257 top += GetRowHeightFromId(autofill_unique_ids()[i]); | 246 top += GetRowHeightFromId(identifiers()[i]); |
| 258 } | 247 } |
| 259 | 248 |
| 260 return gfx::Rect( | 249 return gfx::Rect( |
| 261 0, top, width, GetRowHeightFromId(autofill_unique_ids()[row])); | 250 0, |
| 251 top, | |
| 252 popup_bounds_.width(), | |
| 253 GetRowHeightFromId(identifiers()[index])); | |
| 262 } | 254 } |
| 263 | 255 |
| 264 void AutofillPopupControllerImpl::SetPopupBounds(const gfx::Rect& bounds) { | 256 void AutofillPopupControllerImpl::SetPopupBounds(const gfx::Rect& bounds) { |
| 265 popup_bounds_ = bounds; | 257 popup_bounds_ = bounds; |
| 266 UpdateBoundsAndRedrawPopup(); | 258 UpdateBoundsAndRedrawPopup(); |
| 267 } | 259 } |
| 268 | 260 |
| 269 const gfx::Rect& AutofillPopupControllerImpl::popup_bounds() const { | 261 const gfx::Rect& AutofillPopupControllerImpl::popup_bounds() const { |
| 270 return popup_bounds_; | 262 return popup_bounds_; |
| 271 } | 263 } |
| 272 | 264 |
| 273 gfx::NativeView AutofillPopupControllerImpl::container_view() const { | 265 gfx::NativeView AutofillPopupControllerImpl::container_view() const { |
| 274 return container_view_; | 266 return container_view_; |
| 275 } | 267 } |
| 276 | 268 |
| 277 const gfx::Rect& AutofillPopupControllerImpl::element_bounds() const { | 269 const gfx::Rect& AutofillPopupControllerImpl::element_bounds() const { |
| 278 return element_bounds_; | 270 return element_bounds_; |
| 279 } | 271 } |
| 280 | 272 |
| 281 const std::vector<string16>& AutofillPopupControllerImpl:: | 273 const std::vector<string16>& AutofillPopupControllerImpl::names() const { |
| 282 autofill_values() const { | 274 return names_; |
| 283 return autofill_values_; | |
| 284 } | 275 } |
| 285 | 276 |
| 286 const std::vector<string16>& AutofillPopupControllerImpl:: | 277 const std::vector<string16>& AutofillPopupControllerImpl::subtexts() const { |
| 287 autofill_labels() const { | 278 return subtexts_; |
| 288 return autofill_labels_; | |
| 289 } | 279 } |
| 290 | 280 |
| 291 const std::vector<string16>& AutofillPopupControllerImpl:: | 281 const std::vector<string16>& AutofillPopupControllerImpl::icons() const { |
| 292 autofill_icons() const { | 282 return icons_; |
| 293 return autofill_icons_; | |
| 294 } | 283 } |
| 295 | 284 |
| 296 const std::vector<int>& AutofillPopupControllerImpl:: | 285 const std::vector<int>& AutofillPopupControllerImpl::identifiers() const { |
| 297 autofill_unique_ids() const { | 286 return identifiers_; |
| 298 return autofill_unique_ids_; | |
| 299 } | 287 } |
| 300 | 288 |
| 301 #if !defined(OS_ANDROID) | 289 #if !defined(OS_ANDROID) |
| 302 const gfx::Font& AutofillPopupControllerImpl::label_font() const { | 290 const gfx::Font& AutofillPopupControllerImpl::name_font() const { |
| 303 return label_font_; | 291 return name_font_; |
| 304 } | 292 } |
| 305 | 293 |
| 306 const gfx::Font& AutofillPopupControllerImpl::value_font() const { | 294 const gfx::Font& AutofillPopupControllerImpl::subtext_font() const { |
| 307 return value_font_; | 295 return subtext_font_; |
| 308 } | 296 } |
| 309 #endif | 297 #endif |
| 310 | 298 |
| 311 int AutofillPopupControllerImpl::selected_line() const { | 299 int AutofillPopupControllerImpl::selected_line() const { |
| 312 return selected_line_; | 300 return selected_line_; |
| 313 } | 301 } |
| 314 | 302 |
| 315 bool AutofillPopupControllerImpl::delete_icon_hovered() const { | 303 bool AutofillPopupControllerImpl::delete_icon_hovered() const { |
| 316 return delete_icon_hovered_; | 304 return delete_icon_hovered_; |
| 317 } | 305 } |
| 318 | 306 |
| 319 bool AutofillPopupControllerImpl::HandleKeyPressEvent( | 307 bool AutofillPopupControllerImpl::HandleKeyPressEvent( |
| 320 const content::NativeWebKeyboardEvent& event) { | 308 const content::NativeWebKeyboardEvent& event) { |
| 321 switch (event.windowsKeyCode) { | 309 switch (event.windowsKeyCode) { |
| 322 case ui::VKEY_UP: | 310 case ui::VKEY_UP: |
| 323 SelectPreviousLine(); | 311 SelectPreviousLine(); |
| 324 return true; | 312 return true; |
| 325 case ui::VKEY_DOWN: | 313 case ui::VKEY_DOWN: |
| 326 SelectNextLine(); | 314 SelectNextLine(); |
| 327 return true; | 315 return true; |
| 328 case ui::VKEY_PRIOR: // Page up. | 316 case ui::VKEY_PRIOR: // Page up. |
| 329 SetSelectedLine(0); | 317 SetSelectedLine(0); |
| 330 return true; | 318 return true; |
| 331 case ui::VKEY_NEXT: // Page down. | 319 case ui::VKEY_NEXT: // Page down. |
| 332 SetSelectedLine(autofill_values().size() - 1); | 320 SetSelectedLine(names().size() - 1); |
| 333 return true; | 321 return true; |
| 334 case ui::VKEY_ESCAPE: | 322 case ui::VKEY_ESCAPE: |
| 335 HideInternal(); | 323 HideInternal(); |
| 336 return true; | 324 return true; |
| 337 case ui::VKEY_DELETE: | 325 case ui::VKEY_DELETE: |
| 338 return (event.modifiers & content::NativeWebKeyboardEvent::ShiftKey) && | 326 return (event.modifiers & content::NativeWebKeyboardEvent::ShiftKey) && |
| 339 RemoveSelectedLine(); | 327 RemoveSelectedLine(); |
| 340 case ui::VKEY_RETURN: | 328 case ui::VKEY_RETURN: |
| 341 return AcceptSelectedLine(); | 329 return AcceptSelectedLine(); |
| 342 default: | 330 default: |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 361 | 349 |
| 362 if (selected_line_ != kNoSelection) | 350 if (selected_line_ != kNoSelection) |
| 363 InvalidateRow(selected_line_); | 351 InvalidateRow(selected_line_); |
| 364 | 352 |
| 365 if (selected_line != kNoSelection) | 353 if (selected_line != kNoSelection) |
| 366 InvalidateRow(selected_line); | 354 InvalidateRow(selected_line); |
| 367 | 355 |
| 368 selected_line_ = selected_line; | 356 selected_line_ = selected_line; |
| 369 | 357 |
| 370 if (selected_line_ != kNoSelection) { | 358 if (selected_line_ != kNoSelection) { |
| 371 delegate_->SelectAutofillSuggestion( | 359 delegate_->DidSelectSuggestion(identifiers_[selected_line_]); |
| 372 autofill_unique_ids_[selected_line_]); | |
| 373 } | 360 } |
| 374 } | 361 } |
| 375 | 362 |
| 376 void AutofillPopupControllerImpl::SelectNextLine() { | 363 void AutofillPopupControllerImpl::SelectNextLine() { |
| 377 int new_selected_line = selected_line_ + 1; | 364 int new_selected_line = selected_line_ + 1; |
| 378 | 365 |
| 379 // Skip over any lines that can't be selected. | 366 // Skip over any lines that can't be selected. |
| 380 while (static_cast<size_t>(new_selected_line) < autofill_values_.size() && | 367 while (static_cast<size_t>(new_selected_line) < names_.size() && |
| 381 !CanAccept(autofill_unique_ids()[new_selected_line])) { | 368 !CanAccept(identifiers()[new_selected_line])) { |
| 382 ++new_selected_line; | 369 ++new_selected_line; |
| 383 } | 370 } |
| 384 | 371 |
| 385 if (new_selected_line == static_cast<int>(autofill_values_.size())) | 372 if (new_selected_line == static_cast<int>(names_.size())) |
| 386 new_selected_line = 0; | 373 new_selected_line = 0; |
| 387 | 374 |
| 388 SetSelectedLine(new_selected_line); | 375 SetSelectedLine(new_selected_line); |
| 389 } | 376 } |
| 390 | 377 |
| 391 void AutofillPopupControllerImpl::SelectPreviousLine() { | 378 void AutofillPopupControllerImpl::SelectPreviousLine() { |
| 392 int new_selected_line = selected_line_ - 1; | 379 int new_selected_line = selected_line_ - 1; |
| 393 | 380 |
| 394 // Skip over any lines that can't be selected. | 381 // Skip over any lines that can't be selected. |
| 395 while (new_selected_line > kNoSelection && | 382 while (new_selected_line > kNoSelection && |
| 396 !CanAccept(autofill_unique_ids()[new_selected_line])) { | 383 !CanAccept(identifiers()[new_selected_line])) { |
| 397 --new_selected_line; | 384 --new_selected_line; |
| 398 } | 385 } |
| 399 | 386 |
| 400 if (new_selected_line <= kNoSelection) | 387 if (new_selected_line <= kNoSelection) |
| 401 new_selected_line = autofill_values_.size() - 1; | 388 new_selected_line = names_.size() - 1; |
| 402 | 389 |
| 403 SetSelectedLine(new_selected_line); | 390 SetSelectedLine(new_selected_line); |
| 404 } | 391 } |
| 405 | 392 |
| 406 bool AutofillPopupControllerImpl::AcceptSelectedLine() { | 393 bool AutofillPopupControllerImpl::AcceptSelectedLine() { |
| 407 if (selected_line_ == kNoSelection) | 394 if (selected_line_ == kNoSelection) |
| 408 return false; | 395 return false; |
| 409 | 396 |
| 410 DCHECK_GE(selected_line_, 0); | 397 DCHECK_GE(selected_line_, 0); |
| 411 DCHECK_LT(selected_line_, static_cast<int>(autofill_values_.size())); | 398 DCHECK_LT(selected_line_, static_cast<int>(names_.size())); |
| 412 | 399 |
| 413 if (!CanAccept(autofill_unique_ids_[selected_line_])) | 400 if (!CanAccept(identifiers_[selected_line_])) |
| 414 return false; | 401 return false; |
| 415 | 402 |
| 416 return AcceptAutofillSuggestion( | 403 AcceptSuggestion(selected_line_); |
| 417 autofill_values_[selected_line_], | 404 return true; |
| 418 autofill_unique_ids_[selected_line_], | |
| 419 selected_line_); | |
| 420 } | 405 } |
| 421 | 406 |
| 422 bool AutofillPopupControllerImpl::RemoveSelectedLine() { | 407 bool AutofillPopupControllerImpl::RemoveSelectedLine() { |
| 423 if (selected_line_ == kNoSelection) | 408 if (selected_line_ == kNoSelection) |
| 424 return false; | 409 return false; |
| 425 | 410 |
| 426 DCHECK_GE(selected_line_, 0); | 411 DCHECK_GE(selected_line_, 0); |
| 427 DCHECK_LT(selected_line_, static_cast<int>(autofill_values_.size())); | 412 DCHECK_LT(selected_line_, static_cast<int>(names_.size())); |
| 428 | 413 |
| 429 if (!CanDelete(autofill_unique_ids_[selected_line_])) | 414 if (!CanDelete(selected_line_)) |
| 430 return false; | 415 return false; |
| 431 | 416 |
| 432 if (autofill_unique_ids_[selected_line_] > 0) { | 417 delegate_->RemoveSuggestion(names_[selected_line_], |
| 433 delegate_->RemoveAutofillProfileOrCreditCard( | 418 identifiers_[selected_line_]); |
| 434 autofill_unique_ids_[selected_line_]); | |
| 435 } else { | |
| 436 delegate_->RemoveAutocompleteEntry( | |
| 437 autofill_values_[selected_line_]); | |
| 438 } | |
| 439 | 419 |
| 440 // Remove the deleted element. | 420 // Remove the deleted element. |
| 441 autofill_values_.erase(autofill_values_.begin() + selected_line_); | 421 names_.erase(names_.begin() + selected_line_); |
| 442 autofill_labels_.erase(autofill_labels_.begin() + selected_line_); | 422 subtexts_.erase(subtexts_.begin() + selected_line_); |
| 443 autofill_icons_.erase(autofill_icons_.begin() + selected_line_); | 423 icons_.erase(icons_.begin() + selected_line_); |
| 444 autofill_unique_ids_.erase(autofill_unique_ids_.begin() + selected_line_); | 424 identifiers_.erase(identifiers_.begin() + selected_line_); |
| 445 | 425 |
| 446 SetSelectedLine(kNoSelection); | 426 SetSelectedLine(kNoSelection); |
| 447 | 427 |
| 448 if (HasAutofillEntries()) { | 428 if (HasAutofillEntries()) { |
| 449 delegate_->ClearPreviewedForm(); | 429 delegate_->ClearPreviewedForm(); |
| 450 UpdateBoundsAndRedrawPopup(); | 430 UpdateBoundsAndRedrawPopup(); |
| 451 } else { | 431 } else { |
| 452 HideInternal(); | 432 HideInternal(); |
| 453 } | 433 } |
| 454 | 434 |
| 455 return true; | 435 return true; |
| 456 } | 436 } |
| 457 | 437 |
| 458 int AutofillPopupControllerImpl::LineFromY(int y) { | 438 int AutofillPopupControllerImpl::LineFromY(int y) { |
| 459 int current_height = 0; | 439 int current_height = 0; |
| 460 | 440 |
| 461 for (size_t i = 0; i < autofill_unique_ids().size(); ++i) { | 441 for (size_t i = 0; i < identifiers().size(); ++i) { |
| 462 current_height += GetRowHeightFromId(autofill_unique_ids()[i]); | 442 current_height += GetRowHeightFromId(identifiers()[i]); |
| 463 | 443 |
| 464 if (y <= current_height) | 444 if (y <= current_height) |
| 465 return i; | 445 return i; |
| 466 } | 446 } |
| 467 | 447 |
| 468 // The y value goes beyond the popup so stop the selection at the last line. | 448 // The y value goes beyond the popup so stop the selection at the last line. |
| 469 return autofill_unique_ids().size() - 1; | 449 return identifiers().size() - 1; |
| 450 } | |
| 451 | |
| 452 int AutofillPopupControllerImpl::GetRowHeightFromId(int identifier) { | |
| 453 if (identifier == WebAutofillClient::MenuItemIDSeparator) | |
| 454 return kSeparatorHeight; | |
| 455 | |
| 456 return kRowHeight; | |
| 470 } | 457 } |
| 471 | 458 |
| 472 bool AutofillPopupControllerImpl::DeleteIconIsUnder(int x, int y) { | 459 bool AutofillPopupControllerImpl::DeleteIconIsUnder(int x, int y) { |
| 473 #if defined(OS_ANDROID) | 460 #if defined(OS_ANDROID) |
| 474 return false; | 461 return false; |
| 475 #else | 462 #else |
| 476 if (!CanDelete(selected_line())) | 463 if (!CanDelete(selected_line())) |
| 477 return false; | 464 return false; |
| 478 | 465 |
| 479 int row_start_y = 0; | 466 int row_start_y = 0; |
| 480 for (int i = 0; i < selected_line(); ++i) { | 467 for (int i = 0; i < selected_line(); ++i) { |
| 481 row_start_y += GetRowHeightFromId(autofill_unique_ids()[i]); | 468 row_start_y += GetRowHeightFromId(identifiers()[i]); |
| 482 } | 469 } |
| 483 | 470 |
| 484 gfx::Rect delete_icon_bounds = gfx::Rect( | 471 gfx::Rect delete_icon_bounds = gfx::Rect( |
| 485 GetPopupRequiredWidth() - kDeleteIconWidth - kIconPadding, | 472 GetPopupRequiredWidth() - kDeleteIconWidth - kIconPadding, |
| 486 row_start_y + ((kRowHeight - kDeleteIconHeight) / 2), | 473 row_start_y + ((kRowHeight - kDeleteIconHeight) / 2), |
| 487 kDeleteIconWidth, | 474 kDeleteIconWidth, |
| 488 kDeleteIconHeight); | 475 kDeleteIconHeight); |
| 489 | 476 |
| 490 return delete_icon_bounds.Contains(x, y); | 477 return delete_icon_bounds.Contains(x, y); |
| 491 #endif | 478 #endif |
| 492 } | 479 } |
| 493 | 480 |
| 494 bool AutofillPopupControllerImpl::CanAccept(int id) { | 481 bool AutofillPopupControllerImpl::CanAccept(int id) { |
| 495 return id != WebAutofillClient::MenuItemIDSeparator; | 482 return id != WebAutofillClient::MenuItemIDSeparator && |
| 483 id != WebAutofillClient::MenuItemIDWarningMessage; | |
| 496 } | 484 } |
| 497 | 485 |
| 498 bool AutofillPopupControllerImpl::HasAutofillEntries() { | 486 bool AutofillPopupControllerImpl::HasAutofillEntries() { |
| 499 return autofill_values_.size() != 0 && | 487 return names_.size() != 0 && |
| 500 (autofill_unique_ids_[0] > 0 || | 488 (identifiers_[0] > 0 || |
| 501 autofill_unique_ids_[0] == | 489 identifiers_[0] == |
| 502 WebAutofillClient::MenuItemIDAutocompleteEntry || | 490 WebAutofillClient::MenuItemIDAutocompleteEntry || |
| 503 autofill_unique_ids_[0] == WebAutofillClient::MenuItemIDPasswordEntry || | 491 identifiers_[0] == WebAutofillClient::MenuItemIDPasswordEntry || |
| 504 autofill_unique_ids_[0] == WebAutofillClient::MenuItemIDDataListEntry); | 492 identifiers_[0] == WebAutofillClient::MenuItemIDDataListEntry); |
| 505 } | 493 } |
| 506 | 494 |
| 507 void AutofillPopupControllerImpl::ShowView() { | 495 void AutofillPopupControllerImpl::ShowView() { |
| 508 view_->Show(); | 496 view_->Show(); |
| 509 } | 497 } |
| 510 | 498 |
| 511 void AutofillPopupControllerImpl::InvalidateRow(size_t row) { | 499 void AutofillPopupControllerImpl::InvalidateRow(size_t row) { |
| 512 view_->InvalidateRow(row); | 500 view_->InvalidateRow(row); |
| 513 } | 501 } |
| OLD | NEW |