| 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), | |
| 107 weak_ptr_factory_(this) { | 106 weak_ptr_factory_(this) { |
| 108 #if !defined(OS_ANDROID) | 107 #if !defined(OS_ANDROID) |
| 109 subtext_font_ = name_font_.DeriveFont(kLabelFontSizeDelta); | 108 subtext_font_ = name_font_.DeriveFont(kLabelFontSizeDelta); |
| 110 warning_font_ = name_font_.DeriveFont(0, gfx::Font::ITALIC); | 109 warning_font_ = name_font_.DeriveFont(0, gfx::Font::ITALIC); |
| 111 #endif | 110 #endif |
| 112 } | 111 } |
| 113 | 112 |
| 114 AutofillPopupControllerImpl::~AutofillPopupControllerImpl() {} | 113 AutofillPopupControllerImpl::~AutofillPopupControllerImpl() {} |
| 115 | 114 |
| 116 void AutofillPopupControllerImpl::Show( | 115 void AutofillPopupControllerImpl::Show( |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 view_ = AutofillPopupView::Create(this); | 162 view_ = AutofillPopupView::Create(this); |
| 164 ShowView(); | 163 ShowView(); |
| 165 } else { | 164 } else { |
| 166 UpdateBoundsAndRedrawPopup(); | 165 UpdateBoundsAndRedrawPopup(); |
| 167 } | 166 } |
| 168 | 167 |
| 169 delegate_->OnPopupShown(this); | 168 delegate_->OnPopupShown(this); |
| 170 } | 169 } |
| 171 | 170 |
| 172 void AutofillPopupControllerImpl::Hide() { | 171 void AutofillPopupControllerImpl::Hide() { |
| 173 if (is_hiding_) | |
| 174 return; | |
| 175 is_hiding_ = true; | |
| 176 | |
| 177 SetSelectedLine(kNoSelection); | 172 SetSelectedLine(kNoSelection); |
| 178 | 173 |
| 179 delegate_->OnPopupHidden(this); | 174 delegate_->OnPopupHidden(this); |
| 180 | 175 |
| 181 if (view_) | 176 if (view_) |
| 182 view_->Hide(); | 177 view_->Hide(); |
| 183 else | 178 |
| 184 delete this; | 179 delete this; |
| 185 } | 180 } |
| 186 | 181 |
| 187 bool AutofillPopupControllerImpl::HandleKeyPressEvent( | 182 bool AutofillPopupControllerImpl::HandleKeyPressEvent( |
| 188 const content::NativeWebKeyboardEvent& event) { | 183 const content::NativeWebKeyboardEvent& event) { |
| 189 switch (event.windowsKeyCode) { | 184 switch (event.windowsKeyCode) { |
| 190 case ui::VKEY_UP: | 185 case ui::VKEY_UP: |
| 191 SelectPreviousLine(); | 186 SelectPreviousLine(); |
| 192 return true; | 187 return true; |
| 193 case ui::VKEY_DOWN: | 188 case ui::VKEY_DOWN: |
| 194 SelectNextLine(); | 189 SelectNextLine(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 205 case ui::VKEY_DELETE: | 200 case ui::VKEY_DELETE: |
| 206 return (event.modifiers & content::NativeWebKeyboardEvent::ShiftKey) && | 201 return (event.modifiers & content::NativeWebKeyboardEvent::ShiftKey) && |
| 207 RemoveSelectedLine(); | 202 RemoveSelectedLine(); |
| 208 case ui::VKEY_RETURN: | 203 case ui::VKEY_RETURN: |
| 209 return AcceptSelectedLine(); | 204 return AcceptSelectedLine(); |
| 210 default: | 205 default: |
| 211 return false; | 206 return false; |
| 212 } | 207 } |
| 213 } | 208 } |
| 214 | 209 |
| 215 void AutofillPopupControllerImpl::ViewDestroyed() { | |
| 216 delete this; | |
| 217 } | |
| 218 | |
| 219 void AutofillPopupControllerImpl::UpdateBoundsAndRedrawPopup() { | 210 void AutofillPopupControllerImpl::UpdateBoundsAndRedrawPopup() { |
| 220 #if !defined(OS_ANDROID) | 211 #if !defined(OS_ANDROID) |
| 221 // TODO(csharp): Since UpdatePopupBounds can change the position of the popup, | 212 // 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. | 213 // 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 | 214 // 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. | 215 // should try and move to its desired position. |
| 225 UpdatePopupBounds(); | 216 UpdatePopupBounds(); |
| 226 #endif | 217 #endif |
| 227 | 218 |
| 228 view_->UpdateBoundsAndRedrawPopup(); | 219 view_->UpdateBoundsAndRedrawPopup(); |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 if (bottom_available >= popup_required_height || | 644 if (bottom_available >= popup_required_height || |
| 654 bottom_available >= top_available) { | 645 bottom_available >= top_available) { |
| 655 // The popup can appear below the field. | 646 // The popup can appear below the field. |
| 656 return std::make_pair(bottom_growth_start, popup_required_height); | 647 return std::make_pair(bottom_growth_start, popup_required_height); |
| 657 } else { | 648 } else { |
| 658 // The popup must appear above the field. | 649 // The popup must appear above the field. |
| 659 return std::make_pair(top_growth_end - popup_required_height, | 650 return std::make_pair(top_growth_end - popup_required_height, |
| 660 popup_required_height); | 651 popup_required_height); |
| 661 } | 652 } |
| 662 } | 653 } |
| OLD | NEW |