| 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/tabs/tab_strip_controller.h" | 5 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
| 6 | 6 |
| 7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 DCHECK(modelIndex >= 0 && modelIndex < tabStripModel_->count()); | 573 DCHECK(modelIndex >= 0 && modelIndex < tabStripModel_->count()); |
| 574 NSInteger index = [self indexFromModelIndex:modelIndex]; | 574 NSInteger index = [self indexFromModelIndex:modelIndex]; |
| 575 TabContentsController* controller = [tabContentsArray_ objectAtIndex:index]; | 575 TabContentsController* controller = [tabContentsArray_ objectAtIndex:index]; |
| 576 | 576 |
| 577 // Make sure we do not draw any transient arrangements of views. | 577 // Make sure we do not draw any transient arrangements of views. |
| 578 gfx::ScopedCocoaDisableScreenUpdates cocoa_disabler; | 578 gfx::ScopedCocoaDisableScreenUpdates cocoa_disabler; |
| 579 // Make sure that any layers that move are not animated to their new | 579 // Make sure that any layers that move are not animated to their new |
| 580 // positions. | 580 // positions. |
| 581 ScopedCAActionDisabler ca_disabler; | 581 ScopedCAActionDisabler ca_disabler; |
| 582 | 582 |
| 583 // Resize the new view to fit the window. Calling |view| may lazily | 583 // Ensure the nib is loaded. Sizing won't occur until it's added to the view |
| 584 // instantiate the TabContentsController from the nib. Until we call | 584 // hierarchy with -ensureContentsVisibleInSuperview:. |
| 585 // |-ensureContentsVisible|, the controller doesn't install the RWHVMac into | 585 [controller view]; |
| 586 // the view hierarchy. This is in order to avoid sending the renderer a | |
| 587 // spurious default size loaded from the nib during the call to |-view|. | |
| 588 NSView* newView = [controller view]; | |
| 589 | 586 |
| 590 // Turns content autoresizing off, so removing and inserting views won't | 587 // Remove the old view from the view hierarchy to suppress resizes. We know |
| 591 // trigger unnecessary content relayout. | 588 // there's only one child of |switchView_| because we're the one who put it |
| 592 [controller ensureContentsSizeDoesNotChange]; | 589 // there. There may not be any children in the case of a tab that's been |
| 590 // closed, in which case there's nothing removed. |
| 591 [[[switchView_ subviews] firstObject] removeFromSuperview]; |
| 593 | 592 |
| 594 // Remove the old view from the view hierarchy. We know there's only one | 593 // Prepare the container with any infobars or docked devtools it wants. |
| 595 // child of |switchView_| because we're the one who put it there. There | |
| 596 // may not be any children in the case of a tab that's been closed, in | |
| 597 // which case there's no swapping going on. | |
| 598 NSArray* subviews = [switchView_ subviews]; | |
| 599 if ([subviews count]) { | |
| 600 NSView* oldView = [subviews objectAtIndex:0]; | |
| 601 // Set newView frame to the oldVew frame to prevent NSSplitView hosting | |
| 602 // sidebar and tab content from resizing sidebar's content view. | |
| 603 // ensureContentsVisible (see below) sets content size and autoresizing | |
| 604 // properties. | |
| 605 [newView setFrame:[oldView frame]]; | |
| 606 // Remove the old view first, to ensure ConstrainedWindowSheets keyed to the | |
| 607 // old WebContents are removed before adding new ones. | |
| 608 [oldView removeFromSuperview]; | |
| 609 [switchView_ addSubview:newView]; | |
| 610 } else { | |
| 611 [newView setFrame:[switchView_ bounds]]; | |
| 612 [switchView_ addSubview:newView]; | |
| 613 } | |
| 614 | |
| 615 // New content is in place, delegate should adjust itself accordingly. | |
| 616 [delegate_ onActivateTabWithContents:[controller webContents]]; | 594 [delegate_ onActivateTabWithContents:[controller webContents]]; |
| 617 | 595 |
| 618 // It also restores content autoresizing properties. | 596 // Sizes the WebContents to match the possibly updated size of |switchView_|, |
| 619 [controller ensureContentsVisible]; | 597 // then adds it and starts auto-resizing again. |
| 598 [controller ensureContentsVisibleInSuperview:switchView_]; |
| 620 } | 599 } |
| 621 | 600 |
| 622 // Create a new tab view and set its cell correctly so it draws the way we want | 601 // Create a new tab view and set its cell correctly so it draws the way we want |
| 623 // it to. It will be sized and positioned by |-layoutTabs| so there's no need to | 602 // it to. It will be sized and positioned by |-layoutTabs| so there's no need to |
| 624 // set the frame here. This also creates the view as hidden, it will be | 603 // set the frame here. This also creates the view as hidden, it will be |
| 625 // shown during layout. | 604 // shown during layout. |
| 626 - (TabController*)newTab { | 605 - (TabController*)newTab { |
| 627 TabController* controller = [[[TabController alloc] init] autorelease]; | 606 TabController* controller = [[[TabController alloc] init] autorelease]; |
| 628 [controller setTarget:self]; | 607 [controller setTarget:self]; |
| 629 [controller setAction:@selector(selectTab:)]; | 608 [controller setAction:@selector(selectTab:)]; |
| (...skipping 1698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2328 | 2307 |
| 2329 - (void)themeDidChangeNotification:(NSNotification*)notification { | 2308 - (void)themeDidChangeNotification:(NSNotification*)notification { |
| 2330 [newTabButton_ setImages]; | 2309 [newTabButton_ setImages]; |
| 2331 } | 2310 } |
| 2332 | 2311 |
| 2333 - (void)setVisualEffectsDisabledForFullscreen:(BOOL)fullscreen { | 2312 - (void)setVisualEffectsDisabledForFullscreen:(BOOL)fullscreen { |
| 2334 [tabStripView_ setVisualEffectsDisabledForFullscreen:fullscreen]; | 2313 [tabStripView_ setVisualEffectsDisabledForFullscreen:fullscreen]; |
| 2335 } | 2314 } |
| 2336 | 2315 |
| 2337 @end | 2316 @end |
| OLD | NEW |