| 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/button_example.h" | 5 #include "ui/views/examples/button_example.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "grit/ui_resources.h" | 8 #include "grit/ui_resources.h" |
| 9 #include "ui/base/resource/resource_bundle.h" | 9 #include "ui/base/resource/resource_bundle.h" |
| 10 #include "ui/gfx/image/image.h" | 10 #include "ui/gfx/image/image.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 ButtonExample::ButtonExample() | 23 ButtonExample::ButtonExample() |
| 24 : ExampleBase("Button"), | 24 : ExampleBase("Button"), |
| 25 text_button_(NULL), | 25 text_button_(NULL), |
| 26 image_button_(NULL), | 26 image_button_(NULL), |
| 27 alignment_(TextButton::ALIGN_LEFT), | 27 alignment_(TextButton::ALIGN_LEFT), |
| 28 use_native_theme_border_(false), | 28 use_native_theme_border_(false), |
| 29 icon_(NULL), | 29 icon_(NULL), |
| 30 count_(0) { | 30 count_(0) { |
| 31 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 31 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 32 icon_ = rb.GetImageNamed(IDR_CLOSE_SA_H).ToSkBitmap(); | 32 icon_ = rb.GetImageNamed(IDR_CLOSE_SA_H).ToImageSkia(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 ButtonExample::~ButtonExample() { | 35 ButtonExample::~ButtonExample() { |
| 36 } | 36 } |
| 37 | 37 |
| 38 void ButtonExample::CreateExampleView(View* container) { | 38 void ButtonExample::CreateExampleView(View* container) { |
| 39 container->SetLayoutManager( | 39 container->SetLayoutManager( |
| 40 new BoxLayout(BoxLayout::kVertical, 0, 0, kLayoutSpacing)); | 40 new BoxLayout(BoxLayout::kVertical, 0, 0, kLayoutSpacing)); |
| 41 | 41 |
| 42 text_button_ = new TextButton(this, ASCIIToUTF16("Text Button")); | 42 text_button_ = new TextButton(this, ASCIIToUTF16("Text Button")); |
| 43 container->AddChildView(text_button_); | 43 container->AddChildView(text_button_); |
| 44 | 44 |
| 45 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 45 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 46 image_button_ = new ImageButton(this); | 46 image_button_ = new ImageButton(this); |
| 47 image_button_->SetImage(ImageButton::BS_NORMAL, | 47 image_button_->SetImage(ImageButton::BS_NORMAL, |
| 48 rb.GetImageNamed(IDR_CLOSE).ToImageSkia()); | 48 rb.GetImageNamed(IDR_CLOSE).ToImageSkia()); |
| 49 image_button_->SetImage(ImageButton::BS_HOT, | 49 image_button_->SetImage(ImageButton::BS_HOT, |
| 50 rb.GetImageNamed(IDR_CLOSE_H).ToImageSkia()); | 50 rb.GetImageNamed(IDR_CLOSE_H).ToImageSkia()); |
| 51 image_button_->SetImage(ImageButton::BS_PUSHED, | 51 image_button_->SetImage(ImageButton::BS_PUSHED, |
| 52 rb.GetImageNamed(IDR_CLOSE_P).ToImageSkia()); | 52 rb.GetImageNamed(IDR_CLOSE_P).ToImageSkia()); |
| 53 image_button_->SetOverlayImage(rb.GetImageNamed(IDR_MENU_CHECK).ToSkBitmap()); | 53 image_button_->SetOverlayImage(rb.GetImageNamed( |
| 54 IDR_MENU_CHECK).ToImageSkia()); |
| 54 container->AddChildView(image_button_); | 55 container->AddChildView(image_button_); |
| 55 } | 56 } |
| 56 | 57 |
| 57 void ButtonExample::ButtonPressed(Button* sender, const Event& event) { | 58 void ButtonExample::ButtonPressed(Button* sender, const Event& event) { |
| 58 PrintStatus("Pressed! count: %d", ++count_); | 59 PrintStatus("Pressed! count: %d", ++count_); |
| 59 | 60 |
| 60 if (event.IsControlDown()) { | 61 if (event.IsControlDown()) { |
| 61 if (event.IsShiftDown()) { | 62 if (event.IsShiftDown()) { |
| 62 if (event.IsAltDown()) { | 63 if (event.IsAltDown()) { |
| 63 text_button_->SetMultiLine(!text_button_->multi_line()); | 64 text_button_->SetMultiLine(!text_button_->multi_line()); |
| 64 if (text_button_->multi_line()) { | 65 if (text_button_->multi_line()) { |
| 65 text_button_->SetText(ASCIIToUTF16("Multi-line text\n") + | 66 text_button_->SetText(ASCIIToUTF16("Multi-line text\n") + |
| 66 ASCIIToUTF16("is here to stay all the way!\n") + | 67 ASCIIToUTF16("is here to stay all the way!\n") + |
| 67 ASCIIToUTF16("123")); | 68 ASCIIToUTF16("123")); |
| 68 } else { | 69 } else { |
| 69 text_button_->SetText(ASCIIToUTF16("Button")); | 70 text_button_->SetText(ASCIIToUTF16("Button")); |
| 70 } | 71 } |
| 71 } else { | 72 } else { |
| 72 switch (text_button_->icon_placement()) { | 73 switch (text_button_->icon_placement()) { |
| 73 case TextButton::ICON_ON_LEFT: | 74 case TextButton::ICON_ON_LEFT: |
| 74 text_button_->set_icon_placement(TextButton::ICON_ON_RIGHT); | 75 text_button_->set_icon_placement(TextButton::ICON_ON_RIGHT); |
| 75 break; | 76 break; |
| 76 case TextButton::ICON_ON_RIGHT: | 77 case TextButton::ICON_ON_RIGHT: |
| 77 text_button_->set_icon_placement(TextButton::ICON_ON_LEFT); | 78 text_button_->set_icon_placement(TextButton::ICON_ON_LEFT); |
| 78 break; | 79 break; |
| 79 } | 80 } |
| 80 } | 81 } |
| 81 } else if (event.IsAltDown()) { | 82 } else if (event.IsAltDown()) { |
| 82 if (text_button_->HasIcon()) | 83 if (text_button_->HasIcon()) |
| 83 text_button_->SetIcon(SkBitmap()); | 84 text_button_->SetIcon(gfx::ImageSkia()); |
| 84 else | 85 else |
| 85 text_button_->SetIcon(*icon_); | 86 text_button_->SetIcon(*icon_); |
| 86 } else { | 87 } else { |
| 87 switch (alignment_) { | 88 switch (alignment_) { |
| 88 case TextButton::ALIGN_LEFT: | 89 case TextButton::ALIGN_LEFT: |
| 89 alignment_ = TextButton::ALIGN_CENTER; | 90 alignment_ = TextButton::ALIGN_CENTER; |
| 90 break; | 91 break; |
| 91 case TextButton::ALIGN_CENTER: | 92 case TextButton::ALIGN_CENTER: |
| 92 alignment_ = TextButton::ALIGN_RIGHT; | 93 alignment_ = TextButton::ALIGN_RIGHT; |
| 93 break; | 94 break; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 117 text_button_->set_border(new TextButtonBorder()); | 118 text_button_->set_border(new TextButtonBorder()); |
| 118 } | 119 } |
| 119 } else if (event.IsAltDown()) { | 120 } else if (event.IsAltDown()) { |
| 120 text_button_->SetIsDefault(!text_button_->is_default()); | 121 text_button_->SetIsDefault(!text_button_->is_default()); |
| 121 } | 122 } |
| 122 example_view()->GetLayoutManager()->Layout(example_view()); | 123 example_view()->GetLayoutManager()->Layout(example_view()); |
| 123 } | 124 } |
| 124 | 125 |
| 125 } // namespace examples | 126 } // namespace examples |
| 126 } // namespace views | 127 } // namespace views |
| OLD | NEW |