refactor: rename TopLevelWindow to BaseWindow (#24305)

This commit is contained in:
Cheng Zhao 2020-06-29 16:06:20 +09:00 committed by GitHub
parent 80e5007c47
commit ef3579eae3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 433 additions and 451 deletions

View file

@ -2,8 +2,8 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ELECTRON_API_TOP_LEVEL_WINDOW_H_
#define SHELL_BROWSER_API_ELECTRON_API_TOP_LEVEL_WINDOW_H_
#ifndef SHELL_BROWSER_API_ELECTRON_API_BASE_WINDOW_H_
#define SHELL_BROWSER_API_ELECTRON_API_BASE_WINDOW_H_
#include <map>
#include <memory>
@ -25,27 +25,25 @@ namespace api {
class View;
class TopLevelWindow : public gin_helper::TrackableObject<TopLevelWindow>,
public NativeWindowObserver {
class BaseWindow : public gin_helper::TrackableObject<BaseWindow>,
public NativeWindowObserver {
public:
static gin_helper::WrappableBase* New(gin_helper::Arguments* args);
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
base::WeakPtr<TopLevelWindow> GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
base::WeakPtr<BaseWindow> GetWeakPtr() { return weak_factory_.GetWeakPtr(); }
NativeWindow* window() const { return window_.get(); }
protected:
// Common constructor.
TopLevelWindow(v8::Isolate* isolate, const gin_helper::Dictionary& options);
// Creating independent TopLevelWindow instance.
TopLevelWindow(gin_helper::Arguments* args,
const gin_helper::Dictionary& options);
~TopLevelWindow() override;
BaseWindow(v8::Isolate* isolate, const gin_helper::Dictionary& options);
// Creating independent BaseWindow instance.
BaseWindow(gin_helper::Arguments* args,
const gin_helper::Dictionary& options);
~BaseWindow() override;
// TrackableObject:
void InitWith(v8::Isolate* isolate, v8::Local<v8::Object> wrapper) override;
@ -247,7 +245,7 @@ class TopLevelWindow : public gin_helper::TrackableObject<TopLevelWindow>,
void EmitEventSoon(base::StringPiece eventName) {
base::PostTask(
FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(base::IgnoreResult(&TopLevelWindow::Emit<Args...>),
base::BindOnce(base::IgnoreResult(&BaseWindow::Emit<Args...>),
weak_factory_.GetWeakPtr(), eventName));
}
@ -267,11 +265,11 @@ class TopLevelWindow : public gin_helper::TrackableObject<TopLevelWindow>,
// Reference to JS wrapper to prevent garbage collection.
v8::Global<v8::Value> self_ref_;
base::WeakPtrFactory<TopLevelWindow> weak_factory_;
base::WeakPtrFactory<BaseWindow> weak_factory_;
};
} // namespace api
} // namespace electron
#endif // SHELL_BROWSER_API_ELECTRON_API_TOP_LEVEL_WINDOW_H_
#endif // SHELL_BROWSER_API_ELECTRON_API_BASE_WINDOW_H_

View file

@ -31,7 +31,7 @@ namespace api {
BrowserWindow::BrowserWindow(gin::Arguments* args,
const gin_helper::Dictionary& options)
: TopLevelWindow(args->isolate(), options), weak_factory_(this) {
: BaseWindow(args->isolate(), options), weak_factory_(this) {
// Use options.webPreferences in WebContents.
v8::Isolate* isolate = args->isolate();
gin_helper::Dictionary web_preferences =
@ -90,7 +90,7 @@ BrowserWindow::BrowserWindow(gin::Arguments* args,
InitWithArgs(args);
// Install the content view after TopLevelWindow's JS code is initialized.
// Install the content view after BaseWindow's JS code is initialized.
SetContentView(gin::CreateHandle<View>(isolate, web_contents_view.get()));
#if defined(OS_MACOSX)
@ -106,7 +106,7 @@ BrowserWindow::~BrowserWindow() {
if (api_web_contents_)
api_web_contents_->RemoveObserver(this);
// Note that the OnWindowClosed will not be called after the destructor runs,
// since the window object is managed by the TopLevelWindow class.
// since the window object is managed by the BaseWindow class.
if (web_contents())
Cleanup();
}
@ -277,9 +277,9 @@ void BrowserWindow::OnCloseButtonClicked(bool* prevent_default) {
void BrowserWindow::OnWindowClosed() {
Cleanup();
// See TopLevelWindow::OnWindowClosed on why calling InvalidateWeakPtrs.
// See BaseWindow::OnWindowClosed on why calling InvalidateWeakPtrs.
weak_factory_.InvalidateWeakPtrs();
TopLevelWindow::OnWindowClosed();
BaseWindow::OnWindowClosed();
}
void BrowserWindow::OnWindowBlur() {
@ -290,7 +290,7 @@ void BrowserWindow::OnWindowBlur() {
rwhv->SetActive(false);
#endif
TopLevelWindow::OnWindowBlur();
BaseWindow::OnWindowBlur();
}
void BrowserWindow::OnWindowFocus() {
@ -304,7 +304,7 @@ void BrowserWindow::OnWindowFocus() {
web_contents()->Focus();
#endif
TopLevelWindow::OnWindowFocus();
BaseWindow::OnWindowFocus();
}
void BrowserWindow::OnWindowResize() {
@ -312,11 +312,11 @@ void BrowserWindow::OnWindowResize() {
if (!draggable_regions_.empty())
UpdateDraggableRegions(draggable_regions_);
#endif
TopLevelWindow::OnWindowResize();
BaseWindow::OnWindowResize();
}
void BrowserWindow::OnWindowLeaveFullScreen() {
TopLevelWindow::OnWindowLeaveFullScreen();
BaseWindow::OnWindowLeaveFullScreen();
#if defined(OS_MACOSX)
if (web_contents()->IsFullscreenForCurrentTab())
web_contents()->ExitFullscreen(true);
@ -327,18 +327,18 @@ void BrowserWindow::Focus() {
if (api_web_contents_->IsOffScreen())
FocusOnWebView();
else
TopLevelWindow::Focus();
BaseWindow::Focus();
}
void BrowserWindow::Blur() {
if (api_web_contents_->IsOffScreen())
BlurWebView();
else
TopLevelWindow::Blur();
BaseWindow::Blur();
}
void BrowserWindow::SetBackgroundColor(const std::string& color_name) {
TopLevelWindow::SetBackgroundColor(color_name);
BaseWindow::SetBackgroundColor(color_name);
auto* view = web_contents()->GetRenderWidgetHostView();
if (view)
view->SetBackgroundColor(ParseHexColor(color_name));
@ -355,29 +355,29 @@ void BrowserWindow::SetBackgroundColor(const std::string& color_name) {
}
void BrowserWindow::SetBrowserView(v8::Local<v8::Value> value) {
TopLevelWindow::ResetBrowserViews();
TopLevelWindow::AddBrowserView(value);
BaseWindow::ResetBrowserViews();
BaseWindow::AddBrowserView(value);
#if defined(OS_MACOSX)
UpdateDraggableRegions(draggable_regions_);
#endif
}
void BrowserWindow::AddBrowserView(v8::Local<v8::Value> value) {
TopLevelWindow::AddBrowserView(value);
BaseWindow::AddBrowserView(value);
#if defined(OS_MACOSX)
UpdateDraggableRegions(draggable_regions_);
#endif
}
void BrowserWindow::RemoveBrowserView(v8::Local<v8::Value> value) {
TopLevelWindow::RemoveBrowserView(value);
BaseWindow::RemoveBrowserView(value);
#if defined(OS_MACOSX)
UpdateDraggableRegions(draggable_regions_);
#endif
}
void BrowserWindow::ResetBrowserViews() {
TopLevelWindow::ResetBrowserViews();
BaseWindow::ResetBrowserViews();
#if defined(OS_MACOSX)
UpdateDraggableRegions(draggable_regions_);
#endif
@ -397,7 +397,7 @@ void BrowserWindow::SetVibrancy(v8::Isolate* isolate,
type.empty() ? !window_->transparent() : false);
}
TopLevelWindow::SetVibrancy(isolate, value);
BaseWindow::SetVibrancy(isolate, value);
}
void BrowserWindow::FocusOnWebView() {
@ -464,12 +464,12 @@ void BrowserWindow::Cleanup() {
void BrowserWindow::OnWindowShow() {
web_contents()->WasShown();
TopLevelWindow::OnWindowShow();
BaseWindow::OnWindowShow();
}
void BrowserWindow::OnWindowHide() {
web_contents()->WasOccluded();
TopLevelWindow::OnWindowHide();
BaseWindow::OnWindowHide();
}
// static
@ -520,8 +520,8 @@ v8::Local<v8::Value> BrowserWindow::From(v8::Isolate* isolate,
namespace {
using electron::api::BaseWindow;
using electron::api::BrowserWindow;
using electron::api::TopLevelWindow;
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,

View file

@ -10,7 +10,7 @@
#include <vector>
#include "base/cancelable_callback.h"
#include "shell/browser/api/electron_api_top_level_window.h"
#include "shell/browser/api/electron_api_base_window.h"
#include "shell/browser/api/electron_api_web_contents.h"
#include "shell/common/gin_helper/error_thrower.h"
@ -18,7 +18,7 @@ namespace electron {
namespace api {
class BrowserWindow : public TopLevelWindow,
class BrowserWindow : public BaseWindow,
public content::RenderWidgetHost::InputEventObserver,
public content::WebContentsObserver,
public ExtendedWebContentsObserver {
@ -67,7 +67,7 @@ class BrowserWindow : public TopLevelWindow,
void RequestPreferredWidth(int* width) override;
void OnCloseButtonClicked(bool* prevent_default) override;
// TopLevelWindow:
// BaseWindow:
void OnWindowClosed() override;
void OnWindowBlur() override;
void OnWindowFocus() override;

View file

@ -10,7 +10,7 @@
#include "base/callback.h"
#include "gin/arguments.h"
#include "shell/browser/api/electron_api_top_level_window.h"
#include "shell/browser/api/electron_api_base_window.h"
#include "shell/browser/event_emitter_mixin.h"
#include "shell/browser/ui/electron_menu_model.h"
#include "shell/common/gin_helper/constructible.h"
@ -67,7 +67,7 @@ class Menu : public gin::Wrappable<Menu>,
void ExecuteCommand(int command_id, int event_flags) override;
void OnMenuWillShow(ui::SimpleMenuModel* source) override;
virtual void PopupAt(TopLevelWindow* window,
virtual void PopupAt(BaseWindow* window,
int x,
int y,
int positioning_item,

View file

@ -23,7 +23,7 @@ class MenuMac : public Menu {
explicit MenuMac(gin::Arguments* args);
~MenuMac() override;
void PopupAt(TopLevelWindow* window,
void PopupAt(BaseWindow* window,
int x,
int y,
int positioning_item,

View file

@ -34,7 +34,7 @@ MenuMac::MenuMac(gin::Arguments* args) : Menu(args), weak_factory_(this) {}
MenuMac::~MenuMac() = default;
void MenuMac::PopupAt(TopLevelWindow* window,
void MenuMac::PopupAt(BaseWindow* window,
int x,
int y,
int positioning_item,

View file

@ -21,7 +21,7 @@ MenuViews::MenuViews(gin::Arguments* args) : Menu(args), weak_factory_(this) {}
MenuViews::~MenuViews() = default;
void MenuViews::PopupAt(TopLevelWindow* window,
void MenuViews::PopupAt(BaseWindow* window,
int x,
int y,
int positioning_item,

View file

@ -23,7 +23,7 @@ class MenuViews : public Menu {
~MenuViews() override;
protected:
void PopupAt(TopLevelWindow* window,
void PopupAt(BaseWindow* window,
int x,
int y,
int positioning_item,