OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_CHARACTER_ENCODING_H__ | 5 #ifndef CHROME_BROWSER_CHARACTER_ENCODING_H__ |
6 #define CHROME_BROWSER_CHARACTER_ENCODING_H__ | 6 #define CHROME_BROWSER_CHARACTER_ENCODING_H__ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 | 13 |
14 class CharacterEncoding { | 14 class CharacterEncoding { |
15 public: | 15 public: |
16 // Enumeration of the types of Browser encoding name we | 16 // Enumeration of the types of Browser encoding name we |
17 // currently support. This is defined outside of Browser | 17 // currently support. This is defined outside of Browser |
18 // to avoid cyclical dependencies. | 18 // to avoid cyclical dependencies. |
19 | 19 |
| 20 // Structure to save encoding information. |
| 21 struct EncodingInfo { |
| 22 explicit EncodingInfo(int id); |
| 23 // Gets string key of EncodingInfo. With this method, we can use |
| 24 // l10n_util::SortVectorWithStringKey to sort the encoding menu items |
| 25 // by current locale character sequence. We need to keep the order within |
| 26 // encoding category name, that's why we use category name as key. |
| 27 const std::wstring& GetStringKey() const { return encoding_category_name; } |
| 28 |
| 29 // Encoding command id. |
| 30 int encoding_id; |
| 31 // Encoding display name. |
| 32 std::wstring encoding_display_name; |
| 33 // Encoding category name. |
| 34 std::wstring encoding_category_name; |
| 35 }; |
| 36 |
20 // Return canonical encoding name according to the command ID. | 37 // Return canonical encoding name according to the command ID. |
21 // THIS FUNCTION IS NOT THREADSAFE. You must run this function | 38 // THIS FUNCTION IS NOT THREADSAFE. You must run this function |
22 // only in UI thread. | 39 // only in UI thread. |
23 static std::wstring GetCanonicalEncodingNameByCommandId(int id); | 40 static std::wstring GetCanonicalEncodingNameByCommandId(int id); |
24 | 41 |
25 // Return display name of canonical encoding according to the command | 42 // Return display name of canonical encoding according to the command |
26 // ID. THIS FUNCTION IS NOT THREADSAFE. You must run this function | 43 // ID. THIS FUNCTION IS NOT THREADSAFE. You must run this function |
27 // only in UI thread. | 44 // only in UI thread. |
28 static std::wstring GetCanonicalEncodingDisplayNameByCommandId(int id); | 45 static std::wstring GetCanonicalEncodingDisplayNameByCommandId(int id); |
29 | 46 |
30 // Return count number of all supported canonical encoding. | 47 // Return count number of all supported canonical encoding. |
31 static int GetSupportCanonicalEncodingCount(); | 48 static int GetSupportCanonicalEncodingCount(); |
32 | 49 |
33 // Return canonical encoding name according to the index, which starts | 50 // Return canonical encoding name according to the index, which starts |
34 // from zero to GetSupportCanonicalEncodingCount() - 1. THIS FUNCTION | 51 // from zero to GetSupportCanonicalEncodingCount() - 1. THIS FUNCTION |
35 // IS NOT THREADSAFE. You must run this function only in UI thread. | 52 // IS NOT THREADSAFE. You must run this function only in UI thread. |
36 static std::wstring GetCanonicalEncodingNameByIndex(int index); | 53 static std::wstring GetCanonicalEncodingNameByIndex(int index); |
37 | 54 |
38 // Return display name of canonical encoding according to the index, | 55 // Return display name of canonical encoding according to the index, |
39 // which starts from zero to GetSupportCanonicalEncodingCount() - 1. | 56 // which starts from zero to GetSupportCanonicalEncodingCount() - 1. |
40 // THIS FUNCTION IS NOT THREADSAFE. You must run this function | 57 // THIS FUNCTION IS NOT THREADSAFE. You must run this function |
41 // only in UI thread. | 58 // only in UI thread. |
42 static std::wstring GetCanonicalEncodingDisplayNameByIndex(int index); | 59 static std::wstring GetCanonicalEncodingDisplayNameByIndex(int index); |
43 | 60 |
44 // Return canonical encoding name according to the encoding alias name. THIS | 61 // Return canonical encoding name according to the encoding alias name. THIS |
45 // FUNCTION IS NOT THREADSAFE. You must run this function only in UI thread. | 62 // FUNCTION IS NOT THREADSAFE. You must run this function only in UI thread. |
46 static std::wstring GetCanonicalEncodingNameByAliasName( | 63 static std::wstring GetCanonicalEncodingNameByAliasName( |
47 const std::wstring& alias_name); | 64 const std::wstring& alias_name); |
48 | 65 |
49 // Returns the pointer of a vector of command ids corresponding to | 66 // Returns the pointer of a vector of EncodingInfos corresponding to |
50 // encodings to display in the encoding menu. The list begins with | 67 // encodings to display in the encoding menu. The locale-dependent static |
51 // the locale-dependent static encodings and recently selected | 68 // encodings come at the top of the list and recently selected encodings |
52 // encodings is followed by the rest of encodings belonging to neither. | 69 // come next. Finally, the rest of encodings are listed. |
53 // The vector will be created and destroyed by CharacterEncoding. | 70 // The vector will be created and destroyed by CharacterEncoding. |
54 // The returned std::vector is maintained by this class. The parameter | 71 // The returned std::vector is maintained by this class. The parameter |
| 72 // |locale| points to the current application (UI) locale. The parameter |
55 // |locale_encodings| is string of static encodings list which is from the | 73 // |locale_encodings| is string of static encodings list which is from the |
56 // corresponding string resource that is stored in the resource bundle. | 74 // corresponding string resource that is stored in the resource bundle. |
57 // The parameter |recently_select_encodings| is string of encoding list which | 75 // The parameter |recently_select_encodings| is string of encoding list which |
58 // is from user recently selected. THIS FUNCTION IS NOT THREADSAFE. You must | 76 // is from user recently selected. THIS FUNCTION IS NOT THREADSAFE. You must |
59 // run this function only in UI thread. | 77 // run this function only in UI thread. |
60 static const std::vector<int>* GetCurrentDisplayEncodings( | 78 static const std::vector<EncodingInfo>* GetCurrentDisplayEncodings( |
| 79 const std::wstring& locale, |
61 const std::wstring& locale_encodings, | 80 const std::wstring& locale_encodings, |
62 const std::wstring& recently_select_encodings); | 81 const std::wstring& recently_select_encodings); |
63 | 82 |
64 // This function is for updating |original_selected_encoding_list| with a | 83 // This function is for updating |original_selected_encoding_list| with a |
65 // |new_selected_encoding_id|. If the encoding is already in the original | 84 // |new_selected_encoding_id|. If the encoding is already in the original |
66 // list, then returns false. Otherwise |selected_encoding_list| will return a | 85 // list, then returns false. Otherwise |selected_encoding_list| will return a |
67 // new string for user selected encoding short list and function returns true. | 86 // new string for user selected encoding short list and function returns true. |
68 static bool UpdateRecentlySelectdEncoding( | 87 static bool UpdateRecentlySelectdEncoding( |
69 const std::wstring& original_selected_encodings, | 88 const std::wstring& original_selected_encodings, |
70 int new_selected_encoding_id, | 89 int new_selected_encoding_id, |
71 std::wstring* selected_encodings); | 90 std::wstring* selected_encodings); |
72 | 91 |
73 // Get encoding command id according to input encoding name. If the name is | 92 // Get encoding command id according to input encoding name. If the name is |
74 // valid, return corresponding encoding command id. Otherwise return 0; | 93 // valid, return corresponding encoding command id. Otherwise return 0; |
75 static int GetCommandIdByCanonicalEncodingName( | 94 static int GetCommandIdByCanonicalEncodingName( |
76 const std::wstring& encoding_name); | 95 const std::wstring& encoding_name); |
77 | 96 |
78 private: | 97 private: |
79 // Disallow instantiating it since this class only contains static methods. | 98 // Disallow instantiating it since this class only contains static methods. |
80 DISALLOW_IMPLICIT_CONSTRUCTORS(CharacterEncoding); | 99 DISALLOW_IMPLICIT_CONSTRUCTORS(CharacterEncoding); |
81 }; | 100 }; |
82 | 101 |
83 #endif // CHROME_BROWSER_CHARACTER_ENCODING_H__ | 102 #endif // CHROME_BROWSER_CHARACTER_ENCODING_H__ |
84 | 103 |
OLD | NEW |