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 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1780 initWithWindow:[switchView_ window] delegate:self]); | 1781 initWithWindow:[switchView_ window] delegate:self]); |
1781 return sheetController_.get(); | 1782 return sheetController_.get(); |
1782 } | 1783 } |
1783 | 1784 |
1784 - (void)destroySheetController { | 1785 - (void)destroySheetController { |
1785 // Make sure there are no open sheets. | 1786 // Make sure there are no open sheets. |
1786 DCHECK_EQ(0U, [[sheetController_ viewsWithAttachedSheets] count]); | 1787 DCHECK_EQ(0U, [[sheetController_ viewsWithAttachedSheets] count]); |
1787 sheetController_.reset(); | 1788 sheetController_.reset(); |
1788 } | 1789 } |
1789 | 1790 |
| 1791 // TabContentsControllerDelegate protocol. |
| 1792 - (void)tabContentsViewFrameWillChange:(TabContentsController*)source |
| 1793 frameRect:(NSRect)frameRect { |
| 1794 id<TabContentsControllerDelegate> controller = |
| 1795 [[switchView_ window] windowController]; |
| 1796 [controller tabContentsViewFrameWillChange:source frameRect:frameRect]; |
| 1797 } |
| 1798 |
1790 - (TabContentsController*)activeTabContentsController { | 1799 - (TabContentsController*)activeTabContentsController { |
1791 int modelIndex = tabStripModel_->selected_index(); | 1800 int modelIndex = tabStripModel_->selected_index(); |
1792 if (modelIndex < 0) | 1801 if (modelIndex < 0) |
1793 return nil; | 1802 return nil; |
1794 NSInteger index = [self indexFromModelIndex:modelIndex]; | 1803 NSInteger index = [self indexFromModelIndex:modelIndex]; |
1795 if (index < 0 || | 1804 if (index < 0 || |
1796 index >= (NSInteger)[tabContentsArray_ count]) | 1805 index >= (NSInteger)[tabContentsArray_ count]) |
1797 return nil; | 1806 return nil; |
1798 return [tabContentsArray_ objectAtIndex:index]; | 1807 return [tabContentsArray_ objectAtIndex:index]; |
1799 } | 1808 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1849 NSInteger index = [self indexFromModelIndex:modelIndex]; | 1858 NSInteger index = [self indexFromModelIndex:modelIndex]; |
1850 BrowserWindowController* controller = | 1859 BrowserWindowController* controller = |
1851 (BrowserWindowController*)[[switchView_ window] windowController]; | 1860 (BrowserWindowController*)[[switchView_ window] windowController]; |
1852 DCHECK(index >= 0); | 1861 DCHECK(index >= 0); |
1853 if (index >= 0) { | 1862 if (index >= 0) { |
1854 [controller setTab:[self viewAtIndex:index] isDraggable:YES]; | 1863 [controller setTab:[self viewAtIndex:index] isDraggable:YES]; |
1855 } | 1864 } |
1856 } | 1865 } |
1857 | 1866 |
1858 @end | 1867 @end |
OLD | NEW |