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

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

Issue 113991: Make Combobox portable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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
« no previous file with comments | « views/controls/combobox/combobox.h ('k') | views/controls/combobox/native_combobox_gtk.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "views/controls/combobox/combobox.h"
6
7 #include "views/controls/combobox/native_combobox_wrapper.h"
8
9 namespace views {
10
11 // static
12 const char Combobox::kViewClassName[] = "views/Combobox";
13
14 ////////////////////////////////////////////////////////////////////////////////
15 // Combobox, public:
16
17 Combobox::Combobox(Model* model)
18 : native_wrapper_(NULL),
19 model_(model),
20 listener_(NULL),
21 selected_item_(0) {
22 }
23
24 Combobox::~Combobox() {
25 }
26
27 void Combobox::ModelChanged() {
28 selected_item_ = std::min(0, model_->GetItemCount(this));
29 if (native_wrapper_)
30 native_wrapper_->UpdateFromModel();
31 }
32
33 void Combobox::SetSelectedItem(int index) {
34 selected_item_ = index;
35 if (native_wrapper_)
36 native_wrapper_->UpdateSelectedItem();
37 }
38
39 void Combobox::SelectionChanged() {
40 int prev_selected_item = selected_item_;
41 selected_item_ = native_wrapper_->GetSelectedItem();
42 if (listener_)
43 listener_->ItemChanged(this, prev_selected_item, selected_item_);
44 }
45
46 ////////////////////////////////////////////////////////////////////////////////
47 // Combobox, View overrides:
48
49 gfx::Size Combobox::GetPreferredSize() {
50 if (native_wrapper_)
51 return native_wrapper_->GetPreferredSize();
52 return gfx::Size();
53 }
54
55 void Combobox::Layout() {
56 if (native_wrapper_) {
57 native_wrapper_->GetView()->SetBounds(0, 0, width(), height());
58 native_wrapper_->GetView()->Layout();
59 }
60 }
61
62 void Combobox::SetEnabled(bool flag) {
63 View::SetEnabled(flag);
64 if (native_wrapper_)
65 native_wrapper_->UpdateEnabled();
66 }
67
68 // VK_ESCAPE should be handled by this view when the drop down list is active.
69 // In other words, the list should be closed instead of the dialog.
70 bool Combobox::OverrideAccelerator(const Accelerator& accelerator) {
71 #if defined(OS_WIN)
72 if (accelerator != Accelerator(VK_ESCAPE, false, false, false))
73 return false;
74 #else
75 NOTIMPLEMENTED();
76 // TODO(port): figure out VK_keys
77 #endif
78 return native_wrapper_ && native_wrapper_->IsDropdownOpen();
79 }
80
81 void Combobox::Focus() {
82 // Forward the focus to the wrapper.
83 if (native_wrapper_)
84 native_wrapper_->SetFocus();
85 else
86 View::Focus(); // Will focus the RootView window (so we still get
87 // keyboard messages).
88 }
89
90 void Combobox::ViewHierarchyChanged(bool is_add, View* parent,
91 View* child) {
92 if (is_add && !native_wrapper_ && GetWidget()) {
93 native_wrapper_ = NativeComboboxWrapper::CreateWrapper(this);
94 native_wrapper_->UpdateFromModel();
95 native_wrapper_->UpdateEnabled();
96 AddChildView(native_wrapper_->GetView());
97 }
98 }
99
100 std::string Combobox::GetClassName() const {
101 return kViewClassName;
102 }
103
104 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/combobox/combobox.h ('k') | views/controls/combobox/native_combobox_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698