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

Side by Side Diff: chrome/browser/ui/title_prefix_matcher.h

Issue 6783015: Improvements to tab title prefix eliding as per email discussions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 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
OLDNEW
1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_UI_TITLE_PREFIX_MATCHER_H_ 5 #ifndef CHROME_BROWSER_UI_TITLE_PREFIX_MATCHER_H_
6 #define CHROME_BROWSER_UI_TITLE_PREFIX_MATCHER_H_ 6 #define CHROME_BROWSER_UI_TITLE_PREFIX_MATCHER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/string16.h" 11 #include "base/string16.h"
12 #include "googleurl/src/gurl.h"
12 13
13 // This class exposes a static method that receives a vector of TitleInfo 14 // This class exposes a static method that receives a vector of TitleInfo
14 // objects so that it can find the length of the common prefixes among all 15 // objects so that it can find the length of the common prefixes among all
15 // the titles. It can be used for tab titles for example so that the common 16 // the titles. It can be used for tab titles for example so that the common
16 // prefixes can be elided. 17 // prefixes can be elided.
17 // First, the caller needs to fill a vector of TitleInfo objects with the titles 18 // First, the caller needs to fill a vector of TitleInfo objects with the titles
18 // for which they want to find the common prefix lengths. They can also provide 19 // for which they want to find the common prefix lengths. They can also provide
19 // an optional caller_value where the index of the tabs could be saved 20 // an optional caller_value where the index of the tabs could be saved
20 // for example. This way the caller can remember which tab this title belongs 21 // for example. This way the caller can remember which tab this title belongs
21 // to, if not all tabs are passed into the vector. 22 // to, if not all tabs are passed into the vector.
22 // When CalculatePrefixLengths returns, the TitleInfo objects in the vector 23 // When CalculatePrefixLengths returns, the TitleInfo objects in the vector
23 // are set with the prefix_length that is common between this title 24 // are set with the prefix_length that is common between this title
24 // and at least one other. 25 // and at least one other.
25 // Note that the prefix_length is only calculated at word boundaries. 26 // Note that the prefix_length is only calculated at word boundaries.
26 class TitlePrefixMatcher { 27 class TitlePrefixMatcher {
27 public: 28 public:
28 struct TitleInfo { 29 struct TitleInfo {
29 TitleInfo(const string16* title, int caller_value); 30 TitleInfo(const string16* title, const GURL& url, int caller_value);
31 ~TitleInfo();
30 // We assume the title string will be valid throughout the execution of 32 // We assume the title string will be valid throughout the execution of
31 // the prefix lengths calculation, and so we use a pointer to avoid an 33 // the prefix lengths calculation, and so we use a pointer to avoid an
32 // unnecessary string copy. 34 // unnecessary string copy.
33 const string16* title; 35 const string16* title;
36 // We only look for common prefix when the URL has the same hostname.
37 GURL url;
34 // This contains the number of characters at the beginning of title that 38 // This contains the number of characters at the beginning of title that
35 // are common with other titles in the TitleInfo vector. 39 // are common with other titles in the TitleInfo vector.
36 size_t prefix_length; 40 size_t prefix_length;
37 // Utility data space for the caller. Unused by CalculatePrefixLengths. 41 // Utility data space for the caller. Unused by CalculatePrefixLengths.
38 int caller_value; 42 int caller_value;
39 }; 43 };
40 static void CalculatePrefixLengths(std::vector<TitleInfo>* title_infos); 44 static void CalculatePrefixLengths(std::vector<TitleInfo>* title_infos);
41 45
46 // We want to show the last few common chars of a page title in the tab,
47 // so we only do it if the common prefix is at least kMinElidingLength,
48 // otherwise, we could be replacing less characters than the ellipsis take.
49 static const int kCommonCharsToShow;
50 static const size_t kMinElidingLength;
51
42 private: 52 private:
43 DISALLOW_IMPLICIT_CONSTRUCTORS(TitlePrefixMatcher); 53 DISALLOW_IMPLICIT_CONSTRUCTORS(TitlePrefixMatcher);
44 }; 54 };
45 55
46 #endif // CHROME_BROWSER_UI_TITLE_PREFIX_MATCHER_H_ 56 #endif // CHROME_BROWSER_UI_TITLE_PREFIX_MATCHER_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm ('k') | chrome/browser/ui/title_prefix_matcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698