OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <limits> | 9 #include <limits> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "app/mac/nsimage_cache.h" | 12 #include "app/mac/nsimage_cache.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/mac/mac_util.h" | 14 #include "base/mac/mac_util.h" |
15 #include "base/sys_string_conversions.h" | 15 #include "base/sys_string_conversions.h" |
16 #include "chrome/app/chrome_command_ids.h" | 16 #include "chrome/app/chrome_command_ids.h" |
17 #include "chrome/browser/autocomplete/autocomplete.h" | 17 #include "chrome/browser/autocomplete/autocomplete.h" |
18 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 18 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
19 #include "chrome/browser/autocomplete/autocomplete_match.h" | 19 #include "chrome/browser/autocomplete/autocomplete_match.h" |
20 #include "chrome/browser/extensions/extension_tab_helper.h" | 20 #include "chrome/browser/extensions/extension_tab_helper.h" |
21 #include "chrome/browser/metrics/user_metrics.h" | 21 #include "chrome/browser/metrics/user_metrics.h" |
22 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/debugger/devtools_window.h" | 24 #include "chrome/browser/debugger/devtools_window.h" |
25 #include "chrome/browser/net/url_fixer_upper.h" | 25 #include "chrome/browser/net/url_fixer_upper.h" |
26 #include "chrome/browser/sidebar/sidebar_container.h" | 26 #include "chrome/browser/sidebar/sidebar_container.h" |
27 #include "chrome/browser/sidebar/sidebar_manager.h" | 27 #include "chrome/browser/sidebar/sidebar_manager.h" |
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/ui/browser.h" | 30 #include "chrome/browser/ui/browser.h" |
30 #include "chrome/browser/ui/browser_navigator.h" | 31 #include "chrome/browser/ui/browser_navigator.h" |
31 #include "chrome/browser/ui/find_bar/find_tab_helper.h" | 32 #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
32 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 33 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
33 #import "chrome/browser/ui/cocoa/constrained_window_mac.h" | 34 #import "chrome/browser/ui/cocoa/constrained_window_mac.h" |
34 #import "chrome/browser/ui/cocoa/new_tab_button.h" | 35 #import "chrome/browser/ui/cocoa/new_tab_button.h" |
35 #import "chrome/browser/ui/cocoa/profile_menu_button.h" | 36 #import "chrome/browser/ui/cocoa/profile_menu_button.h" |
36 #import "chrome/browser/ui/cocoa/tab_contents/favicon_util.h" | 37 #import "chrome/browser/ui/cocoa/tab_contents/favicon_util.h" |
37 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" | 38 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" |
38 #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" |
39 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" | 40 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" |
40 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" | 41 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" |
41 #import "chrome/browser/ui/cocoa/tabs/throbber_view.h" | 42 #import "chrome/browser/ui/cocoa/tabs/throbber_view.h" |
42 #import "chrome/browser/ui/cocoa/tracking_area.h" | 43 #import "chrome/browser/ui/cocoa/tracking_area.h" |
43 #include "chrome/browser/ui/find_bar/find_bar.h" | 44 #include "chrome/browser/ui/find_bar/find_bar.h" |
44 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 45 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
45 #include "chrome/browser/ui/title_prefix_matcher.h" | 46 #include "chrome/browser/ui/title_prefix_matcher.h" |
46 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 47 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 48 #include "chrome/browser/ui/tabs/tab_menu_model.h" |
47 #include "chrome/common/chrome_switches.h" | 49 #include "chrome/common/chrome_switches.h" |
48 #include "chrome/common/pref_names.h" | 50 #include "chrome/common/pref_names.h" |
49 #include "content/browser/tab_contents/navigation_controller.h" | 51 #include "content/browser/tab_contents/navigation_controller.h" |
50 #include "content/browser/tab_contents/navigation_entry.h" | 52 #include "content/browser/tab_contents/navigation_entry.h" |
51 #include "content/browser/tab_contents/tab_contents.h" | 53 #include "content/browser/tab_contents/tab_contents.h" |
52 #include "content/browser/tab_contents/tab_contents_view.h" | 54 #include "content/browser/tab_contents/tab_contents_view.h" |
53 #include "content/common/notification_service.h" | 55 #include "content/common/notification_service.h" |
54 #include "grit/app_resources.h" | 56 #include "grit/app_resources.h" |
55 #include "grit/generated_resources.h" | 57 #include "grit/generated_resources.h" |
56 #include "grit/theme_resources.h" | 58 #include "grit/theme_resources.h" |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 const TabContentsWrapper* selection = | 464 const TabContentsWrapper* selection = |
463 tabStripModel_->GetSelectedTabContents(); | 465 tabStripModel_->GetSelectedTabContents(); |
464 for (int i = 0; i < existingTabCount; ++i) { | 466 for (int i = 0; i < existingTabCount; ++i) { |
465 TabContentsWrapper* currentContents = tabStripModel_->GetTabContentsAt(i); | 467 TabContentsWrapper* currentContents = tabStripModel_->GetTabContentsAt(i); |
466 [self insertTabWithContents:currentContents | 468 [self insertTabWithContents:currentContents |
467 atIndex:i | 469 atIndex:i |
468 inForeground:NO]; | 470 inForeground:NO]; |
469 if (selection == currentContents) { | 471 if (selection == currentContents) { |
470 // Must manually force a selection since the model won't send | 472 // Must manually force a selection since the model won't send |
471 // selection messages in this scenario. | 473 // selection messages in this scenario. |
472 [self selectTabWithContents:currentContents | 474 [self activateTabWithContents:currentContents |
473 previousContents:NULL | 475 previousContents:NULL |
474 atIndex:i | 476 atIndex:i |
475 userGesture:NO]; | 477 userGesture:NO]; |
476 } | 478 } |
477 } | 479 } |
478 // Don't lay out the tabs until after the controller has been fully | 480 // Don't lay out the tabs until after the controller has been fully |
479 // constructed. The |verticalLayout_| flag has not been initialized by | 481 // constructed. The |verticalLayout_| flag has not been initialized by |
480 // subclasses at this point, which would cause layout to potentially use | 482 // subclasses at this point, which would cause layout to potentially use |
481 // the wrong mode. | 483 // the wrong mode. |
482 if (existingTabCount) { | 484 if (existingTabCount) { |
483 [self performSelectorOnMainThread:@selector(layoutTabs) | 485 [self performSelectorOnMainThread:@selector(layoutTabs) |
484 withObject:nil | 486 withObject:nil |
485 waitUntilDone:NO]; | 487 waitUntilDone:NO]; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 // ensureContentsVisible (see below) sets content size and autoresizing | 546 // ensureContentsVisible (see below) sets content size and autoresizing |
545 // properties. | 547 // properties. |
546 [newView setFrame:[oldView frame]]; | 548 [newView setFrame:[oldView frame]]; |
547 [switchView_ replaceSubview:oldView with:newView]; | 549 [switchView_ replaceSubview:oldView with:newView]; |
548 } else { | 550 } else { |
549 [newView setFrame:[switchView_ bounds]]; | 551 [newView setFrame:[switchView_ bounds]]; |
550 [switchView_ addSubview:newView]; | 552 [switchView_ addSubview:newView]; |
551 } | 553 } |
552 | 554 |
553 // New content is in place, delegate should adjust itself accordingly. | 555 // New content is in place, delegate should adjust itself accordingly. |
554 [delegate_ onSelectTabWithContents:[controller tabContents]]; | 556 [delegate_ onActivateTabWithContents:[controller tabContents]]; |
555 | 557 |
556 // It also restores content autoresizing properties. | 558 // It also restores content autoresizing properties. |
557 [controller ensureContentsVisible]; | 559 [controller ensureContentsVisible]; |
558 | 560 |
559 // Tell per-tab sheet manager about currently selected tab. | 561 // Tell per-tab sheet manager about currently selected tab. |
560 if (sheetController_.get()) { | 562 if (sheetController_.get()) { |
561 [sheetController_ setActiveView:newView]; | 563 [sheetController_ setActiveView:newView]; |
562 } | 564 } |
563 | 565 |
564 // Make sure the new tabs's sheets are visible (necessary when a background | 566 // Make sure the new tabs's sheets are visible (necessary when a background |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 DCHECK_GE(number, 0); | 617 DCHECK_GE(number, 0); |
616 return number; | 618 return number; |
617 } | 619 } |
618 | 620 |
619 // Given an index into the tab model, returns the index into the tab controller | 621 // Given an index into the tab model, returns the index into the tab controller |
620 // or tab contents controller array accounting for tabs that are currently | 622 // or tab contents controller array accounting for tabs that are currently |
621 // closing. For example, if there are two tabs in the process of closing before | 623 // closing. For example, if there are two tabs in the process of closing before |
622 // |index|, this returns |index| + 2. If there are no closing tabs, this will | 624 // |index|, this returns |index| + 2. If there are no closing tabs, this will |
623 // return |index|. | 625 // return |index|. |
624 - (NSInteger)indexFromModelIndex:(NSInteger)index { | 626 - (NSInteger)indexFromModelIndex:(NSInteger)index { |
625 DCHECK(index >= 0); | 627 DCHECK_GE(index, 0); |
626 if (index < 0) | 628 if (index < 0) |
627 return index; | 629 return index; |
628 | 630 |
629 NSInteger i = 0; | 631 NSInteger i = 0; |
630 for (TabController* controller in tabArray_.get()) { | 632 for (TabController* controller in tabArray_.get()) { |
631 if ([closingControllers_ containsObject:controller]) { | 633 if ([closingControllers_ containsObject:controller]) { |
632 DCHECK([(TabView*)[controller view] isClosing]); | 634 DCHECK([(TabView*)[controller view] isClosing]); |
633 ++index; | 635 ++index; |
634 } | 636 } |
635 if (i == index) // No need to check anything after, it has no effect. | 637 if (i == index) // No need to check anything after, it has no effect. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 | 692 |
691 - (NSUInteger)viewsCount { | 693 - (NSUInteger)viewsCount { |
692 return [tabArray_ count]; | 694 return [tabArray_ count]; |
693 } | 695 } |
694 | 696 |
695 // Called when the user clicks a tab. Tell the model the selection has changed, | 697 // Called when the user clicks a tab. Tell the model the selection has changed, |
696 // which feeds back into us via a notification. | 698 // which feeds back into us via a notification. |
697 - (void)selectTab:(id)sender { | 699 - (void)selectTab:(id)sender { |
698 DCHECK([sender isKindOfClass:[NSView class]]); | 700 DCHECK([sender isKindOfClass:[NSView class]]); |
699 int index = [self modelIndexForTabView:sender]; | 701 int index = [self modelIndexForTabView:sender]; |
700 if (tabStripModel_->ContainsIndex(index)) | 702 NSUInteger modifiers = [[NSApp currentEvent] modifierFlags]; |
701 tabStripModel_->ActivateTabAt(index, true); | 703 if (tabStripModel_->ContainsIndex(index)) { |
| 704 if (modifiers & NSCommandKeyMask && modifiers & NSShiftKeyMask) { |
| 705 tabStripModel_->AddSelectionFromAnchorTo(index); |
| 706 } else if (modifiers & NSShiftKeyMask) { |
| 707 tabStripModel_->ExtendSelectionTo(index); |
| 708 } else if (modifiers & NSCommandKeyMask) { |
| 709 tabStripModel_->ToggleSelectionAt(index); |
| 710 } else if (!tabStripModel_->IsTabSelected(index)) { |
| 711 tabStripModel_->ActivateTabAt(index, true); |
| 712 } |
| 713 } |
702 } | 714 } |
703 | 715 |
704 // Called when the user closes a tab. Asks the model to close the tab. |sender| | 716 // Called when the user closes a tab. Asks the model to close the tab. |sender| |
705 // is the TabView that is potentially going away. | 717 // is the TabView that is potentially going away. |
706 - (void)closeTab:(id)sender { | 718 - (void)closeTab:(id)sender { |
707 DCHECK([sender isKindOfClass:[TabView class]]); | 719 DCHECK([sender isKindOfClass:[TabView class]]); |
708 if ([hoveredTab_ isEqual:sender]) { | 720 if ([hoveredTab_ isEqual:sender]) { |
709 hoveredTab_ = nil; | 721 hoveredTab_ = nil; |
710 } | 722 } |
711 | 723 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 // Returns YES if the specificed command should be enabled for the given | 776 // Returns YES if the specificed command should be enabled for the given |
765 // controller. | 777 // controller. |
766 - (BOOL)isCommandEnabled:(TabStripModel::ContextMenuCommand)command | 778 - (BOOL)isCommandEnabled:(TabStripModel::ContextMenuCommand)command |
767 forController:(TabController*)controller { | 779 forController:(TabController*)controller { |
768 int index = [self modelIndexForTabView:[controller view]]; | 780 int index = [self modelIndexForTabView:[controller view]]; |
769 if (!tabStripModel_->ContainsIndex(index)) | 781 if (!tabStripModel_->ContainsIndex(index)) |
770 return NO; | 782 return NO; |
771 return tabStripModel_->IsContextMenuCommandEnabled(index, command) ? YES : NO; | 783 return tabStripModel_->IsContextMenuCommandEnabled(index, command) ? YES : NO; |
772 } | 784 } |
773 | 785 |
| 786 // Returns a context menu model for a given controller. Caller owns the result. |
| 787 - (ui::SimpleMenuModel*)contextMenuModelForController:(TabController*)controller |
| 788 menuDelegate:(ui::SimpleMenuModel::Delegate*)delegate { |
| 789 int index = [self modelIndexForTabView:[controller view]]; |
| 790 return new TabMenuModel(delegate, tabStripModel_, index); |
| 791 } |
| 792 |
774 - (void)insertPlaceholderForTab:(TabView*)tab | 793 - (void)insertPlaceholderForTab:(TabView*)tab |
775 frame:(NSRect)frame | 794 frame:(NSRect)frame |
776 yStretchiness:(CGFloat)yStretchiness { | 795 yStretchiness:(CGFloat)yStretchiness { |
777 placeholderTab_ = tab; | 796 placeholderTab_ = tab; |
778 placeholderFrame_ = frame; | 797 placeholderFrame_ = frame; |
779 placeholderStretchiness_ = yStretchiness; | 798 placeholderStretchiness_ = yStretchiness; |
780 [self layoutTabsWithAnimation:initialLayoutComplete_ regenerateSubviews:NO]; | 799 [self layoutTabsWithAnimation:initialLayoutComplete_ regenerateSubviews:NO]; |
781 } | 800 } |
782 | 801 |
783 - (BOOL)isDragSessionActive { | 802 - (BOOL)isDragSessionActive { |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1152 [self updateCommonTitlePrefix]; | 1171 [self updateCommonTitlePrefix]; |
1153 | 1172 |
1154 // Send a broadcast that the number of tabs have changed. | 1173 // Send a broadcast that the number of tabs have changed. |
1155 [[NSNotificationCenter defaultCenter] | 1174 [[NSNotificationCenter defaultCenter] |
1156 postNotificationName:kTabStripNumberOfTabsChanged | 1175 postNotificationName:kTabStripNumberOfTabsChanged |
1157 object:self]; | 1176 object:self]; |
1158 } | 1177 } |
1159 | 1178 |
1160 // Called when a notification is received from the model to select a particular | 1179 // Called when a notification is received from the model to select a particular |
1161 // tab. Swaps in the toolbar and content area associated with |newContents|. | 1180 // tab. Swaps in the toolbar and content area associated with |newContents|. |
1162 - (void)selectTabWithContents:(TabContentsWrapper*)newContents | 1181 - (void)activateTabWithContents:(TabContentsWrapper*)newContents |
1163 previousContents:(TabContentsWrapper*)oldContents | 1182 previousContents:(TabContentsWrapper*)oldContents |
1164 atIndex:(NSInteger)modelIndex | 1183 atIndex:(NSInteger)modelIndex |
1165 userGesture:(bool)wasUserGesture { | 1184 userGesture:(bool)wasUserGesture { |
1166 // Take closing tabs into account. | 1185 // Take closing tabs into account. |
1167 NSInteger index = [self indexFromModelIndex:modelIndex]; | 1186 NSInteger activeIndex = [self indexFromModelIndex:modelIndex]; |
1168 | 1187 |
1169 if (oldContents && oldContents != newContents) { | 1188 if (oldContents && oldContents != newContents) { |
1170 int oldModelIndex = | 1189 int oldModelIndex = |
1171 browser_->GetIndexOfController(&(oldContents->controller())); | 1190 browser_->GetIndexOfController(&(oldContents->controller())); |
1172 if (oldModelIndex != -1) { // When closing a tab, the old tab may be gone. | 1191 if (oldModelIndex != -1) { // When closing a tab, the old tab may be gone. |
1173 NSInteger oldIndex = [self indexFromModelIndex:oldModelIndex]; | 1192 NSInteger oldIndex = [self indexFromModelIndex:oldModelIndex]; |
1174 TabContentsController* oldController = | 1193 TabContentsController* oldController = |
1175 [tabContentsArray_ objectAtIndex:oldIndex]; | 1194 [tabContentsArray_ objectAtIndex:oldIndex]; |
1176 [oldController willBecomeUnselectedTab]; | 1195 [oldController willBecomeUnselectedTab]; |
1177 oldContents->view()->StoreFocus(); | 1196 oldContents->view()->StoreFocus(); |
1178 oldContents->tab_contents()->WasHidden(); | 1197 oldContents->tab_contents()->WasHidden(); |
1179 } | 1198 } |
1180 } | 1199 } |
1181 | 1200 |
1182 // De-select all other tabs and select the new tab. | 1201 // First get the vector of indices, which is allays sorted in ascending order. |
| 1202 TabStripSelectionModel::SelectedIndices selection( |
| 1203 tabStripModel_->selection_model().selected_indices()); |
| 1204 // Iterate through all of the tabs, selecting each as necessary. |
| 1205 TabStripSelectionModel::SelectedIndices::iterator iter = selection.begin(); |
1183 int i = 0; | 1206 int i = 0; |
1184 for (TabController* current in tabArray_.get()) { | 1207 for (TabController* current in tabArray_.get()) { |
1185 [current setSelected:(i == index) ? YES : NO]; | 1208 BOOL selected = iter != selection.end() && |
| 1209 [self indexFromModelIndex:*iter] == i; |
| 1210 [current setSelected:selected]; |
| 1211 [current setActive:i == activeIndex]; |
| 1212 if (selected) |
| 1213 ++iter; |
1186 ++i; | 1214 ++i; |
1187 } | 1215 } |
1188 | 1216 |
1189 // Tell the new tab contents it is about to become the selected tab. Here it | 1217 // Tell the new tab contents it is about to become the selected tab. Here it |
1190 // can do things like make sure the toolbar is up to date. | 1218 // can do things like make sure the toolbar is up to date. |
1191 TabContentsController* newController = | 1219 TabContentsController* newController = |
1192 [tabContentsArray_ objectAtIndex:index]; | 1220 [tabContentsArray_ objectAtIndex:activeIndex]; |
1193 [newController willBecomeSelectedTab]; | 1221 [newController willBecomeSelectedTab]; |
1194 | 1222 |
1195 // Relayout for new tabs and to let the selected tab grow to be larger in | 1223 // Relayout for new tabs and to let the selected tab grow to be larger in |
1196 // size than surrounding tabs if the user has many. This also raises the | 1224 // size than surrounding tabs if the user has many. This also raises the |
1197 // selected tab to the top. | 1225 // selected tab to the top. |
1198 [self layoutTabs]; | 1226 [self layoutTabs]; |
1199 | 1227 |
1200 // Swap in the contents for the new tab. | 1228 // Swap in the contents for the new tab. |
1201 [self swapInTabAtIndex:modelIndex]; | 1229 [self swapInTabAtIndex:modelIndex]; |
1202 | 1230 |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1443 // Called when a notification is received from the model that the given tab | 1471 // Called when a notification is received from the model that the given tab |
1444 // has been updated. |loading| will be YES when we only want to update the | 1472 // has been updated. |loading| will be YES when we only want to update the |
1445 // throbber state, not anything else about the (partially) loading tab. | 1473 // throbber state, not anything else about the (partially) loading tab. |
1446 - (void)tabChangedWithContents:(TabContentsWrapper*)contents | 1474 - (void)tabChangedWithContents:(TabContentsWrapper*)contents |
1447 atIndex:(NSInteger)modelIndex | 1475 atIndex:(NSInteger)modelIndex |
1448 changeType:(TabStripModelObserver::TabChangeType)change { | 1476 changeType:(TabStripModelObserver::TabChangeType)change { |
1449 // Take closing tabs into account. | 1477 // Take closing tabs into account. |
1450 NSInteger index = [self indexFromModelIndex:modelIndex]; | 1478 NSInteger index = [self indexFromModelIndex:modelIndex]; |
1451 | 1479 |
1452 if (modelIndex == tabStripModel_->active_index()) | 1480 if (modelIndex == tabStripModel_->active_index()) |
1453 [delegate_ onSelectedTabChange:change]; | 1481 [delegate_ onTabChanged:change withContents:contents->tab_contents()]; |
1454 | 1482 |
1455 if (change == TabStripModelObserver::TITLE_NOT_LOADING) { | 1483 if (change == TabStripModelObserver::TITLE_NOT_LOADING) { |
1456 // TODO(sky): make this work. | 1484 // TODO(sky): make this work. |
1457 // We'll receive another notification of the change asynchronously. | 1485 // We'll receive another notification of the change asynchronously. |
1458 return; | 1486 return; |
1459 } | 1487 } |
1460 | 1488 |
1461 TabController* tabController = [tabArray_ objectAtIndex:index]; | 1489 TabController* tabController = [tabArray_ objectAtIndex:index]; |
1462 | 1490 |
1463 if (change != TabStripModelObserver::LOADING_ONLY) | 1491 if (change != TabStripModelObserver::LOADING_ONLY) |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1519 [tabController setUrl:contents->tab_contents()->GetURL()]; | 1547 [tabController setUrl:contents->tab_contents()->GetURL()]; |
1520 [self updateFaviconForContents:contents->tab_contents() atIndex:modelIndex]; | 1548 [self updateFaviconForContents:contents->tab_contents() atIndex:modelIndex]; |
1521 // If the tab is being restored and it's pinned, the mini state is set after | 1549 // If the tab is being restored and it's pinned, the mini state is set after |
1522 // the tab has already been rendered, so re-layout the tabstrip. In all other | 1550 // the tab has already been rendered, so re-layout the tabstrip. In all other |
1523 // cases, the state is set before the tab is rendered so this isn't needed. | 1551 // cases, the state is set before the tab is rendered so this isn't needed. |
1524 [self layoutTabs]; | 1552 [self layoutTabs]; |
1525 | 1553 |
1526 [self updateCommonTitlePrefix]; | 1554 [self updateCommonTitlePrefix]; |
1527 } | 1555 } |
1528 | 1556 |
1529 - (void)setFrameOfSelectedTab:(NSRect)frame { | 1557 - (void)setFrameOfActiveTab:(NSRect)frame { |
1530 NSView* view = [self selectedTabView]; | 1558 NSView* view = [self activeTabView]; |
1531 NSValue* identifier = [NSValue valueWithPointer:view]; | 1559 NSValue* identifier = [NSValue valueWithPointer:view]; |
1532 [targetFrames_ setObject:[NSValue valueWithRect:frame] | 1560 [targetFrames_ setObject:[NSValue valueWithRect:frame] |
1533 forKey:identifier]; | 1561 forKey:identifier]; |
1534 [view setFrame:frame]; | 1562 [view setFrame:frame]; |
1535 } | 1563 } |
1536 | 1564 |
1537 - (NSView*)selectedTabView { | 1565 - (NSView*)activeTabView { |
1538 int selectedIndex = tabStripModel_->active_index(); | 1566 int activeIndex = tabStripModel_->active_index(); |
1539 // Take closing tabs into account. They can't ever be selected. | 1567 // Take closing tabs into account. They can't ever be selected. |
1540 selectedIndex = [self indexFromModelIndex:selectedIndex]; | 1568 activeIndex = [self indexFromModelIndex:activeIndex]; |
1541 return [self viewAtIndex:selectedIndex]; | 1569 return [self viewAtIndex:activeIndex]; |
1542 } | 1570 } |
1543 | 1571 |
1544 // Find the model index based on the x coordinate of the placeholder. If there | 1572 // Find the model index based on the x coordinate of the placeholder. If there |
1545 // is no placeholder, this returns the end of the tab strip. Closing tabs are | 1573 // is no placeholder, this returns the end of the tab strip. Closing tabs are |
1546 // not considered in computing the index. | 1574 // not considered in computing the index. |
1547 - (int)indexOfPlaceholder { | 1575 - (int)indexOfPlaceholder { |
1548 double placeholderX = placeholderFrame_.origin.x; | 1576 double placeholderX = placeholderFrame_.origin.x; |
1549 int index = 0; | 1577 int index = 0; |
1550 int location = 0; | 1578 int location = 0; |
1551 // Use |tabArray_| here instead of the tab strip count in order to get the | 1579 // Use |tabArray_| here instead of the tab strip count in order to get the |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1756 // |-regenerateSubviewList| to actually add it). | 1784 // |-regenerateSubviewList| to actually add it). |
1757 - (void)regenerateSubviewList { | 1785 - (void)regenerateSubviewList { |
1758 // Remove self as an observer from all the old tabs before a new set of | 1786 // Remove self as an observer from all the old tabs before a new set of |
1759 // potentially different tabs is put in place. | 1787 // potentially different tabs is put in place. |
1760 [self setTabTrackingAreasEnabled:NO]; | 1788 [self setTabTrackingAreasEnabled:NO]; |
1761 | 1789 |
1762 // Subviews to put in (in bottom-to-top order), beginning with the permanent | 1790 // Subviews to put in (in bottom-to-top order), beginning with the permanent |
1763 // ones. | 1791 // ones. |
1764 NSMutableArray* subviews = [NSMutableArray arrayWithArray:permanentSubviews_]; | 1792 NSMutableArray* subviews = [NSMutableArray arrayWithArray:permanentSubviews_]; |
1765 | 1793 |
1766 NSView* selectedTabView = nil; | 1794 NSView* activeTabView = nil; |
1767 // Go through tabs in reverse order, since |subviews| is bottom-to-top. | 1795 // Go through tabs in reverse order, since |subviews| is bottom-to-top. |
1768 for (TabController* tab in [tabArray_ reverseObjectEnumerator]) { | 1796 for (TabController* tab in [tabArray_ reverseObjectEnumerator]) { |
1769 NSView* tabView = [tab view]; | 1797 NSView* tabView = [tab view]; |
1770 if ([tab selected]) { | 1798 if ([tab active]) { |
1771 DCHECK(!selectedTabView); | 1799 DCHECK(!activeTabView); |
1772 selectedTabView = tabView; | 1800 activeTabView = tabView; |
1773 } else { | 1801 } else { |
1774 [subviews addObject:tabView]; | 1802 [subviews addObject:tabView]; |
1775 } | 1803 } |
1776 } | 1804 } |
1777 if (selectedTabView) { | 1805 if (activeTabView) { |
1778 [subviews addObject:selectedTabView]; | 1806 [subviews addObject:activeTabView]; |
1779 } | 1807 } |
1780 [tabStripView_ setSubviews:subviews]; | 1808 [tabStripView_ setSubviews:subviews]; |
1781 [self setTabTrackingAreasEnabled:mouseInside_]; | 1809 [self setTabTrackingAreasEnabled:mouseInside_]; |
1782 } | 1810 } |
1783 | 1811 |
1784 // Get the index and disposition for a potential URL(s) drop given a point (in | 1812 // Get the index and disposition for a potential URL(s) drop given a point (in |
1785 // the |TabStripView|'s coordinates). It considers only the x-coordinate of the | 1813 // the |TabStripView|'s coordinates). It considers only the x-coordinate of the |
1786 // given point. If it's in the "middle" of a tab, it drops on that tab. If it's | 1814 // given point. If it's in the "middle" of a tab, it drops on that tab. If it's |
1787 // to the left, it inserts to the left, and similarly for the right. | 1815 // to the left, it inserts to the left, and similarly for the right. |
1788 - (void)droppingURLsAt:(NSPoint)point | 1816 - (void)droppingURLsAt:(NSPoint)point |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2103 } | 2131 } |
2104 | 2132 |
2105 NSString* menuTitle = | 2133 NSString* menuTitle = |
2106 l10n_util::GetNSStringWithFixup(IDS_PROFILES_CREATE_NEW_PROFILE_OPTION); | 2134 l10n_util::GetNSStringWithFixup(IDS_PROFILES_CREATE_NEW_PROFILE_OPTION); |
2107 [menu addItemWithTitle:menuTitle | 2135 [menu addItemWithTitle:menuTitle |
2108 action:NULL | 2136 action:NULL |
2109 keyEquivalent:@""]; | 2137 keyEquivalent:@""]; |
2110 } | 2138 } |
2111 | 2139 |
2112 @end | 2140 @end |
OLD | NEW |