| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 18 matching lines...) Expand all Loading... |
| 29 const char* kStates[] = { | 29 const char* kStates[] = { |
| 30 "Disabled", | 30 "Disabled", |
| 31 "Normal", | 31 "Normal", |
| 32 "Hot", | 32 "Hot", |
| 33 "Pressed", | 33 "Pressed", |
| 34 "<Dynamic>", | 34 "<Dynamic>", |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 } // namespace | 37 } // namespace |
| 38 | 38 |
| 39 namespace views { |
| 39 namespace examples { | 40 namespace examples { |
| 40 | 41 |
| 41 ExampleNativeThemeButton::ExampleNativeThemeButton( | 42 ExampleNativeThemeButton::ExampleNativeThemeButton( |
| 42 views::ButtonListener* listener, | 43 ButtonListener* listener, |
| 43 views::Combobox* cb_part, | 44 Combobox* cb_part, |
| 44 views::Combobox* cb_state) | 45 Combobox* cb_state) |
| 45 : CustomButton(listener), | 46 : CustomButton(listener), |
| 46 cb_part_(cb_part), | 47 cb_part_(cb_part), |
| 47 cb_state_(cb_state), | 48 cb_state_(cb_state), |
| 48 count_(0), | 49 count_(0), |
| 49 is_checked_(false), | 50 is_checked_(false), |
| 50 is_indeterminate_(false) { | 51 is_indeterminate_(false) { |
| 51 cb_part_->set_listener(this); | 52 cb_part_->set_listener(this); |
| 52 cb_state_->set_listener(this); | 53 cb_state_->set_listener(this); |
| 53 | 54 |
| 54 painter_.reset(new views::NativeThemePainter(this)); | 55 painter_.reset(new NativeThemePainter(this)); |
| 55 set_background(views::Background::CreateBackgroundPainter( | 56 set_background(Background::CreateBackgroundPainter( |
| 56 false, painter_.get())); | 57 false, painter_.get())); |
| 57 } | 58 } |
| 58 | 59 |
| 59 ExampleNativeThemeButton::~ExampleNativeThemeButton() { | 60 ExampleNativeThemeButton::~ExampleNativeThemeButton() { |
| 60 } | 61 } |
| 61 | 62 |
| 62 std::string ExampleNativeThemeButton::MessWithState() { | 63 std::string ExampleNativeThemeButton::MessWithState() { |
| 63 const char* message = NULL; | 64 const char* message = NULL; |
| 64 switch (GetThemePart()) { | 65 switch (GetThemePart()) { |
| 65 case gfx::NativeTheme::kPushButton: | 66 case gfx::NativeTheme::kPushButton: |
| (...skipping 17 matching lines...) Expand all Loading... |
| 83 message = is_checked_ ? "Checked! count:%d" : | 84 message = is_checked_ ? "Checked! count:%d" : |
| 84 is_indeterminate_ ? "Indeterminate! count:%d" : "Unchecked! count:%d"; | 85 is_indeterminate_ ? "Indeterminate! count:%d" : "Unchecked! count:%d"; |
| 85 break; | 86 break; |
| 86 default: | 87 default: |
| 87 DCHECK(false); | 88 DCHECK(false); |
| 88 } | 89 } |
| 89 | 90 |
| 90 return base::StringPrintf(message, ++count_); | 91 return base::StringPrintf(message, ++count_); |
| 91 } | 92 } |
| 92 | 93 |
| 93 void ExampleNativeThemeButton::ItemChanged(views::Combobox* combo_box, | 94 void ExampleNativeThemeButton::ItemChanged(Combobox* combo_box, |
| 94 int prev_index, | 95 int prev_index, |
| 95 int new_index) { | 96 int new_index) { |
| 96 SchedulePaint(); | 97 SchedulePaint(); |
| 97 } | 98 } |
| 98 | 99 |
| 99 gfx::NativeTheme::Part ExampleNativeThemeButton::GetThemePart() const { | 100 gfx::NativeTheme::Part ExampleNativeThemeButton::GetThemePart() const { |
| 100 int selected = cb_part_->selected_item(); | 101 int selected = cb_part_->selected_item(); |
| 101 switch (selected) { | 102 switch (selected) { |
| 102 case 0: | 103 case 0: |
| 103 return gfx::NativeTheme::kPushButton; | 104 return gfx::NativeTheme::kPushButton; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 192 |
| 192 void ExampleNativeThemeButton::OnPaintBackground(gfx::Canvas* canvas) { | 193 void ExampleNativeThemeButton::OnPaintBackground(gfx::Canvas* canvas) { |
| 193 // Fill the background with a known colour so that we know where the bounds | 194 // Fill the background with a known colour so that we know where the bounds |
| 194 // of the View are. | 195 // of the View are. |
| 195 canvas->FillRect(SkColorSetRGB(255, 128, 128), GetLocalBounds()); | 196 canvas->FillRect(SkColorSetRGB(255, 128, 128), GetLocalBounds()); |
| 196 CustomButton::OnPaintBackground(canvas); | 197 CustomButton::OnPaintBackground(canvas); |
| 197 } | 198 } |
| 198 | 199 |
| 199 //////////////////////////////////////////////////////////////////////////////// | 200 //////////////////////////////////////////////////////////////////////////////// |
| 200 | 201 |
| 201 NativeThemeButtonExample::NativeThemeButtonExample(ExamplesMain* main) | 202 NativeThemeButtonExample::NativeThemeButtonExample() |
| 202 : ExampleBase(main, "Native Theme Button") { | 203 : ExampleBase("Native Theme Button") { |
| 203 } | 204 } |
| 204 | 205 |
| 205 NativeThemeButtonExample::~NativeThemeButtonExample() { | 206 NativeThemeButtonExample::~NativeThemeButtonExample() { |
| 206 } | 207 } |
| 207 | 208 |
| 208 void NativeThemeButtonExample::CreateExampleView(views::View* container) { | 209 void NativeThemeButtonExample::CreateExampleView(View* container) { |
| 209 views::GridLayout* layout = new views::GridLayout(container); | 210 GridLayout* layout = new GridLayout(container); |
| 210 container->SetLayoutManager(layout); | 211 container->SetLayoutManager(layout); |
| 211 | 212 |
| 212 layout->AddPaddingRow(0, 8); | 213 layout->AddPaddingRow(0, 8); |
| 213 | 214 |
| 214 views::ColumnSet* column_set = layout->AddColumnSet(0); | 215 ColumnSet* column_set = layout->AddColumnSet(0); |
| 215 column_set->AddPaddingColumn(0, 8); | 216 column_set->AddPaddingColumn(0, 8); |
| 216 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, | 217 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, |
| 217 0.1f, views::GridLayout::USE_PREF, 0, 0); | 218 0.1f, GridLayout::USE_PREF, 0, 0); |
| 218 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | 219 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, |
| 219 0.9f, views::GridLayout::USE_PREF, 0, 0); | 220 0.9f, GridLayout::USE_PREF, 0, 0); |
| 220 column_set->AddPaddingColumn(0, 8); | 221 column_set->AddPaddingColumn(0, 8); |
| 221 | 222 |
| 222 layout->StartRow(0, 0); | 223 layout->StartRow(0, 0); |
| 223 layout->AddView(new views::Label(ASCIIToUTF16("Part:"))); | 224 layout->AddView(new Label(ASCIIToUTF16("Part:"))); |
| 224 views::Combobox* cb_part = new views::Combobox( | 225 Combobox* cb_part = new Combobox( |
| 225 new ExampleComboboxModel(kParts, arraysize(kParts))); | 226 new ExampleComboboxModel(kParts, arraysize(kParts))); |
| 226 cb_part->SetSelectedItem(0); | 227 cb_part->SetSelectedItem(0); |
| 227 layout->AddView(cb_part); | 228 layout->AddView(cb_part); |
| 228 | 229 |
| 229 layout->StartRow(0, 0); | 230 layout->StartRow(0, 0); |
| 230 layout->AddView(new views::Label(ASCIIToUTF16("State:"))); | 231 layout->AddView(new Label(ASCIIToUTF16("State:"))); |
| 231 views::Combobox* cb_state = new views::Combobox( | 232 Combobox* cb_state = new Combobox( |
| 232 new ExampleComboboxModel(kStates, arraysize(kStates))); | 233 new ExampleComboboxModel(kStates, arraysize(kStates))); |
| 233 cb_state->SetSelectedItem(0); | 234 cb_state->SetSelectedItem(0); |
| 234 layout->AddView(cb_state); | 235 layout->AddView(cb_state); |
| 235 | 236 |
| 236 layout->AddPaddingRow(0, 32); | 237 layout->AddPaddingRow(0, 32); |
| 237 | 238 |
| 238 button_ = new ExampleNativeThemeButton(this, cb_part, cb_state); | 239 button_ = new ExampleNativeThemeButton(this, cb_part, cb_state); |
| 239 | 240 |
| 240 column_set = layout->AddColumnSet(1); | 241 column_set = layout->AddColumnSet(1); |
| 241 column_set->AddPaddingColumn(0, 16); | 242 column_set->AddPaddingColumn(0, 16); |
| 242 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | 243 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, |
| 243 1, views::GridLayout::USE_PREF, 0, 0); | 244 1, GridLayout::USE_PREF, 0, 0); |
| 244 column_set->AddPaddingColumn(0, 16); | 245 column_set->AddPaddingColumn(0, 16); |
| 245 layout->StartRow(1, 1); | 246 layout->StartRow(1, 1); |
| 246 layout->AddView(button_); | 247 layout->AddView(button_); |
| 247 | 248 |
| 248 layout->AddPaddingRow(0, 8); | 249 layout->AddPaddingRow(0, 8); |
| 249 } | 250 } |
| 250 | 251 |
| 251 void NativeThemeButtonExample::ButtonPressed(views::Button* sender, | 252 void NativeThemeButtonExample::ButtonPressed(Button* sender, |
| 252 const views::Event& event) { | 253 const Event& event) { |
| 253 PrintStatus(button_->MessWithState().c_str()); | 254 PrintStatus(button_->MessWithState().c_str()); |
| 254 } | 255 } |
| 255 | 256 |
| 256 } // namespace examples | 257 } // namespace examples |
| 258 } // namespace views |
| OLD | NEW |