refactor: make NativeWindow::has_frame_
const (#47200)
* refactor: make NativeWindow::is_modal_ const * refactor: make NativeWindow::title_bar_style_ const and private * refactor: make NativeWindow::has_client_frame() protected refactor: make NativeWindow::transparent() protected * refactor: make NativeWindow::enable_larger_than_screen() protected * refactor: make NativeWindow::has_frame_ const * fixup! refactor: make NativeWindow::has_client_frame() protected fix: GetExpandedWindowSize()
This commit is contained in:
parent
8f09d7037b
commit
38e7ff944e
4 changed files with 52 additions and 56 deletions
|
@ -75,10 +75,12 @@ namespace electron {
|
|||
namespace {
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
gfx::Size GetExpandedWindowSize(const NativeWindow* window, gfx::Size size) {
|
||||
gfx::Size GetExpandedWindowSize(const NativeWindow* window,
|
||||
bool transparent,
|
||||
gfx::Size size) {
|
||||
if (!base::FeatureList::IsEnabled(
|
||||
views::features::kEnableTransparentHwndEnlargement) ||
|
||||
!window->transparent()) {
|
||||
!transparent) {
|
||||
return size;
|
||||
}
|
||||
|
||||
|
@ -97,12 +99,15 @@ gfx::Size GetExpandedWindowSize(const NativeWindow* window, gfx::Size size) {
|
|||
|
||||
NativeWindow::NativeWindow(const gin_helper::Dictionary& options,
|
||||
NativeWindow* parent)
|
||||
: transparent_{options.ValueOrDefault(options::kTransparent, false)},
|
||||
: title_bar_style_{options.ValueOrDefault(options::kTitleBarStyle,
|
||||
TitleBarStyle::kNormal)},
|
||||
transparent_{options.ValueOrDefault(options::kTransparent, false)},
|
||||
enable_larger_than_screen_{
|
||||
options.ValueOrDefault(options::kEnableLargerThanScreen, false)},
|
||||
is_modal_{parent != nullptr && options.ValueOrDefault("modal", false)},
|
||||
has_frame_{options.ValueOrDefault(options::kFrame, true) &&
|
||||
title_bar_style_ == TitleBarStyle::kNormal},
|
||||
parent_{parent} {
|
||||
options.Get(options::kFrame, &has_frame_);
|
||||
options.Get(options::kTitleBarStyle, &title_bar_style_);
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
options.Get(options::kBackgroundMaterial, &background_material_);
|
||||
#elif BUILDFLAG(IS_MAC)
|
||||
|
@ -125,9 +130,6 @@ NativeWindow::NativeWindow(const gin_helper::Dictionary& options,
|
|||
}
|
||||
}
|
||||
|
||||
if (parent)
|
||||
options.Get("modal", &is_modal_);
|
||||
|
||||
WindowList::AddWindow(this);
|
||||
}
|
||||
|
||||
|
@ -407,14 +409,15 @@ gfx::Size NativeWindow::GetContentMinimumSize() const {
|
|||
}
|
||||
|
||||
gfx::Size NativeWindow::GetContentMaximumSize() const {
|
||||
gfx::Size maximum_size = GetContentSizeConstraints().GetMaximumSize();
|
||||
const auto size_constraints = GetContentSizeConstraints();
|
||||
gfx::Size maximum_size = size_constraints.GetMaximumSize();
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
return GetContentSizeConstraints().HasMaximumSize()
|
||||
? GetExpandedWindowSize(this, maximum_size)
|
||||
: maximum_size;
|
||||
#else
|
||||
return maximum_size;
|
||||
if (size_constraints.HasMaximumSize())
|
||||
maximum_size = GetExpandedWindowSize(this, transparent(), maximum_size);
|
||||
#endif
|
||||
|
||||
return maximum_size;
|
||||
}
|
||||
|
||||
void NativeWindow::SetSheetOffset(const double offsetX, const double offsetY) {
|
||||
|
|
|
@ -374,14 +374,16 @@ class NativeWindow : public base::SupportsUserData,
|
|||
views::Widget* widget() const { return widget_.get(); }
|
||||
views::View* content_view() const { return content_view_; }
|
||||
|
||||
enum class TitleBarStyle {
|
||||
enum class TitleBarStyle : uint8_t {
|
||||
kNormal,
|
||||
kHidden,
|
||||
kHiddenInset,
|
||||
kCustomButtonsOnHover,
|
||||
};
|
||||
|
||||
TitleBarStyle title_bar_style() const { return title_bar_style_; }
|
||||
[[nodiscard]] TitleBarStyle title_bar_style() const {
|
||||
return title_bar_style_;
|
||||
}
|
||||
|
||||
bool IsWindowControlsOverlayEnabled() const {
|
||||
bool valid_titlebar_style = title_bar_style() == TitleBarStyle::kHidden
|
||||
|
@ -395,18 +397,11 @@ class NativeWindow : public base::SupportsUserData,
|
|||
|
||||
int titlebar_overlay_height() const { return titlebar_overlay_height_; }
|
||||
|
||||
bool has_frame() const { return has_frame_; }
|
||||
|
||||
[[nodiscard]] bool has_client_frame() const { return has_client_frame_; }
|
||||
|
||||
[[nodiscard]] bool transparent() const { return transparent_; }
|
||||
|
||||
[[nodiscard]] bool enable_larger_than_screen() const {
|
||||
return enable_larger_than_screen_;
|
||||
}
|
||||
[[nodiscard]] bool has_frame() const { return has_frame_; }
|
||||
|
||||
NativeWindow* parent() const { return parent_; }
|
||||
bool is_modal() const { return is_modal_; }
|
||||
|
||||
[[nodiscard]] bool is_modal() const { return is_modal_; }
|
||||
|
||||
[[nodiscard]] constexpr int32_t window_id() const { return window_id_; }
|
||||
|
||||
|
@ -432,15 +427,21 @@ class NativeWindow : public base::SupportsUserData,
|
|||
void UpdateBackgroundThrottlingState();
|
||||
|
||||
protected:
|
||||
NativeWindow(const gin_helper::Dictionary& options, NativeWindow* parent);
|
||||
|
||||
void set_titlebar_overlay_height(int height) {
|
||||
titlebar_overlay_height_ = height;
|
||||
}
|
||||
|
||||
constexpr void set_has_frame(const bool val) { has_frame_ = val; }
|
||||
[[nodiscard]] bool has_client_frame() const { return has_client_frame_; }
|
||||
|
||||
[[nodiscard]] constexpr bool is_closed() const { return is_closed_; }
|
||||
[[nodiscard]] bool transparent() const { return transparent_; }
|
||||
|
||||
NativeWindow(const gin_helper::Dictionary& options, NativeWindow* parent);
|
||||
[[nodiscard]] bool is_closed() const { return is_closed_; }
|
||||
|
||||
[[nodiscard]] bool enable_larger_than_screen() const {
|
||||
return enable_larger_than_screen_;
|
||||
}
|
||||
|
||||
virtual void OnTitleChanged() {}
|
||||
|
||||
|
@ -465,9 +466,6 @@ class NativeWindow : public base::SupportsUserData,
|
|||
// The boolean parsing of the "titleBarOverlay" option
|
||||
bool titlebar_overlay_ = false;
|
||||
|
||||
// The "titleBarStyle" option.
|
||||
TitleBarStyle title_bar_style_ = TitleBarStyle::kNormal;
|
||||
|
||||
// Minimum and maximum size.
|
||||
std::optional<extensions::SizeConstraints> size_constraints_;
|
||||
// Same as above but stored as content size, we are storing 2 types of size
|
||||
|
@ -490,12 +488,26 @@ class NativeWindow : public base::SupportsUserData,
|
|||
static inline int32_t next_id_ = 0;
|
||||
const int32_t window_id_ = ++next_id_;
|
||||
|
||||
// The "titleBarStyle" option.
|
||||
const TitleBarStyle title_bar_style_;
|
||||
|
||||
// Whether window has standard frame, but it's drawn by Electron (the client
|
||||
// application) instead of the OS. Currently only has meaning on Linux for
|
||||
// Wayland hosts.
|
||||
const bool has_client_frame_ = PlatformHasClientFrame();
|
||||
|
||||
// Whether window is transparent.
|
||||
const bool transparent_;
|
||||
|
||||
// Whether window can be resized larger than screen.
|
||||
const bool enable_larger_than_screen_;
|
||||
|
||||
// Is this a modal window.
|
||||
const bool is_modal_;
|
||||
|
||||
// Whether window has standard frame.
|
||||
const bool has_frame_;
|
||||
|
||||
// The content view, weak ref.
|
||||
raw_ptr<views::View> content_view_ = nullptr;
|
||||
|
||||
|
@ -503,14 +515,6 @@ class NativeWindow : public base::SupportsUserData,
|
|||
// "titleBarOverlay"
|
||||
int titlebar_overlay_height_ = 0;
|
||||
|
||||
// Whether window has standard frame.
|
||||
bool has_frame_ = true;
|
||||
|
||||
// Whether window has standard frame, but it's drawn by Electron (the client
|
||||
// application) instead of the OS. Currently only has meaning on Linux for
|
||||
// Wayland hosts.
|
||||
const bool has_client_frame_ = PlatformHasClientFrame();
|
||||
|
||||
// The windows has been closed.
|
||||
bool is_closed_ = false;
|
||||
|
||||
|
@ -527,9 +531,6 @@ class NativeWindow : public base::SupportsUserData,
|
|||
// The parent window, it is guaranteed to be valid during this window's life.
|
||||
raw_ptr<NativeWindow> parent_ = nullptr;
|
||||
|
||||
// Is this a modal window.
|
||||
bool is_modal_ = false;
|
||||
|
||||
bool is_transitioning_fullscreen_ = false;
|
||||
|
||||
std::list<DraggableRegionProvider*> draggable_region_providers_;
|
||||
|
|
|
@ -151,10 +151,6 @@ NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options,
|
|||
const bool paint_when_initially_hidden =
|
||||
options.ValueOrDefault(options::kPaintWhenInitiallyHidden, true);
|
||||
|
||||
// The window without titlebar is treated the same with frameless window.
|
||||
if (title_bar_style_ != TitleBarStyle::kNormal)
|
||||
set_has_frame(false);
|
||||
|
||||
NSUInteger styleMask = NSWindowStyleMaskTitled;
|
||||
|
||||
// The NSWindowStyleMaskFullSizeContentView style removes rounded corners
|
||||
|
@ -252,20 +248,20 @@ NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options,
|
|||
// https://github.com/electron/electron/issues/517.
|
||||
[window_ setOpaque:NO];
|
||||
// Show window buttons if titleBarStyle is not "normal".
|
||||
if (title_bar_style_ == TitleBarStyle::kNormal) {
|
||||
if (title_bar_style() == TitleBarStyle::kNormal) {
|
||||
InternalSetWindowButtonVisibility(false);
|
||||
} else {
|
||||
buttons_proxy_ = [[WindowButtonsProxy alloc] initWithWindow:window_];
|
||||
[buttons_proxy_ setHeight:titlebar_overlay_height()];
|
||||
if (traffic_light_position_) {
|
||||
[buttons_proxy_ setMargin:*traffic_light_position_];
|
||||
} else if (title_bar_style_ == TitleBarStyle::kHiddenInset) {
|
||||
} else if (title_bar_style() == TitleBarStyle::kHiddenInset) {
|
||||
// For macOS >= 11, while this value does not match official macOS apps
|
||||
// like Safari or Notes, it matches titleBarStyle's old implementation
|
||||
// before Electron <= 12.
|
||||
[buttons_proxy_ setMargin:gfx::Point(12, 11)];
|
||||
}
|
||||
if (title_bar_style_ == TitleBarStyle::kCustomButtonsOnHover) {
|
||||
if (title_bar_style() == TitleBarStyle::kCustomButtonsOnHover) {
|
||||
[buttons_proxy_ setShowOnHover:YES];
|
||||
} else {
|
||||
// customButtonsOnHover does not show buttons initially.
|
||||
|
@ -1053,7 +1049,7 @@ void NativeWindowMac::SetSimpleFullScreen(bool simple_fullscreen) {
|
|||
if (has_frame())
|
||||
visibility = true;
|
||||
else
|
||||
visibility = title_bar_style_ != TitleBarStyle::kNormal;
|
||||
visibility = title_bar_style() != TitleBarStyle::kNormal;
|
||||
InternalSetWindowButtonVisibility(visibility);
|
||||
}
|
||||
|
||||
|
@ -1481,7 +1477,7 @@ void NativeWindowMac::SetWindowButtonVisibility(bool visible) {
|
|||
[buttons_proxy_ setVisible:visible];
|
||||
}
|
||||
|
||||
if (title_bar_style_ != TitleBarStyle::kCustomButtonsOnHover)
|
||||
if (title_bar_style() != TitleBarStyle::kCustomButtonsOnHover)
|
||||
InternalSetWindowButtonVisibility(visible);
|
||||
|
||||
NotifyLayoutWindowControlsOverlay();
|
||||
|
|
|
@ -241,10 +241,6 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options,
|
|||
}
|
||||
}
|
||||
|
||||
// |hidden| is the only non-default titleBarStyle valid on Windows and Linux.
|
||||
if (title_bar_style_ == TitleBarStyle::kHidden)
|
||||
set_has_frame(false);
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
// If the taskbar is re-created after we start up, we have to rebuild all of
|
||||
// our buttons.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue