| Index: chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm
|
| ===================================================================
|
| --- chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm (revision 78685)
|
| +++ chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm (working copy)
|
| @@ -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.
|
|
|
| @@ -37,6 +37,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 "content/browser/tab_contents/navigation_controller.h"
|
| #include "content/browser/tab_contents/navigation_entry.h"
|
| @@ -143,6 +144,7 @@
|
| givesIndex:(NSInteger*)index
|
| disposition:(WindowOpenDisposition*)disposition;
|
| - (void)setNewTabButtonHoverState:(BOOL)showHover;
|
| +- (void)updateCommonTitlePrefix;
|
| @end
|
|
|
| // A simple view class that prevents the Window Server from dragging the area
|
| @@ -1023,6 +1025,8 @@
|
| // else.
|
| [self updateFaviconForContents:contents->tab_contents() atIndex:modelIndex];
|
|
|
| + [self updateCommonTitlePrefix];
|
| +
|
| // Send a broadcast that the number of tabs have changed.
|
| [[NSNotificationCenter defaultCenter]
|
| postNotificationName:kTabStripNumberOfTabsChanged
|
| @@ -1142,6 +1146,8 @@
|
|
|
| // 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
|
| @@ -1337,6 +1343,8 @@
|
| 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
|
| @@ -1388,6 +1396,8 @@
|
| // 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 {
|
| @@ -1906,4 +1916,38 @@
|
| }
|
| }
|
|
|
| +// 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];
|
| + }
|
| +}
|
| +
|
| @end
|
|
|