Chromium Code Reviews| 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/memory/scoped_nsobject.h" | 10 #include "base/memory/scoped_nsobject.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 previousContents:(content::WebContents*)oldContents | 21 previousContents:(content::WebContents*)oldContents |
| 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 | 32 |
| 32 - (id)initWithWindowNibPath:(NSString*)nibPath | 33 - (id)initWithWindowNibPath:(NSString*)nibPath |
| 33 parentWindow:(NSWindow*)parentWindow | 34 parentWindow:(NSWindow*)parentWindow |
| 34 anchoredAt:(NSPoint)anchoredAt { | 35 anchoredAt:(NSPoint)anchoredAt { |
| 35 nibPath = [base::mac::FrameworkBundle() pathForResource:nibPath | 36 nibPath = [base::mac::FrameworkBundle() pathForResource:nibPath |
| 36 ofType:@"nib"]; | 37 ofType:@"nib"]; |
| 37 if ((self = [super initWithWindowNibPath:nibPath owner:self])) { | 38 if ((self = [super initWithWindowNibPath:nibPath owner:self])) { |
| 38 parentWindow_ = parentWindow; | 39 parentWindow_ = parentWindow; |
| 39 anchor_ = anchoredAt; | 40 anchor_ = anchoredAt; |
|
Nico
2013/04/29 22:35:48
Nit: All other members are set up here, maybe move
tkent
2013/04/29 23:08:01
Done.
| |
| 40 | 41 |
| 41 // Watch to see if the parent window closes, and if so, close this one. | 42 // Watch to see if the parent window closes, and if so, close this one. |
| 42 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 43 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 43 [center addObserver:self | 44 [center addObserver:self |
| 44 selector:@selector(parentWindowWillClose:) | 45 selector:@selector(parentWindowWillClose:) |
| 45 name:NSWindowWillCloseNotification | 46 name:NSWindowWillCloseNotification |
| 46 object:parentWindow_]; | 47 object:parentWindow_]; |
| 48 shouldOpenAsKeyWindow_ = YES; | |
| 47 } | 49 } |
| 48 return self; | 50 return self; |
| 49 } | 51 } |
| 50 | 52 |
| 51 - (id)initWithWindowNibPath:(NSString*)nibPath | 53 - (id)initWithWindowNibPath:(NSString*)nibPath |
| 52 relativeToView:(NSView*)view | 54 relativeToView:(NSView*)view |
| 53 offset:(NSPoint)offset { | 55 offset:(NSPoint)offset { |
| 54 DCHECK([view window]); | 56 DCHECK([view window]); |
| 55 NSWindow* window = [view window]; | 57 NSWindow* window = [view window]; |
| 56 NSRect bounds = [view convertRect:[view bounds] toView:nil]; | 58 NSRect bounds = [view convertRect:[view bounds] toView:nil]; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 79 bubble_ = contentView.get(); | 81 bubble_ = contentView.get(); |
| 80 | 82 |
| 81 // Watch to see if the parent window closes, and if so, close this one. | 83 // Watch to see if the parent window closes, and if so, close this one. |
| 82 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 84 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 83 [center addObserver:self | 85 [center addObserver:self |
| 84 selector:@selector(parentWindowWillClose:) | 86 selector:@selector(parentWindowWillClose:) |
| 85 name:NSWindowWillCloseNotification | 87 name:NSWindowWillCloseNotification |
| 86 object:parentWindow_]; | 88 object:parentWindow_]; |
| 87 | 89 |
| 88 [self awakeFromNib]; | 90 [self awakeFromNib]; |
| 91 shouldOpenAsKeyWindow_ = YES; | |
|
Nico
2013/04/29 22:35:48
(likewise; probably at least want to do this befor
tkent
2013/04/29 23:08:01
Done.
| |
| 89 } | 92 } |
| 90 return self; | 93 return self; |
| 91 } | 94 } |
| 92 | 95 |
| 93 - (void)awakeFromNib { | 96 - (void)awakeFromNib { |
| 94 // Check all connections have been made in Interface Builder. | 97 // Check all connections have been made in Interface Builder. |
| 95 DCHECK([self window]); | 98 DCHECK([self window]); |
| 96 DCHECK(bubble_); | 99 DCHECK(bubble_); |
| 97 DCHECK_EQ(self, [[self window] delegate]); | 100 DCHECK_EQ(self, [[self window] delegate]); |
| 98 | 101 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 // We want this to be a child of a browser window. addChildWindow: | 144 // We want this to be a child of a browser window. addChildWindow: |
| 142 // (called from this function) will bring the window on-screen; | 145 // (called from this function) will bring the window on-screen; |
| 143 // unfortunately, [NSWindowController showWindow:] will also bring it | 146 // unfortunately, [NSWindowController showWindow:] will also bring it |
| 144 // on-screen (but will cause unexpected changes to the window's | 147 // on-screen (but will cause unexpected changes to the window's |
| 145 // position). We cannot have an addChildWindow: and a subsequent | 148 // position). We cannot have an addChildWindow: and a subsequent |
| 146 // showWindow:. Thus, we have our own version. | 149 // showWindow:. Thus, we have our own version. |
| 147 - (void)showWindow:(id)sender { | 150 - (void)showWindow:(id)sender { |
| 148 NSWindow* window = [self window]; // Completes nib load. | 151 NSWindow* window = [self window]; // Completes nib load. |
| 149 [self updateOriginFromAnchor]; | 152 [self updateOriginFromAnchor]; |
| 150 [parentWindow_ addChildWindow:window ordered:NSWindowAbove]; | 153 [parentWindow_ addChildWindow:window ordered:NSWindowAbove]; |
| 151 [window makeKeyAndOrderFront:self]; | 154 if (shouldOpenAsKeyWindow_) |
| 155 [window makeKeyAndOrderFront:self]; | |
| 156 else | |
| 157 [window orderFront:nil]; | |
| 152 [self registerKeyStateEventTap]; | 158 [self registerKeyStateEventTap]; |
| 153 } | 159 } |
| 154 | 160 |
| 155 - (void)close { | 161 - (void)close { |
| 156 // The bubble will be closing, so remove the event taps. | 162 // The bubble will be closing, so remove the event taps. |
| 157 if (eventTap_) { | 163 if (eventTap_) { |
| 158 [NSEvent removeMonitor:eventTap_]; | 164 [NSEvent removeMonitor:eventTap_]; |
| 159 eventTap_ = nil; | 165 eventTap_ = nil; |
| 160 } | 166 } |
| 161 if (resignationObserver_) { | 167 if (resignationObserver_) { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 | 284 |
| 279 - (void)activateTabWithContents:(content::WebContents*)newContents | 285 - (void)activateTabWithContents:(content::WebContents*)newContents |
| 280 previousContents:(content::WebContents*)oldContents | 286 previousContents:(content::WebContents*)oldContents |
| 281 atIndex:(NSInteger)index | 287 atIndex:(NSInteger)index |
| 282 reason:(int)reason { | 288 reason:(int)reason { |
| 283 // The user switched tabs; close. | 289 // The user switched tabs; close. |
| 284 [self close]; | 290 [self close]; |
| 285 } | 291 } |
| 286 | 292 |
| 287 @end // BaseBubbleController | 293 @end // BaseBubbleController |
| OLD | NEW |