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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « views/controls/combobox/combobox.h ('k') | views/controls/combobox/native_combobox_gtk.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: views/controls/combobox/combobox.cc
===================================================================
--- views/controls/combobox/combobox.cc (revision 0)
+++ views/controls/combobox/combobox.cc (revision 0)
@@ -0,0 +1,104 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "views/controls/combobox/combobox.h"
+
+#include "views/controls/combobox/native_combobox_wrapper.h"
+
+namespace views {
+
+// static
+const char Combobox::kViewClassName[] = "views/Combobox";
+
+////////////////////////////////////////////////////////////////////////////////
+// Combobox, public:
+
+Combobox::Combobox(Model* model)
+ : native_wrapper_(NULL),
+ model_(model),
+ listener_(NULL),
+ selected_item_(0) {
+}
+
+Combobox::~Combobox() {
+}
+
+void Combobox::ModelChanged() {
+ selected_item_ = std::min(0, model_->GetItemCount(this));
+ if (native_wrapper_)
+ native_wrapper_->UpdateFromModel();
+}
+
+void Combobox::SetSelectedItem(int index) {
+ selected_item_ = index;
+ if (native_wrapper_)
+ native_wrapper_->UpdateSelectedItem();
+}
+
+void Combobox::SelectionChanged() {
+ int prev_selected_item = selected_item_;
+ selected_item_ = native_wrapper_->GetSelectedItem();
+ if (listener_)
+ listener_->ItemChanged(this, prev_selected_item, selected_item_);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Combobox, View overrides:
+
+gfx::Size Combobox::GetPreferredSize() {
+ if (native_wrapper_)
+ return native_wrapper_->GetPreferredSize();
+ return gfx::Size();
+}
+
+void Combobox::Layout() {
+ if (native_wrapper_) {
+ native_wrapper_->GetView()->SetBounds(0, 0, width(), height());
+ native_wrapper_->GetView()->Layout();
+ }
+}
+
+void Combobox::SetEnabled(bool flag) {
+ View::SetEnabled(flag);
+ if (native_wrapper_)
+ native_wrapper_->UpdateEnabled();
+}
+
+// VK_ESCAPE should be handled by this view when the drop down list is active.
+// In other words, the list should be closed instead of the dialog.
+bool Combobox::OverrideAccelerator(const Accelerator& accelerator) {
+#if defined(OS_WIN)
+ if (accelerator != Accelerator(VK_ESCAPE, false, false, false))
+ return false;
+#else
+ NOTIMPLEMENTED();
+ // TODO(port): figure out VK_keys
+#endif
+ return native_wrapper_ && native_wrapper_->IsDropdownOpen();
+}
+
+void Combobox::Focus() {
+ // Forward the focus to the wrapper.
+ if (native_wrapper_)
+ native_wrapper_->SetFocus();
+ else
+ View::Focus(); // Will focus the RootView window (so we still get
+ // keyboard messages).
+}
+
+void Combobox::ViewHierarchyChanged(bool is_add, View* parent,
+ View* child) {
+ if (is_add && !native_wrapper_ && GetWidget()) {
+ native_wrapper_ = NativeComboboxWrapper::CreateWrapper(this);
+ native_wrapper_->UpdateFromModel();
+ native_wrapper_->UpdateEnabled();
+ AddChildView(native_wrapper_->GetView());
+ }
+}
+
+std::string Combobox::GetClassName() const {
+ return kViewClassName;
+}
+
+} // namespace views
« 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