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> |
(...skipping 29 matching lines...) Expand all Loading... |
40 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" | 40 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" |
41 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" | 41 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" |
42 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" | 42 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" |
43 #import "chrome/browser/ui/cocoa/tabs/throbber_view.h" | 43 #import "chrome/browser/ui/cocoa/tabs/throbber_view.h" |
44 #import "chrome/browser/ui/cocoa/tracking_area.h" | 44 #import "chrome/browser/ui/cocoa/tracking_area.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_wrapper.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/title_prefix_matcher.h" | |
51 #include "chrome/common/chrome_switches.h" | 50 #include "chrome/common/chrome_switches.h" |
52 #include "chrome/common/pref_names.h" | 51 #include "chrome/common/pref_names.h" |
53 #include "content/browser/tab_contents/navigation_controller.h" | 52 #include "content/browser/tab_contents/navigation_controller.h" |
54 #include "content/browser/tab_contents/navigation_entry.h" | 53 #include "content/browser/tab_contents/navigation_entry.h" |
55 #include "content/browser/tab_contents/tab_contents.h" | 54 #include "content/browser/tab_contents/tab_contents.h" |
56 #include "content/browser/tab_contents/tab_contents_view.h" | 55 #include "content/browser/tab_contents/tab_contents_view.h" |
57 #include "content/browser/user_metrics.h" | 56 #include "content/browser/user_metrics.h" |
58 #include "content/common/notification_service.h" | 57 #include "content/common/notification_service.h" |
59 #include "grit/app_resources.h" | 58 #include "grit/app_resources.h" |
60 #include "grit/generated_resources.h" | 59 #include "grit/generated_resources.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 - (NSInteger)indexFromModelIndex:(NSInteger)index; | 164 - (NSInteger)indexFromModelIndex:(NSInteger)index; |
166 - (NSInteger)numberOfOpenTabs; | 165 - (NSInteger)numberOfOpenTabs; |
167 - (NSInteger)numberOfOpenMiniTabs; | 166 - (NSInteger)numberOfOpenMiniTabs; |
168 - (NSInteger)numberOfOpenNonMiniTabs; | 167 - (NSInteger)numberOfOpenNonMiniTabs; |
169 - (void)mouseMoved:(NSEvent*)event; | 168 - (void)mouseMoved:(NSEvent*)event; |
170 - (void)setTabTrackingAreasEnabled:(BOOL)enabled; | 169 - (void)setTabTrackingAreasEnabled:(BOOL)enabled; |
171 - (void)droppingURLsAt:(NSPoint)point | 170 - (void)droppingURLsAt:(NSPoint)point |
172 givesIndex:(NSInteger*)index | 171 givesIndex:(NSInteger*)index |
173 disposition:(WindowOpenDisposition*)disposition; | 172 disposition:(WindowOpenDisposition*)disposition; |
174 - (void)setNewTabButtonHoverState:(BOOL)showHover; | 173 - (void)setNewTabButtonHoverState:(BOOL)showHover; |
175 - (void)updateCommonTitlePrefix; | |
176 - (BOOL)shouldShowProfileMenuButton; | 174 - (BOOL)shouldShowProfileMenuButton; |
177 - (void)updateProfileMenuButton; | 175 - (void)updateProfileMenuButton; |
178 @end | 176 @end |
179 | 177 |
180 // A simple view class that prevents the Window Server from dragging the area | 178 // A simple view class that prevents the Window Server from dragging the area |
181 // behind tabs. Sometimes core animation confuses it. Unfortunately, it can also | 179 // behind tabs. Sometimes core animation confuses it. Unfortunately, it can also |
182 // falsely pick up clicks during rapid tab closure, so we have to account for | 180 // falsely pick up clicks during rapid tab closure, so we have to account for |
183 // that. | 181 // that. |
184 @interface TabStripControllerDragBlockingView : NSView { | 182 @interface TabStripControllerDragBlockingView : NSView { |
185 TabStripController* controller_; // weak; owns us | 183 TabStripController* controller_; // weak; owns us |
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1187 [self layoutTabs]; | 1185 [self layoutTabs]; |
1188 } | 1186 } |
1189 | 1187 |
1190 // During normal loading, we won't yet have a favicon and we'll get | 1188 // During normal loading, we won't yet have a favicon and we'll get |
1191 // subsequent state change notifications to show the throbber, but when we're | 1189 // subsequent state change notifications to show the throbber, but when we're |
1192 // dragging a tab out into a new window, we have to put the tab's favicon | 1190 // dragging a tab out into a new window, we have to put the tab's favicon |
1193 // into the right state up front as we won't be told to do it from anywhere | 1191 // into the right state up front as we won't be told to do it from anywhere |
1194 // else. | 1192 // else. |
1195 [self updateFaviconForContents:contents atIndex:modelIndex]; | 1193 [self updateFaviconForContents:contents atIndex:modelIndex]; |
1196 | 1194 |
1197 [self updateCommonTitlePrefix]; | |
1198 | |
1199 // Send a broadcast that the number of tabs have changed. | 1195 // Send a broadcast that the number of tabs have changed. |
1200 [[NSNotificationCenter defaultCenter] | 1196 [[NSNotificationCenter defaultCenter] |
1201 postNotificationName:kTabStripNumberOfTabsChanged | 1197 postNotificationName:kTabStripNumberOfTabsChanged |
1202 object:self]; | 1198 object:self]; |
1203 } | 1199 } |
1204 | 1200 |
1205 // Called when a notification is received from the model to select a particular | 1201 // Called when a notification is received from the model to select a particular |
1206 // tab. Swaps in the toolbar and content area associated with |newContents|. | 1202 // tab. Swaps in the toolbar and content area associated with |newContents|. |
1207 - (void)activateTabWithContents:(TabContentsWrapper*)newContents | 1203 - (void)activateTabWithContents:(TabContentsWrapper*)newContents |
1208 previousContents:(TabContentsWrapper*)oldContents | 1204 previousContents:(TabContentsWrapper*)oldContents |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1320 [controller setTarget:nil]; | 1316 [controller setTarget:nil]; |
1321 | 1317 |
1322 if ([hoveredTab_ isEqual:tab]) | 1318 if ([hoveredTab_ isEqual:tab]) |
1323 hoveredTab_ = nil; | 1319 hoveredTab_ = nil; |
1324 | 1320 |
1325 NSValue* identifier = [NSValue valueWithPointer:tab]; | 1321 NSValue* identifier = [NSValue valueWithPointer:tab]; |
1326 [targetFrames_ removeObjectForKey:identifier]; | 1322 [targetFrames_ removeObjectForKey:identifier]; |
1327 | 1323 |
1328 // Once we're totally done with the tab, delete its controller | 1324 // Once we're totally done with the tab, delete its controller |
1329 [tabArray_ removeObjectAtIndex:index]; | 1325 [tabArray_ removeObjectAtIndex:index]; |
1330 | |
1331 [self updateCommonTitlePrefix]; | |
1332 } | 1326 } |
1333 | 1327 |
1334 // Called by the CAAnimation delegate when the tab completes the closing | 1328 // Called by the CAAnimation delegate when the tab completes the closing |
1335 // animation. | 1329 // animation. |
1336 - (void)animationDidStopForController:(TabController*)controller | 1330 - (void)animationDidStopForController:(TabController*)controller |
1337 finished:(BOOL)finished { | 1331 finished:(BOOL)finished { |
1338 [closingControllers_ removeObject:controller]; | 1332 [closingControllers_ removeObject:controller]; |
1339 [self removeTab:controller]; | 1333 [self removeTab:controller]; |
1340 } | 1334 } |
1341 | 1335 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1523 TabController* tabController = [tabArray_ objectAtIndex:index]; | 1517 TabController* tabController = [tabArray_ objectAtIndex:index]; |
1524 | 1518 |
1525 if (change != TabStripModelObserver::LOADING_ONLY) | 1519 if (change != TabStripModelObserver::LOADING_ONLY) |
1526 [self setTabTitle:tabController withContents:contents->tab_contents()]; | 1520 [self setTabTitle:tabController withContents:contents->tab_contents()]; |
1527 | 1521 |
1528 [self updateFaviconForContents:contents atIndex:modelIndex]; | 1522 [self updateFaviconForContents:contents atIndex:modelIndex]; |
1529 | 1523 |
1530 TabContentsController* updatedController = | 1524 TabContentsController* updatedController = |
1531 [tabContentsArray_ objectAtIndex:index]; | 1525 [tabContentsArray_ objectAtIndex:index]; |
1532 [updatedController tabDidChange:contents->tab_contents()]; | 1526 [updatedController tabDidChange:contents->tab_contents()]; |
1533 | |
1534 [self updateCommonTitlePrefix]; | |
1535 } | 1527 } |
1536 | 1528 |
1537 // Called when a tab is moved (usually by drag&drop). Keep our parallel arrays | 1529 // Called when a tab is moved (usually by drag&drop). Keep our parallel arrays |
1538 // in sync with the tab strip model. It can also be pinned/unpinned | 1530 // in sync with the tab strip model. It can also be pinned/unpinned |
1539 // simultaneously, so we need to take care of that. | 1531 // simultaneously, so we need to take care of that. |
1540 - (void)tabMovedWithContents:(TabContentsWrapper*)contents | 1532 - (void)tabMovedWithContents:(TabContentsWrapper*)contents |
1541 fromIndex:(NSInteger)modelFrom | 1533 fromIndex:(NSInteger)modelFrom |
1542 toIndex:(NSInteger)modelTo { | 1534 toIndex:(NSInteger)modelTo { |
1543 // Take closing tabs into account. | 1535 // Take closing tabs into account. |
1544 NSInteger from = [self indexFromModelIndex:modelFrom]; | 1536 NSInteger from = [self indexFromModelIndex:modelFrom]; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1580 | 1572 |
1581 [tabController setMini:tabStripModel_->IsMiniTab(modelIndex)]; | 1573 [tabController setMini:tabStripModel_->IsMiniTab(modelIndex)]; |
1582 [tabController setPinned:tabStripModel_->IsTabPinned(modelIndex)]; | 1574 [tabController setPinned:tabStripModel_->IsTabPinned(modelIndex)]; |
1583 [tabController setApp:tabStripModel_->IsAppTab(modelIndex)]; | 1575 [tabController setApp:tabStripModel_->IsAppTab(modelIndex)]; |
1584 [tabController setUrl:contents->tab_contents()->GetURL()]; | 1576 [tabController setUrl:contents->tab_contents()->GetURL()]; |
1585 [self updateFaviconForContents:contents atIndex:modelIndex]; | 1577 [self updateFaviconForContents:contents atIndex:modelIndex]; |
1586 // If the tab is being restored and it's pinned, the mini state is set after | 1578 // If the tab is being restored and it's pinned, the mini state is set after |
1587 // the tab has already been rendered, so re-layout the tabstrip. In all other | 1579 // the tab has already been rendered, so re-layout the tabstrip. In all other |
1588 // cases, the state is set before the tab is rendered so this isn't needed. | 1580 // cases, the state is set before the tab is rendered so this isn't needed. |
1589 [self layoutTabs]; | 1581 [self layoutTabs]; |
1590 | |
1591 [self updateCommonTitlePrefix]; | |
1592 } | 1582 } |
1593 | 1583 |
1594 - (void)setFrameOfActiveTab:(NSRect)frame { | 1584 - (void)setFrameOfActiveTab:(NSRect)frame { |
1595 NSView* view = [self activeTabView]; | 1585 NSView* view = [self activeTabView]; |
1596 NSValue* identifier = [NSValue valueWithPointer:view]; | 1586 NSValue* identifier = [NSValue valueWithPointer:view]; |
1597 [targetFrames_ setObject:[NSValue valueWithRect:frame] | 1587 [targetFrames_ setObject:[NSValue valueWithRect:frame] |
1598 forKey:identifier]; | 1588 forKey:identifier]; |
1599 [view setFrame:frame]; | 1589 [view setFrame:frame]; |
1600 } | 1590 } |
1601 | 1591 |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2115 NSInteger modelIndex = [self modelIndexForContentsView:tabContentsView]; | 2105 NSInteger modelIndex = [self modelIndexForContentsView:tabContentsView]; |
2116 NSInteger index = [self indexFromModelIndex:modelIndex]; | 2106 NSInteger index = [self indexFromModelIndex:modelIndex]; |
2117 BrowserWindowController* controller = | 2107 BrowserWindowController* controller = |
2118 (BrowserWindowController*)[[switchView_ window] windowController]; | 2108 (BrowserWindowController*)[[switchView_ window] windowController]; |
2119 DCHECK(index >= 0); | 2109 DCHECK(index >= 0); |
2120 if (index >= 0) { | 2110 if (index >= 0) { |
2121 [controller setTab:[self viewAtIndex:index] isDraggable:YES]; | 2111 [controller setTab:[self viewAtIndex:index] isDraggable:YES]; |
2122 } | 2112 } |
2123 } | 2113 } |
2124 | 2114 |
2125 // Update the lengths of common title prefixes for all tabs. This needs | |
2126 // to be done every time tabs are added/removed or when titles change. | |
2127 - (void)updateCommonTitlePrefix { | |
2128 DCHECK_EQ([tabArray_ count], [tabArray_ count]); | |
2129 | |
2130 std::vector<TitlePrefixMatcher::TitleInfo> tabTitleInfos; | |
2131 ScopedVector<string16> titles; | |
2132 size_t tabIndex; | |
2133 size_t tabCount = [tabArray_ count]; | |
2134 | |
2135 // Add all tab titles to |tabTitleInfos|. | |
2136 for (tabIndex = 0; tabIndex < tabCount; ++tabIndex) { | |
2137 TabController* tabController = [tabArray_ objectAtIndex:tabIndex]; | |
2138 string16 title = base::SysNSStringToUTF16([tabController title]); | |
2139 if (!title.empty() && ![tabController mini]) { | |
2140 titles.push_back(new string16(title)); | |
2141 tabTitleInfos.push_back(TitlePrefixMatcher::TitleInfo( | |
2142 titles[titles.size() - 1], [tabController url], tabIndex)); | |
2143 } | |
2144 } | |
2145 | |
2146 // Calculate the prefix length. | |
2147 TitlePrefixMatcher::CalculatePrefixLengths(&tabTitleInfos); | |
2148 | |
2149 // Update the prefix length for each tab. | |
2150 for (size_t infoIndex = 0; infoIndex < tabTitleInfos.size(); ++infoIndex) { | |
2151 tabIndex = tabTitleInfos[infoIndex].caller_value; | |
2152 DCHECK(tabIndex < [tabArray_ count]); | |
2153 TabController* tabController = [tabArray_ objectAtIndex:tabIndex]; | |
2154 [tabController setTitleCommonPrefixLength: | |
2155 tabTitleInfos[infoIndex].prefix_length]; | |
2156 } | |
2157 } | |
2158 | |
2159 - (BOOL)shouldShowProfileMenuButton { | 2115 - (BOOL)shouldShowProfileMenuButton { |
2160 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles)) | 2116 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles)) |
2161 return NO; | 2117 return NO; |
2162 if (browser_->profile()->IsOffTheRecord()) | 2118 if (browser_->profile()->IsOffTheRecord()) |
2163 return NO; | 2119 return NO; |
2164 return (!browser_->profile()->GetPrefs()->GetString( | 2120 return (!browser_->profile()->GetPrefs()->GetString( |
2165 prefs::kGoogleServicesUsername).empty()); | 2121 prefs::kGoogleServicesUsername).empty()); |
2166 } | 2122 } |
2167 | 2123 |
2168 - (void)updateProfileMenuButton { | 2124 - (void)updateProfileMenuButton { |
2169 if (![self shouldShowProfileMenuButton]) { | 2125 if (![self shouldShowProfileMenuButton]) { |
2170 [profileMenuButton_ setHidden:YES]; | 2126 [profileMenuButton_ setHidden:YES]; |
2171 return; | 2127 return; |
2172 } | 2128 } |
2173 | 2129 |
2174 std::string profileName = browser_->profile()->GetPrefs()->GetString( | 2130 std::string profileName = browser_->profile()->GetPrefs()->GetString( |
2175 prefs::kGoogleServicesUsername); | 2131 prefs::kGoogleServicesUsername); |
2176 [profileMenuButton_ setProfileDisplayName: | 2132 [profileMenuButton_ setProfileDisplayName: |
2177 [NSString stringWithUTF8String:profileName.c_str()]]; | 2133 [NSString stringWithUTF8String:profileName.c_str()]]; |
2178 [profileMenuButton_ setHidden:NO]; | 2134 [profileMenuButton_ setHidden:NO]; |
2179 } | 2135 } |
2180 | 2136 |
2181 @end | 2137 @end |
OLD | NEW |