| Index: chrome/browser/ui/autofill/autofill_popup_controller_impl.cc
|
| diff --git a/chrome/browser/ui/autofill/autofill_popup_controller_impl.cc b/chrome/browser/ui/autofill/autofill_popup_controller_impl.cc
|
| index 7e28e376c01d1f46981d08adedc6f8fedd9f4110..5e732dc61db8650c27e1c0839d8380996bd7233f 100644
|
| --- a/chrome/browser/ui/autofill/autofill_popup_controller_impl.cc
|
| +++ b/chrome/browser/ui/autofill/autofill_popup_controller_impl.cc
|
| @@ -20,6 +20,7 @@
|
| #include "ui/gfx/screen.h"
|
| #include "ui/gfx/vector2d.h"
|
|
|
| +using base::WeakPtr;
|
| using WebKit::WebAutofillClient;
|
|
|
| namespace {
|
| @@ -70,8 +71,8 @@ const DataResource kDataResources[] = {
|
| } // end namespace
|
|
|
| // static
|
| -AutofillPopupControllerImpl* AutofillPopupControllerImpl::GetOrCreate(
|
| - AutofillPopupControllerImpl* previous,
|
| +WeakPtr<AutofillPopupControllerImpl> AutofillPopupControllerImpl::GetOrCreate(
|
| + WeakPtr<AutofillPopupControllerImpl> previous,
|
| AutofillPopupDelegate* delegate,
|
| gfx::NativeView container_view,
|
| const gfx::Rect& element_bounds) {
|
| @@ -86,8 +87,9 @@ AutofillPopupControllerImpl* AutofillPopupControllerImpl::GetOrCreate(
|
| if (previous)
|
| previous->Hide();
|
|
|
| - return new AutofillPopupControllerImpl(
|
| - delegate, container_view, element_bounds);
|
| + AutofillPopupControllerImpl* controller =
|
| + new AutofillPopupControllerImpl(delegate, container_view, element_bounds);
|
| + return controller->GetWeakPtr();
|
| }
|
|
|
| AutofillPopupControllerImpl::AutofillPopupControllerImpl(
|
| @@ -101,16 +103,13 @@ AutofillPopupControllerImpl::AutofillPopupControllerImpl(
|
| selected_line_(kNoSelection),
|
| delete_icon_hovered_(false),
|
| is_hiding_(false),
|
| - inform_delegate_of_destruction_(true) {
|
| + weak_ptr_factory_(this) {
|
| #if !defined(OS_ANDROID)
|
| subtext_font_ = name_font_.DeriveFont(kLabelFontSizeDelta);
|
| #endif
|
| }
|
|
|
| -AutofillPopupControllerImpl::~AutofillPopupControllerImpl() {
|
| - if (inform_delegate_of_destruction_)
|
| - delegate_->ControllerDestroyed();
|
| -}
|
| +AutofillPopupControllerImpl::~AutofillPopupControllerImpl() {}
|
|
|
| void AutofillPopupControllerImpl::Show(
|
| const std::vector<string16>& names,
|
| @@ -164,11 +163,23 @@ void AutofillPopupControllerImpl::Show(
|
| } else {
|
| UpdateBoundsAndRedrawPopup();
|
| }
|
| +
|
| + delegate_->OnPopupShown(this);
|
| }
|
|
|
| void AutofillPopupControllerImpl::Hide() {
|
| - inform_delegate_of_destruction_ = false;
|
| - HideInternal();
|
| + if (is_hiding_)
|
| + return;
|
| + is_hiding_ = true;
|
| +
|
| + SetSelectedLine(kNoSelection);
|
| +
|
| + delegate_->OnPopupHidden(this);
|
| +
|
| + if (view_)
|
| + view_->Hide();
|
| + else
|
| + delete this;
|
| }
|
|
|
| bool AutofillPopupControllerImpl::HandleKeyPressEvent(
|
| @@ -187,7 +198,7 @@ bool AutofillPopupControllerImpl::HandleKeyPressEvent(
|
| SetSelectedLine(names().size() - 1);
|
| return true;
|
| case ui::VKEY_ESCAPE:
|
| - HideInternal();
|
| + Hide();
|
| return true;
|
| case ui::VKEY_DELETE:
|
| return (event.modifiers & content::NativeWebKeyboardEvent::ShiftKey) &&
|
| @@ -325,19 +336,6 @@ bool AutofillPopupControllerImpl::delete_icon_hovered() const {
|
| return delete_icon_hovered_;
|
| }
|
|
|
| -void AutofillPopupControllerImpl::HideInternal() {
|
| - if (is_hiding_)
|
| - return;
|
| - is_hiding_ = true;
|
| -
|
| - SetSelectedLine(kNoSelection);
|
| -
|
| - if (view_)
|
| - view_->Hide();
|
| - else
|
| - delete this;
|
| -}
|
| -
|
| void AutofillPopupControllerImpl::SetSelectedLine(int selected_line) {
|
| if (selected_line_ == selected_line)
|
| return;
|
| @@ -426,7 +424,7 @@ bool AutofillPopupControllerImpl::RemoveSelectedLine() {
|
| delegate_->ClearPreviewedForm();
|
| UpdateBoundsAndRedrawPopup();
|
| } else {
|
| - HideInternal();
|
| + Hide();
|
| }
|
|
|
| return true;
|
| @@ -528,6 +526,10 @@ int AutofillPopupControllerImpl::GetDesiredPopupHeight() const {
|
| return popup_height;
|
| }
|
|
|
| +WeakPtr<AutofillPopupControllerImpl> AutofillPopupControllerImpl::GetWeakPtr() {
|
| + return weak_ptr_factory_.GetWeakPtr();
|
| +}
|
| +
|
| int AutofillPopupControllerImpl::RowWidthWithoutText(int row) const {
|
| int row_size = kEndPadding + kNamePadding;
|
|
|
|
|