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

Side by Side Diff: chrome/browser/views/options/fonts_page_view.cc

Issue 113991: Make Combobox portable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "chrome/browser/views/options/fonts_page_view.h" 5 #include "chrome/browser/views/options/fonts_page_view.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <shlobj.h> 8 #include <shlobj.h>
9 #include <vsstyle.h> 9 #include <vsstyle.h>
10 #include <vssym32.h> 10 #include <vssym32.h>
(...skipping 20 matching lines...) Expand all
31 #include "views/grid_layout.h" 31 #include "views/grid_layout.h"
32 #include "views/standard_layout.h" 32 #include "views/standard_layout.h"
33 #include "views/widget/widget.h" 33 #include "views/widget/widget.h"
34 34
35 namespace { 35 namespace {
36 36
37 static std::vector<CharacterEncoding::EncodingInfo> sorted_encoding_list; 37 static std::vector<CharacterEncoding::EncodingInfo> sorted_encoding_list;
38 38
39 } // namespace 39 } // namespace
40 40
41 class DefaultEncodingComboboxModel : public views::ComboBox::Model { 41 class DefaultEncodingComboboxModel : public views::Combobox::Model {
42 public: 42 public:
43 DefaultEncodingComboboxModel() { 43 DefaultEncodingComboboxModel() {
44 canonical_encoding_names_length_ = 44 canonical_encoding_names_length_ =
45 CharacterEncoding::GetSupportCanonicalEncodingCount(); 45 CharacterEncoding::GetSupportCanonicalEncodingCount();
46 // Initialize the vector of all sorted encodings according to current 46 // Initialize the vector of all sorted encodings according to current
47 // UI locale. 47 // UI locale.
48 if (!sorted_encoding_list.size()) { 48 if (!sorted_encoding_list.size()) {
49 std::wstring locale = g_browser_process->GetApplicationLocale(); 49 std::wstring locale = g_browser_process->GetApplicationLocale();
50 for (int i = 0; i < canonical_encoding_names_length_; i++) { 50 for (int i = 0; i < canonical_encoding_names_length_; i++) {
51 sorted_encoding_list.push_back(CharacterEncoding::EncodingInfo( 51 sorted_encoding_list.push_back(CharacterEncoding::EncodingInfo(
52 CharacterEncoding::GetEncodingCommandIdByIndex(i))); 52 CharacterEncoding::GetEncodingCommandIdByIndex(i)));
53 } 53 }
54 l10n_util::SortVectorWithStringKey(locale, &sorted_encoding_list, true); 54 l10n_util::SortVectorWithStringKey(locale, &sorted_encoding_list, true);
55 } 55 }
56 } 56 }
57 57
58 virtual ~DefaultEncodingComboboxModel() {} 58 virtual ~DefaultEncodingComboboxModel() {}
59 59
60 // Overridden from views::Combobox::Model. 60 // Overridden from views::Combobox::Model.
61 virtual int GetItemCount(views::ComboBox* source) { 61 virtual int GetItemCount(views::Combobox* source) {
62 return canonical_encoding_names_length_; 62 return canonical_encoding_names_length_;
63 } 63 }
64 64
65 virtual std::wstring GetItemAt(views::ComboBox* source, int index) { 65 virtual std::wstring GetItemAt(views::Combobox* source, int index) {
66 DCHECK(index >= 0 && canonical_encoding_names_length_ > index); 66 DCHECK(index >= 0 && canonical_encoding_names_length_ > index);
67 return sorted_encoding_list[index].encoding_display_name; 67 return sorted_encoding_list[index].encoding_display_name;
68 } 68 }
69 69
70 std::wstring GetEncodingCharsetByIndex(int index) { 70 std::wstring GetEncodingCharsetByIndex(int index) {
71 DCHECK(index >= 0 && canonical_encoding_names_length_ > index); 71 DCHECK(index >= 0 && canonical_encoding_names_length_ > index);
72 int encoding_id = sorted_encoding_list[index].encoding_id; 72 int encoding_id = sorted_encoding_list[index].encoding_id;
73 return CharacterEncoding::GetCanonicalEncodingNameByCommandId(encoding_id); 73 return CharacterEncoding::GetCanonicalEncodingNameByCommandId(encoding_id);
74 } 74 }
75 75
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 font_name = fixed_width_font_display_view_->font_name(); 246 font_name = fixed_width_font_display_view_->font_name();
247 font_size = fixed_width_font_size_pixel_; 247 font_size = fixed_width_font_size_pixel_;
248 } else { 248 } else {
249 NOTREACHED(); 249 NOTREACHED();
250 return; 250 return;
251 } 251 }
252 252
253 select_font_dialog_->SelectFont(owning_hwnd, NULL, font_name, font_size); 253 select_font_dialog_->SelectFont(owning_hwnd, NULL, font_name, font_size);
254 } 254 }
255 255
256 void FontsPageView::ItemChanged(views::ComboBox* combo_box, 256 void FontsPageView::ItemChanged(views::Combobox* combo_box,
257 int prev_index, int new_index) { 257 int prev_index, int new_index) {
258 if (combo_box == default_encoding_combobox_) { 258 if (combo_box == default_encoding_combobox_) {
259 if (prev_index != new_index) { // Default-Encoding has been changed. 259 if (prev_index != new_index) { // Default-Encoding has been changed.
260 encoding_dropdown_clicked_ = true; 260 encoding_dropdown_clicked_ = true;
261 default_encoding_selected_ = default_encoding_combobox_model_-> 261 default_encoding_selected_ = default_encoding_combobox_model_->
262 GetEncodingCharsetByIndex(new_index); 262 GetEncodingCharsetByIndex(new_index);
263 default_encoding_changed_ = true; 263 default_encoding_changed_ = true;
264 } 264 }
265 } 265 }
266 } 266 }
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 GridLayout::FILL, GridLayout::CENTER); 456 GridLayout::FILL, GridLayout::CENTER);
457 layout->AddView(fixed_width_font_change_page_button_); 457 layout->AddView(fixed_width_font_change_page_button_);
458 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); 458 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
459 } 459 }
460 460
461 void FontsPageView::InitEncodingLayout() { 461 void FontsPageView::InitEncodingLayout() {
462 default_encoding_combobox_label_ = new views::Label( 462 default_encoding_combobox_label_ = new views::Label(
463 l10n_util::GetString( 463 l10n_util::GetString(
464 IDS_FONT_LANGUAGE_SETTING_FONT_DEFAULT_ENCODING_SELECTOR_LABEL)); 464 IDS_FONT_LANGUAGE_SETTING_FONT_DEFAULT_ENCODING_SELECTOR_LABEL));
465 default_encoding_combobox_model_.reset(new DefaultEncodingComboboxModel); 465 default_encoding_combobox_model_.reset(new DefaultEncodingComboboxModel);
466 default_encoding_combobox_ = new views::ComboBox( 466 default_encoding_combobox_ = new views::Combobox(
467 default_encoding_combobox_model_.get()); 467 default_encoding_combobox_model_.get());
468 int selected_encoding_index = default_encoding_combobox_model_-> 468 int selected_encoding_index = default_encoding_combobox_model_->
469 GetSelectedEncodingIndex(profile()); 469 GetSelectedEncodingIndex(profile());
470 default_encoding_combobox_->SetSelectedItem(selected_encoding_index); 470 default_encoding_combobox_->SetSelectedItem(selected_encoding_index);
471 default_encoding_selected_ = default_encoding_combobox_model_-> 471 default_encoding_selected_ = default_encoding_combobox_model_->
472 GetEncodingCharsetByIndex(selected_encoding_index); 472 GetEncodingCharsetByIndex(selected_encoding_index);
473 default_encoding_combobox_->SetListener(this); 473 default_encoding_combobox_->set_listener(this);
474 474
475 // Now add the views. 475 // Now add the views.
476 using views::GridLayout; 476 using views::GridLayout;
477 using views::ColumnSet; 477 using views::ColumnSet;
478 478
479 encoding_contents_ = new views::View; 479 encoding_contents_ = new views::View;
480 GridLayout* layout = new GridLayout(encoding_contents_); 480 GridLayout* layout = new GridLayout(encoding_contents_);
481 encoding_contents_->SetLayoutManager(layout); 481 encoding_contents_->SetLayoutManager(layout);
482 482
483 // Double column. 483 // Double column.
484 const int double_column_view_set_id = 2; 484 const int double_column_view_set_id = 2;
485 ColumnSet* column_set = layout->AddColumnSet(double_column_view_set_id); 485 ColumnSet* column_set = layout->AddColumnSet(double_column_view_set_id);
486 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 0, 486 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 0,
487 GridLayout::USE_PREF, 0, 0); 487 GridLayout::USE_PREF, 0, 0);
488 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); 488 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing);
489 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, 489 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
490 GridLayout::USE_PREF, 0, 0); 490 GridLayout::USE_PREF, 0, 0);
491 491
492 // Add Encoding ComboBox. 492 // Add Encoding Combobox.
493 layout->StartRow(0, double_column_view_set_id); 493 layout->StartRow(0, double_column_view_set_id);
494 layout->AddView(default_encoding_combobox_label_); 494 layout->AddView(default_encoding_combobox_label_);
495 layout->AddView(default_encoding_combobox_, 1, 1, GridLayout::FILL, 495 layout->AddView(default_encoding_combobox_, 1, 1, GridLayout::FILL,
496 GridLayout::CENTER); 496 GridLayout::CENTER);
497 } 497 }
OLDNEW
« no previous file with comments | « chrome/browser/views/options/fonts_page_view.h ('k') | chrome/browser/views/options/general_page_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698