OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" | 5 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/mac/bundle_locations.h" | 8 #include "base/mac/bundle_locations.h" |
9 #include "base/mac/mac_util.h" | 9 #include "base/mac/mac_util.h" |
10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 atIndex:(NSInteger)index | 22 atIndex:(NSInteger)index |
23 reason:(int)reason; | 23 reason:(int)reason; |
24 @end | 24 @end |
25 | 25 |
26 @implementation BaseBubbleController | 26 @implementation BaseBubbleController |
27 | 27 |
28 @synthesize parentWindow = parentWindow_; | 28 @synthesize parentWindow = parentWindow_; |
29 @synthesize anchorPoint = anchor_; | 29 @synthesize anchorPoint = anchor_; |
30 @synthesize bubble = bubble_; | 30 @synthesize bubble = bubble_; |
31 @synthesize shouldOpenAsKeyWindow = shouldOpenAsKeyWindow_; | 31 @synthesize shouldOpenAsKeyWindow = shouldOpenAsKeyWindow_; |
| 32 @synthesize shouldCloseOnResignKey = shouldCloseOnResignKey_; |
32 | 33 |
33 - (id)initWithWindowNibPath:(NSString*)nibPath | 34 - (id)initWithWindowNibPath:(NSString*)nibPath |
34 parentWindow:(NSWindow*)parentWindow | 35 parentWindow:(NSWindow*)parentWindow |
35 anchoredAt:(NSPoint)anchoredAt { | 36 anchoredAt:(NSPoint)anchoredAt { |
36 nibPath = [base::mac::FrameworkBundle() pathForResource:nibPath | 37 nibPath = [base::mac::FrameworkBundle() pathForResource:nibPath |
37 ofType:@"nib"]; | 38 ofType:@"nib"]; |
38 if ((self = [super initWithWindowNibPath:nibPath owner:self])) { | 39 if ((self = [super initWithWindowNibPath:nibPath owner:self])) { |
39 parentWindow_ = parentWindow; | 40 parentWindow_ = parentWindow; |
40 anchor_ = anchoredAt; | 41 anchor_ = anchoredAt; |
41 shouldOpenAsKeyWindow_ = YES; | 42 shouldOpenAsKeyWindow_ = YES; |
(...skipping 23 matching lines...) Expand all Loading... |
65 } | 66 } |
66 | 67 |
67 - (id)initWithWindow:(NSWindow*)theWindow | 68 - (id)initWithWindow:(NSWindow*)theWindow |
68 parentWindow:(NSWindow*)parentWindow | 69 parentWindow:(NSWindow*)parentWindow |
69 anchoredAt:(NSPoint)anchoredAt { | 70 anchoredAt:(NSPoint)anchoredAt { |
70 DCHECK(theWindow); | 71 DCHECK(theWindow); |
71 if ((self = [super initWithWindow:theWindow])) { | 72 if ((self = [super initWithWindow:theWindow])) { |
72 parentWindow_ = parentWindow; | 73 parentWindow_ = parentWindow; |
73 anchor_ = anchoredAt; | 74 anchor_ = anchoredAt; |
74 shouldOpenAsKeyWindow_ = YES; | 75 shouldOpenAsKeyWindow_ = YES; |
| 76 shouldCloseOnResignKey_ = YES; |
75 | 77 |
76 DCHECK(![[self window] delegate]); | 78 DCHECK(![[self window] delegate]); |
77 [theWindow setDelegate:self]; | 79 [theWindow setDelegate:self]; |
78 | 80 |
79 base::scoped_nsobject<InfoBubbleView> contentView( | 81 base::scoped_nsobject<InfoBubbleView> contentView( |
80 [[InfoBubbleView alloc] initWithFrame:NSZeroRect]); | 82 [[InfoBubbleView alloc] initWithFrame:NSZeroRect]); |
81 [theWindow setContentView:contentView.get()]; | 83 [theWindow setContentView:contentView.get()]; |
82 bubble_ = contentView.get(); | 84 bubble_ = contentView.get(); |
83 | 85 |
84 // Watch to see if the parent window closes, and if so, close this one. | 86 // Watch to see if the parent window closes, and if so, close this one. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 [[[self window] parentWindow] removeChildWindow:[self window]]; | 179 [[[self window] parentWindow] removeChildWindow:[self window]]; |
178 [super close]; | 180 [super close]; |
179 } | 181 } |
180 | 182 |
181 // The controller is the delegate of the window so it receives did resign key | 183 // The controller is the delegate of the window so it receives did resign key |
182 // notifications. When key is resigned mirror Windows behavior and close the | 184 // notifications. When key is resigned mirror Windows behavior and close the |
183 // window. | 185 // window. |
184 - (void)windowDidResignKey:(NSNotification*)notification { | 186 - (void)windowDidResignKey:(NSNotification*)notification { |
185 NSWindow* window = [self window]; | 187 NSWindow* window = [self window]; |
186 DCHECK_EQ([notification object], window); | 188 DCHECK_EQ([notification object], window); |
187 if ([window isVisible]) { | 189 if ([window isVisible] && [self shouldCloseOnResignKey]) { |
188 // If the window isn't visible, it is already closed, and this notification | 190 // If the window isn't visible, it is already closed, and this notification |
189 // has been sent as part of the closing operation, so no need to close. | 191 // has been sent as part of the closing operation, so no need to close. |
190 [self close]; | 192 [self close]; |
191 } | 193 } |
192 } | 194 } |
193 | 195 |
194 // Since the bubble shares first responder with its parent window, set | 196 // Since the bubble shares first responder with its parent window, set |
195 // event handlers to dismiss the bubble when it would normally lose key | 197 // event handlers to dismiss the bubble when it would normally lose key |
196 // state. | 198 // state. |
197 - (void)registerKeyStateEventTap { | 199 - (void)registerKeyStateEventTap { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 | 286 |
285 - (void)activateTabWithContents:(content::WebContents*)newContents | 287 - (void)activateTabWithContents:(content::WebContents*)newContents |
286 previousContents:(content::WebContents*)oldContents | 288 previousContents:(content::WebContents*)oldContents |
287 atIndex:(NSInteger)index | 289 atIndex:(NSInteger)index |
288 reason:(int)reason { | 290 reason:(int)reason { |
289 // The user switched tabs; close. | 291 // The user switched tabs; close. |
290 [self close]; | 292 [self close]; |
291 } | 293 } |
292 | 294 |
293 @end // BaseBubbleController | 295 @end // BaseBubbleController |
OLD | NEW |