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

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

Issue 1971333002: Views: factor out Combobox background and const-ify style (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Redo PositionArrowWithinShoulder Created 4 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
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 28 matching lines...) Expand all
39 #include "ui/views/mouse_constants.h" 39 #include "ui/views/mouse_constants.h"
40 #include "ui/views/painter.h" 40 #include "ui/views/painter.h"
41 #include "ui/views/resources/grit/views_resources.h" 41 #include "ui/views/resources/grit/views_resources.h"
42 #include "ui/views/style/platform_style.h" 42 #include "ui/views/style/platform_style.h"
43 #include "ui/views/widget/widget.h" 43 #include "ui/views/widget/widget.h"
44 44
45 namespace views { 45 namespace views {
46 46
47 namespace { 47 namespace {
48 48
49 // Action style shoulder padding widths
50 const int kActionLeftPadding = 12;
51 const int kActionRightPadding = 11;
52
49 // Menu border widths 53 // Menu border widths
50 const int kMenuBorderWidthLeft = 1; 54 const int kMenuBorderWidthLeft = 1;
51 const int kMenuBorderWidthTop = 1; 55 const int kMenuBorderWidthTop = 1;
52 const int kMenuBorderWidthRight = 1; 56 const int kMenuBorderWidthRight = 1;
53 57
54 // Limit how small a combobox can be. 58 // Limit how small a combobox can be.
55 const int kMinComboboxWidth = 25; 59 const int kMinComboboxWidth = 25;
56 60
57 // Size of the combobox arrow margins
58 const int kDisclosureArrowLeftPadding = 7;
59 const int kDisclosureArrowRightPadding = 7;
60 const int kDisclosureArrowButtonLeftPadding = 11;
61 const int kDisclosureArrowButtonRightPadding = 12;
62
63 // Define the id of the first item in the menu (since it needs to be > 0) 61 // Define the id of the first item in the menu (since it needs to be > 0)
64 const int kFirstMenuItemId = 1000; 62 const int kFirstMenuItemId = 1000;
65 63
66 // Used to indicate that no item is currently selected by the user. 64 // Used to indicate that no item is currently selected by the user.
67 const int kNoSelection = -1; 65 const int kNoSelection = -1;
68 66
69 const int kBodyButtonImages[] = IMAGE_GRID(IDR_COMBOBOX_BUTTON); 67 const int kBodyButtonImages[] = IMAGE_GRID(IDR_COMBOBOX_BUTTON);
70 const int kHoveredBodyButtonImages[] = IMAGE_GRID(IDR_COMBOBOX_BUTTON_H); 68 const int kHoveredBodyButtonImages[] = IMAGE_GRID(IDR_COMBOBOX_BUTTON_H);
71 const int kPressedBodyButtonImages[] = IMAGE_GRID(IDR_COMBOBOX_BUTTON_P); 69 const int kPressedBodyButtonImages[] = IMAGE_GRID(IDR_COMBOBOX_BUTTON_P);
72 const int kFocusedBodyButtonImages[] = IMAGE_GRID(IDR_COMBOBOX_BUTTON_F); 70 const int kFocusedBodyButtonImages[] = IMAGE_GRID(IDR_COMBOBOX_BUTTON_F);
73 const int kFocusedHoveredBodyButtonImages[] = 71 const int kFocusedHoveredBodyButtonImages[] =
74 IMAGE_GRID(IDR_COMBOBOX_BUTTON_F_H); 72 IMAGE_GRID(IDR_COMBOBOX_BUTTON_F_H);
75 const int kFocusedPressedBodyButtonImages[] = 73 const int kFocusedPressedBodyButtonImages[] =
76 IMAGE_GRID(IDR_COMBOBOX_BUTTON_F_P); 74 IMAGE_GRID(IDR_COMBOBOX_BUTTON_F_P);
77 75
78 #define MENU_IMAGE_GRID(x) { \ 76 #define MENU_IMAGE_GRID(x) { \
79 x ## _MENU_TOP, x ## _MENU_CENTER, x ## _MENU_BOTTOM, } 77 x ## _MENU_TOP, x ## _MENU_CENTER, x ## _MENU_BOTTOM, }
80 78
81 const int kMenuButtonImages[] = MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON); 79 const int kMenuButtonImages[] = MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON);
82 const int kHoveredMenuButtonImages[] = MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_H); 80 const int kHoveredMenuButtonImages[] = MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_H);
83 const int kPressedMenuButtonImages[] = MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_P); 81 const int kPressedMenuButtonImages[] = MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_P);
84 const int kFocusedMenuButtonImages[] = MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_F); 82 const int kFocusedMenuButtonImages[] = MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_F);
85 const int kFocusedHoveredMenuButtonImages[] = 83 const int kFocusedHoveredMenuButtonImages[] =
86 MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_F_H); 84 MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_F_H);
87 const int kFocusedPressedMenuButtonImages[] = 85 const int kFocusedPressedMenuButtonImages[] =
88 MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_F_P); 86 MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_F_P);
89 87
90 #undef MENU_IMAGE_GRID 88 #undef MENU_IMAGE_GRID
91 89
90 gfx::Rect PositionArrowWithinShoulder(const gfx::Rect& shoulder_bounds,
sky 2016/05/17 16:49:21 similar comment about naming.
Elly Fong-Jones 2016/05/17 17:35:05 -> PositionArrowWithinContainer
91 const gfx::Size& arrow_size,
92 Combobox::Style style) {
93 gfx::Rect bounds(shoulder_bounds);
94 if (style == Combobox::STYLE_ACTION) {
95 // This positions the arrow horizontally. The later call to
96 // ClampToCenteredSize will position it vertically without touching the
97 // horizontal position.
98 bounds.Inset(kActionLeftPadding, 0, kActionRightPadding, 0);
99 DCHECK_EQ(bounds.width(), arrow_size.width());
100 }
101
102 bounds.ClampToCenteredSize(arrow_size);
103 return bounds;
104 }
105
92 // The transparent button which holds a button state but is not rendered. 106 // The transparent button which holds a button state but is not rendered.
93 class TransparentButton : public CustomButton { 107 class TransparentButton : public CustomButton {
94 public: 108 public:
95 TransparentButton(ButtonListener* listener) 109 TransparentButton(ButtonListener* listener)
96 : CustomButton(listener) { 110 : CustomButton(listener) {
97 SetAnimationDuration(LabelButton::kHoverAnimationDurationMs); 111 SetAnimationDuration(LabelButton::kHoverAnimationDurationMs);
98 SetFocusBehavior(FocusBehavior::NEVER); 112 SetFocusBehavior(FocusBehavior::NEVER);
99 } 113 }
100 ~TransparentButton() override {} 114 ~TransparentButton() override {}
101 115
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 350
337 Combobox* owner_; // Weak. Owns this. 351 Combobox* owner_; // Weak. Owns this.
338 ui::ComboboxModel* model_; // Weak. 352 ui::ComboboxModel* model_; // Weak.
339 353
340 DISALLOW_COPY_AND_ASSIGN(ComboboxMenuModelAdapter); 354 DISALLOW_COPY_AND_ASSIGN(ComboboxMenuModelAdapter);
341 }; 355 };
342 356
343 //////////////////////////////////////////////////////////////////////////////// 357 ////////////////////////////////////////////////////////////////////////////////
344 // Combobox, public: 358 // Combobox, public:
345 359
346 Combobox::Combobox(ui::ComboboxModel* model) 360 Combobox::Combobox(ui::ComboboxModel* model, Style style)
347 : model_(model), 361 : model_(model),
348 style_(STYLE_NORMAL), 362 style_(style),
349 listener_(NULL), 363 listener_(NULL),
350 selected_index_(model_->GetDefaultIndex()), 364 selected_index_(model_->GetDefaultIndex()),
351 invalid_(false), 365 invalid_(false),
352 menu_model_adapter_(new ComboboxMenuModelAdapter(this, model)), 366 menu_model_adapter_(new ComboboxMenuModelAdapter(this, model)),
353 text_button_(new TransparentButton(this)), 367 text_button_(new TransparentButton(this)),
354 arrow_button_(new TransparentButton(this)), 368 arrow_button_(new TransparentButton(this)),
355 weak_ptr_factory_(this) { 369 weak_ptr_factory_(this) {
370 if (style_ == STYLE_ACTION)
sky 2016/05/17 16:49:21 nit: move to initializer on 364.
Elly Fong-Jones 2016/05/17 17:35:05 Done.
371 selected_index_ = 0;
372
356 ModelChanged(); 373 ModelChanged();
357 #if defined(OS_MACOSX) 374 #if defined(OS_MACOSX)
358 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); 375 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY);
359 #else 376 #else
360 SetFocusBehavior(FocusBehavior::ALWAYS); 377 SetFocusBehavior(FocusBehavior::ALWAYS);
361 #endif 378 #endif
362 379
363 UpdateBorder(); 380 UpdateBorder();
381 arrow_image_ = PlatformStyle::CreateComboboxArrow(enabled(), style);
364 // set_background() takes ownership but takes a raw pointer. 382 // set_background() takes ownership but takes a raw pointer.
365 std::unique_ptr<Background> b = PlatformStyle::CreateComboboxBackground(); 383 std::unique_ptr<Background> b =
384 PlatformStyle::CreateComboboxBackground(GetShoulderWidth());
366 set_background(b.release()); 385 set_background(b.release());
367 386
368 // Initialize the button images. 387 // Initialize the button images.
369 Button::ButtonState button_states[] = { 388 Button::ButtonState button_states[] = {
370 Button::STATE_DISABLED, 389 Button::STATE_DISABLED,
371 Button::STATE_NORMAL, 390 Button::STATE_NORMAL,
372 Button::STATE_HOVERED, 391 Button::STATE_HOVERED,
373 Button::STATE_PRESSED, 392 Button::STATE_PRESSED,
374 }; 393 };
375 for (int i = 0; i < 2; i++) { 394 for (int i = 0; i < 2; i++) {
(...skipping 21 matching lines...) Expand all
397 DCHECK(selector_.get() != GetInputMethod()->GetTextInputClient()); 416 DCHECK(selector_.get() != GetInputMethod()->GetTextInputClient());
398 } 417 }
399 } 418 }
400 419
401 // static 420 // static
402 const gfx::FontList& Combobox::GetFontList() { 421 const gfx::FontList& Combobox::GetFontList() {
403 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 422 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
404 return rb.GetFontListWithDelta(ui::kLabelFontSizeDelta); 423 return rb.GetFontListWithDelta(ui::kLabelFontSizeDelta);
405 } 424 }
406 425
407 void Combobox::SetStyle(Style style) {
408 if (style_ == style)
409 return;
410
411 style_ = style;
412 if (style_ == STYLE_ACTION)
413 selected_index_ = 0;
414
415 UpdateBorder();
416 content_size_ = GetContentSize();
417 PreferredSizeChanged();
418 }
419
420 void Combobox::ModelChanged() { 426 void Combobox::ModelChanged() {
421 // If the selection is no longer valid (or the model is empty), restore the 427 // If the selection is no longer valid (or the model is empty), restore the
422 // default index. 428 // default index.
423 if (selected_index_ >= model_->GetItemCount() || 429 if (selected_index_ >= model_->GetItemCount() ||
424 model_->GetItemCount() == 0 || 430 model_->GetItemCount() == 0 ||
425 model_->IsItemSeparatorAt(selected_index_)) { 431 model_->IsItemSeparatorAt(selected_index_)) {
426 selected_index_ = model_->GetDefaultIndex(); 432 selected_index_ = model_->GetDefaultIndex();
427 } 433 }
428 434
429 content_size_ = GetContentSize(); 435 content_size_ = GetContentSize();
(...skipping 28 matching lines...) Expand all
458 void Combobox::SetInvalid(bool invalid) { 464 void Combobox::SetInvalid(bool invalid) {
459 if (invalid == invalid_) 465 if (invalid == invalid_)
460 return; 466 return;
461 467
462 invalid_ = invalid; 468 invalid_ = invalid;
463 469
464 UpdateBorder(); 470 UpdateBorder();
465 SchedulePaint(); 471 SchedulePaint();
466 } 472 }
467 473
468 int Combobox::GetArrowButtonWidth() const {
469 return GetDisclosureArrowLeftPadding() +
470 ArrowSize().width() +
471 GetDisclosureArrowRightPadding();
472 }
473
474 void Combobox::Layout() { 474 void Combobox::Layout() {
475 PrefixDelegate::Layout(); 475 PrefixDelegate::Layout();
476 476
477 gfx::Insets insets = GetInsets(); 477 gfx::Insets insets = GetInsets();
478 int text_button_width = 0; 478 int text_button_width = 0;
479 int arrow_button_width = 0; 479 int arrow_button_width = 0;
480 480
481 switch (style_) { 481 switch (style_) {
482 case STYLE_NORMAL: { 482 case STYLE_NORMAL: {
483 arrow_button_width = width(); 483 arrow_button_width = width();
484 break; 484 break;
485 } 485 }
486 case STYLE_ACTION: { 486 case STYLE_ACTION: {
487 arrow_button_width = GetDisclosureArrowLeftPadding() + 487 arrow_button_width = GetShoulderWidth();
488 ArrowSize().width() +
489 GetDisclosureArrowRightPadding();
490 text_button_width = width() - arrow_button_width; 488 text_button_width = width() - arrow_button_width;
491 break; 489 break;
492 } 490 }
493 } 491 }
494 492
495 int arrow_button_x = std::max(0, text_button_width); 493 int arrow_button_x = std::max(0, text_button_width);
496 text_button_->SetBounds(0, 0, std::max(0, text_button_width), height()); 494 text_button_->SetBounds(0, 0, std::max(0, text_button_width), height());
497 arrow_button_->SetBounds(arrow_button_x, 0, arrow_button_width, height()); 495 arrow_button_->SetBounds(arrow_button_x, 0, arrow_button_width, height());
498 } 496 }
499 497
498 void Combobox::OnEnabledChanged() {
499 PrefixDelegate::OnEnabledChanged();
500 arrow_image_ = PlatformStyle::CreateComboboxArrow(enabled(), style_);
501 }
502
500 int Combobox::GetRowCount() { 503 int Combobox::GetRowCount() {
501 return model()->GetItemCount(); 504 return model()->GetItemCount();
502 } 505 }
503 506
504 int Combobox::GetSelectedRow() { 507 int Combobox::GetSelectedRow() {
505 return selected_index_; 508 return selected_index_;
506 } 509 }
507 510
508 void Combobox::SetSelectedRow(int row) { 511 void Combobox::SetSelectedRow(int row) {
509 int prev_index = selected_index_; 512 int prev_index = selected_index_;
(...skipping 12 matching lines...) Expand all
522 525
523 gfx::Size Combobox::GetPreferredSize() const { 526 gfx::Size Combobox::GetPreferredSize() const {
524 // The preferred size will drive the local bounds which in turn is used to set 527 // The preferred size will drive the local bounds which in turn is used to set
525 // the minimum width for the dropdown list. 528 // the minimum width for the dropdown list.
526 gfx::Insets insets = GetInsets(); 529 gfx::Insets insets = GetInsets();
527 insets += gfx::Insets(Textfield::kTextPadding, 530 insets += gfx::Insets(Textfield::kTextPadding,
528 Textfield::kTextPadding, 531 Textfield::kTextPadding,
529 Textfield::kTextPadding, 532 Textfield::kTextPadding,
530 Textfield::kTextPadding); 533 Textfield::kTextPadding);
531 int total_width = std::max(kMinComboboxWidth, content_size_.width()) + 534 int total_width = std::max(kMinComboboxWidth, content_size_.width()) +
532 insets.width() + GetDisclosureArrowLeftPadding() + 535 insets.width() + GetShoulderWidth();
533 ArrowSize().width() + GetDisclosureArrowRightPadding();
534 return gfx::Size(total_width, content_size_.height() + insets.height()); 536 return gfx::Size(total_width, content_size_.height() + insets.height());
535 } 537 }
536 538
537 const char* Combobox::GetClassName() const { 539 const char* Combobox::GetClassName() const {
538 return kViewClassName; 540 return kViewClassName;
539 } 541 }
540 542
541 bool Combobox::SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) { 543 bool Combobox::SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) {
542 // Escape should close the drop down list when it is active, not host UI. 544 // Escape should close the drop down list when it is active, not host UI.
543 if (e.key_code() != ui::VKEY_ESCAPE || 545 if (e.key_code() != ui::VKEY_ESCAPE ||
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 enabled() ? ui::NativeTheme::kColorId_LabelEnabledColor : 733 enabled() ? ui::NativeTheme::kColorId_LabelEnabledColor :
732 ui::NativeTheme::kColorId_LabelDisabledColor); 734 ui::NativeTheme::kColorId_LabelDisabledColor);
733 735
734 DCHECK_GE(selected_index_, 0); 736 DCHECK_GE(selected_index_, 0);
735 DCHECK_LT(selected_index_, model()->GetItemCount()); 737 DCHECK_LT(selected_index_, model()->GetItemCount());
736 if (selected_index_ < 0 || selected_index_ > model()->GetItemCount()) 738 if (selected_index_ < 0 || selected_index_ > model()->GetItemCount())
737 selected_index_ = 0; 739 selected_index_ = 0;
738 base::string16 text = model()->GetItemAt(selected_index_); 740 base::string16 text = model()->GetItemAt(selected_index_);
739 741
740 gfx::Size arrow_size = ArrowSize(); 742 gfx::Size arrow_size = ArrowSize();
741 int disclosure_arrow_offset = width() - arrow_size.width() - 743 int disclosure_arrow_offset = width() - GetShoulderWidth();
742 GetDisclosureArrowLeftPadding() - GetDisclosureArrowRightPadding();
743 744
744 const gfx::FontList& font_list = Combobox::GetFontList(); 745 const gfx::FontList& font_list = Combobox::GetFontList();
745 int text_width = gfx::GetStringWidth(text, font_list); 746 int text_width = gfx::GetStringWidth(text, font_list);
746 if ((text_width + insets.width()) > disclosure_arrow_offset) 747 if ((text_width + insets.width()) > disclosure_arrow_offset)
747 text_width = disclosure_arrow_offset - insets.width(); 748 text_width = disclosure_arrow_offset - insets.width();
748 749
749 gfx::Rect text_bounds(x, y, text_width, text_height); 750 gfx::Rect text_bounds(x, y, text_width, text_height);
750 AdjustBoundsForRTLUI(&text_bounds); 751 AdjustBoundsForRTLUI(&text_bounds);
751 canvas->DrawStringRect(text, font_list, text_color, text_bounds); 752 canvas->DrawStringRect(text, font_list, text_color, text_bounds);
752 753
753 int arrow_x = disclosure_arrow_offset + GetDisclosureArrowLeftPadding(); 754 gfx::Rect arrow_bounds(disclosure_arrow_offset, 0, GetShoulderWidth(),
754 gfx::Rect arrow_bounds(arrow_x, 755 height());
755 height() / 2 - arrow_size.height() / 2, 756 arrow_bounds = PositionArrowWithinShoulder(arrow_bounds, ArrowSize(), style_);
756 arrow_size.width(),
757 arrow_size.height());
758 AdjustBoundsForRTLUI(&arrow_bounds); 757 AdjustBoundsForRTLUI(&arrow_bounds);
759 758
760 gfx::ImageSkia arrow_image = PlatformStyle::CreateComboboxArrow( 759 canvas->DrawImageInt(arrow_image_, arrow_bounds.x(), arrow_bounds.y());
761 enabled(), style_);
762 canvas->DrawImageInt(arrow_image, arrow_bounds.x(), arrow_bounds.y());
763 } 760 }
764 761
765 void Combobox::PaintButtons(gfx::Canvas* canvas) { 762 void Combobox::PaintButtons(gfx::Canvas* canvas) {
766 DCHECK(style_ == STYLE_ACTION); 763 DCHECK(style_ == STYLE_ACTION);
767 764
768 gfx::ScopedCanvas scoped_canvas(canvas); 765 gfx::ScopedRTLFlipCanvas scoped_canvas(canvas, bounds());
769 if (base::i18n::IsRTL()) {
770 canvas->Translate(gfx::Vector2d(width(), 0));
771 canvas->Scale(-1, 1);
772 }
773 766
774 bool focused = HasFocus(); 767 bool focused = HasFocus();
775 const std::vector<const gfx::ImageSkia*>& arrow_button_images = 768 const std::vector<const gfx::ImageSkia*>& arrow_button_images =
776 menu_button_images_[focused][ 769 menu_button_images_[focused][
777 arrow_button_->state() == Button::STATE_HOVERED ? 770 arrow_button_->state() == Button::STATE_HOVERED ?
778 Button::STATE_NORMAL : arrow_button_->state()]; 771 Button::STATE_NORMAL : arrow_button_->state()];
779 772
780 int text_button_hover_alpha = 773 int text_button_hover_alpha =
781 text_button_->state() == Button::STATE_PRESSED ? 0 : 774 text_button_->state() == Button::STATE_PRESSED ? 0 :
782 static_cast<int>(static_cast<TransparentButton*>(text_button_)-> 775 static_cast<int>(static_cast<TransparentButton*>(text_button_)->
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 863
871 // This combobox may be deleted by the listener. 864 // This combobox may be deleted by the listener.
872 base::WeakPtr<Combobox> weak_ptr = weak_ptr_factory_.GetWeakPtr(); 865 base::WeakPtr<Combobox> weak_ptr = weak_ptr_factory_.GetWeakPtr();
873 if (listener_) 866 if (listener_)
874 listener_->OnPerformAction(this); 867 listener_->OnPerformAction(this);
875 868
876 if (weak_ptr && style_ == STYLE_ACTION) 869 if (weak_ptr && style_ == STYLE_ACTION)
877 selected_index_ = 0; 870 selected_index_ = 0;
878 } 871 }
879 872
880 int Combobox::GetDisclosureArrowLeftPadding() const {
881 switch (style_) {
882 case STYLE_NORMAL:
883 return kDisclosureArrowLeftPadding;
884 case STYLE_ACTION:
885 return kDisclosureArrowButtonLeftPadding;
886 }
887 NOTREACHED();
888 return 0;
889 }
890
891 int Combobox::GetDisclosureArrowRightPadding() const {
892 switch (style_) {
893 case STYLE_NORMAL:
894 return kDisclosureArrowRightPadding;
895 case STYLE_ACTION:
896 return kDisclosureArrowButtonRightPadding;
897 }
898 NOTREACHED();
899 return 0;
900 }
901
902 gfx::Size Combobox::ArrowSize() const { 873 gfx::Size Combobox::ArrowSize() const {
903 return PlatformStyle::CreateComboboxArrow(enabled(), style_).size(); 874 return arrow_image_.size();
904 } 875 }
905 876
906 gfx::Size Combobox::GetContentSize() const { 877 gfx::Size Combobox::GetContentSize() const {
907 const gfx::FontList& font_list = GetFontList(); 878 const gfx::FontList& font_list = GetFontList();
908 879
909 int width = 0; 880 int width = 0;
910 for (int i = 0; i < model()->GetItemCount(); ++i) { 881 for (int i = 0; i < model()->GetItemCount(); ++i) {
911 if (model_->IsItemSeparatorAt(i)) 882 if (model_->IsItemSeparatorAt(i))
912 continue; 883 continue;
913 884
914 if (style_ != STYLE_ACTION || i == selected_index_) { 885 if (style_ != STYLE_ACTION || i == selected_index_) {
915 width = std::max( 886 width = std::max(
916 width, 887 width,
917 gfx::GetStringWidth(menu_model_adapter_->GetLabelAt(i), font_list)); 888 gfx::GetStringWidth(menu_model_adapter_->GetLabelAt(i), font_list));
918 } 889 }
919 } 890 }
920 return gfx::Size(width, font_list.GetHeight()); 891 return gfx::Size(width, font_list.GetHeight());
921 } 892 }
922 893
923 PrefixSelector* Combobox::GetPrefixSelector() { 894 PrefixSelector* Combobox::GetPrefixSelector() {
924 if (!selector_) 895 if (!selector_)
925 selector_.reset(new PrefixSelector(this)); 896 selector_.reset(new PrefixSelector(this));
926 return selector_.get(); 897 return selector_.get();
927 } 898 }
928 899
900 int Combobox::GetShoulderWidth() const {
901 const int kNormalPadding = 7;
902 int padding = style_ == STYLE_NORMAL ?
903 kNormalPadding * 2 :
904 kActionLeftPadding + kActionRightPadding;
905 return ArrowSize().width() + padding;
906 }
907
929 } // namespace views 908 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698