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