OLD | NEW |
---|---|
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); |
30 // We assume the title string will be valid throughout the execution of | 31 // We assume the title string will be valid throughout the execution of |
sky
2011/04/04 15:48:17
Add a destructor and move it to the .cc
MAD
2011/04/05 16:13:12
Done.
| |
31 // the prefix lengths calculation, and so we use a pointer to avoid an | 32 // the prefix lengths calculation, and so we use a pointer to avoid an |
32 // unnecessary string copy. | 33 // unnecessary string copy. |
33 const string16* title; | 34 const string16* title; |
35 // We only look for common prefix when the URL has the same hostname. | |
36 GURL url; | |
34 // This contains the number of characters at the beginning of title that | 37 // This contains the number of characters at the beginning of title that |
35 // are common with other titles in the TitleInfo vector. | 38 // are common with other titles in the TitleInfo vector. |
36 size_t prefix_length; | 39 size_t prefix_length; |
37 // Utility data space for the caller. Unused by CalculatePrefixLengths. | 40 // Utility data space for the caller. Unused by CalculatePrefixLengths. |
38 int caller_value; | 41 int caller_value; |
39 }; | 42 }; |
40 static void CalculatePrefixLengths(std::vector<TitleInfo>* title_infos); | 43 static void CalculatePrefixLengths(std::vector<TitleInfo>* title_infos); |
41 | 44 |
45 // This is the number of common characters at the end of the common prefix | |
46 // that tabs should still display. | |
47 static const int kCommonCharsToShow; | |
48 | |
49 // This is the minimum number of common characters we should get before | |
50 // enabling the prefix eliding. | |
51 static const size_t kMinElidingLength; | |
52 | |
42 private: | 53 private: |
43 DISALLOW_IMPLICIT_CONSTRUCTORS(TitlePrefixMatcher); | 54 DISALLOW_IMPLICIT_CONSTRUCTORS(TitlePrefixMatcher); |
44 }; | 55 }; |
45 | 56 |
46 #endif // CHROME_BROWSER_UI_TITLE_PREFIX_MATCHER_H_ | 57 #endif // CHROME_BROWSER_UI_TITLE_PREFIX_MATCHER_H_ |
OLD | NEW |