forked from chromium/chromium
-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
browser_native_widget_window_mac.mm
93 lines (73 loc) · 2.92 KB
/
browser_native_widget_window_mac.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "components/remote_cocoa/app_shim/browser_native_widget_window_mac.h"
#import <AppKit/AppKit.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"
@interface NSWindow (PrivateBrowserNativeWidgetAPI)
+ (Class)frameViewClassForStyleMask:(NSUInteger)windowStyle;
@end
@interface NSThemeFrame (PrivateBrowserNativeWidgetAPI)
- (CGFloat)_titlebarHeight;
- (void)setStyleMask:(NSUInteger)styleMask;
@end
@interface BrowserWindowFrame : NativeWidgetMacNSWindowTitledFrame
@end
@implementation BrowserWindowFrame {
BOOL _inFullScreen;
}
// NSThemeFrame overrides.
- (CGFloat)_titlebarHeight {
bool overrideTitlebarHeight = false;
float titlebarHeight = 0;
if (!_inFullScreen) {
auto* window = base::mac::ObjCCast<NativeWidgetMacNSWindow>([self window]);
remote_cocoa::NativeWidgetNSWindowBridge* bridge = [window bridge];
if (bridge) {
bridge->host()->GetWindowFrameTitlebarHeight(&overrideTitlebarHeight,
&titlebarHeight);
}
}
if (overrideTitlebarHeight && (@available(macOS 10.10, *)))
return titlebarHeight;
return [super _titlebarHeight];
}
- (void)setStyleMask:(NSUInteger)styleMask {
_inFullScreen = (styleMask & NSWindowStyleMaskFullScreen) != 0;
[super setStyleMask:styleMask];
}
- (BOOL)_shouldCenterTrafficLights {
return YES;
}
// On 10.10, this prevents the window server from treating the title bar as an
// unconditionally-draggable region, and allows -[BridgedContentView hitTest:]
// to choose case-by-case whether to take a mouse event or let it turn into a
// window drag. Not needed for newer macOS. See r549802 for details.
- (NSRect)_draggableFrame NS_DEPRECATED_MAC(10_10, 10_11) {
return NSZeroRect;
}
@end
@implementation BrowserNativeWidgetWindow
// NSWindow (PrivateAPI) overrides.
+ (Class)frameViewClassForStyleMask:(NSUInteger)windowStyle {
// - NSThemeFrame and its subclasses will be nil if it's missing at runtime.
if ([BrowserWindowFrame class])
return [BrowserWindowFrame class];
return [super frameViewClassForStyleMask:windowStyle];
}
// The base implementation returns YES if the window's frame view is a custom
// class, which causes undesirable changes in behavior. AppKit NSWindow
// subclasses are known to override it and return NO.
- (BOOL)_usesCustomDrawing {
return NO;
}
// Handle "Move focus to the window toolbar" configured in System Preferences ->
// Keyboard -> Shortcuts -> Keyboard. Usually Ctrl+F5. The argument (|unknown|)
// tends to just be nil.
- (void)_handleFocusToolbarHotKey:(id)unknown {
remote_cocoa::NativeWidgetNSWindowBridge* bridge = [self bridge];
if (bridge)
bridge->host()->OnFocusWindowToolbar();
}
@end