| 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; |
| 41 shouldOpenAsKeyWindow_ = YES; |
| 40 | 42 |
| 41 // Watch to see if the parent window closes, and if so, close this one. | 43 // Watch to see if the parent window closes, and if so, close this one. |
| 42 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 44 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 43 [center addObserver:self | 45 [center addObserver:self |
| 44 selector:@selector(parentWindowWillClose:) | 46 selector:@selector(parentWindowWillClose:) |
| 45 name:NSWindowWillCloseNotification | 47 name:NSWindowWillCloseNotification |
| 46 object:parentWindow_]; | 48 object:parentWindow_]; |
| 47 } | 49 } |
| 48 return self; | 50 return self; |
| 49 } | 51 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 62 anchoredAt:anchor]; | 64 anchoredAt:anchor]; |
| 63 } | 65 } |
| 64 | 66 |
| 65 - (id)initWithWindow:(NSWindow*)theWindow | 67 - (id)initWithWindow:(NSWindow*)theWindow |
| 66 parentWindow:(NSWindow*)parentWindow | 68 parentWindow:(NSWindow*)parentWindow |
| 67 anchoredAt:(NSPoint)anchoredAt { | 69 anchoredAt:(NSPoint)anchoredAt { |
| 68 DCHECK(theWindow); | 70 DCHECK(theWindow); |
| 69 if ((self = [super initWithWindow:theWindow])) { | 71 if ((self = [super initWithWindow:theWindow])) { |
| 70 parentWindow_ = parentWindow; | 72 parentWindow_ = parentWindow; |
| 71 anchor_ = anchoredAt; | 73 anchor_ = anchoredAt; |
| 74 shouldOpenAsKeyWindow_ = YES; |
| 72 | 75 |
| 73 DCHECK(![[self window] delegate]); | 76 DCHECK(![[self window] delegate]); |
| 74 [theWindow setDelegate:self]; | 77 [theWindow setDelegate:self]; |
| 75 | 78 |
| 76 scoped_nsobject<InfoBubbleView> contentView( | 79 scoped_nsobject<InfoBubbleView> contentView( |
| 77 [[InfoBubbleView alloc] initWithFrame:NSMakeRect(0, 0, 0, 0)]); | 80 [[InfoBubbleView alloc] initWithFrame:NSMakeRect(0, 0, 0, 0)]); |
| 78 [theWindow setContentView:contentView.get()]; | 81 [theWindow setContentView:contentView.get()]; |
| 79 bubble_ = contentView.get(); | 82 bubble_ = contentView.get(); |
| 80 | 83 |
| 81 // Watch to see if the parent window closes, and if so, close this one. | 84 // Watch to see if the parent window closes, and if so, close this one. |
| (...skipping 59 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 |