Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / fullscreen_window.mm
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.
4
5 #import "chrome/browser/ui/cocoa/fullscreen_window.h"
6
7 #import "chrome/browser/ui/cocoa/themed_window.h"
8
9 @implementation FullscreenWindow
10
11 // Make sure our designated initializer gets called.
12 - (id)init {
13   return [self initForScreen:[NSScreen mainScreen]];
14 }
15
16 - (id)initForScreen:(NSScreen*)screen {
17   NSRect contentRect;
18   contentRect.origin = NSZeroPoint;
19   contentRect.size = [screen frame].size;
20
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     [[self contentView] setWantsLayer:YES];
31   }
32   return self;
33 }
34
35 - (void)dealloc {
36   // Paranoia; doesn't seem to be necessary but it doesn't hurt.
37   [NSApp removeWindowsItem:self];
38
39   [super dealloc];
40 }
41
42 - (void)setTitle:(NSString *)title {
43   [NSApp changeWindowsItem:self title:title filename:NO];
44   [super setTitle:title];
45 }
46
47 // According to
48 // http://www.cocoabuilder.com/archive/message/cocoa/2006/6/19/165953 ,
49 // NSBorderlessWindowMask windows cannot become key or main.
50 // In our case, however, we don't want that behavior, so we override
51 // canBecomeKeyWindow and canBecomeMainWindow.
52
53 - (BOOL)canBecomeKeyWindow {
54   return YES;
55 }
56
57 - (BOOL)canBecomeMainWindow {
58   return YES;
59 }
60
61 // When becoming/resigning main status, explicitly set the background color,
62 // which is required by |TabView|.
63 - (void)becomeMainWindow {
64   [super becomeMainWindow];
65   [self setBackgroundColor:[NSColor windowFrameColor]];
66 }
67
68 - (void)resignMainWindow {
69   [super resignMainWindow];
70   [self setBackgroundColor:[NSColor windowBackgroundColor]];
71 }
72
73 // We need our own version, since the default one wants to flash the close
74 // button (and possibly other things), which results in nothing happening.
75 - (void)performClose:(id)sender {
76   BOOL shouldClose = YES;
77
78   // If applicable, check if this window should close.
79   id delegate = [self delegate];
80   if ([delegate respondsToSelector:@selector(windowShouldClose:)])
81     shouldClose = [delegate windowShouldClose:self];
82
83   if (shouldClose) {
84     [self close];
85   }
86 }
87
88 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item {
89   SEL action = [item action];
90
91   // Explicitly enable |-performClose:| (see above); otherwise the fact that
92   // this window does not have a close button results in it being disabled.
93   if (action == @selector(performClose:))
94     return YES;
95
96   return [super validateUserInterfaceItem:item];
97 }
98
99 @end