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

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

Issue 6688050: Mac: Elides the beginning of tab titles that have common prefixes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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
« no previous file with comments | « chrome/browser/ui/cocoa/tabs/tab_controller.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 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
(...skipping 18 matching lines...) Expand all
30 #import "chrome/browser/ui/cocoa/constrained_window_mac.h" 30 #import "chrome/browser/ui/cocoa/constrained_window_mac.h"
31 #import "chrome/browser/ui/cocoa/new_tab_button.h" 31 #import "chrome/browser/ui/cocoa/new_tab_button.h"
32 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" 32 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h"
33 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" 33 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h"
34 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" 34 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
35 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" 35 #import "chrome/browser/ui/cocoa/tabs/tab_view.h"
36 #import "chrome/browser/ui/cocoa/tabs/throbber_view.h" 36 #import "chrome/browser/ui/cocoa/tabs/throbber_view.h"
37 #import "chrome/browser/ui/cocoa/tracking_area.h" 37 #import "chrome/browser/ui/cocoa/tracking_area.h"
38 #include "chrome/browser/ui/find_bar/find_bar.h" 38 #include "chrome/browser/ui/find_bar/find_bar.h"
39 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 39 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
40 #include "chrome/browser/ui/title_prefix_matcher.h"
40 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 41 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
41 #include "content/browser/tab_contents/navigation_controller.h" 42 #include "content/browser/tab_contents/navigation_controller.h"
42 #include "content/browser/tab_contents/navigation_entry.h" 43 #include "content/browser/tab_contents/navigation_entry.h"
43 #include "content/browser/tab_contents/tab_contents.h" 44 #include "content/browser/tab_contents/tab_contents.h"
44 #include "content/browser/tab_contents/tab_contents_view.h" 45 #include "content/browser/tab_contents/tab_contents_view.h"
45 #include "grit/app_resources.h" 46 #include "grit/app_resources.h"
46 #include "grit/generated_resources.h" 47 #include "grit/generated_resources.h"
47 #include "grit/theme_resources.h" 48 #include "grit/theme_resources.h"
48 #include "skia/ext/skia_utils_mac.h" 49 #include "skia/ext/skia_utils_mac.h"
49 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" 50 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 - (NSInteger)indexFromModelIndex:(NSInteger)index; 137 - (NSInteger)indexFromModelIndex:(NSInteger)index;
137 - (NSInteger)numberOfOpenTabs; 138 - (NSInteger)numberOfOpenTabs;
138 - (NSInteger)numberOfOpenMiniTabs; 139 - (NSInteger)numberOfOpenMiniTabs;
139 - (NSInteger)numberOfOpenNonMiniTabs; 140 - (NSInteger)numberOfOpenNonMiniTabs;
140 - (void)mouseMoved:(NSEvent*)event; 141 - (void)mouseMoved:(NSEvent*)event;
141 - (void)setTabTrackingAreasEnabled:(BOOL)enabled; 142 - (void)setTabTrackingAreasEnabled:(BOOL)enabled;
142 - (void)droppingURLsAt:(NSPoint)point 143 - (void)droppingURLsAt:(NSPoint)point
143 givesIndex:(NSInteger*)index 144 givesIndex:(NSInteger*)index
144 disposition:(WindowOpenDisposition*)disposition; 145 disposition:(WindowOpenDisposition*)disposition;
145 - (void)setNewTabButtonHoverState:(BOOL)showHover; 146 - (void)setNewTabButtonHoverState:(BOOL)showHover;
147 - (void)updateCommonTitlePrefix;
146 @end 148 @end
147 149
148 // A simple view class that prevents the Window Server from dragging the area 150 // A simple view class that prevents the Window Server from dragging the area
149 // behind tabs. Sometimes core animation confuses it. Unfortunately, it can also 151 // behind tabs. Sometimes core animation confuses it. Unfortunately, it can also
150 // falsely pick up clicks during rapid tab closure, so we have to account for 152 // falsely pick up clicks during rapid tab closure, so we have to account for
151 // that. 153 // that.
152 @interface TabStripControllerDragBlockingView : NSView { 154 @interface TabStripControllerDragBlockingView : NSView {
153 TabStripController* controller_; // weak; owns us 155 TabStripController* controller_; // weak; owns us
154 } 156 }
155 157
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 [self layoutTabs]; 1018 [self layoutTabs];
1017 } 1019 }
1018 1020
1019 // During normal loading, we won't yet have a favicon and we'll get 1021 // During normal loading, we won't yet have a favicon and we'll get
1020 // subsequent state change notifications to show the throbber, but when we're 1022 // subsequent state change notifications to show the throbber, but when we're
1021 // dragging a tab out into a new window, we have to put the tab's favicon 1023 // dragging a tab out into a new window, we have to put the tab's favicon
1022 // into the right state up front as we won't be told to do it from anywhere 1024 // into the right state up front as we won't be told to do it from anywhere
1023 // else. 1025 // else.
1024 [self updateFaviconForContents:contents->tab_contents() atIndex:modelIndex]; 1026 [self updateFaviconForContents:contents->tab_contents() atIndex:modelIndex];
1025 1027
1028 [self updateCommonTitlePrefix];
1029
1026 // Send a broadcast that the number of tabs have changed. 1030 // Send a broadcast that the number of tabs have changed.
1027 [[NSNotificationCenter defaultCenter] 1031 [[NSNotificationCenter defaultCenter]
1028 postNotificationName:kTabStripNumberOfTabsChanged 1032 postNotificationName:kTabStripNumberOfTabsChanged
1029 object:self]; 1033 object:self];
1030 } 1034 }
1031 1035
1032 // Called when a notification is received from the model to select a particular 1036 // Called when a notification is received from the model to select a particular
1033 // tab. Swaps in the toolbar and content area associated with |newContents|. 1037 // tab. Swaps in the toolbar and content area associated with |newContents|.
1034 - (void)selectTabWithContents:(TabContentsWrapper*)newContents 1038 - (void)selectTabWithContents:(TabContentsWrapper*)newContents
1035 previousContents:(TabContentsWrapper*)oldContents 1039 previousContents:(TabContentsWrapper*)oldContents
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 [controller setTarget:nil]; 1139 [controller setTarget:nil];
1136 1140
1137 if ([hoveredTab_ isEqual:tab]) 1141 if ([hoveredTab_ isEqual:tab])
1138 hoveredTab_ = nil; 1142 hoveredTab_ = nil;
1139 1143
1140 NSValue* identifier = [NSValue valueWithPointer:tab]; 1144 NSValue* identifier = [NSValue valueWithPointer:tab];
1141 [targetFrames_ removeObjectForKey:identifier]; 1145 [targetFrames_ removeObjectForKey:identifier];
1142 1146
1143 // Once we're totally done with the tab, delete its controller 1147 // Once we're totally done with the tab, delete its controller
1144 [tabArray_ removeObjectAtIndex:index]; 1148 [tabArray_ removeObjectAtIndex:index];
1149
1150 [self updateCommonTitlePrefix];
1145 } 1151 }
1146 1152
1147 // Called by the CAAnimation delegate when the tab completes the closing 1153 // Called by the CAAnimation delegate when the tab completes the closing
1148 // animation. 1154 // animation.
1149 - (void)animationDidStopForController:(TabController*)controller 1155 - (void)animationDidStopForController:(TabController*)controller
1150 finished:(BOOL)finished { 1156 finished:(BOOL)finished {
1151 [closingControllers_ removeObject:controller]; 1157 [closingControllers_ removeObject:controller];
1152 [self removeTab:controller]; 1158 [self removeTab:controller];
1153 } 1159 }
1154 1160
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 TabController* tabController = [tabArray_ objectAtIndex:index]; 1336 TabController* tabController = [tabArray_ objectAtIndex:index];
1331 1337
1332 if (change != TabStripModelObserver::LOADING_ONLY) 1338 if (change != TabStripModelObserver::LOADING_ONLY)
1333 [self setTabTitle:tabController withContents:contents->tab_contents()]; 1339 [self setTabTitle:tabController withContents:contents->tab_contents()];
1334 1340
1335 [self updateFaviconForContents:contents->tab_contents() atIndex:modelIndex]; 1341 [self updateFaviconForContents:contents->tab_contents() atIndex:modelIndex];
1336 1342
1337 TabContentsController* updatedController = 1343 TabContentsController* updatedController =
1338 [tabContentsArray_ objectAtIndex:index]; 1344 [tabContentsArray_ objectAtIndex:index];
1339 [updatedController tabDidChange:contents->tab_contents()]; 1345 [updatedController tabDidChange:contents->tab_contents()];
1346
1347 [self updateCommonTitlePrefix];
1340 } 1348 }
1341 1349
1342 // Called when a tab is moved (usually by drag&drop). Keep our parallel arrays 1350 // Called when a tab is moved (usually by drag&drop). Keep our parallel arrays
1343 // in sync with the tab strip model. It can also be pinned/unpinned 1351 // in sync with the tab strip model. It can also be pinned/unpinned
1344 // simultaneously, so we need to take care of that. 1352 // simultaneously, so we need to take care of that.
1345 - (void)tabMovedWithContents:(TabContentsWrapper*)contents 1353 - (void)tabMovedWithContents:(TabContentsWrapper*)contents
1346 fromIndex:(NSInteger)modelFrom 1354 fromIndex:(NSInteger)modelFrom
1347 toIndex:(NSInteger)modelTo { 1355 toIndex:(NSInteger)modelTo {
1348 // Take closing tabs into account. 1356 // Take closing tabs into account.
1349 NSInteger from = [self indexFromModelIndex:modelFrom]; 1357 NSInteger from = [self indexFromModelIndex:modelFrom];
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1381 return; 1389 return;
1382 1390
1383 [tabController setMini:tabStripModel_->IsMiniTab(modelIndex)]; 1391 [tabController setMini:tabStripModel_->IsMiniTab(modelIndex)];
1384 [tabController setPinned:tabStripModel_->IsTabPinned(modelIndex)]; 1392 [tabController setPinned:tabStripModel_->IsTabPinned(modelIndex)];
1385 [tabController setApp:tabStripModel_->IsAppTab(modelIndex)]; 1393 [tabController setApp:tabStripModel_->IsAppTab(modelIndex)];
1386 [self updateFaviconForContents:contents->tab_contents() atIndex:modelIndex]; 1394 [self updateFaviconForContents:contents->tab_contents() atIndex:modelIndex];
1387 // If the tab is being restored and it's pinned, the mini state is set after 1395 // If the tab is being restored and it's pinned, the mini state is set after
1388 // the tab has already been rendered, so re-layout the tabstrip. In all other 1396 // the tab has already been rendered, so re-layout the tabstrip. In all other
1389 // cases, the state is set before the tab is rendered so this isn't needed. 1397 // cases, the state is set before the tab is rendered so this isn't needed.
1390 [self layoutTabs]; 1398 [self layoutTabs];
1399
1400 [self updateCommonTitlePrefix];
1391 } 1401 }
1392 1402
1393 - (void)setFrameOfSelectedTab:(NSRect)frame { 1403 - (void)setFrameOfSelectedTab:(NSRect)frame {
1394 NSView* view = [self selectedTabView]; 1404 NSView* view = [self selectedTabView];
1395 NSValue* identifier = [NSValue valueWithPointer:view]; 1405 NSValue* identifier = [NSValue valueWithPointer:view];
1396 [targetFrames_ setObject:[NSValue valueWithRect:frame] 1406 [targetFrames_ setObject:[NSValue valueWithRect:frame]
1397 forKey:identifier]; 1407 forKey:identifier];
1398 [view setFrame:frame]; 1408 [view setFrame:frame];
1399 } 1409 }
1400 1410
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
1899 NSInteger modelIndex = [self modelIndexForContentsView:tabContentsView]; 1909 NSInteger modelIndex = [self modelIndexForContentsView:tabContentsView];
1900 NSInteger index = [self indexFromModelIndex:modelIndex]; 1910 NSInteger index = [self indexFromModelIndex:modelIndex];
1901 BrowserWindowController* controller = 1911 BrowserWindowController* controller =
1902 (BrowserWindowController*)[[switchView_ window] windowController]; 1912 (BrowserWindowController*)[[switchView_ window] windowController];
1903 DCHECK(index >= 0); 1913 DCHECK(index >= 0);
1904 if (index >= 0) { 1914 if (index >= 0) {
1905 [controller setTab:[self viewAtIndex:index] isDraggable:YES]; 1915 [controller setTab:[self viewAtIndex:index] isDraggable:YES];
1906 } 1916 }
1907 } 1917 }
1908 1918
1919 // Update the lengths of common title prefixes for all tabs. This needs
1920 // to be done every time tabs are added/removed or when titles change.
1921 - (void)updateCommonTitlePrefix {
1922 DCHECK_EQ([tabArray_ count], [tabArray_ count]);
1923
1924 std::vector<TitlePrefixMatcher::TitleInfo> tabTitleInfos;
1925 ScopedVector<string16> titles;
1926 size_t tabIndex;
1927 size_t tabCount = [tabArray_ count];
1928
1929 // Add all tab titles to |tabTitleInfos|.
1930 for (tabIndex = 0; tabIndex < tabCount; ++tabIndex) {
1931 TabController* tabController = [tabArray_ objectAtIndex:tabIndex];
1932 string16 title = base::SysNSStringToUTF16([tabController title]);
1933 if (!title.empty() && ![tabController mini]) {
1934 titles.push_back(new string16(title));
1935 tabTitleInfos.push_back(TitlePrefixMatcher::TitleInfo(
1936 titles[titles.size() - 1], tabIndex));
1937 }
1938 }
1939
1940 // Calculate the prefix length.
1941 TitlePrefixMatcher::CalculatePrefixLengths(&tabTitleInfos);
1942
1943 // Update the prefix length for each tab.
1944 for (size_t infoIndex = 0; infoIndex < tabTitleInfos.size(); ++infoIndex) {
1945 tabIndex = tabTitleInfos[infoIndex].caller_value;
1946 DCHECK(tabIndex < [tabArray_ count]);
1947 TabController* tabController = [tabArray_ objectAtIndex:tabIndex];
1948 [tabController setTitleCommonPrefixLength:
1949 tabTitleInfos[infoIndex].prefix_length];
1950 }
1951 }
1952
1909 @end 1953 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/tabs/tab_controller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698