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 24 matching lines...) Expand all Loading... |
35 void ButtonExample::CreateExampleView(View* container) { | 35 void ButtonExample::CreateExampleView(View* container) { |
36 container->SetLayoutManager(new BoxLayout(BoxLayout::kVertical, 0, 0, 10)); | 36 container->SetLayoutManager(new BoxLayout(BoxLayout::kVertical, 0, 0, 10)); |
37 | 37 |
38 text_button_ = new TextButton(this, ASCIIToUTF16("Text Button")); | 38 text_button_ = new TextButton(this, ASCIIToUTF16("Text Button")); |
39 text_button_->set_focusable(true); | 39 text_button_->set_focusable(true); |
40 text_button_->SetHoverColor(SK_ColorRED); | 40 text_button_->SetHoverColor(SK_ColorRED); |
41 container->AddChildView(text_button_); | 41 container->AddChildView(text_button_); |
42 | 42 |
43 label_button_ = new LabelButton(this, ASCIIToUTF16("Label Button")); | 43 label_button_ = new LabelButton(this, ASCIIToUTF16("Label Button")); |
44 label_button_->set_focusable(true); | 44 label_button_->set_focusable(true); |
45 label_button_->SetTextColor(CustomButton::STATE_HOVERED, SK_ColorRED); | 45 label_button_->SetTextColor(Button::STATE_HOVERED, SK_ColorRED); |
46 container->AddChildView(label_button_); | 46 container->AddChildView(label_button_); |
47 | 47 |
48 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 48 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
49 image_button_ = new ImageButton(this); | 49 image_button_ = new ImageButton(this); |
50 image_button_->set_focusable(true); | 50 image_button_->set_focusable(true); |
51 image_button_->SetImage(ImageButton::STATE_NORMAL, | 51 image_button_->SetImage(ImageButton::STATE_NORMAL, |
52 rb.GetImageNamed(IDR_CLOSE).ToImageSkia()); | 52 rb.GetImageNamed(IDR_CLOSE).ToImageSkia()); |
53 image_button_->SetImage(ImageButton::STATE_HOVERED, | 53 image_button_->SetImage(ImageButton::STATE_HOVERED, |
54 rb.GetImageNamed(IDR_CLOSE_H).ToImageSkia()); | 54 rb.GetImageNamed(IDR_CLOSE_H).ToImageSkia()); |
55 image_button_->SetImage(ImageButton::STATE_PRESSED, | 55 image_button_->SetImage(ImageButton::STATE_PRESSED, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 if (event.IsAltDown()) { | 138 if (event.IsAltDown()) { |
139 label_button_->SetTextMultiLine(!label_button_->GetTextMultiLine()); | 139 label_button_->SetTextMultiLine(!label_button_->GetTextMultiLine()); |
140 label_button_->SetText(ASCIIToUTF16(label_button_->GetTextMultiLine() ? | 140 label_button_->SetText(ASCIIToUTF16(label_button_->GetTextMultiLine() ? |
141 "Multi-line text\nis here to stay all the way!\n123" : | 141 "Multi-line text\nis here to stay all the way!\n123" : |
142 "Label Button")); | 142 "Label Button")); |
143 } else { | 143 } else { |
144 label_button_->SetText(!label_button_->GetText().empty() ? | 144 label_button_->SetText(!label_button_->GetText().empty() ? |
145 string16() : ASCIIToUTF16("Label Button")); | 145 string16() : ASCIIToUTF16("Label Button")); |
146 } | 146 } |
147 } else if (event.IsAltDown()) { | 147 } else if (event.IsAltDown()) { |
148 label_button_->SetImage(CustomButton::STATE_NORMAL, | 148 label_button_->SetImage(Button::STATE_NORMAL, |
149 label_button_->GetImage(CustomButton::STATE_NORMAL).isNull() ? | 149 label_button_->GetImage(Button::STATE_NORMAL).isNull() ? |
150 *icon_ : gfx::ImageSkia()); | 150 *icon_ : gfx::ImageSkia()); |
151 } else { | 151 } else { |
152 label_button_->SetHorizontalAlignment( | 152 label_button_->SetHorizontalAlignment( |
153 static_cast<gfx::HorizontalAlignment>( | 153 static_cast<gfx::HorizontalAlignment>( |
154 (label_button_->GetHorizontalAlignment() + 1) % 3)); | 154 (label_button_->GetHorizontalAlignment() + 1) % 3)); |
155 } | 155 } |
156 } else if (event.IsShiftDown()) { | 156 } else if (event.IsShiftDown()) { |
157 if (event.IsAltDown()) { | 157 if (event.IsAltDown()) { |
158 label_button_->SetText(ASCIIToUTF16( | 158 label_button_->SetText(ASCIIToUTF16( |
159 label_button_->GetText().length() > 20 ? "Label Button" : | 159 label_button_->GetText().length() > 20 ? "Label Button" : |
160 "StartofReallyReallyReallyReallyReallyReallyReally" | 160 "StartofReallyReallyReallyReallyReallyReallyReally" |
161 "ReallyReallyReallyReallyReallyReallyReally" | 161 "ReallyReallyReallyReallyReallyReallyReally" |
162 "ReallyReallyReallyReallyReallyReallyReallyLongButtonText")); | 162 "ReallyReallyReallyReallyReallyReallyReallyLongButtonText")); |
163 } else { | 163 } else { |
164 label_button_->SetNativeTheme(!label_button_->native_theme()); | 164 label_button_->SetStyle(static_cast<Button::ButtonStyle>( |
| 165 (label_button_->style() + 1) % Button::STYLE_COUNT)); |
165 } | 166 } |
166 } else if (event.IsAltDown()) { | 167 } else if (event.IsAltDown()) { |
167 label_button_->SetDefaultButton(!label_button_->default_button()); | 168 label_button_->SetDefaultButton(!label_button_->default_button()); |
168 } else { | 169 } else { |
169 label_button_->set_min_size(gfx::Size()); | 170 label_button_->set_min_size(gfx::Size()); |
170 } | 171 } |
171 example_view()->GetLayoutManager()->Layout(example_view()); | 172 example_view()->GetLayoutManager()->Layout(example_view()); |
172 } | 173 } |
173 | 174 |
174 void ButtonExample::ButtonPressed(Button* sender, const ui::Event& event) { | 175 void ButtonExample::ButtonPressed(Button* sender, const ui::Event& event) { |
175 if (sender == text_button_) | 176 if (sender == text_button_) |
176 TextButtonPressed(event); | 177 TextButtonPressed(event); |
177 else if (sender == label_button_) | 178 else if (sender == label_button_) |
178 LabelButtonPressed(event); | 179 LabelButtonPressed(event); |
179 else | 180 else |
180 PrintStatus("Image Button Pressed! count: %d", ++count_); | 181 PrintStatus("Image Button Pressed! count: %d", ++count_); |
181 } | 182 } |
182 | 183 |
183 } // namespace examples | 184 } // namespace examples |
184 } // namespace views | 185 } // namespace views |
OLD | NEW |