views: Don't retain MenuRunner on heap.

Sometimes the MenuHost would crash when the window is closed, the author
didn't recommend using MenuRunner on stack, but since we always run the
menu synchronously, this is no problem.
This commit is contained in:
Cheng Zhao 2014-07-21 21:42:01 +08:00
parent 1a79093378
commit 21949e2f0c
4 changed files with 6 additions and 18 deletions

View file

@ -25,16 +25,14 @@ void MenuViews::Popup(Window* window) {
cursor = gfx::win::ScreenToDIPPoint(cursor); cursor = gfx::win::ScreenToDIPPoint(cursor);
#endif #endif
menu_runner_.reset(new views::MenuRunner(model())); views::MenuRunner menu_runner(model());
views::MenuRunner::RunResult result = menu_runner_->RunMenuAt( ignore_result(menu_runner.RunMenuAt(
static_cast<NativeWindowViews*>(window->window())->widget(), static_cast<NativeWindowViews*>(window->window())->widget(),
NULL, NULL,
gfx::Rect(cursor, gfx::Size()), gfx::Rect(cursor, gfx::Size()),
views::MenuItemView::TOPLEFT, views::MenuItemView::TOPLEFT,
ui::MENU_SOURCE_MOUSE, ui::MENU_SOURCE_MOUSE,
views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU); views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU));
if (result == views::MenuRunner::MENU_DELETED)
LOG(ERROR) << "Menu deleted when running";
} }
// static // static

View file

@ -7,10 +7,6 @@
#include "atom/browser/api/atom_api_menu.h" #include "atom/browser/api/atom_api_menu.h"
namespace views {
class MenuRunner;
}
namespace atom { namespace atom {
namespace api { namespace api {
@ -23,8 +19,6 @@ class MenuViews : public Menu {
virtual void Popup(Window* window) OVERRIDE; virtual void Popup(Window* window) OVERRIDE;
private: private:
scoped_ptr<views::MenuRunner> menu_runner_;
DISALLOW_COPY_AND_ASSIGN(MenuViews); DISALLOW_COPY_AND_ASSIGN(MenuViews);
}; };

View file

@ -34,16 +34,14 @@ void MenuDelegate::RunMenu(ui::MenuModel* model, views::MenuButton* button) {
id_ = button->tag(); id_ = button->tag();
views::MenuItemView* item = BuildMenu(model); views::MenuItemView* item = BuildMenu(model);
menu_runner_.reset(new views::MenuRunner(item)); views::MenuRunner menu_runner(item);
views::MenuRunner::RunResult result = menu_runner_->RunMenuAt( ignore_result(menu_runner.RunMenuAt(
button->GetWidget()->GetTopLevelWidget(), button->GetWidget()->GetTopLevelWidget(),
button, button,
bounds, bounds,
views::MenuItemView::TOPRIGHT, views::MenuItemView::TOPRIGHT,
ui::MENU_SOURCE_MOUSE, ui::MENU_SOURCE_MOUSE,
views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU); views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU));
if (result == views::MenuRunner::MENU_DELETED)
LOG(ERROR) << "Menu deleted when running";
} }
views::MenuItemView* MenuDelegate::BuildMenu(ui::MenuModel* model) { views::MenuItemView* MenuDelegate::BuildMenu(ui::MenuModel* model) {

View file

@ -11,7 +11,6 @@
namespace views { namespace views {
class MenuModelAdapter; class MenuModelAdapter;
class MenuRunner;
} }
namespace ui { namespace ui {
@ -59,7 +58,6 @@ class MenuDelegate : public views::MenuDelegate {
views::MenuDelegate* delegate() const { return delegates_[id_]; } views::MenuDelegate* delegate() const { return delegates_[id_]; }
MenuBar* menu_bar_; MenuBar* menu_bar_;
scoped_ptr<views::MenuRunner> menu_runner_;
// Current item's id. // Current item's id.
int id_; int id_;