Commit f9c05e29 authored by sail@chromium.org's avatar sail@chromium.org

Remove prefix eliding

For M12 we experimented with eliding common prefixes in tab titles.

After lots of feedback we've decided to remove this feature.

BUG=83668
TEST=Testing
Review URL: http://codereview.chromium.org/7067007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86371 0039d316-1c4b-4281-b951-d872f2087c98
parent 9f8f2f47
......@@ -111,11 +111,6 @@ 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)
......
......@@ -9,7 +9,6 @@
#import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h"
#import "chrome/browser/ui/cocoa/tabs/tab_view.h"
#import "chrome/browser/ui/cocoa/themed_window.h"
#include "chrome/browser/ui/title_prefix_matcher.h"
#import "chrome/common/extensions/extension.h"
#include "grit/generated_resources.h"
#import "third_party/GTM/AppKit/GTMFadeTruncatingTextFieldCell.h"
......@@ -320,14 +319,4 @@ 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 -
TitlePrefixMatcher::kCommonCharsToShow];
[cell setTruncateMode:length > TitlePrefixMatcher::kMinElidingLength ?
GTMFadeTruncatingHeadAndTail : GTMFadeTruncatingTail];
}
@end
......@@ -47,7 +47,6 @@
#include "chrome/browser/ui/find_bar/find_tab_helper.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/browser/ui/tabs/tab_menu_model.h"
#include "chrome/browser/ui/title_prefix_matcher.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "content/browser/tab_contents/navigation_controller.h"
......@@ -172,7 +171,6 @@ private:
givesIndex:(NSInteger*)index
disposition:(WindowOpenDisposition*)disposition;
- (void)setNewTabButtonHoverState:(BOOL)showHover;
- (void)updateCommonTitlePrefix;
- (BOOL)shouldShowProfileMenuButton;
- (void)updateProfileMenuButton;
@end
......@@ -1194,8 +1192,6 @@ class NotificationBridge : public NotificationObserver {
// else.
[self updateFaviconForContents:contents atIndex:modelIndex];
[self updateCommonTitlePrefix];
// Send a broadcast that the number of tabs have changed.
[[NSNotificationCenter defaultCenter]
postNotificationName:kTabStripNumberOfTabsChanged
......@@ -1327,8 +1323,6 @@ 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
......@@ -1530,8 +1524,6 @@ 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
......@@ -1587,8 +1579,6 @@ 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)setFrameOfActiveTab:(NSRect)frame {
......@@ -2122,40 +2112,6 @@ 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], [tabController url], 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;
......
// 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.
#include "chrome/browser/ui/title_prefix_matcher.h"
#include "base/hash_tables.h"
#include "base/i18n/break_iterator.h"
#include "base/logging.h"
#include "base/utf_string_conversions.h"
namespace {
// We use this value to identify that we have already seen the title associated
// to this value in the duplicate_titles hash_set, ans marked it as a duplicate.
const size_t kPreviouslySeenIndex = 0xFFFFFFFF;
}
// static
const int TitlePrefixMatcher::kCommonCharsToShow = 2;
const size_t TitlePrefixMatcher::kMinElidingLength =
TitlePrefixMatcher::kCommonCharsToShow + 3;
TitlePrefixMatcher::TitleInfo::TitleInfo(
const string16* title, const GURL& url, int caller_value)
: title(title),
url(url),
prefix_length(0),
caller_value(caller_value) {
DCHECK(title != NULL);
}
TitlePrefixMatcher::TitleInfo::~TitleInfo() {
}
// static
void TitlePrefixMatcher::CalculatePrefixLengths(
std::vector<TitleInfo>* title_infos) {
DCHECK(title_infos != NULL);
// This set will contain the indexes of the TitleInfo objects in the vector
// that have a duplicate.
base::hash_set<size_t> duplicate_titles;
// This map is used to identify duplicates by remembering the vector indexes
// we have seen with a given title string. The vector index is set to
// kPreviouslySeenIndex once we identified duplicates and placed their
// indices in duplicate_titles.
base::hash_map<string16, size_t> existing_title;
// We identify if there are identical titles upfront,
// because we don't want to remove prefixes for those at all.
// We do it as a separate pass so that we don't need to remove
// previously parsed titles when we find a duplicate title later on.
for (size_t i = 0; i < title_infos->size(); ++i) {
// We use pairs to test existence and insert in one shot.
std::pair<base::hash_map<string16, size_t>::iterator, bool> insert_result =
existing_title.insert(std::make_pair(*(*title_infos)[i].title, i));
if (!insert_result.second) {
// insert_result.second is false when we insert a duplicate in the set.
// insert_result.first is a map iterator and thus
// insert_result.first->first is the string title key of the map.
DCHECK_EQ(*(*title_infos)[i].title, insert_result.first->first);
duplicate_titles.insert(i);
// insert_result.first->second is the value of the title index and if it's
// not kPreviouslySeenIndex yet, we must remember it as a duplicate too.
if (insert_result.first->second != kPreviouslySeenIndex) {
duplicate_titles.insert(insert_result.first->second);
insert_result.first->second = kPreviouslySeenIndex;
}
}
}
// This next loop accumulates all the potential prefixes,
// and remember on which titles we saw them.
base::hash_map<string16, std::vector<size_t> > prefixes;
for (size_t i = 0; i < title_infos->size(); ++i) {
// Duplicate titles are not to be included in this process.
if (duplicate_titles.find(i) != duplicate_titles.end())
continue;
const TitleInfo& title_info = (*title_infos)[i];
const string16* title = title_info.title;
// We prefix the hostname at the beginning, so that we only group
// titles that are from the same hostname.
string16 hostname = ASCIIToUTF16(title_info.url.host());
// We only create prefixes at word boundaries.
base::i18n::BreakIterator iter(title,
base::i18n::BreakIterator::BREAK_WORD);
// We ignore this title if we can't break it into words, or if it only
// contains a single word.
if (!iter.Init() || !iter.Advance())
continue;
// We continue advancing even though we already advanced to the first
// word above, so that we can use iter.prev() to identify the end of the
// previous word and more easily ignore the last word while iterating.
while (iter.Advance()) {
if (iter.IsWord())
prefixes[hostname + title->substr(0, iter.prev())].push_back(i);
}
}
// Now we parse the map to find common prefixes
// and keep the largest per title.
for (base::hash_map<string16, std::vector<size_t> >::iterator iter =
prefixes.begin(); iter != prefixes.end(); ++iter) {
// iter->first is the prefix string, iter->second is a vector of indices.
if (iter->second.size() > 1) {
// We need to subtract the hostname size since we added it to the prefix.
const TitleInfo& first_title_info = (*title_infos)[iter->second[0]];
DCHECK_GE(iter->first.size(), first_title_info.url.host().size());
size_t prefix_length = iter->first.size() -
first_title_info.url.host().size();
for (size_t i = 0; i < iter->second.size(); ++i){
TitleInfo& title_info = (*title_infos)[iter->second[i]];
DCHECK_EQ(first_title_info.url.host(), title_info.url.host());
if (title_info.prefix_length < prefix_length)
title_info.prefix_length = prefix_length;
}
}
}
}
// 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.
#ifndef CHROME_BROWSER_UI_TITLE_PREFIX_MATCHER_H_
#define CHROME_BROWSER_UI_TITLE_PREFIX_MATCHER_H_
#pragma once
#include <vector>
#include "base/string16.h"
#include "googleurl/src/gurl.h"
// This class exposes a static method that receives a vector of TitleInfo
// objects so that it can find the length of the common prefixes among all
// the titles. It can be used for tab titles for example so that the common
// prefixes can be elided.
// First, the caller needs to fill a vector of TitleInfo objects with the titles
// for which they want to find the common prefix lengths. They can also provide
// an optional caller_value where the index of the tabs could be saved
// for example. This way the caller can remember which tab this title belongs
// to, if not all tabs are passed into the vector.
// When CalculatePrefixLengths returns, the TitleInfo objects in the vector
// are set with the prefix_length that is common between this title
// and at least one other.
// Note that the prefix_length is only calculated at word boundaries.
class TitlePrefixMatcher {
public:
struct TitleInfo {
TitleInfo(const string16* title, const GURL& url, int caller_value);
~TitleInfo();
// We assume the title string will be valid throughout the execution of
// the prefix lengths calculation, and so we use a pointer to avoid an
// unnecessary string copy.
const string16* title;
// We only look for common prefix when the URL has the same hostname.
GURL url;
// This contains the number of characters at the beginning of title that
// are common with other titles in the TitleInfo vector.
size_t prefix_length;
// Utility data space for the caller. Unused by CalculatePrefixLengths.
int caller_value;
};
static void CalculatePrefixLengths(std::vector<TitleInfo>* title_infos);
// We want to show the last few common chars of a page title in the tab,
// so we only do it if the common prefix is at least kMinElidingLength,
// otherwise, we could be replacing less characters than the ellipsis take.
static const int kCommonCharsToShow;
static const size_t kMinElidingLength;
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(TitlePrefixMatcher);
};
#endif // CHROME_BROWSER_UI_TITLE_PREFIX_MATCHER_H_
// 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.
#include "base/logging.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/ui/title_prefix_matcher.h"
#include "googleurl/src/gurl.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
const GURL kUrlA1("http://a.b.c/123");
const GURL kUrlA2("http://a.b.c/alphabits");
const GURL kUrlB1("http://www.here.com/here/and/there");
const GURL kUrlB2("http://www.here.com/elsewhere");
const GURL kUrlC1("http://www.here.ca/far/far/away");
const string16 kFoofooAbcdef(ASCIIToUTF16("Foofoo abcdef"));
const string16 kFoofooAbcdeg(ASCIIToUTF16("Foofoo abcdeg"));
const string16 kFooAbcdef(ASCIIToUTF16("Foo abcdef"));
const string16 kFooAbcdeg(ASCIIToUTF16("Foo abcdeg"));
const string16 kBarAbcDef(ASCIIToUTF16("Bar abc def"));
const string16 kBarAbcDeg(ASCIIToUTF16("Bar abc deg"));
const string16 kBarAbdDef(ASCIIToUTF16("Bar abd def"));
const string16 kBar(ASCIIToUTF16("Bar"));
const string16 kFoo(ASCIIToUTF16("Foo"));
}
TEST(TitlePrefixMatcherTest, BasicTests) {
std::vector<TitlePrefixMatcher::TitleInfo> tab_title_infos;
tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFoofooAbcdef,
kUrlA1, 0));
tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFoofooAbcdeg,
kUrlA1, 1));
TitlePrefixMatcher::CalculatePrefixLengths(&tab_title_infos);
EXPECT_EQ(0, tab_title_infos[0].caller_value);
EXPECT_EQ(7U, tab_title_infos[0].prefix_length);
EXPECT_EQ(1, tab_title_infos[1].caller_value);
EXPECT_EQ(7U, tab_title_infos[1].prefix_length);
tab_title_infos.clear();
tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFoofooAbcdef,
kUrlA1, 0));
tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFoofooAbcdeg,
kUrlA1, 1));
tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFooAbcdef,
kUrlA1, 2));
tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFooAbcdeg,
kUrlA1, 3));
TitlePrefixMatcher::CalculatePrefixLengths(&tab_title_infos);
EXPECT_EQ(0, tab_title_infos[0].caller_value);
EXPECT_EQ(7U, tab_title_infos[0].prefix_length);
EXPECT_EQ(1, tab_title_infos[1].caller_value);
EXPECT_EQ(7U, tab_title_infos[1].prefix_length);
EXPECT_EQ(2, tab_title_infos[2].caller_value);
EXPECT_EQ(4U, tab_title_infos[2].prefix_length);
EXPECT_EQ(3, tab_title_infos[3].caller_value);
EXPECT_EQ(4U, tab_title_infos[3].prefix_length);
}
TEST(TitlePrefixMatcherTest, Duplicates) {
std::vector<TitlePrefixMatcher::TitleInfo> tab_title_infos;
tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFoofooAbcdef,
kUrlA1, 0));
tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFoofooAbcdeg,
kUrlA1, 1));
tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFooAbcdef,
kUrlA1, 2));
tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFooAbcdeg,
kUrlA1, 3));
tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFoofooAbcdef,
kUrlA1, 4));
TitlePrefixMatcher::CalculatePrefixLengths(&tab_title_infos);
EXPECT_EQ(0, tab_title_infos[0].caller_value);
EXPECT_EQ(0U, tab_title_infos[0].prefix_length);
EXPECT_EQ(1, tab_title_infos[1].caller_value);
EXPECT_EQ(0U, tab_title_infos[1].prefix_length);
EXPECT_EQ(2, tab_title_infos[2].caller_value);
EXPECT_EQ(4U, tab_title_infos[2].prefix_length);
EXPECT_EQ(3, tab_title_infos[3].caller_value);
EXPECT_EQ(4U, tab_title_infos[3].prefix_length);
EXPECT_EQ(4, tab_title_infos[4].caller_value);
EXPECT_EQ(0U, tab_title_infos[4].prefix_length);
}
TEST(TitlePrefixMatcherTest, MultiplePrefixes) {
std::vector<TitlePrefixMatcher::TitleInfo> tab_title_infos;
tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFooAbcdef,
kUrlA1, 0));
tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFooAbcdeg,
kUrlA1, 1));
tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kBarAbcDef,
kUrlA1, 2));
tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kBarAbcDeg,
kUrlA1, 3));
tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kBarAbdDef,
kUrlA1, 4));
tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kBar,
kUrlA1, 5));
tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFoo,
kUrlA1, 6));
TitlePrefixMatcher::CalculatePrefixLengths(&tab_title_infos);
EXPECT_EQ(0, tab_title_infos[0].caller_value);
EXPECT_EQ(4U, tab_title_infos[0].prefix_length);
EXPECT_EQ(1, tab_title_infos[1].caller_value);
EXPECT_EQ(4U, tab_title_infos[1].prefix_length);
EXPECT_EQ(2, tab_title_infos[2].caller_value);
EXPECT_EQ(8U, tab_title_infos[2].prefix_length);
EXPECT_EQ(3, tab_title_infos[3].caller_value);
EXPECT_EQ(8U, tab_title_infos[3].prefix_length);
EXPECT_EQ(4, tab_title_infos[4].caller_value);
EXPECT_EQ(4U, tab_title_infos[4].prefix_length);
EXPECT_EQ(5, tab_title_infos[5].caller_value);
EXPECT_EQ(0U, tab_title_infos[5].prefix_length);
EXPECT_EQ(6, tab_title_infos[6].caller_value);
EXPECT_EQ(0U, tab_title_infos[6].prefix_length);
}
TEST(TitlePrefixMatcherTest, DifferentHosts) {
std::vector<TitlePrefixMatcher::TitleInfo> tab_title_infos;
tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFoofooAbcdef,
kUrlA1, 0));
tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFoofooAbcdeg,
kUrlA2, 1));
tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFooAbcdef,
kUrlB1, 2));
tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kBarAbdDef,
kUrlC1, 3));
tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kBarAbcDef,
kUrlA1, 4));
tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kBarAbcDeg,
kUrlA2, 5));
tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFooAbcdeg,
kUrlB2, 6));
TitlePrefixMatcher::CalculatePrefixLengths(&tab_title_infos);
EXPECT_EQ(0, tab_title_infos[0].caller_value);
EXPECT_EQ(7U, tab_title_infos[0].prefix_length);
EXPECT_EQ(1, tab_title_infos[1].caller_value);
EXPECT_EQ(7U, tab_title_infos[1].prefix_length);
EXPECT_EQ(2, tab_title_infos[2].caller_value);
EXPECT_EQ(4U, tab_title_infos[2].prefix_length);
EXPECT_EQ(3, tab_title_infos[3].caller_value);
EXPECT_EQ(0U, tab_title_infos[3].prefix_length);
EXPECT_EQ(4, tab_title_infos[4].caller_value);
EXPECT_EQ(8U, tab_title_infos[4].prefix_length);
EXPECT_EQ(5, tab_title_infos[5].caller_value);
EXPECT_EQ(8U, tab_title_infos[5].prefix_length);
EXPECT_EQ(6, tab_title_infos[6].caller_value);
EXPECT_EQ(4U, tab_title_infos[6].prefix_length);
}
......@@ -10,7 +10,6 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/browser/ui/title_prefix_matcher.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/tabs/tab_controller.h"
#include "chrome/common/chrome_switches.h"
......@@ -475,8 +474,6 @@ void BaseTab::PaintTitle(gfx::Canvas* canvas, SkColor title_color) {
// Paint the Title.
const gfx::Rect& title_bounds = GetTitleBounds();
string16 title = data().title;
bool should_truncate = false;
int prefix_length = 0;
if (title.empty()) {
title = data().loading ?
......@@ -484,25 +481,12 @@ void BaseTab::PaintTitle(gfx::Canvas* canvas, SkColor title_color) {
TabContentsWrapper::GetDefaultTitle();
} else {
Browser::FormatTitleForDisplay(&title);
// If we'll need to truncate, check if we should also truncate
// a common prefix, but only if there is enough room for it.
// We arbitrarily choose to request enough room for 6 average chars.
should_truncate =
data().common_prefix_length > TitlePrefixMatcher::kMinElidingLength &&
font_->GetExpectedTextWidth(6) < title_bounds.width() &&
font_->GetStringWidth(title) > title_bounds.width();
prefix_length = data().common_prefix_length -
TitlePrefixMatcher::kCommonCharsToShow;
}
#if defined(OS_WIN)
canvas->AsCanvasSkia()->DrawFadeTruncatingString(title,
should_truncate ? gfx::CanvasSkia::TruncateFadeHeadAndTail :
gfx::CanvasSkia::TruncateFadeTail,
prefix_length, *font_, title_color, title_bounds);
gfx::CanvasSkia::TruncateFadeTail, 0, *font_, title_color, title_bounds);
#else
if (should_truncate)
title.replace(0, prefix_length, UTF8ToUTF16(ui::kEllipsis));
canvas->DrawStringInt(title, *font_, title_color,
title_bounds.x(), title_bounds.y(),
title_bounds.width(), title_bounds.height());
......
......@@ -5,7 +5,6 @@
#include "chrome/browser/ui/views/tabs/base_tab_strip.h"
#include "base/logging.h"
#include "chrome/browser/ui/title_prefix_matcher.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/tabs/dragged_tab_controller.h"
#include "chrome/browser/ui/views/tabs/tab_strip_controller.h"
......@@ -132,7 +131,6 @@ void BaseTabStrip::AddTabAt(int model_index, const TabRendererData& data) {
TabData d = { tab, gfx::Rect() };
tab_data_.insert(tab_data_.begin() + ModelIndexToTabIndex(model_index), d);
UpdateCommonTitlePrefix();
AddChildView(tab);
......@@ -160,7 +158,6 @@ void BaseTabStrip::SetTabData(int model_index, const TabRendererData& data) {
BaseTab* tab = GetBaseTabAtModelIndex(model_index);
bool mini_state_changed = tab->data().mini != data.mini;
tab->SetData(data);
UpdateCommonTitlePrefix();
if (mini_state_changed) {
if (GetWindow() && GetWindow()->IsVisible())
......@@ -473,36 +470,6 @@ void BaseTabStrip::RemoveAndDeleteTab(BaseTab* tab) {
tab_data_.erase(tab_data_.begin() + tab_data_index);
delete tab;
UpdateCommonTitlePrefix();
}
bool BaseTabStrip::IgnoreTitlePrefixEliding(BaseTab* tab) {
DCHECK(tab != NULL);
return tab->data().mini || tab->data().title.empty();
}
void BaseTabStrip::UpdateCommonTitlePrefix() {
std::vector<TitlePrefixMatcher::TitleInfo> tab_title_infos;
for (int tab_index = 0; tab_index < tab_count(); ++tab_index) {
DCHECK(tab_data_[tab_index].tab != NULL);
if (!IgnoreTitlePrefixEliding(tab_data_[tab_index].tab)) {
tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(
&tab_data_[tab_index].tab->data().title,
tab_data_[tab_index].tab->data().url,
tab_index));
}
}
TitlePrefixMatcher::CalculatePrefixLengths(&tab_title_infos);
for (size_t title_index = 0; title_index < tab_title_infos.size();
++title_index) {
int tab_index = tab_title_infos[title_index].caller_value;
TabRendererData data = tab_data_[tab_index].tab->data();
if (data.common_prefix_length !=
tab_title_infos[title_index].prefix_length) {
data.common_prefix_length = tab_title_infos[title_index].prefix_length;
tab_data_[tab_index].tab->SetData(data);
}
}
}
int BaseTabStrip::TabIndexOfTab(BaseTab* tab) const {
......
......@@ -201,15 +201,6 @@ class BaseTabStrip : public AbstractTabStripView,
tab_data_[index].ideal_bounds = bounds;
}
// Identifies whether we should ignore title prefix eliding or not
// for the specified tab. This allows derived class like the one
// for side tabs to make a different choice (e.g., for mini tabs).
virtual bool IgnoreTitlePrefixEliding(BaseTab* tab);
// 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.
virtual void UpdateCommonTitlePrefix();
// Returns the index into |tab_data_| corresponding to the specified tab, or
// -1 if the tab isn't in |tab_data_|.
int TabIndexOfTab(BaseTab* tab) const;
......
......@@ -289,11 +289,6 @@ BaseTab* SideTabStrip::CreateTab() {
return new SideTab(this);
}
bool SideTabStrip::IgnoreTitlePrefixEliding(BaseTab* tab) {
DCHECK(tab != NULL);
return tab->data().title.empty();
}
void SideTabStrip::GenerateIdealBounds() {
gfx::Rect layout_rect = GetContentsBounds();
layout_rect.Inset(kTabStripInset, kTabStripInset);
......
......@@ -44,7 +44,6 @@ class SideTabStrip : public BaseTabStrip, public views::ButtonListener {
protected:
// BaseTabStrip overrides:
virtual BaseTab* CreateTab() OVERRIDE;
virtual bool IgnoreTitlePrefixEliding(BaseTab* tab) OVERRIDE;
virtual void GenerateIdealBounds() OVERRIDE;
virtual void StartInsertTabAnimation(int model_index) OVERRIDE;
virtual void AnimateToIdealBounds() OVERRIDE;
......
......@@ -6,7 +6,6 @@
TabRendererData::TabRendererData()
: network_state(NETWORK_STATE_NONE),
common_prefix_length(0),
loading(false),
crashed_status(base::TERMINATION_STATUS_STILL_RUNNING),
incognito(false),
......@@ -26,7 +25,6 @@ bool TabRendererData::Equals(const TabRendererData& data) {
network_state == data.network_state &&
title == data.title &&
url == data.url &&
common_prefix_length == data.common_prefix_length &&
loading == data.loading &&
crashed_status == data.crashed_status &&
incognito == data.incognito &&
......
......@@ -42,9 +42,6 @@ struct TabRendererData {
NetworkState network_state;
string16 title;
GURL url;
// Identifies the number of chars at the beginning of the string
// that are common to other tab titles.
size_t common_prefix_length;
bool loading;
base::TerminationStatus crashed_status;
bool incognito;
......
......@@ -2877,8 +2877,6 @@
'browser/ui/tabs/hover_tab_selector.h',
'browser/ui/tabs/tab_menu_model.cc',
'browser/ui/tabs/tab_menu_model.h',
'browser/ui/title_prefix_matcher.cc',
'browser/ui/title_prefix_matcher.h',
'browser/ui/toolbar/back_forward_menu_model.cc',
'browser/ui/toolbar/back_forward_menu_model.h',
'browser/ui/toolbar/encoding_menu_controller.cc',
......
......@@ -1791,7 +1791,6 @@
'browser/ui/tabs/tab_menu_model_unittest.cc',
'browser/ui/tests/ui_gfx_image_unittest.cc',
'browser/ui/tests/ui_gfx_image_unittest.mm',
'browser/ui/title_prefix_matcher_unittest.cc',
'browser/ui/toolbar/back_forward_menu_model_unittest.cc',
'browser/ui/toolbar/encoding_menu_controller_unittest.cc',
'browser/ui/toolbar/wrench_menu_model_unittest.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment