feat: add View API

This commit is contained in:
Cheng Zhao 2018-05-07 14:52:25 +09:00
parent 874af5c982
commit e058d11657
8 changed files with 108 additions and 0 deletions

View file

@ -3,7 +3,9 @@
// found in the LICENSE file.
#include "atom/browser/api/atom_api_url_request.h"
#include <string>
#include "atom/browser/api/atom_api_session.h"
#include "atom/browser/net/atom_url_request.h"
#include "atom/common/api/event_emitter_caller.h"

View file

@ -7,6 +7,7 @@
#include <array>
#include <string>
#include "atom/browser/api/event_emitter.h"
#include "atom/browser/api/trackable_object.h"
#include "base/memory/weak_ptr.h"

View file

@ -0,0 +1,54 @@
// Copyright (c) 2018 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/browser/api/atom_api_view.h"
#include "native_mate/dictionary.h"
#include "atom/common/node_includes.h"
namespace atom {
namespace api {
View::View() : view_(new views::View()) {
view_->set_owned_by_client();
}
View::~View() {}
// static
mate::WrappableBase* View::New(mate::Arguments* args) {
return new View();
}
// static
void View::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {}
} // namespace api
} // namespace atom
namespace {
using atom::api::View;
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
View::SetConstructor(isolate, base::Bind(&View::New));
mate::Dictionary constructor(isolate,
View::GetConstructor(isolate)->GetFunction());
mate::Dictionary dict(isolate, exports);
dict.Set("View", constructor);
}
} // namespace
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_view, Initialize)

View file

@ -0,0 +1,38 @@
// Copyright (c) 2018 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ATOM_BROWSER_API_ATOM_API_VIEW_H_
#define ATOM_BROWSER_API_ATOM_API_VIEW_H_
#include <memory>
#include "atom/browser/api/event_emitter.h"
#include "ui/views/view.h"
namespace atom {
namespace api {
class View : public mate::EventEmitter<View> {
public:
static mate::WrappableBase* New(mate::Arguments* args);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
protected:
View();
~View() override;
private:
std::unique_ptr<views::View> view_;
DISALLOW_COPY_AND_ASSIGN(View);
};
} // namespace api
} // namespace atom
#endif // ATOM_BROWSER_API_ATOM_API_VIEW_H_