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