refactor: rename the atom directory to shell

This commit is contained in:
Samuel Attard 2019-06-19 13:43:10 -07:00 committed by Samuel Attard
parent 4575a4aae3
commit d7f07e8a80
631 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,86 @@
// 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/views/atom_api_box_layout.h"
#include <string>
#include "atom/browser/api/atom_api_view.h"
#include "atom/common/api/constructor.h"
#include "atom/common/node_includes.h"
#include "native_mate/dictionary.h"
namespace mate {
template <>
struct Converter<views::BoxLayout::Orientation> {
static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val,
views::BoxLayout::Orientation* out) {
std::string orientation;
if (!ConvertFromV8(isolate, val, &orientation))
return false;
if (orientation == "horizontal")
*out = views::BoxLayout::kHorizontal;
else if (orientation == "vertical")
*out = views::BoxLayout::kVertical;
else
return false;
return true;
}
};
} // namespace mate
namespace atom {
namespace api {
BoxLayout::BoxLayout(views::BoxLayout::Orientation orientation)
: LayoutManager(new views::BoxLayout(orientation)) {}
BoxLayout::~BoxLayout() {}
void BoxLayout::SetFlexForView(mate::Handle<View> view, int flex) {
auto* box_layout = static_cast<views::BoxLayout*>(layout_manager());
box_layout->SetFlexForView(view->view(), flex);
}
// static
mate::WrappableBase* BoxLayout::New(mate::Arguments* args,
views::BoxLayout::Orientation orientation) {
auto* layout = new BoxLayout(orientation);
layout->InitWith(args->isolate(), args->GetThis());
return layout;
}
// static
void BoxLayout::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "BoxLayout"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("setFlexForView", &BoxLayout::SetFlexForView);
}
} // namespace api
} // namespace atom
namespace {
using atom::api::BoxLayout;
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
dict.Set("BoxLayout", mate::CreateConstructor<BoxLayout>(
isolate, base::BindRepeating(&BoxLayout::New)));
}
} // namespace
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_box_layout, Initialize)

View file

@ -0,0 +1,40 @@
// 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_VIEWS_ATOM_API_BOX_LAYOUT_H_
#define ATOM_BROWSER_API_VIEWS_ATOM_API_BOX_LAYOUT_H_
#include "atom/browser/api/views/atom_api_layout_manager.h"
#include "native_mate/handle.h"
#include "ui/views/layout/box_layout.h"
namespace atom {
namespace api {
class View;
class BoxLayout : public LayoutManager {
public:
static mate::WrappableBase* New(mate::Arguments* args,
views::BoxLayout::Orientation orientation);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
void SetFlexForView(mate::Handle<View> view, int flex);
protected:
explicit BoxLayout(views::BoxLayout::Orientation orientation);
~BoxLayout() override;
private:
DISALLOW_COPY_AND_ASSIGN(BoxLayout);
};
} // namespace api
} // namespace atom
#endif // ATOM_BROWSER_API_VIEWS_ATOM_API_BOX_LAYOUT_H_

View file

@ -0,0 +1,59 @@
// 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/views/atom_api_button.h"
#include "atom/common/api/constructor.h"
#include "atom/common/node_includes.h"
#include "native_mate/dictionary.h"
namespace atom {
namespace api {
Button::Button(views::Button* impl) : View(impl) {
view()->set_owned_by_client();
// Make the button focusable as per the platform.
button()->SetFocusForPlatform();
}
Button::~Button() {}
void Button::ButtonPressed(views::Button* sender, const ui::Event& event) {
Emit("click");
}
// static
mate::WrappableBase* Button::New(mate::Arguments* args) {
args->ThrowError("Button can not be created directly");
return nullptr;
}
// static
void Button::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "Button"));
}
} // namespace api
} // namespace atom
namespace {
using atom::api::Button;
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
dict.Set("Button", mate::CreateConstructor<Button>(
isolate, base::BindRepeating(&Button::New)));
}
} // namespace
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_button, Initialize)

View file

@ -0,0 +1,40 @@
// 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_VIEWS_ATOM_API_BUTTON_H_
#define ATOM_BROWSER_API_VIEWS_ATOM_API_BUTTON_H_
#include "atom/browser/api/atom_api_view.h"
#include "native_mate/handle.h"
#include "ui/views/controls/button/button.h"
namespace atom {
namespace api {
class Button : public View, public views::ButtonListener {
public:
static mate::WrappableBase* New(mate::Arguments* args);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
protected:
explicit Button(views::Button* view);
~Button() override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
views::Button* button() const { return static_cast<views::Button*>(view()); }
private:
DISALLOW_COPY_AND_ASSIGN(Button);
};
} // namespace api
} // namespace atom
#endif // ATOM_BROWSER_API_VIEWS_ATOM_API_BUTTON_H_

View file

@ -0,0 +1,79 @@
// 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/views/atom_api_label_button.h"
#include "atom/common/api/constructor.h"
#include "atom/common/node_includes.h"
#include "base/strings/utf_string_conversions.h"
#include "native_mate/dictionary.h"
namespace atom {
namespace api {
LabelButton::LabelButton(views::LabelButton* impl) : Button(impl) {}
LabelButton::LabelButton(const std::string& text)
: Button(new views::LabelButton(this, base::UTF8ToUTF16(text))) {}
LabelButton::~LabelButton() {}
const base::string16& LabelButton::GetText() const {
return label_button()->GetText();
}
void LabelButton::SetText(const base::string16& text) {
label_button()->SetText(text);
}
bool LabelButton::IsDefault() const {
return label_button()->is_default();
}
void LabelButton::SetIsDefault(bool is_default) {
label_button()->SetIsDefault(is_default);
}
// static
mate::WrappableBase* LabelButton::New(mate::Arguments* args,
const std::string& text) {
// Constructor call.
auto* view = new LabelButton(text);
view->InitWith(args->isolate(), args->GetThis());
return view;
}
// static
void LabelButton::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "LabelButton"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("getText", &LabelButton::GetText)
.SetMethod("setText", &LabelButton::SetText)
.SetMethod("isDefault", &LabelButton::IsDefault)
.SetMethod("setIsDefault", &LabelButton::SetIsDefault);
}
} // namespace api
} // namespace atom
namespace {
using atom::api::LabelButton;
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
dict.Set("LabelButton", mate::CreateConstructor<LabelButton>(
isolate, base::BindRepeating(&LabelButton::New)));
}
} // namespace
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_label_button, Initialize)

View file

@ -0,0 +1,47 @@
// 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_VIEWS_ATOM_API_LABEL_BUTTON_H_
#define ATOM_BROWSER_API_VIEWS_ATOM_API_LABEL_BUTTON_H_
#include <string>
#include "atom/browser/api/views/atom_api_button.h"
#include "ui/views/controls/button/label_button.h"
namespace atom {
namespace api {
class LabelButton : public Button {
public:
static mate::WrappableBase* New(mate::Arguments* args,
const std::string& text);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
const base::string16& GetText() const;
void SetText(const base::string16& text);
bool IsDefault() const;
void SetIsDefault(bool is_default);
protected:
explicit LabelButton(views::LabelButton* impl);
explicit LabelButton(const std::string& text);
~LabelButton() override;
views::LabelButton* label_button() const {
return static_cast<views::LabelButton*>(view());
}
private:
DISALLOW_COPY_AND_ASSIGN(LabelButton);
};
} // namespace api
} // namespace atom
#endif // ATOM_BROWSER_API_VIEWS_ATOM_API_LABEL_BUTTON_H_

View file

@ -0,0 +1,63 @@
// 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/views/atom_api_layout_manager.h"
#include "atom/common/api/constructor.h"
#include "atom/common/node_includes.h"
#include "native_mate/dictionary.h"
namespace atom {
namespace api {
LayoutManager::LayoutManager(views::LayoutManager* layout_manager)
: layout_manager_(layout_manager) {
DCHECK(layout_manager_);
}
LayoutManager::~LayoutManager() {
if (managed_by_us_)
delete layout_manager_;
}
std::unique_ptr<views::LayoutManager> LayoutManager::TakeOver() {
if (!managed_by_us_) // already taken over.
return nullptr;
managed_by_us_ = false;
return std::unique_ptr<views::LayoutManager>(layout_manager_);
}
// static
mate::WrappableBase* LayoutManager::New(mate::Arguments* args) {
args->ThrowError("LayoutManager can not be created directly");
return nullptr;
}
// static
void LayoutManager::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {}
} // namespace api
} // namespace atom
namespace {
using atom::api::LayoutManager;
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
dict.Set("LayoutManager",
mate::CreateConstructor<LayoutManager>(
isolate, base::BindRepeating(&LayoutManager::New)));
}
} // namespace
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_layout_manager, Initialize)

View file

@ -0,0 +1,44 @@
// 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_VIEWS_ATOM_API_LAYOUT_MANAGER_H_
#define ATOM_BROWSER_API_VIEWS_ATOM_API_LAYOUT_MANAGER_H_
#include <memory>
#include "atom/browser/api/trackable_object.h"
#include "ui/views/layout/layout_manager.h"
namespace atom {
namespace api {
class LayoutManager : public mate::TrackableObject<LayoutManager> {
public:
static mate::WrappableBase* New(mate::Arguments* args);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
// Take over the ownership of the LayoutManager, and leave weak ref here.
std::unique_ptr<views::LayoutManager> TakeOver();
views::LayoutManager* layout_manager() const { return layout_manager_; }
protected:
explicit LayoutManager(views::LayoutManager* layout_manager);
~LayoutManager() override;
private:
bool managed_by_us_ = true;
views::LayoutManager* layout_manager_;
DISALLOW_COPY_AND_ASSIGN(LayoutManager);
};
} // namespace api
} // namespace atom
#endif // ATOM_BROWSER_API_VIEWS_ATOM_API_LAYOUT_MANAGER_H_

View file

@ -0,0 +1,57 @@
// 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/views/atom_api_md_text_button.h"
#include "atom/common/api/constructor.h"
#include "atom/common/node_includes.h"
#include "base/strings/utf_string_conversions.h"
#include "native_mate/dictionary.h"
namespace atom {
namespace api {
MdTextButton::MdTextButton(const std::string& text)
: LabelButton(views::MdTextButton::Create(this, base::UTF8ToUTF16(text))) {}
MdTextButton::~MdTextButton() {}
// static
mate::WrappableBase* MdTextButton::New(mate::Arguments* args,
const std::string& text) {
// Constructor call.
auto* view = new MdTextButton(text);
view->InitWith(args->isolate(), args->GetThis());
return view;
}
// static
void MdTextButton::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "MdTextButton"));
}
} // namespace api
} // namespace atom
namespace {
using atom::api::MdTextButton;
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
dict.Set("MdTextButton",
mate::CreateConstructor<MdTextButton>(
isolate, base::BindRepeating(&MdTextButton::New)));
}
} // namespace
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_md_text_button, Initialize)

View file

@ -0,0 +1,41 @@
// 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_VIEWS_ATOM_API_MD_TEXT_BUTTON_H_
#define ATOM_BROWSER_API_VIEWS_ATOM_API_MD_TEXT_BUTTON_H_
#include <string>
#include "atom/browser/api/views/atom_api_label_button.h"
#include "ui/views/controls/button/md_text_button.h"
namespace atom {
namespace api {
class MdTextButton : public LabelButton {
public:
static mate::WrappableBase* New(mate::Arguments* args,
const std::string& text);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
protected:
explicit MdTextButton(const std::string& text);
~MdTextButton() override;
views::MdTextButton* md_text_button() const {
return static_cast<views::MdTextButton*>(view());
}
private:
DISALLOW_COPY_AND_ASSIGN(MdTextButton);
};
} // namespace api
} // namespace atom
#endif // ATOM_BROWSER_API_VIEWS_ATOM_API_MD_TEXT_BUTTON_H_

View file

@ -0,0 +1,59 @@
// 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/views/atom_api_resize_area.h"
#include "atom/common/api/constructor.h"
#include "atom/common/node_includes.h"
#include "native_mate/dictionary.h"
namespace atom {
namespace api {
ResizeArea::ResizeArea() : View(new views::ResizeArea(this)) {
view()->set_owned_by_client();
}
ResizeArea::~ResizeArea() {}
void ResizeArea::OnResize(int resize_amount, bool done_resizing) {
Emit("resize", resize_amount, done_resizing);
}
// static
mate::WrappableBase* ResizeArea::New(mate::Arguments* args) {
// Constructor call.
auto* view = new ResizeArea();
view->InitWith(args->isolate(), args->GetThis());
return view;
}
// static
void ResizeArea::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "ResizeArea"));
}
} // namespace api
} // namespace atom
namespace {
using atom::api::ResizeArea;
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
dict.Set("ResizeArea", mate::CreateConstructor<ResizeArea>(
isolate, base::BindRepeating(&ResizeArea::New)));
}
} // namespace
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_resize_area, Initialize)

View file

@ -0,0 +1,43 @@
// 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_VIEWS_ATOM_API_RESIZE_AREA_H_
#define ATOM_BROWSER_API_VIEWS_ATOM_API_RESIZE_AREA_H_
#include "atom/browser/api/atom_api_view.h"
#include "native_mate/handle.h"
#include "ui/views/controls/resize_area.h"
#include "ui/views/controls/resize_area_delegate.h"
namespace atom {
namespace api {
class ResizeArea : public View, protected views::ResizeAreaDelegate {
public:
static mate::WrappableBase* New(mate::Arguments* args);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
protected:
void OnResize(int resize_amount, bool done_resizing) override;
private:
ResizeArea();
~ResizeArea() override;
views::ResizeArea* resize_area() const {
return static_cast<views::ResizeArea*>(view());
}
private:
DISALLOW_COPY_AND_ASSIGN(ResizeArea);
};
} // namespace api
} // namespace atom
#endif // ATOM_BROWSER_API_VIEWS_ATOM_API_RESIZE_AREA_H_

View file

@ -0,0 +1,66 @@
// 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/views/atom_api_text_field.h"
#include "atom/common/api/constructor.h"
#include "atom/common/node_includes.h"
#include "native_mate/dictionary.h"
namespace atom {
namespace api {
TextField::TextField() : View(new views::Textfield()) {
view()->set_owned_by_client();
}
TextField::~TextField() {}
void TextField::SetText(const base::string16& new_text) {
text_field()->SetText(new_text);
}
base::string16 TextField::GetText() const {
return text_field()->text();
}
// static
mate::WrappableBase* TextField::New(mate::Arguments* args) {
// Constructor call.
auto* view = new TextField();
view->InitWith(args->isolate(), args->GetThis());
return view;
}
// static
void TextField::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(mate::StringToV8(isolate, "TextField"));
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("setText", &TextField::SetText)
.SetMethod("getText", &TextField::GetText);
}
} // namespace api
} // namespace atom
namespace {
using atom::api::TextField;
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
mate::Dictionary dict(isolate, exports);
dict.Set("TextField", mate::CreateConstructor<TextField>(
isolate, base::BindRepeating(&TextField::New)));
}
} // namespace
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_text_field, Initialize)

View file

@ -0,0 +1,42 @@
// 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_VIEWS_ATOM_API_TEXT_FIELD_H_
#define ATOM_BROWSER_API_VIEWS_ATOM_API_TEXT_FIELD_H_
#include "atom/browser/api/atom_api_view.h"
#include "native_mate/handle.h"
#include "ui/views/controls/textfield/textfield.h"
namespace atom {
namespace api {
class TextField : public View {
public:
static mate::WrappableBase* New(mate::Arguments* args);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
void SetText(const base::string16& new_text);
base::string16 GetText() const;
private:
TextField();
~TextField() override;
views::Textfield* text_field() const {
return static_cast<views::Textfield*>(view());
}
private:
DISALLOW_COPY_AND_ASSIGN(TextField);
};
} // namespace api
} // namespace atom
#endif // ATOM_BROWSER_API_VIEWS_ATOM_API_TEXT_FIELD_H_