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

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

Issue 12288046: Merge 182751 (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1410/src/
Patch Set: Created 7 years, 10 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 | 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 <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 AutofillPopupDelegate* delegate, 97 AutofillPopupDelegate* delegate,
98 gfx::NativeView container_view, 98 gfx::NativeView container_view,
99 const gfx::RectF& element_bounds) 99 const gfx::RectF& element_bounds)
100 : view_(NULL), 100 : view_(NULL),
101 delegate_(delegate), 101 delegate_(delegate),
102 container_view_(container_view), 102 container_view_(container_view),
103 element_bounds_(element_bounds), 103 element_bounds_(element_bounds),
104 selected_line_(kNoSelection), 104 selected_line_(kNoSelection),
105 delete_icon_hovered_(false), 105 delete_icon_hovered_(false),
106 is_hiding_(false), 106 is_hiding_(false),
107 inform_delegate_of_destruction_(true),
108 weak_ptr_factory_(this) { 107 weak_ptr_factory_(this) {
109 #if !defined(OS_ANDROID) 108 #if !defined(OS_ANDROID)
110 subtext_font_ = name_font_.DeriveFont(kLabelFontSizeDelta); 109 subtext_font_ = name_font_.DeriveFont(kLabelFontSizeDelta);
111 warning_font_ = name_font_.DeriveFont(0, gfx::Font::ITALIC); 110 warning_font_ = name_font_.DeriveFont(0, gfx::Font::ITALIC);
112 #endif 111 #endif
113 } 112 }
114 113
115 AutofillPopupControllerImpl::~AutofillPopupControllerImpl() {} 114 AutofillPopupControllerImpl::~AutofillPopupControllerImpl() {}
116 115
117 void AutofillPopupControllerImpl::Show( 116 void AutofillPopupControllerImpl::Show(
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 view_ = AutofillPopupView::Create(this); 163 view_ = AutofillPopupView::Create(this);
165 ShowView(); 164 ShowView();
166 } else { 165 } else {
167 UpdateBoundsAndRedrawPopup(); 166 UpdateBoundsAndRedrawPopup();
168 } 167 }
169 168
170 delegate_->OnPopupShown(this); 169 delegate_->OnPopupShown(this);
171 } 170 }
172 171
173 void AutofillPopupControllerImpl::Hide() { 172 void AutofillPopupControllerImpl::Hide() {
174 inform_delegate_of_destruction_ = false; 173 if (is_hiding_)
175 HideInternal(); 174 return;
175 is_hiding_ = true;
176
177 SetSelectedLine(kNoSelection);
178
179 delegate_->OnPopupHidden(this);
180
181 if (view_)
182 view_->Hide();
183 else
184 delete this;
176 } 185 }
177 186
178 bool AutofillPopupControllerImpl::HandleKeyPressEvent( 187 bool AutofillPopupControllerImpl::HandleKeyPressEvent(
179 const content::NativeWebKeyboardEvent& event) { 188 const content::NativeWebKeyboardEvent& event) {
180 switch (event.windowsKeyCode) { 189 switch (event.windowsKeyCode) {
181 case ui::VKEY_UP: 190 case ui::VKEY_UP:
182 SelectPreviousLine(); 191 SelectPreviousLine();
183 return true; 192 return true;
184 case ui::VKEY_DOWN: 193 case ui::VKEY_DOWN:
185 SelectNextLine(); 194 SelectNextLine();
186 return true; 195 return true;
187 case ui::VKEY_PRIOR: // Page up. 196 case ui::VKEY_PRIOR: // Page up.
188 SetSelectedLine(0); 197 SetSelectedLine(0);
189 return true; 198 return true;
190 case ui::VKEY_NEXT: // Page down. 199 case ui::VKEY_NEXT: // Page down.
191 SetSelectedLine(names().size() - 1); 200 SetSelectedLine(names().size() - 1);
192 return true; 201 return true;
193 case ui::VKEY_ESCAPE: 202 case ui::VKEY_ESCAPE:
194 HideInternal(); 203 Hide();
195 return true; 204 return true;
196 case ui::VKEY_DELETE: 205 case ui::VKEY_DELETE:
197 return (event.modifiers & content::NativeWebKeyboardEvent::ShiftKey) && 206 return (event.modifiers & content::NativeWebKeyboardEvent::ShiftKey) &&
198 RemoveSelectedLine(); 207 RemoveSelectedLine();
199 case ui::VKEY_RETURN: 208 case ui::VKEY_RETURN:
200 return AcceptSelectedLine(); 209 return AcceptSelectedLine();
201 default: 210 default:
202 return false; 211 return false;
203 } 212 }
204 } 213 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 #endif 335 #endif
327 336
328 int AutofillPopupControllerImpl::selected_line() const { 337 int AutofillPopupControllerImpl::selected_line() const {
329 return selected_line_; 338 return selected_line_;
330 } 339 }
331 340
332 bool AutofillPopupControllerImpl::delete_icon_hovered() const { 341 bool AutofillPopupControllerImpl::delete_icon_hovered() const {
333 return delete_icon_hovered_; 342 return delete_icon_hovered_;
334 } 343 }
335 344
336 void AutofillPopupControllerImpl::HideInternal() {
337 if (is_hiding_)
338 return;
339 is_hiding_ = true;
340
341 SetSelectedLine(kNoSelection);
342
343 if (inform_delegate_of_destruction_)
344 delegate_->OnPopupHidden(this);
345
346 if (view_)
347 view_->Hide();
348 else
349 delete this;
350 }
351
352 void AutofillPopupControllerImpl::SetSelectedLine(int selected_line) { 345 void AutofillPopupControllerImpl::SetSelectedLine(int selected_line) {
353 if (selected_line_ == selected_line) 346 if (selected_line_ == selected_line)
354 return; 347 return;
355 348
356 if (selected_line_ != kNoSelection) 349 if (selected_line_ != kNoSelection)
357 InvalidateRow(selected_line_); 350 InvalidateRow(selected_line_);
358 351
359 if (selected_line != kNoSelection) 352 if (selected_line != kNoSelection)
360 InvalidateRow(selected_line); 353 InvalidateRow(selected_line);
361 354
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 subtexts_.erase(subtexts_.begin() + selected_line_); 423 subtexts_.erase(subtexts_.begin() + selected_line_);
431 icons_.erase(icons_.begin() + selected_line_); 424 icons_.erase(icons_.begin() + selected_line_);
432 identifiers_.erase(identifiers_.begin() + selected_line_); 425 identifiers_.erase(identifiers_.begin() + selected_line_);
433 426
434 SetSelectedLine(kNoSelection); 427 SetSelectedLine(kNoSelection);
435 428
436 if (HasSuggestions()) { 429 if (HasSuggestions()) {
437 delegate_->ClearPreviewedForm(); 430 delegate_->ClearPreviewedForm();
438 UpdateBoundsAndRedrawPopup(); 431 UpdateBoundsAndRedrawPopup();
439 } else { 432 } else {
440 HideInternal(); 433 Hide();
441 } 434 }
442 435
443 return true; 436 return true;
444 } 437 }
445 438
446 int AutofillPopupControllerImpl::LineFromY(int y) { 439 int AutofillPopupControllerImpl::LineFromY(int y) {
447 int current_height = 0; 440 int current_height = 0;
448 441
449 for (size_t i = 0; i < identifiers().size(); ++i) { 442 for (size_t i = 0; i < identifiers().size(); ++i) {
450 current_height += GetRowHeightFromId(identifiers()[i]); 443 current_height += GetRowHeightFromId(identifiers()[i]);
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 if (bottom_available >= popup_required_height || 654 if (bottom_available >= popup_required_height ||
662 bottom_available >= top_available) { 655 bottom_available >= top_available) {
663 // The popup can appear below the field. 656 // The popup can appear below the field.
664 return std::make_pair(bottom_growth_start, popup_required_height); 657 return std::make_pair(bottom_growth_start, popup_required_height);
665 } else { 658 } else {
666 // The popup must appear above the field. 659 // The popup must appear above the field.
667 return std::make_pair(top_growth_end - popup_required_height, 660 return std::make_pair(top_growth_end - popup_required_height,
668 popup_required_height); 661 popup_required_height);
669 } 662 }
670 } 663 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698