| 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 17 matching lines...) Expand all Loading... |
| 28 #include "chrome/browser/tabs/tab_strip_model.h" | 28 #include "chrome/browser/tabs/tab_strip_model.h" |
| 29 #include "chrome/browser/tabs/tab_strip_selection_model.h" | 29 #include "chrome/browser/tabs/tab_strip_selection_model.h" |
| 30 #include "chrome/browser/ui/browser.h" | 30 #include "chrome/browser/ui/browser.h" |
| 31 #include "chrome/browser/ui/browser_navigator.h" | 31 #include "chrome/browser/ui/browser_navigator.h" |
| 32 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 32 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 33 #import "chrome/browser/ui/cocoa/constrained_window_mac.h" | 33 #import "chrome/browser/ui/cocoa/constrained_window_mac.h" |
| 34 #include "chrome/browser/ui/cocoa/drag_util.h" | 34 #include "chrome/browser/ui/cocoa/drag_util.h" |
| 35 #import "chrome/browser/ui/cocoa/image_button_cell.h" | 35 #import "chrome/browser/ui/cocoa/image_button_cell.h" |
| 36 #import "chrome/browser/ui/cocoa/new_tab_button.h" | 36 #import "chrome/browser/ui/cocoa/new_tab_button.h" |
| 37 #import "chrome/browser/ui/cocoa/tab_contents/favicon_util.h" | 37 #import "chrome/browser/ui/cocoa/tab_contents/favicon_util.h" |
| 38 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" |
| 38 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" | 39 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" |
| 39 #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h" | 40 #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h" |
| 40 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" | 41 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" |
| 41 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" | 42 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" |
| 42 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" | 43 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" |
| 43 #import "chrome/browser/ui/cocoa/tabs/throbber_view.h" | 44 #import "chrome/browser/ui/cocoa/tabs/throbber_view.h" |
| 44 #import "chrome/browser/ui/cocoa/tracking_area.h" | 45 #import "chrome/browser/ui/cocoa/tracking_area.h" |
| 45 #include "chrome/browser/ui/constrained_window_tab_helper.h" | 46 #include "chrome/browser/ui/constrained_window_tab_helper.h" |
| 46 #include "chrome/browser/ui/find_bar/find_bar.h" | 47 #include "chrome/browser/ui/find_bar/find_bar.h" |
| 47 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 48 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
| (...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1152 | 1153 |
| 1153 // Cancel any pending tab transition. | 1154 // Cancel any pending tab transition. |
| 1154 hoverTabSelector_->CancelTabTransition(); | 1155 hoverTabSelector_->CancelTabTransition(); |
| 1155 | 1156 |
| 1156 // Take closing tabs into account. | 1157 // Take closing tabs into account. |
| 1157 NSInteger index = [self indexFromModelIndex:modelIndex]; | 1158 NSInteger index = [self indexFromModelIndex:modelIndex]; |
| 1158 | 1159 |
| 1159 // Make a new tab. Load the contents of this tab from the nib and associate | 1160 // Make a new tab. Load the contents of this tab from the nib and associate |
| 1160 // the new controller with |contents| so it can be looked up later. | 1161 // the new controller with |contents| so it can be looked up later. |
| 1161 scoped_nsobject<TabContentsController> contentsController( | 1162 scoped_nsobject<TabContentsController> contentsController( |
| 1162 [[TabContentsController alloc] initWithContents:contents->web_contents() | 1163 [[TabContentsController alloc] |
| 1163 delegate:self]); | 1164 initWithContents:contents->web_contents()]); |
| 1164 [tabContentsArray_ insertObject:contentsController atIndex:index]; | 1165 [tabContentsArray_ insertObject:contentsController atIndex:index]; |
| 1165 | 1166 |
| 1166 // Make a new tab and add it to the strip. Keep track of its controller. | 1167 // Make a new tab and add it to the strip. Keep track of its controller. |
| 1167 TabController* newController = [self newTab]; | 1168 TabController* newController = [self newTab]; |
| 1168 [newController setMini:tabStripModel_->IsMiniTab(modelIndex)]; | 1169 [newController setMini:tabStripModel_->IsMiniTab(modelIndex)]; |
| 1169 [newController setPinned:tabStripModel_->IsTabPinned(modelIndex)]; | 1170 [newController setPinned:tabStripModel_->IsTabPinned(modelIndex)]; |
| 1170 [newController setApp:tabStripModel_->IsAppTab(modelIndex)]; | 1171 [newController setApp:tabStripModel_->IsAppTab(modelIndex)]; |
| 1171 [newController setUrl:contents->web_contents()->GetURL()]; | 1172 [newController setUrl:contents->web_contents()->GetURL()]; |
| 1172 [tabArray_ insertObject:newController atIndex:index]; | 1173 [tabArray_ insertObject:newController atIndex:index]; |
| 1173 NSView* newView = [newController view]; | 1174 NSView* newView = [newController view]; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1271 NSInteger index = [self indexFromModelIndex:modelIndex]; | 1272 NSInteger index = [self indexFromModelIndex:modelIndex]; |
| 1272 TabContentsController* oldController = | 1273 TabContentsController* oldController = |
| 1273 [tabContentsArray_ objectAtIndex:index]; | 1274 [tabContentsArray_ objectAtIndex:index]; |
| 1274 DCHECK_EQ(oldContents->web_contents(), [oldController webContents]); | 1275 DCHECK_EQ(oldContents->web_contents(), [oldController webContents]); |
| 1275 | 1276 |
| 1276 // Simply create a new TabContentsController for |newContents| and place it | 1277 // Simply create a new TabContentsController for |newContents| and place it |
| 1277 // into the array, replacing |oldContents|. A ActiveTabChanged notification | 1278 // into the array, replacing |oldContents|. A ActiveTabChanged notification |
| 1278 // will follow, at which point we will install the new view. | 1279 // will follow, at which point we will install the new view. |
| 1279 scoped_nsobject<TabContentsController> newController( | 1280 scoped_nsobject<TabContentsController> newController( |
| 1280 [[TabContentsController alloc] | 1281 [[TabContentsController alloc] |
| 1281 initWithContents:newContents->web_contents() | 1282 initWithContents:newContents->web_contents()]); |
| 1282 delegate:self]); | |
| 1283 | 1283 |
| 1284 // Bye bye, |oldController|. | 1284 // Bye bye, |oldController|. |
| 1285 [tabContentsArray_ replaceObjectAtIndex:index withObject:newController]; | 1285 [tabContentsArray_ replaceObjectAtIndex:index withObject:newController]; |
| 1286 | 1286 |
| 1287 [delegate_ onReplaceTabWithContents:newContents->web_contents()]; | 1287 [delegate_ onReplaceTabWithContents:newContents->web_contents()]; |
| 1288 | 1288 |
| 1289 // Fake a tab changed notification to force tab titles and favicons to update. | 1289 // Fake a tab changed notification to force tab titles and favicons to update. |
| 1290 [self tabChangedWithContents:newContents | 1290 [self tabChangedWithContents:newContents |
| 1291 atIndex:modelIndex | 1291 atIndex:modelIndex |
| 1292 changeType:TabStripModelObserver::ALL]; | 1292 changeType:TabStripModelObserver::ALL]; |
| (...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2041 initWithWindow:[switchView_ window] delegate:self]); | 2041 initWithWindow:[switchView_ window] delegate:self]); |
| 2042 return sheetController_.get(); | 2042 return sheetController_.get(); |
| 2043 } | 2043 } |
| 2044 | 2044 |
| 2045 - (void)destroySheetController { | 2045 - (void)destroySheetController { |
| 2046 // Make sure there are no open sheets. | 2046 // Make sure there are no open sheets. |
| 2047 DCHECK_EQ(0U, [[sheetController_ viewsWithAttachedSheets] count]); | 2047 DCHECK_EQ(0U, [[sheetController_ viewsWithAttachedSheets] count]); |
| 2048 sheetController_.reset(); | 2048 sheetController_.reset(); |
| 2049 } | 2049 } |
| 2050 | 2050 |
| 2051 // TabContentsControllerDelegate protocol. | |
| 2052 - (void)tabContentsViewFrameWillChange:(TabContentsController*)source | |
| 2053 frameRect:(NSRect)frameRect { | |
| 2054 id<TabContentsControllerDelegate> controller = | |
| 2055 [[switchView_ window] windowController]; | |
| 2056 [controller tabContentsViewFrameWillChange:source frameRect:frameRect]; | |
| 2057 } | |
| 2058 | |
| 2059 - (TabContentsController*)activeTabContentsController { | 2051 - (TabContentsController*)activeTabContentsController { |
| 2060 int modelIndex = tabStripModel_->active_index(); | 2052 int modelIndex = tabStripModel_->active_index(); |
| 2061 if (modelIndex < 0) | 2053 if (modelIndex < 0) |
| 2062 return nil; | 2054 return nil; |
| 2063 NSInteger index = [self indexFromModelIndex:modelIndex]; | 2055 NSInteger index = [self indexFromModelIndex:modelIndex]; |
| 2064 if (index < 0 || | 2056 if (index < 0 || |
| 2065 index >= (NSInteger)[tabContentsArray_ count]) | 2057 index >= (NSInteger)[tabContentsArray_ count]) |
| 2066 return nil; | 2058 return nil; |
| 2067 return [tabContentsArray_ objectAtIndex:index]; | 2059 return [tabContentsArray_ objectAtIndex:index]; |
| 2068 } | 2060 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2125 NSInteger index = [self indexFromModelIndex:modelIndex]; | 2117 NSInteger index = [self indexFromModelIndex:modelIndex]; |
| 2126 BrowserWindowController* controller = | 2118 BrowserWindowController* controller = |
| 2127 (BrowserWindowController*)[[switchView_ window] windowController]; | 2119 (BrowserWindowController*)[[switchView_ window] windowController]; |
| 2128 DCHECK(index >= 0); | 2120 DCHECK(index >= 0); |
| 2129 if (index >= 0) { | 2121 if (index >= 0) { |
| 2130 [controller setTab:[self viewAtIndex:index] isDraggable:YES]; | 2122 [controller setTab:[self viewAtIndex:index] isDraggable:YES]; |
| 2131 } | 2123 } |
| 2132 } | 2124 } |
| 2133 | 2125 |
| 2134 @end | 2126 @end |
| OLD | NEW |