fix: WCO respects maximizable/closable/minimizable (#34677)
This commit is contained in:
parent
106aa0e922
commit
3b881e4a13
4 changed files with 44 additions and 6 deletions
|
@ -876,6 +876,11 @@ bool NativeWindowViews::IsMovable() {
|
||||||
void NativeWindowViews::SetMinimizable(bool minimizable) {
|
void NativeWindowViews::SetMinimizable(bool minimizable) {
|
||||||
#if BUILDFLAG(IS_WIN)
|
#if BUILDFLAG(IS_WIN)
|
||||||
FlipWindowStyle(GetAcceleratedWidget(), minimizable, WS_MINIMIZEBOX);
|
FlipWindowStyle(GetAcceleratedWidget(), minimizable, WS_MINIMIZEBOX);
|
||||||
|
if (titlebar_overlay_enabled()) {
|
||||||
|
auto* frame_view =
|
||||||
|
static_cast<WinFrameView*>(widget()->non_client_view()->frame_view());
|
||||||
|
frame_view->caption_button_container()->UpdateButtons();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
minimizable_ = minimizable;
|
minimizable_ = minimizable;
|
||||||
}
|
}
|
||||||
|
@ -891,6 +896,11 @@ bool NativeWindowViews::IsMinimizable() {
|
||||||
void NativeWindowViews::SetMaximizable(bool maximizable) {
|
void NativeWindowViews::SetMaximizable(bool maximizable) {
|
||||||
#if BUILDFLAG(IS_WIN)
|
#if BUILDFLAG(IS_WIN)
|
||||||
FlipWindowStyle(GetAcceleratedWidget(), maximizable, WS_MAXIMIZEBOX);
|
FlipWindowStyle(GetAcceleratedWidget(), maximizable, WS_MAXIMIZEBOX);
|
||||||
|
if (titlebar_overlay_enabled()) {
|
||||||
|
auto* frame_view =
|
||||||
|
static_cast<WinFrameView*>(widget()->non_client_view()->frame_view());
|
||||||
|
frame_view->caption_button_container()->UpdateButtons();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
maximizable_ = maximizable;
|
maximizable_ = maximizable;
|
||||||
}
|
}
|
||||||
|
@ -926,6 +936,11 @@ void NativeWindowViews::SetClosable(bool closable) {
|
||||||
} else {
|
} else {
|
||||||
EnableMenuItem(menu, SC_CLOSE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
|
EnableMenuItem(menu, SC_CLOSE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
|
||||||
}
|
}
|
||||||
|
if (titlebar_overlay_enabled()) {
|
||||||
|
auto* frame_view =
|
||||||
|
static_cast<WinFrameView*>(widget()->non_client_view()->frame_view());
|
||||||
|
frame_view->caption_button_container()->UpdateButtons();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,11 +148,30 @@ void WinCaptionButtonContainer::UpdateButtons() {
|
||||||
restore_button_->SetVisible(is_maximized);
|
restore_button_->SetVisible(is_maximized);
|
||||||
maximize_button_->SetVisible(!is_maximized);
|
maximize_button_->SetVisible(!is_maximized);
|
||||||
|
|
||||||
|
const bool minimizable = frame_view_->window()->IsMinimizable();
|
||||||
|
minimize_button_->SetEnabled(minimizable);
|
||||||
|
|
||||||
// In touch mode, windows cannot be taken out of fullscreen or tiled mode, so
|
// In touch mode, windows cannot be taken out of fullscreen or tiled mode, so
|
||||||
// the maximize/restore button should be disabled.
|
// the maximize/restore button should be disabled.
|
||||||
const bool is_touch = ui::TouchUiController::Get()->touch_ui();
|
const bool is_touch = ui::TouchUiController::Get()->touch_ui();
|
||||||
restore_button_->SetEnabled(!is_touch);
|
restore_button_->SetEnabled(!is_touch);
|
||||||
maximize_button_->SetEnabled(!is_touch);
|
|
||||||
|
// The maximize button should only be enabled if the window is
|
||||||
|
// maximizable *and* touch mode is disabled.
|
||||||
|
const bool maximizable = frame_view_->window()->IsMaximizable();
|
||||||
|
maximize_button_->SetEnabled(!is_touch && maximizable);
|
||||||
|
|
||||||
|
const bool closable = frame_view_->window()->IsClosable();
|
||||||
|
close_button_->SetEnabled(closable);
|
||||||
|
|
||||||
|
// If all three of closable, maximizable, and minimizable are disabled,
|
||||||
|
// Windows natively only shows the disabled closable button. Copy that
|
||||||
|
// behavior here.
|
||||||
|
if (!maximizable && !closable && !minimizable) {
|
||||||
|
minimize_button_->SetVisible(false);
|
||||||
|
maximize_button_->SetVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
InvalidateLayout();
|
InvalidateLayout();
|
||||||
}
|
}
|
||||||
} // namespace electron
|
} // namespace electron
|
||||||
|
|
|
@ -41,6 +41,11 @@ class WinCaptionButtonContainer : public views::View,
|
||||||
gfx::Size GetButtonSize() const;
|
gfx::Size GetButtonSize() const;
|
||||||
void SetButtonSize(gfx::Size size);
|
void SetButtonSize(gfx::Size size);
|
||||||
|
|
||||||
|
// Sets caption button visibility and enabled state based on window state.
|
||||||
|
// Only one of maximize or restore button should ever be visible at the same
|
||||||
|
// time, and both are disabled in tablet UI mode.
|
||||||
|
void UpdateButtons();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// views::View:
|
// views::View:
|
||||||
void AddedToWidget() override;
|
void AddedToWidget() override;
|
||||||
|
@ -52,11 +57,6 @@ class WinCaptionButtonContainer : public views::View,
|
||||||
|
|
||||||
void ResetWindowControls();
|
void ResetWindowControls();
|
||||||
|
|
||||||
// Sets caption button visibility and enabled state based on window state.
|
|
||||||
// Only one of maximize or restore button should ever be visible at the same
|
|
||||||
// time, and both are disabled in tablet UI mode.
|
|
||||||
void UpdateButtons();
|
|
||||||
|
|
||||||
WinFrameView* const frame_view_;
|
WinFrameView* const frame_view_;
|
||||||
WinCaptionButton* const minimize_button_;
|
WinCaptionButton* const minimize_button_;
|
||||||
WinCaptionButton* const maximize_button_;
|
WinCaptionButton* const maximize_button_;
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "shell/browser/native_window_views.h"
|
#include "shell/browser/native_window_views.h"
|
||||||
#include "shell/browser/ui/views/frameless_view.h"
|
#include "shell/browser/ui/views/frameless_view.h"
|
||||||
#include "shell/browser/ui/views/win_caption_button.h"
|
#include "shell/browser/ui/views/win_caption_button.h"
|
||||||
|
#include "shell/browser/ui/views/win_caption_button_container.h"
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
|
||||||
|
@ -43,6 +44,9 @@ class WinFrameView : public FramelessView {
|
||||||
|
|
||||||
NativeWindowViews* window() const { return window_; }
|
NativeWindowViews* window() const { return window_; }
|
||||||
views::Widget* frame() const { return frame_; }
|
views::Widget* frame() const { return frame_; }
|
||||||
|
WinCaptionButtonContainer* caption_button_container() {
|
||||||
|
return caption_button_container_;
|
||||||
|
}
|
||||||
|
|
||||||
bool IsMaximized() const;
|
bool IsMaximized() const;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue