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

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

Issue 1898633004: Views: Add new SetFocusBehavior method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 4 years, 7 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/controls/webview/webview_unittest.cc ('k') | ui/views/examples/tree_view_example.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 26 matching lines...) Expand all
37 ButtonExample::~ButtonExample() { 37 ButtonExample::~ButtonExample() {
38 } 38 }
39 39
40 void ButtonExample::CreateExampleView(View* container) { 40 void ButtonExample::CreateExampleView(View* container) {
41 container->set_background(Background::CreateSolidBackground(SK_ColorWHITE)); 41 container->set_background(Background::CreateSolidBackground(SK_ColorWHITE));
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_->SetFocusable(true); 47 label_button_->SetFocusBehavior(View::FocusBehavior::ALWAYS);
48 container->AddChildView(label_button_); 48 container->AddChildView(label_button_);
49 49
50 styled_button_ = new LabelButton(this, ASCIIToUTF16("Styled Button")); 50 styled_button_ = new LabelButton(this, ASCIIToUTF16("Styled Button"));
51 styled_button_->SetStyle(Button::STYLE_BUTTON); 51 styled_button_->SetStyle(Button::STYLE_BUTTON);
52 container->AddChildView(styled_button_); 52 container->AddChildView(styled_button_);
53 53
54 disabled_button_ = new LabelButton(this, ASCIIToUTF16("Disabled Button")); 54 disabled_button_ = new LabelButton(this, ASCIIToUTF16("Disabled Button"));
55 disabled_button_->SetStyle(Button::STYLE_BUTTON); 55 disabled_button_->SetStyle(Button::STYLE_BUTTON);
56 disabled_button_->SetState(Button::STATE_DISABLED); 56 disabled_button_->SetState(Button::STATE_DISABLED);
57 container->AddChildView(disabled_button_); 57 container->AddChildView(disabled_button_);
58 58
59 container->AddChildView(new BlueButton(this, ASCIIToUTF16("Blue Button"))); 59 container->AddChildView(new BlueButton(this, ASCIIToUTF16("Blue Button")));
60 60
61 container->AddChildView(MdTextButton::CreateMdButton( 61 container->AddChildView(MdTextButton::CreateMdButton(
62 nullptr, base::ASCIIToUTF16("Material design"))); 62 nullptr, base::ASCIIToUTF16("Material design")));
63 MdTextButton* md_button = MdTextButton::CreateMdButton( 63 MdTextButton* md_button = MdTextButton::CreateMdButton(
64 nullptr, base::ASCIIToUTF16("Strong call to action")); 64 nullptr, base::ASCIIToUTF16("Strong call to action"));
65 md_button->SetCallToAction(MdTextButton::STRONG_CALL_TO_ACTION); 65 md_button->SetCallToAction(MdTextButton::STRONG_CALL_TO_ACTION);
66 container->AddChildView(md_button); 66 container->AddChildView(md_button);
67 md_button = MdTextButton::CreateMdButton( 67 md_button = MdTextButton::CreateMdButton(
68 nullptr, base::ASCIIToUTF16("Weak call to action")); 68 nullptr, base::ASCIIToUTF16("Weak call to action"));
69 md_button->SetCallToAction(MdTextButton::WEAK_CALL_TO_ACTION); 69 md_button->SetCallToAction(MdTextButton::WEAK_CALL_TO_ACTION);
70 container->AddChildView(md_button); 70 container->AddChildView(md_button);
71 71
72 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 72 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
73 image_button_ = new ImageButton(this); 73 image_button_ = new ImageButton(this);
74 image_button_->SetFocusable(true); 74 image_button_->SetFocusBehavior(View::FocusBehavior::ALWAYS);
75 image_button_->SetImage(ImageButton::STATE_NORMAL, 75 image_button_->SetImage(ImageButton::STATE_NORMAL,
76 rb.GetImageNamed(IDR_CLOSE).ToImageSkia()); 76 rb.GetImageNamed(IDR_CLOSE).ToImageSkia());
77 image_button_->SetImage(ImageButton::STATE_HOVERED, 77 image_button_->SetImage(ImageButton::STATE_HOVERED,
78 rb.GetImageNamed(IDR_CLOSE_H).ToImageSkia()); 78 rb.GetImageNamed(IDR_CLOSE_H).ToImageSkia());
79 image_button_->SetImage(ImageButton::STATE_PRESSED, 79 image_button_->SetImage(ImageButton::STATE_PRESSED,
80 rb.GetImageNamed(IDR_CLOSE_P).ToImageSkia()); 80 rb.GetImageNamed(IDR_CLOSE_P).ToImageSkia());
81 container->AddChildView(image_button_); 81 container->AddChildView(image_button_);
82 } 82 }
83 83
84 void ButtonExample::LabelButtonPressed(LabelButton* label_button, 84 void ButtonExample::LabelButtonPressed(LabelButton* label_button,
(...skipping 11 matching lines...) Expand all
96 label_button->GetImage(Button::STATE_NORMAL).isNull() 96 label_button->GetImage(Button::STATE_NORMAL).isNull()
97 ? *icon_ 97 ? *icon_
98 : gfx::ImageSkia()); 98 : gfx::ImageSkia());
99 } else { 99 } else {
100 static int alignment = 0; 100 static int alignment = 0;
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 label_button->SetFocusable(!label_button->IsFocusable()); 106 label_button->SetFocusBehavior(label_button->IsFocusable()
107 ? View::FocusBehavior::NEVER
108 : View::FocusBehavior::ALWAYS);
107 } else { 109 } else {
108 label_button->SetStyle(static_cast<Button::ButtonStyle>( 110 label_button->SetStyle(static_cast<Button::ButtonStyle>(
109 (label_button->style() + 1) % Button::STYLE_COUNT)); 111 (label_button->style() + 1) % Button::STYLE_COUNT));
110 } 112 }
111 } else if (event.IsAltDown()) { 113 } else if (event.IsAltDown()) {
112 label_button->SetIsDefault(!label_button->is_default()); 114 label_button->SetIsDefault(!label_button->is_default());
113 } else { 115 } else {
114 label_button->SetMinSize(gfx::Size()); 116 label_button->SetMinSize(gfx::Size());
115 } 117 }
116 example_view()->GetLayoutManager()->Layout(example_view()); 118 example_view()->GetLayoutManager()->Layout(example_view());
117 } 119 }
118 120
119 void ButtonExample::ButtonPressed(Button* sender, const ui::Event& event) { 121 void ButtonExample::ButtonPressed(Button* sender, const ui::Event& event) {
120 if (sender == label_button_) 122 if (sender == label_button_)
121 LabelButtonPressed(label_button_, event); 123 LabelButtonPressed(label_button_, event);
122 else if (sender == styled_button_) 124 else if (sender == styled_button_)
123 LabelButtonPressed(styled_button_, event); 125 LabelButtonPressed(styled_button_, event);
124 else if (sender == disabled_button_) 126 else if (sender == disabled_button_)
125 LabelButtonPressed(disabled_button_, event); 127 LabelButtonPressed(disabled_button_, event);
126 else 128 else
127 PrintStatus("Image Button Pressed! count: %d", ++count_); 129 PrintStatus("Image Button Pressed! count: %d", ++count_);
128 } 130 }
129 131
130 } // namespace examples 132 } // namespace examples
131 } // namespace views 133 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/webview/webview_unittest.cc ('k') | ui/views/examples/tree_view_example.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698