OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/examples/native_theme_button_example.h" | 5 #include "ui/views/examples/native_theme_button_example.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 return base::StringPrintf(message, ++count_); | 91 return base::StringPrintf(message, ++count_); |
92 } | 92 } |
93 | 93 |
94 void ExampleNativeThemeButton::ItemChanged(Combobox* combo_box, | 94 void ExampleNativeThemeButton::ItemChanged(Combobox* combo_box, |
95 int prev_index, | 95 int prev_index, |
96 int new_index) { | 96 int new_index) { |
97 SchedulePaint(); | 97 SchedulePaint(); |
98 } | 98 } |
99 | 99 |
100 gfx::NativeTheme::Part ExampleNativeThemeButton::GetThemePart() const { | 100 gfx::NativeTheme::Part ExampleNativeThemeButton::GetThemePart() const { |
101 int selected = cb_part_->selected_item(); | 101 switch (cb_part_->selected_index()) { |
102 switch (selected) { | |
103 case 0: | 102 case 0: |
104 return gfx::NativeTheme::kPushButton; | 103 return gfx::NativeTheme::kPushButton; |
105 case 1: | 104 case 1: |
106 return gfx::NativeTheme::kRadio; | 105 return gfx::NativeTheme::kRadio; |
107 case 2: | 106 case 2: |
108 return gfx::NativeTheme::kCheckbox; | 107 return gfx::NativeTheme::kCheckbox; |
109 default: | 108 default: |
110 DCHECK(false); | 109 DCHECK(false); |
111 } | 110 } |
112 return gfx::NativeTheme::kPushButton; | 111 return gfx::NativeTheme::kPushButton; |
113 } | 112 } |
114 | 113 |
115 gfx::Rect ExampleNativeThemeButton::GetThemePaintRect() const { | 114 gfx::Rect ExampleNativeThemeButton::GetThemePaintRect() const { |
116 gfx::NativeTheme::ExtraParams extra; | 115 gfx::NativeTheme::ExtraParams extra; |
117 gfx::NativeTheme::State state = GetThemeState(&extra); | 116 gfx::NativeTheme::State state = GetThemeState(&extra); |
118 gfx::Size size(gfx::NativeTheme::instance()->GetPartSize(GetThemePart(), | 117 gfx::Size size(gfx::NativeTheme::instance()->GetPartSize(GetThemePart(), |
119 state, | 118 state, |
120 extra)); | 119 extra)); |
121 gfx::Rect rect(size); | 120 gfx::Rect rect(size); |
122 rect.set_x(GetMirroredXForRect(rect)); | 121 rect.set_x(GetMirroredXForRect(rect)); |
123 return rect; | 122 return rect; |
124 } | 123 } |
125 | 124 |
126 gfx::NativeTheme::State ExampleNativeThemeButton::GetThemeState( | 125 gfx::NativeTheme::State ExampleNativeThemeButton::GetThemeState( |
127 gfx::NativeTheme::ExtraParams* params) const { | 126 gfx::NativeTheme::ExtraParams* params) const { |
128 GetExtraParams(params); | 127 GetExtraParams(params); |
129 | 128 |
130 int selected = cb_state_->selected_item(); | 129 int selected = cb_state_->selected_index(); |
131 if (selected > 3) { | 130 if (selected > 3) { |
132 switch (state()) { | 131 switch (state()) { |
133 case BS_DISABLED: | 132 case BS_DISABLED: |
134 return gfx::NativeTheme::kDisabled; | 133 return gfx::NativeTheme::kDisabled; |
135 case BS_NORMAL: | 134 case BS_NORMAL: |
136 return gfx::NativeTheme::kNormal; | 135 return gfx::NativeTheme::kNormal; |
137 case BS_HOT: | 136 case BS_HOT: |
138 return gfx::NativeTheme::kHovered; | 137 return gfx::NativeTheme::kHovered; |
139 case BS_PUSHED: | 138 case BS_PUSHED: |
140 return gfx::NativeTheme::kPressed; | 139 return gfx::NativeTheme::kPressed; |
(...skipping 22 matching lines...) Expand all Loading... |
163 | 162 |
164 params->button.checked = is_checked_; | 163 params->button.checked = is_checked_; |
165 params->button.indeterminate = is_indeterminate_; | 164 params->button.indeterminate = is_indeterminate_; |
166 params->button.is_default = false; | 165 params->button.is_default = false; |
167 params->button.has_border = false; | 166 params->button.has_border = false; |
168 params->button.classic_state = 0; | 167 params->button.classic_state = 0; |
169 params->button.background_color = SkColorSetARGB(0, 0, 0, 0); | 168 params->button.background_color = SkColorSetARGB(0, 0, 0, 0); |
170 } | 169 } |
171 | 170 |
172 const ui::Animation* ExampleNativeThemeButton::GetThemeAnimation() const { | 171 const ui::Animation* ExampleNativeThemeButton::GetThemeAnimation() const { |
173 int selected = cb_state_->selected_item(); | 172 return cb_state_->selected_index() <= 3 ? NULL : hover_animation_.get(); |
174 return selected <= 3 ? NULL : hover_animation_.get(); | |
175 } | 173 } |
176 | 174 |
177 gfx::NativeTheme::State ExampleNativeThemeButton::GetBackgroundThemeState( | 175 gfx::NativeTheme::State ExampleNativeThemeButton::GetBackgroundThemeState( |
178 gfx::NativeTheme::ExtraParams* params) const { | 176 gfx::NativeTheme::ExtraParams* params) const { |
179 GetExtraParams(params); | 177 GetExtraParams(params); |
180 return gfx::NativeTheme::kNormal; | 178 return gfx::NativeTheme::kNormal; |
181 } | 179 } |
182 | 180 |
183 gfx::NativeTheme::State ExampleNativeThemeButton::GetForegroundThemeState( | 181 gfx::NativeTheme::State ExampleNativeThemeButton::GetForegroundThemeState( |
184 gfx::NativeTheme::ExtraParams* params) const { | 182 gfx::NativeTheme::ExtraParams* params) const { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, | 215 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, |
218 0.1f, GridLayout::USE_PREF, 0, 0); | 216 0.1f, GridLayout::USE_PREF, 0, 0); |
219 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, | 217 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, |
220 0.9f, GridLayout::USE_PREF, 0, 0); | 218 0.9f, GridLayout::USE_PREF, 0, 0); |
221 column_set->AddPaddingColumn(0, 8); | 219 column_set->AddPaddingColumn(0, 8); |
222 | 220 |
223 layout->StartRow(0, 0); | 221 layout->StartRow(0, 0); |
224 layout->AddView(new Label(ASCIIToUTF16("Part:"))); | 222 layout->AddView(new Label(ASCIIToUTF16("Part:"))); |
225 Combobox* cb_part = new Combobox( | 223 Combobox* cb_part = new Combobox( |
226 new ExampleComboboxModel(kParts, arraysize(kParts))); | 224 new ExampleComboboxModel(kParts, arraysize(kParts))); |
227 cb_part->SetSelectedItem(0); | 225 cb_part->SetSelectedIndex(0); |
228 layout->AddView(cb_part); | 226 layout->AddView(cb_part); |
229 | 227 |
230 layout->StartRow(0, 0); | 228 layout->StartRow(0, 0); |
231 layout->AddView(new Label(ASCIIToUTF16("State:"))); | 229 layout->AddView(new Label(ASCIIToUTF16("State:"))); |
232 Combobox* cb_state = new Combobox( | 230 Combobox* cb_state = new Combobox( |
233 new ExampleComboboxModel(kStates, arraysize(kStates))); | 231 new ExampleComboboxModel(kStates, arraysize(kStates))); |
234 cb_state->SetSelectedItem(0); | 232 cb_state->SetSelectedIndex(0); |
235 layout->AddView(cb_state); | 233 layout->AddView(cb_state); |
236 | 234 |
237 layout->AddPaddingRow(0, 32); | 235 layout->AddPaddingRow(0, 32); |
238 | 236 |
239 button_ = new ExampleNativeThemeButton(this, cb_part, cb_state); | 237 button_ = new ExampleNativeThemeButton(this, cb_part, cb_state); |
240 | 238 |
241 column_set = layout->AddColumnSet(1); | 239 column_set = layout->AddColumnSet(1); |
242 column_set->AddPaddingColumn(0, 16); | 240 column_set->AddPaddingColumn(0, 16); |
243 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, | 241 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, |
244 1, GridLayout::USE_PREF, 0, 0); | 242 1, GridLayout::USE_PREF, 0, 0); |
245 column_set->AddPaddingColumn(0, 16); | 243 column_set->AddPaddingColumn(0, 16); |
246 layout->StartRow(1, 1); | 244 layout->StartRow(1, 1); |
247 layout->AddView(button_); | 245 layout->AddView(button_); |
248 | 246 |
249 layout->AddPaddingRow(0, 8); | 247 layout->AddPaddingRow(0, 8); |
250 } | 248 } |
251 | 249 |
252 void NativeThemeButtonExample::ButtonPressed(Button* sender, | 250 void NativeThemeButtonExample::ButtonPressed(Button* sender, |
253 const Event& event) { | 251 const Event& event) { |
254 PrintStatus(button_->MessWithState().c_str()); | 252 PrintStatus(button_->MessWithState().c_str()); |
255 } | 253 } |
256 | 254 |
257 } // namespace examples | 255 } // namespace examples |
258 } // namespace views | 256 } // namespace views |
OLD | NEW |