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

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

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

Powered by Google App Engine
This is Rietveld 408576698