fix: revert moving IsClosed() and IsClosable() into NativeWindow::Close() (#47482)

Revert "refactor: move `IsClosed()` and `IsClosable()` tests into `NativeWindow::Close()` (#46888)"

This reverts commit 3faddd5ae2.
This commit is contained in:
Keeley Hammond 2025-06-16 16:41:19 -07:00 committed by GitHub
parent 2ad762e075
commit 3536d4976a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 35 additions and 35 deletions

View file

@ -362,6 +362,7 @@ void BaseWindow::SetContentView(gin::Handle<View> view) {
} }
void BaseWindow::CloseImmediately() { void BaseWindow::CloseImmediately() {
if (!window_->IsClosed())
window_->CloseImmediately(); window_->CloseImmediately();
} }

View file

@ -285,6 +285,10 @@ void NativeWindow::SetShape(const std::vector<gfx::Rect>& rects) {
widget()->SetShape(std::make_unique<std::vector<gfx::Rect>>(rects)); widget()->SetShape(std::make_unique<std::vector<gfx::Rect>>(rects));
} }
bool NativeWindow::IsClosed() const {
return is_closed_;
}
void NativeWindow::SetSize(const gfx::Size& size, bool animate) { void NativeWindow::SetSize(const gfx::Size& size, bool animate) {
SetBounds(gfx::Rect(GetPosition(), size), animate); SetBounds(gfx::Rect(GetPosition(), size), animate);
} }
@ -523,23 +527,8 @@ void NativeWindow::NotifyWindowCloseButtonClicked() {
CloseImmediately(); CloseImmediately();
} }
void NativeWindow::Close() {
if (!IsClosable()) {
WindowList::WindowCloseCancelled(this);
return;
}
if (!is_closed())
CloseImpl();
}
void NativeWindow::CloseImmediately() {
if (!is_closed())
CloseImmediatelyImpl();
}
void NativeWindow::NotifyWindowClosed() { void NativeWindow::NotifyWindowClosed() {
if (is_closed()) if (is_closed_)
return; return;
is_closed_ = true; is_closed_ = true;

View file

@ -81,10 +81,9 @@ class NativeWindow : public base::SupportsUserData,
virtual void SetContentView(views::View* view) = 0; virtual void SetContentView(views::View* view) = 0;
// wrapper around CloseImpl that checks that window_ can be closed virtual void Close() = 0;
void Close(); virtual void CloseImmediately() = 0;
// wrapper around CloseImmediatelyImpl that checks that window_ can be closed virtual bool IsClosed() const;
void CloseImmediately();
virtual void Focus(bool focus) = 0; virtual void Focus(bool focus) = 0;
virtual bool IsFocused() const = 0; virtual bool IsFocused() const = 0;
virtual void Show() = 0; virtual void Show() = 0;
@ -427,6 +426,8 @@ class NativeWindow : public base::SupportsUserData,
void UpdateBackgroundThrottlingState(); void UpdateBackgroundThrottlingState();
protected: protected:
friend class api::BrowserView;
NativeWindow(const gin_helper::Dictionary& options, NativeWindow* parent); NativeWindow(const gin_helper::Dictionary& options, NativeWindow* parent);
void set_titlebar_overlay_height(int height) { void set_titlebar_overlay_height(int height) {
@ -457,9 +458,6 @@ class NativeWindow : public base::SupportsUserData,
void set_content_view(views::View* view) { content_view_ = view; } void set_content_view(views::View* view) { content_view_ = view; }
virtual void CloseImpl() = 0;
virtual void CloseImmediatelyImpl() = 0;
static inline constexpr base::cstring_view kNativeWindowKey = static inline constexpr base::cstring_view kNativeWindowKey =
"__ELECTRON_NATIVE_WINDOW__"; "__ELECTRON_NATIVE_WINDOW__";

View file

@ -39,8 +39,8 @@ class NativeWindowMac : public NativeWindow,
// NativeWindow: // NativeWindow:
void OnTitleChanged() override; void OnTitleChanged() override;
void SetContentView(views::View* view) override; void SetContentView(views::View* view) override;
void CloseImpl() override; void Close() override;
void CloseImmediatelyImpl() override; void CloseImmediately() override;
void Focus(bool focus) override; void Focus(bool focus) override;
bool IsFocused() const override; bool IsFocused() const override;
void Show() override; void Show() override;

View file

@ -33,6 +33,7 @@
#include "shell/browser/ui/cocoa/root_view_mac.h" #include "shell/browser/ui/cocoa/root_view_mac.h"
#include "shell/browser/ui/cocoa/window_buttons_proxy.h" #include "shell/browser/ui/cocoa/window_buttons_proxy.h"
#include "shell/browser/ui/drag_util.h" #include "shell/browser/ui/drag_util.h"
#include "shell/browser/window_list.h"
#include "shell/common/gin_converters/gfx_converter.h" #include "shell/common/gin_converters/gfx_converter.h"
#include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/dictionary.h"
#include "shell/common/node_util.h" #include "shell/common/node_util.h"
@ -336,7 +337,12 @@ void NativeWindowMac::SetContentView(views::View* view) {
root_view->DeprecatedLayoutImmediately(); root_view->DeprecatedLayoutImmediately();
} }
void NativeWindowMac::CloseImpl() { void NativeWindowMac::Close() {
if (!IsClosable()) {
WindowList::WindowCloseCancelled(this);
return;
}
if (is_transitioning_fullscreen()) { if (is_transitioning_fullscreen()) {
SetHasDeferredWindowClose(true); SetHasDeferredWindowClose(true);
return; return;
@ -372,7 +378,7 @@ void NativeWindowMac::CloseImpl() {
} }
} }
void NativeWindowMac::CloseImmediatelyImpl() { void NativeWindowMac::CloseImmediately() {
// Ensure we're detached from the parent window before closing. // Ensure we're detached from the parent window before closing.
RemoveChildFromParentWindow(); RemoveChildFromParentWindow();
@ -1686,7 +1692,7 @@ bool NativeWindowMac::IsActive() const {
} }
void NativeWindowMac::Cleanup() { void NativeWindowMac::Cleanup() {
DCHECK(!is_closed()); DCHECK(!IsClosed());
ui::NativeTheme::GetInstanceForNativeUi()->RemoveObserver(this); ui::NativeTheme::GetInstanceForNativeUi()->RemoveObserver(this);
display::Screen::GetScreen()->RemoveObserver(this); display::Screen::GetScreen()->RemoveObserver(this);
[window_ cleanup]; [window_ cleanup];

View file

@ -31,6 +31,7 @@
#include "shell/browser/ui/views/root_view.h" #include "shell/browser/ui/views/root_view.h"
#include "shell/browser/web_contents_preferences.h" #include "shell/browser/web_contents_preferences.h"
#include "shell/browser/web_view_manager.h" #include "shell/browser/web_view_manager.h"
#include "shell/browser/window_list.h"
#include "shell/common/electron_constants.h" #include "shell/common/electron_constants.h"
#include "shell/common/gin_converters/image_converter.h" #include "shell/common/gin_converters/image_converter.h"
#include "shell/common/gin_helper/arguments.h" #include "shell/common/gin_helper/arguments.h"
@ -532,11 +533,16 @@ void NativeWindowViews::SetContentView(views::View* view) {
root_view_.GetMainView()->DeprecatedLayoutImmediately(); root_view_.GetMainView()->DeprecatedLayoutImmediately();
} }
void NativeWindowViews::CloseImpl() { void NativeWindowViews::Close() {
if (!IsClosable()) {
WindowList::WindowCloseCancelled(this);
return;
}
widget()->Close(); widget()->Close();
} }
void NativeWindowViews::CloseImmediatelyImpl() { void NativeWindowViews::CloseImmediately() {
widget()->CloseNow(); widget()->CloseNow();
} }

View file

@ -53,8 +53,8 @@ class NativeWindowViews : public NativeWindow,
// NativeWindow: // NativeWindow:
void SetContentView(views::View* view) override; void SetContentView(views::View* view) override;
void CloseImpl() override; void Close() override;
void CloseImmediatelyImpl() override; void CloseImmediately() override;
void Focus(bool focus) override; void Focus(bool focus) override;
bool IsFocused() const override; bool IsFocused() const override;
void Show() override; void Show() override;

View file

@ -84,7 +84,7 @@ void WindowList::CloseAllWindows() {
std::ranges::reverse(weak_windows); std::ranges::reverse(weak_windows);
#endif #endif
for (const auto& window : weak_windows) { for (const auto& window : weak_windows) {
if (window) if (window && !window->IsClosed())
window->Close(); window->Close();
} }
} }
@ -95,7 +95,7 @@ void WindowList::DestroyAllWindows() {
ConvertToWeakPtrVector(GetInstance()->windows_); ConvertToWeakPtrVector(GetInstance()->windows_);
for (const auto& window : weak_windows) { for (const auto& window : weak_windows) {
if (window) if (window && !window->IsClosed())
window->CloseImmediately(); window->CloseImmediately();
} }
} }