Add async menu.popup on Windows/Linux
This commit is contained in:
parent
636ef0fd29
commit
b091d104f5
2 changed files with 18 additions and 5 deletions
|
@ -8,14 +8,16 @@
|
||||||
#include "atom/browser/unresponsive_suppressor.h"
|
#include "atom/browser/unresponsive_suppressor.h"
|
||||||
#include "content/public/browser/render_widget_host_view.h"
|
#include "content/public/browser/render_widget_host_view.h"
|
||||||
#include "ui/display/screen.h"
|
#include "ui/display/screen.h"
|
||||||
#include "ui/views/controls/menu/menu_runner.h"
|
|
||||||
|
using views::MenuRunner;
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
namespace api {
|
namespace api {
|
||||||
|
|
||||||
MenuViews::MenuViews(v8::Isolate* isolate, v8::Local<v8::Object> wrapper)
|
MenuViews::MenuViews(v8::Isolate* isolate, v8::Local<v8::Object> wrapper)
|
||||||
: Menu(isolate, wrapper) {
|
: Menu(isolate, wrapper),
|
||||||
|
weak_factory_(this) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuViews::PopupAt(Window* window, int x, int y, int positioning_item) {
|
void MenuViews::PopupAt(Window* window, int x, int y, int positioning_item) {
|
||||||
|
@ -42,10 +44,11 @@ void MenuViews::PopupAt(Window* window, int x, int y, int positioning_item) {
|
||||||
atom::UnresponsiveSuppressor suppressor;
|
atom::UnresponsiveSuppressor suppressor;
|
||||||
|
|
||||||
// Show the menu.
|
// Show the menu.
|
||||||
views::MenuRunner menu_runner(
|
menu_runner_.reset(new MenuRunner(
|
||||||
model(),
|
model(),
|
||||||
views::MenuRunner::CONTEXT_MENU | views::MenuRunner::HAS_MNEMONICS);
|
MenuRunner::CONTEXT_MENU | MenuRunner::HAS_MNEMONICS | MenuRunner::ASYNC,
|
||||||
ignore_result(menu_runner.RunMenuAt(
|
base::Bind(&MenuViews::OnMenuClosed, weak_factory_.GetWeakPtr())));
|
||||||
|
ignore_result(menu_runner_->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()),
|
||||||
|
@ -53,6 +56,10 @@ void MenuViews::PopupAt(Window* window, int x, int y, int positioning_item) {
|
||||||
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());
|
||||||
|
|
|
@ -6,7 +6,9 @@
|
||||||
#define ATOM_BROWSER_API_ATOM_API_MENU_VIEWS_H_
|
#define ATOM_BROWSER_API_ATOM_API_MENU_VIEWS_H_
|
||||||
|
|
||||||
#include "atom/browser/api/atom_api_menu.h"
|
#include "atom/browser/api/atom_api_menu.h"
|
||||||
|
#include "base/memory/weak_ptr.h"
|
||||||
#include "ui/display/screen.h"
|
#include "ui/display/screen.h"
|
||||||
|
#include "ui/views/controls/menu/menu_runner.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
@ -18,8 +20,12 @@ class MenuViews : public Menu {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void PopupAt(Window* window, int x, int y, int positioning_item) override;
|
void PopupAt(Window* window, int x, int y, int positioning_item) override;
|
||||||
|
void OnMenuClosed();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::unique_ptr<views::MenuRunner> menu_runner_;
|
||||||
|
base::WeakPtrFactory<MenuViews> weak_factory_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(MenuViews);
|
DISALLOW_COPY_AND_ASSIGN(MenuViews);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue