Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm

Issue 10534093: TabContentsWrapper -> TabContents, part 37. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 27 matching lines...) Expand all
38 #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h" 38 #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h"
39 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" 39 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h"
40 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" 40 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
41 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" 41 #import "chrome/browser/ui/cocoa/tabs/tab_view.h"
42 #import "chrome/browser/ui/cocoa/tabs/throbber_view.h" 42 #import "chrome/browser/ui/cocoa/tabs/throbber_view.h"
43 #import "chrome/browser/ui/cocoa/tracking_area.h" 43 #import "chrome/browser/ui/cocoa/tracking_area.h"
44 #include "chrome/browser/ui/constrained_window_tab_helper.h" 44 #include "chrome/browser/ui/constrained_window_tab_helper.h"
45 #include "chrome/browser/ui/find_bar/find_bar.h" 45 #include "chrome/browser/ui/find_bar/find_bar.h"
46 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 46 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
47 #include "chrome/browser/ui/find_bar/find_tab_helper.h" 47 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
48 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 48 #include "chrome/browser/ui/tab_contents/tab_contents.h"
49 #include "chrome/browser/ui/tabs/tab_menu_model.h" 49 #include "chrome/browser/ui/tabs/tab_menu_model.h"
50 #include "chrome/browser/ui/tabs/tab_strip_model.h" 50 #include "chrome/browser/ui/tabs/tab_strip_model.h"
51 #include "chrome/browser/ui/tabs/tab_strip_selection_model.h" 51 #include "chrome/browser/ui/tabs/tab_strip_selection_model.h"
52 #include "chrome/common/chrome_switches.h" 52 #include "chrome/common/chrome_switches.h"
53 #include "chrome/common/pref_names.h" 53 #include "chrome/common/pref_names.h"
54 #include "content/public/browser/navigation_controller.h" 54 #include "content/public/browser/navigation_controller.h"
55 #include "content/public/browser/user_metrics.h" 55 #include "content/public/browser/user_metrics.h"
56 #include "content/public/browser/web_contents.h" 56 #include "content/public/browser/web_contents.h"
57 #include "content/public/browser/web_contents_view.h" 57 #include "content/public/browser/web_contents_view.h"
58 #include "grit/generated_resources.h" 58 #include "grit/generated_resources.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 bool animate_; 137 bool animate_;
138 DISALLOW_COPY_AND_ASSIGN(ScopedNSAnimationContextGroup); 138 DISALLOW_COPY_AND_ASSIGN(ScopedNSAnimationContextGroup);
139 }; 139 };
140 140
141 } // namespace 141 } // namespace
142 142
143 @interface TabStripController (Private) 143 @interface TabStripController (Private)
144 - (void)addSubviewToPermanentList:(NSView*)aView; 144 - (void)addSubviewToPermanentList:(NSView*)aView;
145 - (void)regenerateSubviewList; 145 - (void)regenerateSubviewList;
146 - (NSInteger)indexForContentsView:(NSView*)view; 146 - (NSInteger)indexForContentsView:(NSView*)view;
147 - (void)updateFaviconForContents:(TabContentsWrapper*)contents 147 - (void)updateFaviconForContents:(TabContents*)contents
148 atIndex:(NSInteger)modelIndex; 148 atIndex:(NSInteger)modelIndex;
149 - (void)layoutTabsWithAnimation:(BOOL)animate 149 - (void)layoutTabsWithAnimation:(BOOL)animate
150 regenerateSubviews:(BOOL)doUpdate; 150 regenerateSubviews:(BOOL)doUpdate;
151 - (void)animationDidStopForController:(TabController*)controller 151 - (void)animationDidStopForController:(TabController*)controller
152 finished:(BOOL)finished; 152 finished:(BOOL)finished;
153 - (NSInteger)indexFromModelIndex:(NSInteger)index; 153 - (NSInteger)indexFromModelIndex:(NSInteger)index;
154 - (NSInteger)numberOfOpenTabs; 154 - (NSInteger)numberOfOpenTabs;
155 - (NSInteger)numberOfOpenMiniTabs; 155 - (NSInteger)numberOfOpenMiniTabs;
156 - (NSInteger)numberOfOpenNonMiniTabs; 156 - (NSInteger)numberOfOpenNonMiniTabs;
157 - (void)mouseMoved:(NSEvent*)event; 157 - (void)mouseMoved:(NSEvent*)event;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 295
296 - (void)animationDidStop:(CAAnimation*)animation finished:(BOOL)finished { 296 - (void)animationDidStop:(CAAnimation*)animation finished:(BOOL)finished {
297 [strip_ animationDidStopForController:controller_ finished:finished]; 297 [strip_ animationDidStopForController:controller_ finished:finished];
298 } 298 }
299 299
300 @end 300 @end
301 301
302 #pragma mark - 302 #pragma mark -
303 303
304 // In general, there is a one-to-one correspondence between TabControllers, 304 // In general, there is a one-to-one correspondence between TabControllers,
305 // TabViews, TabContentsControllers, and the TabContentsWrapper in the 305 // TabViews, TabContentsControllers, and the TabContents in the
306 // TabStripModel. In the steady-state, the indices line up so an index coming 306 // TabStripModel. In the steady-state, the indices line up so an index coming
307 // from the model is directly mapped to the same index in the parallel arrays 307 // from the model is directly mapped to the same index in the parallel arrays
308 // holding our views and controllers. This is also true when new tabs are 308 // holding our views and controllers. This is also true when new tabs are
309 // created (even though there is a small period of animation) because the tab is 309 // created (even though there is a small period of animation) because the tab is
310 // present in the model while the TabView is animating into place. As a result, 310 // present in the model while the TabView is animating into place. As a result,
311 // nothing special need be done to handle "new tab" animation. 311 // nothing special need be done to handle "new tab" animation.
312 // 312 //
313 // This all goes out the window with the "close tab" animation. The animation 313 // This all goes out the window with the "close tab" animation. The animation
314 // kicks off in |-tabDetachedWithContents:atIndex:| with the notification that 314 // kicks off in |-tabDetachedWithContents:atIndex:| with the notification that
315 // the tab has been removed from the model. The simplest solution at this 315 // the tab has been removed from the model. The simplest solution at this
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 // Set accessibility descriptions. http://openradar.appspot.com/7496255 446 // Set accessibility descriptions. http://openradar.appspot.com/7496255
447 NSString* description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_NEWTAB); 447 NSString* description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_NEWTAB);
448 [[newTabButton_ cell] 448 [[newTabButton_ cell]
449 accessibilitySetOverrideValue:description 449 accessibilitySetOverrideValue:description
450 forAttribute:NSAccessibilityDescriptionAttribute]; 450 forAttribute:NSAccessibilityDescriptionAttribute];
451 451
452 // Controller may have been (re-)created by switching layout modes, which 452 // Controller may have been (re-)created by switching layout modes, which
453 // means the tab model is already fully formed with tabs. Need to walk the 453 // means the tab model is already fully formed with tabs. Need to walk the
454 // list and create the UI for each. 454 // list and create the UI for each.
455 const int existingTabCount = tabStripModel_->count(); 455 const int existingTabCount = tabStripModel_->count();
456 const TabContentsWrapper* selection = 456 const TabContents* selection = tabStripModel_->GetActiveTabContents();
457 tabStripModel_->GetActiveTabContents();
458 for (int i = 0; i < existingTabCount; ++i) { 457 for (int i = 0; i < existingTabCount; ++i) {
459 TabContentsWrapper* currentContents = tabStripModel_->GetTabContentsAt(i); 458 TabContents* currentContents = tabStripModel_->GetTabContentsAt(i);
460 [self insertTabWithContents:currentContents 459 [self insertTabWithContents:currentContents
461 atIndex:i 460 atIndex:i
462 inForeground:NO]; 461 inForeground:NO];
463 if (selection == currentContents) { 462 if (selection == currentContents) {
464 // Must manually force a selection since the model won't send 463 // Must manually force a selection since the model won't send
465 // selection messages in this scenario. 464 // selection messages in this scenario.
466 [self activateTabWithContents:currentContents 465 [self activateTabWithContents:currentContents
467 previousContents:NULL 466 previousContents:NULL
468 atIndex:i 467 atIndex:i
469 userGesture:NO]; 468 userGesture:NO];
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 // It also restores content autoresizing properties. 548 // It also restores content autoresizing properties.
550 [controller ensureContentsVisible]; 549 [controller ensureContentsVisible];
551 550
552 // Tell per-tab sheet manager about currently selected tab. 551 // Tell per-tab sheet manager about currently selected tab.
553 if (sheetController_.get()) { 552 if (sheetController_.get()) {
554 [sheetController_ setActiveView:newView]; 553 [sheetController_ setActiveView:newView];
555 } 554 }
556 555
557 // Make sure the new tabs's sheets are visible (necessary when a background 556 // Make sure the new tabs's sheets are visible (necessary when a background
558 // tab opened a sheet while it was in the background and now becomes active). 557 // tab opened a sheet while it was in the background and now becomes active).
559 TabContentsWrapper* newTab = tabStripModel_->GetTabContentsAt(modelIndex); 558 TabContents* newTab = tabStripModel_->GetTabContentsAt(modelIndex);
560 DCHECK(newTab); 559 DCHECK(newTab);
561 if (newTab) { 560 if (newTab) {
562 ConstrainedWindowTabHelper::ConstrainedWindowList::iterator it, end; 561 ConstrainedWindowTabHelper::ConstrainedWindowList::iterator it, end;
563 end = newTab->constrained_window_tab_helper()->constrained_window_end(); 562 end = newTab->constrained_window_tab_helper()->constrained_window_end();
564 NSWindowController* controller = [[newView window] windowController]; 563 NSWindowController* controller = [[newView window] windowController];
565 DCHECK([controller isKindOfClass:[BrowserWindowController class]]); 564 DCHECK([controller isKindOfClass:[BrowserWindowController class]]);
566 565
567 for (it = newTab->constrained_window_tab_helper()-> 566 for (it = newTab->constrained_window_tab_helper()->
568 constrained_window_begin(); 567 constrained_window_begin();
569 it != end; 568 it != end;
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 if (contents) 1136 if (contents)
1138 titleString = base::SysUTF16ToNSString(contents->GetTitle()); 1137 titleString = base::SysUTF16ToNSString(contents->GetTitle());
1139 if (![titleString length]) { 1138 if (![titleString length]) {
1140 titleString = l10n_util::GetNSString(IDS_BROWSER_WINDOW_MAC_TAB_UNTITLED); 1139 titleString = l10n_util::GetNSString(IDS_BROWSER_WINDOW_MAC_TAB_UNTITLED);
1141 } 1140 }
1142 [tab setTitle:titleString]; 1141 [tab setTitle:titleString];
1143 } 1142 }
1144 1143
1145 // Called when a notification is received from the model to insert a new tab 1144 // Called when a notification is received from the model to insert a new tab
1146 // at |modelIndex|. 1145 // at |modelIndex|.
1147 - (void)insertTabWithContents:(TabContentsWrapper*)contents 1146 - (void)insertTabWithContents:(TabContents*)contents
1148 atIndex:(NSInteger)modelIndex 1147 atIndex:(NSInteger)modelIndex
1149 inForeground:(bool)inForeground { 1148 inForeground:(bool)inForeground {
1150 DCHECK(contents); 1149 DCHECK(contents);
1151 DCHECK(modelIndex == TabStripModel::kNoTab || 1150 DCHECK(modelIndex == TabStripModel::kNoTab ||
1152 tabStripModel_->ContainsIndex(modelIndex)); 1151 tabStripModel_->ContainsIndex(modelIndex));
1153 1152
1154 // Cancel any pending tab transition. 1153 // Cancel any pending tab transition.
1155 hoverTabSelector_->CancelTabTransition(); 1154 hoverTabSelector_->CancelTabTransition();
1156 1155
1157 // Take closing tabs into account. 1156 // Take closing tabs into account.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 // During normal loading, we won't yet have a favicon and we'll get 1194 // During normal loading, we won't yet have a favicon and we'll get
1196 // subsequent state change notifications to show the throbber, but when we're 1195 // subsequent state change notifications to show the throbber, but when we're
1197 // dragging a tab out into a new window, we have to put the tab's favicon 1196 // dragging a tab out into a new window, we have to put the tab's favicon
1198 // into the right state up front as we won't be told to do it from anywhere 1197 // into the right state up front as we won't be told to do it from anywhere
1199 // else. 1198 // else.
1200 [self updateFaviconForContents:contents atIndex:modelIndex]; 1199 [self updateFaviconForContents:contents atIndex:modelIndex];
1201 } 1200 }
1202 1201
1203 // Called when a notification is received from the model to select a particular 1202 // Called when a notification is received from the model to select a particular
1204 // tab. Swaps in the toolbar and content area associated with |newContents|. 1203 // tab. Swaps in the toolbar and content area associated with |newContents|.
1205 - (void)activateTabWithContents:(TabContentsWrapper*)newContents 1204 - (void)activateTabWithContents:(TabContents*)newContents
1206 previousContents:(TabContentsWrapper*)oldContents 1205 previousContents:(TabContents*)oldContents
1207 atIndex:(NSInteger)modelIndex 1206 atIndex:(NSInteger)modelIndex
1208 userGesture:(bool)wasUserGesture { 1207 userGesture:(bool)wasUserGesture {
1209 // Take closing tabs into account. 1208 // Take closing tabs into account.
1210 NSInteger activeIndex = [self indexFromModelIndex:modelIndex]; 1209 NSInteger activeIndex = [self indexFromModelIndex:modelIndex];
1211 1210
1212 if (oldContents) { 1211 if (oldContents) {
1213 int oldModelIndex = browser_->GetIndexOfController( 1212 int oldModelIndex = browser_->GetIndexOfController(
1214 &(oldContents->web_contents()->GetController())); 1213 &(oldContents->web_contents()->GetController()));
1215 if (oldModelIndex != -1) { // When closing a tab, the old tab may be gone. 1214 if (oldModelIndex != -1) { // When closing a tab, the old tab may be gone.
1216 NSInteger oldIndex = [self indexFromModelIndex:oldModelIndex]; 1215 NSInteger oldIndex = [self indexFromModelIndex:oldModelIndex];
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 1253
1255 if (newContents) { 1254 if (newContents) {
1256 newContents->web_contents()->DidBecomeSelected(); 1255 newContents->web_contents()->DidBecomeSelected();
1257 newContents->web_contents()->GetView()->RestoreFocus(); 1256 newContents->web_contents()->GetView()->RestoreFocus();
1258 1257
1259 if (newContents->find_tab_helper()->find_ui_active()) 1258 if (newContents->find_tab_helper()->find_ui_active())
1260 browser_->GetFindBarController()->find_bar()->SetFocusAndSelection(); 1259 browser_->GetFindBarController()->find_bar()->SetFocusAndSelection();
1261 } 1260 }
1262 } 1261 }
1263 1262
1264 - (void)tabReplacedWithContents:(TabContentsWrapper*)newContents 1263 - (void)tabReplacedWithContents:(TabContents*)newContents
1265 previousContents:(TabContentsWrapper*)oldContents 1264 previousContents:(TabContents*)oldContents
1266 atIndex:(NSInteger)modelIndex { 1265 atIndex:(NSInteger)modelIndex {
1267 NSInteger index = [self indexFromModelIndex:modelIndex]; 1266 NSInteger index = [self indexFromModelIndex:modelIndex];
1268 TabContentsController* oldController = 1267 TabContentsController* oldController =
1269 [tabContentsArray_ objectAtIndex:index]; 1268 [tabContentsArray_ objectAtIndex:index];
1270 DCHECK_EQ(oldContents->web_contents(), [oldController webContents]); 1269 DCHECK_EQ(oldContents->web_contents(), [oldController webContents]);
1271 1270
1272 // Simply create a new TabContentsController for |newContents| and place it 1271 // Simply create a new TabContentsController for |newContents| and place it
1273 // into the array, replacing |oldContents|. A ActiveTabChanged notification 1272 // into the array, replacing |oldContents|. A ActiveTabChanged notification
1274 // will follow, at which point we will install the new view. 1273 // will follow, at which point we will install the new view.
1275 scoped_nsobject<TabContentsController> newController( 1274 scoped_nsobject<TabContentsController> newController(
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 NSRect newFrame = [tabView frame]; 1368 NSRect newFrame = [tabView frame];
1370 newFrame = NSOffsetRect(newFrame, 0, -newFrame.size.height); 1369 newFrame = NSOffsetRect(newFrame, 0, -newFrame.size.height);
1371 ScopedNSAnimationContextGroup animationGroup(true); 1370 ScopedNSAnimationContextGroup animationGroup(true);
1372 animationGroup.SetCurrentContextDuration(kAnimationDuration); 1371 animationGroup.SetCurrentContextDuration(kAnimationDuration);
1373 [[tabView animator] setFrame:newFrame]; 1372 [[tabView animator] setFrame:newFrame];
1374 } 1373 }
1375 1374
1376 // Called when a notification is received from the model that the given tab 1375 // Called when a notification is received from the model that the given tab
1377 // has gone away. Start an animation then force a layout to put everything 1376 // has gone away. Start an animation then force a layout to put everything
1378 // in motion. 1377 // in motion.
1379 - (void)tabDetachedWithContents:(TabContentsWrapper*)contents 1378 - (void)tabDetachedWithContents:(TabContents*)contents
1380 atIndex:(NSInteger)modelIndex { 1379 atIndex:(NSInteger)modelIndex {
1381 // Take closing tabs into account. 1380 // Take closing tabs into account.
1382 NSInteger index = [self indexFromModelIndex:modelIndex]; 1381 NSInteger index = [self indexFromModelIndex:modelIndex];
1383 1382
1384 // Cancel any pending tab transition. 1383 // Cancel any pending tab transition.
1385 hoverTabSelector_->CancelTabTransition(); 1384 hoverTabSelector_->CancelTabTransition();
1386 1385
1387 TabController* tab = [tabArray_ objectAtIndex:index]; 1386 TabController* tab = [tabArray_ objectAtIndex:index];
1388 if (tabStripModel_->count() > 0) { 1387 if (tabStripModel_->count() > 0) {
1389 [self startClosingTabWithAnimation:tab]; 1388 [self startClosingTabWithAnimation:tab];
1390 [self layoutTabs]; 1389 [self layoutTabs];
1391 } else { 1390 } else {
1392 [self removeTab:tab]; 1391 [self removeTab:tab];
1393 } 1392 }
1394 1393
1395 [delegate_ onTabDetachedWithContents:contents->web_contents()]; 1394 [delegate_ onTabDetachedWithContents:contents->web_contents()];
1396 } 1395 }
1397 1396
1398 // A helper routine for creating an NSImageView to hold the favicon or app icon 1397 // A helper routine for creating an NSImageView to hold the favicon or app icon
1399 // for |contents|. 1398 // for |contents|.
1400 - (NSImageView*)iconImageViewForContents:(TabContentsWrapper*)contents { 1399 - (NSImageView*)iconImageViewForContents:(TabContents*)contents {
1401 BOOL isApp = contents->extension_tab_helper()->is_app(); 1400 BOOL isApp = contents->extension_tab_helper()->is_app();
1402 NSImage* image = nil; 1401 NSImage* image = nil;
1403 // Favicons come from the renderer, and the renderer draws everything in the 1402 // Favicons come from the renderer, and the renderer draws everything in the
1404 // system color space. 1403 // system color space.
1405 CGColorSpaceRef colorSpace = base::mac::GetSystemColorSpace(); 1404 CGColorSpaceRef colorSpace = base::mac::GetSystemColorSpace();
1406 if (isApp) { 1405 if (isApp) {
1407 SkBitmap* icon = contents->extension_tab_helper()->GetExtensionAppIcon(); 1406 SkBitmap* icon = contents->extension_tab_helper()->GetExtensionAppIcon();
1408 if (icon) 1407 if (icon)
1409 image = gfx::SkBitmapToNSImageWithColorSpace(*icon, colorSpace); 1408 image = gfx::SkBitmapToNSImageWithColorSpace(*icon, colorSpace);
1410 } else { 1409 } else {
1411 image = mac::FaviconForTabContents(contents); 1410 image = mac::FaviconForTabContents(contents);
1412 } 1411 }
1413 1412
1414 // Either we don't have a valid favicon or there was some issue converting it 1413 // Either we don't have a valid favicon or there was some issue converting it
1415 // from an SkBitmap. Either way, just show the default. 1414 // from an SkBitmap. Either way, just show the default.
1416 if (!image) 1415 if (!image)
1417 image = defaultFavicon_.get(); 1416 image = defaultFavicon_.get();
1418 NSRect frame = NSMakeRect(0, 0, kIconWidthAndHeight, kIconWidthAndHeight); 1417 NSRect frame = NSMakeRect(0, 0, kIconWidthAndHeight, kIconWidthAndHeight);
1419 NSImageView* view = [[[NSImageView alloc] initWithFrame:frame] autorelease]; 1418 NSImageView* view = [[[NSImageView alloc] initWithFrame:frame] autorelease];
1420 [view setImage:image]; 1419 [view setImage:image];
1421 return view; 1420 return view;
1422 } 1421 }
1423 1422
1424 // Updates the current loading state, replacing the icon view with a favicon, 1423 // Updates the current loading state, replacing the icon view with a favicon,
1425 // a throbber, the default icon, or nothing at all. 1424 // a throbber, the default icon, or nothing at all.
1426 - (void)updateFaviconForContents:(TabContentsWrapper*)contents 1425 - (void)updateFaviconForContents:(TabContents*)contents
1427 atIndex:(NSInteger)modelIndex { 1426 atIndex:(NSInteger)modelIndex {
1428 if (!contents) 1427 if (!contents)
1429 return; 1428 return;
1430 1429
1431 static NSImage* throbberWaitingImage = 1430 static NSImage* throbberWaitingImage =
1432 [ResourceBundle::GetSharedInstance().GetNativeImageNamed( 1431 [ResourceBundle::GetSharedInstance().GetNativeImageNamed(
1433 IDR_THROBBER_WAITING) retain]; 1432 IDR_THROBBER_WAITING) retain];
1434 static NSImage* throbberLoadingImage = 1433 static NSImage* throbberLoadingImage =
1435 [ResourceBundle::GetSharedInstance().GetNativeImageNamed(IDR_THROBBER) 1434 [ResourceBundle::GetSharedInstance().GetNativeImageNamed(IDR_THROBBER)
1436 retain]; 1435 retain];
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1488 } 1487 }
1489 } 1488 }
1490 1489
1491 [tabController setIconView:iconView]; 1490 [tabController setIconView:iconView];
1492 } 1491 }
1493 } 1492 }
1494 1493
1495 // Called when a notification is received from the model that the given tab 1494 // Called when a notification is received from the model that the given tab
1496 // has been updated. |loading| will be YES when we only want to update the 1495 // has been updated. |loading| will be YES when we only want to update the
1497 // throbber state, not anything else about the (partially) loading tab. 1496 // throbber state, not anything else about the (partially) loading tab.
1498 - (void)tabChangedWithContents:(TabContentsWrapper*)contents 1497 - (void)tabChangedWithContents:(TabContents*)contents
1499 atIndex:(NSInteger)modelIndex 1498 atIndex:(NSInteger)modelIndex
1500 changeType:(TabStripModelObserver::TabChangeType)change { 1499 changeType:(TabStripModelObserver::TabChangeType)change {
1501 // Take closing tabs into account. 1500 // Take closing tabs into account.
1502 NSInteger index = [self indexFromModelIndex:modelIndex]; 1501 NSInteger index = [self indexFromModelIndex:modelIndex];
1503 1502
1504 if (modelIndex == tabStripModel_->active_index()) 1503 if (modelIndex == tabStripModel_->active_index())
1505 [delegate_ onTabChanged:change withContents:contents->web_contents()]; 1504 [delegate_ onTabChanged:change withContents:contents->web_contents()];
1506 1505
1507 if (change == TabStripModelObserver::TITLE_NOT_LOADING) { 1506 if (change == TabStripModelObserver::TITLE_NOT_LOADING) {
1508 // TODO(sky): make this work. 1507 // TODO(sky): make this work.
1509 // We'll receive another notification of the change asynchronously. 1508 // We'll receive another notification of the change asynchronously.
1510 return; 1509 return;
1511 } 1510 }
1512 1511
1513 TabController* tabController = [tabArray_ objectAtIndex:index]; 1512 TabController* tabController = [tabArray_ objectAtIndex:index];
1514 1513
1515 if (change != TabStripModelObserver::LOADING_ONLY) 1514 if (change != TabStripModelObserver::LOADING_ONLY)
1516 [self setTabTitle:tabController withContents:contents->web_contents()]; 1515 [self setTabTitle:tabController withContents:contents->web_contents()];
1517 1516
1518 [self updateFaviconForContents:contents atIndex:modelIndex]; 1517 [self updateFaviconForContents:contents atIndex:modelIndex];
1519 1518
1520 TabContentsController* updatedController = 1519 TabContentsController* updatedController =
1521 [tabContentsArray_ objectAtIndex:index]; 1520 [tabContentsArray_ objectAtIndex:index];
1522 [updatedController tabDidChange:contents->web_contents()]; 1521 [updatedController tabDidChange:contents->web_contents()];
1523 } 1522 }
1524 1523
1525 // Called when a tab is moved (usually by drag&drop). Keep our parallel arrays 1524 // Called when a tab is moved (usually by drag&drop). Keep our parallel arrays
1526 // in sync with the tab strip model. It can also be pinned/unpinned 1525 // in sync with the tab strip model. It can also be pinned/unpinned
1527 // simultaneously, so we need to take care of that. 1526 // simultaneously, so we need to take care of that.
1528 - (void)tabMovedWithContents:(TabContentsWrapper*)contents 1527 - (void)tabMovedWithContents:(TabContents*)contents
1529 fromIndex:(NSInteger)modelFrom 1528 fromIndex:(NSInteger)modelFrom
1530 toIndex:(NSInteger)modelTo { 1529 toIndex:(NSInteger)modelTo {
1531 // Take closing tabs into account. 1530 // Take closing tabs into account.
1532 NSInteger from = [self indexFromModelIndex:modelFrom]; 1531 NSInteger from = [self indexFromModelIndex:modelFrom];
1533 NSInteger to = [self indexFromModelIndex:modelTo]; 1532 NSInteger to = [self indexFromModelIndex:modelTo];
1534 1533
1535 // Cancel any pending tab transition. 1534 // Cancel any pending tab transition.
1536 hoverTabSelector_->CancelTabTransition(); 1535 hoverTabSelector_->CancelTabTransition();
1537 1536
1538 scoped_nsobject<TabContentsController> movedTabContentsController( 1537 scoped_nsobject<TabContentsController> movedTabContentsController(
1539 [[tabContentsArray_ objectAtIndex:from] retain]); 1538 [[tabContentsArray_ objectAtIndex:from] retain]);
1540 [tabContentsArray_ removeObjectAtIndex:from]; 1539 [tabContentsArray_ removeObjectAtIndex:from];
1541 [tabContentsArray_ insertObject:movedTabContentsController.get() 1540 [tabContentsArray_ insertObject:movedTabContentsController.get()
1542 atIndex:to]; 1541 atIndex:to];
1543 scoped_nsobject<TabController> movedTabController( 1542 scoped_nsobject<TabController> movedTabController(
1544 [[tabArray_ objectAtIndex:from] retain]); 1543 [[tabArray_ objectAtIndex:from] retain]);
1545 DCHECK([movedTabController isKindOfClass:[TabController class]]); 1544 DCHECK([movedTabController isKindOfClass:[TabController class]]);
1546 [tabArray_ removeObjectAtIndex:from]; 1545 [tabArray_ removeObjectAtIndex:from];
1547 [tabArray_ insertObject:movedTabController.get() atIndex:to]; 1546 [tabArray_ insertObject:movedTabController.get() atIndex:to];
1548 1547
1549 // The tab moved, which means that the mini-tab state may have changed. 1548 // The tab moved, which means that the mini-tab state may have changed.
1550 if (tabStripModel_->IsMiniTab(modelTo) != [movedTabController mini]) 1549 if (tabStripModel_->IsMiniTab(modelTo) != [movedTabController mini])
1551 [self tabMiniStateChangedWithContents:contents atIndex:modelTo]; 1550 [self tabMiniStateChangedWithContents:contents atIndex:modelTo];
1552 1551
1553 [self layoutTabs]; 1552 [self layoutTabs];
1554 } 1553 }
1555 1554
1556 // Called when a tab is pinned or unpinned without moving. 1555 // Called when a tab is pinned or unpinned without moving.
1557 - (void)tabMiniStateChangedWithContents:(TabContentsWrapper*)contents 1556 - (void)tabMiniStateChangedWithContents:(TabContents*)contents
1558 atIndex:(NSInteger)modelIndex { 1557 atIndex:(NSInteger)modelIndex {
1559 // Take closing tabs into account. 1558 // Take closing tabs into account.
1560 NSInteger index = [self indexFromModelIndex:modelIndex]; 1559 NSInteger index = [self indexFromModelIndex:modelIndex];
1561 1560
1562 TabController* tabController = [tabArray_ objectAtIndex:index]; 1561 TabController* tabController = [tabArray_ objectAtIndex:index];
1563 DCHECK([tabController isKindOfClass:[TabController class]]); 1562 DCHECK([tabController isKindOfClass:[TabController class]]);
1564 1563
1565 // Don't do anything if the change was already picked up by the move event. 1564 // Don't do anything if the change was already picked up by the move event.
1566 if (tabStripModel_->IsMiniTab(modelIndex) == [tabController mini]) 1565 if (tabStripModel_->IsMiniTab(modelIndex) == [tabController mini])
1567 return; 1566 return;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 1633
1635 // Move the given tab at index |from| in this window to the location of the 1634 // Move the given tab at index |from| in this window to the location of the
1636 // current placeholder. 1635 // current placeholder.
1637 - (void)moveTabFromIndex:(NSInteger)from { 1636 - (void)moveTabFromIndex:(NSInteger)from {
1638 int toIndex = [self indexOfPlaceholder]; 1637 int toIndex = [self indexOfPlaceholder];
1639 // Cancel any pending tab transition. 1638 // Cancel any pending tab transition.
1640 hoverTabSelector_->CancelTabTransition(); 1639 hoverTabSelector_->CancelTabTransition();
1641 tabStripModel_->MoveTabContentsAt(from, toIndex, true); 1640 tabStripModel_->MoveTabContentsAt(from, toIndex, true);
1642 } 1641 }
1643 1642
1644 // Drop a given TabContentsWrapper at the location of the current placeholder. 1643 // Drop a given TabContents at the location of the current placeholder.
1645 // If there is no placeholder, it will go at the end. Used when dragging from 1644 // If there is no placeholder, it will go at the end. Used when dragging from
1646 // another window when we don't have access to the WebContents as part of our 1645 // another window when we don't have access to the WebContents as part of our
1647 // strip. |frame| is in the coordinate system of the tab strip view and 1646 // strip. |frame| is in the coordinate system of the tab strip view and
1648 // represents where the user dropped the new tab so it can be animated into its 1647 // represents where the user dropped the new tab so it can be animated into its
1649 // correct location when the tab is added to the model. If the tab was pinned in 1648 // correct location when the tab is added to the model. If the tab was pinned in
1650 // its previous window, setting |pinned| to YES will propagate that state to the 1649 // its previous window, setting |pinned| to YES will propagate that state to the
1651 // new window. Mini-tabs are either app or pinned tabs; the app state is stored 1650 // new window. Mini-tabs are either app or pinned tabs; the app state is stored
1652 // by the |contents|, but the |pinned| state is the caller's responsibility. 1651 // by the |contents|, but the |pinned| state is the caller's responsibility.
1653 - (void)dropTabContents:(TabContentsWrapper*)contents 1652 - (void)dropTabContents:(TabContents*)contents
1654 withFrame:(NSRect)frame 1653 withFrame:(NSRect)frame
1655 asPinnedTab:(BOOL)pinned { 1654 asPinnedTab:(BOOL)pinned {
1656 int modelIndex = [self indexOfPlaceholder]; 1655 int modelIndex = [self indexOfPlaceholder];
1657 1656
1658 // Mark that the new tab being created should start at |frame|. It will be 1657 // Mark that the new tab being created should start at |frame|. It will be
1659 // reset as soon as the tab has been positioned. 1658 // reset as soon as the tab has been positioned.
1660 droppedTabFrame_ = frame; 1659 droppedTabFrame_ = frame;
1661 1660
1662 // Insert it into this tab strip. We want it in the foreground and to not 1661 // Insert it into this tab strip. We want it in the foreground and to not
1663 // inherit the current tab's group. 1662 // inherit the current tab's group.
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
2112 NSInteger index = [self indexFromModelIndex:modelIndex]; 2111 NSInteger index = [self indexFromModelIndex:modelIndex];
2113 BrowserWindowController* controller = 2112 BrowserWindowController* controller =
2114 (BrowserWindowController*)[[switchView_ window] windowController]; 2113 (BrowserWindowController*)[[switchView_ window] windowController];
2115 DCHECK(index >= 0); 2114 DCHECK(index >= 0);
2116 if (index >= 0) { 2115 if (index >= 0) {
2117 [controller setTab:[self viewAtIndex:index] isDraggable:YES]; 2116 [controller setTab:[self viewAtIndex:index] isDraggable:YES];
2118 } 2117 }
2119 } 2118 }
2120 2119
2121 @end 2120 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/tabs/tab_strip_controller.h ('k') | chrome/browser/ui/cocoa/tabs/tab_strip_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698