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/views/autofill/autofill_popup_view_views.h" | 5 #include "chrome/browser/ui/views/autofill/autofill_popup_view_views.h" |
6 | 6 |
7 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" | 7 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" |
8 #include "grit/ui_resources.h" | 8 #include "grit/ui_resources.h" |
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" |
10 #include "ui/base/keycodes/keyboard_codes.h" | 10 #include "ui/base/keycodes/keyboard_codes.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 const SkColor kValueTextColor = SkColorSetARGB(0xFF, 0x00, 0x00, 0x00); | 27 const SkColor kValueTextColor = SkColorSetARGB(0xFF, 0x00, 0x00, 0x00); |
28 | 28 |
29 } // namespace | 29 } // namespace |
30 | 30 |
31 AutofillPopupViewViews::AutofillPopupViewViews( | 31 AutofillPopupViewViews::AutofillPopupViewViews( |
32 AutofillPopupController* controller) | 32 AutofillPopupController* controller) |
33 : controller_(controller), | 33 : controller_(controller), |
34 observing_widget_(NULL) {} | 34 observing_widget_(NULL) {} |
35 | 35 |
36 AutofillPopupViewViews::~AutofillPopupViewViews() { | 36 AutofillPopupViewViews::~AutofillPopupViewViews() { |
| 37 } |
| 38 |
| 39 void AutofillPopupViewViews::Hide() { |
| 40 AutofillPopupView::Hide(); |
| 41 |
37 if (observing_widget_) | 42 if (observing_widget_) |
38 observing_widget_->RemoveObserver(this); | 43 observing_widget_->RemoveObserver(this); |
39 | 44 |
40 controller_->ViewDestroyed(); | 45 // The controller is no longer valid after it hides us. |
41 } | 46 controller_ = NULL; |
42 | 47 |
43 void AutofillPopupViewViews::Hide() { | |
44 if (GetWidget()) { | 48 if (GetWidget()) { |
45 // This deletes |this|. | 49 // This deletes |this|. |
46 GetWidget()->Close(); | 50 GetWidget()->Close(); |
47 } else { | 51 } else { |
48 delete this; | 52 delete this; |
49 } | 53 } |
50 } | 54 } |
51 | 55 |
52 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { | 56 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { |
| 57 // This can happen if we have a paint message in the queue when the popup |
| 58 // is told to hide (so the controller is invalid at this point). Its ok to |
| 59 // avoid drawing popup, sine we don't have access to the data anymore, and it |
| 60 // should be hidden soon. |
| 61 if (!controller_) |
| 62 return; |
| 63 |
53 canvas->DrawColor(kPopupBackground); | 64 canvas->DrawColor(kPopupBackground); |
54 OnPaintBorder(canvas); | 65 OnPaintBorder(canvas); |
55 | 66 |
56 for (size_t i = 0; i < controller_->names().size(); ++i) { | 67 for (size_t i = 0; i < controller_->names().size(); ++i) { |
57 gfx::Rect line_rect = controller_->GetRowBounds(i); | 68 gfx::Rect line_rect = controller_->GetRowBounds(i); |
58 | 69 |
59 if (controller_->identifiers()[i] == | 70 if (controller_->identifiers()[i] == |
60 WebAutofillClient::MenuItemIDSeparator) { | 71 WebAutofillClient::MenuItemIDSeparator) { |
61 canvas->DrawRect(line_rect, kItemTextColor); | 72 canvas->DrawRect(line_rect, kItemTextColor); |
62 } else { | 73 } else { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 void AutofillPopupViewViews::OnMouseReleased(const ui::MouseEvent& event) { | 110 void AutofillPopupViewViews::OnMouseReleased(const ui::MouseEvent& event) { |
100 // We only care about the left click. | 111 // We only care about the left click. |
101 if (event.IsOnlyLeftMouseButton() && | 112 if (event.IsOnlyLeftMouseButton() && |
102 HitTestPoint(gfx::Point(event.x(), event.y()))) | 113 HitTestPoint(gfx::Point(event.x(), event.y()))) |
103 controller_->MouseClicked(event.x(), event.y()); | 114 controller_->MouseClicked(event.x(), event.y()); |
104 } | 115 } |
105 | 116 |
106 void AutofillPopupViewViews::OnWidgetBoundsChanged( | 117 void AutofillPopupViewViews::OnWidgetBoundsChanged( |
107 views::Widget* widget, | 118 views::Widget* widget, |
108 const gfx::Rect& new_bounds) { | 119 const gfx::Rect& new_bounds) { |
109 Hide(); | 120 controller_->Hide(); |
110 } | 121 } |
111 | 122 |
112 void AutofillPopupViewViews::Show() { | 123 void AutofillPopupViewViews::Show() { |
113 if (!GetWidget()) { | 124 if (!GetWidget()) { |
114 // The widget is destroyed by the corresponding NativeWidget, so we use | 125 // The widget is destroyed by the corresponding NativeWidget, so we use |
115 // a weak pointer to hold the reference and don't have to worry about | 126 // a weak pointer to hold the reference and don't have to worry about |
116 // deletion. | 127 // deletion. |
117 views::Widget* widget = new views::Widget; | 128 views::Widget* widget = new views::Widget; |
118 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 129 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
119 params.delegate = this; | 130 params.delegate = this; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 canvas->GetStringWidth(controller_->subtexts()[index], | 214 canvas->GetStringWidth(controller_->subtexts()[index], |
204 controller_->subtext_font()), | 215 controller_->subtext_font()), |
205 entry_rect.height(), | 216 entry_rect.height(), |
206 gfx::Canvas::TEXT_ALIGN_CENTER); | 217 gfx::Canvas::TEXT_ALIGN_CENTER); |
207 } | 218 } |
208 | 219 |
209 AutofillPopupView* AutofillPopupView::Create( | 220 AutofillPopupView* AutofillPopupView::Create( |
210 AutofillPopupController* controller) { | 221 AutofillPopupController* controller) { |
211 return new AutofillPopupViewViews(controller); | 222 return new AutofillPopupViewViews(controller); |
212 } | 223 } |
OLD | NEW |