This commit is contained in:
Cheng Zhao 2013-05-06 20:27:09 +08:00
Родитель 5915591592
Коммит 7cc04035c4
6 изменённых файлов: 174 добавлений и 0 удалений

Просмотреть файл

@ -35,6 +35,10 @@
'browser/api/atom_api_event.h',
'browser/api/atom_api_event_emitter.cc',
'browser/api/atom_api_event_emitter.h',
'browser/api/atom_api_menu.cc',
'browser/api/atom_api_menu.h',
'browser/api/atom_api_menu_mac.h',
'browser/api/atom_api_menu_mac.mm',
'browser/api/atom_api_window.cc',
'browser/api/atom_api_window.h',
'browser/api/atom_browser_bindings.cc',

Просмотреть файл

@ -0,0 +1,62 @@
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "browser/api/atom_api_menu.h"
namespace atom {
namespace api {
Menu::Menu(v8::Handle<v8::Object> wrapper)
: EventEmitter(wrapper),
model_(new ui::SimpleMenuModel(this)) {
}
Menu::~Menu() {
}
bool Menu::IsCommandIdChecked(int command_id) const {
return false;
}
bool Menu::IsCommandIdEnabled(int command_id) const {
return true;
}
bool Menu::GetAcceleratorForCommandId(int command_id,
ui::Accelerator* accelerator) {
return false;
}
void Menu::ExecuteCommand(int command_id, int event_flags) {
}
// static
v8::Handle<v8::Value> Menu::New(const v8::Arguments &args) {
v8::HandleScope scope;
if (!args.IsConstructCall())
return node::ThrowError("Require constructor call");
Menu::Create(args.This());
return args.This();
}
// static
void Menu::Initialize(v8::Handle<v8::Object> target) {
v8::HandleScope scope;
v8::Local<v8::FunctionTemplate> t(v8::FunctionTemplate::New(Menu::New));
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(v8::String::NewSymbol("Menu"));
target->Set(v8::String::NewSymbol("Menu"), t->GetFunction());
}
} // namespace api
} // namespace atom
NODE_MODULE(atom_browser_menu, atom::api::Menu::Initialize)

Просмотреть файл

@ -0,0 +1,48 @@
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ATOM_BROWSER_API_ATOM_API_MENU_H_
#define ATOM_BROWSER_API_ATOM_API_MENU_H_
#include "base/memory/scoped_ptr.h"
#include "browser/api/atom_api_event_emitter.h"
#include "ui/base/models/simple_menu_model.h"
namespace atom {
namespace api {
class Menu : public EventEmitter,
public ui::SimpleMenuModel::Delegate {
public:
virtual ~Menu();
static Menu* Create(v8::Handle<v8::Object> wrapper);
static void Initialize(v8::Handle<v8::Object> target);
protected:
explicit Menu(v8::Handle<v8::Object> wrapper);
// ui::SimpleMenuModel::Delegate implementations:
virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
virtual bool GetAcceleratorForCommandId(
int command_id,
ui::Accelerator* accelerator) OVERRIDE;
virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
scoped_ptr<ui::SimpleMenuModel> model_;
private:
static v8::Handle<v8::Value> New(const v8::Arguments &args);
DISALLOW_COPY_AND_ASSIGN(Menu);
};
} // namespace api
} // namespace atom
#endif // ATOM_BROWSER_API_ATOM_API_MENU_H_

Просмотреть файл

@ -0,0 +1,32 @@
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ATOM_BROWSER_API_ATOM_API_MENU_MAC_H_
#define ATOM_BROWSER_API_ATOM_API_MENU_MAC_H_
#include "browser/api/atom_api_menu.h"
#import "chrome/browser/ui/cocoa/menu_controller.h"
namespace atom {
namespace api {
class MenuMac : public Menu {
public:
explicit MenuMac(v8::Handle<v8::Object> wrapper);
virtual ~MenuMac();
protected:
scoped_nsobject<MenuController> controller_;
private:
DISALLOW_COPY_AND_ASSIGN(MenuMac);
};
} // namespace api
} // namespace atom
#endif // ATOM_BROWSER_API_ATOM_API_MENU_MAC_H_

Просмотреть файл

@ -0,0 +1,27 @@
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "browser/api/atom_api_menu_mac.h"
namespace atom {
namespace api {
MenuMac::MenuMac(v8::Handle<v8::Object> wrapper)
: Menu(wrapper),
controller_([[MenuController alloc] initWithModel:model_.get()
useWithPopUpButtonCell:NO]) {
}
MenuMac::~MenuMac() {
}
// static
Menu* Menu::Create(v8::Handle<v8::Object> wrapper) {
return new MenuMac(wrapper);
}
} // namespace api
} // namespace atom

Просмотреть файл

@ -12,6 +12,7 @@ NODE_EXT_LIST_START
NODE_EXT_LIST_ITEM(atom_browser_app)
NODE_EXT_LIST_ITEM(atom_browser_dialog)
NODE_EXT_LIST_ITEM(atom_browser_ipc)
NODE_EXT_LIST_ITEM(atom_browser_menu)
NODE_EXT_LIST_ITEM(atom_browser_window)
// Module names start with `atom_renderer_` can only be used by renderer