diff --git a/BUILD.gn b/BUILD.gn index 66836a05df4..7a7fc511db0 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -600,24 +600,10 @@ source_set("electron_lib") { ] } - if (enable_view_api) { + if (enable_views_api) { 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.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", ] } diff --git a/buildflags/BUILD.gn b/buildflags/BUILD.gn index 6209a7de40d..f49fc1613d0 100644 --- a/buildflags/BUILD.gn +++ b/buildflags/BUILD.gn @@ -13,7 +13,7 @@ buildflag_header("buildflags") { "ENABLE_RUN_AS_NODE=$enable_run_as_node", "ENABLE_OSR=$enable_osr", "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_PDF_VIEWER=$enable_pdf_viewer", "ENABLE_TTS=$enable_tts", diff --git a/buildflags/buildflags.gni b/buildflags/buildflags.gni index ee6f22bf435..a926a324d15 100644 --- a/buildflags/buildflags.gni +++ b/buildflags/buildflags.gni @@ -12,7 +12,7 @@ declare_args() { enable_remote_module = true - enable_view_api = false + enable_views_api = true enable_pdf_viewer = true diff --git a/filenames.auto.gni b/filenames.auto.gni index 5588dc2f553..cb69151489a 100644 --- a/filenames.auto.gni +++ b/filenames.auto.gni @@ -244,14 +244,7 @@ auto_filenames = { "lib/browser/api/touch-bar.js", "lib/browser/api/tray.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/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.js", "lib/browser/chrome-extension-shim.js", diff --git a/lib/browser/api/module-keys.js b/lib/browser/api/module-keys.js index 172e9a1220a..66a1f4a60cb 100644 --- a/lib/browser/api/module-keys.js +++ b/lib/browser/api/module-keys.js @@ -42,12 +42,6 @@ module.exports = [ if (features.isViewApiEnabled()) { module.exports.push( - { name: 'BoxLayout' }, - { name: 'Button' }, - { name: 'LabelButton' }, - { name: 'LayoutManager' }, - { name: 'MdTextButton' }, - { name: 'ResizeArea' }, - { name: 'TextField' } + { name: 'ImageView' } ); } diff --git a/lib/browser/api/module-list.ts b/lib/browser/api/module-list.ts index 479bdf6bed7..1b908caccef 100644 --- a/lib/browser/api/module-list.ts +++ b/lib/browser/api/module-list.ts @@ -37,13 +37,6 @@ export const browserModuleList: ElectronInternal.ModuleEntry[] = [ if (features.isViewApiEnabled()) { browserModuleList.push( - { name: 'BoxLayout', loader: () => require('./views/box-layout') }, - { 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') } + { name: 'ImageView', loader: () => require('./views/image-view') } ); } diff --git a/lib/browser/api/views/box-layout.js b/lib/browser/api/views/box-layout.js deleted file mode 100644 index f9c89f8861d..00000000000 --- a/lib/browser/api/views/box-layout.js +++ /dev/null @@ -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; diff --git a/lib/browser/api/views/button.js b/lib/browser/api/views/button.js deleted file mode 100644 index d3b094eb0fb..00000000000 --- a/lib/browser/api/views/button.js +++ /dev/null @@ -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; diff --git a/lib/browser/api/views/label-button.js b/lib/browser/api/views/label-button.js deleted file mode 100644 index 0a205a177df..00000000000 --- a/lib/browser/api/views/label-button.js +++ /dev/null @@ -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; diff --git a/lib/browser/api/views/layout-manager.js b/lib/browser/api/views/layout-manager.js deleted file mode 100644 index e7b3b8c8f13..00000000000 --- a/lib/browser/api/views/layout-manager.js +++ /dev/null @@ -1,8 +0,0 @@ -'use strict'; - -const { LayoutManager } = process.electronBinding('layout_manager'); - -LayoutManager.prototype._init = function () { -}; - -module.exports = LayoutManager; diff --git a/lib/browser/api/views/md-text-button.js b/lib/browser/api/views/md-text-button.js deleted file mode 100644 index 2528bf487e5..00000000000 --- a/lib/browser/api/views/md-text-button.js +++ /dev/null @@ -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; diff --git a/lib/browser/api/views/resize-area.js b/lib/browser/api/views/resize-area.js deleted file mode 100644 index d36c3805f54..00000000000 --- a/lib/browser/api/views/resize-area.js +++ /dev/null @@ -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; diff --git a/lib/browser/api/views/text-field.js b/lib/browser/api/views/text-field.js deleted file mode 100644 index eeb740019ad..00000000000 --- a/lib/browser/api/views/text-field.js +++ /dev/null @@ -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; diff --git a/shell/browser/api/electron_api_view.cc b/shell/browser/api/electron_api_view.cc index d36aabd83cc..e8e172b5080 100644 --- a/shell/browser/api/electron_api_view.cc +++ b/shell/browser/api/electron_api_view.cc @@ -23,12 +23,7 @@ View::~View() { delete view_; } -#if BUILDFLAG(ENABLE_VIEW_API) -void View::SetLayoutManager(gin::Handle<LayoutManager> layout_manager) { - layout_manager_.Reset(isolate(), layout_manager->GetWrapper()); - view()->SetLayoutManager(layout_manager->TakeOver()); -} - +#if BUILDFLAG(ENABLE_VIEWS_API) void View::AddChildView(gin::Handle<View> child) { AddChildViewAt(child, child_views_.size()); } @@ -53,9 +48,8 @@ gin_helper::WrappableBase* View::New(gin::Arguments* args) { void View::BuildPrototype(v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) { prototype->SetClassName(gin::StringToV8(isolate, "View")); -#if BUILDFLAG(ENABLE_VIEW_API) +#if BUILDFLAG(ENABLE_VIEWS_API) gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) - .SetMethod("setLayoutManager", &View::SetLayoutManager) .SetMethod("addChildView", &View::AddChildView) .SetMethod("addChildViewAt", &View::AddChildViewAt); #endif diff --git a/shell/browser/api/electron_api_view.h b/shell/browser/api/electron_api_view.h index cdb14a07bf6..d82b0fcf95e 100644 --- a/shell/browser/api/electron_api_view.h +++ b/shell/browser/api/electron_api_view.h @@ -10,22 +10,21 @@ #include "electron/buildflags/buildflags.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" namespace electron { namespace api { -class View : public gin_helper::TrackableObject<View> { +class View : public gin_helper::Wrappable<View> { public: static gin_helper::WrappableBase* New(gin::Arguments* args); static void BuildPrototype(v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype); -#if BUILDFLAG(ENABLE_VIEW_API) - void SetLayoutManager(gin::Handle<LayoutManager> layout_manager); +#if BUILDFLAG(ENABLE_VIEWS_API) void AddChildView(gin::Handle<View> view); void AddChildViewAt(gin::Handle<View> view, size_t index); #endif @@ -41,7 +40,6 @@ class View : public gin_helper::TrackableObject<View> { void set_delete_view(bool should) { delete_view_ = should; } private: - v8::Global<v8::Object> layout_manager_; std::vector<v8::Global<v8::Object>> child_views_; bool delete_view_ = true; @@ -54,21 +52,4 @@ class View : public gin_helper::TrackableObject<View> { } // 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_ diff --git a/shell/browser/api/views/electron_api_box_layout.cc b/shell/browser/api/views/electron_api_box_layout.cc deleted file mode 100644 index 98c873ebfeb..00000000000 --- a/shell/browser/api/views/electron_api_box_layout.cc +++ /dev/null @@ -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) diff --git a/shell/browser/api/views/electron_api_box_layout.h b/shell/browser/api/views/electron_api_box_layout.h deleted file mode 100644 index 74fd50ca8d1..00000000000 --- a/shell/browser/api/views/electron_api_box_layout.h +++ /dev/null @@ -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_ diff --git a/shell/browser/api/views/electron_api_button.cc b/shell/browser/api/views/electron_api_button.cc deleted file mode 100644 index 19427ac8e02..00000000000 --- a/shell/browser/api/views/electron_api_button.cc +++ /dev/null @@ -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) diff --git a/shell/browser/api/views/electron_api_button.h b/shell/browser/api/views/electron_api_button.h deleted file mode 100644 index 68f43d75412..00000000000 --- a/shell/browser/api/views/electron_api_button.h +++ /dev/null @@ -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_ diff --git a/shell/browser/api/views/electron_api_label_button.cc b/shell/browser/api/views/electron_api_label_button.cc deleted file mode 100644 index df82f51c91c..00000000000 --- a/shell/browser/api/views/electron_api_label_button.cc +++ /dev/null @@ -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) diff --git a/shell/browser/api/views/electron_api_label_button.h b/shell/browser/api/views/electron_api_label_button.h deleted file mode 100644 index 7cfe96e0096..00000000000 --- a/shell/browser/api/views/electron_api_label_button.h +++ /dev/null @@ -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_ diff --git a/shell/browser/api/views/electron_api_layout_manager.cc b/shell/browser/api/views/electron_api_layout_manager.cc deleted file mode 100644 index c8141c34d84..00000000000 --- a/shell/browser/api/views/electron_api_layout_manager.cc +++ /dev/null @@ -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) diff --git a/shell/browser/api/views/electron_api_layout_manager.h b/shell/browser/api/views/electron_api_layout_manager.h deleted file mode 100644 index 361272fef7b..00000000000 --- a/shell/browser/api/views/electron_api_layout_manager.h +++ /dev/null @@ -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_ diff --git a/shell/browser/api/views/electron_api_md_text_button.cc b/shell/browser/api/views/electron_api_md_text_button.cc deleted file mode 100644 index ed903dafced..00000000000 --- a/shell/browser/api/views/electron_api_md_text_button.cc +++ /dev/null @@ -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) diff --git a/shell/browser/api/views/electron_api_md_text_button.h b/shell/browser/api/views/electron_api_md_text_button.h deleted file mode 100644 index ec94c68fc3d..00000000000 --- a/shell/browser/api/views/electron_api_md_text_button.h +++ /dev/null @@ -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_ diff --git a/shell/browser/api/views/electron_api_resize_area.cc b/shell/browser/api/views/electron_api_resize_area.cc deleted file mode 100644 index 71883a24b68..00000000000 --- a/shell/browser/api/views/electron_api_resize_area.cc +++ /dev/null @@ -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) diff --git a/shell/browser/api/views/electron_api_resize_area.h b/shell/browser/api/views/electron_api_resize_area.h deleted file mode 100644 index 7ebb67d48f2..00000000000 --- a/shell/browser/api/views/electron_api_resize_area.h +++ /dev/null @@ -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_ diff --git a/shell/browser/api/views/electron_api_text_field.cc b/shell/browser/api/views/electron_api_text_field.cc deleted file mode 100644 index 85d7029344b..00000000000 --- a/shell/browser/api/views/electron_api_text_field.cc +++ /dev/null @@ -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) diff --git a/shell/browser/api/views/electron_api_text_field.h b/shell/browser/api/views/electron_api_text_field.h deleted file mode 100644 index f23430e8155..00000000000 --- a/shell/browser/api/views/electron_api_text_field.h +++ /dev/null @@ -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_ diff --git a/shell/common/api/features.cc b/shell/common/api/features.cc index 3f875fcd448..28808a72fb0 100644 --- a/shell/common/api/features.cc +++ b/shell/common/api/features.cc @@ -38,7 +38,7 @@ bool IsFakeLocationProviderEnabled() { } bool IsViewApiEnabled() { - return BUILDFLAG(ENABLE_VIEW_API); + return BUILDFLAG(ENABLE_VIEWS_API); } bool IsTtsEnabled() { diff --git a/shell/common/node_bindings.cc b/shell/common/node_bindings.cc index 25445b767bd..1371ead2aa2 100644 --- a/shell/common/node_bindings.cc +++ b/shell/common/node_bindings.cc @@ -73,15 +73,7 @@ V(electron_renderer_ipc) \ V(electron_renderer_web_frame) -#define ELECTRON_VIEW_MODULES(V) \ - 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_VIEWS_MODULES(V) V(electron_browser_image_view) #define ELECTRON_DESKTOP_CAPTURER_MODULE(V) V(electron_browser_desktop_capturer) @@ -92,8 +84,8 @@ // implementation when calling the NODE_LINKED_MODULE_CONTEXT_AWARE. #define V(modname) void _register_##modname(); ELECTRON_BUILTIN_MODULES(V) -#if BUILDFLAG(ENABLE_VIEW_API) -ELECTRON_VIEW_MODULES(V) +#if BUILDFLAG(ENABLE_VIEWS_API) +ELECTRON_VIEWS_MODULES(V) #endif #if BUILDFLAG(ENABLE_DESKTOP_CAPTURER) ELECTRON_DESKTOP_CAPTURER_MODULE(V) @@ -291,8 +283,8 @@ NodeBindings::~NodeBindings() { void NodeBindings::RegisterBuiltinModules() { #define V(modname) _register_##modname(); ELECTRON_BUILTIN_MODULES(V) -#if BUILDFLAG(ENABLE_VIEW_API) - ELECTRON_VIEW_MODULES(V) +#if BUILDFLAG(ENABLE_VIEWS_API) + ELECTRON_VIEWS_MODULES(V) #endif #if BUILDFLAG(ENABLE_DESKTOP_CAPTURER) ELECTRON_DESKTOP_CAPTURER_MODULE(V)