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

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

Issue 273223002: views: Make view::Views::GetPreferredSize() const. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More compile fix for ToT Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/views/controls/combobox/combobox.h ('k') | ui/views/controls/image_view.h » ('j') | 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/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
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
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
OLDNEW
« no previous file with comments | « ui/views/controls/combobox/combobox.h ('k') | ui/views/controls/image_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698