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/ui/cocoa/fullscreen_controller.h" | 5 #import "chrome/browser/ui/cocoa/fullscreen_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
| 9 #import "base/mac/mac_util.h" |
9 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 10 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
10 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" | 11 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" |
11 | 12 |
12 NSString* const kWillEnterFullscreenNotification = | 13 NSString* const kWillEnterFullscreenNotification = |
13 @"WillEnterFullscreenNotification"; | 14 @"WillEnterFullscreenNotification"; |
14 NSString* const kWillLeaveFullscreenNotification = | 15 NSString* const kWillLeaveFullscreenNotification = |
15 @"WillLeaveFullscreenNotification"; | 16 @"WillLeaveFullscreenNotification"; |
16 | 17 |
17 namespace { | 18 namespace { |
18 // The activation zone for the main menu is 4 pixels high; if we make it any | 19 // The activation zone for the main menu is 4 pixels high; if we make it any |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 // Returns YES if the fullscreen window is on the primary screen. | 96 // Returns YES if the fullscreen window is on the primary screen. |
96 - (BOOL)isWindowOnPrimaryScreen; | 97 - (BOOL)isWindowOnPrimaryScreen; |
97 | 98 |
98 // Returns YES if it is ok to show and hide the menu bar in response to the | 99 // Returns YES if it is ok to show and hide the menu bar in response to the |
99 // overlay opening and closing. Will return NO if the window is not main or not | 100 // overlay opening and closing. Will return NO if the window is not main or not |
100 // on the primary monitor. | 101 // on the primary monitor. |
101 - (BOOL)shouldToggleMenuBar; | 102 - (BOOL)shouldToggleMenuBar; |
102 | 103 |
103 // Returns |kFullScreenModeHideAll| when the overlay is hidden and | 104 // Returns |kFullScreenModeHideAll| when the overlay is hidden and |
104 // |kFullScreenModeHideDock| when the overlay is shown. | 105 // |kFullScreenModeHideDock| when the overlay is shown. |
105 - (mac_util::FullScreenMode)desiredFullscreenMode; | 106 - (base::mac::FullScreenMode)desiredFullscreenMode; |
106 | 107 |
107 // Change the overlay to the given fraction, with or without animation. Only | 108 // Change the overlay to the given fraction, with or without animation. Only |
108 // guaranteed to work properly with |fraction == 0| or |fraction == 1|. This | 109 // guaranteed to work properly with |fraction == 0| or |fraction == 1|. This |
109 // performs the show/hide (animation) immediately. It does not touch the timers. | 110 // performs the show/hide (animation) immediately. It does not touch the timers. |
110 - (void)changeOverlayToFraction:(CGFloat)fraction | 111 - (void)changeOverlayToFraction:(CGFloat)fraction |
111 withAnimation:(BOOL)animate; | 112 withAnimation:(BOOL)animate; |
112 | 113 |
113 // Schedule the floating bar to be shown/hidden because of mouse position. | 114 // Schedule the floating bar to be shown/hidden because of mouse position. |
114 - (void)scheduleShowForMouse; | 115 - (void)scheduleShowForMouse; |
115 - (void)scheduleHideForMouse; | 116 - (void)scheduleHideForMouse; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 @end | 160 @end |
160 | 161 |
161 | 162 |
162 @implementation FullscreenController | 163 @implementation FullscreenController |
163 | 164 |
164 @synthesize isFullscreen = isFullscreen_; | 165 @synthesize isFullscreen = isFullscreen_; |
165 | 166 |
166 - (id)initWithBrowserController:(BrowserWindowController*)controller { | 167 - (id)initWithBrowserController:(BrowserWindowController*)controller { |
167 if ((self == [super init])) { | 168 if ((self == [super init])) { |
168 browserController_ = controller; | 169 browserController_ = controller; |
169 currentFullscreenMode_ = mac_util::kFullScreenModeNormal; | 170 currentFullscreenMode_ = base::mac::kFullScreenModeNormal; |
170 } | 171 } |
171 | 172 |
172 // Let the world know what we're up to. | 173 // Let the world know what we're up to. |
173 [[NSNotificationCenter defaultCenter] | 174 [[NSNotificationCenter defaultCenter] |
174 postNotificationName:kWillEnterFullscreenNotification | 175 postNotificationName:kWillEnterFullscreenNotification |
175 object:nil]; | 176 object:nil]; |
176 | 177 |
177 return self; | 178 return self; |
178 } | 179 } |
179 | 180 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 currentAnimation_.reset(); | 309 currentAnimation_.reset(); |
309 } | 310 } |
310 | 311 |
311 - (CGFloat)floatingBarShownFraction { | 312 - (CGFloat)floatingBarShownFraction { |
312 return [browserController_ floatingBarShownFraction]; | 313 return [browserController_ floatingBarShownFraction]; |
313 } | 314 } |
314 | 315 |
315 - (void)changeFloatingBarShownFraction:(CGFloat)fraction { | 316 - (void)changeFloatingBarShownFraction:(CGFloat)fraction { |
316 [browserController_ setFloatingBarShownFraction:fraction]; | 317 [browserController_ setFloatingBarShownFraction:fraction]; |
317 | 318 |
318 mac_util::FullScreenMode desiredMode = [self desiredFullscreenMode]; | 319 base::mac::FullScreenMode desiredMode = [self desiredFullscreenMode]; |
319 if (desiredMode != currentFullscreenMode_ && [self shouldToggleMenuBar]) { | 320 if (desiredMode != currentFullscreenMode_ && [self shouldToggleMenuBar]) { |
320 if (currentFullscreenMode_ == mac_util::kFullScreenModeNormal) | 321 if (currentFullscreenMode_ == base::mac::kFullScreenModeNormal) |
321 mac_util::RequestFullScreen(desiredMode); | 322 base::mac::RequestFullScreen(desiredMode); |
322 else | 323 else |
323 mac_util::SwitchFullScreenModes(currentFullscreenMode_, desiredMode); | 324 base::mac::SwitchFullScreenModes(currentFullscreenMode_, desiredMode); |
324 currentFullscreenMode_ = desiredMode; | 325 currentFullscreenMode_ = desiredMode; |
325 } | 326 } |
326 } | 327 } |
327 | 328 |
328 // Used to activate the floating bar in fullscreen mode. | 329 // Used to activate the floating bar in fullscreen mode. |
329 - (void)mouseEntered:(NSEvent*)event { | 330 - (void)mouseEntered:(NSEvent*)event { |
330 DCHECK(isFullscreen_); | 331 DCHECK(isFullscreen_); |
331 | 332 |
332 // Having gotten a mouse entered, we no longer need to do exit checks. | 333 // Having gotten a mouse entered, we no longer need to do exit checks. |
333 [self cancelMouseExitCheck]; | 334 [self cancelMouseExitCheck]; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 NSScreen* screen = [[browserController_ window] screen]; | 399 NSScreen* screen = [[browserController_ window] screen]; |
399 NSScreen* primaryScreen = [[NSScreen screens] objectAtIndex:0]; | 400 NSScreen* primaryScreen = [[NSScreen screens] objectAtIndex:0]; |
400 return (screen == primaryScreen); | 401 return (screen == primaryScreen); |
401 } | 402 } |
402 | 403 |
403 - (BOOL)shouldToggleMenuBar { | 404 - (BOOL)shouldToggleMenuBar { |
404 return [self isWindowOnPrimaryScreen] && | 405 return [self isWindowOnPrimaryScreen] && |
405 [[browserController_ window] isMainWindow]; | 406 [[browserController_ window] isMainWindow]; |
406 } | 407 } |
407 | 408 |
408 - (mac_util::FullScreenMode)desiredFullscreenMode { | 409 - (base::mac::FullScreenMode)desiredFullscreenMode { |
409 if ([browserController_ floatingBarShownFraction] >= 1.0) | 410 if ([browserController_ floatingBarShownFraction] >= 1.0) |
410 return mac_util::kFullScreenModeHideDock; | 411 return base::mac::kFullScreenModeHideDock; |
411 return mac_util::kFullScreenModeHideAll; | 412 return base::mac::kFullScreenModeHideAll; |
412 } | 413 } |
413 | 414 |
414 - (void)changeOverlayToFraction:(CGFloat)fraction | 415 - (void)changeOverlayToFraction:(CGFloat)fraction |
415 withAnimation:(BOOL)animate { | 416 withAnimation:(BOOL)animate { |
416 // The non-animated case is really simple, so do it and return. | 417 // The non-animated case is really simple, so do it and return. |
417 if (!animate) { | 418 if (!animate) { |
418 [currentAnimation_ stopAnimation]; | 419 [currentAnimation_ stopAnimation]; |
419 [self changeFloatingBarShownFraction:fraction]; | 420 [self changeFloatingBarShownFraction:fraction]; |
420 return; | 421 return; |
421 } | 422 } |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 // Call the main status resignation code to perform the associated cleanup, | 602 // Call the main status resignation code to perform the associated cleanup, |
602 // since we will no longer be receiving actual status resignation | 603 // since we will no longer be receiving actual status resignation |
603 // notifications. | 604 // notifications. |
604 [self hideActiveWindowUI]; | 605 [self hideActiveWindowUI]; |
605 | 606 |
606 // No more calls back up to the BWC. | 607 // No more calls back up to the BWC. |
607 browserController_ = nil; | 608 browserController_ = nil; |
608 } | 609 } |
609 | 610 |
610 - (void)showActiveWindowUI { | 611 - (void)showActiveWindowUI { |
611 DCHECK_EQ(currentFullscreenMode_, mac_util::kFullScreenModeNormal); | 612 DCHECK_EQ(currentFullscreenMode_, base::mac::kFullScreenModeNormal); |
612 if (currentFullscreenMode_ != mac_util::kFullScreenModeNormal) | 613 if (currentFullscreenMode_ != base::mac::kFullScreenModeNormal) |
613 return; | 614 return; |
614 | 615 |
615 if ([self shouldToggleMenuBar]) { | 616 if ([self shouldToggleMenuBar]) { |
616 mac_util::FullScreenMode desiredMode = [self desiredFullscreenMode]; | 617 base::mac::FullScreenMode desiredMode = [self desiredFullscreenMode]; |
617 mac_util::RequestFullScreen(desiredMode); | 618 base::mac::RequestFullScreen(desiredMode); |
618 currentFullscreenMode_ = desiredMode; | 619 currentFullscreenMode_ = desiredMode; |
619 } | 620 } |
620 | 621 |
621 // TODO(rohitrao): Insert the Exit Fullscreen button. http://crbug.com/35956 | 622 // TODO(rohitrao): Insert the Exit Fullscreen button. http://crbug.com/35956 |
622 } | 623 } |
623 | 624 |
624 - (void)hideActiveWindowUI { | 625 - (void)hideActiveWindowUI { |
625 if (currentFullscreenMode_ != mac_util::kFullScreenModeNormal) { | 626 if (currentFullscreenMode_ != base::mac::kFullScreenModeNormal) { |
626 mac_util::ReleaseFullScreen(currentFullscreenMode_); | 627 base::mac::ReleaseFullScreen(currentFullscreenMode_); |
627 currentFullscreenMode_ = mac_util::kFullScreenModeNormal; | 628 currentFullscreenMode_ = base::mac::kFullScreenModeNormal; |
628 } | 629 } |
629 | 630 |
630 // TODO(rohitrao): Remove the Exit Fullscreen button. http://crbug.com/35956 | 631 // TODO(rohitrao): Remove the Exit Fullscreen button. http://crbug.com/35956 |
631 } | 632 } |
632 | 633 |
633 @end | 634 @end |
OLD | NEW |