summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/title_prefix_matcher.h
diff options
context:
space:
mode:
authormad@chromium.org <mad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-11 21:12:18 +0000
committermad@chromium.org <mad@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-11 21:12:18 +0000
commit976cc37fdc10fb413081484ab5c4785e64eba995 (patch)
tree6081df910ad41473a9768b99f929e88c68789544 /chrome/browser/ui/title_prefix_matcher.h
parentb10539a0f2ef8200f0f9506d3b532418718bf308 (diff)
downloadchromium_src-976cc37fdc10fb413081484ab5c4785e64eba995.zip
chromium_src-976cc37fdc10fb413081484ab5c4785e64eba995.tar.gz
chromium_src-976cc37fdc10fb413081484ab5c4785e64eba995.tar.bz2
Elides the beginning of tab titles that have common prefixes.
BUG=69304 TEST=Make sure the tab titles are displayed as spec'd, and that there isn't any performance issues. Review URL: http://codereview.chromium.org/6579050 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77860 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/title_prefix_matcher.h')
-rw-r--r--chrome/browser/ui/title_prefix_matcher.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/chrome/browser/ui/title_prefix_matcher.h b/chrome/browser/ui/title_prefix_matcher.h
new file mode 100644
index 0000000..94cbb6d
--- /dev/null
+++ b/chrome/browser/ui/title_prefix_matcher.h
@@ -0,0 +1,46 @@
+// 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"
+
+// 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, int caller_value);
+ // 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;
+ // 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);
+
+ private:
+ DISALLOW_IMPLICIT_CONSTRUCTORS(TitlePrefixMatcher);
+};
+
+#endif // CHROME_BROWSER_UI_TITLE_PREFIX_MATCHER_H_