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

Side by Side Diff: ui/views/controls/button/button_dropdown.h

Issue 10832184: Fixed memory leak. Untangled confusing code with menu initialization and ownership. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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
« no previous file with comments | « chrome/browser/ui/views/toolbar_view.cc ('k') | ui/views/controls/button/button_dropdown.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 UI_VIEWS_CONTROLS_BUTTON_BUTTON_DROPDOWN_H_ 5 #ifndef UI_VIEWS_CONTROLS_BUTTON_BUTTON_DROPDOWN_H_
6 #define UI_VIEWS_CONTROLS_BUTTON_BUTTON_DROPDOWN_H_ 6 #define UI_VIEWS_CONTROLS_BUTTON_BUTTON_DROPDOWN_H_
7 7
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "ui/views/controls/button/image_button.h" 9 #include "ui/views/controls/button/image_button.h"
10 10
(...skipping 11 matching lines...) Expand all
22 // 22 //
23 // A button class that when pressed (and held) or pressed (and drag down) will 23 // A button class that when pressed (and held) or pressed (and drag down) will
24 // display a menu 24 // display a menu
25 // 25 //
26 //////////////////////////////////////////////////////////////////////////////// 26 ////////////////////////////////////////////////////////////////////////////////
27 class VIEWS_EXPORT ButtonDropDown : public ImageButton { 27 class VIEWS_EXPORT ButtonDropDown : public ImageButton {
28 public: 28 public:
29 // The button's class name. 29 // The button's class name.
30 static const char kViewClassName[]; 30 static const char kViewClassName[];
31 31
32 // Takes ownership of the |model|.
32 ButtonDropDown(ButtonListener* listener, ui::MenuModel* model); 33 ButtonDropDown(ButtonListener* listener, ui::MenuModel* model);
33 virtual ~ButtonDropDown(); 34 virtual ~ButtonDropDown();
34 35
35 // If menu is currently pending for long press - stop it. 36 // If menu is currently pending for long press - stop it.
36 void ClearPendingMenu(); 37 void ClearPendingMenu();
37 38
38 // Indicates if menu is currently showing. 39 // Indicates if menu is currently showing.
39 bool IsMenuShowing() const; 40 bool IsMenuShowing() const;
40 41
41 // Overridden from views::View 42 // Overridden from views::View
(...skipping 18 matching lines...) Expand all
60 virtual bool ShouldEnterPushedState(const Event& event) OVERRIDE; 61 virtual bool ShouldEnterPushedState(const Event& event) OVERRIDE;
61 62
62 // Returns if menu should be shown. Override this to change default behavior. 63 // Returns if menu should be shown. Override this to change default behavior.
63 virtual bool ShouldShowMenu(); 64 virtual bool ShouldShowMenu();
64 65
65 // Function to show the dropdown menu. 66 // Function to show the dropdown menu.
66 virtual void ShowDropDownMenu(); 67 virtual void ShowDropDownMenu();
67 68
68 private: 69 private:
69 // The model that populates the attached menu. 70 // The model that populates the attached menu.
70 ui::MenuModel* model_; 71 scoped_ptr<ui::MenuModel> model_;
71 72
72 // Indicates if menu is currently showing. 73 // Indicates if menu is currently showing.
73 bool menu_showing_; 74 bool menu_showing_;
74 75
75 // Y position of mouse when left mouse button is pressed 76 // Y position of mouse when left mouse button is pressed
76 int y_position_on_lbuttondown_; 77 int y_position_on_lbuttondown_;
77 78
78 // Menu runner to display drop down menu. 79 // Menu runner to display drop down menu.
79 scoped_ptr<MenuRunner> menu_runner_; 80 scoped_ptr<MenuRunner> menu_runner_;
80 81
81 // A factory for tasks that show the dropdown context menu for the button. 82 // A factory for tasks that show the dropdown context menu for the button.
82 base::WeakPtrFactory<ButtonDropDown> show_menu_factory_; 83 base::WeakPtrFactory<ButtonDropDown> show_menu_factory_;
83 84
84 DISALLOW_COPY_AND_ASSIGN(ButtonDropDown); 85 DISALLOW_COPY_AND_ASSIGN(ButtonDropDown);
85 }; 86 };
86 87
87 } // namespace views 88 } // namespace views
88 89
89 #endif // UI_VIEWS_CONTROLS_BUTTON_BUTTON_DROPDOWN_H_ 90 #endif // UI_VIEWS_CONTROLS_BUTTON_BUTTON_DROPDOWN_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/toolbar_view.cc ('k') | ui/views/controls/button/button_dropdown.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698