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

Side by Side Diff: chrome/browser/ui/views/options/options_group_view.cc

Issue 6670011: Options: Remove the GTK and Views native options code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 9 years, 9 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
(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 #include <vsstyle.h>
6 #include <vssym32.h>
7
8 #include "chrome/browser/ui/views/options/options_group_view.h"
9
10 #include "base/string_number_conversions.h"
11 #include "base/utf_string_conversions.h"
12 #include "grit/locale_settings.h"
13 #include "grit/generated_resources.h"
14 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/gfx/canvas.h"
17 #include "ui/gfx/font.h"
18 #include "ui/gfx/native_theme_win.h"
19 #include "views/controls/label.h"
20 #include "views/controls/separator.h"
21 #include "views/layout/grid_layout.h"
22 #include "views/layout/layout_constants.h"
23
24 static const int kLeftColumnWidthChars = 20;
25 static const int kOptionsGroupViewColumnSpacing = 30;
26
27 ///////////////////////////////////////////////////////////////////////////////
28 // OptionsGroupView, public:
29
30 OptionsGroupView::OptionsGroupView(views::View* contents,
31 const std::wstring& title,
32 const std::wstring& description,
33 bool show_separator)
34 : contents_(contents),
35 title_label_(new views::Label(title)),
36 description_label_(new views::Label(description)),
37 separator_(NULL),
38 show_separator_(show_separator),
39 highlighted_(false) {
40 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
41 const gfx::Font& title_font =
42 rb.GetFont(ResourceBundle::BaseFont).DeriveFont(0, gfx::Font::BOLD);
43 title_label_->SetFont(title_font);
44 SkColor title_color = gfx::NativeTheme::instance()->GetThemeColorWithDefault(
45 gfx::NativeTheme::BUTTON, BP_GROUPBOX, GBS_NORMAL, TMT_TEXTCOLOR,
46 COLOR_WINDOWTEXT);
47 title_label_->SetColor(title_color);
48 title_label_->SetMultiLine(true);
49 title_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
50
51 description_label_->SetMultiLine(true);
52 description_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
53
54 SetAccessibleName(WideToUTF16Hack(title));
55 contents->SetAccessibleName(WideToUTF16Hack(title));
56 }
57
58 OptionsGroupView::~OptionsGroupView() {
59 }
60
61 void OptionsGroupView::SetHighlighted(bool highlighted) {
62 highlighted_ = highlighted;
63 SchedulePaint();
64 }
65
66 int OptionsGroupView::GetContentsWidth() const {
67 return contents_->width();
68 }
69
70 ///////////////////////////////////////////////////////////////////////////////
71 // OptionsGroupView, views::View overrides:
72
73 AccessibilityTypes::Role OptionsGroupView::GetAccessibleRole() {
74 return AccessibilityTypes::ROLE_GROUPING;
75 }
76
77 void OptionsGroupView::OnPaint(gfx::Canvas* canvas) {
78 if (highlighted_) {
79 COLORREF infocolor = GetSysColor(COLOR_INFOBK);
80 SkColor background_color = SkColorSetRGB(GetRValue(infocolor),
81 GetGValue(infocolor),
82 GetBValue(infocolor));
83 int y_offset = views::kUnrelatedControlVerticalSpacing / 2;
84 canvas->FillRectInt(background_color, 0, 0, width(),
85 height() - y_offset);
86 }
87 }
88
89 void OptionsGroupView::ViewHierarchyChanged(bool is_add,
90 views::View* parent,
91 views::View* child) {
92 if (is_add && child == this)
93 Init();
94 }
95
96 ///////////////////////////////////////////////////////////////////////////////
97 // OptionsGroupView, private:
98
99 void OptionsGroupView::Init() {
100 using views::GridLayout;
101 using views::ColumnSet;
102
103 GridLayout* layout = new GridLayout(this);
104 SetLayoutManager(layout);
105
106 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
107 const gfx::Font& font = rb.GetFont(ResourceBundle::BaseFont);
108 int left_column_chars = 0;
109 base::StringToInt(
110 l10n_util::GetStringUTF16(IDS_OPTIONS_DIALOG_LEFT_COLUMN_WIDTH_CHARS),
111 &left_column_chars);
112 int left_column_width = font.GetExpectedTextWidth(left_column_chars);
113
114 const int two_column_layout_id = 0;
115 ColumnSet* column_set = layout->AddColumnSet(two_column_layout_id);
116 column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
117 column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0,
118 GridLayout::FIXED, left_column_width, 0);
119 column_set->AddPaddingColumn(0, kOptionsGroupViewColumnSpacing);
120 column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 1,
121 GridLayout::USE_PREF, 0, 0);
122 column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
123
124 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
125 layout->StartRow(0, two_column_layout_id);
126 layout->AddView(title_label_, 1, 1, GridLayout::FILL, GridLayout::LEADING);
127 layout->AddView(contents_, 1, 3, GridLayout::FILL, GridLayout::FILL);
128 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
129 layout->StartRow(1, two_column_layout_id);
130 layout->AddView(description_label_, 1, 1,
131 GridLayout::FILL, GridLayout::LEADING);
132 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing);
133
134 if (show_separator_) {
135 const int single_column_layout_id = 1;
136 column_set = layout->AddColumnSet(single_column_layout_id);
137 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1,
138 GridLayout::USE_PREF, 0, 0);
139
140 separator_ = new views::Separator;
141 layout->StartRow(0, single_column_layout_id);
142 layout->AddView(separator_);
143 }
144 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/options/options_group_view.h ('k') | chrome/browser/ui/views/options/options_page_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698