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

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

Issue 2110983002: [Mac] Refactor Cocoa fullscreen code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Replaced NSTrackingArea with CrTrackingArea Created 4 years, 5 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/browser_window_controller.h" 5 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <numeric> 8 #include <numeric>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa .h" 52 #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa .h"
53 #import "chrome/browser/ui/cocoa/fast_resize_view.h" 53 #import "chrome/browser/ui/cocoa/fast_resize_view.h"
54 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" 54 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
55 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" 55 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h"
56 #import "chrome/browser/ui/cocoa/framed_browser_window.h" 56 #import "chrome/browser/ui/cocoa/framed_browser_window.h"
57 #include "chrome/browser/ui/cocoa/fullscreen_low_power_coordinator.h" 57 #include "chrome/browser/ui/cocoa/fullscreen_low_power_coordinator.h"
58 #import "chrome/browser/ui/cocoa/fullscreen_window.h" 58 #import "chrome/browser/ui/cocoa/fullscreen_window.h"
59 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" 59 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h"
60 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h" 60 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h"
61 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" 61 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h"
62 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" 62 #import "chrome/browser/ui/cocoa/fullscreen_toolbar_controller.h"
63 #import "chrome/browser/ui/cocoa/profiles/avatar_base_controller.h" 63 #import "chrome/browser/ui/cocoa/profiles/avatar_base_controller.h"
64 #import "chrome/browser/ui/cocoa/profiles/avatar_button_controller.h" 64 #import "chrome/browser/ui/cocoa/profiles/avatar_button_controller.h"
65 #import "chrome/browser/ui/cocoa/profiles/avatar_icon_controller.h" 65 #import "chrome/browser/ui/cocoa/profiles/avatar_icon_controller.h"
66 #import "chrome/browser/ui/cocoa/status_bubble_mac.h" 66 #import "chrome/browser/ui/cocoa/status_bubble_mac.h"
67 #import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h" 67 #import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h"
68 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" 68 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h"
69 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" 69 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
70 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" 70 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
71 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" 71 #import "chrome/browser/ui/cocoa/tabs/tab_view.h"
72 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 72 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 409
410 // We are done initializing now. 410 // We are done initializing now.
411 initializing_ = NO; 411 initializing_ = NO;
412 } 412 }
413 return self; 413 return self;
414 } 414 }
415 415
416 - (void)dealloc { 416 - (void)dealloc {
417 browser_->tab_strip_model()->CloseAllTabs(); 417 browser_->tab_strip_model()->CloseAllTabs();
418 418
419 // Explicitly release |presentationModeController_| here, as it may call back 419 // Explicitly release |fullscreenToolbarController_| here, as it may call back
420 // to this BWC in |-dealloc|. We are required to call |-exitPresentationMode| 420 // to this BWC in |-dealloc|. We are required to call |-exitFullscreenMode|
421 // before releasing the controller. 421 // before releasing the controller.
422 [presentationModeController_ exitPresentationMode]; 422 [fullscreenToolbarController_ exitFullscreenMode];
423 presentationModeController_.reset(); 423 fullscreenToolbarController_.reset();
424 424
425 // Explicitly release |fullscreenTransition_| here since it may call back to 425 // Explicitly release |fullscreenTransition_| here since it may call back to
426 // this BWC in |-dealloc|. Reset the fullscreen variables. 426 // this BWC in |-dealloc|. Reset the fullscreen variables.
427 if (fullscreenTransition_) { 427 if (fullscreenTransition_) {
428 [fullscreenTransition_ browserWillBeDestroyed]; 428 [fullscreenTransition_ browserWillBeDestroyed];
429 [self resetCustomAppKitFullscreenVariables]; 429 [self resetCustomAppKitFullscreenVariables];
430 } 430 }
431 431
432 // Under certain testing configurations we may not actually own the browser. 432 // Under certain testing configurations we may not actually own the browser.
433 if (ownsBrowser_ == NO) 433 if (ownsBrowser_ == NO)
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 manager = PermissionBubbleManager::FromWebContents(newContents); 1027 manager = PermissionBubbleManager::FromWebContents(newContents);
1028 if (manager) 1028 if (manager)
1029 manager->DisplayPendingRequests(); 1029 manager->DisplayPendingRequests();
1030 } 1030 }
1031 1031
1032 // If the web contents want to focus on the location bar, do not call the 1032 // If the web contents want to focus on the location bar, do not call the
1033 // animation since the location bar will drop down when it's focused. 1033 // animation since the location bar will drop down when it's focused.
1034 bool willFocusLocationBar = 1034 bool willFocusLocationBar =
1035 newContents && newContents->FocusLocationBarByDefault(); 1035 newContents && newContents->FocusLocationBarByDefault();
1036 if ([self isInAnyFullscreenMode] && !willFocusLocationBar) 1036 if ([self isInAnyFullscreenMode] && !willFocusLocationBar)
1037 [[self presentationModeController] revealToolbarForTabStripChanges]; 1037 [[self fullscreenToolbarController] revealToolbarForTabStripChanges];
1038 } 1038 }
1039 1039
1040 - (void)zoomChangedForActiveTab:(BOOL)canShowBubble { 1040 - (void)zoomChangedForActiveTab:(BOOL)canShowBubble {
1041 [toolbarController_ zoomChangedForActiveTab:canShowBubble]; 1041 [toolbarController_ zoomChangedForActiveTab:canShowBubble];
1042 } 1042 }
1043 1043
1044 // Return the rect, in WebKit coordinates (flipped), of the window's grow box 1044 // Return the rect, in WebKit coordinates (flipped), of the window's grow box
1045 // in the coordinate system of the content area of the currently selected tab. 1045 // in the coordinate system of the content area of the currently selected tab.
1046 // |windowGrowBox| needs to be in the window's coordinate system. 1046 // |windowGrowBox| needs to be in the window's coordinate system.
1047 - (NSRect)selectedTabGrowBoxRect { 1047 - (NSRect)selectedTabGrowBoxRect {
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 } 1479 }
1480 } 1480 }
1481 1481
1482 - (void)onTabDetachedWithContents:(WebContents*)contents { 1482 - (void)onTabDetachedWithContents:(WebContents*)contents {
1483 [infoBarContainerController_ tabDetachedWithContents:contents]; 1483 [infoBarContainerController_ tabDetachedWithContents:contents];
1484 } 1484 }
1485 1485
1486 - (void)onTabInsertedInForeground:(BOOL)inForeground { 1486 - (void)onTabInsertedInForeground:(BOOL)inForeground {
1487 if ([self isInAnyFullscreenMode] && !inForeground && 1487 if ([self isInAnyFullscreenMode] && !inForeground &&
1488 ![toolbarController_ isLocationBarFocused]) { 1488 ![toolbarController_ isLocationBarFocused]) {
1489 [[self presentationModeController] revealToolbarForTabStripChanges]; 1489 [[self fullscreenToolbarController] revealToolbarForTabStripChanges];
1490 } 1490 }
1491 } 1491 }
1492 1492
1493 - (void)userChangedTheme { 1493 - (void)userChangedTheme {
1494 NSView* rootView = [[[self window] contentView] superview]; 1494 NSView* rootView = [[[self window] contentView] superview];
1495 [rootView cr_recursivelyInvokeBlock:^(id view) { 1495 [rootView cr_recursivelyInvokeBlock:^(id view) {
1496 if ([view conformsToProtocol:@protocol(ThemedWindowDrawing)]) 1496 if ([view conformsToProtocol:@protocol(ThemedWindowDrawing)])
1497 [view windowDidChangeTheme]; 1497 [view windowDidChangeTheme];
1498 1498
1499 // TODO(andresantoso): Remove this once all themed views respond to 1499 // TODO(andresantoso): Remove this once all themed views respond to
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
1827 return 1827 return
1828 [[tabStripController_ activeTabContentsController] blockFullscreenResize]; 1828 [[tabStripController_ activeTabContentsController] blockFullscreenResize];
1829 } 1829 }
1830 1830
1831 - (void)sheetDidEnd:(NSWindow*)sheet 1831 - (void)sheetDidEnd:(NSWindow*)sheet
1832 returnCode:(NSInteger)code 1832 returnCode:(NSInteger)code
1833 context:(void*)context { 1833 context:(void*)context {
1834 [sheet orderOut:self]; 1834 [sheet orderOut:self];
1835 } 1835 }
1836 1836
1837 - (PresentationModeController*)presentationModeController { 1837 - (FullscreenToolbarController*)fullscreenToolbarController {
1838 return presentationModeController_.get(); 1838 return fullscreenToolbarController_.get();
1839 } 1839 }
1840 1840
1841 - (void)setPresentationModeController:(PresentationModeController*)controller { 1841 - (void)setFullscreenToolbarController:
1842 presentationModeController_.reset([controller retain]); 1842 (FullscreenToolbarController*)controller {
1843 fullscreenToolbarController_.reset([controller retain]);
1843 } 1844 }
1844 1845
1845 - (void)executeExtensionCommand:(const std::string&)extension_id 1846 - (void)executeExtensionCommand:(const std::string&)extension_id
1846 command:(const extensions::Command&)command { 1847 command:(const extensions::Command&)command {
1847 // Global commands are handled by the ExtensionCommandsGlobalRegistry 1848 // Global commands are handled by the ExtensionCommandsGlobalRegistry
1848 // instance. 1849 // instance.
1849 DCHECK(!command.global()); 1850 DCHECK(!command.global());
1850 extension_keybinding_registry_->ExecuteCommand(extension_id, 1851 extension_keybinding_registry_->ExecuteCommand(extension_id,
1851 command.accelerator()); 1852 command.accelerator());
1852 } 1853 }
1853 1854
1854 - (void)setAlertState:(TabAlertState)alertState { 1855 - (void)setAlertState:(TabAlertState)alertState {
1855 static_cast<BrowserWindowCocoa*>([self browserWindow]) 1856 static_cast<BrowserWindowCocoa*>([self browserWindow])
1856 ->UpdateAlertState(alertState); 1857 ->UpdateAlertState(alertState);
1857 } 1858 }
1858 1859
1859 - (TabAlertState)alertState { 1860 - (TabAlertState)alertState {
1860 return static_cast<BrowserWindowCocoa*>([self browserWindow])->alert_state(); 1861 return static_cast<BrowserWindowCocoa*>([self browserWindow])->alert_state();
1861 } 1862 }
1862 1863
1863 @end // @implementation BrowserWindowController 1864 @end // @implementation BrowserWindowController
1864 1865
1865 @implementation BrowserWindowController(Fullscreen) 1866 @implementation BrowserWindowController(Fullscreen)
1866 1867
1867 - (void)handleLionToggleFullscreen {
1868 chrome::ExecuteCommand(browser_.get(), IDC_FULLSCREEN);
1869 }
1870
1871 - (void)enterBrowserFullscreen { 1868 - (void)enterBrowserFullscreen {
1872 [self enterAppKitFullscreen]; 1869 [self enterAppKitFullscreen];
1873 } 1870 }
1874 1871
1875 - (void)updateUIForTabFullscreen: 1872 - (void)updateUIForTabFullscreen:
1876 (ExclusiveAccessContext::TabFullscreenState)state { 1873 (ExclusiveAccessContext::TabFullscreenState)state {
1877 DCHECK([self isInAnyFullscreenMode]); 1874 DCHECK([self isInAnyFullscreenMode]);
1878 if (state == ExclusiveAccessContext::STATE_ENTER_TAB_FULLSCREEN) { 1875 if (state == ExclusiveAccessContext::STATE_ENTER_TAB_FULLSCREEN) {
1879 [self adjustUIForSlidingFullscreenStyle:fullscreen_mac::OMNIBOX_TABS_NONE]; 1876 [self adjustUIForSlidingFullscreenStyle:fullscreen_mac::OMNIBOX_TABS_NONE];
1880 return; 1877 return;
(...skipping 16 matching lines...) Expand all
1897 browser_->extension_window_controller()->SetFullscreenMode(NO, GURL()); 1894 browser_->extension_window_controller()->SetFullscreenMode(NO, GURL());
1898 return YES; 1895 return YES;
1899 } 1896 }
1900 return NO; 1897 return NO;
1901 } 1898 }
1902 1899
1903 - (void)setFullscreenToolbarVisible:(BOOL)visible { 1900 - (void)setFullscreenToolbarVisible:(BOOL)visible {
1904 if (shouldShowFullscreenToolbar_ == visible) 1901 if (shouldShowFullscreenToolbar_ == visible)
1905 return; 1902 return;
1906 1903
1907 [presentationModeController_ setToolbarFraction:0.0]; 1904 [fullscreenToolbarController_ setToolbarFraction:0.0];
1908 shouldShowFullscreenToolbar_ = visible; 1905 shouldShowFullscreenToolbar_ = visible;
1909 [self adjustUIForSlidingFullscreenStyle: 1906 [self adjustUIForSlidingFullscreenStyle:
1910 shouldShowFullscreenToolbar_ ? fullscreen_mac::OMNIBOX_TABS_PRESENT 1907 shouldShowFullscreenToolbar_ ? fullscreen_mac::OMNIBOX_TABS_PRESENT
1911 : fullscreen_mac::OMNIBOX_TABS_HIDDEN]; 1908 : fullscreen_mac::OMNIBOX_TABS_HIDDEN];
1912 } 1909 }
1913 1910
1914 - (BOOL)isInAnyFullscreenMode { 1911 - (BOOL)isInAnyFullscreenMode {
1915 return [self isInImmersiveFullscreen] || [self isInAppKitFullscreen]; 1912 return [self isInImmersiveFullscreen] || [self isInAppKitFullscreen];
1916 } 1913 }
1917 1914
1918 - (BOOL)isInImmersiveFullscreen { 1915 - (BOOL)isInImmersiveFullscreen {
1919 return fullscreenWindow_.get() != nil || enteringImmersiveFullscreen_; 1916 return fullscreenWindow_.get() != nil || enteringImmersiveFullscreen_;
1920 } 1917 }
1921 1918
1922 - (BOOL)isInAppKitFullscreen { 1919 - (BOOL)isInAppKitFullscreen {
1923 return !exitingAppKitFullscreen_ && 1920 return !exitingAppKitFullscreen_ &&
1924 (([[self window] styleMask] & NSFullScreenWindowMask) == 1921 (([[self window] styleMask] & NSFullScreenWindowMask) ==
1925 NSFullScreenWindowMask || 1922 NSFullScreenWindowMask ||
1926 enteringAppKitFullscreen_); 1923 enteringAppKitFullscreen_);
1927 } 1924 }
1928 1925
1929 - (CGFloat)menubarOffset { 1926 - (CGFloat)menubarOffset {
1930 return [presentationModeController_ menubarOffset]; 1927 return [fullscreenToolbarController_ menubarOffset];
1931 } 1928 }
1932 1929
1933 - (NSView*)avatarView { 1930 - (NSView*)avatarView {
1934 return [avatarButtonController_ view]; 1931 return [avatarButtonController_ view];
1935 } 1932 }
1936 1933
1937 - (void)enterWebContentFullscreen { 1934 - (void)enterWebContentFullscreen {
1938 // HTML5 Fullscreen should only use AppKit fullscreen in 10.10+. 1935 // HTML5 Fullscreen should only use AppKit fullscreen in 10.10+.
1939 // However, if the user is using multiple monitors and turned off 1936 // However, if the user is using multiple monitors and turned off
1940 // "Separate Space in Each Display", use Immersive Fullscreen so 1937 // "Separate Space in Each Display", use Immersive Fullscreen so
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1983 DCHECK(barVisibilityLocks_); 1980 DCHECK(barVisibilityLocks_);
1984 return [barVisibilityLocks_ containsObject:owner]; 1981 return [barVisibilityLocks_ containsObject:owner];
1985 } 1982 }
1986 1983
1987 - (void)lockBarVisibilityForOwner:(id)owner 1984 - (void)lockBarVisibilityForOwner:(id)owner
1988 withAnimation:(BOOL)animate 1985 withAnimation:(BOOL)animate
1989 delay:(BOOL)delay { 1986 delay:(BOOL)delay {
1990 if (![self isBarVisibilityLockedForOwner:owner]) { 1987 if (![self isBarVisibilityLockedForOwner:owner]) {
1991 [barVisibilityLocks_ addObject:owner]; 1988 [barVisibilityLocks_ addObject:owner];
1992 1989
1993 // If enabled, show the overlay if necessary (and if in presentation mode). 1990 // If enabled, show the overlay if necessary (and if the fullscreen
1991 // toolbar is hidden).
1994 if (barVisibilityUpdatesEnabled_) { 1992 if (barVisibilityUpdatesEnabled_) {
1995 [presentationModeController_ ensureOverlayShownWithAnimation:animate 1993 [fullscreenToolbarController_ ensureOverlayShownWithAnimation:animate
1996 delay:delay]; 1994 delay:delay];
1997 } 1995 }
1998 } 1996 }
1999 } 1997 }
2000 1998
2001 - (void)releaseBarVisibilityForOwner:(id)owner 1999 - (void)releaseBarVisibilityForOwner:(id)owner
2002 withAnimation:(BOOL)animate 2000 withAnimation:(BOOL)animate
2003 delay:(BOOL)delay { 2001 delay:(BOOL)delay {
2004 if ([self isBarVisibilityLockedForOwner:owner]) { 2002 if ([self isBarVisibilityLockedForOwner:owner]) {
2005 [barVisibilityLocks_ removeObject:owner]; 2003 [barVisibilityLocks_ removeObject:owner];
2006 2004
2007 // If enabled, hide the overlay if necessary (and if in presentation mode). 2005 // If enabled, hide the overlay if necessary (and if the fullscreen
2006 // toolbar is hidden).
2008 if (barVisibilityUpdatesEnabled_ && 2007 if (barVisibilityUpdatesEnabled_ &&
2009 ![barVisibilityLocks_ count]) { 2008 ![barVisibilityLocks_ count]) {
2010 [presentationModeController_ ensureOverlayHiddenWithAnimation:animate 2009 [fullscreenToolbarController_ ensureOverlayHiddenWithAnimation:animate
2011 delay:delay]; 2010 delay:delay];
2012 } 2011 }
2013 } 2012 }
2014 } 2013 }
2015 2014
2016 - (BOOL)floatingBarHasFocus { 2015 - (BOOL)floatingBarHasFocus {
2017 NSResponder* focused = [[self window] firstResponder]; 2016 NSResponder* focused = [[self window] firstResponder];
2018 return [focused isKindOfClass:[AutocompleteTextFieldEditor class]]; 2017 return [focused isKindOfClass:[AutocompleteTextFieldEditor class]];
2019 } 2018 }
2020 2019
2021 - (ExclusiveAccessController*)exclusiveAccessController { 2020 - (ExclusiveAccessController*)exclusiveAccessController {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2054 2053
2055 - (NSRect)savedRegularWindowFrame { 2054 - (NSRect)savedRegularWindowFrame {
2056 return savedRegularWindowFrame_; 2055 return savedRegularWindowFrame_;
2057 } 2056 }
2058 2057
2059 - (BOOL)isFullscreenTransitionInProgress { 2058 - (BOOL)isFullscreenTransitionInProgress {
2060 return enteringAppKitFullscreen_ || exitingAppKitFullscreen_; 2059 return enteringAppKitFullscreen_ || exitingAppKitFullscreen_;
2061 } 2060 }
2062 2061
2063 @end // @implementation BrowserWindowController(WindowType) 2062 @end // @implementation BrowserWindowController(WindowType)
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/browser_window_controller.h ('k') | chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698