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

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

Issue 2289143004: Add ink drop ripple (but no highlight) to comboboxes in harmony. (Closed)
Patch Set: remove explicit and improve combobox example Created 4 years, 3 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/tree/tree_view.cc ('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/combobox_example.h" 5 #include "ui/views/examples/combobox_example.h"
6 6
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "ui/views/controls/combobox/combobox.h" 9 #include "ui/views/controls/combobox/combobox.h"
10 #include "ui/views/layout/box_layout.h" 10 #include "ui/views/layout/box_layout.h"
11 11
12 namespace views { 12 namespace views {
13 namespace examples { 13 namespace examples {
14 14
15 ComboboxModelExample::ComboboxModelExample() { 15 ComboboxModelExample::ComboboxModelExample() {
16 } 16 }
17 17
18 ComboboxModelExample::~ComboboxModelExample() { 18 ComboboxModelExample::~ComboboxModelExample() {
19 } 19 }
20 20
21 int ComboboxModelExample::GetItemCount() const { 21 int ComboboxModelExample::GetItemCount() const {
22 return 10; 22 return 10;
23 } 23 }
24 24
25 base::string16 ComboboxModelExample::GetItemAt(int index) { 25 base::string16 ComboboxModelExample::GetItemAt(int index) {
26 return base::UTF8ToUTF16(base::StringPrintf("Item %d", index)); 26 return base::UTF8ToUTF16(base::StringPrintf("%c item", 'A' + index));
27 } 27 }
28 28
29 ComboboxExample::ComboboxExample() : ExampleBase("Combo Box") { 29 ComboboxExample::ComboboxExample() : ExampleBase("Combo Box") {
30 } 30 }
31 31
32 ComboboxExample::~ComboboxExample() { 32 ComboboxExample::~ComboboxExample() {
33 // Delete |combobox_| first as it references |combobox_model_|. 33 // Delete |combobox_| first as it references |combobox_model_|.
34 delete combobox_; 34 delete combobox_;
35 delete disabled_combobox_; 35 delete disabled_combobox_;
36 delete action_combobox_; 36 delete action_combobox_;
(...skipping 12 matching lines...) Expand all
49 disabled_combobox_->SetSelectedIndex(4); 49 disabled_combobox_->SetSelectedIndex(4);
50 disabled_combobox_->SetEnabled(false); 50 disabled_combobox_->SetEnabled(false);
51 51
52 action_combobox_ = new Combobox(&combobox_model_, Combobox::STYLE_ACTION); 52 action_combobox_ = new Combobox(&combobox_model_, Combobox::STYLE_ACTION);
53 action_combobox_->set_listener(this); 53 action_combobox_->set_listener(this);
54 // Note: STYLE_ACTION comboboxes always have the first item selected by 54 // Note: STYLE_ACTION comboboxes always have the first item selected by
55 // default. 55 // default.
56 56
57 container->SetLayoutManager(new BoxLayout( 57 container->SetLayoutManager(new BoxLayout(
58 BoxLayout::kVertical, 58 BoxLayout::kVertical,
59 1, 1, 1)); 59 0, 10, 5));
60 container->AddChildView(combobox_); 60 container->AddChildView(combobox_);
61 container->AddChildView(disabled_combobox_); 61 container->AddChildView(disabled_combobox_);
62 container->AddChildView(action_combobox_); 62 container->AddChildView(action_combobox_);
63 } 63 }
64 64
65 void ComboboxExample::OnPerformAction(Combobox* combobox) { 65 void ComboboxExample::OnPerformAction(Combobox* combobox) {
66 if (combobox == combobox_) { 66 if (combobox == combobox_) {
67 PrintStatus("Selected: %s", base::UTF16ToUTF8(combobox_model_.GetItemAt( 67 PrintStatus("Selected: %s", base::UTF16ToUTF8(combobox_model_.GetItemAt(
68 combobox->selected_index())).c_str()); 68 combobox->selected_index())).c_str());
69 } else if (combobox == action_combobox_) { 69 } else if (combobox == action_combobox_) {
70 PrintStatus("Action: %s", base::UTF16ToUTF8(combobox_model_.GetItemAt( 70 PrintStatus("Action: %s", base::UTF16ToUTF8(combobox_model_.GetItemAt(
71 combobox->selected_index())).c_str()); 71 combobox->selected_index())).c_str());
72 } else { 72 } else {
73 NOTREACHED() << "Surprising combobox."; 73 NOTREACHED() << "Surprising combobox.";
74 } 74 }
75 } 75 }
76 76
77 } // namespace examples 77 } // namespace examples
78 } // namespace views 78 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/tree/tree_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698