app_list_window_controller.mm revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
1// Copyright 2013 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 "ui/app_list/cocoa/app_list_window_controller.h" 6 7#include "ui/app_list/app_list_view_delegate.h" 8#import "ui/app_list/cocoa/app_list_view_controller.h" 9#import "ui/app_list/cocoa/apps_grid_controller.h" 10#import "ui/app_list/cocoa/apps_search_box_controller.h" 11#include "ui/base/cocoa/window_size_constants.h" 12 13@interface AppListWindow : NSWindow; 14@end 15 16@implementation AppListWindow 17 18// If we initialize a window with NSBorderlessWindowMask, it will not accept key 19// events (among other things) unless canBecomeKeyWindow is overridden. 20- (BOOL)canBecomeKeyWindow { 21 return YES; 22} 23 24- (BOOL)canBecomeMainWindow { 25 return YES; 26} 27 28@end 29 30@implementation AppListWindowController; 31 32- (id)init { 33 base::scoped_nsobject<NSWindow> controlledWindow( 34 [[AppListWindow alloc] initWithContentRect:ui::kWindowSizeDeterminedLater 35 styleMask:NSBorderlessWindowMask 36 backing:NSBackingStoreBuffered 37 defer:NO]); 38 [controlledWindow setReleasedWhenClosed:NO]; 39 [controlledWindow setBackgroundColor:[NSColor clearColor]]; 40 [controlledWindow setOpaque:NO]; 41 [controlledWindow setHasShadow:YES]; 42 [controlledWindow setLevel:NSDockWindowLevel]; 43 [controlledWindow 44 setCollectionBehavior:NSWindowCollectionBehaviorMoveToActiveSpace]; 45 46 if ((self = [super initWithWindow:controlledWindow])) { 47 appListViewController_.reset([[AppListViewController alloc] init]); 48 [[self window] setFrame:[[appListViewController_ view] bounds] 49 display:NO]; 50 [[self window] setContentView:[appListViewController_ view]]; 51 [[self window] setDelegate:self]; 52 } 53 return self; 54} 55 56- (AppListViewController*)appListViewController { 57 return appListViewController_; 58} 59 60- (void)windowDidResignMain:(NSNotification*)notification { 61 if ([appListViewController_ delegate]) 62 [appListViewController_ delegate]->Dismiss(); 63} 64 65- (void)windowWillClose:(NSNotification*)notification { 66 [[appListViewController_ searchBoxController] clearSearch]; 67} 68 69@end 70