chore: remove unused classes of views API (#22861)

* chore: remove unused views API classes

* chore: remove LayoutManager code

* chore: no more need to make View inherit from TrackabeObject

* chore: make enable_view_api default to true

* chore: enable_view_api => enable_views_api
This commit is contained in:
Cheng Zhao 2020-03-28 15:44:57 +09:00 committed by GitHub
parent d5cae424d8
commit 76ae3b7ecb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 16 additions and 948 deletions

View file

@ -600,24 +600,10 @@ source_set("electron_lib") {
] ]
} }
if (enable_view_api) { if (enable_views_api) {
sources += [ sources += [
"shell/browser/api/views/electron_api_box_layout.cc",
"shell/browser/api/views/electron_api_box_layout.h",
"shell/browser/api/views/electron_api_button.cc",
"shell/browser/api/views/electron_api_button.h",
"shell/browser/api/views/electron_api_image_view.cc", "shell/browser/api/views/electron_api_image_view.cc",
"shell/browser/api/views/electron_api_image_view.h", "shell/browser/api/views/electron_api_image_view.h",
"shell/browser/api/views/electron_api_label_button.cc",
"shell/browser/api/views/electron_api_label_button.h",
"shell/browser/api/views/electron_api_layout_manager.cc",
"shell/browser/api/views/electron_api_layout_manager.h",
"shell/browser/api/views/electron_api_md_text_button.cc",
"shell/browser/api/views/electron_api_md_text_button.h",
"shell/browser/api/views/electron_api_resize_area.cc",
"shell/browser/api/views/electron_api_resize_area.h",
"shell/browser/api/views/electron_api_text_field.cc",
"shell/browser/api/views/electron_api_text_field.h",
] ]
} }

View file

@ -13,7 +13,7 @@ buildflag_header("buildflags") {
"ENABLE_RUN_AS_NODE=$enable_run_as_node", "ENABLE_RUN_AS_NODE=$enable_run_as_node",
"ENABLE_OSR=$enable_osr", "ENABLE_OSR=$enable_osr",
"ENABLE_REMOTE_MODULE=$enable_remote_module", "ENABLE_REMOTE_MODULE=$enable_remote_module",
"ENABLE_VIEW_API=$enable_view_api", "ENABLE_VIEWS_API=$enable_views_api",
"ENABLE_PEPPER_FLASH=$enable_pepper_flash", "ENABLE_PEPPER_FLASH=$enable_pepper_flash",
"ENABLE_PDF_VIEWER=$enable_pdf_viewer", "ENABLE_PDF_VIEWER=$enable_pdf_viewer",
"ENABLE_TTS=$enable_tts", "ENABLE_TTS=$enable_tts",

View file

@ -12,7 +12,7 @@ declare_args() {
enable_remote_module = true enable_remote_module = true
enable_view_api = false enable_views_api = true
enable_pdf_viewer = true enable_pdf_viewer = true

View file

@ -244,14 +244,7 @@ auto_filenames = {
"lib/browser/api/touch-bar.js", "lib/browser/api/touch-bar.js",
"lib/browser/api/tray.js", "lib/browser/api/tray.js",
"lib/browser/api/view.js", "lib/browser/api/view.js",
"lib/browser/api/views/box-layout.js",
"lib/browser/api/views/button.js",
"lib/browser/api/views/image-view.js", "lib/browser/api/views/image-view.js",
"lib/browser/api/views/label-button.js",
"lib/browser/api/views/layout-manager.js",
"lib/browser/api/views/md-text-button.js",
"lib/browser/api/views/resize-area.js",
"lib/browser/api/views/text-field.js",
"lib/browser/api/web-contents-view.js", "lib/browser/api/web-contents-view.js",
"lib/browser/api/web-contents.js", "lib/browser/api/web-contents.js",
"lib/browser/chrome-extension-shim.js", "lib/browser/chrome-extension-shim.js",

View file

@ -42,12 +42,6 @@ module.exports = [
if (features.isViewApiEnabled()) { if (features.isViewApiEnabled()) {
module.exports.push( module.exports.push(
{ name: 'BoxLayout' }, { name: 'ImageView' }
{ name: 'Button' },
{ name: 'LabelButton' },
{ name: 'LayoutManager' },
{ name: 'MdTextButton' },
{ name: 'ResizeArea' },
{ name: 'TextField' }
); );
} }

View file

@ -37,13 +37,6 @@ export const browserModuleList: ElectronInternal.ModuleEntry[] = [
if (features.isViewApiEnabled()) { if (features.isViewApiEnabled()) {
browserModuleList.push( browserModuleList.push(
{ name: 'BoxLayout', loader: () => require('./views/box-layout') }, { name: 'ImageView', loader: () => require('./views/image-view') }
{ name: 'Button', loader: () => require('./views/button') },
{ name: 'ImageView', loader: () => require('./views/image-view') },
{ name: 'LabelButton', loader: () => require('./views/label-button') },
{ name: 'LayoutManager', loader: () => require('./views/layout-manager') },
{ name: 'MdTextButton', loader: () => require('./views/md-text-button') },
{ name: 'ResizeArea', loader: () => require('./views/resize-area') },
{ name: 'TextField', loader: () => require('./views/text-field') }
); );
} }

View file

@ -1,15 +0,0 @@
'use strict';
const electron = require('electron');
const { LayoutManager } = electron;
const { BoxLayout } = process.electronBinding('box_layout');
Object.setPrototypeOf(BoxLayout.prototype, LayoutManager.prototype);
BoxLayout.prototype._init = function () {
// Call parent class's _init.
LayoutManager.prototype._init.call(this);
};
module.exports = BoxLayout;

View file

@ -1,15 +0,0 @@
'use strict';
const electron = require('electron');
const { View } = electron;
const { Button } = process.electronBinding('button');
Object.setPrototypeOf(Button.prototype, View.prototype);
Button.prototype._init = function () {
// Call parent class's _init.
View.prototype._init.call(this);
};
module.exports = Button;

View file

@ -1,15 +0,0 @@
'use strict';
const electron = require('electron');
const { Button } = electron;
const { LabelButton } = process.electronBinding('label_button');
Object.setPrototypeOf(LabelButton.prototype, Button.prototype);
LabelButton.prototype._init = function () {
// Call parent class's _init.
Button.prototype._init.call(this);
};
module.exports = LabelButton;

View file

@ -1,8 +0,0 @@
'use strict';
const { LayoutManager } = process.electronBinding('layout_manager');
LayoutManager.prototype._init = function () {
};
module.exports = LayoutManager;

View file

@ -1,15 +0,0 @@
'use strict';
const electron = require('electron');
const { LabelButton } = electron;
const { MdTextButton } = process.electronBinding('md_text_button');
Object.setPrototypeOf(MdTextButton.prototype, LabelButton.prototype);
MdTextButton.prototype._init = function () {
// Call parent class's _init.
LabelButton.prototype._init.call(this);
};
module.exports = MdTextButton;

View file

@ -1,15 +0,0 @@
'use strict';
const electron = require('electron');
const { View } = electron;
const { ResizeArea } = process.electronBinding('resize_area');
Object.setPrototypeOf(ResizeArea.prototype, View.prototype);
ResizeArea.prototype._init = function () {
// Call parent class's _init.
View.prototype._init.call(this);
};
module.exports = ResizeArea;

View file

@ -1,15 +0,0 @@
'use strict';
const electron = require('electron');
const { View } = electron;
const { TextField } = process.electronBinding('text_field');
Object.setPrototypeOf(TextField.prototype, View.prototype);
TextField.prototype._init = function () {
// Call parent class's _init.
View.prototype._init.call(this);
};
module.exports = TextField;

View file

@ -23,12 +23,7 @@ View::~View() {
delete view_; delete view_;
} }
#if BUILDFLAG(ENABLE_VIEW_API) #if BUILDFLAG(ENABLE_VIEWS_API)
void View::SetLayoutManager(gin::Handle<LayoutManager> layout_manager) {
layout_manager_.Reset(isolate(), layout_manager->GetWrapper());
view()->SetLayoutManager(layout_manager->TakeOver());
}
void View::AddChildView(gin::Handle<View> child) { void View::AddChildView(gin::Handle<View> child) {
AddChildViewAt(child, child_views_.size()); AddChildViewAt(child, child_views_.size());
} }
@ -53,9 +48,8 @@ gin_helper::WrappableBase* View::New(gin::Arguments* args) {
void View::BuildPrototype(v8::Isolate* isolate, void View::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) { v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(gin::StringToV8(isolate, "View")); prototype->SetClassName(gin::StringToV8(isolate, "View"));
#if BUILDFLAG(ENABLE_VIEW_API) #if BUILDFLAG(ENABLE_VIEWS_API)
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("setLayoutManager", &View::SetLayoutManager)
.SetMethod("addChildView", &View::AddChildView) .SetMethod("addChildView", &View::AddChildView)
.SetMethod("addChildViewAt", &View::AddChildViewAt); .SetMethod("addChildViewAt", &View::AddChildViewAt);
#endif #endif

View file

@ -10,22 +10,21 @@
#include "electron/buildflags/buildflags.h" #include "electron/buildflags/buildflags.h"
#include "gin/handle.h" #include "gin/handle.h"
#include "shell/browser/api/views/electron_api_layout_manager.h" #include "shell/common/gin_helper/wrappable.h"
#include "ui/views/view.h" #include "ui/views/view.h"
namespace electron { namespace electron {
namespace api { namespace api {
class View : public gin_helper::TrackableObject<View> { class View : public gin_helper::Wrappable<View> {
public: public:
static gin_helper::WrappableBase* New(gin::Arguments* args); static gin_helper::WrappableBase* New(gin::Arguments* args);
static void BuildPrototype(v8::Isolate* isolate, static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype); v8::Local<v8::FunctionTemplate> prototype);
#if BUILDFLAG(ENABLE_VIEW_API) #if BUILDFLAG(ENABLE_VIEWS_API)
void SetLayoutManager(gin::Handle<LayoutManager> layout_manager);
void AddChildView(gin::Handle<View> view); void AddChildView(gin::Handle<View> view);
void AddChildViewAt(gin::Handle<View> view, size_t index); void AddChildViewAt(gin::Handle<View> view, size_t index);
#endif #endif
@ -41,7 +40,6 @@ class View : public gin_helper::TrackableObject<View> {
void set_delete_view(bool should) { delete_view_ = should; } void set_delete_view(bool should) { delete_view_ = should; }
private: private:
v8::Global<v8::Object> layout_manager_;
std::vector<v8::Global<v8::Object>> child_views_; std::vector<v8::Global<v8::Object>> child_views_;
bool delete_view_ = true; bool delete_view_ = true;
@ -54,21 +52,4 @@ class View : public gin_helper::TrackableObject<View> {
} // namespace electron } // namespace electron
namespace gin {
template <>
struct Converter<views::View*> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
views::View** out) {
electron::api::View* view;
if (!Converter<electron::api::View*>::FromV8(isolate, val, &view))
return false;
*out = view->view();
return true;
}
};
} // namespace gin
#endif // SHELL_BROWSER_API_ELECTRON_API_VIEW_H_ #endif // SHELL_BROWSER_API_ELECTRON_API_VIEW_H_

View file

@ -1,88 +0,0 @@
// 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 "shell/browser/api/views/electron_api_box_layout.h"
#include <string>
#include "shell/browser/api/electron_api_view.h"
#include "shell/common/gin_helper/constructor.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/object_template_builder.h"
#include "shell/common/node_includes.h"
namespace gin {
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::Orientation::kHorizontal;
else if (orientation == "vertical")
*out = views::BoxLayout::Orientation::kVertical;
else
return false;
return true;
}
};
} // namespace gin
namespace electron {
namespace api {
BoxLayout::BoxLayout(views::BoxLayout::Orientation orientation)
: LayoutManager(new views::BoxLayout(orientation)) {}
BoxLayout::~BoxLayout() {}
void BoxLayout::SetFlexForView(gin::Handle<View> view, int flex) {
auto* box_layout = static_cast<views::BoxLayout*>(layout_manager());
box_layout->SetFlexForView(view->view(), flex);
}
// static
gin_helper::WrappableBase* BoxLayout::New(
gin_helper::Arguments* args,
views::BoxLayout::Orientation orientation) {
auto* layout = new BoxLayout(orientation);
layout->InitWithArgs(args);
return layout;
}
// static
void BoxLayout::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(gin::StringToV8(isolate, "BoxLayout"));
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("setFlexForView", &BoxLayout::SetFlexForView);
}
} // namespace api
} // namespace electron
namespace {
using electron::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();
gin_helper::Dictionary dict(isolate, exports);
dict.Set("BoxLayout", gin_helper::CreateConstructor<BoxLayout>(
isolate, base::BindRepeating(&BoxLayout::New)));
}
} // namespace
NODE_LINKED_MODULE_CONTEXT_AWARE(electron_browser_box_layout, Initialize)

View file

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

View file

@ -1,58 +0,0 @@
// 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 "shell/browser/api/views/electron_api_button.h"
#include "shell/common/gin_helper/constructor.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/node_includes.h"
namespace electron {
namespace api {
Button::Button(views::Button* impl) : View(impl) {
// 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
gin_helper::WrappableBase* Button::New(gin_helper::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(gin::StringToV8(isolate, "Button"));
}
} // namespace api
} // namespace electron
namespace {
using electron::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();
gin_helper::Dictionary dict(isolate, exports);
dict.Set("Button", gin_helper::CreateConstructor<Button>(
isolate, base::BindRepeating(&Button::New)));
}
} // namespace
NODE_LINKED_MODULE_CONTEXT_AWARE(electron_browser_button, Initialize)

View file

@ -1,40 +0,0 @@
// 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 SHELL_BROWSER_API_VIEWS_ELECTRON_API_BUTTON_H_
#define SHELL_BROWSER_API_VIEWS_ELECTRON_API_BUTTON_H_
#include "gin/handle.h"
#include "shell/browser/api/electron_api_view.h"
#include "ui/views/controls/button/button.h"
namespace electron {
namespace api {
class Button : public View, public views::ButtonListener {
public:
static gin_helper::WrappableBase* New(gin_helper::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 electron
#endif // SHELL_BROWSER_API_VIEWS_ELECTRON_API_BUTTON_H_

View file

@ -1,80 +0,0 @@
// 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 "shell/browser/api/views/electron_api_label_button.h"
#include "base/strings/utf_string_conversions.h"
#include "shell/common/gin_helper/constructor.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/object_template_builder.h"
#include "shell/common/node_includes.h"
namespace electron {
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()->GetIsDefault();
}
void LabelButton::SetIsDefault(bool is_default) {
label_button()->SetIsDefault(is_default);
}
// static
gin_helper::WrappableBase* LabelButton::New(gin_helper::Arguments* args,
const std::string& text) {
// Constructor call.
auto* view = new LabelButton(text);
view->InitWithArgs(args);
return view;
}
// static
void LabelButton::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(gin::StringToV8(isolate, "LabelButton"));
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("getText", &LabelButton::GetText)
.SetMethod("setText", &LabelButton::SetText)
.SetMethod("isDefault", &LabelButton::IsDefault)
.SetMethod("setIsDefault", &LabelButton::SetIsDefault);
}
} // namespace api
} // namespace electron
namespace {
using electron::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();
gin_helper::Dictionary dict(isolate, exports);
dict.Set("LabelButton", gin_helper::CreateConstructor<LabelButton>(
isolate, base::BindRepeating(&LabelButton::New)));
}
} // namespace
NODE_LINKED_MODULE_CONTEXT_AWARE(electron_browser_label_button, Initialize)

View file

@ -1,47 +0,0 @@
// 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 SHELL_BROWSER_API_VIEWS_ELECTRON_API_LABEL_BUTTON_H_
#define SHELL_BROWSER_API_VIEWS_ELECTRON_API_LABEL_BUTTON_H_
#include <string>
#include "shell/browser/api/views/electron_api_button.h"
#include "ui/views/controls/button/label_button.h"
namespace electron {
namespace api {
class LabelButton : public Button {
public:
static gin_helper::WrappableBase* New(gin_helper::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 electron
#endif // SHELL_BROWSER_API_VIEWS_ELECTRON_API_LABEL_BUTTON_H_

View file

@ -1,63 +0,0 @@
// 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 "shell/browser/api/views/electron_api_layout_manager.h"
#include "shell/common/gin_helper/constructor.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/node_includes.h"
namespace electron {
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
gin_helper::WrappableBase* LayoutManager::New(gin_helper::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 electron
namespace {
using electron::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();
gin_helper::Dictionary dict(isolate, exports);
dict.Set("LayoutManager",
gin_helper::CreateConstructor<LayoutManager>(
isolate, base::BindRepeating(&LayoutManager::New)));
}
} // namespace
NODE_LINKED_MODULE_CONTEXT_AWARE(electron_browser_layout_manager, Initialize)

View file

@ -1,44 +0,0 @@
// 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 SHELL_BROWSER_API_VIEWS_ELECTRON_API_LAYOUT_MANAGER_H_
#define SHELL_BROWSER_API_VIEWS_ELECTRON_API_LAYOUT_MANAGER_H_
#include <memory>
#include "shell/common/gin_helper/trackable_object.h"
#include "ui/views/layout/layout_manager.h"
namespace electron {
namespace api {
class LayoutManager : public gin_helper::TrackableObject<LayoutManager> {
public:
static gin_helper::WrappableBase* New(gin_helper::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 electron
#endif // SHELL_BROWSER_API_VIEWS_ELECTRON_API_LAYOUT_MANAGER_H_

View file

@ -1,58 +0,0 @@
// 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 "shell/browser/api/views/electron_api_md_text_button.h"
#include "base/strings/utf_string_conversions.h"
#include "shell/common/gin_helper/constructor.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/node_includes.h"
namespace electron {
namespace api {
MdTextButton::MdTextButton(const std::string& text)
: LabelButton(
views::MdTextButton::Create(this, base::UTF8ToUTF16(text)).get()) {}
MdTextButton::~MdTextButton() {}
// static
gin_helper::WrappableBase* MdTextButton::New(gin_helper::Arguments* args,
const std::string& text) {
// Constructor call.
auto* view = new MdTextButton(text);
view->InitWithArgs(args);
return view;
}
// static
void MdTextButton::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(gin::StringToV8(isolate, "MdTextButton"));
}
} // namespace api
} // namespace electron
namespace {
using electron::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();
gin_helper::Dictionary dict(isolate, exports);
dict.Set("MdTextButton",
gin_helper::CreateConstructor<MdTextButton>(
isolate, base::BindRepeating(&MdTextButton::New)));
}
} // namespace
NODE_LINKED_MODULE_CONTEXT_AWARE(electron_browser_md_text_button, Initialize)

View file

@ -1,41 +0,0 @@
// 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 SHELL_BROWSER_API_VIEWS_ELECTRON_API_MD_TEXT_BUTTON_H_
#define SHELL_BROWSER_API_VIEWS_ELECTRON_API_MD_TEXT_BUTTON_H_
#include <string>
#include "shell/browser/api/views/electron_api_label_button.h"
#include "ui/views/controls/button/md_text_button.h"
namespace electron {
namespace api {
class MdTextButton : public LabelButton {
public:
static gin_helper::WrappableBase* New(gin_helper::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 electron
#endif // SHELL_BROWSER_API_VIEWS_ELECTRON_API_MD_TEXT_BUTTON_H_

View file

@ -1,57 +0,0 @@
// 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 "shell/browser/api/views/electron_api_resize_area.h"
#include "shell/common/gin_helper/constructor.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/node_includes.h"
namespace electron {
namespace api {
ResizeArea::ResizeArea() : View(new views::ResizeArea(this)) {}
ResizeArea::~ResizeArea() {}
void ResizeArea::OnResize(int resize_amount, bool done_resizing) {
Emit("resize", resize_amount, done_resizing);
}
// static
gin_helper::WrappableBase* ResizeArea::New(gin_helper::Arguments* args) {
// Constructor call.
auto* view = new ResizeArea();
view->InitWithArgs(args);
return view;
}
// static
void ResizeArea::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(gin::StringToV8(isolate, "ResizeArea"));
}
} // namespace api
} // namespace electron
namespace {
using electron::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();
gin_helper::Dictionary dict(isolate, exports);
dict.Set("ResizeArea", gin_helper::CreateConstructor<ResizeArea>(
isolate, base::BindRepeating(&ResizeArea::New)));
}
} // namespace
NODE_LINKED_MODULE_CONTEXT_AWARE(electron_browser_resize_area, Initialize)

View file

@ -1,43 +0,0 @@
// 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 SHELL_BROWSER_API_VIEWS_ELECTRON_API_RESIZE_AREA_H_
#define SHELL_BROWSER_API_VIEWS_ELECTRON_API_RESIZE_AREA_H_
#include "gin/handle.h"
#include "shell/browser/api/electron_api_view.h"
#include "ui/views/controls/resize_area.h"
#include "ui/views/controls/resize_area_delegate.h"
namespace electron {
namespace api {
class ResizeArea : public View, protected views::ResizeAreaDelegate {
public:
static gin_helper::WrappableBase* New(gin_helper::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 electron
#endif // SHELL_BROWSER_API_VIEWS_ELECTRON_API_RESIZE_AREA_H_

View file

@ -1,65 +0,0 @@
// 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 "shell/browser/api/views/electron_api_text_field.h"
#include "shell/common/gin_helper/constructor.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/object_template_builder.h"
#include "shell/common/node_includes.h"
namespace electron {
namespace api {
TextField::TextField() : View(new views::Textfield()) {}
TextField::~TextField() {}
void TextField::SetText(const base::string16& new_text) {
text_field()->SetText(new_text);
}
base::string16 TextField::GetText() const {
return text_field()->GetText();
}
// static
gin_helper::WrappableBase* TextField::New(gin_helper::Arguments* args) {
// Constructor call.
auto* view = new TextField();
view->InitWithArgs(args);
return view;
}
// static
void TextField::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(gin::StringToV8(isolate, "TextField"));
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("setText", &TextField::SetText)
.SetMethod("getText", &TextField::GetText);
}
} // namespace api
} // namespace electron
namespace {
using electron::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();
gin_helper::Dictionary dict(isolate, exports);
dict.Set("TextField", gin_helper::CreateConstructor<TextField>(
isolate, base::BindRepeating(&TextField::New)));
}
} // namespace
NODE_LINKED_MODULE_CONTEXT_AWARE(electron_browser_text_field, Initialize)

View file

@ -1,42 +0,0 @@
// 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 SHELL_BROWSER_API_VIEWS_ELECTRON_API_TEXT_FIELD_H_
#define SHELL_BROWSER_API_VIEWS_ELECTRON_API_TEXT_FIELD_H_
#include "gin/handle.h"
#include "shell/browser/api/electron_api_view.h"
#include "ui/views/controls/textfield/textfield.h"
namespace electron {
namespace api {
class TextField : public View {
public:
static gin_helper::WrappableBase* New(gin_helper::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 electron
#endif // SHELL_BROWSER_API_VIEWS_ELECTRON_API_TEXT_FIELD_H_

View file

@ -38,7 +38,7 @@ bool IsFakeLocationProviderEnabled() {
} }
bool IsViewApiEnabled() { bool IsViewApiEnabled() {
return BUILDFLAG(ENABLE_VIEW_API); return BUILDFLAG(ENABLE_VIEWS_API);
} }
bool IsTtsEnabled() { bool IsTtsEnabled() {

View file

@ -73,15 +73,7 @@
V(electron_renderer_ipc) \ V(electron_renderer_ipc) \
V(electron_renderer_web_frame) V(electron_renderer_web_frame)
#define ELECTRON_VIEW_MODULES(V) \ #define ELECTRON_VIEWS_MODULES(V) V(electron_browser_image_view)
V(electron_browser_box_layout) \
V(electron_browser_button) \
V(electron_browser_image_view) \
V(electron_browser_label_button) \
V(electron_browser_layout_manager) \
V(electron_browser_md_text_button) \
V(electron_browser_resize_area) \
V(electron_browser_text_field)
#define ELECTRON_DESKTOP_CAPTURER_MODULE(V) V(electron_browser_desktop_capturer) #define ELECTRON_DESKTOP_CAPTURER_MODULE(V) V(electron_browser_desktop_capturer)
@ -92,8 +84,8 @@
// implementation when calling the NODE_LINKED_MODULE_CONTEXT_AWARE. // implementation when calling the NODE_LINKED_MODULE_CONTEXT_AWARE.
#define V(modname) void _register_##modname(); #define V(modname) void _register_##modname();
ELECTRON_BUILTIN_MODULES(V) ELECTRON_BUILTIN_MODULES(V)
#if BUILDFLAG(ENABLE_VIEW_API) #if BUILDFLAG(ENABLE_VIEWS_API)
ELECTRON_VIEW_MODULES(V) ELECTRON_VIEWS_MODULES(V)
#endif #endif
#if BUILDFLAG(ENABLE_DESKTOP_CAPTURER) #if BUILDFLAG(ENABLE_DESKTOP_CAPTURER)
ELECTRON_DESKTOP_CAPTURER_MODULE(V) ELECTRON_DESKTOP_CAPTURER_MODULE(V)
@ -291,8 +283,8 @@ NodeBindings::~NodeBindings() {
void NodeBindings::RegisterBuiltinModules() { void NodeBindings::RegisterBuiltinModules() {
#define V(modname) _register_##modname(); #define V(modname) _register_##modname();
ELECTRON_BUILTIN_MODULES(V) ELECTRON_BUILTIN_MODULES(V)
#if BUILDFLAG(ENABLE_VIEW_API) #if BUILDFLAG(ENABLE_VIEWS_API)
ELECTRON_VIEW_MODULES(V) ELECTRON_VIEWS_MODULES(V)
#endif #endif
#if BUILDFLAG(ENABLE_DESKTOP_CAPTURER) #if BUILDFLAG(ENABLE_DESKTOP_CAPTURER)
ELECTRON_DESKTOP_CAPTURER_MODULE(V) ELECTRON_DESKTOP_CAPTURER_MODULE(V)