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 |
321 // Move the tab strip background view. | |
322 [self insertTabStripBackgroundViewIntoWindow:destWindow]; | |
erikchen
2014/10/09 21:24:39
I assume this was an oversight in the CL that intr
Andre
2014/10/09 23:15:48
tabStripBackgroundView should not be moved here.
T
erikchen
2014/10/10 00:47:45
Done.
| |
323 | |
322 // Add the tab strip after setting the content view and moving the incognito | 324 // 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). | 325 // badge (if any), so that the tab strip will be on top (in the z-order). |
324 if ([self hasTabStrip]) | 326 if ([self hasTabStrip]) |
325 [self insertTabStripView:tabStripView intoWindow:[self window]]; | 327 [self insertTabStripView:tabStripView intoWindow:destWindow]; |
326 | 328 |
327 [sourceWindow setWindowController:nil]; | 329 [sourceWindow setWindowController:nil]; |
328 [self setWindow:destWindow]; | 330 [self setWindow:destWindow]; |
329 [destWindow setWindowController:self]; | 331 [destWindow setWindowController:self]; |
330 | 332 |
331 // Move the status bubble over, if we have one. | 333 // Move the status bubble over, if we have one. |
332 if (statusBubble_) | 334 if (statusBubble_) |
333 statusBubble_->SwitchParentWindow(destWindow); | 335 statusBubble_->SwitchParentWindow(destWindow); |
334 | 336 |
335 // Move the title over. | 337 // Move the title over. |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
619 | 621 |
620 - (void)windowDidEnterFullScreen:(NSNotification*)notification { | 622 - (void)windowDidEnterFullScreen:(NSNotification*)notification { |
621 // In Yosemite, some combination of the titlebar and toolbar always show in | 623 // 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 | 624 // 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. | 625 // contains the views, and hide it. There is no need to ever unhide the view. |
624 // http://crbug.com/380235 | 626 // http://crbug.com/380235 |
625 if (base::mac::IsOSYosemiteOrLater()) { | 627 if (base::mac::IsOSYosemiteOrLater()) { |
626 for (NSWindow* window in [[NSApplication sharedApplication] windows]) { | 628 for (NSWindow* window in [[NSApplication sharedApplication] windows]) { |
627 if ([window | 629 if ([window |
628 isKindOfClass:NSClassFromString(@"NSToolbarFullScreenWindow")]) { | 630 isKindOfClass:NSClassFromString(@"NSToolbarFullScreenWindow")]) { |
629 [window.contentView setHidden:YES]; | 631 [[window contentView] setHidden:YES]; |
630 } | 632 } |
631 } | 633 } |
632 } | 634 } |
633 | 635 |
634 if (notification) // For System Fullscreen when non-nil. | 636 if (notification) // For System Fullscreen when non-nil. |
635 [self deregisterForContentViewResizeNotifications]; | 637 [self deregisterForContentViewResizeNotifications]; |
636 enteringAppKitFullscreen_ = NO; | 638 enteringAppKitFullscreen_ = NO; |
637 enteringImmersiveFullscreen_ = NO; | 639 enteringImmersiveFullscreen_ = NO; |
638 enteringPresentationMode_ = NO; | 640 enteringPresentationMode_ = NO; |
639 | 641 |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
905 if ([infoBarContainerController_ view]) | 907 if ([infoBarContainerController_ view]) |
906 [subviews addObject:[infoBarContainerController_ view]]; | 908 [subviews addObject:[infoBarContainerController_ view]]; |
907 if ([findBarCocoaController_ view]) | 909 if ([findBarCocoaController_ view]) |
908 [subviews addObject:[findBarCocoaController_ view]]; | 910 [subviews addObject:[findBarCocoaController_ view]]; |
909 | 911 |
910 [self setContentViewSubviews:subviews]; | 912 [self setContentViewSubviews:subviews]; |
911 } | 913 } |
912 | 914 |
913 - (void)setContentViewSubviews:(NSArray*)subviews { | 915 - (void)setContentViewSubviews:(NSArray*)subviews { |
914 // Subviews already match. | 916 // Subviews already match. |
915 if ([[self.window.contentView subviews] isEqual:subviews]) | 917 if ([[self.chromeContentView subviews] isEqual:subviews]) |
916 return; | 918 return; |
917 | 919 |
918 // The tabContentArea isn't a subview, so just set all the subviews. | 920 // The tabContentArea isn't a subview, so just set all the subviews. |
919 NSView* tabContentArea = [self tabContentArea]; | 921 NSView* tabContentArea = [self tabContentArea]; |
920 if (![[self.window.contentView subviews] containsObject:tabContentArea]) { | 922 if (![[self.chromeContentView subviews] containsObject:tabContentArea]) { |
921 [self.window.contentView setSubviews:subviews]; | 923 [self.chromeContentView setSubviews:subviews]; |
922 return; | 924 return; |
923 } | 925 } |
924 | 926 |
925 // Remove all subviews that aren't the tabContentArea. | 927 // Remove all subviews that aren't the tabContentArea. |
926 for (NSView* view in [[self.window.contentView subviews] copy]) { | 928 for (NSView* view in [[self.chromeContentView subviews] copy]) { |
927 if (view != tabContentArea) | 929 if (view != tabContentArea) |
928 [view removeFromSuperview]; | 930 [view removeFromSuperview]; |
929 } | 931 } |
930 | 932 |
931 // Add in the subviews below the tabContentArea. | 933 // Add in the subviews below the tabContentArea. |
932 NSInteger index = [subviews indexOfObject:tabContentArea]; | 934 NSInteger index = [subviews indexOfObject:tabContentArea]; |
933 for (int i = index - 1; i >= 0; --i) { | 935 for (int i = index - 1; i >= 0; --i) { |
934 NSView* view = [subviews objectAtIndex:i]; | 936 NSView* view = [subviews objectAtIndex:i]; |
935 [self.window.contentView addSubview:view | 937 [self.chromeContentView addSubview:view |
936 positioned:NSWindowBelow | 938 positioned:NSWindowBelow |
937 relativeTo:nil]; | 939 relativeTo:nil]; |
938 } | 940 } |
939 | 941 |
940 // Add in the subviews above the tabContentArea. | 942 // Add in the subviews above the tabContentArea. |
941 for (NSUInteger i = index + 1; i < [subviews count]; ++i) { | 943 for (NSUInteger i = index + 1; i < [subviews count]; ++i) { |
942 NSView* view = [subviews objectAtIndex:i]; | 944 NSView* view = [subviews objectAtIndex:i]; |
943 [self.window.contentView addSubview:view | 945 [self.chromeContentView addSubview:view |
944 positioned:NSWindowAbove | 946 positioned:NSWindowAbove |
945 relativeTo:nil]; | 947 relativeTo:nil]; |
946 } | 948 } |
947 } | 949 } |
948 | 950 |
949 - (void)updateSubviewZOrderHack { | 951 - (void)updateSubviewZOrderHack { |
950 // TODO(erikchen): Remove and then add the tabStripView to the root NSView. | 952 // TODO(erikchen): Remove and then add the tabStripView to the root NSView. |
951 // This fixes a layer ordering problem that occurs between the contentView | 953 // This fixes a layer ordering problem that occurs between the contentView |
952 // and the tabStripView. This is a hack required because NSThemeFrame is not | 954 // and the tabStripView. This is a hack required because NSThemeFrame is not |
953 // layer backed, and because Chrome adds subviews directly to the | 955 // layer backed, and because Chrome adds subviews directly to the |
954 // NSThemeFrame. | 956 // NSThemeFrame. |
955 // http://crbug.com/407921 | 957 // http://crbug.com/407921 |
(...skipping 14 matching lines...) Expand all Loading... | |
970 | 972 |
971 [CATransaction commit]; | 973 [CATransaction commit]; |
972 hasAdjustedTabStripWhileEnteringAppKitFullscreen_ = YES; | 974 hasAdjustedTabStripWhileEnteringAppKitFullscreen_ = YES; |
973 } | 975 } |
974 } else { | 976 } else { |
975 hasAdjustedTabStripWhileEnteringAppKitFullscreen_ = NO; | 977 hasAdjustedTabStripWhileEnteringAppKitFullscreen_ = NO; |
976 } | 978 } |
977 } | 979 } |
978 | 980 |
979 @end // @implementation BrowserWindowController(Private) | 981 @end // @implementation BrowserWindowController(Private) |
OLD | NEW |