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

Side by Side Diff: ui/views/controls/combobox/combobox.cc

Issue 9875001: views: Rename Combobox "selected getter/setter" accessors to something more accurate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: combo box -> combobox Created 8 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 | 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/controls/combobox/combobox.h" 5 #include "ui/views/controls/combobox/combobox.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "ui/base/accessibility/accessible_view_state.h" 9 #include "ui/base/accessibility/accessible_view_state.h"
10 #include "ui/base/keycodes/keyboard_codes.h" 10 #include "ui/base/keycodes/keyboard_codes.h"
11 #include "ui/base/models/combobox_model.h" 11 #include "ui/base/models/combobox_model.h"
12 #include "ui/base/resource/resource_bundle.h" 12 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/views/controls/combobox/combobox_listener.h" 13 #include "ui/views/controls/combobox/combobox_listener.h"
14 #include "ui/views/controls/native/native_view_host.h" 14 #include "ui/views/controls/native/native_view_host.h"
15 #include "ui/views/widget/widget.h" 15 #include "ui/views/widget/widget.h"
16 16
17 namespace views { 17 namespace views {
18 18
19 // static 19 // static
20 const char Combobox::kViewClassName[] = "views/Combobox"; 20 const char Combobox::kViewClassName[] = "views/Combobox";
21 21
22 //////////////////////////////////////////////////////////////////////////////// 22 ////////////////////////////////////////////////////////////////////////////////
23 // Combobox, public: 23 // Combobox, public:
24 24
25 Combobox::Combobox(ui::ComboboxModel* model) 25 Combobox::Combobox(ui::ComboboxModel* model)
26 : native_wrapper_(NULL), 26 : native_wrapper_(NULL),
27 model_(model), 27 model_(model),
28 listener_(NULL), 28 listener_(NULL),
29 selected_item_(0) { 29 selected_index_(0) {
30 DCHECK(model);
30 set_focusable(true); 31 set_focusable(true);
31 } 32 }
32 33
33 Combobox::~Combobox() { 34 Combobox::~Combobox() {
34 } 35 }
35 36
36 // static 37 // static
37 const gfx::Font& Combobox::GetFont() { 38 const gfx::Font& Combobox::GetFont() {
38 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 39 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
39 return rb.GetFont(ui::ResourceBundle::BaseFont); 40 return rb.GetFont(ui::ResourceBundle::BaseFont);
40 } 41 }
41 42
42 void Combobox::ModelChanged() { 43 void Combobox::ModelChanged() {
43 selected_item_ = std::min(0, model_->GetItemCount()); 44 selected_index_ = std::min(0, model_->GetItemCount());
44 if (native_wrapper_) 45 if (native_wrapper_)
45 native_wrapper_->UpdateFromModel(); 46 native_wrapper_->UpdateFromModel();
46 PreferredSizeChanged(); 47 PreferredSizeChanged();
47 } 48 }
48 49
49 void Combobox::SetSelectedItem(int index) { 50 void Combobox::SetSelectedIndex(int index) {
50 selected_item_ = index; 51 selected_index_ = index;
51 if (native_wrapper_) 52 if (native_wrapper_)
52 native_wrapper_->UpdateSelectedItem(); 53 native_wrapper_->UpdateSelectedIndex();
53 } 54 }
54 55
55 void Combobox::SelectionChanged() { 56 void Combobox::SelectionChanged() {
56 int prev_selected_item = selected_item_; 57 int prev_selected_index = selected_index_;
57 selected_item_ = native_wrapper_->GetSelectedItem(); 58 selected_index_ = native_wrapper_->GetSelectedIndex();
58 if (listener_) 59 if (listener_)
59 listener_->ItemChanged(this, prev_selected_item, selected_item_); 60 listener_->ItemChanged(this, prev_selected_index, selected_index_);
60 if (GetWidget()) { 61 if (GetWidget()) {
61 GetWidget()->NotifyAccessibilityEvent( 62 GetWidget()->NotifyAccessibilityEvent(
62 this, ui::AccessibilityTypes::EVENT_VALUE_CHANGED, false); 63 this, ui::AccessibilityTypes::EVENT_VALUE_CHANGED, false);
63 } 64 }
64 } 65 }
65 66
66 void Combobox::SetAccessibleName(const string16& name) { 67 void Combobox::SetAccessibleName(const string16& name) {
67 accessible_name_ = name; 68 accessible_name_ = name;
68 } 69 }
69 70
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 } 123 }
123 124
124 void Combobox::OnBlur() { 125 void Combobox::OnBlur() {
125 if (native_wrapper_) 126 if (native_wrapper_)
126 native_wrapper_->HandleBlur(); 127 native_wrapper_->HandleBlur();
127 } 128 }
128 129
129 void Combobox::GetAccessibleState(ui::AccessibleViewState* state) { 130 void Combobox::GetAccessibleState(ui::AccessibleViewState* state) {
130 state->role = ui::AccessibilityTypes::ROLE_COMBOBOX; 131 state->role = ui::AccessibilityTypes::ROLE_COMBOBOX;
131 state->name = accessible_name_; 132 state->name = accessible_name_;
132 state->value = model_->GetItemAt(selected_item_); 133 state->value = model_->GetItemAt(selected_index_);
133 state->index = selected_item(); 134 state->index = selected_index_;
134 state->count = model()->GetItemCount(); 135 state->count = model()->GetItemCount();
135 } 136 }
136 137
137 void Combobox::ViewHierarchyChanged(bool is_add, View* parent, View* child) { 138 void Combobox::ViewHierarchyChanged(bool is_add, View* parent, View* child) {
138 if (is_add && !native_wrapper_ && GetWidget()) { 139 if (is_add && !native_wrapper_ && GetWidget()) {
139 // The native wrapper's lifetime will be managed by the view hierarchy after 140 // The native wrapper's lifetime will be managed by the view hierarchy after
140 // we call AddChildView. 141 // we call AddChildView.
141 native_wrapper_ = NativeComboboxWrapper::CreateWrapper(this); 142 native_wrapper_ = NativeComboboxWrapper::CreateWrapper(this);
142 AddChildView(native_wrapper_->GetView()); 143 AddChildView(native_wrapper_->GetView());
143 // The underlying native widget may not be created until the wrapper is 144 // The underlying native widget may not be created until the wrapper is
144 // parented. For this reason the wrapper is only updated after adding its 145 // parented. For this reason the wrapper is only updated after adding its
145 // view. 146 // view.
146 native_wrapper_->UpdateFromModel(); 147 native_wrapper_->UpdateFromModel();
147 native_wrapper_->UpdateSelectedItem(); 148 native_wrapper_->UpdateSelectedIndex();
148 native_wrapper_->UpdateEnabled(); 149 native_wrapper_->UpdateEnabled();
149 } 150 }
150 } 151 }
151 152
152 std::string Combobox::GetClassName() const { 153 std::string Combobox::GetClassName() const {
153 return kViewClassName; 154 return kViewClassName;
154 } 155 }
155 156
156 } // namespace views 157 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/combobox/combobox.h ('k') | ui/views/controls/combobox/native_combobox_views.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698