OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/cocoa/base_bubble_controller.h" | 5 #import "chrome/browser/cocoa/base_bubble_controller.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/mac_util.h" | 9 #include "base/mac_util.h" |
| 10 #include "base/scoped_nsobject.h" |
10 #include "base/string_util.h" | 11 #include "base/string_util.h" |
11 #import "chrome/browser/cocoa/info_bubble_view.h" | 12 #import "chrome/browser/cocoa/info_bubble_view.h" |
12 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
13 | 14 |
14 @implementation BaseBubbleController | 15 @implementation BaseBubbleController |
15 | 16 |
| 17 @synthesize parentWindow = parentWindow_; |
16 @synthesize bubble = bubble_; | 18 @synthesize bubble = bubble_; |
17 | 19 |
18 - (id)initWithWindowNibPath:(NSString*)nibPath | 20 - (id)initWithWindowNibPath:(NSString*)nibPath |
19 parentWindow:(NSWindow*)parentWindow | 21 parentWindow:(NSWindow*)parentWindow |
20 anchoredAt:(NSPoint)anchoredAt { | 22 anchoredAt:(NSPoint)anchoredAt { |
21 nibPath = [mac_util::MainAppBundle() pathForResource:nibPath | 23 nibPath = [mac_util::MainAppBundle() pathForResource:nibPath |
22 ofType:@"nib"]; | 24 ofType:@"nib"]; |
23 if ((self = [super initWithWindowNibPath:nibPath owner:self])) { | 25 if ((self = [super initWithWindowNibPath:nibPath owner:self])) { |
24 parentWindow_ = parentWindow; | 26 parentWindow_ = parentWindow; |
25 anchor_ = anchoredAt; | 27 anchor_ = anchoredAt; |
(...skipping 15 matching lines...) Expand all Loading... |
41 NSWindow* window = [view window]; | 43 NSWindow* window = [view window]; |
42 NSRect bounds = [view convertRect:[view bounds] toView:nil]; | 44 NSRect bounds = [view convertRect:[view bounds] toView:nil]; |
43 NSPoint anchor = NSMakePoint(NSMinX(bounds) + offset.x, | 45 NSPoint anchor = NSMakePoint(NSMinX(bounds) + offset.x, |
44 NSMinY(bounds) + offset.y); | 46 NSMinY(bounds) + offset.y); |
45 anchor = [window convertBaseToScreen:anchor]; | 47 anchor = [window convertBaseToScreen:anchor]; |
46 return [self initWithWindowNibPath:nibPath | 48 return [self initWithWindowNibPath:nibPath |
47 parentWindow:window | 49 parentWindow:window |
48 anchoredAt:anchor]; | 50 anchoredAt:anchor]; |
49 } | 51 } |
50 | 52 |
| 53 - (id)initWithWindow:(NSWindow*)theWindow |
| 54 parentWindow:(NSWindow*)parentWindow |
| 55 anchoredAt:(NSPoint)anchoredAt { |
| 56 DCHECK(theWindow); |
| 57 if ((self = [super initWithWindow:theWindow])) { |
| 58 parentWindow_ = parentWindow; |
| 59 anchor_ = anchoredAt; |
| 60 DCHECK(![[self window] delegate]); |
| 61 [theWindow setDelegate:self]; |
| 62 |
| 63 scoped_nsobject<InfoBubbleView> contentView( |
| 64 [[InfoBubbleView alloc] initWithFrame:NSMakeRect(0, 0, 0, 0)]); |
| 65 [theWindow setContentView:contentView.get()]; |
| 66 bubble_ = contentView.get(); |
| 67 |
| 68 // Watch to see if the parent window closes, and if so, close this one. |
| 69 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 70 [center addObserver:self |
| 71 selector:@selector(parentWindowWillClose:) |
| 72 name:NSWindowWillCloseNotification |
| 73 object:parentWindow_]; |
| 74 |
| 75 [self awakeFromNib]; |
| 76 } |
| 77 return self; |
| 78 } |
51 | 79 |
52 - (void)awakeFromNib { | 80 - (void)awakeFromNib { |
53 // Check all connections have been made in Interface Builder. | 81 // Check all connections have been made in Interface Builder. |
54 DCHECK([self window]); | 82 DCHECK([self window]); |
55 DCHECK(bubble_); | 83 DCHECK(bubble_); |
56 DCHECK_EQ(self, [[self window] delegate]); | 84 DCHECK_EQ(self, [[self window] delegate]); |
57 | 85 |
58 [bubble_ setBubbleType:info_bubble::kWhiteInfoBubble]; | 86 [bubble_ setBubbleType:info_bubble::kWhiteInfoBubble]; |
59 [bubble_ setArrowLocation:info_bubble::kTopRight]; | 87 [bubble_ setArrowLocation:info_bubble::kTopRight]; |
60 } | 88 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 142 } |
115 } | 143 } |
116 | 144 |
117 // By implementing this, ESC causes the window to go away. | 145 // By implementing this, ESC causes the window to go away. |
118 - (IBAction)cancel:(id)sender { | 146 - (IBAction)cancel:(id)sender { |
119 // This is not a "real" cancel as potential changes to the radio group are not | 147 // This is not a "real" cancel as potential changes to the radio group are not |
120 // undone. That's ok. | 148 // undone. That's ok. |
121 [self close]; | 149 [self close]; |
122 } | 150 } |
123 @end // BaseBubbleController | 151 @end // BaseBubbleController |
OLD | NEW |