| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/views/autofill/autofill_popup_base_view.h" | 5 #include "chrome/browser/ui/views/autofill/autofill_popup_base_view.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "chrome/browser/ui/autofill/popup_constants.h" | 10 #include "chrome/browser/ui/autofill/popup_constants.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE), | 56 ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE), |
| 57 ui::AcceleratorManager::kNormalPriority, | 57 ui::AcceleratorManager::kNormalPriority, |
| 58 this); | 58 this); |
| 59 | 59 |
| 60 // The widget is destroyed by the corresponding NativeWidget, so we use | 60 // The widget is destroyed by the corresponding NativeWidget, so we use |
| 61 // a weak pointer to hold the reference and don't have to worry about | 61 // a weak pointer to hold the reference and don't have to worry about |
| 62 // deletion. | 62 // deletion. |
| 63 views::Widget* widget = new views::Widget; | 63 views::Widget* widget = new views::Widget; |
| 64 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 64 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
| 65 params.delegate = this; | 65 params.delegate = this; |
| 66 params.context = container_view(); | 66 params.parent = container_view(); |
| 67 widget->Init(params); | 67 widget->Init(params); |
| 68 widget->SetContentsView(this); | 68 widget->SetContentsView(this); |
| 69 | 69 |
| 70 // No animation for popup appearance (too distracting). | 70 // No animation for popup appearance (too distracting). |
| 71 wm::SetWindowVisibilityAnimationTransition( | 71 wm::SetWindowVisibilityAnimationTransition( |
| 72 widget->GetNativeView(), wm::ANIMATE_HIDE); | 72 widget->GetNativeView(), wm::ANIMATE_HIDE); |
| 73 } | 73 } |
| 74 | 74 |
| 75 SetBorder(views::Border::CreateSolidBorder(kPopupBorderThickness, | 75 SetBorder(views::Border::CreateSolidBorder(kPopupBorderThickness, |
| 76 kBorderColor)); | 76 kBorderColor)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 95 // assume the the widget is still valid after this point. | 95 // assume the the widget is still valid after this point. |
| 96 // http://crbug.com/229224 | 96 // http://crbug.com/229224 |
| 97 // NOTE: This deletes |this|. | 97 // NOTE: This deletes |this|. |
| 98 GetWidget()->Close(); | 98 GetWidget()->Close(); |
| 99 } else { | 99 } else { |
| 100 delete this; | 100 delete this; |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 | 103 |
| 104 void AutofillPopupBaseView::RemoveObserver() { | 104 void AutofillPopupBaseView::RemoveObserver() { |
| 105 if (observing_widget_) { | 105 observing_widget_->GetFocusManager()->UnregisterAccelerators(this); |
| 106 observing_widget_->GetFocusManager()->UnregisterAccelerators(this); | 106 observing_widget_->RemoveObserver(this); |
| 107 observing_widget_->RemoveObserver(this); | |
| 108 } | |
| 109 views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this); | 107 views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this); |
| 110 } | 108 } |
| 111 | 109 |
| 112 void AutofillPopupBaseView::DoUpdateBoundsAndRedrawPopup() { | 110 void AutofillPopupBaseView::DoUpdateBoundsAndRedrawPopup() { |
| 113 GetWidget()->SetBounds(delegate_->popup_bounds()); | 111 GetWidget()->SetBounds(delegate_->popup_bounds()); |
| 114 SchedulePaint(); | 112 SchedulePaint(); |
| 115 } | 113 } |
| 116 | 114 |
| 117 void AutofillPopupBaseView::OnNativeFocusChange( | 115 void AutofillPopupBaseView::OnNativeFocusChange( |
| 118 gfx::NativeView focused_before, | 116 gfx::NativeView focused_before, |
| 119 gfx::NativeView focused_now) { | 117 gfx::NativeView focused_now) { |
| 120 if (GetWidget() && GetWidget()->GetNativeView() != focused_now) | 118 if (GetWidget() && GetWidget()->GetNativeView() != focused_now) |
| 121 HideController(); | 119 HideController(); |
| 122 } | 120 } |
| 123 | 121 |
| 124 void AutofillPopupBaseView::OnWidgetDestroying(views::Widget* widget) { | |
| 125 DCHECK_EQ(widget, observing_widget_); | |
| 126 observing_widget_ = NULL; | |
| 127 } | |
| 128 | |
| 129 void AutofillPopupBaseView::OnWidgetBoundsChanged(views::Widget* widget, | 122 void AutofillPopupBaseView::OnWidgetBoundsChanged(views::Widget* widget, |
| 130 const gfx::Rect& new_bounds) { | 123 const gfx::Rect& new_bounds) { |
| 131 DCHECK_EQ(widget, observing_widget_); | 124 DCHECK_EQ(widget, observing_widget_); |
| 132 HideController(); | 125 HideController(); |
| 133 } | 126 } |
| 134 | 127 |
| 135 void AutofillPopupBaseView::OnMouseCaptureLost() { | 128 void AutofillPopupBaseView::OnMouseCaptureLost() { |
| 136 ClearSelection(); | 129 ClearSelection(); |
| 137 } | 130 } |
| 138 | 131 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 void AutofillPopupBaseView::HideController() { | 234 void AutofillPopupBaseView::HideController() { |
| 242 if (delegate_) | 235 if (delegate_) |
| 243 delegate_->Hide(); | 236 delegate_->Hide(); |
| 244 } | 237 } |
| 245 | 238 |
| 246 gfx::NativeView AutofillPopupBaseView::container_view() { | 239 gfx::NativeView AutofillPopupBaseView::container_view() { |
| 247 return delegate_->container_view(); | 240 return delegate_->container_view(); |
| 248 } | 241 } |
| 249 | 242 |
| 250 } // namespace autofill | 243 } // namespace autofill |
| OLD | NEW |