Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: ui/views/examples/button_example.cc

Issue 1569113002: MacViews: Style BUTTON_STYLE buttons using the "modern" UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: respond to comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/examples/button_example.h ('k') | ui/views/style/mac/combobox_background_mac.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 11 matching lines...) Expand all
22 namespace { 22 namespace {
23 const char kLabelButton[] = "Label Button"; 23 const char kLabelButton[] = "Label Button";
24 const char kLongText[] = "Start of Really Really Really Really Really Really " 24 const char kLongText[] = "Start of Really Really Really Really Really Really "
25 "Really Really Really Really Really Really Really " 25 "Really Really Really Really Really Really Really "
26 "Really Really Really Really Really Long Button Text"; 26 "Really Really Really Really Really Long Button Text";
27 } // namespace 27 } // namespace
28 28
29 namespace views { 29 namespace views {
30 namespace examples { 30 namespace examples {
31 31
32 ButtonExample::ButtonExample() 32 ButtonExample::ButtonExample() : ExampleBase("Button") {
33 : ExampleBase("Button"),
34 label_button_(NULL),
35 image_button_(NULL),
36 icon_(NULL),
37 count_(0) {
38 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 33 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
39 icon_ = rb.GetImageNamed(IDR_CLOSE_H).ToImageSkia(); 34 icon_ = rb.GetImageNamed(IDR_CLOSE_H).ToImageSkia();
40 } 35 }
41 36
42 ButtonExample::~ButtonExample() { 37 ButtonExample::~ButtonExample() {
43 } 38 }
44 39
45 void ButtonExample::CreateExampleView(View* container) { 40 void ButtonExample::CreateExampleView(View* container) {
46 container->set_background(Background::CreateSolidBackground(SK_ColorWHITE)); 41 container->set_background(Background::CreateSolidBackground(SK_ColorWHITE));
47 BoxLayout* layout = new BoxLayout(BoxLayout::kVertical, 10, 10, 10); 42 BoxLayout* layout = new BoxLayout(BoxLayout::kVertical, 10, 10, 10);
48 layout->set_cross_axis_alignment(BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); 43 layout->set_cross_axis_alignment(BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
49 container->SetLayoutManager(layout); 44 container->SetLayoutManager(layout);
50 45
51 label_button_ = new LabelButton(this, ASCIIToUTF16(kLabelButton)); 46 label_button_ = new LabelButton(this, ASCIIToUTF16(kLabelButton));
52 label_button_->SetFocusable(true); 47 label_button_->SetFocusable(true);
53 container->AddChildView(label_button_); 48 container->AddChildView(label_button_);
54 49
55 LabelButton* styled_button = 50 styled_button_ = new LabelButton(this, ASCIIToUTF16("Styled Button"));
56 new LabelButton(this, ASCIIToUTF16("Styled Button")); 51 styled_button_->SetStyle(Button::STYLE_BUTTON);
57 styled_button->SetStyle(Button::STYLE_BUTTON); 52 container->AddChildView(styled_button_);
58 container->AddChildView(styled_button);
59 53
60 LabelButton* disabled_button = 54 disabled_button_ = new LabelButton(this, ASCIIToUTF16("Disabled Button"));
61 new LabelButton(this, ASCIIToUTF16("Disabled Button")); 55 disabled_button_->SetStyle(Button::STYLE_BUTTON);
62 disabled_button->SetStyle(Button::STYLE_BUTTON); 56 disabled_button_->SetState(Button::STATE_DISABLED);
63 disabled_button->SetState(Button::STATE_DISABLED); 57 container->AddChildView(disabled_button_);
64 container->AddChildView(disabled_button);
65 58
66 container->AddChildView(new BlueButton(this, ASCIIToUTF16("Blue Button"))); 59 container->AddChildView(new BlueButton(this, ASCIIToUTF16("Blue Button")));
67 60
68 container->AddChildView(MdTextButton::CreateMdButton( 61 container->AddChildView(MdTextButton::CreateMdButton(
69 nullptr, base::ASCIIToUTF16("Material design"))); 62 nullptr, base::ASCIIToUTF16("Material design")));
70 MdTextButton* md_button = MdTextButton::CreateMdButton( 63 MdTextButton* md_button = MdTextButton::CreateMdButton(
71 nullptr, base::ASCIIToUTF16("Strong call to action")); 64 nullptr, base::ASCIIToUTF16("Strong call to action"));
72 md_button->SetCallToAction(MdTextButton::STRONG_CALL_TO_ACTION); 65 md_button->SetCallToAction(MdTextButton::STRONG_CALL_TO_ACTION);
73 container->AddChildView(md_button); 66 container->AddChildView(md_button);
74 md_button = MdTextButton::CreateMdButton( 67 md_button = MdTextButton::CreateMdButton(
75 nullptr, base::ASCIIToUTF16("Weak call to action")); 68 nullptr, base::ASCIIToUTF16("Weak call to action"));
76 md_button->SetCallToAction(MdTextButton::WEAK_CALL_TO_ACTION); 69 md_button->SetCallToAction(MdTextButton::WEAK_CALL_TO_ACTION);
77 container->AddChildView(md_button); 70 container->AddChildView(md_button);
78 71
79 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 72 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
80 image_button_ = new ImageButton(this); 73 image_button_ = new ImageButton(this);
81 image_button_->SetFocusable(true); 74 image_button_->SetFocusable(true);
82 image_button_->SetImage(ImageButton::STATE_NORMAL, 75 image_button_->SetImage(ImageButton::STATE_NORMAL,
83 rb.GetImageNamed(IDR_CLOSE).ToImageSkia()); 76 rb.GetImageNamed(IDR_CLOSE).ToImageSkia());
84 image_button_->SetImage(ImageButton::STATE_HOVERED, 77 image_button_->SetImage(ImageButton::STATE_HOVERED,
85 rb.GetImageNamed(IDR_CLOSE_H).ToImageSkia()); 78 rb.GetImageNamed(IDR_CLOSE_H).ToImageSkia());
86 image_button_->SetImage(ImageButton::STATE_PRESSED, 79 image_button_->SetImage(ImageButton::STATE_PRESSED,
87 rb.GetImageNamed(IDR_CLOSE_P).ToImageSkia()); 80 rb.GetImageNamed(IDR_CLOSE_P).ToImageSkia());
88 container->AddChildView(image_button_); 81 container->AddChildView(image_button_);
89 } 82 }
90 83
91 void ButtonExample::LabelButtonPressed(const ui::Event& event) { 84 void ButtonExample::LabelButtonPressed(LabelButton* label_button,
85 const ui::Event& event) {
92 PrintStatus("Label Button Pressed! count: %d", ++count_); 86 PrintStatus("Label Button Pressed! count: %d", ++count_);
93 if (event.IsControlDown()) { 87 if (event.IsControlDown()) {
94 if (event.IsShiftDown()) { 88 if (event.IsShiftDown()) {
95 label_button_->SetText(ASCIIToUTF16( 89 label_button->SetText(ASCIIToUTF16(
96 label_button_->GetText().empty() 90 label_button->GetText().empty()
97 ? kLongText 91 ? kLongText
98 : label_button_->GetText().length() > 50 ? kLabelButton : "")); 92 : label_button->GetText().length() > 50 ? kLabelButton : ""));
99 } else if (event.IsAltDown()) { 93 } else if (event.IsAltDown()) {
100 label_button_->SetImage(Button::STATE_NORMAL, 94 label_button->SetImage(
101 label_button_->GetImage(Button::STATE_NORMAL).isNull() ? 95 Button::STATE_NORMAL,
102 *icon_ : gfx::ImageSkia()); 96 label_button->GetImage(Button::STATE_NORMAL).isNull()
97 ? *icon_
98 : gfx::ImageSkia());
103 } else { 99 } else {
104 static int alignment = 0; 100 static int alignment = 0;
105 label_button_->SetHorizontalAlignment( 101 label_button->SetHorizontalAlignment(
106 static_cast<gfx::HorizontalAlignment>(++alignment % 3)); 102 static_cast<gfx::HorizontalAlignment>(++alignment % 3));
107 } 103 }
108 } else if (event.IsShiftDown()) { 104 } else if (event.IsShiftDown()) {
109 if (event.IsAltDown()) { 105 if (event.IsAltDown()) {
110 label_button_->SetFocusable(!label_button_->IsFocusable()); 106 label_button->SetFocusable(!label_button->IsFocusable());
111 } else { 107 } else {
112 label_button_->SetStyle(static_cast<Button::ButtonStyle>( 108 label_button->SetStyle(static_cast<Button::ButtonStyle>(
113 (label_button_->style() + 1) % Button::STYLE_COUNT)); 109 (label_button->style() + 1) % Button::STYLE_COUNT));
114 } 110 }
115 } else if (event.IsAltDown()) { 111 } else if (event.IsAltDown()) {
116 label_button_->SetIsDefault(!label_button_->is_default()); 112 label_button->SetIsDefault(!label_button->is_default());
117 } else { 113 } else {
118 label_button_->SetMinSize(gfx::Size()); 114 label_button->SetMinSize(gfx::Size());
119 } 115 }
120 example_view()->GetLayoutManager()->Layout(example_view()); 116 example_view()->GetLayoutManager()->Layout(example_view());
121 } 117 }
122 118
123 void ButtonExample::ButtonPressed(Button* sender, const ui::Event& event) { 119 void ButtonExample::ButtonPressed(Button* sender, const ui::Event& event) {
124 if (sender == label_button_) 120 if (sender == label_button_)
125 LabelButtonPressed(event); 121 LabelButtonPressed(label_button_, event);
122 else if (sender == styled_button_)
123 LabelButtonPressed(styled_button_, event);
124 else if (sender == disabled_button_)
125 LabelButtonPressed(disabled_button_, event);
126 else 126 else
127 PrintStatus("Image Button Pressed! count: %d", ++count_); 127 PrintStatus("Image Button Pressed! count: %d", ++count_);
128 } 128 }
129 129
130 } // namespace examples 130 } // namespace examples
131 } // namespace views 131 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/examples/button_example.h ('k') | ui/views/style/mac/combobox_background_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698