Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: chrome/browser/ui/autofill/autofill_popup_controller_impl.h

Issue 12217024: Use WeakPtr to simplify AutofillPopupControllerImpl memory management (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix android build Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #ifndef CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_ 5 #ifndef CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_
6 #define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_ 6 #define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_
7 7
8 #include "base/gtest_prod_util.h" 8 #include "base/gtest_prod_util.h"
9 #include "base/memory/weak_ptr.h"
9 #include "base/string16.h" 10 #include "base/string16.h"
10 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" 11 #include "chrome/browser/ui/autofill/autofill_popup_controller.h"
11 #include "content/public/browser/keyboard_listener.h" 12 #include "content/public/browser/keyboard_listener.h"
12 #include "ui/gfx/font.h" 13 #include "ui/gfx/font.h"
13 #include "ui/gfx/rect.h" 14 #include "ui/gfx/rect.h"
14 #include "ui/gfx/rect_f.h" 15 #include "ui/gfx/rect_f.h"
15 16
16 class AutofillPopupDelegate; 17 class AutofillPopupDelegate;
17 class AutofillPopupView; 18 class AutofillPopupView;
18 19
19 namespace gfx { 20 namespace gfx {
20 class Display; 21 class Display;
21 } 22 }
22 23
23 namespace ui { 24 namespace ui {
24 class KeyEvent; 25 class KeyEvent;
25 } 26 }
26 27
27 // This class is a controller for an AutofillPopupView. It implements 28 // This class is a controller for an AutofillPopupView. It implements
28 // AutofillPopupController to allow calls from AutofillPopupView. The 29 // AutofillPopupController to allow calls from AutofillPopupView. The
29 // other, public functions are available to its instantiator. 30 // other, public functions are available to its instantiator.
30 class AutofillPopupControllerImpl : public AutofillPopupController, 31 class AutofillPopupControllerImpl : public AutofillPopupController,
31 public content::KeyboardListener { 32 public content::KeyboardListener {
32 public: 33 public:
33 // Creates a new |AutofillPopupControllerImpl|, or reuses |previous| if 34 // Creates a new |AutofillPopupControllerImpl|, or reuses |previous| if
34 // the construction arguments are the same. |previous| may be invalidated by 35 // the construction arguments are the same. |previous| may be invalidated by
35 // this call. 36 // this call.
36 static AutofillPopupControllerImpl* GetOrCreate( 37 static base::WeakPtr<AutofillPopupControllerImpl> GetOrCreate(
37 AutofillPopupControllerImpl* previous, 38 base::WeakPtr<AutofillPopupControllerImpl> previous,
38 AutofillPopupDelegate* delegate, 39 AutofillPopupDelegate* delegate,
39 gfx::NativeView container_view, 40 gfx::NativeView container_view,
40 const gfx::RectF& element_bounds); 41 const gfx::RectF& element_bounds);
41 42
42 // Shows the popup, or updates the existing popup with the given values. 43 // Shows the popup, or updates the existing popup with the given values.
43 void Show(const std::vector<string16>& names, 44 void Show(const std::vector<string16>& names,
44 const std::vector<string16>& subtexts, 45 const std::vector<string16>& subtexts,
45 const std::vector<string16>& icons, 46 const std::vector<string16>& icons,
46 const std::vector<int>& identifiers); 47 const std::vector<int>& identifiers);
47 48
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 132
132 // Protected so tests can access. 133 // Protected so tests can access.
133 #if !defined(OS_ANDROID) 134 #if !defined(OS_ANDROID)
134 // Calculates the desired width of the popup based on its contents. 135 // Calculates the desired width of the popup based on its contents.
135 int GetDesiredPopupWidth() const; 136 int GetDesiredPopupWidth() const;
136 137
137 // Calculates the desired height of the popup based on its contents. 138 // Calculates the desired height of the popup based on its contents.
138 int GetDesiredPopupHeight() const; 139 int GetDesiredPopupHeight() const;
139 #endif 140 #endif
140 141
142 base::WeakPtr<AutofillPopupControllerImpl> GetWeakPtr();
143
141 private: 144 private:
142 const gfx::Rect RoundedElementBounds() const; 145 const gfx::Rect RoundedElementBounds() const;
143 #if !defined(OS_ANDROID) 146 #if !defined(OS_ANDROID)
144 // Calculate the width of the row, excluding all the text. This provides 147 // Calculate the width of the row, excluding all the text. This provides
145 // the size of the row that won't be reducible (since all the text can be 148 // the size of the row that won't be reducible (since all the text can be
146 // elided if there isn't enough space). 149 // elided if there isn't enough space).
147 int RowWidthWithoutText(int row) const; 150 int RowWidthWithoutText(int row) const;
148 151
149 // Calculates and sets the bounds of the popup, including placing it properly 152 // Calculates and sets the bounds of the popup, including placing it properly
150 // to prevent it from going off the screen. 153 // to prevent it from going off the screen.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 int selected_line_; 204 int selected_line_;
202 205
203 // Used to indicate if the delete icon within a row is currently selected. 206 // Used to indicate if the delete icon within a row is currently selected.
204 bool delete_icon_hovered_; 207 bool delete_icon_hovered_;
205 208
206 // True if |HideInternal| has already been called. 209 // True if |HideInternal| has already been called.
207 bool is_hiding_; 210 bool is_hiding_;
208 211
209 // True if the delegate should be informed when |this| is destroyed. 212 // True if the delegate should be informed when |this| is destroyed.
210 bool inform_delegate_of_destruction_; 213 bool inform_delegate_of_destruction_;
214
215 base::WeakPtrFactory<AutofillPopupControllerImpl> weak_ptr_factory_;
211 }; 216 };
212 217
213 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_ 218 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698