OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_UI_TITLE_PREFIX_MATCHER_H_ |
| 6 #define CHROME_BROWSER_UI_TITLE_PREFIX_MATCHER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <vector> |
| 10 |
| 11 #include "base/string16.h" |
| 12 |
| 13 // 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 // the titles. It can be used for tab titles for example so that the common |
| 16 // prefixes can be elided. |
| 17 // 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 // 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 // to, if not all tabs are passed into the vector. |
| 22 // When CalculatePrefixLengths returns, the TitleInfo objects in the vector |
| 23 // are set with the prefix_length that is common between this title |
| 24 // and at least one other. |
| 25 // Note that the prefix_length is only calculated at word boundaries. |
| 26 class TitlePrefixMatcher { |
| 27 public: |
| 28 struct TitleInfo { |
| 29 TitleInfo(const string16* title, int caller_value); |
| 30 // 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 |
| 32 // unnecessary string copy. |
| 33 const string16* title; |
| 34 // This contains the number of characters at the beginning of title that |
| 35 // are common with other titles in the TitleInfo vector. |
| 36 size_t prefix_length; |
| 37 // Utility data space for the caller. Unused by CalculatePrefixLengths. |
| 38 int caller_value; |
| 39 }; |
| 40 static void CalculatePrefixLengths(std::vector<TitleInfo>* title_infos); |
| 41 private: |
| 42 DISALLOW_IMPLICIT_CONSTRUCTORS(TitlePrefixMatcher); |
| 43 }; |
| 44 |
| 45 #endif // CHROME_BROWSER_UI_TITLE_PREFIX_MATCHER_H_ |
OLD | NEW |