Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(701)

Side by Side Diff: chrome/browser/ui/cocoa/base_bubble_controller.mm

Issue 952793002: Mac: Make ui/base/cocoa WindowAnimator Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: git add Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/foundation_util.h" 9 #include "base/mac/foundation_util.h"
10 #include "base/mac/mac_util.h" 10 #include "base/mac/mac_util.h"
11 #include "base/mac/scoped_nsobject.h" 11 #include "base/mac/scoped_nsobject.h"
12 #include "base/mac/sdk_forward_declarations.h" 12 #include "base/mac/sdk_forward_declarations.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 14 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
15 #import "chrome/browser/ui/cocoa/info_bubble_view.h" 15 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
16 #import "chrome/browser/ui/cocoa/info_bubble_window.h" 16 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
17 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" 17 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h"
18 18
19 @interface BaseBubbleController (Private) 19 @interface BaseBubbleController (Private)
20 - (InfoBubbleWindow*)bubbleWindow;
20 - (void)registerForNotifications; 21 - (void)registerForNotifications;
21 - (void)updateOriginFromAnchor; 22 - (void)updateOriginFromAnchor;
22 - (void)activateTabWithContents:(content::WebContents*)newContents 23 - (void)activateTabWithContents:(content::WebContents*)newContents
23 previousContents:(content::WebContents*)oldContents 24 previousContents:(content::WebContents*)oldContents
24 atIndex:(NSInteger)index 25 atIndex:(NSInteger)index
25 reason:(int)reason; 26 reason:(int)reason;
26 - (void)recordAnchorOffset; 27 - (void)recordAnchorOffset;
27 - (void)parentWindowDidResize:(NSNotification*)notification; 28 - (void)parentWindowDidResize:(NSNotification*)notification;
28 - (void)parentWindowWillClose:(NSNotification*)notification; 29 - (void)parentWindowWillClose:(NSNotification*)notification;
29 - (void)parentWindowWillBecomeFullScreen:(NSNotification*)notification; 30 - (void)parentWindowWillBecomeFullScreen:(NSNotification*)notification;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 } 108 }
108 109
109 [bubble_ setArrowLocation:info_bubble::kTopRight]; 110 [bubble_ setArrowLocation:info_bubble::kTopRight];
110 } 111 }
111 112
112 - (void)dealloc { 113 - (void)dealloc {
113 [[NSNotificationCenter defaultCenter] removeObserver:self]; 114 [[NSNotificationCenter defaultCenter] removeObserver:self];
114 [super dealloc]; 115 [super dealloc];
115 } 116 }
116 117
118 - (InfoBubbleWindow*)bubbleWindow {
119 return base::mac::ObjCCastStrict<InfoBubbleWindow>([self window]);
120 }
121
117 - (void)registerForNotifications { 122 - (void)registerForNotifications {
118 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; 123 NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
119 // Watch to see if the parent window closes, and if so, close this one. 124 // Watch to see if the parent window closes, and if so, close this one.
120 [center addObserver:self 125 [center addObserver:self
121 selector:@selector(parentWindowWillClose:) 126 selector:@selector(parentWindowWillClose:)
122 name:NSWindowWillCloseNotification 127 name:NSWindowWillCloseNotification
123 object:parentWindow_]; 128 object:parentWindow_];
124 // Watch for the full screen event, if so, close the bubble 129 // Watch for the full screen event, if so, close the bubble
125 [center addObserver:self 130 [center addObserver:self
126 selector:@selector(parentWindowWillBecomeFullScreen:) 131 selector:@selector(parentWindowWillBecomeFullScreen:)
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 if (shouldOpenAsKeyWindow_) 231 if (shouldOpenAsKeyWindow_)
227 [window makeKeyAndOrderFront:self]; 232 [window makeKeyAndOrderFront:self];
228 else 233 else
229 [window orderFront:nil]; 234 [window orderFront:nil];
230 [self registerKeyStateEventTap]; 235 [self registerKeyStateEventTap];
231 [self recordAnchorOffset]; 236 [self recordAnchorOffset];
232 } 237 }
233 238
234 - (void)close { 239 - (void)close {
235 [self closeCleanup]; 240 [self closeCleanup];
236 [super close]; 241 [[self bubbleWindow] animateClose];
237 } 242 }
238 243
239 // The controller is the delegate of the window so it receives did resign key 244 // The controller is the delegate of the window so it receives did resign key
240 // notifications. When key is resigned mirror Windows behavior and close the 245 // notifications. When key is resigned mirror Windows behavior and close the
241 // window. 246 // window.
242 - (void)windowDidResignKey:(NSNotification*)notification { 247 - (void)windowDidResignKey:(NSNotification*)notification {
243 NSWindow* window = [self window]; 248 NSWindow* window = [self window];
244 DCHECK_EQ([notification object], window); 249 DCHECK_EQ([notification object], window);
245 250
246 // If the window isn't visible, it is already closed, and this notification 251 // If the window isn't visible, it is already closed, and this notification
247 // has been sent as part of the closing operation, so no need to close. 252 // has been sent as part of the closing operation, so no need to close.
248 if (![window isVisible]) 253 if (![window isVisible])
249 return; 254 return;
250 255
251 // Don't close when explicily disabled, or if there's an attached sheet (e.g. 256 // Don't close when explicily disabled, or if there's an attached sheet (e.g.
252 // Open File dialog). 257 // Open File dialog).
253 if ([self shouldCloseOnResignKey] && ![window attachedSheet]) { 258 if ([self shouldCloseOnResignKey] && ![window attachedSheet]) {
254 [self close]; 259 [self close];
255 return; 260 return;
256 } 261 }
257 262
258 // The bubble should not receive key events when it is no longer key window, 263 // The bubble should not receive key events when it is no longer key window,
259 // so disable sharing parent key state. Share parent key state is only used 264 // so disable sharing parent key state. Share parent key state is only used
260 // to enable the close/minimize/maximize buttons of the parent window when 265 // to enable the close/minimize/maximize buttons of the parent window when
261 // the bubble has key state, so disabling it here is safe. 266 // the bubble has key state, so disabling it here is safe.
262 InfoBubbleWindow* bubbleWindow = 267 [[self bubbleWindow] setAllowShareParentKeyState:NO];
263 base::mac::ObjCCastStrict<InfoBubbleWindow>([self window]);
264 [bubbleWindow setAllowShareParentKeyState:NO];
265 } 268 }
266 269
267 - (void)windowDidBecomeKey:(NSNotification*)notification { 270 - (void)windowDidBecomeKey:(NSNotification*)notification {
268 // Re-enable share parent key state to make sure the close/minimize/maximize 271 // Re-enable share parent key state to make sure the close/minimize/maximize
269 // buttons of the parent window are active. 272 // buttons of the parent window are active.
270 InfoBubbleWindow* bubbleWindow = 273 [[self bubbleWindow] setAllowShareParentKeyState:YES];
271 base::mac::ObjCCastStrict<InfoBubbleWindow>([self window]);
272 [bubbleWindow setAllowShareParentKeyState:YES];
273 } 274 }
274 275
275 // Since the bubble shares first responder with its parent window, set event 276 // Since the bubble shares first responder with its parent window, set event
276 // handlers to dismiss the bubble when it would normally lose key state. 277 // handlers to dismiss the bubble when it would normally lose key state.
277 // Events on sheets are ignored: this assumes the sheet belongs to the bubble 278 // Events on sheets are ignored: this assumes the sheet belongs to the bubble
278 // since, to affect a sheet on a different window, the bubble would also lose 279 // since, to affect a sheet on a different window, the bubble would also lose
279 // key status in -[NSWindowDelegate windowDidResignKey:]. This keeps the logic 280 // key status in -[NSWindowDelegate windowDidResignKey:]. This keeps the logic
280 // simple, since -[NSWindow attachedSheet] returns nil while the sheet is still 281 // simple, since -[NSWindow attachedSheet] returns nil while the sheet is still
281 // closing. 282 // closing.
282 - (void)registerKeyStateEventTap { 283 - (void)registerKeyStateEventTap {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 382
382 - (void)activateTabWithContents:(content::WebContents*)newContents 383 - (void)activateTabWithContents:(content::WebContents*)newContents
383 previousContents:(content::WebContents*)oldContents 384 previousContents:(content::WebContents*)oldContents
384 atIndex:(NSInteger)index 385 atIndex:(NSInteger)index
385 reason:(int)reason { 386 reason:(int)reason {
386 // The user switched tabs; close. 387 // The user switched tabs; close.
387 [self close]; 388 [self close];
388 } 389 }
389 390
390 @end // BaseBubbleController 391 @end // BaseBubbleController
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/app_list_service_mac.mm ('k') | chrome/browser/ui/cocoa/info_bubble_window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698