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" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 12 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
13 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 13 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
14 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" | 14 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" |
15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
17 | 17 |
18 @interface BaseBubbleController (Private) | 18 @interface BaseBubbleController (Private) |
19 - (void)registerForNotifications; | 19 - (void)registerForNotifications; |
20 - (void)updateOriginFromAnchor; | 20 - (void)updateOriginFromAnchor; |
21 - (void)activateTabWithContents:(content::WebContents*)newContents | 21 - (void)activateTabWithContents:(content::WebContents*)newContents |
22 previousContents:(content::WebContents*)oldContents | 22 previousContents:(content::WebContents*)oldContents |
23 atIndex:(NSInteger)index | 23 atIndex:(NSInteger)index |
24 reason:(int)reason; | 24 reason:(int)reason; |
25 - (void)recordAnchorOffset; | 25 - (void)recordAnchorOffset; |
26 - (void)parentWindowDidResize:(NSNotification*)notification; | 26 - (void)parentWindowDidResize:(NSNotification*)notification; |
27 - (void)parentWindowWillClose:(NSNotification*)notification; | 27 - (void)parentWindowWillClose:(NSNotification*)notification; |
28 - (void)parentWindowWillBecomeFullScreen:(NSNotification*)notification; | |
28 - (void)closeCleanup; | 29 - (void)closeCleanup; |
29 @end | 30 @end |
30 | 31 |
31 @implementation BaseBubbleController | 32 @implementation BaseBubbleController |
32 | 33 |
33 @synthesize parentWindow = parentWindow_; | 34 @synthesize parentWindow = parentWindow_; |
34 @synthesize anchorPoint = anchor_; | 35 @synthesize anchorPoint = anchor_; |
35 @synthesize bubble = bubble_; | 36 @synthesize bubble = bubble_; |
36 @synthesize shouldOpenAsKeyWindow = shouldOpenAsKeyWindow_; | 37 @synthesize shouldOpenAsKeyWindow = shouldOpenAsKeyWindow_; |
37 @synthesize shouldCloseOnResignKey = shouldCloseOnResignKey_; | 38 @synthesize shouldCloseOnResignKey = shouldCloseOnResignKey_; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 [super dealloc]; | 113 [super dealloc]; |
113 } | 114 } |
114 | 115 |
115 - (void)registerForNotifications { | 116 - (void)registerForNotifications { |
116 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 117 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
117 // Watch to see if the parent window closes, and if so, close this one. | 118 // Watch to see if the parent window closes, and if so, close this one. |
118 [center addObserver:self | 119 [center addObserver:self |
119 selector:@selector(parentWindowWillClose:) | 120 selector:@selector(parentWindowWillClose:) |
120 name:NSWindowWillCloseNotification | 121 name:NSWindowWillCloseNotification |
121 object:parentWindow_]; | 122 object:parentWindow_]; |
123 // Watch for the full screen event, if so, close the bubble | |
124 [center addObserver:self | |
125 selector:@selector(parentWindowWillBecomeFullScreen:) | |
126 name:NSWindowWillEnterFullScreenNotification | |
Robert Sesek
2014/06/11 15:03:54
This notification is only available on 10.7 and la
| |
127 object:parentWindow_]; | |
122 // Watch for parent window's resizing, to ensure this one is always | 128 // Watch for parent window's resizing, to ensure this one is always |
123 // anchored correctly. | 129 // anchored correctly. |
124 [center addObserver:self | 130 [center addObserver:self |
125 selector:@selector(parentWindowDidResize:) | 131 selector:@selector(parentWindowDidResize:) |
126 name:NSWindowDidResizeNotification | 132 name:NSWindowDidResizeNotification |
127 object:parentWindow_]; | 133 object:parentWindow_]; |
128 } | 134 } |
129 | 135 |
130 - (void)setAnchorPoint:(NSPoint)anchor { | 136 - (void)setAnchorPoint:(NSPoint)anchor { |
131 anchor_ = anchor; | 137 anchor_ = anchor; |
(...skipping 12 matching lines...) Expand all Loading... | |
144 - (NSBox*)separatorWithFrame:(NSRect)frame { | 150 - (NSBox*)separatorWithFrame:(NSRect)frame { |
145 frame.size.height = 1.0; | 151 frame.size.height = 1.0; |
146 base::scoped_nsobject<NSBox> spacer([[NSBox alloc] initWithFrame:frame]); | 152 base::scoped_nsobject<NSBox> spacer([[NSBox alloc] initWithFrame:frame]); |
147 [spacer setBoxType:NSBoxSeparator]; | 153 [spacer setBoxType:NSBoxSeparator]; |
148 [spacer setBorderType:NSLineBorder]; | 154 [spacer setBorderType:NSLineBorder]; |
149 [spacer setAlphaValue:0.2]; | 155 [spacer setAlphaValue:0.2]; |
150 return [spacer.release() autorelease]; | 156 return [spacer.release() autorelease]; |
151 } | 157 } |
152 | 158 |
153 - (void)parentWindowDidResize:(NSNotification*)notification { | 159 - (void)parentWindowDidResize:(NSNotification*)notification { |
160 if (!parentWindow_) | |
161 return; | |
162 | |
154 DCHECK_EQ(parentWindow_, [notification object]); | 163 DCHECK_EQ(parentWindow_, [notification object]); |
155 NSPoint newOrigin = NSMakePoint(NSMinX([parentWindow_ frame]), | 164 NSPoint newOrigin = NSMakePoint(NSMinX([parentWindow_ frame]), |
156 NSMaxY([parentWindow_ frame])); | 165 NSMaxY([parentWindow_ frame])); |
157 newOrigin.x -= anchorOffset_.x; | 166 newOrigin.x -= anchorOffset_.x; |
158 newOrigin.y -= anchorOffset_.y; | 167 newOrigin.y -= anchorOffset_.y; |
159 [self setAnchorPoint:newOrigin]; | 168 [self setAnchorPoint:newOrigin]; |
160 } | 169 } |
161 | 170 |
162 - (void)parentWindowWillClose:(NSNotification*)notification { | 171 - (void)parentWindowWillClose:(NSNotification*)notification { |
163 parentWindow_ = nil; | 172 parentWindow_ = nil; |
164 [self close]; | 173 [self close]; |
165 } | 174 } |
166 | 175 |
176 - (void)parentWindowWillBecomeFullScreen:(NSNotification*)notification { | |
177 parentWindow_ = nil; | |
178 [self close]; | |
179 } | |
180 | |
167 - (void)closeCleanup { | 181 - (void)closeCleanup { |
168 if (eventTap_) { | 182 if (eventTap_) { |
169 [NSEvent removeMonitor:eventTap_]; | 183 [NSEvent removeMonitor:eventTap_]; |
170 eventTap_ = nil; | 184 eventTap_ = nil; |
171 } | 185 } |
172 if (resignationObserver_) { | 186 if (resignationObserver_) { |
173 [[NSNotificationCenter defaultCenter] | 187 [[NSNotificationCenter defaultCenter] |
174 removeObserver:resignationObserver_ | 188 removeObserver:resignationObserver_ |
175 name:NSWindowDidResignKeyNotification | 189 name:NSWindowDidResignKeyNotification |
176 object:nil]; | 190 object:nil]; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 | 341 |
328 - (void)activateTabWithContents:(content::WebContents*)newContents | 342 - (void)activateTabWithContents:(content::WebContents*)newContents |
329 previousContents:(content::WebContents*)oldContents | 343 previousContents:(content::WebContents*)oldContents |
330 atIndex:(NSInteger)index | 344 atIndex:(NSInteger)index |
331 reason:(int)reason { | 345 reason:(int)reason { |
332 // The user switched tabs; close. | 346 // The user switched tabs; close. |
333 [self close]; | 347 [self close]; |
334 } | 348 } |
335 | 349 |
336 @end // BaseBubbleController | 350 @end // BaseBubbleController |
OLD | NEW |