[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / fullscreen_window.mm
blob9125b2119b72cab770043163c69ed4bc2ef05069
1 // Copyright (c) 2012 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.
5 #import "chrome/browser/ui/cocoa/fullscreen_window.h"
7 #import "chrome/browser/ui/cocoa/themed_window.h"
9 @implementation FullscreenWindow
11 // Make sure our designated initializer gets called.
12 - (id)init {
13   return [self initForScreen:[NSScreen mainScreen]];
16 - (id)initForScreen:(NSScreen*)screen {
17   NSRect contentRect;
18   contentRect.origin = NSZeroPoint;
19   contentRect.size = [screen frame].size;
21   if ((self = [super initWithContentRect:contentRect
22                                styleMask:NSBorderlessWindowMask
23                                  backing:NSBackingStoreBuffered
24                                    defer:YES
25                                   screen:screen])) {
26     [self setReleasedWhenClosed:NO];
27     // Borderless windows don't usually show up in the Windows menu so whine at
28     // Cocoa until it complies. See -dealloc and -setTitle: as well.
29     [NSApp addWindowsItem:self title:@"" filename:NO];
30   }
31   return self;
34 - (void)dealloc {
35   // Paranoia; doesn't seem to be necessary but it doesn't hurt.
36   [NSApp removeWindowsItem:self];
38   [super dealloc];
41 - (void)setTitle:(NSString *)title {
42   [NSApp changeWindowsItem:self title:title filename:NO];
43   [super setTitle:title];
46 // According to
47 // http://www.cocoabuilder.com/archive/message/cocoa/2006/6/19/165953 ,
48 // NSBorderlessWindowMask windows cannot become key or main.
49 // In our case, however, we don't want that behavior, so we override
50 // canBecomeKeyWindow and canBecomeMainWindow.
52 - (BOOL)canBecomeKeyWindow {
53   return YES;
56 - (BOOL)canBecomeMainWindow {
57   return YES;
60 // When becoming/resigning main status, explicitly set the background color,
61 // which is required by |TabView|.
62 - (void)becomeMainWindow {
63   [super becomeMainWindow];
64   [self setBackgroundColor:[NSColor windowFrameColor]];
67 - (void)resignMainWindow {
68   [super resignMainWindow];
69   [self setBackgroundColor:[NSColor windowBackgroundColor]];
72 // We need our own version, since the default one wants to flash the close
73 // button (and possibly other things), which results in nothing happening.
74 - (void)performClose:(id)sender {
75   BOOL shouldClose = YES;
77   // If applicable, check if this window should close.
78   id delegate = [self delegate];
79   if ([delegate respondsToSelector:@selector(windowShouldClose:)])
80     shouldClose = [delegate windowShouldClose:self];
82   if (shouldClose) {
83     [self close];
84   }
87 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item {
88   SEL action = [item action];
90   // Explicitly enable |-performClose:| (see above); otherwise the fact that
91   // this window does not have a close button results in it being disabled.
92   if (action == @selector(performClose:))
93     return YES;
95   return [super validateUserInterfaceItem:item];
98 @end