From 76ae3b7ecbd0eef93b6842319c791cc00cf9ef59 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 28 Mar 2020 15:44:57 +0900 Subject: [PATCH] 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 --- BUILD.gn | 16 +--- buildflags/BUILD.gn | 2 +- buildflags/buildflags.gni | 2 +- filenames.auto.gni | 7 -- lib/browser/api/module-keys.js | 8 +- lib/browser/api/module-list.ts | 9 +- lib/browser/api/views/box-layout.js | 15 ---- lib/browser/api/views/button.js | 15 ---- lib/browser/api/views/label-button.js | 15 ---- lib/browser/api/views/layout-manager.js | 8 -- lib/browser/api/views/md-text-button.js | 15 ---- lib/browser/api/views/resize-area.js | 15 ---- lib/browser/api/views/text-field.js | 15 ---- shell/browser/api/electron_api_view.cc | 10 +-- shell/browser/api/electron_api_view.h | 25 +----- .../api/views/electron_api_box_layout.cc | 88 ------------------- .../api/views/electron_api_box_layout.h | 41 --------- .../browser/api/views/electron_api_button.cc | 58 ------------ shell/browser/api/views/electron_api_button.h | 40 --------- .../api/views/electron_api_label_button.cc | 80 ----------------- .../api/views/electron_api_label_button.h | 47 ---------- .../api/views/electron_api_layout_manager.cc | 63 ------------- .../api/views/electron_api_layout_manager.h | 44 ---------- .../api/views/electron_api_md_text_button.cc | 58 ------------ .../api/views/electron_api_md_text_button.h | 41 --------- .../api/views/electron_api_resize_area.cc | 57 ------------ .../api/views/electron_api_resize_area.h | 43 --------- .../api/views/electron_api_text_field.cc | 65 -------------- .../api/views/electron_api_text_field.h | 42 --------- shell/common/api/features.cc | 2 +- shell/common/node_bindings.cc | 18 ++-- 31 files changed, 16 insertions(+), 948 deletions(-) delete mode 100644 lib/browser/api/views/box-layout.js delete mode 100644 lib/browser/api/views/button.js delete mode 100644 lib/browser/api/views/label-button.js delete mode 100644 lib/browser/api/views/layout-manager.js delete mode 100644 lib/browser/api/views/md-text-button.js delete mode 100644 lib/browser/api/views/resize-area.js delete mode 100644 lib/browser/api/views/text-field.js delete mode 100644 shell/browser/api/views/electron_api_box_layout.cc delete mode 100644 shell/browser/api/views/electron_api_box_layout.h delete mode 100644 shell/browser/api/views/electron_api_button.cc delete mode 100644 shell/browser/api/views/electron_api_button.h delete mode 100644 shell/browser/api/views/electron_api_label_button.cc delete mode 100644 shell/browser/api/views/electron_api_label_button.h delete mode 100644 shell/browser/api/views/electron_api_layout_manager.cc delete mode 100644 shell/browser/api/views/electron_api_layout_manager.h delete mode 100644 shell/browser/api/views/electron_api_md_text_button.cc delete mode 100644 shell/browser/api/views/electron_api_md_text_button.h delete mode 100644 shell/browser/api/views/electron_api_resize_area.cc delete mode 100644 shell/browser/api/views/electron_api_resize_area.h delete mode 100644 shell/browser/api/views/electron_api_text_field.cc delete mode 100644 shell/browser/api/views/electron_api_text_field.h diff --git a/BUILD.gn b/BUILD.gn index 66836a05df41..7a7fc511db05 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 6209a7de40d8..f49fc1613d0d 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 ee6f22bf4357..a926a324d15f 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 5588dc2f5538..cb69151489a3 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 172e9a1220ad..66a1f4a60cb9 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 479bdf6bed7f..1b908caccef3 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 f9c89f8861d4..000000000000 --- 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 d3b094eb0fb6..000000000000 --- 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 0a205a177dfe..000000000000 --- 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 e7b3b8c8f136..000000000000 --- 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 2528bf487e54..000000000000 --- 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 d36c3805f54a..000000000000 --- 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 eeb740019ada..000000000000 --- 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 d36aabd83cc6..e8e172b50809 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 layout_manager) { - layout_manager_.Reset(isolate(), layout_manager->GetWrapper()); - view()->SetLayoutManager(layout_manager->TakeOver()); -} - +#if BUILDFLAG(ENABLE_VIEWS_API) void View::AddChildView(gin::Handle 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 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 cdb14a07bf63..d82b0fcf95ea 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 { +class View : public gin_helper::Wrappable { public: static gin_helper::WrappableBase* New(gin::Arguments* args); static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); -#if BUILDFLAG(ENABLE_VIEW_API) - void SetLayoutManager(gin::Handle layout_manager); +#if BUILDFLAG(ENABLE_VIEWS_API) void AddChildView(gin::Handle view); void AddChildViewAt(gin::Handle view, size_t index); #endif @@ -41,7 +40,6 @@ class View : public gin_helper::TrackableObject { void set_delete_view(bool should) { delete_view_ = should; } private: - v8::Global layout_manager_; std::vector> child_views_; bool delete_view_ = true; @@ -54,21 +52,4 @@ class View : public gin_helper::TrackableObject { } // namespace electron -namespace gin { - -template <> -struct Converter { - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - views::View** out) { - electron::api::View* view; - if (!Converter::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 98c873ebfeba..000000000000 --- 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 - -#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 { - static bool FromV8(v8::Isolate* isolate, - v8::Handle 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, int flex) { - auto* box_layout = static_cast(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 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 exports, - v8::Local unused, - v8::Local context, - void* priv) { - v8::Isolate* isolate = context->GetIsolate(); - gin_helper::Dictionary dict(isolate, exports); - dict.Set("BoxLayout", gin_helper::CreateConstructor( - 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 74fd50ca8d1c..000000000000 --- 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 prototype); - - void SetFlexForView(gin::Handle 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 19427ac8e027..000000000000 --- 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 prototype) { - prototype->SetClassName(gin::StringToV8(isolate, "Button")); -} - -} // namespace api - -} // namespace electron - -namespace { - -using electron::api::Button; - -void Initialize(v8::Local exports, - v8::Local unused, - v8::Local context, - void* priv) { - v8::Isolate* isolate = context->GetIsolate(); - gin_helper::Dictionary dict(isolate, exports); - dict.Set("Button", gin_helper::CreateConstructor