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/browser.h" |
| 10 #import "chrome/browser/cocoa/bookmark_bar_state_controller.h" |
9 #import "chrome/browser/cocoa/tab_strip_view.h" | 11 #import "chrome/browser/cocoa/tab_strip_view.h" |
10 #import "chrome/browser/cocoa/tab_cell.h" | 12 #import "chrome/browser/cocoa/tab_cell.h" |
11 #import "chrome/browser/cocoa/tab_contents_controller.h" | 13 #import "chrome/browser/cocoa/tab_contents_controller.h" |
12 #import "chrome/browser/cocoa/tab_controller.h" | 14 #import "chrome/browser/cocoa/tab_controller.h" |
13 #import "chrome/browser/cocoa/tab_view.h" | 15 #import "chrome/browser/cocoa/tab_view.h" |
14 #import "chrome/browser/tab_contents/tab_contents.h" | 16 #import "chrome/browser/tab_contents/tab_contents.h" |
15 #import "chrome/browser/tabs/tab_strip_model.h" | 17 #import "chrome/browser/tabs/tab_strip_model.h" |
16 | 18 |
17 // The amount of overlap tabs have in their button frames. | 19 // The amount of overlap tabs have in their button frames. |
18 const short kTabOverlap = 16; | 20 const short kTabOverlap = 16; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 virtual void TabStripEmpty(); | 58 virtual void TabStripEmpty(); |
57 | 59 |
58 private: | 60 private: |
59 TabStripController* controller_; // weak, owns me | 61 TabStripController* controller_; // weak, owns me |
60 TabStripModel* model_; // weak, owned by Browser | 62 TabStripModel* model_; // weak, owned by Browser |
61 }; | 63 }; |
62 | 64 |
63 @implementation TabStripController | 65 @implementation TabStripController |
64 | 66 |
65 - (id)initWithView:(TabStripView*)view | 67 - (id)initWithView:(TabStripView*)view |
66 tabModel:(TabStripModel*)tabModel | 68 browser:(Browser*)browser { |
67 toolbarModel:(ToolbarModel*)toolbarModel | 69 DCHECK(view && browser); |
68 commands:(CommandUpdater*)commands { | |
69 DCHECK(view && tabModel && toolbarModel); | |
70 if ((self = [super init])) { | 70 if ((self = [super init])) { |
71 tabView_ = view; | 71 tabView_ = view; |
72 tabModel_ = tabModel; | 72 tabModel_ = browser->tabstrip_model(); |
73 toolbarModel_ = toolbarModel; | 73 toolbarModel_ = browser->toolbar_model(); |
74 commands_ = commands; | 74 bookmarkModel_ = browser->profile()->GetBookmarkModel(); |
75 bridge_ = new TabStripBridge(tabModel, self); | 75 commands_ = browser->command_updater(); |
| 76 bridge_ = new TabStripBridge(tabModel_, self); |
76 tabContentsArray_ = [[NSMutableArray alloc] init]; | 77 tabContentsArray_ = [[NSMutableArray alloc] init]; |
77 tabArray_ = [[NSMutableArray alloc] init]; | 78 tabArray_ = [[NSMutableArray alloc] init]; |
78 | 79 bookmarkBarStateController_ = [[BookmarkBarStateController alloc] |
| 80 initWithBrowser:browser]; |
79 // Take the only child view present in the nib as the new tab button. For | 81 // Take the only child view present in the nib as the new tab button. For |
80 // some reason, if the view is present in the nib apriori, it draws | 82 // some reason, if the view is present in the nib apriori, it draws |
81 // correctly. If we create it in code and add it to the tab view, it draws | 83 // correctly. If we create it in code and add it to the tab view, it draws |
82 // with all sorts of crazy artifacts. | 84 // with all sorts of crazy artifacts. |
83 newTabButton_ = [[tabView_ subviews] objectAtIndex:0]; | 85 newTabButton_ = [[tabView_ subviews] objectAtIndex:0]; |
84 DCHECK([newTabButton_ isKindOfClass:[NSButton class]]); | 86 DCHECK([newTabButton_ isKindOfClass:[NSButton class]]); |
85 [newTabButton_ setTarget:nil]; | 87 [newTabButton_ setTarget:nil]; |
86 [newTabButton_ setAction:@selector(commandDispatch:)]; | 88 [newTabButton_ setAction:@selector(commandDispatch:)]; |
87 [newTabButton_ setTag:IDC_NEW_TAB]; | 89 [newTabButton_ setTag:IDC_NEW_TAB]; |
88 | 90 |
89 [tabView_ setWantsLayer:YES]; | 91 [tabView_ setWantsLayer:YES]; |
90 } | 92 } |
91 return self; | 93 return self; |
92 } | 94 } |
93 | 95 |
94 - (void)dealloc { | 96 - (void)dealloc { |
95 delete bridge_; | 97 delete bridge_; |
| 98 [bookmarkBarStateController_ release]; |
96 [tabContentsArray_ release]; | 99 [tabContentsArray_ release]; |
97 [tabArray_ release]; | 100 [tabArray_ release]; |
98 [super dealloc]; | 101 [super dealloc]; |
99 } | 102 } |
100 | 103 |
101 // Finds the associated TabContentsController at the given |index| and swaps | 104 // Finds the associated TabContentsController at the given |index| and swaps |
102 // out the sole child of the contentArea to display its contents. | 105 // out the sole child of the contentArea to display its contents. |
103 - (void)swapInTabAtIndex:(NSInteger)index { | 106 - (void)swapInTabAtIndex:(NSInteger)index { |
104 TabContentsController* controller = [tabContentsArray_ objectAtIndex:index]; | 107 TabContentsController* controller = [tabContentsArray_ objectAtIndex:index]; |
105 | 108 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 220 |
218 // TODO(pinkerton): handle tab dragging in here | 221 // TODO(pinkerton): handle tab dragging in here |
219 | 222 |
220 // Make a new tab. Load the contents of this tab from the nib and associate | 223 // Make a new tab. Load the contents of this tab from the nib and associate |
221 // the new controller with |contents| so it can be looked up later. | 224 // the new controller with |contents| so it can be looked up later. |
222 TabContentsController* contentsController = | 225 TabContentsController* contentsController = |
223 [[[TabContentsController alloc] initWithNibName:@"TabContents" | 226 [[[TabContentsController alloc] initWithNibName:@"TabContents" |
224 bundle:nil | 227 bundle:nil |
225 contents:contents | 228 contents:contents |
226 commands:commands_ | 229 commands:commands_ |
227 toolbarModel:toolbarModel_] | 230 toolbarModel:toolbarModel_ |
| 231 bookmarkModel:bookmarkModel_] |
228 autorelease]; | 232 autorelease]; |
| 233 if ([self isBookmarkBarVisible]) |
| 234 [contentsController toggleBookmarkBar:YES]; |
229 [tabContentsArray_ insertObject:contentsController atIndex:index]; | 235 [tabContentsArray_ insertObject:contentsController atIndex:index]; |
230 | 236 |
231 // Make a new tab and add it to the strip. Keep track of its controller. | 237 // Make a new tab and add it to the strip. Keep track of its controller. |
232 // TODO(pinkerton): move everyone else over and animate. Also will need to | 238 // TODO(pinkerton): move everyone else over and animate. Also will need to |
233 // move the "add tab" button over. | 239 // move the "add tab" button over. |
234 NSRect newTabFrame = [self frameForNewTabAtIndex:index]; | 240 NSRect newTabFrame = [self frameForNewTabAtIndex:index]; |
235 TabController* newController = [self newTabWithFrame:newTabFrame]; | 241 TabController* newController = [self newTabWithFrame:newTabFrame]; |
236 [tabArray_ insertObject:newController atIndex:index]; | 242 [tabArray_ insertObject:newController atIndex:index]; |
237 NSView* newView = [newController view]; | 243 NSView* newView = [newController view]; |
238 [tabView_ addSubview:newView]; | 244 [tabView_ addSubview:newView]; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 [selectedController setIsLoading:isLoading]; | 386 [selectedController setIsLoading:isLoading]; |
381 } | 387 } |
382 | 388 |
383 // Make the location bar the first responder, if possible. | 389 // Make the location bar the first responder, if possible. |
384 - (void)focusLocationBar { | 390 - (void)focusLocationBar { |
385 TabContentsController* selectedController = | 391 TabContentsController* selectedController = |
386 [tabContentsArray_ objectAtIndex:tabModel_->selected_index()]; | 392 [tabContentsArray_ objectAtIndex:tabModel_->selected_index()]; |
387 [selectedController focusLocationBar]; | 393 [selectedController focusLocationBar]; |
388 } | 394 } |
389 | 395 |
| 396 - (BOOL)isBookmarkBarVisible { |
| 397 return [bookmarkBarStateController_ visible]; |
| 398 } |
| 399 |
| 400 // Called from BrowserWindowController |
| 401 - (void)toggleBookmarkBar { |
| 402 [bookmarkBarStateController_ toggleBookmarkBar]; |
| 403 BOOL visible = [self isBookmarkBarVisible]; |
| 404 for (TabContentsController *controller in tabContentsArray_) { |
| 405 [controller toggleBookmarkBar:visible]; |
| 406 } |
| 407 |
| 408 } |
| 409 |
| 410 |
390 @end | 411 @end |
391 | 412 |
392 //-------------------------------------------------------------------------- | 413 //-------------------------------------------------------------------------- |
393 | 414 |
394 TabStripBridge::TabStripBridge(TabStripModel* model, | 415 TabStripBridge::TabStripBridge(TabStripModel* model, |
395 TabStripController* controller) | 416 TabStripController* controller) |
396 : controller_(controller), model_(model) { | 417 : controller_(controller), model_(model) { |
397 // Register to be a listener on the model so we can get updates and tell | 418 // Register to be a listener on the model so we can get updates and tell |
398 // the TabStripController about them. | 419 // the TabStripController about them. |
399 model_->AddObserver(this); | 420 model_->AddObserver(this); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 NOTIMPLEMENTED(); | 453 NOTIMPLEMENTED(); |
433 } | 454 } |
434 | 455 |
435 void TabStripBridge::TabChangedAt(TabContents* contents, int index) { | 456 void TabStripBridge::TabChangedAt(TabContents* contents, int index) { |
436 [controller_ tabChangedWithContents:contents atIndex:index]; | 457 [controller_ tabChangedWithContents:contents atIndex:index]; |
437 } | 458 } |
438 | 459 |
439 void TabStripBridge::TabStripEmpty() { | 460 void TabStripBridge::TabStripEmpty() { |
440 NOTIMPLEMENTED(); | 461 NOTIMPLEMENTED(); |
441 } | 462 } |
OLD | NEW |