OLD | NEW |
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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 | 371 |
372 bool Combobox::IsCommandEnabled(int id) const { | 372 bool Combobox::IsCommandEnabled(int id) const { |
373 return model()->IsItemEnabledAt(MenuCommandToIndex(id)); | 373 return model()->IsItemEnabledAt(MenuCommandToIndex(id)); |
374 } | 374 } |
375 | 375 |
376 void Combobox::ExecuteCommand(int id) { | 376 void Combobox::ExecuteCommand(int id) { |
377 selected_index_ = MenuCommandToIndex(id); | 377 selected_index_ = MenuCommandToIndex(id); |
378 OnPerformAction(); | 378 OnPerformAction(); |
379 } | 379 } |
380 | 380 |
381 bool Combobox::GetAccelerator(int id, ui::Accelerator* accel) { | 381 bool Combobox::GetAccelerator(int id, ui::Accelerator* accel) const { |
382 return false; | 382 return false; |
383 } | 383 } |
384 | 384 |
385 int Combobox::GetRowCount() { | 385 int Combobox::GetRowCount() { |
386 return model()->GetItemCount(); | 386 return model()->GetItemCount(); |
387 } | 387 } |
388 | 388 |
389 int Combobox::GetSelectedRow() { | 389 int Combobox::GetSelectedRow() { |
390 return selected_index_; | 390 return selected_index_; |
391 } | 391 } |
392 | 392 |
393 void Combobox::SetSelectedRow(int row) { | 393 void Combobox::SetSelectedRow(int row) { |
394 int prev_index = selected_index_; | 394 int prev_index = selected_index_; |
395 SetSelectedIndex(row); | 395 SetSelectedIndex(row); |
396 if (selected_index_ != prev_index) | 396 if (selected_index_ != prev_index) |
397 OnPerformAction(); | 397 OnPerformAction(); |
398 } | 398 } |
399 | 399 |
400 base::string16 Combobox::GetTextForRow(int row) { | 400 base::string16 Combobox::GetTextForRow(int row) { |
401 return model()->IsItemSeparatorAt(row) ? base::string16() : | 401 return model()->IsItemSeparatorAt(row) ? base::string16() : |
402 model()->GetItemAt(row); | 402 model()->GetItemAt(row); |
403 } | 403 } |
404 | 404 |
405 //////////////////////////////////////////////////////////////////////////////// | 405 //////////////////////////////////////////////////////////////////////////////// |
406 // Combobox, View overrides: | 406 // Combobox, View overrides: |
407 | 407 |
408 gfx::Size Combobox::GetPreferredSize() { | 408 gfx::Size Combobox::GetPreferredSize() const { |
409 if (content_size_.IsEmpty()) | |
410 UpdateFromModel(); | |
411 | |
412 // The preferred size will drive the local bounds which in turn is used to set | 409 // The preferred size will drive the local bounds which in turn is used to set |
413 // the minimum width for the dropdown list. | 410 // the minimum width for the dropdown list. |
414 gfx::Insets insets = GetInsets(); | 411 gfx::Insets insets = GetInsets(); |
415 int total_width = std::max(kMinComboboxWidth, content_size_.width()) + | 412 int total_width = std::max(kMinComboboxWidth, content_size_.width()) + |
416 insets.width() + GetDisclosureArrowLeftPadding() + | 413 insets.width() + GetDisclosureArrowLeftPadding() + |
417 disclosure_arrow_->width() + GetDisclosureArrowRightPadding(); | 414 disclosure_arrow_->width() + GetDisclosureArrowRightPadding(); |
418 return gfx::Size(total_width, content_size_.height() + insets.height()); | 415 return gfx::Size(total_width, content_size_.height() + insets.height()); |
419 } | 416 } |
420 | 417 |
421 const char* Combobox::GetClassName() const { | 418 const char* Combobox::GetClassName() const { |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 case STYLE_NORMAL: | 823 case STYLE_NORMAL: |
827 return kDisclosureArrowRightPadding; | 824 return kDisclosureArrowRightPadding; |
828 case STYLE_ACTION: | 825 case STYLE_ACTION: |
829 return kDisclosureArrowButtonRightPadding; | 826 return kDisclosureArrowButtonRightPadding; |
830 } | 827 } |
831 NOTREACHED(); | 828 NOTREACHED(); |
832 return 0; | 829 return 0; |
833 } | 830 } |
834 | 831 |
835 } // namespace views | 832 } // namespace views |
OLD | NEW |