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

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

Issue 2406323002: CustomButton: restrict animation repaints to buttons that actually animate (Closed)
Patch Set: don't use bool(T*) Created 4 years, 2 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') | no next file » | 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 styled_button_->SetStyle(Button::STYLE_BUTTON); 52 styled_button_->SetStyle(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_->SetStyle(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 container->AddChildView( 62 md_button_ =
63 MdTextButton::Create(nullptr, base::ASCIIToUTF16("Material design"))); 63 MdTextButton::Create(this, base::ASCIIToUTF16("Material design"));
64 MdTextButton* md_button = 64 container->AddChildView(md_button_);
65 MdTextButton::Create(nullptr, base::ASCIIToUTF16("Default")); 65
66 md_button->SetIsDefault(true); 66 md_default_button_ =
67 container->AddChildView(md_button); 67 MdTextButton::Create(this, base::ASCIIToUTF16("Default"));
68 md_button = 68 md_default_button_->SetIsDefault(true);
69 MdTextButton::Create(nullptr, base::ASCIIToUTF16("Call to action")); 69 container->AddChildView(md_default_button_);
70 md_button->SetProminent(true); 70
71 container->AddChildView(md_button); 71 md_prominent_button_ =
72 MdTextButton::Create(this, base::ASCIIToUTF16("Call to action"));
73 md_prominent_button_->SetProminent(true);
74 container->AddChildView(md_prominent_button_);
72 75
73 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 76 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
74 image_button_ = new ImageButton(this); 77 image_button_ = new ImageButton(this);
75 image_button_->SetFocusForPlatform(); 78 image_button_->SetFocusForPlatform();
76 image_button_->set_request_focus_on_press(true); 79 image_button_->set_request_focus_on_press(true);
77 image_button_->SetImage(ImageButton::STATE_NORMAL, 80 image_button_->SetImage(ImageButton::STATE_NORMAL,
78 rb.GetImageNamed(IDR_CLOSE).ToImageSkia()); 81 rb.GetImageNamed(IDR_CLOSE).ToImageSkia());
79 image_button_->SetImage(ImageButton::STATE_HOVERED, 82 image_button_->SetImage(ImageButton::STATE_HOVERED,
80 rb.GetImageNamed(IDR_CLOSE_H).ToImageSkia()); 83 rb.GetImageNamed(IDR_CLOSE_H).ToImageSkia());
81 image_button_->SetImage(ImageButton::STATE_PRESSED, 84 image_button_->SetImage(ImageButton::STATE_PRESSED,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 } 118 }
116 } else if (event.IsAltDown()) { 119 } else if (event.IsAltDown()) {
117 label_button->SetIsDefault(!label_button->is_default()); 120 label_button->SetIsDefault(!label_button->is_default());
118 } else { 121 } else {
119 label_button->SetMinSize(gfx::Size()); 122 label_button->SetMinSize(gfx::Size());
120 } 123 }
121 example_view()->GetLayoutManager()->Layout(example_view()); 124 example_view()->GetLayoutManager()->Layout(example_view());
122 } 125 }
123 126
124 void ButtonExample::ButtonPressed(Button* sender, const ui::Event& event) { 127 void ButtonExample::ButtonPressed(Button* sender, const ui::Event& event) {
125 if (sender == label_button_) 128 if (sender == label_button_) {
126 LabelButtonPressed(label_button_, event); 129 LabelButtonPressed(label_button_, event);
127 else if (sender == styled_button_) 130 } else if (sender == styled_button_) {
128 LabelButtonPressed(styled_button_, event); 131 LabelButtonPressed(styled_button_, event);
129 else if (sender == disabled_button_) 132 } else if (sender == disabled_button_) {
130 LabelButtonPressed(disabled_button_, event); 133 LabelButtonPressed(disabled_button_, event);
131 else 134 } else if (sender == md_button_ || sender == md_default_button_ ||
135 sender == md_prominent_button_) {
136 static_cast<CustomButton*>(sender)->StartThrobbing(5);
137 } else {
132 PrintStatus("Image Button Pressed! count: %d", ++count_); 138 PrintStatus("Image Button Pressed! count: %d", ++count_);
139 }
133 } 140 }
134 141
135 } // namespace examples 142 } // namespace examples
136 } // namespace views 143 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/examples/button_example.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698