| 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 #include <windows.h> | 4 #include <windows.h> |
| 5 #include <shlobj.h> | 5 #include <shlobj.h> |
| 6 #include <vsstyle.h> | 6 #include <vsstyle.h> |
| 7 #include <vssym32.h> | 7 #include <vssym32.h> |
| 8 | 8 |
| 9 #include <vector> |
| 10 |
| 9 #include "chrome/browser/views/options/fonts_page_view.h" | 11 #include "chrome/browser/views/options/fonts_page_view.h" |
| 10 | 12 |
| 11 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 12 #include "base/gfx/native_theme.h" | 14 #include "base/gfx/native_theme.h" |
| 13 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 14 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/character_encoding.h" | 17 #include "chrome/browser/character_encoding.h" |
| 16 #include "chrome/browser/shell_dialogs.h" | 18 #include "chrome/browser/shell_dialogs.h" |
| 17 #include "chrome/browser/views/password_manager_view.h" | 19 #include "chrome/browser/views/password_manager_view.h" |
| 18 #include "chrome/browser/views/standard_layout.h" | 20 #include "chrome/browser/views/standard_layout.h" |
| 19 #include "chrome/common/gfx/chrome_canvas.h" | 21 #include "chrome/common/gfx/chrome_canvas.h" |
| 20 #include "chrome/common/gfx/chrome_font.h" | 22 #include "chrome/common/gfx/chrome_font.h" |
| 21 #include "chrome/common/l10n_util.h" | 23 #include "chrome/common/l10n_util.h" |
| 22 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/common/pref_service.h" | 25 #include "chrome/common/pref_service.h" |
| 24 #include "chrome/common/resource_bundle.h" | 26 #include "chrome/common/resource_bundle.h" |
| 25 #include "chrome/views/checkbox.h" | 27 #include "chrome/views/checkbox.h" |
| 26 #include "chrome/views/grid_layout.h" | 28 #include "chrome/views/grid_layout.h" |
| 27 #include "chrome/views/native_button.h" | 29 #include "chrome/views/native_button.h" |
| 28 #include "chrome/views/radio_button.h" | 30 #include "chrome/views/radio_button.h" |
| 29 #include "chrome/views/text_field.h" | 31 #include "chrome/views/text_field.h" |
| 30 #include "chrome/views/widget.h" | 32 #include "chrome/views/widget.h" |
| 31 #include "grit/generated_resources.h" | 33 #include "grit/generated_resources.h" |
| 32 #include "grit/theme_resources.h" | 34 #include "grit/theme_resources.h" |
| 33 #include "grit/locale_settings.h" | 35 #include "grit/locale_settings.h" |
| 34 #include "skia/include/SkBitmap.h" | 36 #include "skia/include/SkBitmap.h" |
| 35 | 37 |
| 38 namespace { |
| 39 |
| 40 static std::vector<CharacterEncoding::EncodingInfo> sorted_encoding_list; |
| 41 |
| 42 } // namespace |
| 43 |
| 36 class DefaultEncodingComboboxModel : public views::ComboBox::Model { | 44 class DefaultEncodingComboboxModel : public views::ComboBox::Model { |
| 37 public: | 45 public: |
| 38 DefaultEncodingComboboxModel() { | 46 DefaultEncodingComboboxModel() { |
| 39 canonical_encoding_names_length_ = | 47 canonical_encoding_names_length_ = |
| 40 CharacterEncoding::GetSupportCanonicalEncodingCount(); | 48 CharacterEncoding::GetSupportCanonicalEncodingCount(); |
| 49 // Initialize the vector of all sorted encodings according to current |
| 50 // UI locale. |
| 51 if (!sorted_encoding_list.size()) { |
| 52 std::wstring locale = g_browser_process->GetApplicationLocale(); |
| 53 for (int i = 0; i < canonical_encoding_names_length_; i++) { |
| 54 sorted_encoding_list.push_back(CharacterEncoding::EncodingInfo( |
| 55 CharacterEncoding::GetEncodingCommandIdByIndex(i))); |
| 56 } |
| 57 l10n_util::SortVectorWithStringKey(locale, &sorted_encoding_list, true); |
| 58 } |
| 41 } | 59 } |
| 42 | 60 |
| 43 virtual ~DefaultEncodingComboboxModel() {} | 61 virtual ~DefaultEncodingComboboxModel() {} |
| 44 | 62 |
| 45 // Overridden from views::Combobox::Model. | 63 // Overridden from views::Combobox::Model. |
| 46 virtual int GetItemCount(views::ComboBox* source) { | 64 virtual int GetItemCount(views::ComboBox* source) { |
| 47 return canonical_encoding_names_length_; | 65 return canonical_encoding_names_length_; |
| 48 } | 66 } |
| 49 | 67 |
| 50 virtual std::wstring GetItemAt(views::ComboBox* source, int index) { | 68 virtual std::wstring GetItemAt(views::ComboBox* source, int index) { |
| 51 DCHECK(index >= 0 && canonical_encoding_names_length_ > index); | 69 DCHECK(index >= 0 && canonical_encoding_names_length_ > index); |
| 52 return CharacterEncoding::GetCanonicalEncodingDisplayNameByIndex(index); | 70 return sorted_encoding_list[index].encoding_display_name; |
| 53 } | 71 } |
| 54 | 72 |
| 55 std::wstring GetEncodingCharsetByIndex(int index) { | 73 std::wstring GetEncodingCharsetByIndex(int index) { |
| 56 DCHECK(index >= 0 && canonical_encoding_names_length_ > index); | 74 DCHECK(index >= 0 && canonical_encoding_names_length_ > index); |
| 57 return CharacterEncoding::GetCanonicalEncodingNameByIndex(index); | 75 int encoding_id = sorted_encoding_list[index].encoding_id; |
| 76 return CharacterEncoding::GetCanonicalEncodingNameByCommandId(encoding_id); |
| 58 } | 77 } |
| 59 | 78 |
| 60 int GetSelectedEncodingIndex(Profile* profile) { | 79 int GetSelectedEncodingIndex(Profile* profile) { |
| 61 StringPrefMember current_encoding_string; | 80 StringPrefMember current_encoding_string; |
| 62 current_encoding_string.Init(prefs::kDefaultCharset, | 81 current_encoding_string.Init(prefs::kDefaultCharset, |
| 63 profile->GetPrefs(), | 82 profile->GetPrefs(), |
| 64 NULL); | 83 NULL); |
| 65 const std::wstring current_encoding = current_encoding_string.GetValue(); | 84 const std::wstring current_encoding = current_encoding_string.GetValue(); |
| 66 for (int i = 0; i < canonical_encoding_names_length_; i++) { | 85 for (int i = 0; i < canonical_encoding_names_length_; i++) { |
| 67 if (CharacterEncoding::GetCanonicalEncodingNameByIndex(i) == | 86 if (GetEncodingCharsetByIndex(i) == current_encoding) |
| 68 current_encoding) | |
| 69 return i; | 87 return i; |
| 70 } | 88 } |
| 71 | 89 |
| 72 return 0; | 90 return 0; |
| 73 } | 91 } |
| 74 | 92 |
| 75 private: | 93 private: |
| 76 int canonical_encoding_names_length_; | 94 int canonical_encoding_names_length_; |
| 77 DISALLOW_EVIL_CONSTRUCTORS(DefaultEncodingComboboxModel); | 95 DISALLOW_EVIL_CONSTRUCTORS(DefaultEncodingComboboxModel); |
| 78 }; | 96 }; |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | 489 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
| 472 GridLayout::USE_PREF, 0, 0); | 490 GridLayout::USE_PREF, 0, 0); |
| 473 | 491 |
| 474 // Add Encoding ComboBox. | 492 // Add Encoding ComboBox. |
| 475 layout->StartRow(0, double_column_view_set_id); | 493 layout->StartRow(0, double_column_view_set_id); |
| 476 layout->AddView(default_encoding_combobox_label_); | 494 layout->AddView(default_encoding_combobox_label_); |
| 477 layout->AddView(default_encoding_combobox_, 1, 1, GridLayout::FILL, | 495 layout->AddView(default_encoding_combobox_, 1, 1, GridLayout::FILL, |
| 478 GridLayout::CENTER); | 496 GridLayout::CENTER); |
| 479 } | 497 } |
| 480 | 498 |
| OLD | NEW |