| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 AutofillPopupControllerImpl::AutofillPopupControllerImpl( | 96 AutofillPopupControllerImpl::AutofillPopupControllerImpl( |
| 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 hide_called_(false), |
| 107 weak_ptr_factory_(this) { | 107 weak_ptr_factory_(this) { |
| 108 #if !defined(OS_ANDROID) | 108 #if !defined(OS_ANDROID) |
| 109 subtext_font_ = name_font_.DeriveFont(kLabelFontSizeDelta); | 109 subtext_font_ = name_font_.DeriveFont(kLabelFontSizeDelta); |
| 110 warning_font_ = name_font_.DeriveFont(0, gfx::Font::ITALIC); | 110 warning_font_ = name_font_.DeriveFont(0, gfx::Font::ITALIC); |
| 111 #endif | 111 #endif |
| 112 } | 112 } |
| 113 | 113 |
| 114 AutofillPopupControllerImpl::~AutofillPopupControllerImpl() {} | 114 AutofillPopupControllerImpl::~AutofillPopupControllerImpl() { |
| 115 CHECK(hide_called_); |
| 116 } |
| 115 | 117 |
| 116 void AutofillPopupControllerImpl::Show( | 118 void AutofillPopupControllerImpl::Show( |
| 117 const std::vector<string16>& names, | 119 const std::vector<string16>& names, |
| 118 const std::vector<string16>& subtexts, | 120 const std::vector<string16>& subtexts, |
| 119 const std::vector<string16>& icons, | 121 const std::vector<string16>& icons, |
| 120 const std::vector<int>& identifiers) { | 122 const std::vector<int>& identifiers) { |
| 121 names_ = names; | 123 names_ = names; |
| 122 full_names_ = names; | 124 full_names_ = names; |
| 123 subtexts_ = subtexts; | 125 subtexts_ = subtexts; |
| 124 icons_ = icons; | 126 icons_ = icons; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 view_ = AutofillPopupView::Create(this); | 165 view_ = AutofillPopupView::Create(this); |
| 164 ShowView(); | 166 ShowView(); |
| 165 } else { | 167 } else { |
| 166 UpdateBoundsAndRedrawPopup(); | 168 UpdateBoundsAndRedrawPopup(); |
| 167 } | 169 } |
| 168 | 170 |
| 169 delegate_->OnPopupShown(this); | 171 delegate_->OnPopupShown(this); |
| 170 } | 172 } |
| 171 | 173 |
| 172 void AutofillPopupControllerImpl::Hide() { | 174 void AutofillPopupControllerImpl::Hide() { |
| 173 if (is_hiding_) | 175 hide_called_ = true; |
| 174 return; | |
| 175 is_hiding_ = true; | |
| 176 | 176 |
| 177 SetSelectedLine(kNoSelection); | 177 SetSelectedLine(kNoSelection); |
| 178 | 178 |
| 179 delegate_->OnPopupHidden(this); | 179 delegate_->OnPopupHidden(this); |
| 180 | 180 |
| 181 if (view_) | 181 if (view_) |
| 182 view_->Hide(); | 182 view_->Hide(); |
| 183 else | 183 |
| 184 delete this; | 184 delete this; |
| 185 } | 185 } |
| 186 | 186 |
| 187 bool AutofillPopupControllerImpl::HandleKeyPressEvent( | 187 bool AutofillPopupControllerImpl::HandleKeyPressEvent( |
| 188 const content::NativeWebKeyboardEvent& event) { | 188 const content::NativeWebKeyboardEvent& event) { |
| 189 switch (event.windowsKeyCode) { | 189 switch (event.windowsKeyCode) { |
| 190 case ui::VKEY_UP: | 190 case ui::VKEY_UP: |
| 191 SelectPreviousLine(); | 191 SelectPreviousLine(); |
| 192 return true; | 192 return true; |
| 193 case ui::VKEY_DOWN: | 193 case ui::VKEY_DOWN: |
| 194 SelectNextLine(); | 194 SelectNextLine(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 205 case ui::VKEY_DELETE: | 205 case ui::VKEY_DELETE: |
| 206 return (event.modifiers & content::NativeWebKeyboardEvent::ShiftKey) && | 206 return (event.modifiers & content::NativeWebKeyboardEvent::ShiftKey) && |
| 207 RemoveSelectedLine(); | 207 RemoveSelectedLine(); |
| 208 case ui::VKEY_RETURN: | 208 case ui::VKEY_RETURN: |
| 209 return AcceptSelectedLine(); | 209 return AcceptSelectedLine(); |
| 210 default: | 210 default: |
| 211 return false; | 211 return false; |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 | 214 |
| 215 void AutofillPopupControllerImpl::ViewDestroyed() { | |
| 216 delete this; | |
| 217 } | |
| 218 | |
| 219 void AutofillPopupControllerImpl::UpdateBoundsAndRedrawPopup() { | 215 void AutofillPopupControllerImpl::UpdateBoundsAndRedrawPopup() { |
| 220 #if !defined(OS_ANDROID) | 216 #if !defined(OS_ANDROID) |
| 221 // TODO(csharp): Since UpdatePopupBounds can change the position of the popup, | 217 // TODO(csharp): Since UpdatePopupBounds can change the position of the popup, |
| 222 // the popup could end up jumping from above the element to below it. | 218 // the popup could end up jumping from above the element to below it. |
| 223 // It is unclear if it is better to keep the popup where it was, or if it | 219 // It is unclear if it is better to keep the popup where it was, or if it |
| 224 // should try and move to its desired position. | 220 // should try and move to its desired position. |
| 225 UpdatePopupBounds(); | 221 UpdatePopupBounds(); |
| 226 #endif | 222 #endif |
| 227 | 223 |
| 228 view_->UpdateBoundsAndRedrawPopup(); | 224 view_->UpdateBoundsAndRedrawPopup(); |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 if (bottom_available >= popup_required_height || | 649 if (bottom_available >= popup_required_height || |
| 654 bottom_available >= top_available) { | 650 bottom_available >= top_available) { |
| 655 // The popup can appear below the field. | 651 // The popup can appear below the field. |
| 656 return std::make_pair(bottom_growth_start, popup_required_height); | 652 return std::make_pair(bottom_growth_start, popup_required_height); |
| 657 } else { | 653 } else { |
| 658 // The popup must appear above the field. | 654 // The popup must appear above the field. |
| 659 return std::make_pair(top_growth_end - popup_required_height, | 655 return std::make_pair(top_growth_end - popup_required_height, |
| 660 popup_required_height); | 656 popup_required_height); |
| 661 } | 657 } |
| 662 } | 658 } |
| OLD | NEW |