forked from chromiumembedded/cef
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
views: mac: Fix frameless window behavior (fixes issue chromiumembedd…
…ed#3189) Frameless windows now display as expected. Default traffic light buttons can optionally be shown at configurable vertical position. Layout respects text direction.
- Loading branch information
1 parent
42f351a
commit 276423d
Showing
22 changed files
with
581 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2023 The Chromium Embedded Framework Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be found | ||
// in the LICENSE file. | ||
|
||
#ifndef CEF_LIBCEF_BROWSER_VIEWS_NATIVE_WIDGET_MAC_H_ | ||
#define CEF_LIBCEF_BROWSER_VIEWS_NATIVE_WIDGET_MAC_H_ | ||
#pragma once | ||
|
||
#include "third_party/abseil-cpp/absl/types/optional.h" | ||
#include "ui/views/widget/native_widget_mac.h" | ||
|
||
class CefNativeWidgetMac : public views::NativeWidgetMac { | ||
public: | ||
CefNativeWidgetMac(views::internal::NativeWidgetDelegate* delegate, | ||
bool is_frameless, | ||
bool with_window_buttons, | ||
absl::optional<float> title_bar_height); | ||
~CefNativeWidgetMac() override = default; | ||
|
||
CefNativeWidgetMac(const CefNativeWidgetMac&) = delete; | ||
CefNativeWidgetMac& operator=(const CefNativeWidgetMac&) = delete; | ||
|
||
protected: | ||
// NativeWidgetMac: | ||
NativeWidgetMacNSWindow* CreateNSWindow( | ||
const remote_cocoa::mojom::CreateWindowParams* params) override; | ||
|
||
void GetWindowFrameTitlebarHeight(bool* override_titlebar_height, | ||
float* titlebar_height) override; | ||
|
||
private: | ||
const bool is_frameless_; | ||
const bool with_window_buttons_; | ||
const absl::optional<float> title_bar_height_; | ||
}; | ||
|
||
#endif // CEF_LIBCEF_BROWSER_VIEWS_NATIVE_WIDGET_MAC_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2023 The Chromium Embedded Framework Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be found | ||
// in the LICENSE file. | ||
|
||
#include "libcef/browser/views/native_widget_mac.h" | ||
|
||
#include "libcef/browser/views/ns_window.h" | ||
|
||
CefNativeWidgetMac::CefNativeWidgetMac( | ||
views::internal::NativeWidgetDelegate* delegate, | ||
bool is_frameless, | ||
bool with_window_buttons, | ||
absl::optional<float> title_bar_height) | ||
: views::NativeWidgetMac(delegate), | ||
is_frameless_(is_frameless), | ||
with_window_buttons_(with_window_buttons), | ||
title_bar_height_(title_bar_height) {} | ||
|
||
NativeWidgetMacNSWindow* CefNativeWidgetMac::CreateNSWindow( | ||
const remote_cocoa::mojom::CreateWindowParams* params) { | ||
NSUInteger style_mask = | ||
NSWindowStyleMaskTitled | NSWindowStyleMaskMiniaturizable | | ||
NSWindowStyleMaskClosable | NSWindowStyleMaskResizable | | ||
NSWindowStyleMaskTexturedBackground; | ||
auto window = [[CefNSWindow alloc] initWithStyle:style_mask | ||
isFrameless:is_frameless_]; | ||
|
||
if (is_frameless_) { | ||
[window setTitlebarAppearsTransparent:YES]; | ||
[window setTitleVisibility:NSWindowTitleHidden]; | ||
} | ||
|
||
if (!with_window_buttons_) { | ||
[[window standardWindowButton:NSWindowCloseButton] setHidden:YES]; | ||
[[window standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES]; | ||
[[window standardWindowButton:NSWindowZoomButton] setHidden:YES]; | ||
} | ||
|
||
return window; | ||
} | ||
|
||
void CefNativeWidgetMac::GetWindowFrameTitlebarHeight( | ||
bool* override_titlebar_height, | ||
float* titlebar_height) { | ||
if (title_bar_height_) { | ||
*override_titlebar_height = true; | ||
*titlebar_height = title_bar_height_.value(); | ||
} else { | ||
views::NativeWidgetMac::GetWindowFrameTitlebarHeight( | ||
override_titlebar_height, titlebar_height); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2023 The Chromium Embedded Framework Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be found | ||
// in the LICENSE file. | ||
|
||
#ifndef CEF_LIBCEF_BROWSER_VIEWS_NS_WINDOW_H_ | ||
#define CEF_LIBCEF_BROWSER_VIEWS_NS_WINDOW_H_ | ||
#pragma once | ||
|
||
#include "components/remote_cocoa/app_shim/native_widget_mac_nswindow.h" | ||
|
||
@interface CefNSWindow : NativeWidgetMacNSWindow { | ||
@private | ||
bool is_frameless_; | ||
} | ||
- (id)initWithStyle:(NSUInteger)style_mask isFrameless:(bool)is_frameless; | ||
|
||
- (BOOL)shouldCenterTrafficLights; | ||
@end | ||
|
||
#endif // CEF_LIBCEF_BROWSER_VIEWS_NS_WINDOW_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// Copyright 2023 The Chromium Embedded Framework Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be found | ||
// in the LICENSE file. | ||
|
||
#include "libcef/browser/views/ns_window.h" | ||
|
||
#include "base/i18n/rtl.h" | ||
#include "components/remote_cocoa/app_shim/native_widget_ns_window_bridge.h" | ||
#include "components/remote_cocoa/common/native_widget_ns_window_host.mojom.h" | ||
#include "ui/base/cocoa/window_size_constants.h" | ||
|
||
@interface CefThemeFrame : NativeWidgetMacNSWindowTitledFrame | ||
@end | ||
|
||
// NSThemeFrame (PrivateAPI) definitions. | ||
@interface NSThemeFrame (PrivateAPI) | ||
- (void)setStyleMask:(NSUInteger)styleMask; | ||
- (CGFloat)_titlebarHeight; | ||
- (BOOL)_shouldCenterTrafficLights; | ||
@end | ||
|
||
@implementation CefThemeFrame { | ||
bool in_full_screen_; | ||
} | ||
|
||
// NSThemeFrame (PrivateAPI) overrides. | ||
- (void)setStyleMask:(NSUInteger)styleMask { | ||
in_full_screen_ = (styleMask & NSWindowStyleMaskFullScreen) != 0; | ||
[super setStyleMask:styleMask]; | ||
} | ||
|
||
- (CGFloat)_titlebarHeight { | ||
if (!in_full_screen_) { | ||
bool override_titlebar_height = false; | ||
float titlebar_height = 0; | ||
auto* window = base::mac::ObjCCast<CefNSWindow>([self window]); | ||
if (auto* bridge = [window bridge]) { | ||
bridge->host()->GetWindowFrameTitlebarHeight(&override_titlebar_height, | ||
&titlebar_height); | ||
|
||
if (override_titlebar_height) | ||
return titlebar_height; | ||
} | ||
} | ||
|
||
return [super _titlebarHeight]; | ||
} | ||
|
||
- (BOOL)_shouldCenterTrafficLights { | ||
auto* window = base::mac::ObjCCast<CefNSWindow>([self window]); | ||
return [window shouldCenterTrafficLights]; | ||
} | ||
|
||
- (BOOL)_shouldFlipTrafficLightsForRTL { | ||
return base::i18n::IsRTL() ? YES : NO; | ||
} | ||
|
||
@end | ||
|
||
@interface NSWindow (PrivateAPI) | ||
+ (Class)frameViewClassForStyleMask:(NSUInteger)windowStyle; | ||
@end | ||
|
||
@implementation CefNSWindow | ||
|
||
- (id)initWithStyle:(NSUInteger)style_mask isFrameless:(bool)is_frameless { | ||
if ((self = [super initWithContentRect:ui::kWindowSizeDeterminedLater | ||
styleMask:style_mask | ||
backing:NSBackingStoreBuffered | ||
defer:NO])) { | ||
is_frameless_ = is_frameless; | ||
} | ||
return self; | ||
} | ||
|
||
- (BOOL)shouldCenterTrafficLights { | ||
return is_frameless_ ? YES : NO; | ||
} | ||
|
||
// NSWindow overrides. | ||
- (NSRect)contentRectForFrameRect:(NSRect)frameRect { | ||
if (is_frameless_) { | ||
return frameRect; | ||
} | ||
return [super contentRectForFrameRect:frameRect]; | ||
} | ||
|
||
- (NSRect)frameRectForContentRect:(NSRect)contentRect { | ||
if (is_frameless_) { | ||
return contentRect; | ||
} | ||
return [super frameRectForContentRect:contentRect]; | ||
} | ||
|
||
// NSWindow (PrivateAPI) overrides. | ||
+ (Class)frameViewClassForStyleMask:(NSUInteger)windowStyle { | ||
if (Class custom_frame = [CefThemeFrame class]) { | ||
return custom_frame; | ||
} | ||
|
||
return [super frameViewClassForStyleMask:windowStyle]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.