| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/sys_string_conversions.h" | 7 #import "base/sys_string_conversions.h" |
| 8 #import "chrome/app/chrome_dll_resource.h" | 8 #import "chrome/app/chrome_dll_resource.h" |
| 9 #import "chrome/browser/cocoa/tab_strip_view.h" | 9 #import "chrome/browser/cocoa/tab_strip_view.h" |
| 10 #import "chrome/browser/cocoa/tab_cell.h" | 10 #import "chrome/browser/cocoa/tab_cell.h" |
| 11 #import "chrome/browser/cocoa/tab_contents_controller.h" | 11 #import "chrome/browser/cocoa/tab_contents_controller.h" |
| 12 #import "chrome/browser/cocoa/tab_controller.h" |
| 13 #import "chrome/browser/cocoa/tab_view.h" |
| 12 #import "chrome/browser/tab_contents/tab_contents.h" | 14 #import "chrome/browser/tab_contents/tab_contents.h" |
| 13 #import "chrome/browser/tabs/tab_strip_model.h" | 15 #import "chrome/browser/tabs/tab_strip_model.h" |
| 14 | 16 |
| 15 // The amount of overlap tabs have in their button frames. | 17 // The amount of overlap tabs have in their button frames. |
| 16 const short kTabOverlap = 16; | 18 const short kTabOverlap = 16; |
| 17 | 19 |
| 18 // The private methods the brige object needs from the controller. | 20 // The private methods the brige object needs from the controller. |
| 19 @interface TabStripController(BridgeMethods) | 21 @interface TabStripController(BridgeMethods) |
| 20 - (void)insertTabWithContents:(TabContents*)contents | 22 - (void)insertTabWithContents:(TabContents*)contents |
| 21 atIndex:(NSInteger)index | 23 atIndex:(NSInteger)index |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 tabModel:(TabStripModel*)tabModel | 66 tabModel:(TabStripModel*)tabModel |
| 65 toolbarModel:(ToolbarModel*)toolbarModel | 67 toolbarModel:(ToolbarModel*)toolbarModel |
| 66 commands:(CommandUpdater*)commands { | 68 commands:(CommandUpdater*)commands { |
| 67 DCHECK(view && tabModel && toolbarModel); | 69 DCHECK(view && tabModel && toolbarModel); |
| 68 if ((self = [super init])) { | 70 if ((self = [super init])) { |
| 69 tabView_ = view; | 71 tabView_ = view; |
| 70 tabModel_ = tabModel; | 72 tabModel_ = tabModel; |
| 71 toolbarModel_ = toolbarModel; | 73 toolbarModel_ = toolbarModel; |
| 72 commands_ = commands; | 74 commands_ = commands; |
| 73 bridge_ = new TabStripBridge(tabModel, self); | 75 bridge_ = new TabStripBridge(tabModel, self); |
| 74 tabControllerArray_ = [[NSMutableArray alloc] init]; | 76 tabContentsArray_ = [[NSMutableArray alloc] init]; |
| 77 tabArray_ = [[NSMutableArray alloc] init]; |
| 75 | 78 |
| 76 // Create the new tab button separate from the nib so we can make sure | 79 // Create the new tab button separate from the nib so we can make sure |
| 77 // it's always at the end of the subview list. | 80 // it's always at the end of the subview list. |
| 78 NSImage* image = [NSImage imageNamed:@"newtab"]; | 81 NSImage* image = [NSImage imageNamed:@"newtab"]; |
| 79 NSRect frame = NSMakeRect(0, 0, [image size].width, [image size].height); | 82 NSRect frame = NSMakeRect(0, 0, [image size].width, [image size].height); |
| 80 newTabButton_ = [[NSButton alloc] initWithFrame:frame]; | 83 newTabButton_ = [[NSButton alloc] initWithFrame:frame]; |
| 81 [newTabButton_ setImage:image]; | 84 [newTabButton_ setImage:image]; |
| 82 [newTabButton_ setImagePosition:NSImageOnly]; | 85 [newTabButton_ setImagePosition:NSImageOnly]; |
| 83 [newTabButton_ setTarget:nil]; | 86 [newTabButton_ setTarget:nil]; |
| 84 [newTabButton_ setAction:@selector(commandDispatch:)]; | 87 [newTabButton_ setAction:@selector(commandDispatch:)]; |
| 85 [newTabButton_ setTag:IDC_NEW_TAB]; | 88 [newTabButton_ setTag:IDC_NEW_TAB]; |
| 86 [newTabButton_ setButtonType:NSMomentaryPushInButton]; | 89 [newTabButton_ setButtonType:NSMomentaryPushInButton]; |
| 87 [newTabButton_ setBordered:NO]; | 90 [newTabButton_ setBordered:NO]; |
| 88 } | 91 } |
| 89 return self; | 92 return self; |
| 90 } | 93 } |
| 91 | 94 |
| 92 - (void)dealloc { | 95 - (void)dealloc { |
| 93 delete bridge_; | 96 delete bridge_; |
| 94 [tabControllerArray_ release]; | 97 [tabContentsArray_ release]; |
| 98 [tabArray_ release]; |
| 95 [newTabButton_ release]; | 99 [newTabButton_ release]; |
| 96 [super dealloc]; | 100 [super dealloc]; |
| 97 } | 101 } |
| 98 | 102 |
| 99 // Finds the associated TabContentsController at the given |index| and swaps | 103 // Finds the associated TabContentsController at the given |index| and swaps |
| 100 // out the sole child of the contentArea to display its contents. | 104 // out the sole child of the contentArea to display its contents. |
| 101 - (void)swapInTabAtIndex:(NSInteger)index { | 105 - (void)swapInTabAtIndex:(NSInteger)index { |
| 102 TabContentsController* controller = [tabControllerArray_ objectAtIndex:index]; | 106 TabContentsController* controller = [tabContentsArray_ objectAtIndex:index]; |
| 103 | 107 |
| 104 // Resize the new view to fit the window | 108 // Resize the new view to fit the window |
| 105 NSView* contentView = [[tabView_ window] contentView]; | 109 NSView* contentView = [[tabView_ window] contentView]; |
| 106 NSView* newView = [controller view]; | 110 NSView* newView = [controller view]; |
| 107 NSRect frame = [contentView bounds]; | 111 NSRect frame = [contentView bounds]; |
| 108 frame.size.height -= 14.0; | 112 frame.size.height -= 14.0; |
| 109 [newView setFrame:frame]; | 113 [newView setFrame:frame]; |
| 110 | 114 |
| 111 // Remove the old view from the view hierarchy. We know there's only one | 115 // Remove the old view from the view hierarchy. We know there's only one |
| 112 // child of the contentView because we're the one who put it there. There | 116 // child of the contentView because we're the one who put it there. There |
| 113 // may not be any children in the case of a tab that's been closed, in | 117 // may not be any children in the case of a tab that's been closed, in |
| 114 // which case there's no swapping going on. | 118 // which case there's no swapping going on. |
| 115 NSArray* subviews = [contentView subviews]; | 119 NSArray* subviews = [contentView subviews]; |
| 116 if ([subviews count]) { | 120 if ([subviews count]) { |
| 117 NSView* oldView = [subviews objectAtIndex:0]; | 121 NSView* oldView = [subviews objectAtIndex:0]; |
| 118 [contentView replaceSubview:oldView with:newView]; | 122 [contentView replaceSubview:oldView with:newView]; |
| 119 } else { | 123 } else { |
| 120 [contentView addSubview:newView]; | 124 [contentView addSubview:newView]; |
| 121 } | 125 } |
| 122 } | 126 } |
| 123 | 127 |
| 124 // Create a new tab view and set its cell correctly so it draws the way we | 128 // Create a new tab view and set its cell correctly so it draws the way we |
| 125 // want it to. | 129 // want it to. |
| 126 - (NSButton*)newTabWithFrame:(NSRect)frame { | 130 - (TabController*)newTabWithFrame:(NSRect)frame { |
| 127 NSButton* button = [[[NSButton alloc] initWithFrame:frame] autorelease]; | 131 TabController* controller = [[[TabController alloc] init] autorelease]; |
| 128 TabCell* cell = [[[TabCell alloc] init] autorelease]; | 132 [controller setTarget:self]; |
| 129 [button setCell:cell]; | 133 [controller setAction:@selector(selectTab:)]; |
| 130 [button setButtonType:NSMomentaryPushInButton]; | 134 TabView* view = [controller tabView]; |
| 131 [button setTitle:@"New Tab"]; | 135 [view setFrame:frame]; |
| 132 [button setBezelStyle:NSRegularSquareBezelStyle]; | |
| 133 [button setTarget:self]; | |
| 134 [button setAction:@selector(selectTab:)]; | |
| 135 | 136 |
| 136 return button; | 137 return controller; |
| 137 } | 138 } |
| 138 | 139 |
| 139 // Returns the number of tab buttons in the tab strip by counting the children. | 140 // Returns the number of tabs in the tab strip. This is just the number |
| 140 // Recall the last view is the "new tab" button, so the number of tabs is one | 141 // of TabControllers we know about as there's a 1-to-1 mapping from these |
| 141 // less than the count. | 142 // controllers to a tab. |
| 142 - (NSInteger)numberOfTabViews { | 143 - (NSInteger)numberOfTabViews { |
| 143 return [[tabView_ subviews] count] - 1; | 144 return [tabArray_ count]; |
| 144 } | 145 } |
| 145 | 146 |
| 146 // Returns the index of the subview |view|. Returns -1 if not present. | 147 // Returns the index of the subview |view|. Returns -1 if not present. |
| 147 - (NSInteger)indexForTabView:(NSView*)view { | 148 - (NSInteger)indexForTabView:(NSView*)view { |
| 148 NSInteger index = -1; | 149 NSInteger index = -1; |
| 149 const int numSubviews = [self numberOfTabViews]; | 150 const int numSubviews = [self numberOfTabViews]; |
| 150 for (int i = 0; i < numSubviews; i++) { | 151 for (int i = 0; i < numSubviews; i++) { |
| 151 if ([[tabView_ subviews] objectAtIndex:i] == view) | 152 if ([[tabView_ subviews] objectAtIndex:i] == view) |
| 152 index = i; | 153 index = i; |
| 153 } | 154 } |
| 154 return index; | 155 return index; |
| 155 } | 156 } |
| 156 | 157 |
| 157 // Called when the user clicks a tab. Tell the model the selection has changed, | 158 // Called when the user clicks a tab. Tell the model the selection has changed, |
| 158 // which feeds back into us via a notification. | 159 // which feeds back into us via a notification. |
| 159 - (void)selectTab:(id)sender { | 160 - (void)selectTab:(id)sender { |
| 160 int index = [self indexForTabView:sender]; // for testing... | 161 int index = [self indexForTabView:sender]; // for testing... |
| 161 if (index >= 0 && tabModel_->ContainsIndex(index)) | 162 if (index >= 0 && tabModel_->ContainsIndex(index)) |
| 162 tabModel_->SelectTabContentsAt(index, true); | 163 tabModel_->SelectTabContentsAt(index, true); |
| 163 } | 164 } |
| 164 | 165 |
| 165 // Return the frame for a new tab that will go to the immediate right of the | 166 // Return the frame for a new tab that will go to the immediate right of the |
| 166 // tab at |index|. If |index| is 0, this will be the first tab, indented so | 167 // tab at |index|. If |index| is 0, this will be the first tab, indented so |
| 167 // as to not cover the window controls. | 168 // as to not cover the window controls. |
| 168 - (NSRect)frameForNewTabAtIndex:(NSInteger)index { | 169 - (NSRect)frameForNewTabAtIndex:(NSInteger)index { |
| 169 const short kIndentLeavingSpaceForControls = 66; | 170 const short kIndentLeavingSpaceForControls = 66; |
| 170 const short kNewTabWidth = 160; | 171 const short kNewTabWidth = [TabController maxTabWidth]; |
| 171 | 172 |
| 172 short xOffset = kIndentLeavingSpaceForControls; | 173 short xOffset = kIndentLeavingSpaceForControls; |
| 173 if (index > 0) { | 174 if (index > 0) { |
| 174 NSRect previousTab = [[[tabView_ subviews] objectAtIndex:index - 1] frame]; | 175 NSRect previousTab = [[[tabView_ subviews] objectAtIndex:index - 1] frame]; |
| 175 xOffset = NSMaxX(previousTab) - kTabOverlap; | 176 xOffset = NSMaxX(previousTab) - kTabOverlap; |
| 176 } | 177 } |
| 177 | 178 |
| 178 return NSMakeRect(xOffset, 0, kNewTabWidth, [tabView_ frame].size.height); | 179 return NSMakeRect(xOffset, 0, kNewTabWidth, [tabView_ frame].size.height); |
| 179 } | 180 } |
| 180 | 181 |
| 181 // Handles setting the title of the tab based on the given |contents|. Uses | 182 // Handles setting the title of the tab based on the given |contents|. Uses |
| 182 // a canned string if |contents| is NULL. | 183 // a canned string if |contents| is NULL. |
| 183 - (void)setTabTitle:(NSButton*)tab withContents:(TabContents*)contents { | 184 - (void)setTabTitle:(NSViewController*)tab withContents:(TabContents*)contents { |
| 184 NSString* titleString = nil; | 185 NSString* titleString = nil; |
| 185 if (contents) | 186 if (contents) |
| 186 titleString = base::SysUTF16ToNSString(contents->GetTitle()); | 187 titleString = base::SysUTF16ToNSString(contents->GetTitle()); |
| 187 if (![titleString length]) | 188 if (![titleString length]) |
| 188 titleString = NSLocalizedString(@"untitled", nil); | 189 titleString = NSLocalizedString(@"untitled", nil); |
| 189 [tab setTitle:titleString]; | 190 [tab setTitle:titleString]; |
| 190 } | 191 } |
| 191 | 192 |
| 192 // Called when a notification is received from the model to insert a new tab | 193 // Called when a notification is received from the model to insert a new tab |
| 193 // at |index|. | 194 // at |index|. |
| 194 - (void)insertTabWithContents:(TabContents*)contents | 195 - (void)insertTabWithContents:(TabContents*)contents |
| 195 atIndex:(NSInteger)index | 196 atIndex:(NSInteger)index |
| 196 inForeground:(bool)inForeground { | 197 inForeground:(bool)inForeground { |
| 197 DCHECK(contents); | 198 DCHECK(contents); |
| 198 DCHECK(index == TabStripModel::kNoTab || tabModel_->ContainsIndex(index)); | 199 DCHECK(index == TabStripModel::kNoTab || tabModel_->ContainsIndex(index)); |
| 199 | 200 |
| 200 // TODO(pinkerton): handle tab dragging in here | 201 // TODO(pinkerton): handle tab dragging in here |
| 201 | 202 |
| 202 // Make a new tab. Load the contents of this tab from the nib and associate | 203 // Make a new tab. Load the contents of this tab from the nib and associate |
| 203 // the new controller with |contents| so it can be looked up later. | 204 // the new controller with |contents| so it can be looked up later. |
| 204 TabContentsController* contentsController = | 205 TabContentsController* contentsController = |
| 205 [[[TabContentsController alloc] initWithNibName:@"TabContents" | 206 [[[TabContentsController alloc] initWithNibName:@"TabContents" |
| 206 bundle:nil | 207 bundle:nil |
| 207 contents:contents | 208 contents:contents |
| 208 commands:commands_ | 209 commands:commands_ |
| 209 toolbarModel:toolbarModel_] | 210 toolbarModel:toolbarModel_] |
| 210 autorelease]; | 211 autorelease]; |
| 211 [tabControllerArray_ insertObject:contentsController atIndex:index]; | 212 [tabContentsArray_ insertObject:contentsController atIndex:index]; |
| 212 | 213 |
| 213 // Remove the new tab button so the only views present are the tabs, | 214 // Remove the new tab button so the only views present are the tabs, |
| 214 // we'll add it back when we're done | 215 // we'll add it back when we're done |
| 215 [newTabButton_ removeFromSuperview]; | 216 [newTabButton_ removeFromSuperview]; |
| 216 | 217 |
| 217 // Make a new tab view and add it to the strip. | 218 // Make a new tab and add it to the strip. Keep track of its controller. |
| 218 // TODO(pinkerton): move everyone else over and animate. Also will need to | 219 // TODO(pinkerton): move everyone else over and animate. Also will need to |
| 219 // move the "add tab" button over. | 220 // move the "add tab" button over. |
| 220 NSRect newTabFrame = [self frameForNewTabAtIndex:index]; | 221 NSRect newTabFrame = [self frameForNewTabAtIndex:index]; |
| 221 NSButton* newView = [self newTabWithFrame:newTabFrame]; | 222 TabController* newController = [self newTabWithFrame:newTabFrame]; |
| 223 [tabArray_ insertObject:newController atIndex:index]; |
| 224 NSView* newView = [newController view]; |
| 222 [tabView_ addSubview:newView]; | 225 [tabView_ addSubview:newView]; |
| 223 | 226 |
| 224 [self setTabTitle:newView withContents:contents]; | 227 [self setTabTitle:newController withContents:contents]; |
| 225 | 228 |
| 226 // Add the new tab button back in to the right of the last tab. | 229 // Add the new tab button back in to the right of the last tab. |
| 227 const NSInteger kNewTabXOffset = 10; | 230 const NSInteger kNewTabXOffset = 10; |
| 228 NSRect lastTab = | 231 NSRect lastTab = |
| 229 [[[tabView_ subviews] objectAtIndex:[[tabView_ subviews] count] - 1] frame]; | 232 [[[tabView_ subviews] objectAtIndex:[[tabView_ subviews] count] - 1] frame]; |
| 230 NSInteger maxRightEdge = NSMaxX(lastTab); | 233 NSInteger maxRightEdge = NSMaxX(lastTab); |
| 231 NSRect newTabButtonFrame = [newTabButton_ frame]; | 234 NSRect newTabButtonFrame = [newTabButton_ frame]; |
| 232 newTabButtonFrame.origin.x = maxRightEdge + kNewTabXOffset; | 235 newTabButtonFrame.origin.x = maxRightEdge + kNewTabXOffset; |
| 233 [newTabButton_ setFrame:newTabButtonFrame]; | 236 [newTabButton_ setFrame:newTabButtonFrame]; |
| 234 [tabView_ addSubview:newTabButton_]; | 237 [tabView_ addSubview:newTabButton_]; |
| 235 | 238 |
| 236 // Select the newly created tab if in the foreground | 239 // Select the newly created tab if in the foreground |
| 237 if (inForeground) | 240 if (inForeground) |
| 238 [self swapInTabAtIndex:index]; | 241 [self swapInTabAtIndex:index]; |
| 239 } | 242 } |
| 240 | 243 |
| 241 // Called when a notification is received from the model to select a particular | 244 // Called when a notification is received from the model to select a particular |
| 242 // tab. Swaps in the toolbar and content area associated with |newContents|. | 245 // tab. Swaps in the toolbar and content area associated with |newContents|. |
| 243 - (void)selectTabWithContents:(TabContents*)newContents | 246 - (void)selectTabWithContents:(TabContents*)newContents |
| 244 previousContents:(TabContents*)oldContents | 247 previousContents:(TabContents*)oldContents |
| 245 atIndex:(NSInteger)index | 248 atIndex:(NSInteger)index |
| 246 userGesture:(bool)wasUserGesture { | 249 userGesture:(bool)wasUserGesture { |
| 247 // De-select all other tabs and select the new tab. | 250 // De-select all other tabs and select the new tab. |
| 248 const int numSubviews = [self numberOfTabViews]; | 251 const int numSubviews = [self numberOfTabViews]; |
| 249 for (int i = 0; i < numSubviews; i++) { | 252 for (int i = 0; i < numSubviews; i++) { |
| 250 NSButton* current = [[tabView_ subviews] objectAtIndex:i]; | 253 TabController* current = [tabArray_ objectAtIndex:i]; |
| 251 [current setState:(i == index) ? NSOnState : NSOffState]; | 254 [current setSelected:(i == index) ? YES : NO]; |
| 252 } | 255 } |
| 253 | 256 |
| 254 // Tell the new tab contents it is about to become the selected tab. Here it | 257 // Tell the new tab contents it is about to become the selected tab. Here it |
| 255 // can do things like make sure the toolbar is up to date. | 258 // can do things like make sure the toolbar is up to date. |
| 256 TabContentsController* newController = | 259 TabContentsController* newController = |
| 257 [tabControllerArray_ objectAtIndex:index]; | 260 [tabContentsArray_ objectAtIndex:index]; |
| 258 [newController willBecomeSelectedTab]; | 261 [newController willBecomeSelectedTab]; |
| 259 | 262 |
| 260 // Swap in the contents for the new tab | 263 // Swap in the contents for the new tab |
| 261 [self swapInTabAtIndex:index]; | 264 [self swapInTabAtIndex:index]; |
| 262 } | 265 } |
| 263 | 266 |
| 264 // Called when a notification is received from the model that the given tab | 267 // Called when a notification is received from the model that the given tab |
| 265 // has gone away. Remove all knowledge about this tab and it's associated | 268 // has gone away. Remove all knowledge about this tab and it's associated |
| 266 // controller and remove the view from the strip. | 269 // controller and remove the view from the strip. |
| 267 - (void)tabDetachedWithContents:(TabContents*)contents | 270 - (void)tabDetachedWithContents:(TabContents*)contents |
| 268 atIndex:(NSInteger)index { | 271 atIndex:(NSInteger)index { |
| 269 // Release the tab contents controller so those views get destroyed. This | 272 // Release the tab contents controller so those views get destroyed. This |
| 270 // will remove all the tab content Cocoa views from the hierarchy. A | 273 // will remove all the tab content Cocoa views from the hierarchy. A |
| 271 // subsequent "select tab" notification will follow from the model. To | 274 // subsequent "select tab" notification will follow from the model. To |
| 272 // tell us what to swap in in its absence. | 275 // tell us what to swap in in its absence. |
| 273 [tabControllerArray_ removeObjectAtIndex:index]; | 276 [tabContentsArray_ removeObjectAtIndex:index]; |
| 274 | 277 |
| 275 // Remove the |index|th view from the tab strip | 278 // Remove the |index|th view from the tab strip |
| 276 NSView* tab = [[tabView_ subviews] objectAtIndex:index]; | 279 NSView* tab = [[tabView_ subviews] objectAtIndex:index]; |
| 277 NSInteger tabWidth = [tab frame].size.width; | 280 NSInteger tabWidth = [tab frame].size.width; |
| 278 [tab removeFromSuperview]; | 281 [tab removeFromSuperview]; |
| 279 | 282 |
| 280 // Move all the views to the right the width of the tab that was closed. | 283 // Move all the views to the right the width of the tab that was closed. |
| 281 // TODO(pinkerton): Animate! | 284 // TODO(pinkerton): Animate! |
| 282 const int numSubviews = [[tabView_ subviews] count]; | 285 const int numSubviews = [[tabView_ subviews] count]; |
| 283 for (int i = index; i < numSubviews; i++) { | 286 for (int i = index; i < numSubviews; i++) { |
| 284 NSView* curr = [[tabView_ subviews] objectAtIndex:i]; | 287 NSView* curr = [[tabView_ subviews] objectAtIndex:i]; |
| 285 NSRect newFrame = [curr frame]; | 288 NSRect newFrame = [curr frame]; |
| 286 newFrame.origin.x -= tabWidth - kTabOverlap; | 289 newFrame.origin.x -= tabWidth - kTabOverlap; |
| 287 [curr setFrame:newFrame]; | 290 [curr setFrame:newFrame]; |
| 288 } | 291 } |
| 292 |
| 293 // Once we're totally done with the tab, delete its controller |
| 294 [tabArray_ removeObjectAtIndex:index]; |
| 289 } | 295 } |
| 290 | 296 |
| 291 // Called when a notification is received from the model that the given tab | 297 // Called when a notification is received from the model that the given tab |
| 292 // has been updated. | 298 // has been updated. |
| 293 - (void)tabChangedWithContents:(TabContents*)contents | 299 - (void)tabChangedWithContents:(TabContents*)contents |
| 294 atIndex:(NSInteger)index { | 300 atIndex:(NSInteger)index { |
| 295 NSButton* tab = [[tabView_ subviews] objectAtIndex:index]; | 301 [self setTabTitle:[tabArray_ objectAtIndex:index] withContents:contents]; |
| 296 [self setTabTitle:tab withContents:contents]; | |
| 297 | 302 |
| 298 TabContentsController* updatedController = | 303 TabContentsController* updatedController = |
| 299 [tabControllerArray_ objectAtIndex:index]; | 304 [tabContentsArray_ objectAtIndex:index]; |
| 300 [updatedController tabDidChange:contents]; | 305 [updatedController tabDidChange:contents]; |
| 301 } | 306 } |
| 302 | 307 |
| 303 - (LocationBar*)locationBar { | 308 - (LocationBar*)locationBar { |
| 304 TabContentsController* selectedController = | 309 TabContentsController* selectedController = |
| 305 [tabControllerArray_ objectAtIndex:tabModel_->selected_index()]; | 310 [tabContentsArray_ objectAtIndex:tabModel_->selected_index()]; |
| 306 return [selectedController locationBar]; | 311 return [selectedController locationBar]; |
| 307 } | 312 } |
| 308 | 313 |
| 309 - (void)updateToolbarWithContents:(TabContents*)tab | 314 - (void)updateToolbarWithContents:(TabContents*)tab |
| 310 shouldRestoreState:(BOOL)shouldRestore { | 315 shouldRestoreState:(BOOL)shouldRestore { |
| 311 // TODO(pinkerton): OS_WIN maintains this, but I'm not sure why. It's | 316 // TODO(pinkerton): OS_WIN maintains this, but I'm not sure why. It's |
| 312 // available by querying the model, which we have available to us. | 317 // available by querying the model, which we have available to us. |
| 313 currentTab_ = tab; | 318 currentTab_ = tab; |
| 314 | 319 |
| 315 // tell the appropriate controller to update its state. |shouldRestore| being | 320 // tell the appropriate controller to update its state. |shouldRestore| being |
| 316 // YES means we're going back to this tab and should put back any state | 321 // YES means we're going back to this tab and should put back any state |
| 317 // associated with it. | 322 // associated with it. |
| 318 TabContentsController* controller = | 323 TabContentsController* controller = |
| 319 [tabControllerArray_ objectAtIndex:tabModel_->GetIndexOfTabContents(tab)]; | 324 [tabContentsArray_ objectAtIndex:tabModel_->GetIndexOfTabContents(tab)]; |
| 320 [controller updateToolbarWithContents:shouldRestore ? tab : nil]; | 325 [controller updateToolbarWithContents:shouldRestore ? tab : nil]; |
| 321 } | 326 } |
| 322 | 327 |
| 323 - (void)setStarredState:(BOOL)isStarred { | 328 - (void)setStarredState:(BOOL)isStarred { |
| 324 TabContentsController* selectedController = | 329 TabContentsController* selectedController = |
| 325 [tabControllerArray_ objectAtIndex:tabModel_->selected_index()]; | 330 [tabContentsArray_ objectAtIndex:tabModel_->selected_index()]; |
| 326 [selectedController setStarredState:isStarred]; | 331 [selectedController setStarredState:isStarred]; |
| 327 } | 332 } |
| 328 | 333 |
| 329 // Return the rect, in WebKit coordinates (flipped), of the window's grow box | 334 // Return the rect, in WebKit coordinates (flipped), of the window's grow box |
| 330 // in the coordinate system of the content area of the currently selected tab. | 335 // in the coordinate system of the content area of the currently selected tab. |
| 331 - (NSRect)selectedTabGrowBoxRect { | 336 - (NSRect)selectedTabGrowBoxRect { |
| 332 int selectedIndex = tabModel_->selected_index(); | 337 int selectedIndex = tabModel_->selected_index(); |
| 333 if (selectedIndex == TabStripModel::kNoTab) { | 338 if (selectedIndex == TabStripModel::kNoTab) { |
| 334 // When the window is initially being constructed, there may be no currently | 339 // When the window is initially being constructed, there may be no currently |
| 335 // selected tab, so pick the first one. If there aren't any, just bail with | 340 // selected tab, so pick the first one. If there aren't any, just bail with |
| 336 // an empty rect. | 341 // an empty rect. |
| 337 selectedIndex = 0; | 342 selectedIndex = 0; |
| 338 } | 343 } |
| 339 TabContentsController* selectedController = | 344 TabContentsController* selectedController = |
| 340 [tabControllerArray_ objectAtIndex:selectedIndex]; | 345 [tabContentsArray_ objectAtIndex:selectedIndex]; |
| 341 if (!selectedController) | 346 if (!selectedController) |
| 342 return NSZeroRect; | 347 return NSZeroRect; |
| 343 return [selectedController growBoxRect]; | 348 return [selectedController growBoxRect]; |
| 344 } | 349 } |
| 345 | 350 |
| 346 // Called to tell the selected tab to update its loading state. | 351 // Called to tell the selected tab to update its loading state. |
| 347 - (void)setIsLoading:(BOOL)isLoading { | 352 - (void)setIsLoading:(BOOL)isLoading { |
| 348 // TODO(pinkerton): update the favicon on the selected tab view to/from | 353 // TODO(pinkerton): update the favicon on the selected tab view to/from |
| 349 // a spinner? | 354 // a spinner? |
| 350 | 355 |
| 351 TabContentsController* selectedController = | 356 TabContentsController* selectedController = |
| 352 [tabControllerArray_ objectAtIndex:tabModel_->selected_index()]; | 357 [tabContentsArray_ objectAtIndex:tabModel_->selected_index()]; |
| 353 [selectedController setIsLoading:isLoading]; | 358 [selectedController setIsLoading:isLoading]; |
| 354 } | 359 } |
| 355 | 360 |
| 356 // Make the location bar the first responder, if possible. | 361 // Make the location bar the first responder, if possible. |
| 357 - (void)focusLocationBar { | 362 - (void)focusLocationBar { |
| 358 TabContentsController* selectedController = | 363 TabContentsController* selectedController = |
| 359 [tabControllerArray_ objectAtIndex:tabModel_->selected_index()]; | 364 [tabContentsArray_ objectAtIndex:tabModel_->selected_index()]; |
| 360 [selectedController focusLocationBar]; | 365 [selectedController focusLocationBar]; |
| 361 } | 366 } |
| 362 | 367 |
| 363 @end | 368 @end |
| 364 | 369 |
| 365 //-------------------------------------------------------------------------- | 370 //-------------------------------------------------------------------------- |
| 366 | 371 |
| 367 TabStripBridge::TabStripBridge(TabStripModel* model, | 372 TabStripBridge::TabStripBridge(TabStripModel* model, |
| 368 TabStripController* controller) | 373 TabStripController* controller) |
| 369 : controller_(controller), model_(model) { | 374 : controller_(controller), model_(model) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 NOTIMPLEMENTED(); | 410 NOTIMPLEMENTED(); |
| 406 } | 411 } |
| 407 | 412 |
| 408 void TabStripBridge::TabChangedAt(TabContents* contents, int index) { | 413 void TabStripBridge::TabChangedAt(TabContents* contents, int index) { |
| 409 [controller_ tabChangedWithContents:contents atIndex:index]; | 414 [controller_ tabChangedWithContents:contents atIndex:index]; |
| 410 } | 415 } |
| 411 | 416 |
| 412 void TabStripBridge::TabStripEmpty() { | 417 void TabStripBridge::TabStripEmpty() { |
| 413 NOTIMPLEMENTED(); | 418 NOTIMPLEMENTED(); |
| 414 } | 419 } |
| OLD | NEW |