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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_->SetFocusForPlatform(); | 47 label_button_->SetFocusForPlatform(); |
48 label_button_->set_request_focus_on_press(true); | 48 label_button_->set_request_focus_on_press(true); |
49 container->AddChildView(label_button_); | 49 container->AddChildView(label_button_); |
50 | 50 |
51 styled_button_ = new LabelButton(this, ASCIIToUTF16("Styled Button")); | 51 styled_button_ = new LabelButton(this, ASCIIToUTF16("Styled Button")); |
52 styled_button_->SetStyle(Button::STYLE_BUTTON); | 52 styled_button_->SetStyleDeprecated(Button::STYLE_BUTTON); |
53 container->AddChildView(styled_button_); | 53 container->AddChildView(styled_button_); |
54 | 54 |
55 disabled_button_ = new LabelButton(this, ASCIIToUTF16("Disabled Button")); | 55 disabled_button_ = new LabelButton(this, ASCIIToUTF16("Disabled Button")); |
56 disabled_button_->SetStyle(Button::STYLE_BUTTON); | 56 disabled_button_->SetStyleDeprecated(Button::STYLE_BUTTON); |
57 disabled_button_->SetState(Button::STATE_DISABLED); | 57 disabled_button_->SetState(Button::STATE_DISABLED); |
58 container->AddChildView(disabled_button_); | 58 container->AddChildView(disabled_button_); |
59 | 59 |
60 container->AddChildView(new BlueButton(this, ASCIIToUTF16("Blue Button"))); | 60 container->AddChildView(new BlueButton(this, ASCIIToUTF16("Blue Button"))); |
61 | 61 |
62 md_button_ = | 62 md_button_ = |
63 MdTextButton::Create(this, base::ASCIIToUTF16("Material design")); | 63 MdTextButton::Create(this, base::ASCIIToUTF16("Material design")); |
64 container->AddChildView(md_button_); | 64 container->AddChildView(md_button_); |
65 | 65 |
66 md_default_button_ = | 66 md_default_button_ = |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // Toggle focusability. | 106 // Toggle focusability. |
107 label_button_->IsAccessibilityFocusable() | 107 label_button_->IsAccessibilityFocusable() |
108 ? label_button_->SetFocusBehavior(View::FocusBehavior::NEVER) | 108 ? label_button_->SetFocusBehavior(View::FocusBehavior::NEVER) |
109 : label_button_->SetFocusForPlatform(); | 109 : label_button_->SetFocusForPlatform(); |
110 } else { | 110 } else { |
111 label_button->SetStyle(static_cast<Button::ButtonStyle>( | 111 label_button->SetStyleDeprecated(static_cast<Button::ButtonStyle>( |
112 (label_button->style() + 1) % Button::STYLE_COUNT)); | 112 (label_button->style() + 1) % Button::STYLE_COUNT)); |
113 } | 113 } |
114 } else if (event.IsAltDown()) { | 114 } else if (event.IsAltDown()) { |
115 label_button->SetIsDefault(!label_button->is_default()); | 115 label_button->SetIsDefault(!label_button->is_default()); |
116 } else { | 116 } else { |
117 label_button->SetMinSize(gfx::Size()); | 117 label_button->SetMinSize(gfx::Size()); |
118 } | 118 } |
119 example_view()->GetLayoutManager()->Layout(example_view()); | 119 example_view()->GetLayoutManager()->Layout(example_view()); |
120 } | 120 } |
121 | 121 |
122 void ButtonExample::ButtonPressed(Button* sender, const ui::Event& event) { | 122 void ButtonExample::ButtonPressed(Button* sender, const ui::Event& event) { |
123 if (sender == label_button_) | 123 if (sender == label_button_) |
124 LabelButtonPressed(label_button_, event); | 124 LabelButtonPressed(label_button_, event); |
125 else if (sender == styled_button_) | 125 else if (sender == styled_button_) |
126 LabelButtonPressed(styled_button_, event); | 126 LabelButtonPressed(styled_button_, event); |
127 else if (sender == disabled_button_) | 127 else if (sender == disabled_button_) |
128 LabelButtonPressed(disabled_button_, event); | 128 LabelButtonPressed(disabled_button_, event); |
129 else if (sender == md_button_ || sender == md_default_button_) | 129 else if (sender == md_button_ || sender == md_default_button_) |
130 static_cast<CustomButton*>(sender)->StartThrobbing(5); | 130 static_cast<CustomButton*>(sender)->StartThrobbing(5); |
131 else | 131 else |
132 PrintStatus("Image Button Pressed! count: %d", ++count_); | 132 PrintStatus("Image Button Pressed! count: %d", ++count_); |
133 } | 133 } |
134 | 134 |
135 } // namespace examples | 135 } // namespace examples |
136 } // namespace views | 136 } // namespace views |
OLD | NEW |