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

Unified Diff: chrome/browser/character_encoding.cc

Issue 21414: We will sort the encoding menu items according to current used UI language ex... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/character_encoding.h ('k') | chrome/browser/encoding_menu_controller_delegate.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/character_encoding.cc
===================================================================
--- chrome/browser/character_encoding.cc (revision 10076)
+++ chrome/browser/character_encoding.cc (working copy)
@@ -40,8 +40,8 @@
{ IDC_ENCODING_BIG5HKSCS, L"Big5-HKSCS", IDS_ENCODING_TRAD_CHINESE },
{ IDC_ENCODING_KOREAN, L"windows-949", IDS_ENCODING_KOREAN },
{ IDC_ENCODING_SHIFTJIS, L"Shift_JIS", IDS_ENCODING_JAPANESE },
+ { IDC_ENCODING_EUCJP, L"EUC-JP", IDS_ENCODING_JAPANESE },
{ IDC_ENCODING_ISO2022JP, L"ISO-2022-JP", IDS_ENCODING_JAPANESE },
- { IDC_ENCODING_EUCJP, L"EUC-JP", IDS_ENCODING_JAPANESE },
{ IDC_ENCODING_THAI, L"windows-874", IDS_ENCODING_THAI },
{ IDC_ENCODING_ISO885915, L"ISO-8859-15", IDS_ENCODING_WESTERN },
{ IDC_ENCODING_MACINTOSH, L"macintosh", IDS_ENCODING_WESTERN },
@@ -71,7 +71,8 @@
static const int canonical_encoding_names_length =
arraysize(canonical_encoding_names);
-typedef std::map<int, std::pair<const wchar_t*, int> > IdToCanonicalEncodingNameMapType;
+typedef std::map<int, std::pair<const wchar_t*, int> >
+ IdToCanonicalEncodingNameMapType;
typedef std::map<const std::wstring, int> CanonicalEncodingNameToIdMapType;
class CanonicalEncodingMap {
@@ -85,15 +86,15 @@
return &locale_dependent_encoding_ids_;
}
- std::vector<int>* const current_display_encoding_ids() {
- return &current_display_encoding_ids_;
+ std::vector<CharacterEncoding::EncodingInfo>* const current_display_encodings() {
+ return &current_display_encodings_;
}
private:
scoped_ptr<IdToCanonicalEncodingNameMapType> id_to_encoding_name_map_;
scoped_ptr<CanonicalEncodingNameToIdMapType> encoding_name_to_id_map_;
std::vector<int> locale_dependent_encoding_ids_;
- std::vector<int> current_display_encoding_ids_;
+ std::vector<CharacterEncoding::EncodingInfo> current_display_encodings_;
DISALLOW_EVIL_CONSTRUCTORS(CanonicalEncodingMap);
};
@@ -131,33 +132,25 @@
const int default_encoding_menus[] = {
IDC_ENCODING_UTF16LE,
- 0,
IDC_ENCODING_ISO88591,
IDC_ENCODING_WINDOWS1252,
- 0,
IDC_ENCODING_GBK,
IDC_ENCODING_GB18030,
IDC_ENCODING_BIG5,
IDC_ENCODING_BIG5HKSCS,
- 0,
IDC_ENCODING_KOREAN,
- 0,
IDC_ENCODING_SHIFTJIS,
+ IDC_ENCODING_EUCJP,
IDC_ENCODING_ISO2022JP,
- IDC_ENCODING_EUCJP,
- 0,
IDC_ENCODING_THAI,
- 0,
IDC_ENCODING_ISO885915,
IDC_ENCODING_MACINTOSH,
IDC_ENCODING_ISO88592,
IDC_ENCODING_WINDOWS1250,
- 0,
IDC_ENCODING_ISO88595,
IDC_ENCODING_WINDOWS1251,
IDC_ENCODING_KOI8R,
IDC_ENCODING_KOI8U,
- 0,
IDC_ENCODING_ISO88597,
IDC_ENCODING_WINDOWS1253,
IDC_ENCODING_WINDOWS1254,
@@ -166,7 +159,6 @@
IDC_ENCODING_ISO88598,
IDC_ENCODING_WINDOWS1255,
IDC_ENCODING_WINDOWS1258,
-
IDC_ENCODING_ISO88594,
IDC_ENCODING_ISO885913,
IDC_ENCODING_WINDOWS1257,
@@ -182,7 +174,7 @@
// comma, get available encoding ids and save them to |available_list|.
// The parameter |maximum_size| indicates maximum size of encoding items we
// want to get from the |encoding_list|.
-static void ParseEncodingListSeparatedWithComma(
+void ParseEncodingListSeparatedWithComma(
const std::wstring& encoding_list, std::vector<int>* const available_list,
size_t maximum_size) {
WStringTokenizer tokenizer(encoding_list, L",");
@@ -211,8 +203,33 @@
return category_name;
}
+int GetEncodingCategoryStringIdByCommandId(int id) {
+ const IdToCanonicalEncodingNameMapType* map =
+ canonical_encoding_name_map_singleton.
+ GetIdToCanonicalEncodingNameMapData();
+ DCHECK(map);
+
+ IdToCanonicalEncodingNameMapType::const_iterator found_name = map->find(id);
+ if (found_name != map->end())
+ return found_name->second.second;
+ return 0;
+}
+
+std::wstring GetEncodingCategoryStringByCommandId(int id) {
+ int category_id = GetEncodingCategoryStringIdByCommandId(id);
+ if (category_id)
+ return l10n_util::GetString(category_id);
+ return std::wstring();
+}
+
} // namespace
+CharacterEncoding::EncodingInfo::EncodingInfo(int id)
+ : encoding_id(id) {
+ encoding_category_name = GetEncodingCategoryStringByCommandId(id),
+ encoding_display_name = GetCanonicalEncodingDisplayNameByCommandId(id);
+}
+
// Static.
int CharacterEncoding::GetCommandIdByCanonicalEncodingName(
const std::wstring& encoding_name) {
@@ -314,13 +331,14 @@
// FireFox, we always put UTF-8 as toppest position, after then put user
// recently selected encodings, then put local dependent encoding items.
// At last, we put all rest encoding items.
-const std::vector<int>* CharacterEncoding::GetCurrentDisplayEncodings(
+const std::vector<CharacterEncoding::EncodingInfo>* CharacterEncoding::GetCurrentDisplayEncodings(
+ const std::wstring& locale,
const std::wstring& locale_encodings,
const std::wstring& recently_select_encodings) {
std::vector<int>* const locale_dependent_encoding_list =
canonical_encoding_name_map_singleton.locale_dependent_encoding_ids();
- std::vector<int>* const encoding_list =
- canonical_encoding_name_map_singleton.current_display_encoding_ids();
+ std::vector<CharacterEncoding::EncodingInfo>* const encoding_list =
+ canonical_encoding_name_map_singleton.current_display_encodings();
// Initialize locale dependent static encoding list.
if (locale_dependent_encoding_list->empty() && !locale_encodings.empty())
@@ -337,7 +355,7 @@
// Clear old encoding list since user recently selected encodings changed.
encoding_list->clear();
// Always add UTF-8 to first encoding position.
- encoding_list->push_back(IDC_ENCODING_UTF8);
+ encoding_list->push_back(EncodingInfo(IDC_ENCODING_UTF8));
std::set<int> inserted_encoding;
inserted_encoding.insert(IDC_ENCODING_UTF8);
@@ -352,8 +370,7 @@
recently_select_encoding_list.insert(recently_select_encoding_list.begin(),
locale_dependent_encoding_list->begin(),
locale_dependent_encoding_list->end());
- std::vector<int>::const_iterator it;
- for (it = recently_select_encoding_list.begin();
+ for (std::vector<int>::iterator it = recently_select_encoding_list.begin();
it != recently_select_encoding_list.end(); ++it) {
// Test whether we have met this encoding id.
bool ok = inserted_encoding.insert(*it).second;
@@ -361,27 +378,40 @@
// happened, but just in case some one manually edit preference file.
if (!ok)
continue;
- encoding_list->push_back(*it);
+ encoding_list->push_back(EncodingInfo(*it));
}
// Append a separator;
- encoding_list->push_back(0);
+ encoding_list->push_back(EncodingInfo(0));
- // Add those encodings which are in default_encoding_menus and does not
- // override with locale-dependent encodings list.
- bool previous_is_separator = true;
+ // We need to keep "Unicode (UTF-16LE)" always at the top (among the rest
+ // of encodings) instead of being sorted along with other encodings. So if
+ // "Unicode (UTF-16LE)" is already in previous encodings, sort the rest
+ // of encodings. Otherwise Put "Unicode (UTF-16LE)" on the first of the
+ // rest of encodings, skip "Unicode (UTF-16LE)" and sort all left encodings.
+ int start_sorted_index = encoding_list->size();
+ if (inserted_encoding.find(IDC_ENCODING_UTF16LE) ==
+ inserted_encoding.end()) {
+ encoding_list->push_back(EncodingInfo(IDC_ENCODING_UTF16LE));
+ inserted_encoding.insert(IDC_ENCODING_UTF16LE);
+ start_sorted_index++;
+ }
+
+ // Add the rest of encodings that are neither in the static encoding list
+ // nor in the list of recently selected encodings.
+ // Build the encoding list sorted in the current locale sorting order.
for (int i = 0; i < default_encoding_menus_length; ++i) {
int id = default_encoding_menus[i];
- if (id) {
- // We have inserted this encoding, skip it.
- if (inserted_encoding.find(id) != inserted_encoding.end())
- continue;
- encoding_list->push_back(id);
- previous_is_separator = false;
- } else if (!previous_is_separator) {
- encoding_list->push_back(0);
- previous_is_separator = true;
- }
+ // We have inserted this encoding, skip it.
+ if (inserted_encoding.find(id) != inserted_encoding.end())
+ continue;
+ encoding_list->push_back(EncodingInfo(id));
}
+ // Sort the encoding list.
+ l10n_util::SortVectorWithStringKey(locale,
+ encoding_list,
+ start_sorted_index,
+ encoding_list->size(),
+ true);
}
DCHECK(!encoding_list->empty());
return encoding_list;
« no previous file with comments | « chrome/browser/character_encoding.h ('k') | chrome/browser/encoding_menu_controller_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698