fix: titlebar and buttons state under simple fullscreen (#30671)
This commit is contained in:
parent
a9983c1d06
commit
00d65eb9ac
3 changed files with 85 additions and 59 deletions
|
@ -1006,6 +1006,13 @@ void NativeWindowMac::SetSimpleFullScreen(bool simple_fullscreen) {
|
||||||
window.level = NSPopUpMenuWindowLevel;
|
window.level = NSPopUpMenuWindowLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Always hide the titlebar in simple fullscreen mode.
|
||||||
|
//
|
||||||
|
// Note that we must remove the NSWindowStyleMaskTitled style instead of
|
||||||
|
// using the [window_ setTitleVisibility:], as the latter would leave the
|
||||||
|
// window with rounded corners.
|
||||||
|
SetStyleMask(false, NSWindowStyleMaskTitled);
|
||||||
|
|
||||||
if (!window_button_visibility_.has_value()) {
|
if (!window_button_visibility_.has_value()) {
|
||||||
// Lets keep previous behaviour - hide window controls in titled
|
// Lets keep previous behaviour - hide window controls in titled
|
||||||
// fullscreen mode when not specified otherwise.
|
// fullscreen mode when not specified otherwise.
|
||||||
|
@ -1022,16 +1029,6 @@ void NativeWindowMac::SetSimpleFullScreen(bool simple_fullscreen) {
|
||||||
} else if (!simple_fullscreen && is_simple_fullscreen_) {
|
} else if (!simple_fullscreen && is_simple_fullscreen_) {
|
||||||
is_simple_fullscreen_ = false;
|
is_simple_fullscreen_ = false;
|
||||||
|
|
||||||
// Restore default window controls visibility state.
|
|
||||||
if (!window_button_visibility_.has_value()) {
|
|
||||||
bool visibility;
|
|
||||||
if (has_frame())
|
|
||||||
visibility = true;
|
|
||||||
else
|
|
||||||
visibility = title_bar_style_ != TitleBarStyle::kNormal;
|
|
||||||
InternalSetWindowButtonVisibility(visibility);
|
|
||||||
}
|
|
||||||
|
|
||||||
[window setFrame:original_frame_ display:YES animate:YES];
|
[window setFrame:original_frame_ display:YES animate:YES];
|
||||||
window.level = original_level_;
|
window.level = original_level_;
|
||||||
|
|
||||||
|
@ -1044,6 +1041,19 @@ void NativeWindowMac::SetSimpleFullScreen(bool simple_fullscreen) {
|
||||||
// Restore window manipulation abilities
|
// Restore window manipulation abilities
|
||||||
SetMaximizable(was_maximizable_);
|
SetMaximizable(was_maximizable_);
|
||||||
SetMovable(was_movable_);
|
SetMovable(was_movable_);
|
||||||
|
|
||||||
|
// Restore default window controls visibility state.
|
||||||
|
if (!window_button_visibility_.has_value()) {
|
||||||
|
bool visibility;
|
||||||
|
if (has_frame())
|
||||||
|
visibility = true;
|
||||||
|
else
|
||||||
|
visibility = title_bar_style_ != TitleBarStyle::kNormal;
|
||||||
|
InternalSetWindowButtonVisibility(visibility);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buttons_proxy_)
|
||||||
|
[buttons_proxy_ redraw];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,13 +25,6 @@
|
||||||
@interface WindowButtonsProxy : NSObject {
|
@interface WindowButtonsProxy : NSObject {
|
||||||
@private
|
@private
|
||||||
NSWindow* window_;
|
NSWindow* window_;
|
||||||
// The view that contains the window buttons and title.
|
|
||||||
NSView* titlebar_container_;
|
|
||||||
|
|
||||||
// The window buttons.
|
|
||||||
NSButton* left_;
|
|
||||||
NSButton* right_;
|
|
||||||
NSButton* middle_;
|
|
||||||
|
|
||||||
// Current left-top margin of buttons.
|
// Current left-top margin of buttons.
|
||||||
gfx::Point margin_;
|
gfx::Point margin_;
|
||||||
|
|
|
@ -34,25 +34,6 @@
|
||||||
show_on_hover_ = NO;
|
show_on_hover_ = NO;
|
||||||
mouse_inside_ = NO;
|
mouse_inside_ = NO;
|
||||||
|
|
||||||
// Save the sequence of the buttons for later computation.
|
|
||||||
if (base::i18n::IsRTL()) {
|
|
||||||
left_ = [window_ standardWindowButton:NSWindowZoomButton];
|
|
||||||
right_ = [window_ standardWindowButton:NSWindowCloseButton];
|
|
||||||
} else {
|
|
||||||
left_ = [window_ standardWindowButton:NSWindowCloseButton];
|
|
||||||
right_ = [window_ standardWindowButton:NSWindowZoomButton];
|
|
||||||
}
|
|
||||||
middle_ = [window_ standardWindowButton:NSWindowMiniaturizeButton];
|
|
||||||
|
|
||||||
// Safety check just in case Apple changes the view structure in a macOS
|
|
||||||
// upgrade.
|
|
||||||
if (!left_.superview || !left_.superview.superview) {
|
|
||||||
NOTREACHED() << "macOS has changed its window buttons view structure.";
|
|
||||||
titlebar_container_ = nullptr;
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
titlebar_container_ = left_.superview.superview;
|
|
||||||
|
|
||||||
// Remember the default margin.
|
// Remember the default margin.
|
||||||
margin_ = default_margin_ = [self getCurrentMargin];
|
margin_ = default_margin_ = [self getCurrentMargin];
|
||||||
|
|
||||||
|
@ -66,19 +47,22 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setVisible:(BOOL)visible {
|
- (void)setVisible:(BOOL)visible {
|
||||||
if (!titlebar_container_)
|
NSView* titleBarContainer = [self titleBarContainer];
|
||||||
|
if (!titleBarContainer)
|
||||||
return;
|
return;
|
||||||
[titlebar_container_ setHidden:!visible];
|
[titleBarContainer setHidden:!visible];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)isVisible {
|
- (BOOL)isVisible {
|
||||||
if (!titlebar_container_)
|
NSView* titleBarContainer = [self titleBarContainer];
|
||||||
|
if (!titleBarContainer)
|
||||||
return YES;
|
return YES;
|
||||||
return ![titlebar_container_ isHidden];
|
return ![titleBarContainer isHidden];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setShowOnHover:(BOOL)yes {
|
- (void)setShowOnHover:(BOOL)yes {
|
||||||
if (!titlebar_container_)
|
NSView* titleBarContainer = [self titleBarContainer];
|
||||||
|
if (!titleBarContainer)
|
||||||
return;
|
return;
|
||||||
show_on_hover_ = yes;
|
show_on_hover_ = yes;
|
||||||
// Put a transparent view above the window buttons so we can track mouse
|
// Put a transparent view above the window buttons so we can track mouse
|
||||||
|
@ -86,7 +70,7 @@
|
||||||
if (show_on_hover_) {
|
if (show_on_hover_) {
|
||||||
hover_view_.reset([[ButtonsAreaHoverView alloc] initWithProxy:self]);
|
hover_view_.reset([[ButtonsAreaHoverView alloc] initWithProxy:self]);
|
||||||
[hover_view_ setFrame:[self getButtonsBounds]];
|
[hover_view_ setFrame:[self getButtonsBounds]];
|
||||||
[titlebar_container_ addSubview:hover_view_.get()];
|
[titleBarContainer addSubview:hover_view_.get()];
|
||||||
} else {
|
} else {
|
||||||
[hover_view_ removeFromSuperview];
|
[hover_view_ removeFromSuperview];
|
||||||
hover_view_.reset();
|
hover_view_.reset();
|
||||||
|
@ -107,12 +91,17 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)redraw {
|
- (void)redraw {
|
||||||
if (!titlebar_container_)
|
NSView* titleBarContainer = [self titleBarContainer];
|
||||||
|
if (!titleBarContainer)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
float button_width = NSWidth(left_.frame);
|
NSView* left = [self leftButton];
|
||||||
float button_height = NSHeight(left_.frame);
|
NSView* middle = [self middleButton];
|
||||||
float padding = NSMinX(middle_.frame) - NSMaxX(left_.frame);
|
NSView* right = [self rightButton];
|
||||||
|
|
||||||
|
float button_width = NSWidth(left.frame);
|
||||||
|
float button_height = NSHeight(left.frame);
|
||||||
|
float padding = NSMinX(middle.frame) - NSMaxX(left.frame);
|
||||||
float start;
|
float start;
|
||||||
if (base::i18n::IsRTL())
|
if (base::i18n::IsRTL())
|
||||||
start =
|
start =
|
||||||
|
@ -120,16 +109,16 @@
|
||||||
else
|
else
|
||||||
start = margin_.x();
|
start = margin_.x();
|
||||||
|
|
||||||
NSRect cbounds = titlebar_container_.frame;
|
NSRect cbounds = titleBarContainer.frame;
|
||||||
cbounds.size.height = button_height + 2 * margin_.y();
|
cbounds.size.height = button_height + 2 * margin_.y();
|
||||||
cbounds.origin.y = NSHeight(window_.frame) - NSHeight(cbounds);
|
cbounds.origin.y = NSHeight(window_.frame) - NSHeight(cbounds);
|
||||||
[titlebar_container_ setFrame:cbounds];
|
[titleBarContainer setFrame:cbounds];
|
||||||
|
|
||||||
[left_ setFrameOrigin:NSMakePoint(start, margin_.y())];
|
[left setFrameOrigin:NSMakePoint(start, margin_.y())];
|
||||||
start += button_width + padding;
|
start += button_width + padding;
|
||||||
[middle_ setFrameOrigin:NSMakePoint(start, margin_.y())];
|
[middle setFrameOrigin:NSMakePoint(start, margin_.y())];
|
||||||
start += button_width + padding;
|
start += button_width + padding;
|
||||||
[right_ setFrameOrigin:NSMakePoint(start, margin_.y())];
|
[right setFrameOrigin:NSMakePoint(start, margin_.y())];
|
||||||
|
|
||||||
if (hover_view_)
|
if (hover_view_)
|
||||||
[hover_view_ setFrame:[self getButtonsBounds]];
|
[hover_view_ setFrame:[self getButtonsBounds]];
|
||||||
|
@ -176,25 +165,59 @@
|
||||||
|
|
||||||
// Return the bounds of all 3 buttons.
|
// Return the bounds of all 3 buttons.
|
||||||
- (NSRect)getButtonsBounds {
|
- (NSRect)getButtonsBounds {
|
||||||
return NSMakeRect(NSMinX(left_.frame), NSMinY(left_.frame),
|
NSView* left = [self leftButton];
|
||||||
NSMaxX(right_.frame) - NSMinX(left_.frame),
|
NSView* right = [self rightButton];
|
||||||
NSHeight(left_.frame));
|
return NSMakeRect(NSMinX(left.frame), NSMinY(left.frame),
|
||||||
|
NSMaxX(right.frame) - NSMinX(left.frame),
|
||||||
|
NSHeight(left.frame));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute margin from position of current buttons.
|
// Compute margin from position of current buttons.
|
||||||
- (gfx::Point)getCurrentMargin {
|
- (gfx::Point)getCurrentMargin {
|
||||||
gfx::Point result;
|
gfx::Point result;
|
||||||
if (!titlebar_container_)
|
NSView* titleBarContainer = [self titleBarContainer];
|
||||||
|
if (!titleBarContainer)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
result.set_y((NSHeight(titlebar_container_.frame) - NSHeight(left_.frame)) /
|
NSView* left = [self leftButton];
|
||||||
2);
|
NSView* right = [self rightButton];
|
||||||
|
|
||||||
|
result.set_y((NSHeight(titleBarContainer.frame) - NSHeight(left.frame)) / 2);
|
||||||
|
|
||||||
if (base::i18n::IsRTL())
|
if (base::i18n::IsRTL())
|
||||||
result.set_x(NSWidth(window_.frame) - NSMaxX(right_.frame));
|
result.set_x(NSWidth(window_.frame) - NSMaxX(right.frame));
|
||||||
else
|
else
|
||||||
result.set_x(NSMinX(left_.frame));
|
result.set_x(NSMinX(left.frame));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Receive the titlebar container, which might be nil if the window does not
|
||||||
|
// have the NSWindowStyleMaskTitled style.
|
||||||
|
- (NSView*)titleBarContainer {
|
||||||
|
NSView* left = [self leftButton];
|
||||||
|
if (!left.superview)
|
||||||
|
return nil;
|
||||||
|
return left.superview.superview;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Receive the window buttons, note that the buttons might be removed and
|
||||||
|
// re-added on the fly so we should not cache them.
|
||||||
|
- (NSButton*)leftButton {
|
||||||
|
if (base::i18n::IsRTL())
|
||||||
|
return [window_ standardWindowButton:NSWindowZoomButton];
|
||||||
|
else
|
||||||
|
return [window_ standardWindowButton:NSWindowCloseButton];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSButton*)middleButton {
|
||||||
|
return [window_ standardWindowButton:NSWindowMiniaturizeButton];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSButton*)rightButton {
|
||||||
|
if (base::i18n::IsRTL())
|
||||||
|
return [window_ standardWindowButton:NSWindowCloseButton];
|
||||||
|
else
|
||||||
|
return [window_ standardWindowButton:NSWindowZoomButton];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Reference in a new issue