| 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/browser_window_controller_private.h" | 5 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 // While we move views (and focus) around, disable any bar visibility changes. | 281 // While we move views (and focus) around, disable any bar visibility changes. |
| 282 [self disableBarVisibilityUpdates]; | 282 [self disableBarVisibilityUpdates]; |
| 283 | 283 |
| 284 // Retain the tab strip view while we remove it from its superview. | 284 // Retain the tab strip view while we remove it from its superview. |
| 285 base::scoped_nsobject<NSView> tabStripView; | 285 base::scoped_nsobject<NSView> tabStripView; |
| 286 if ([self hasTabStrip]) { | 286 if ([self hasTabStrip]) { |
| 287 tabStripView.reset([[self tabStripView] retain]); | 287 tabStripView.reset([[self tabStripView] retain]); |
| 288 [tabStripView removeFromSuperview]; | 288 [tabStripView removeFromSuperview]; |
| 289 } | 289 } |
| 290 | 290 |
| 291 // Ditto for the content view. | |
| 292 base::scoped_nsobject<NSView> contentView( | |
| 293 [[sourceWindow contentView] retain]); | |
| 294 // Disable autoresizing of subviews while we move views around. This prevents | 291 // Disable autoresizing of subviews while we move views around. This prevents |
| 295 // spurious renderer resizes. | 292 // spurious renderer resizes. |
| 296 [contentView setAutoresizesSubviews:NO]; | 293 [self.chromeContentView setAutoresizesSubviews:NO]; |
| 297 [contentView removeFromSuperview]; | 294 [self.chromeContentView removeFromSuperview]; |
| 298 | 295 |
| 299 // Have to do this here, otherwise later calls can crash because the window | 296 // Have to do this here, otherwise later calls can crash because the window |
| 300 // has no delegate. | 297 // has no delegate. |
| 301 [sourceWindow setDelegate:nil]; | 298 [sourceWindow setDelegate:nil]; |
| 302 [destWindow setDelegate:self]; | 299 [destWindow setDelegate:self]; |
| 303 | 300 |
| 304 // With this call, valgrind complains that a "Conditional jump or move depends | 301 // With this call, valgrind complains that a "Conditional jump or move depends |
| 305 // on uninitialised value(s)". The error happens in -[NSThemeFrame | 302 // on uninitialised value(s)". The error happens in -[NSThemeFrame |
| 306 // drawOverlayRect:]. I'm pretty convinced this is an Apple bug, but there is | 303 // drawOverlayRect:]. I'm pretty convinced this is an Apple bug, but there is |
| 307 // no visual impact. I have been unable to tickle it away with other window | 304 // no visual impact. I have been unable to tickle it away with other window |
| 308 // or view manipulation Cocoa calls. Stack added to suppressions_mac.txt. | 305 // or view manipulation Cocoa calls. Stack added to suppressions_mac.txt. |
| 309 [contentView setAutoresizesSubviews:YES]; | 306 [self.chromeContentView setAutoresizesSubviews:YES]; |
| 310 [destWindow setContentView:contentView]; | 307 [[destWindow contentView] addSubview:self.chromeContentView |
| 311 [self moveContentViewToBack:contentView]; | 308 positioned:NSWindowBelow |
| 309 relativeTo:nil]; |
| 310 [self.chromeContentView setFrame:[[destWindow contentView] bounds]]; |
| 312 | 311 |
| 313 // Move the incognito badge if present. | 312 // Move the incognito badge if present. |
| 314 if ([self shouldShowAvatar]) { | 313 if ([self shouldShowAvatar]) { |
| 315 NSView* avatarButtonView = [avatarButtonController_ view]; | 314 NSView* avatarButtonView = [avatarButtonController_ view]; |
| 316 | 315 |
| 317 [avatarButtonView removeFromSuperview]; | 316 [avatarButtonView removeFromSuperview]; |
| 318 [avatarButtonView setHidden:YES]; // Will be shown in layout. | 317 [avatarButtonView setHidden:YES]; // Will be shown in layout. |
| 319 [[destWindow cr_windowView] addSubview:avatarButtonView]; | 318 [[destWindow cr_windowView] addSubview:avatarButtonView]; |
| 320 } | 319 } |
| 321 | 320 |
| 322 // Add the tab strip after setting the content view and moving the incognito | 321 // Add the tab strip after setting the content view and moving the incognito |
| 323 // badge (if any), so that the tab strip will be on top (in the z-order). | 322 // badge (if any), so that the tab strip will be on top (in the z-order). |
| 324 if ([self hasTabStrip]) | 323 if ([self hasTabStrip]) |
| 325 [self insertTabStripView:tabStripView intoWindow:[self window]]; | 324 [self insertTabStripView:tabStripView intoWindow:destWindow]; |
| 326 | 325 |
| 327 [sourceWindow setWindowController:nil]; | 326 [sourceWindow setWindowController:nil]; |
| 328 [self setWindow:destWindow]; | 327 [self setWindow:destWindow]; |
| 329 [destWindow setWindowController:self]; | 328 [destWindow setWindowController:self]; |
| 330 | 329 |
| 331 // Move the status bubble over, if we have one. | 330 // Move the status bubble over, if we have one. |
| 332 if (statusBubble_) | 331 if (statusBubble_) |
| 333 statusBubble_->SwitchParentWindow(destWindow); | 332 statusBubble_->SwitchParentWindow(destWindow); |
| 334 | 333 |
| 335 // Move the title over. | 334 // Move the title over. |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 | 618 |
| 620 - (void)windowDidEnterFullScreen:(NSNotification*)notification { | 619 - (void)windowDidEnterFullScreen:(NSNotification*)notification { |
| 621 // In Yosemite, some combination of the titlebar and toolbar always show in | 620 // In Yosemite, some combination of the titlebar and toolbar always show in |
| 622 // full-screen mode. We do not want either to show. Search for the window that | 621 // full-screen mode. We do not want either to show. Search for the window that |
| 623 // contains the views, and hide it. There is no need to ever unhide the view. | 622 // contains the views, and hide it. There is no need to ever unhide the view. |
| 624 // http://crbug.com/380235 | 623 // http://crbug.com/380235 |
| 625 if (base::mac::IsOSYosemiteOrLater()) { | 624 if (base::mac::IsOSYosemiteOrLater()) { |
| 626 for (NSWindow* window in [[NSApplication sharedApplication] windows]) { | 625 for (NSWindow* window in [[NSApplication sharedApplication] windows]) { |
| 627 if ([window | 626 if ([window |
| 628 isKindOfClass:NSClassFromString(@"NSToolbarFullScreenWindow")]) { | 627 isKindOfClass:NSClassFromString(@"NSToolbarFullScreenWindow")]) { |
| 629 [window.contentView setHidden:YES]; | 628 [[window contentView] setHidden:YES]; |
| 630 } | 629 } |
| 631 } | 630 } |
| 632 } | 631 } |
| 633 | 632 |
| 634 if (notification) // For System Fullscreen when non-nil. | 633 if (notification) // For System Fullscreen when non-nil. |
| 635 [self deregisterForContentViewResizeNotifications]; | 634 [self deregisterForContentViewResizeNotifications]; |
| 636 enteringAppKitFullscreen_ = NO; | 635 enteringAppKitFullscreen_ = NO; |
| 637 enteringImmersiveFullscreen_ = NO; | 636 enteringImmersiveFullscreen_ = NO; |
| 638 enteringPresentationMode_ = NO; | 637 enteringPresentationMode_ = NO; |
| 639 | 638 |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 if ([infoBarContainerController_ view]) | 904 if ([infoBarContainerController_ view]) |
| 906 [subviews addObject:[infoBarContainerController_ view]]; | 905 [subviews addObject:[infoBarContainerController_ view]]; |
| 907 if ([findBarCocoaController_ view]) | 906 if ([findBarCocoaController_ view]) |
| 908 [subviews addObject:[findBarCocoaController_ view]]; | 907 [subviews addObject:[findBarCocoaController_ view]]; |
| 909 | 908 |
| 910 [self setContentViewSubviews:subviews]; | 909 [self setContentViewSubviews:subviews]; |
| 911 } | 910 } |
| 912 | 911 |
| 913 - (void)setContentViewSubviews:(NSArray*)subviews { | 912 - (void)setContentViewSubviews:(NSArray*)subviews { |
| 914 // Subviews already match. | 913 // Subviews already match. |
| 915 if ([[self.window.contentView subviews] isEqual:subviews]) | 914 if ([[self.chromeContentView subviews] isEqual:subviews]) |
| 916 return; | 915 return; |
| 917 | 916 |
| 918 // The tabContentArea isn't a subview, so just set all the subviews. | 917 // The tabContentArea isn't a subview, so just set all the subviews. |
| 919 NSView* tabContentArea = [self tabContentArea]; | 918 NSView* tabContentArea = [self tabContentArea]; |
| 920 if (![[self.window.contentView subviews] containsObject:tabContentArea]) { | 919 if (![[self.chromeContentView subviews] containsObject:tabContentArea]) { |
| 921 [self.window.contentView setSubviews:subviews]; | 920 [self.chromeContentView setSubviews:subviews]; |
| 922 return; | 921 return; |
| 923 } | 922 } |
| 924 | 923 |
| 925 // Remove all subviews that aren't the tabContentArea. | 924 // Remove all subviews that aren't the tabContentArea. |
| 926 for (NSView* view in [[self.window.contentView subviews] copy]) { | 925 for (NSView* view in [[self.chromeContentView subviews] copy]) { |
| 927 if (view != tabContentArea) | 926 if (view != tabContentArea) |
| 928 [view removeFromSuperview]; | 927 [view removeFromSuperview]; |
| 929 } | 928 } |
| 930 | 929 |
| 931 // Add in the subviews below the tabContentArea. | 930 // Add in the subviews below the tabContentArea. |
| 932 NSInteger index = [subviews indexOfObject:tabContentArea]; | 931 NSInteger index = [subviews indexOfObject:tabContentArea]; |
| 933 for (int i = index - 1; i >= 0; --i) { | 932 for (int i = index - 1; i >= 0; --i) { |
| 934 NSView* view = [subviews objectAtIndex:i]; | 933 NSView* view = [subviews objectAtIndex:i]; |
| 935 [self.window.contentView addSubview:view | 934 [self.chromeContentView addSubview:view |
| 936 positioned:NSWindowBelow | 935 positioned:NSWindowBelow |
| 937 relativeTo:nil]; | 936 relativeTo:nil]; |
| 938 } | 937 } |
| 939 | 938 |
| 940 // Add in the subviews above the tabContentArea. | 939 // Add in the subviews above the tabContentArea. |
| 941 for (NSUInteger i = index + 1; i < [subviews count]; ++i) { | 940 for (NSUInteger i = index + 1; i < [subviews count]; ++i) { |
| 942 NSView* view = [subviews objectAtIndex:i]; | 941 NSView* view = [subviews objectAtIndex:i]; |
| 943 [self.window.contentView addSubview:view | 942 [self.chromeContentView addSubview:view |
| 944 positioned:NSWindowAbove | 943 positioned:NSWindowAbove |
| 945 relativeTo:nil]; | 944 relativeTo:nil]; |
| 946 } | 945 } |
| 947 } | 946 } |
| 948 | 947 |
| 949 - (void)updateSubviewZOrderHack { | 948 - (void)updateSubviewZOrderHack { |
| 950 // TODO(erikchen): Remove and then add the tabStripView to the root NSView. | 949 // TODO(erikchen): Remove and then add the tabStripView to the root NSView. |
| 951 // This fixes a layer ordering problem that occurs between the contentView | 950 // This fixes a layer ordering problem that occurs between the contentView |
| 952 // and the tabStripView. This is a hack required because NSThemeFrame is not | 951 // and the tabStripView. This is a hack required because NSThemeFrame is not |
| 953 // layer backed, and because Chrome adds subviews directly to the | 952 // layer backed, and because Chrome adds subviews directly to the |
| 954 // NSThemeFrame. | 953 // NSThemeFrame. |
| 955 // http://crbug.com/407921 | 954 // http://crbug.com/407921 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 970 | 969 |
| 971 [CATransaction commit]; | 970 [CATransaction commit]; |
| 972 hasAdjustedTabStripWhileEnteringAppKitFullscreen_ = YES; | 971 hasAdjustedTabStripWhileEnteringAppKitFullscreen_ = YES; |
| 973 } | 972 } |
| 974 } else { | 973 } else { |
| 975 hasAdjustedTabStripWhileEnteringAppKitFullscreen_ = NO; | 974 hasAdjustedTabStripWhileEnteringAppKitFullscreen_ = NO; |
| 976 } | 975 } |
| 977 } | 976 } |
| 978 | 977 |
| 979 @end // @implementation BrowserWindowController(Private) | 978 @end // @implementation BrowserWindowController(Private) |
| OLD | NEW |