blob: ecbb34c472261df1af5152e53d54bc1d00192529 (
plain)
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
94
95
96
97
98
99
100
|
// Copyright (c) 2010 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 "chrome/browser/ui/cocoa/fullscreen_window.h"
#include "base/mac_util.h"
#include "chrome/browser/themes/browser_theme_provider.h"
#import "chrome/browser/ui/cocoa/themed_window.h"
@implementation FullscreenWindow
// Make sure our designated initializer gets called.
- (id)init {
return [self initForScreen:[NSScreen mainScreen]];
}
- (id)initForScreen:(NSScreen*)screen {
NSRect contentRect;
contentRect.origin = NSZeroPoint;
contentRect.size = [screen frame].size;
if ((self = [super initWithContentRect:contentRect
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:YES
screen:screen])) {
[self setReleasedWhenClosed:NO];
// Borderless windows don't usually show up in the Windows menu so whine at
// Cocoa until it complies. See -dealloc and -setTitle: as well.
[NSApp addWindowsItem:self title:@"" filename:NO];
}
return self;
}
- (void)dealloc {
// Paranoia; doesn't seem to be necessary but it doesn't hurt.
[NSApp removeWindowsItem:self];
[super dealloc];
}
- (void)setTitle:(NSString *)title {
[NSApp changeWindowsItem:self title:title filename:NO];
[super setTitle:title];
}
// According to
// http://www.cocoabuilder.com/archive/message/cocoa/2006/6/19/165953 ,
// NSBorderlessWindowMask windows cannot become key or main.
// In our case, however, we don't want that behavior, so we override
// canBecomeKeyWindow and canBecomeMainWindow.
- (BOOL)canBecomeKeyWindow {
return YES;
}
- (BOOL)canBecomeMainWindow {
return YES;
}
// When becoming/resigning main status, explicitly set the background color,
// which is required by |TabView|.
- (void)becomeMainWindow {
[super becomeMainWindow];
[self setBackgroundColor:[NSColor windowFrameColor]];
}
- (void)resignMainWindow {
[super resignMainWindow];
[self setBackgroundColor:[NSColor windowBackgroundColor]];
}
// We need our own version, since the default one wants to flash the close
// button (and possibly other things), which results in nothing happening.
- (void)performClose:(id)sender {
BOOL shouldClose = YES;
// If applicable, check if this window should close.
id delegate = [self delegate];
if ([delegate respondsToSelector:@selector(windowShouldClose:)])
shouldClose = [delegate windowShouldClose:self];
if (shouldClose) {
[self close];
}
}
- (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item {
SEL action = [item action];
// Explicitly enable |-performClose:| (see above); otherwise the fact that
// this window does not have a close button results in it being disabled.
if (action == @selector(performClose:))
return YES;
return [super validateUserInterfaceItem:item];
}
@end
|