summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorsail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-30 06:39:36 +0000
committersail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-30 06:39:36 +0000
commitef954469c286571918d174082a8766b7566ab574 (patch)
tree6b730bc158c607013c6cc2263c32185c6dccda64 /chrome
parentfe9c0de2e9272dbea78dc588f3b744ac97938773 (diff)
downloadchromium_src-ef954469c286571918d174082a8766b7566ab574.zip
chromium_src-ef954469c286571918d174082a8766b7566ab574.tar.gz
chromium_src-ef954469c286571918d174082a8766b7566ab574.tar.bz2
Mac: Elides the beginning of tab titles that have common prefixes
This is just the Mac version of mad's change. See: http://codereview.chromium.org/6579050/ I'm updating GTM with my change to fade the beginning of the text field: http://code.google.com/p/google-toolbox-for-mac/source/detail?r=437 BUG=69304 TEST=Still testing. Review URL: http://codereview.chromium.org/6688050 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79798 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/ui/cocoa/tabs/tab_controller.h7
-rw-r--r--chrome/browser/ui/cocoa/tabs/tab_controller.mm10
-rw-r--r--chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm44
3 files changed, 60 insertions, 1 deletions
diff --git a/chrome/browser/ui/cocoa/tabs/tab_controller.h b/chrome/browser/ui/cocoa/tabs/tab_controller.h
index 581b82c..b5e8003 100644
--- a/chrome/browser/ui/cocoa/tabs/tab_controller.h
+++ b/chrome/browser/ui/cocoa/tabs/tab_controller.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -103,6 +103,11 @@ class MenuDelegate;
// Update the title color to match the tabs current state.
- (void)updateTitleColor;
+
+// Sets the maximum number of characters that can be truncated from the
+// beginning of the title. This is used to remove a common prefix among multiple
+// tabs.
+- (void)setTitleCommonPrefixLength:(NSUInteger)length;
@end
@interface TabController(TestingAPI)
diff --git a/chrome/browser/ui/cocoa/tabs/tab_controller.mm b/chrome/browser/ui/cocoa/tabs/tab_controller.mm
index 41daafa..3a4c416 100644
--- a/chrome/browser/ui/cocoa/tabs/tab_controller.mm
+++ b/chrome/browser/ui/cocoa/tabs/tab_controller.mm
@@ -11,6 +11,7 @@
#import "chrome/browser/ui/cocoa/themed_window.h"
#import "chrome/common/extensions/extension.h"
#include "grit/generated_resources.h"
+#import "third_party/GTM/AppKit/GTMFadeTruncatingTextFieldCell.h"
#include "ui/base/l10n/l10n_util_mac.h"
@implementation TabController
@@ -303,4 +304,13 @@ class MenuDelegate : public ui::SimpleMenuModel::Delegate {
return NO;
}
+- (void)setTitleCommonPrefixLength:(NSUInteger)length {
+ DCHECK([[titleView_ cell] isKindOfClass:
+ [GTMFadeTruncatingTextFieldCell class]]);
+ GTMFadeTruncatingTextFieldCell* cell = [titleView_ cell];
+ [cell setDesiredCharactersToTruncateFromHead:length];
+ [cell setTruncateMode:length > 0 ? GTMFadeTruncatingHeadAndTail :
+ GTMFadeTruncatingTail];
+}
+
@end
diff --git a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm
index 12feb1b..b80e6a2 100644
--- a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm
+++ b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm
@@ -40,6 +40,7 @@
#import "chrome/browser/ui/cocoa/tracking_area.h"
#include "chrome/browser/ui/find_bar/find_bar.h"
#include "chrome/browser/ui/find_bar/find_bar_controller.h"
+#include "chrome/browser/ui/title_prefix_matcher.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
@@ -168,6 +169,7 @@ private:
givesIndex:(NSInteger*)index
disposition:(WindowOpenDisposition*)disposition;
- (void)setNewTabButtonHoverState:(BOOL)showHover;
+- (void)updateCommonTitlePrefix;
- (BOOL)shouldShowProfileMenuButton;
- (void)updateProfileMenuButton;
@end
@@ -1130,6 +1132,8 @@ class NotificationBridge : public NotificationObserver {
// else.
[self updateFaviconForContents:contents->tab_contents() atIndex:modelIndex];
+ [self updateCommonTitlePrefix];
+
// Send a broadcast that the number of tabs have changed.
[[NSNotificationCenter defaultCenter]
postNotificationName:kTabStripNumberOfTabsChanged
@@ -1249,6 +1253,8 @@ class NotificationBridge : public NotificationObserver {
// Once we're totally done with the tab, delete its controller
[tabArray_ removeObjectAtIndex:index];
+
+ [self updateCommonTitlePrefix];
}
// Called by the CAAnimation delegate when the tab completes the closing
@@ -1444,6 +1450,8 @@ class NotificationBridge : public NotificationObserver {
TabContentsController* updatedController =
[tabContentsArray_ objectAtIndex:index];
[updatedController tabDidChange:contents->tab_contents()];
+
+ [self updateCommonTitlePrefix];
}
// Called when a tab is moved (usually by drag&drop). Keep our parallel arrays
@@ -1495,6 +1503,8 @@ class NotificationBridge : public NotificationObserver {
// the tab has already been rendered, so re-layout the tabstrip. In all other
// cases, the state is set before the tab is rendered so this isn't needed.
[self layoutTabs];
+
+ [self updateCommonTitlePrefix];
}
- (void)setFrameOfSelectedTab:(NSRect)frame {
@@ -2013,6 +2023,40 @@ class NotificationBridge : public NotificationObserver {
}
}
+// Update the lengths of common title prefixes for all tabs. This needs
+// to be done every time tabs are added/removed or when titles change.
+- (void)updateCommonTitlePrefix {
+ DCHECK_EQ([tabArray_ count], [tabArray_ count]);
+
+ std::vector<TitlePrefixMatcher::TitleInfo> tabTitleInfos;
+ ScopedVector<string16> titles;
+ size_t tabIndex;
+ size_t tabCount = [tabArray_ count];
+
+ // Add all tab titles to |tabTitleInfos|.
+ for (tabIndex = 0; tabIndex < tabCount; ++tabIndex) {
+ TabController* tabController = [tabArray_ objectAtIndex:tabIndex];
+ string16 title = base::SysNSStringToUTF16([tabController title]);
+ if (!title.empty() && ![tabController mini]) {
+ titles.push_back(new string16(title));
+ tabTitleInfos.push_back(TitlePrefixMatcher::TitleInfo(
+ titles[titles.size() - 1], tabIndex));
+ }
+ }
+
+ // Calculate the prefix length.
+ TitlePrefixMatcher::CalculatePrefixLengths(&tabTitleInfos);
+
+ // Update the prefix length for each tab.
+ for (size_t infoIndex = 0; infoIndex < tabTitleInfos.size(); ++infoIndex) {
+ tabIndex = tabTitleInfos[infoIndex].caller_value;
+ DCHECK(tabIndex < [tabArray_ count]);
+ TabController* tabController = [tabArray_ objectAtIndex:tabIndex];
+ [tabController setTitleCommonPrefixLength:
+ tabTitleInfos[infoIndex].prefix_length];
+ }
+}
+
- (BOOL)shouldShowProfileMenuButton {
if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kMultiProfiles))
return NO;