diff options
-rw-r--r-- | chrome/browser/chromeos/clock_menu_button.cc | 10 | ||||
-rw-r--r-- | chrome/browser/chromeos/clock_menu_button.h | 5 | ||||
-rw-r--r-- | views/controls/menu/menu_2.h | 6 |
3 files changed, 16 insertions, 5 deletions
diff --git a/chrome/browser/chromeos/clock_menu_button.cc b/chrome/browser/chromeos/clock_menu_button.cc index 98af0b4..745fe24 100644 --- a/chrome/browser/chromeos/clock_menu_button.cc +++ b/chrome/browser/chromeos/clock_menu_button.cc @@ -26,7 +26,6 @@ const int kTimerSlopSeconds = 1; ClockMenuButton::ClockMenuButton(Browser* browser) : MenuButton(NULL, std::wstring(), this, false), - clock_menu_(this), browser_(browser) { set_border(NULL); SetFont(ResourceBundle::GetSharedInstance().GetFont( @@ -141,9 +140,12 @@ void ClockMenuButton::ActivatedAt(int index) { // ClockMenuButton, views::ViewMenuDelegate implementation: void ClockMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { - clock_menu_.Rebuild(); - clock_menu_.UpdateStates(); - clock_menu_.RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); + if (!clock_menu_.get()) + clock_menu_.reset(new views::Menu2(this)); + else + clock_menu_->Rebuild(); + clock_menu_->UpdateStates(); + clock_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); } } // namespace chromeos diff --git a/chrome/browser/chromeos/clock_menu_button.h b/chrome/browser/chromeos/clock_menu_button.h index a720302..b3d0543 100644 --- a/chrome/browser/chromeos/clock_menu_button.h +++ b/chrome/browser/chromeos/clock_menu_button.h @@ -5,6 +5,7 @@ #ifndef CHROME_BROWSER_CHROMEOS_CLOCK_MENU_BUTTON_H_ #define CHROME_BROWSER_CHROMEOS_CLOCK_MENU_BUTTON_H_ +#include "base/scoped_ptr.h" #include "base/timer.h" #include "chrome/common/notification_observer.h" #include "chrome/common/pref_member.h" @@ -67,7 +68,9 @@ class ClockMenuButton : public views::MenuButton, StringPrefMember timezone_; // The clock menu. - views::Menu2 clock_menu_; + // NOTE: we use a scoped_ptr here as menu calls into 'this' from the + // constructor. + scoped_ptr<views::Menu2> clock_menu_; // The browser object. Can be NULL if the button is on the login manager // screen. diff --git a/views/controls/menu/menu_2.h b/views/controls/menu/menu_2.h index 4bfe9b9..416c949 100644 --- a/views/controls/menu/menu_2.h +++ b/views/controls/menu/menu_2.h @@ -20,6 +20,12 @@ class NativeMenuGtk; // A menu. Populated from a model, and relies on a delegate to execute commands. class Menu2 { public: + // Creates a new menu populated with the contents of |model|. + // WARNING: this populates the menu on construction by invoking methods on + // the model. As such, it is typically not safe to use this as the model + // from the constructor. EG: + // MyClass : menu_(this) {} + // is likely to have problems. explicit Menu2(menus::MenuModel* model); virtual ~Menu2() {} |