| 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/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "ui/base/resource/resource_bundle.h" | 8 #include "ui/base/resource/resource_bundle.h" |
| 9 #include "ui/gfx/image/image.h" | 9 #include "ui/gfx/image/image.h" |
| 10 #include "ui/resources/grit/ui_resources.h" | 10 #include "ui/resources/grit/ui_resources.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 ButtonExample::~ButtonExample() { | 37 ButtonExample::~ButtonExample() { |
| 38 } | 38 } |
| 39 | 39 |
| 40 void ButtonExample::CreateExampleView(View* container) { | 40 void ButtonExample::CreateExampleView(View* container) { |
| 41 container->set_background(Background::CreateSolidBackground(SK_ColorWHITE)); | 41 container->set_background(Background::CreateSolidBackground(SK_ColorWHITE)); |
| 42 BoxLayout* layout = new BoxLayout(BoxLayout::kVertical, 10, 10, 10); | 42 BoxLayout* layout = new BoxLayout(BoxLayout::kVertical, 10, 10, 10); |
| 43 layout->set_cross_axis_alignment(BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | 43 layout->set_cross_axis_alignment(BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); |
| 44 container->SetLayoutManager(layout); | 44 container->SetLayoutManager(layout); |
| 45 | 45 |
| 46 label_button_ = new LabelButton(this, ASCIIToUTF16(kLabelButton)); | 46 label_button_ = new LabelButton(this, ASCIIToUTF16(kLabelButton)); |
| 47 label_button_->SetFocusBehavior(View::FocusBehavior::ALWAYS); | 47 Button::ConfigureDefaultFocus(label_button_); |
| 48 container->AddChildView(label_button_); | 48 container->AddChildView(label_button_); |
| 49 | 49 |
| 50 styled_button_ = new LabelButton(this, ASCIIToUTF16("Styled Button")); | 50 styled_button_ = new LabelButton(this, ASCIIToUTF16("Styled Button")); |
| 51 styled_button_->SetStyle(Button::STYLE_BUTTON); | 51 styled_button_->SetStyle(Button::STYLE_BUTTON); |
| 52 container->AddChildView(styled_button_); | 52 container->AddChildView(styled_button_); |
| 53 | 53 |
| 54 disabled_button_ = new LabelButton(this, ASCIIToUTF16("Disabled Button")); | 54 disabled_button_ = new LabelButton(this, ASCIIToUTF16("Disabled Button")); |
| 55 disabled_button_->SetStyle(Button::STYLE_BUTTON); | 55 disabled_button_->SetStyle(Button::STYLE_BUTTON); |
| 56 disabled_button_->SetState(Button::STATE_DISABLED); | 56 disabled_button_->SetState(Button::STATE_DISABLED); |
| 57 container->AddChildView(disabled_button_); | 57 container->AddChildView(disabled_button_); |
| 58 | 58 |
| 59 container->AddChildView(new BlueButton(this, ASCIIToUTF16("Blue Button"))); | 59 container->AddChildView(new BlueButton(this, ASCIIToUTF16("Blue Button"))); |
| 60 | 60 |
| 61 container->AddChildView(MdTextButton::CreateMdButton( | 61 container->AddChildView(MdTextButton::CreateMdButton( |
| 62 nullptr, base::ASCIIToUTF16("Material design"))); | 62 nullptr, base::ASCIIToUTF16("Material design"))); |
| 63 MdTextButton* md_button = MdTextButton::CreateMdButton( | 63 MdTextButton* md_button = MdTextButton::CreateMdButton( |
| 64 nullptr, base::ASCIIToUTF16("Strong call to action")); | 64 nullptr, base::ASCIIToUTF16("Strong call to action")); |
| 65 md_button->SetCallToAction(MdTextButton::STRONG_CALL_TO_ACTION); | 65 md_button->SetCallToAction(MdTextButton::STRONG_CALL_TO_ACTION); |
| 66 container->AddChildView(md_button); | 66 container->AddChildView(md_button); |
| 67 md_button = MdTextButton::CreateMdButton( | 67 md_button = MdTextButton::CreateMdButton( |
| 68 nullptr, base::ASCIIToUTF16("Weak call to action")); | 68 nullptr, base::ASCIIToUTF16("Weak call to action")); |
| 69 md_button->SetCallToAction(MdTextButton::WEAK_CALL_TO_ACTION); | 69 md_button->SetCallToAction(MdTextButton::WEAK_CALL_TO_ACTION); |
| 70 container->AddChildView(md_button); | 70 container->AddChildView(md_button); |
| 71 | 71 |
| 72 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 72 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 73 image_button_ = new ImageButton(this); | 73 image_button_ = new ImageButton(this); |
| 74 image_button_->SetFocusBehavior(View::FocusBehavior::ALWAYS); | 74 Button::ConfigureDefaultFocus(image_button_); |
| 75 image_button_->SetImage(ImageButton::STATE_NORMAL, | 75 image_button_->SetImage(ImageButton::STATE_NORMAL, |
| 76 rb.GetImageNamed(IDR_CLOSE).ToImageSkia()); | 76 rb.GetImageNamed(IDR_CLOSE).ToImageSkia()); |
| 77 image_button_->SetImage(ImageButton::STATE_HOVERED, | 77 image_button_->SetImage(ImageButton::STATE_HOVERED, |
| 78 rb.GetImageNamed(IDR_CLOSE_H).ToImageSkia()); | 78 rb.GetImageNamed(IDR_CLOSE_H).ToImageSkia()); |
| 79 image_button_->SetImage(ImageButton::STATE_PRESSED, | 79 image_button_->SetImage(ImageButton::STATE_PRESSED, |
| 80 rb.GetImageNamed(IDR_CLOSE_P).ToImageSkia()); | 80 rb.GetImageNamed(IDR_CLOSE_P).ToImageSkia()); |
| 81 container->AddChildView(image_button_); | 81 container->AddChildView(image_button_); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void ButtonExample::LabelButtonPressed(LabelButton* label_button, | 84 void ButtonExample::LabelButtonPressed(LabelButton* label_button, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 96 label_button->GetImage(Button::STATE_NORMAL).isNull() | 96 label_button->GetImage(Button::STATE_NORMAL).isNull() |
| 97 ? *icon_ | 97 ? *icon_ |
| 98 : gfx::ImageSkia()); | 98 : gfx::ImageSkia()); |
| 99 } else { | 99 } else { |
| 100 static int alignment = 0; | 100 static int alignment = 0; |
| 101 label_button->SetHorizontalAlignment( | 101 label_button->SetHorizontalAlignment( |
| 102 static_cast<gfx::HorizontalAlignment>(++alignment % 3)); | 102 static_cast<gfx::HorizontalAlignment>(++alignment % 3)); |
| 103 } | 103 } |
| 104 } else if (event.IsShiftDown()) { | 104 } else if (event.IsShiftDown()) { |
| 105 if (event.IsAltDown()) { | 105 if (event.IsAltDown()) { |
| 106 label_button->SetFocusBehavior(label_button->IsFocusable() | 106 // Toggle focusability. |
| 107 ? View::FocusBehavior::NEVER | 107 label_button_->IsAccessibilityFocusable() |
| 108 : View::FocusBehavior::ALWAYS); | 108 ? label_button_->SetFocusBehavior(View::FocusBehavior::NEVER) |
| 109 : Button::ConfigureDefaultFocus(label_button_); |
| 109 } else { | 110 } else { |
| 110 label_button->SetStyle(static_cast<Button::ButtonStyle>( | 111 label_button->SetStyle(static_cast<Button::ButtonStyle>( |
| 111 (label_button->style() + 1) % Button::STYLE_COUNT)); | 112 (label_button->style() + 1) % Button::STYLE_COUNT)); |
| 112 } | 113 } |
| 113 } else if (event.IsAltDown()) { | 114 } else if (event.IsAltDown()) { |
| 114 label_button->SetIsDefault(!label_button->is_default()); | 115 label_button->SetIsDefault(!label_button->is_default()); |
| 115 } else { | 116 } else { |
| 116 label_button->SetMinSize(gfx::Size()); | 117 label_button->SetMinSize(gfx::Size()); |
| 117 } | 118 } |
| 118 example_view()->GetLayoutManager()->Layout(example_view()); | 119 example_view()->GetLayoutManager()->Layout(example_view()); |
| 119 } | 120 } |
| 120 | 121 |
| 121 void ButtonExample::ButtonPressed(Button* sender, const ui::Event& event) { | 122 void ButtonExample::ButtonPressed(Button* sender, const ui::Event& event) { |
| 122 if (sender == label_button_) | 123 if (sender == label_button_) |
| 123 LabelButtonPressed(label_button_, event); | 124 LabelButtonPressed(label_button_, event); |
| 124 else if (sender == styled_button_) | 125 else if (sender == styled_button_) |
| 125 LabelButtonPressed(styled_button_, event); | 126 LabelButtonPressed(styled_button_, event); |
| 126 else if (sender == disabled_button_) | 127 else if (sender == disabled_button_) |
| 127 LabelButtonPressed(disabled_button_, event); | 128 LabelButtonPressed(disabled_button_, event); |
| 128 else | 129 else |
| 129 PrintStatus("Image Button Pressed! count: %d", ++count_); | 130 PrintStatus("Image Button Pressed! count: %d", ++count_); |
| 130 } | 131 } |
| 131 | 132 |
| 132 } // namespace examples | 133 } // namespace examples |
| 133 } // namespace views | 134 } // namespace views |
| OLD | NEW |