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

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

Issue 1881093002: Implement Tab Detaching in Fullscreen Mode on Mac OSX (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add to the histogram Created 4 years, 8 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 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 356
357 // We don't want to try and show the bar before it gets placed in its parent 357 // We don't want to try and show the bar before it gets placed in its parent
358 // view, so this step shoudn't be inside the bookmark bar controller's 358 // view, so this step shoudn't be inside the bookmark bar controller's
359 // |-awakeFromNib|. 359 // |-awakeFromNib|.
360 windowShim_->BookmarkBarStateChanged( 360 windowShim_->BookmarkBarStateChanged(
361 BookmarkBar::DONT_ANIMATE_STATE_CHANGE); 361 BookmarkBar::DONT_ANIMATE_STATE_CHANGE);
362 362
363 // Allow bar visibility to be changed. 363 // Allow bar visibility to be changed.
364 [self enableBarVisibilityUpdates]; 364 [self enableBarVisibilityUpdates];
365 365
366 // Set the window to participate in Lion Fullscreen mode. Setting this flag 366 [self updateFullscreenCollectionBehavior];
367 // has no effect on Snow Leopard or earlier. Panels can share a fullscreen
368 // space with a tabbed window, but they can not be primary fullscreen
369 // windows.
370 // This ensures the fullscreen button is appropriately positioned. It must
371 // be done before calling layoutSubviews because the new avatar button's
372 // position depends on the fullscreen button's position, as well as
373 // TabStripController's rightIndentForControls.
374 // The fullscreen button's position may depend on the old avatar button's
375 // width, but that does not require calling layoutSubviews first.
376 NSUInteger collectionBehavior = [window collectionBehavior];
377 collectionBehavior |=
378 browser_->type() == Browser::TYPE_TABBED ||
379 browser_->type() == Browser::TYPE_POPUP ?
380 NSWindowCollectionBehaviorFullScreenPrimary :
381 NSWindowCollectionBehaviorFullScreenAuxiliary;
382 [window setCollectionBehavior:collectionBehavior];
383 367
384 [self layoutSubviews]; 368 [self layoutSubviews];
385 369
386 // For non-trusted, non-app popup windows, |desiredContentRect| contains the 370 // For non-trusted, non-app popup windows, |desiredContentRect| contains the
387 // desired height of the content, not of the whole window. Now that all the 371 // desired height of the content, not of the whole window. Now that all the
388 // views are laid out, measure the current content area size and grow if 372 // views are laid out, measure the current content area size and grow if
389 // needed. The window has not been placed onscreen yet, so this extra resize 373 // needed. The window has not been placed onscreen yet, so this extra resize
390 // will not cause visible jank. 374 // will not cause visible jank.
391 if (chrome::SavedBoundsAreContentBounds(browser_.get())) { 375 if (chrome::SavedBoundsAreContentBounds(browser_.get())) {
392 CGFloat deltaH = desiredContentRect.height() - 376 CGFloat deltaH = desiredContentRect.height() -
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 1182
1199 // Disable screen updates so that this appears as a single visual change. 1183 // Disable screen updates so that this appears as a single visual change.
1200 gfx::ScopedCocoaDisableScreenUpdates disabler; 1184 gfx::ScopedCocoaDisableScreenUpdates disabler;
1201 1185
1202 // Set the window size. Need to do this before we detach the tab so it's 1186 // Set the window size. Need to do this before we detach the tab so it's
1203 // still in the window. We have to flip the coordinates as that's what 1187 // still in the window. We have to flip the coordinates as that's what
1204 // is expected by the Browser code. 1188 // is expected by the Browser code.
1205 NSWindow* sourceWindow = [draggedTab window]; 1189 NSWindow* sourceWindow = [draggedTab window];
1206 NSRect windowRect = [sourceWindow frame]; 1190 NSRect windowRect = [sourceWindow frame];
1207 NSScreen* screen = [sourceWindow screen]; 1191 NSScreen* screen = [sourceWindow screen];
1208 windowRect.origin.y = NSHeight([screen frame]) - NSMaxY(windowRect); 1192 windowRect.origin.y =
1193 NSHeight([screen frame]) - NSMaxY(windowRect) + [self menubarOffset];
1209 gfx::Rect browserRect(windowRect.origin.x, windowRect.origin.y, 1194 gfx::Rect browserRect(windowRect.origin.x, windowRect.origin.y,
1210 NSWidth(windowRect), NSHeight(windowRect)); 1195 NSWidth(windowRect), NSHeight(windowRect));
1211 1196
1212 std::vector<TabStripModelDelegate::NewStripContents> contentses; 1197 std::vector<TabStripModelDelegate::NewStripContents> contentses;
1213 TabStripModel* model = browser_->tab_strip_model(); 1198 TabStripModel* model = browser_->tab_strip_model();
1214 1199
1215 for (TabView* tabView in tabViews) { 1200 for (TabView* tabView in tabViews) {
1216 // Fetch the tab contents for the tab being dragged. 1201 // Fetch the tab contents for the tab being dragged.
1217 int index = [tabStripController_ modelIndexForTabView:tabView]; 1202 int index = [tabStripController_ modelIndexForTabView:tabView];
1218 bool isPinned = model->IsTabPinned(index); 1203 bool isPinned = model->IsTabPinned(index);
(...skipping 19 matching lines...) Expand all
1238 // Create a new window with the dragged tabs in its model. 1223 // Create a new window with the dragged tabs in its model.
1239 Browser* newBrowser = browser_->tab_strip_model()->delegate()-> 1224 Browser* newBrowser = browser_->tab_strip_model()->delegate()->
1240 CreateNewStripWithContents(contentses, browserRect, false); 1225 CreateNewStripWithContents(contentses, browserRect, false);
1241 1226
1242 // Get the new controller by asking the new window for its delegate. 1227 // Get the new controller by asking the new window for its delegate.
1243 BrowserWindowController* controller = 1228 BrowserWindowController* controller =
1244 reinterpret_cast<BrowserWindowController*>( 1229 reinterpret_cast<BrowserWindowController*>(
1245 [newBrowser->window()->GetNativeWindow() delegate]); 1230 [newBrowser->window()->GetNativeWindow() delegate]);
1246 DCHECK(controller && [controller isKindOfClass:[TabWindowController class]]); 1231 DCHECK(controller && [controller isKindOfClass:[TabWindowController class]]);
1247 1232
1233 // Ensure that the window will appear on top of the source window in
1234 // fullscreen mode.
1235 if ([self isInAppKitFullscreen]) {
1236 NSWindow* window = [controller window];
1237 NSUInteger collectionBehavior = [window collectionBehavior];
1238 collectionBehavior &= ~NSWindowCollectionBehaviorFullScreenPrimary;
1239 collectionBehavior |= NSWindowCollectionBehaviorFullScreenAuxiliary;
1240 [window setCollectionBehavior:collectionBehavior];
1241 [window setLevel:NSFloatingWindowLevel];
1242
1243 controller->savedRegularWindowFrame_ = savedRegularWindowFrame_;
1244 }
1245
1248 // And make sure we use the correct frame in the new view. 1246 // And make sure we use the correct frame in the new view.
1249 TabStripController* tabStripController = [controller tabStripController]; 1247 TabStripController* tabStripController = [controller tabStripController];
1250 NSView* tabStrip = [self tabStripView]; 1248 NSView* tabStrip = [self tabStripView];
1251 NSEnumerator* tabEnumerator = [tabViews objectEnumerator]; 1249 NSEnumerator* tabEnumerator = [tabViews objectEnumerator];
1252 for (NSView* newView in [tabStripController tabViews]) { 1250 for (NSView* newView in [tabStripController tabViews]) {
1253 NSView* oldView = [tabEnumerator nextObject]; 1251 NSView* oldView = [tabEnumerator nextObject];
1254 if (oldView) { 1252 if (oldView) {
1255 // Pushes tabView's frame back inside the tabstrip. 1253 // Pushes tabView's frame back inside the tabstrip.
1256 NSRect sourceTabRect = [oldView frame]; 1254 NSRect sourceTabRect = [oldView frame];
1257 NSSize tabOverflow = 1255 NSSize tabOverflow =
1258 [self overflowFrom:[tabStrip convertRect:sourceTabRect toView:nil] 1256 [self overflowFrom:[tabStrip convertRect:sourceTabRect toView:nil]
1259 to:[tabStrip frame]]; 1257 to:[tabStrip frame]];
1260 NSRect tabRect = 1258 NSRect tabRect =
1261 NSOffsetRect(sourceTabRect, -tabOverflow.width, -tabOverflow.height); 1259 NSOffsetRect(sourceTabRect, -tabOverflow.width, -tabOverflow.height);
1262 // Force the added tab to the right size (remove stretching.) 1260 // Force the added tab to the right size (remove stretching.)
1263 tabRect.size.height = [TabStripController defaultTabHeight]; 1261 tabRect.size.height = [TabStripController defaultTabHeight];
1264 1262
1265 [tabStripController setFrame:tabRect ofTabView:newView]; 1263 [tabStripController setFrame:tabRect ofTabView:newView];
1266 } 1264 }
1267 } 1265 }
1268 1266
1269 return controller; 1267 return controller;
1270 } 1268 }
1271 1269
1270 - (void)detachedWindowEnterFullscreenIfNeeded:(TabWindowController*)source {
1271 // Ensure that this is only called when the tab is detached into its own
1272 // window (in which the overlay window will be present).
1273 DCHECK([self overlayWindow]);
1274
1275 if (([[source window] styleMask] & NSFullScreenWindowMask)
1276 == NSFullScreenWindowMask) {
1277 [self updateFullscreenCollectionBehavior];
1278
1279 // Since the detached window in fullscreen will have the size of the
1280 // screen, it will set |savedRegularWindowFrame_| to the screen size after
1281 // it enters fullscreen. Make sure that we have the correct value for the
1282 // |savedRegularWindowFrame_|.
1283 NSRect regularWindowFrame = savedRegularWindowFrame_;
1284 [[self window] toggleFullScreen:nil];
1285 savedRegularWindowFrame_ = regularWindowFrame;
1286 }
1287 }
1288
1272 - (void)insertPlaceholderForTab:(TabView*)tab 1289 - (void)insertPlaceholderForTab:(TabView*)tab
1273 frame:(NSRect)frame { 1290 frame:(NSRect)frame {
1274 [super insertPlaceholderForTab:tab frame:frame]; 1291 [super insertPlaceholderForTab:tab frame:frame];
1275 [tabStripController_ insertPlaceholderForTab:tab frame:frame]; 1292 [tabStripController_ insertPlaceholderForTab:tab frame:frame];
1276 } 1293 }
1277 1294
1278 - (void)removePlaceholder { 1295 - (void)removePlaceholder {
1279 [super removePlaceholder]; 1296 [super removePlaceholder];
1280 [tabStripController_ insertPlaceholderForTab:nil frame:NSZeroRect]; 1297 [tabStripController_ insertPlaceholderForTab:nil frame:NSZeroRect];
1281 } 1298 }
1282 1299
1283 - (BOOL)isDragSessionActive { 1300 - (BOOL)isDragSessionActive {
1284 // The tab can be dragged within the existing tab strip or detached 1301 // The tab can be dragged within the existing tab strip or detached
1285 // into its own window (then the overlay window will be present). 1302 // into its own window (then the overlay window will be present).
1286 return [[self tabStripController] isDragSessionActive] || 1303 return [[self tabStripController] isDragSessionActive] ||
1287 [self overlayWindow] != nil; 1304 [self overlayWindow] != nil;
1288 } 1305 }
1289 1306
1290 - (BOOL)tabDraggingAllowed { 1307 - (BOOL)tabDraggingAllowed {
1291 return [tabStripController_ tabDraggingAllowed]; 1308 return [tabStripController_ tabDraggingAllowed];
1292 } 1309 }
1293 1310
1294 - (BOOL)tabTearingAllowed { 1311 - (BOOL)tabTearingAllowed {
1295 return ![self isInAnyFullscreenMode]; 1312 return ![self isInAnyFullscreenMode] ||
1313 base::CommandLine::ForCurrentProcess()->HasSwitch(
1314 switches::kEnableFullscreenTabDetaching);
1296 } 1315 }
1297 1316
1298 - (BOOL)windowMovementAllowed { 1317 - (BOOL)windowMovementAllowed {
1299 return ![self isInAnyFullscreenMode]; 1318 return ![self isInAnyFullscreenMode] || [self overlayWindow];
1300 } 1319 }
1301 1320
1302 - (BOOL)isTabFullyVisible:(TabView*)tab { 1321 - (BOOL)isTabFullyVisible:(TabView*)tab {
1303 return [tabStripController_ isTabFullyVisible:tab]; 1322 return [tabStripController_ isTabFullyVisible:tab];
1304 } 1323 }
1305 1324
1306 - (void)showNewTabButton:(BOOL)show { 1325 - (void)showNewTabButton:(BOOL)show {
1307 [tabStripController_ showNewTabButton:show]; 1326 [tabStripController_ showNewTabButton:show];
1308 } 1327 }
1309 1328
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
1901 return fullscreenWindow_.get() != nil || enteringImmersiveFullscreen_; 1920 return fullscreenWindow_.get() != nil || enteringImmersiveFullscreen_;
1902 } 1921 }
1903 1922
1904 - (BOOL)isInAppKitFullscreen { 1923 - (BOOL)isInAppKitFullscreen {
1905 return !exitingAppKitFullscreen_ && 1924 return !exitingAppKitFullscreen_ &&
1906 (([[self window] styleMask] & NSFullScreenWindowMask) == 1925 (([[self window] styleMask] & NSFullScreenWindowMask) ==
1907 NSFullScreenWindowMask || 1926 NSFullScreenWindowMask ||
1908 enteringAppKitFullscreen_); 1927 enteringAppKitFullscreen_);
1909 } 1928 }
1910 1929
1930 - (CGFloat)menubarOffset {
1931 return [presentationModeController_ menubarOffset];
1932 }
1933
1911 - (void)enterExtensionFullscreen { 1934 - (void)enterExtensionFullscreen {
1912 if (chrome::mac::SupportsSystemFullscreen()) { 1935 if (chrome::mac::SupportsSystemFullscreen()) {
1913 [self enterBrowserFullscreenWithToolbar:NO]; 1936 [self enterBrowserFullscreenWithToolbar:NO];
1914 } else { 1937 } else {
1915 [self enterImmersiveFullscreen]; 1938 [self enterImmersiveFullscreen];
1916 DCHECK(!exclusiveAccessController_->url().is_empty()); 1939 DCHECK(!exclusiveAccessController_->url().is_empty());
1917 [self updateFullscreenExitBubble]; 1940 [self updateFullscreenExitBubble];
1918 } 1941 }
1919 } 1942 }
1920 1943
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
2046 2069
2047 - (BOOL)isTabbedWindow { 2070 - (BOOL)isTabbedWindow {
2048 return browser_->is_type_tabbed(); 2071 return browser_->is_type_tabbed();
2049 } 2072 }
2050 2073
2051 - (NSRect)savedRegularWindowFrame { 2074 - (NSRect)savedRegularWindowFrame {
2052 return savedRegularWindowFrame_; 2075 return savedRegularWindowFrame_;
2053 } 2076 }
2054 2077
2055 @end // @implementation BrowserWindowController(WindowType) 2078 @end // @implementation BrowserWindowController(WindowType)
OLDNEW
« no previous file with comments | « chrome/browser/about_flags.cc ('k') | chrome/browser/ui/cocoa/browser_window_controller_private.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698