Implement Menu.closePopup on Windows/Linux

This commit is contained in:
Kevin Sawicki 2017-02-16 11:04:42 -08:00
parent 0a5ccdccb4
commit 91d1af053f
2 changed files with 10 additions and 11 deletions

View file

@ -49,11 +49,12 @@ void MenuViews::PopupAt(
atom::UnresponsiveSuppressor suppressor; atom::UnresponsiveSuppressor suppressor;
// Show the menu. // Show the menu.
menu_runner_.reset(new MenuRunner( int32_t window_id = window->ID();
model(), auto close_callback = base::Bind(
flags, &MenuViews::ClosePopupAt, weak_factory_.GetWeakPtr(), window_id);
base::Bind(&MenuViews::OnMenuClosed, weak_factory_.GetWeakPtr()))); menu_runners_[window_id] = std::unique_ptr<MenuRunner>(new MenuRunner(
ignore_result(menu_runner_->RunMenuAt( model(), flags, close_callback));
ignore_result(menu_runners_[window_id]->RunMenuAt(
static_cast<NativeWindowViews*>(window->window())->widget(), static_cast<NativeWindowViews*>(window->window())->widget(),
NULL, NULL,
gfx::Rect(location, gfx::Size()), gfx::Rect(location, gfx::Size()),
@ -61,10 +62,6 @@ void MenuViews::PopupAt(
ui::MENU_SOURCE_MOUSE)); ui::MENU_SOURCE_MOUSE));
} }
void MenuViews::OnMenuClosed() {
menu_runner_.reset();
}
// static // static
mate::WrappableBase* Menu::New(mate::Arguments* args) { mate::WrappableBase* Menu::New(mate::Arguments* args) {
return new MenuViews(args->isolate(), args->GetThis()); return new MenuViews(args->isolate(), args->GetThis());

View file

@ -5,6 +5,8 @@
#ifndef ATOM_BROWSER_API_ATOM_API_MENU_VIEWS_H_ #ifndef ATOM_BROWSER_API_ATOM_API_MENU_VIEWS_H_
#define ATOM_BROWSER_API_ATOM_API_MENU_VIEWS_H_ #define ATOM_BROWSER_API_ATOM_API_MENU_VIEWS_H_
#include <map>
#include "atom/browser/api/atom_api_menu.h" #include "atom/browser/api/atom_api_menu.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
@ -21,10 +23,10 @@ class MenuViews : public Menu {
protected: protected:
void PopupAt( void PopupAt(
Window* window, int x, int y, int positioning_item, bool async) override; Window* window, int x, int y, int positioning_item, bool async) override;
void OnMenuClosed(); void ClosePopupAt(int32_t window_id);
private: private:
std::unique_ptr<views::MenuRunner> menu_runner_; std::map<int32_t, std::unique_ptr<views::MenuRunner>> menu_runners_;
base::WeakPtrFactory<MenuViews> weak_factory_; base::WeakPtrFactory<MenuViews> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(MenuViews); DISALLOW_COPY_AND_ASSIGN(MenuViews);