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