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

@ -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,