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

Side by Side Diff: chrome/browser/ui/autofill/autofill_popup_controller_impl.cc

Issue 11636040: AutofillPopupController clarifications + simplifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: relative patchset Created 8 years 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 | Annotate | Revision Log
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/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"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 sub_label_font_ = label_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>& labels,
108 const std::vector<string16>& autofill_labels, 108 const std::vector<string16>& sub_labels,
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 labels_ = labels;
112 autofill_labels_ = autofill_labels; 112 sub_labels_ = sub_labels;
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 < labels_.size(); ++i) {
121 if (autofill_values_[i].length() > 15) 121 if (labels_[i].length() > 15)
122 autofill_values_[i].erase(15); 122 labels_[i].erase(15);
123 if (autofill_labels[i].length() > 15) 123 if (sub_labels[i].length() > 15)
124 autofill_labels_[i].erase(15); 124 sub_labels_[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::MouseLeftPopup() {
183 SetSelectedLine(kNoSelection); 174 SetSelectedLine(kNoSelection);
184 } 175 }
185 176
177 void AutofillPopupControllerImpl::AcceptSuggestion(size_t index) {
178 delegate_->DidAcceptAutofillSuggestion(labels_[index],
179 identifiers_[index]);
180 }
181
186 int AutofillPopupControllerImpl::GetIconResourceID( 182 int AutofillPopupControllerImpl::GetIconResourceID(
187 const string16& resource_name) { 183 const string16& resource_name) {
188 for (size_t i = 0; i < arraysize(kDataResources); ++i) { 184 for (size_t i = 0; i < arraysize(kDataResources); ++i) {
189 if (resource_name == ASCIIToUTF16(kDataResources[i].name)) 185 if (resource_name == ASCIIToUTF16(kDataResources[i].name))
190 return kDataResources[i].id; 186 return kDataResources[i].id;
191 } 187 }
192 188
193 return -1; 189 return -1;
194 } 190 }
195 191
196 bool AutofillPopupControllerImpl::CanDelete(int id) { 192 bool AutofillPopupControllerImpl::CanDelete(size_t index) {
193 int id = identifiers_[index];
197 return id > 0 || 194 return id > 0 ||
198 id == WebAutofillClient::MenuItemIDAutocompleteEntry || 195 id == WebAutofillClient::MenuItemIDAutocompleteEntry ||
199 id == WebAutofillClient::MenuItemIDPasswordEntry; 196 id == WebAutofillClient::MenuItemIDPasswordEntry;
200 } 197 }
201 198
202 #if !defined(OS_ANDROID) 199 #if !defined(OS_ANDROID)
203 int AutofillPopupControllerImpl::GetPopupRequiredWidth() { 200 int AutofillPopupControllerImpl::GetPopupRequiredWidth() {
204 if (value_font_.platform_font() == NULL || 201 if (label_font_.platform_font() == NULL ||
205 label_font_.platform_font() == NULL) { 202 sub_label_font_.platform_font() == NULL) {
206 // We can't calculate the size of the popup if the fonts 203 // We can't calculate the size of the popup if the fonts
207 // aren't present. 204 // aren't present.
208 return 0; 205 return 0;
209 } 206 }
210 207
211 int popup_width = element_bounds().width(); 208 int popup_width = element_bounds().width();
212 DCHECK_EQ(autofill_values().size(), autofill_labels().size()); 209 DCHECK_EQ(labels().size(), sub_labels().size());
213 for (size_t i = 0; i < autofill_values().size(); ++i) { 210 for (size_t i = 0; i < labels().size(); ++i) {
214 int row_size = kEndPadding + 211 int row_size = kEndPadding +
215 value_font_.GetStringWidth(autofill_values()[i]) + 212 label_font_.GetStringWidth(labels()[i]) +
216 kLabelPadding + 213 kLabelPadding +
217 label_font_.GetStringWidth(autofill_labels()[i]); 214 sub_label_font_.GetStringWidth(sub_labels()[i]);
218 215
219 // Add the Autofill icon size, if required. 216 // Add the Autofill icon size, if required.
220 if (!autofill_icons()[i].empty()) 217 if (!icons()[i].empty())
221 row_size += kAutofillIconWidth + kIconPadding; 218 row_size += kAutofillIconWidth + kIconPadding;
222 219
223 // Add delete icon, if required. 220 // Add delete icon, if required.
224 if (CanDelete(autofill_unique_ids()[i])) 221 if (CanDelete(i))
225 row_size += kDeleteIconWidth + kIconPadding; 222 row_size += kDeleteIconWidth + kIconPadding;
226 223
227 // Add the padding at the end 224 // Add the padding at the end
228 row_size += kEndPadding; 225 row_size += kEndPadding;
229 226
230 popup_width = std::max(popup_width, row_size); 227 popup_width = std::max(popup_width, row_size);
231 } 228 }
232 229
233 return popup_width; 230 return popup_width;
234 } 231 }
235 232
236 int AutofillPopupControllerImpl::GetPopupRequiredHeight() { 233 int AutofillPopupControllerImpl::GetPopupRequiredHeight() {
237 int popup_height = 0; 234 int popup_height = 0;
238 235
239 for (size_t i = 0; i < autofill_unique_ids().size(); ++i) { 236 for (size_t i = 0; i < identifiers().size(); ++i) {
240 popup_height += GetRowHeightFromId(autofill_unique_ids()[i]); 237 popup_height += GetRowHeightFromId(identifiers()[i]);
241 } 238 }
242 239
243 return popup_height; 240 return popup_height;
244 } 241 }
245 #endif // !defined(OS_ANDROID) 242 #endif // !defined(OS_ANDROID)
246 243
247 int AutofillPopupControllerImpl::GetRowHeightFromId(int unique_id) { 244 gfx::Rect AutofillPopupControllerImpl::GetRowBounds(size_t row) {
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; 245 int top = 0;
256 for (size_t i = 0; i < row; ++i) { 246 for (size_t i = 0; i < row; ++i) {
257 top += GetRowHeightFromId(autofill_unique_ids()[i]); 247 top += GetRowHeightFromId(identifiers()[i]);
258 } 248 }
259 249
260 return gfx::Rect( 250 return gfx::Rect(
261 0, top, width, GetRowHeightFromId(autofill_unique_ids()[row])); 251 0,
252 top,
253 popup_bounds_.width(),
254 GetRowHeightFromId(identifiers()[row]));
262 } 255 }
263 256
264 void AutofillPopupControllerImpl::SetPopupBounds(const gfx::Rect& bounds) { 257 void AutofillPopupControllerImpl::SetPopupBounds(const gfx::Rect& bounds) {
265 popup_bounds_ = bounds; 258 popup_bounds_ = bounds;
266 UpdateBoundsAndRedrawPopup(); 259 UpdateBoundsAndRedrawPopup();
267 } 260 }
268 261
269 const gfx::Rect& AutofillPopupControllerImpl::popup_bounds() const { 262 const gfx::Rect& AutofillPopupControllerImpl::popup_bounds() const {
270 return popup_bounds_; 263 return popup_bounds_;
271 } 264 }
272 265
273 gfx::NativeView AutofillPopupControllerImpl::container_view() const { 266 gfx::NativeView AutofillPopupControllerImpl::container_view() const {
274 return container_view_; 267 return container_view_;
275 } 268 }
276 269
277 const gfx::Rect& AutofillPopupControllerImpl::element_bounds() const { 270 const gfx::Rect& AutofillPopupControllerImpl::element_bounds() const {
278 return element_bounds_; 271 return element_bounds_;
279 } 272 }
280 273
281 const std::vector<string16>& AutofillPopupControllerImpl:: 274 const std::vector<string16>& AutofillPopupControllerImpl::labels() const {
282 autofill_values() const { 275 return labels_;
283 return autofill_values_;
284 } 276 }
285 277
286 const std::vector<string16>& AutofillPopupControllerImpl:: 278 const std::vector<string16>& AutofillPopupControllerImpl::sub_labels() const {
287 autofill_labels() const { 279 return sub_labels_;
288 return autofill_labels_;
289 } 280 }
290 281
291 const std::vector<string16>& AutofillPopupControllerImpl:: 282 const std::vector<string16>& AutofillPopupControllerImpl::icons() const {
292 autofill_icons() const { 283 return icons_;
293 return autofill_icons_;
294 } 284 }
295 285
296 const std::vector<int>& AutofillPopupControllerImpl:: 286 const std::vector<int>& AutofillPopupControllerImpl::identifiers() const {
297 autofill_unique_ids() const { 287 return identifiers_;
298 return autofill_unique_ids_;
299 } 288 }
300 289
301 #if !defined(OS_ANDROID) 290 #if !defined(OS_ANDROID)
302 const gfx::Font& AutofillPopupControllerImpl::label_font() const { 291 const gfx::Font& AutofillPopupControllerImpl::label_font() const {
303 return label_font_; 292 return label_font_;
304 } 293 }
305 294
306 const gfx::Font& AutofillPopupControllerImpl::value_font() const { 295 const gfx::Font& AutofillPopupControllerImpl::sub_label_font() const {
307 return value_font_; 296 return sub_label_font_;
308 } 297 }
309 #endif 298 #endif
310 299
311 int AutofillPopupControllerImpl::selected_line() const { 300 int AutofillPopupControllerImpl::selected_line() const {
312 return selected_line_; 301 return selected_line_;
313 } 302 }
314 303
315 bool AutofillPopupControllerImpl::delete_icon_hovered() const { 304 bool AutofillPopupControllerImpl::delete_icon_hovered() const {
316 return delete_icon_hovered_; 305 return delete_icon_hovered_;
317 } 306 }
318 307
319 bool AutofillPopupControllerImpl::HandleKeyPressEvent( 308 bool AutofillPopupControllerImpl::HandleKeyPressEvent(
320 const content::NativeWebKeyboardEvent& event) { 309 const content::NativeWebKeyboardEvent& event) {
321 switch (event.windowsKeyCode) { 310 switch (event.windowsKeyCode) {
322 case ui::VKEY_UP: 311 case ui::VKEY_UP:
323 SelectPreviousLine(); 312 SelectPreviousLine();
324 return true; 313 return true;
325 case ui::VKEY_DOWN: 314 case ui::VKEY_DOWN:
326 SelectNextLine(); 315 SelectNextLine();
327 return true; 316 return true;
328 case ui::VKEY_PRIOR: // Page up. 317 case ui::VKEY_PRIOR: // Page up.
329 SetSelectedLine(0); 318 SetSelectedLine(0);
330 return true; 319 return true;
331 case ui::VKEY_NEXT: // Page down. 320 case ui::VKEY_NEXT: // Page down.
332 SetSelectedLine(autofill_values().size() - 1); 321 SetSelectedLine(labels().size() - 1);
333 return true; 322 return true;
334 case ui::VKEY_ESCAPE: 323 case ui::VKEY_ESCAPE:
335 HideInternal(); 324 HideInternal();
336 return true; 325 return true;
337 case ui::VKEY_DELETE: 326 case ui::VKEY_DELETE:
338 return (event.modifiers & content::NativeWebKeyboardEvent::ShiftKey) && 327 return (event.modifiers & content::NativeWebKeyboardEvent::ShiftKey) &&
339 RemoveSelectedLine(); 328 RemoveSelectedLine();
340 case ui::VKEY_RETURN: 329 case ui::VKEY_RETURN:
341 return AcceptSelectedLine(); 330 return AcceptSelectedLine();
342 default: 331 default:
(...skipping 19 matching lines...) Expand all
362 if (selected_line_ != kNoSelection) 351 if (selected_line_ != kNoSelection)
363 InvalidateRow(selected_line_); 352 InvalidateRow(selected_line_);
364 353
365 if (selected_line != kNoSelection) 354 if (selected_line != kNoSelection)
366 InvalidateRow(selected_line); 355 InvalidateRow(selected_line);
367 356
368 selected_line_ = selected_line; 357 selected_line_ = selected_line;
369 358
370 if (selected_line_ != kNoSelection) { 359 if (selected_line_ != kNoSelection) {
371 delegate_->SelectAutofillSuggestion( 360 delegate_->SelectAutofillSuggestion(
372 autofill_unique_ids_[selected_line_]); 361 identifiers_[selected_line_]);
373 } 362 }
374 } 363 }
375 364
376 void AutofillPopupControllerImpl::SelectNextLine() { 365 void AutofillPopupControllerImpl::SelectNextLine() {
377 int new_selected_line = selected_line_ + 1; 366 int new_selected_line = selected_line_ + 1;
378 367
379 // Skip over any lines that can't be selected. 368 // Skip over any lines that can't be selected.
380 while (static_cast<size_t>(new_selected_line) < autofill_values_.size() && 369 while (static_cast<size_t>(new_selected_line) < labels_.size() &&
381 !CanAccept(autofill_unique_ids()[new_selected_line])) { 370 !CanAccept(identifiers()[new_selected_line])) {
382 ++new_selected_line; 371 ++new_selected_line;
383 } 372 }
384 373
385 if (new_selected_line == static_cast<int>(autofill_values_.size())) 374 if (new_selected_line == static_cast<int>(labels_.size()))
386 new_selected_line = 0; 375 new_selected_line = 0;
387 376
388 SetSelectedLine(new_selected_line); 377 SetSelectedLine(new_selected_line);
389 } 378 }
390 379
391 void AutofillPopupControllerImpl::SelectPreviousLine() { 380 void AutofillPopupControllerImpl::SelectPreviousLine() {
392 int new_selected_line = selected_line_ - 1; 381 int new_selected_line = selected_line_ - 1;
393 382
394 // Skip over any lines that can't be selected. 383 // Skip over any lines that can't be selected.
395 while (new_selected_line > kNoSelection && 384 while (new_selected_line > kNoSelection &&
396 !CanAccept(autofill_unique_ids()[new_selected_line])) { 385 !CanAccept(identifiers()[new_selected_line])) {
397 --new_selected_line; 386 --new_selected_line;
398 } 387 }
399 388
400 if (new_selected_line <= kNoSelection) 389 if (new_selected_line <= kNoSelection)
401 new_selected_line = autofill_values_.size() - 1; 390 new_selected_line = labels_.size() - 1;
402 391
403 SetSelectedLine(new_selected_line); 392 SetSelectedLine(new_selected_line);
404 } 393 }
405 394
406 bool AutofillPopupControllerImpl::AcceptSelectedLine() { 395 bool AutofillPopupControllerImpl::AcceptSelectedLine() {
407 if (selected_line_ == kNoSelection) 396 if (selected_line_ == kNoSelection)
408 return false; 397 return false;
409 398
410 DCHECK_GE(selected_line_, 0); 399 DCHECK_GE(selected_line_, 0);
411 DCHECK_LT(selected_line_, static_cast<int>(autofill_values_.size())); 400 DCHECK_LT(selected_line_, static_cast<int>(labels_.size()));
412 401
413 if (!CanAccept(autofill_unique_ids_[selected_line_])) 402 if (!CanAccept(identifiers_[selected_line_]))
414 return false; 403 return false;
415 404
416 return AcceptAutofillSuggestion( 405 AcceptSuggestion(selected_line_);
417 autofill_values_[selected_line_], 406 return true;
418 autofill_unique_ids_[selected_line_],
419 selected_line_);
420 } 407 }
421 408
422 bool AutofillPopupControllerImpl::RemoveSelectedLine() { 409 bool AutofillPopupControllerImpl::RemoveSelectedLine() {
423 if (selected_line_ == kNoSelection) 410 if (selected_line_ == kNoSelection)
424 return false; 411 return false;
425 412
426 DCHECK_GE(selected_line_, 0); 413 DCHECK_GE(selected_line_, 0);
427 DCHECK_LT(selected_line_, static_cast<int>(autofill_values_.size())); 414 DCHECK_LT(selected_line_, static_cast<int>(labels_.size()));
428 415
429 if (!CanDelete(autofill_unique_ids_[selected_line_])) 416 if (!CanDelete(selected_line_))
430 return false; 417 return false;
431 418
432 if (autofill_unique_ids_[selected_line_] > 0) { 419 if (identifiers_[selected_line_] > 0) {
433 delegate_->RemoveAutofillProfileOrCreditCard( 420 delegate_->RemoveAutofillProfileOrCreditCard(identifiers_[selected_line_]);
434 autofill_unique_ids_[selected_line_]);
435 } else { 421 } else {
436 delegate_->RemoveAutocompleteEntry( 422 delegate_->RemoveAutocompleteEntry(labels_[selected_line_]);
437 autofill_values_[selected_line_]);
438 } 423 }
439 424
440 // Remove the deleted element. 425 // Remove the deleted element.
441 autofill_values_.erase(autofill_values_.begin() + selected_line_); 426 labels_.erase(labels_.begin() + selected_line_);
442 autofill_labels_.erase(autofill_labels_.begin() + selected_line_); 427 sub_labels_.erase(sub_labels_.begin() + selected_line_);
443 autofill_icons_.erase(autofill_icons_.begin() + selected_line_); 428 icons_.erase(icons_.begin() + selected_line_);
444 autofill_unique_ids_.erase(autofill_unique_ids_.begin() + selected_line_); 429 identifiers_.erase(identifiers_.begin() + selected_line_);
445 430
446 SetSelectedLine(kNoSelection); 431 SetSelectedLine(kNoSelection);
447 432
448 if (HasAutofillEntries()) { 433 if (HasAutofillEntries()) {
449 delegate_->ClearPreviewedForm(); 434 delegate_->ClearPreviewedForm();
450 UpdateBoundsAndRedrawPopup(); 435 UpdateBoundsAndRedrawPopup();
451 } else { 436 } else {
452 HideInternal(); 437 HideInternal();
453 } 438 }
454 439
455 return true; 440 return true;
456 } 441 }
457 442
458 int AutofillPopupControllerImpl::LineFromY(int y) { 443 int AutofillPopupControllerImpl::LineFromY(int y) {
459 int current_height = 0; 444 int current_height = 0;
460 445
461 for (size_t i = 0; i < autofill_unique_ids().size(); ++i) { 446 for (size_t i = 0; i < identifiers().size(); ++i) {
462 current_height += GetRowHeightFromId(autofill_unique_ids()[i]); 447 current_height += GetRowHeightFromId(identifiers()[i]);
463 448
464 if (y <= current_height) 449 if (y <= current_height)
465 return i; 450 return i;
466 } 451 }
467 452
468 // The y value goes beyond the popup so stop the selection at the last line. 453 // The y value goes beyond the popup so stop the selection at the last line.
469 return autofill_unique_ids().size() - 1; 454 return identifiers().size() - 1;
455 }
456
457 int AutofillPopupControllerImpl::GetRowHeightFromId(int unique_id) {
458 if (unique_id == WebAutofillClient::MenuItemIDSeparator)
459 return kSeparatorHeight;
460
461 return kRowHeight;
470 } 462 }
471 463
472 bool AutofillPopupControllerImpl::DeleteIconIsUnder(int x, int y) { 464 bool AutofillPopupControllerImpl::DeleteIconIsUnder(int x, int y) {
473 #if defined(OS_ANDROID) 465 #if defined(OS_ANDROID)
474 return false; 466 return false;
475 #else 467 #else
476 if (!CanDelete(selected_line())) 468 if (!CanDelete(selected_line()))
477 return false; 469 return false;
478 470
479 int row_start_y = 0; 471 int row_start_y = 0;
480 for (int i = 0; i < selected_line(); ++i) { 472 for (int i = 0; i < selected_line(); ++i) {
481 row_start_y += GetRowHeightFromId(autofill_unique_ids()[i]); 473 row_start_y += GetRowHeightFromId(identifiers()[i]);
482 } 474 }
483 475
484 gfx::Rect delete_icon_bounds = gfx::Rect( 476 gfx::Rect delete_icon_bounds = gfx::Rect(
485 GetPopupRequiredWidth() - kDeleteIconWidth - kIconPadding, 477 GetPopupRequiredWidth() - kDeleteIconWidth - kIconPadding,
486 row_start_y + ((kRowHeight - kDeleteIconHeight) / 2), 478 row_start_y + ((kRowHeight - kDeleteIconHeight) / 2),
487 kDeleteIconWidth, 479 kDeleteIconWidth,
488 kDeleteIconHeight); 480 kDeleteIconHeight);
489 481
490 return delete_icon_bounds.Contains(x, y); 482 return delete_icon_bounds.Contains(x, y);
491 #endif 483 #endif
492 } 484 }
493 485
494 bool AutofillPopupControllerImpl::CanAccept(int id) { 486 bool AutofillPopupControllerImpl::CanAccept(int id) {
495 return id != WebAutofillClient::MenuItemIDSeparator; 487 return id != WebAutofillClient::MenuItemIDSeparator &&
488 id != WebAutofillClient::MenuItemIDWarningMessage;
496 } 489 }
497 490
498 bool AutofillPopupControllerImpl::HasAutofillEntries() { 491 bool AutofillPopupControllerImpl::HasAutofillEntries() {
499 return autofill_values_.size() != 0 && 492 return labels_.size() != 0 &&
500 (autofill_unique_ids_[0] > 0 || 493 (identifiers_[0] > 0 ||
501 autofill_unique_ids_[0] == 494 identifiers_[0] ==
502 WebAutofillClient::MenuItemIDAutocompleteEntry || 495 WebAutofillClient::MenuItemIDAutocompleteEntry ||
503 autofill_unique_ids_[0] == WebAutofillClient::MenuItemIDPasswordEntry || 496 identifiers_[0] == WebAutofillClient::MenuItemIDPasswordEntry ||
504 autofill_unique_ids_[0] == WebAutofillClient::MenuItemIDDataListEntry); 497 identifiers_[0] == WebAutofillClient::MenuItemIDDataListEntry);
505 } 498 }
506 499
507 void AutofillPopupControllerImpl::ShowView() { 500 void AutofillPopupControllerImpl::ShowView() {
508 view_->Show(); 501 view_->Show();
509 } 502 }
510 503
511 void AutofillPopupControllerImpl::InvalidateRow(size_t row) { 504 void AutofillPopupControllerImpl::InvalidateRow(size_t row) {
512 view_->InvalidateRow(row); 505 view_->InvalidateRow(row);
513 } 506 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698