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 "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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 } | 42 } |
43 | 43 |
44 ButtonExample::~ButtonExample() { | 44 ButtonExample::~ButtonExample() { |
45 } | 45 } |
46 | 46 |
47 void ButtonExample::CreateExampleView(View* container) { | 47 void ButtonExample::CreateExampleView(View* container) { |
48 container->set_background(Background::CreateSolidBackground(SK_ColorWHITE)); | 48 container->set_background(Background::CreateSolidBackground(SK_ColorWHITE)); |
49 container->SetLayoutManager(new BoxLayout(BoxLayout::kVertical, 10, 10, 10)); | 49 container->SetLayoutManager(new BoxLayout(BoxLayout::kVertical, 10, 10, 10)); |
50 | 50 |
51 text_button_ = new TextButton(this, ASCIIToUTF16(kTextButton)); | 51 text_button_ = new TextButton(this, ASCIIToUTF16(kTextButton)); |
52 text_button_->set_focusable(true); | 52 text_button_->SetFocusable(true); |
53 container->AddChildView(text_button_); | 53 container->AddChildView(text_button_); |
54 | 54 |
55 label_button_ = new LabelButton(this, ASCIIToUTF16(kLabelButton)); | 55 label_button_ = new LabelButton(this, ASCIIToUTF16(kLabelButton)); |
56 label_button_->set_focusable(true); | 56 label_button_->SetFocusable(true); |
57 container->AddChildView(label_button_); | 57 container->AddChildView(label_button_); |
58 | 58 |
59 LabelButton* disabled_button = | 59 LabelButton* disabled_button = |
60 new LabelButton(this, ASCIIToUTF16("Disabled Button")); | 60 new LabelButton(this, ASCIIToUTF16("Disabled Button")); |
61 disabled_button->SetStyle(Button::STYLE_BUTTON); | 61 disabled_button->SetStyle(Button::STYLE_BUTTON); |
62 disabled_button->SetState(Button::STATE_DISABLED); | 62 disabled_button->SetState(Button::STATE_DISABLED); |
63 container->AddChildView(disabled_button); | 63 container->AddChildView(disabled_button); |
64 | 64 |
65 container->AddChildView(new BlueButton(this, ASCIIToUTF16("Blue Button"))); | 65 container->AddChildView(new BlueButton(this, ASCIIToUTF16("Blue Button"))); |
66 | 66 |
67 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 67 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
68 image_button_ = new ImageButton(this); | 68 image_button_ = new ImageButton(this); |
69 image_button_->set_focusable(true); | 69 image_button_->SetFocusable(true); |
70 image_button_->SetImage(ImageButton::STATE_NORMAL, | 70 image_button_->SetImage(ImageButton::STATE_NORMAL, |
71 rb.GetImageNamed(IDR_CLOSE).ToImageSkia()); | 71 rb.GetImageNamed(IDR_CLOSE).ToImageSkia()); |
72 image_button_->SetImage(ImageButton::STATE_HOVERED, | 72 image_button_->SetImage(ImageButton::STATE_HOVERED, |
73 rb.GetImageNamed(IDR_CLOSE_H).ToImageSkia()); | 73 rb.GetImageNamed(IDR_CLOSE_H).ToImageSkia()); |
74 image_button_->SetImage(ImageButton::STATE_PRESSED, | 74 image_button_->SetImage(ImageButton::STATE_PRESSED, |
75 rb.GetImageNamed(IDR_CLOSE_P).ToImageSkia()); | 75 rb.GetImageNamed(IDR_CLOSE_P).ToImageSkia()); |
76 image_button_->SetOverlayImage(rb.GetImageNamed( | 76 image_button_->SetOverlayImage(rb.GetImageNamed( |
77 IDR_MENU_CHECK).ToImageSkia()); | 77 IDR_MENU_CHECK).ToImageSkia()); |
78 container->AddChildView(image_button_); | 78 container->AddChildView(image_button_); |
79 } | 79 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 label_button_->SetImage(Button::STATE_NORMAL, | 154 label_button_->SetImage(Button::STATE_NORMAL, |
155 label_button_->GetImage(Button::STATE_NORMAL).isNull() ? | 155 label_button_->GetImage(Button::STATE_NORMAL).isNull() ? |
156 *icon_ : gfx::ImageSkia()); | 156 *icon_ : gfx::ImageSkia()); |
157 } else { | 157 } else { |
158 label_button_->SetHorizontalAlignment( | 158 label_button_->SetHorizontalAlignment( |
159 static_cast<gfx::HorizontalAlignment>( | 159 static_cast<gfx::HorizontalAlignment>( |
160 (label_button_->GetHorizontalAlignment() + 1) % 3)); | 160 (label_button_->GetHorizontalAlignment() + 1) % 3)); |
161 } | 161 } |
162 } else if (event.IsShiftDown()) { | 162 } else if (event.IsShiftDown()) { |
163 if (event.IsAltDown()) { | 163 if (event.IsAltDown()) { |
164 label_button_->set_focusable(!label_button_->focusable()); | 164 label_button_->SetFocusable(!label_button_->focusable()); |
165 } else { | 165 } else { |
166 label_button_->SetStyle(static_cast<Button::ButtonStyle>( | 166 label_button_->SetStyle(static_cast<Button::ButtonStyle>( |
167 (label_button_->style() + 1) % Button::STYLE_COUNT)); | 167 (label_button_->style() + 1) % Button::STYLE_COUNT)); |
168 } | 168 } |
169 } else if (event.IsAltDown()) { | 169 } else if (event.IsAltDown()) { |
170 label_button_->SetIsDefault(!label_button_->is_default()); | 170 label_button_->SetIsDefault(!label_button_->is_default()); |
171 } else { | 171 } else { |
172 label_button_->set_min_size(gfx::Size()); | 172 label_button_->set_min_size(gfx::Size()); |
173 } | 173 } |
174 example_view()->GetLayoutManager()->Layout(example_view()); | 174 example_view()->GetLayoutManager()->Layout(example_view()); |
175 } | 175 } |
176 | 176 |
177 void ButtonExample::ButtonPressed(Button* sender, const ui::Event& event) { | 177 void ButtonExample::ButtonPressed(Button* sender, const ui::Event& event) { |
178 if (sender == text_button_) | 178 if (sender == text_button_) |
179 TextButtonPressed(event); | 179 TextButtonPressed(event); |
180 else if (sender == label_button_) | 180 else if (sender == label_button_) |
181 LabelButtonPressed(event); | 181 LabelButtonPressed(event); |
182 else | 182 else |
183 PrintStatus("Image Button Pressed! count: %d", ++count_); | 183 PrintStatus("Image Button Pressed! count: %d", ++count_); |
184 } | 184 } |
185 | 185 |
186 } // namespace examples | 186 } // namespace examples |
187 } // namespace views | 187 } // namespace views |
OLD | NEW |