win: Add BrowserWindow.setMenu API.
This commit is contained in:
parent
2024ae5dba
commit
5a6ff0f80d
7 changed files with 54 additions and 1 deletions
|
@ -351,6 +351,10 @@ void Menu::Initialize(v8::Handle<v8::Object> target) {
|
||||||
|
|
||||||
NODE_SET_PROTOTYPE_METHOD(t, "popup", Popup);
|
NODE_SET_PROTOTYPE_METHOD(t, "popup", Popup);
|
||||||
|
|
||||||
|
#if defined(OS_WIN)
|
||||||
|
NODE_SET_PROTOTYPE_METHOD(t, "attachToWindow", AttachToWindow);
|
||||||
|
#endif
|
||||||
|
|
||||||
target->Set(v8::String::NewSymbol("Menu"), t->GetFunction());
|
target->Set(v8::String::NewSymbol("Menu"), t->GetFunction());
|
||||||
|
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
|
|
|
@ -68,7 +68,9 @@ class Menu : public EventEmitter,
|
||||||
|
|
||||||
static v8::Handle<v8::Value> Popup(const v8::Arguments &args);
|
static v8::Handle<v8::Value> Popup(const v8::Arguments &args);
|
||||||
|
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_WIN)
|
||||||
|
static v8::Handle<v8::Value> AttachToWindow(const v8::Arguments &args);
|
||||||
|
#elif defined(OS_MACOSX)
|
||||||
static v8::Handle<v8::Value> SetApplicationMenu(const v8::Arguments &args);
|
static v8::Handle<v8::Value> SetApplicationMenu(const v8::Arguments &args);
|
||||||
static v8::Handle<v8::Value> SendActionToFirstResponder(
|
static v8::Handle<v8::Value> SendActionToFirstResponder(
|
||||||
const v8::Arguments &args);
|
const v8::Arguments &args);
|
||||||
|
|
|
@ -4,7 +4,9 @@
|
||||||
|
|
||||||
#include "browser/api/atom_api_menu_win.h"
|
#include "browser/api/atom_api_menu_win.h"
|
||||||
|
|
||||||
|
#include "browser/native_window_win.h"
|
||||||
#include "browser/ui/win/menu_2.h"
|
#include "browser/ui/win/menu_2.h"
|
||||||
|
#include "common/v8_conversions.h"
|
||||||
#include "ui/gfx/point.h"
|
#include "ui/gfx/point.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
@ -23,6 +25,23 @@ void MenuWin::Popup(NativeWindow* native_window) {
|
||||||
menu_->RunContextMenuAt(gfx::Point(0, 0));
|
menu_->RunContextMenuAt(gfx::Point(0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
v8::Handle<v8::Value> Menu::AttachToWindow(const v8::Arguments& args) {
|
||||||
|
v8::HandleScope scope;
|
||||||
|
|
||||||
|
Menu* self = ObjectWrap::Unwrap<Menu>(args.This());
|
||||||
|
if (self == NULL)
|
||||||
|
return node::ThrowError("Menu is already destroyed");
|
||||||
|
|
||||||
|
NativeWindow* native_window;
|
||||||
|
if (!FromV8Arguments(args, &native_window))
|
||||||
|
return node::ThrowTypeError("Bad argument");
|
||||||
|
|
||||||
|
static_cast<NativeWindowWin*>(native_window)->SetMenu(self->model_.get());
|
||||||
|
|
||||||
|
return v8::Undefined();
|
||||||
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
Menu* Menu::Create(v8::Handle<v8::Object> wrapper) {
|
Menu* Menu::Create(v8::Handle<v8::Object> wrapper) {
|
||||||
return new MenuWin(wrapper);
|
return new MenuWin(wrapper);
|
||||||
|
|
|
@ -17,6 +17,14 @@ BrowserWindow::toggleDevTools = ->
|
||||||
BrowserWindow::restart = ->
|
BrowserWindow::restart = ->
|
||||||
@loadUrl(@getUrl())
|
@loadUrl(@getUrl())
|
||||||
|
|
||||||
|
BrowserWindow::setMenu = (menu) ->
|
||||||
|
throw new Error('BrowserWindow.setMenu is only available on Windows') unless process.platform is 'win32'
|
||||||
|
|
||||||
|
throw new TypeError('Invalid menu') unless menu?.constructor?.name is 'Menu'
|
||||||
|
|
||||||
|
@menu = menu # Keep a reference of menu in case of GC.
|
||||||
|
@menu.attachToWindow this
|
||||||
|
|
||||||
BrowserWindow.getFocusedWindow = ->
|
BrowserWindow.getFocusedWindow = ->
|
||||||
windows = objectsRegistry.getAllWindows()
|
windows = objectsRegistry.getAllWindows()
|
||||||
return window for window in windows when window.isFocused()
|
return window for window in windows when window.isFocused()
|
||||||
|
|
|
@ -159,6 +159,8 @@ app.on('finish-launching', function() {
|
||||||
|
|
||||||
if (process.platform == 'darwin')
|
if (process.platform == 'darwin')
|
||||||
Menu.setApplicationMenu(menu);
|
Menu.setApplicationMenu(menu);
|
||||||
|
else
|
||||||
|
mainWindow.setMenu(menu);
|
||||||
|
|
||||||
ipc.on('message', function(processId, routingId, type) {
|
ipc.on('message', function(processId, routingId, type) {
|
||||||
console.log(type);
|
console.log(type);
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
#include "base/values.h"
|
#include "base/values.h"
|
||||||
|
#include "browser/ui/win/menu_2.h"
|
||||||
#include "common/draggable_region.h"
|
#include "common/draggable_region.h"
|
||||||
#include "common/options_switches.h"
|
#include "common/options_switches.h"
|
||||||
#include "content/public/browser/native_web_keyboard_event.h"
|
#include "content/public/browser/native_web_keyboard_event.h"
|
||||||
|
@ -325,6 +326,11 @@ gfx::NativeWindow NativeWindowWin::GetNativeWindow() {
|
||||||
return window_->GetNativeView();
|
return window_->GetNativeView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeWindowWin::SetMenu(ui::MenuModel* menu_model) {
|
||||||
|
menu_.reset(new atom::Menu2(menu_model, true));
|
||||||
|
::SetMenu(GetNativeWindow(), menu_->GetNativeMenu());
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindowWin::UpdateDraggableRegions(
|
void NativeWindowWin::UpdateDraggableRegions(
|
||||||
const std::vector<DraggableRegion>& regions) {
|
const std::vector<DraggableRegion>& regions) {
|
||||||
if (has_frame_)
|
if (has_frame_)
|
||||||
|
|
|
@ -12,6 +12,10 @@
|
||||||
#include "ui/gfx/size.h"
|
#include "ui/gfx/size.h"
|
||||||
#include "ui/views/widget/widget_delegate.h"
|
#include "ui/views/widget/widget_delegate.h"
|
||||||
|
|
||||||
|
namespace ui {
|
||||||
|
class MenuModel;
|
||||||
|
}
|
||||||
|
|
||||||
namespace views {
|
namespace views {
|
||||||
class WebView;
|
class WebView;
|
||||||
class Widget;
|
class Widget;
|
||||||
|
@ -19,6 +23,8 @@ class Widget;
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
class Menu2;
|
||||||
|
|
||||||
class NativeWindowWin : public NativeWindow,
|
class NativeWindowWin : public NativeWindow,
|
||||||
public views::WidgetDelegate {
|
public views::WidgetDelegate {
|
||||||
public:
|
public:
|
||||||
|
@ -60,6 +66,9 @@ class NativeWindowWin : public NativeWindow,
|
||||||
virtual bool IsKiosk() OVERRIDE;
|
virtual bool IsKiosk() OVERRIDE;
|
||||||
virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
|
virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
|
||||||
|
|
||||||
|
// Set the native window menu.
|
||||||
|
void SetMenu(ui::MenuModel* menu_model);
|
||||||
|
|
||||||
SkRegion* draggable_region() { return draggable_region_.get(); }
|
SkRegion* draggable_region() { return draggable_region_.get(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -89,6 +98,9 @@ class NativeWindowWin : public NativeWindow,
|
||||||
scoped_ptr<views::Widget> window_;
|
scoped_ptr<views::Widget> window_;
|
||||||
views::WebView* web_view_; // managed by window_.
|
views::WebView* web_view_; // managed by window_.
|
||||||
|
|
||||||
|
// The window menu.
|
||||||
|
scoped_ptr<atom::Menu2> menu_;
|
||||||
|
|
||||||
scoped_ptr<SkRegion> draggable_region_;
|
scoped_ptr<SkRegion> draggable_region_;
|
||||||
|
|
||||||
bool resizable_;
|
bool resizable_;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue