| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/cocoa/tab_strip_controller.h" | 5 #import "chrome/browser/cocoa/tab_strip_controller.h" |
| 6 | 6 |
| 7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 [newView setFrame:[oldView frame]]; | 462 [newView setFrame:[oldView frame]]; |
| 463 [switchView_ replaceSubview:oldView with:newView]; | 463 [switchView_ replaceSubview:oldView with:newView]; |
| 464 } else { | 464 } else { |
| 465 [newView setFrame:[switchView_ bounds]]; | 465 [newView setFrame:[switchView_ bounds]]; |
| 466 [switchView_ addSubview:newView]; | 466 [switchView_ addSubview:newView]; |
| 467 } | 467 } |
| 468 | 468 |
| 469 // New content is in place, delegate should adjust itself accordingly. | 469 // New content is in place, delegate should adjust itself accordingly. |
| 470 [delegate_ onSelectTabWithContents:[controller tabContents]]; | 470 [delegate_ onSelectTabWithContents:[controller tabContents]]; |
| 471 | 471 |
| 472 // It also resores content autoresizing properties. | 472 // It also restores content autoresizing properties. |
| 473 [controller ensureContentsVisible]; | 473 [controller ensureContentsVisible]; |
| 474 | 474 |
| 475 // Make sure the new tabs's sheets are visible (necessary when a background | 475 // Make sure the new tabs's sheets are visible (necessary when a background |
| 476 // tab opened a sheet while it was in the background and now becomes active). | 476 // tab opened a sheet while it was in the background and now becomes active). |
| 477 TabContents* newTab = tabStripModel_->GetTabContentsAt(modelIndex); | 477 TabContents* newTab = tabStripModel_->GetTabContentsAt(modelIndex); |
| 478 DCHECK(newTab); | 478 DCHECK(newTab); |
| 479 if (newTab) { | 479 if (newTab) { |
| 480 TabContents::ConstrainedWindowList::iterator it, end; | 480 TabContents::ConstrainedWindowList::iterator it, end; |
| 481 end = newTab->constrained_window_end(); | 481 end = newTab->constrained_window_end(); |
| 482 NSWindowController* controller = [[newView window] windowController]; | 482 NSWindowController* controller = [[newView window] windowController]; |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 DCHECK(contents); | 966 DCHECK(contents); |
| 967 DCHECK(modelIndex == TabStripModel::kNoTab || | 967 DCHECK(modelIndex == TabStripModel::kNoTab || |
| 968 tabStripModel_->ContainsIndex(modelIndex)); | 968 tabStripModel_->ContainsIndex(modelIndex)); |
| 969 | 969 |
| 970 // Take closing tabs into account. | 970 // Take closing tabs into account. |
| 971 NSInteger index = [self indexFromModelIndex:modelIndex]; | 971 NSInteger index = [self indexFromModelIndex:modelIndex]; |
| 972 | 972 |
| 973 // Make a new tab. Load the contents of this tab from the nib and associate | 973 // Make a new tab. Load the contents of this tab from the nib and associate |
| 974 // the new controller with |contents| so it can be looked up later. | 974 // the new controller with |contents| so it can be looked up later. |
| 975 scoped_nsobject<TabContentsController> contentsController( | 975 scoped_nsobject<TabContentsController> contentsController( |
| 976 [[TabContentsController alloc] initWithContents:contents]); | 976 [[TabContentsController alloc] initWithContents:contents delegate:self]); |
| 977 [tabContentsArray_ insertObject:contentsController atIndex:index]; | 977 [tabContentsArray_ insertObject:contentsController atIndex:index]; |
| 978 | 978 |
| 979 // Make a new tab and add it to the strip. Keep track of its controller. | 979 // Make a new tab and add it to the strip. Keep track of its controller. |
| 980 TabController* newController = [self newTab]; | 980 TabController* newController = [self newTab]; |
| 981 [newController setMini:tabStripModel_->IsMiniTab(modelIndex)]; | 981 [newController setMini:tabStripModel_->IsMiniTab(modelIndex)]; |
| 982 [newController setPinned:tabStripModel_->IsTabPinned(modelIndex)]; | 982 [newController setPinned:tabStripModel_->IsTabPinned(modelIndex)]; |
| 983 [newController setApp:tabStripModel_->IsAppTab(modelIndex)]; | 983 [newController setApp:tabStripModel_->IsAppTab(modelIndex)]; |
| 984 [tabArray_ insertObject:newController atIndex:index]; | 984 [tabArray_ insertObject:newController atIndex:index]; |
| 985 NSView* newView = [newController view]; | 985 NSView* newView = [newController view]; |
| 986 | 986 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1073 atIndex:(NSInteger)modelIndex { | 1073 atIndex:(NSInteger)modelIndex { |
| 1074 NSInteger index = [self indexFromModelIndex:modelIndex]; | 1074 NSInteger index = [self indexFromModelIndex:modelIndex]; |
| 1075 TabContentsController* oldController = | 1075 TabContentsController* oldController = |
| 1076 [tabContentsArray_ objectAtIndex:index]; | 1076 [tabContentsArray_ objectAtIndex:index]; |
| 1077 DCHECK_EQ(oldContents, [oldController tabContents]); | 1077 DCHECK_EQ(oldContents, [oldController tabContents]); |
| 1078 | 1078 |
| 1079 // Simply create a new TabContentsController for |newContents| and place it | 1079 // Simply create a new TabContentsController for |newContents| and place it |
| 1080 // into the array, replacing |oldContents|. A TabSelectedAt notification will | 1080 // into the array, replacing |oldContents|. A TabSelectedAt notification will |
| 1081 // follow, at which point we will install the new view. | 1081 // follow, at which point we will install the new view. |
| 1082 scoped_nsobject<TabContentsController> newController( | 1082 scoped_nsobject<TabContentsController> newController( |
| 1083 [[TabContentsController alloc] initWithContents:newContents]); | 1083 [[TabContentsController alloc] initWithContents:newContents |
| 1084 delegate:self]); |
| 1084 | 1085 |
| 1085 // Bye bye, |oldController|. | 1086 // Bye bye, |oldController|. |
| 1086 [tabContentsArray_ replaceObjectAtIndex:index withObject:newController]; | 1087 [tabContentsArray_ replaceObjectAtIndex:index withObject:newController]; |
| 1087 | 1088 |
| 1088 [delegate_ onReplaceTabWithContents:newContents]; | 1089 [delegate_ onReplaceTabWithContents:newContents]; |
| 1089 } | 1090 } |
| 1090 | 1091 |
| 1091 // Remove all knowledge about this tab and its associated controller, and remove | 1092 // Remove all knowledge about this tab and its associated controller, and remove |
| 1092 // the view from the strip. | 1093 // the view from the strip. |
| 1093 - (void)removeTab:(TabController*)controller { | 1094 - (void)removeTab:(TabController*)controller { |
| (...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1775 initWithWindow:[switchView_ window] delegate:self]); | 1776 initWithWindow:[switchView_ window] delegate:self]); |
| 1776 return sheetController_.get(); | 1777 return sheetController_.get(); |
| 1777 } | 1778 } |
| 1778 | 1779 |
| 1779 - (void)destroySheetController { | 1780 - (void)destroySheetController { |
| 1780 // Make sure there are no open sheets. | 1781 // Make sure there are no open sheets. |
| 1781 DCHECK_EQ(0U, [[sheetController_ viewsWithAttachedSheets] count]); | 1782 DCHECK_EQ(0U, [[sheetController_ viewsWithAttachedSheets] count]); |
| 1782 sheetController_.reset(); | 1783 sheetController_.reset(); |
| 1783 } | 1784 } |
| 1784 | 1785 |
| 1786 // TabContentsViewControllerDelegate protocol. |
| 1787 - (void)tabContentsViewFrameWillChange:(TabContentsViewController*)source |
| 1788 frameRect:(NSRect)frameRect { |
| 1789 id<TabContentsViewControllerDelegate> controller = |
| 1790 [[switchView_ window] windowController]; |
| 1791 [controller tabContentsViewFrameWillChange:source frameRect:frameRect]; |
| 1792 } |
| 1793 |
| 1785 - (TabContentsController*)activeTabContentsController { | 1794 - (TabContentsController*)activeTabContentsController { |
| 1786 int modelIndex = tabStripModel_->selected_index(); | 1795 int modelIndex = tabStripModel_->selected_index(); |
| 1787 if (modelIndex < 0) | 1796 if (modelIndex < 0) |
| 1788 return nil; | 1797 return nil; |
| 1789 NSInteger index = [self indexFromModelIndex:modelIndex]; | 1798 NSInteger index = [self indexFromModelIndex:modelIndex]; |
| 1790 if (index < 0 || | 1799 if (index < 0 || |
| 1791 index >= (NSInteger)[tabContentsArray_ count]) | 1800 index >= (NSInteger)[tabContentsArray_ count]) |
| 1792 return nil; | 1801 return nil; |
| 1793 return [tabContentsArray_ objectAtIndex:index]; | 1802 return [tabContentsArray_ objectAtIndex:index]; |
| 1794 } | 1803 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1844 NSInteger index = [self indexFromModelIndex:modelIndex]; | 1853 NSInteger index = [self indexFromModelIndex:modelIndex]; |
| 1845 BrowserWindowController* controller = | 1854 BrowserWindowController* controller = |
| 1846 (BrowserWindowController*)[[switchView_ window] windowController]; | 1855 (BrowserWindowController*)[[switchView_ window] windowController]; |
| 1847 DCHECK(index >= 0); | 1856 DCHECK(index >= 0); |
| 1848 if (index >= 0) { | 1857 if (index >= 0) { |
| 1849 [controller setTab:[self viewAtIndex:index] isDraggable:YES]; | 1858 [controller setTab:[self viewAtIndex:index] isDraggable:YES]; |
| 1850 } | 1859 } |
| 1851 } | 1860 } |
| 1852 | 1861 |
| 1853 @end | 1862 @end |
| OLD | NEW |