diff options
-rw-r--r-- | ui/base/models/simple_menu_model.cc | 14 | ||||
-rw-r--r-- | ui/base/models/simple_menu_model.h | 6 | ||||
-rw-r--r-- | views/controls/menu/native_menu_win.cc | 18 |
3 files changed, 21 insertions, 17 deletions
diff --git a/ui/base/models/simple_menu_model.cc b/ui/base/models/simple_menu_model.cc index ba7555b..6152766 100644 --- a/ui/base/models/simple_menu_model.cc +++ b/ui/base/models/simple_menu_model.cc @@ -4,6 +4,7 @@ #include "ui/base/models/simple_menu_model.h" +#include "base/message_loop.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/l10n/l10n_util.h" @@ -51,7 +52,9 @@ void SimpleMenuModel::Delegate::MenuClosed() { //////////////////////////////////////////////////////////////////////////////// // SimpleMenuModel, public: -SimpleMenuModel::SimpleMenuModel(Delegate* delegate) : delegate_(delegate) { +SimpleMenuModel::SimpleMenuModel(Delegate* delegate) + : delegate_(delegate), + ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { } SimpleMenuModel::~SimpleMenuModel() { @@ -288,6 +291,15 @@ MenuModel* SimpleMenuModel::GetSubmenuModelAt(int index) const { } void SimpleMenuModel::MenuClosed() { + // Due to how menus work on the different platforms, ActivatedAt will be + // called after this. It's more convenient for the delegate to be called + // afterwards though, so post a task. + MessageLoop::current()->PostTask( + FROM_HERE, + method_factory_.NewRunnableMethod(&SimpleMenuModel::OnMenuClosed)); +} + +void SimpleMenuModel::OnMenuClosed() { if (delegate_) delegate_->MenuClosed(); } diff --git a/ui/base/models/simple_menu_model.h b/ui/base/models/simple_menu_model.h index c321f07..32490ad 100644 --- a/ui/base/models/simple_menu_model.h +++ b/ui/base/models/simple_menu_model.h @@ -9,6 +9,7 @@ #include <vector> #include "base/string16.h" +#include "base/task.h" #include "ui/base/models/menu_model.h" namespace ui { @@ -138,10 +139,15 @@ class SimpleMenuModel : public MenuModel { void InsertItemAtIndex(const Item& item, int index); void ValidateItem(const Item& item); + // Notify the delegate that the menu is closed. + void OnMenuClosed(); + std::vector<Item> items_; Delegate* delegate_; + ScopedRunnableMethodFactory<SimpleMenuModel> method_factory_; + DISALLOW_COPY_AND_ASSIGN(SimpleMenuModel); }; diff --git a/views/controls/menu/native_menu_win.cc b/views/controls/menu/native_menu_win.cc index fab94b2..e7238a4 100644 --- a/views/controls/menu/native_menu_win.cc +++ b/views/controls/menu/native_menu_win.cc @@ -5,9 +5,7 @@ #include "views/controls/menu/native_menu_win.h" #include "base/logging.h" -#include "base/message_loop.h" #include "base/stl_util-inl.h" -#include "base/task.h" #include "gfx/canvas_skia.h" #include "gfx/font.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -54,9 +52,7 @@ struct NativeMenuWin::ItemData { // structure we have constructed in NativeMenuWin. class NativeMenuWin::MenuHostWindow { public: - MenuHostWindow(NativeMenuWin* parent) - : parent_(parent), - ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { + MenuHostWindow(NativeMenuWin* parent) : parent_(parent) { RegisterClass(); hwnd_ = CreateWindowEx(l10n_util::GetExtendedStyles(), kWindowClassName, L"", 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL); @@ -247,10 +243,6 @@ class NativeMenuWin::MenuHostWindow { SetTextColor(dc, prev_text_color); } - void OnMenuClosed() { - parent_->model_->MenuClosed(); - } - bool ProcessWindowMessage(HWND window, UINT message, WPARAM w_param, @@ -274,12 +266,7 @@ class NativeMenuWin::MenuHostWindow { *l_result = 0; return true; case WM_EXITMENULOOP: - // WM_MENUCOMMAND comes after this message, but still in the same - // callstack. So use PostTask to guarantee that we'll tell the model - // that the menus is closed after any other notifications. - MessageLoop::current()->PostTask( - FROM_HERE, - method_factory_.NewRunnableMethod(&MenuHostWindow::OnMenuClosed)); + parent_->model_->MenuClosed(); return true; // TODO(beng): bring over owner draw from old menu system. } @@ -303,7 +290,6 @@ class NativeMenuWin::MenuHostWindow { HWND hwnd_; NativeMenuWin* parent_; - ScopedRunnableMethodFactory<MenuHostWindow> method_factory_; DISALLOW_COPY_AND_ASSIGN(MenuHostWindow); }; |