| 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 28 matching lines...) Expand all Loading... |
| 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 arrow container 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 PositionArrowWithinContainer(const gfx::Rect& container_bounds, |
| 91 const gfx::Size& arrow_size, |
| 92 Combobox::Style style) { |
| 93 gfx::Rect bounds(container_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 Loading... |
| 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_(style == STYLE_ACTION ? 0 : 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) { |
| 356 ModelChanged(); | 370 ModelChanged(); |
| 357 #if defined(OS_MACOSX) | 371 #if defined(OS_MACOSX) |
| 358 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); | 372 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); |
| 359 #else | 373 #else |
| 360 SetFocusBehavior(FocusBehavior::ALWAYS); | 374 SetFocusBehavior(FocusBehavior::ALWAYS); |
| 361 #endif | 375 #endif |
| 362 | 376 |
| 363 UpdateBorder(); | 377 UpdateBorder(); |
| 378 arrow_image_ = PlatformStyle::CreateComboboxArrow(enabled(), style); |
| 364 // set_background() takes ownership but takes a raw pointer. | 379 // set_background() takes ownership but takes a raw pointer. |
| 365 std::unique_ptr<Background> b = PlatformStyle::CreateComboboxBackground(); | 380 std::unique_ptr<Background> b = |
| 381 PlatformStyle::CreateComboboxBackground(GetArrowContainerWidth()); |
| 366 set_background(b.release()); | 382 set_background(b.release()); |
| 367 | 383 |
| 368 // Initialize the button images. | 384 // Initialize the button images. |
| 369 Button::ButtonState button_states[] = { | 385 Button::ButtonState button_states[] = { |
| 370 Button::STATE_DISABLED, | 386 Button::STATE_DISABLED, |
| 371 Button::STATE_NORMAL, | 387 Button::STATE_NORMAL, |
| 372 Button::STATE_HOVERED, | 388 Button::STATE_HOVERED, |
| 373 Button::STATE_PRESSED, | 389 Button::STATE_PRESSED, |
| 374 }; | 390 }; |
| 375 for (int i = 0; i < 2; i++) { | 391 for (int i = 0; i < 2; i++) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 397 DCHECK(selector_.get() != GetInputMethod()->GetTextInputClient()); | 413 DCHECK(selector_.get() != GetInputMethod()->GetTextInputClient()); |
| 398 } | 414 } |
| 399 } | 415 } |
| 400 | 416 |
| 401 // static | 417 // static |
| 402 const gfx::FontList& Combobox::GetFontList() { | 418 const gfx::FontList& Combobox::GetFontList() { |
| 403 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 419 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 404 return rb.GetFontListWithDelta(ui::kLabelFontSizeDelta); | 420 return rb.GetFontListWithDelta(ui::kLabelFontSizeDelta); |
| 405 } | 421 } |
| 406 | 422 |
| 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() { | 423 void Combobox::ModelChanged() { |
| 421 // If the selection is no longer valid (or the model is empty), restore the | 424 // If the selection is no longer valid (or the model is empty), restore the |
| 422 // default index. | 425 // default index. |
| 423 if (selected_index_ >= model_->GetItemCount() || | 426 if (selected_index_ >= model_->GetItemCount() || |
| 424 model_->GetItemCount() == 0 || | 427 model_->GetItemCount() == 0 || |
| 425 model_->IsItemSeparatorAt(selected_index_)) { | 428 model_->IsItemSeparatorAt(selected_index_)) { |
| 426 selected_index_ = model_->GetDefaultIndex(); | 429 selected_index_ = model_->GetDefaultIndex(); |
| 427 } | 430 } |
| 428 | 431 |
| 429 content_size_ = GetContentSize(); | 432 content_size_ = GetContentSize(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 458 void Combobox::SetInvalid(bool invalid) { | 461 void Combobox::SetInvalid(bool invalid) { |
| 459 if (invalid == invalid_) | 462 if (invalid == invalid_) |
| 460 return; | 463 return; |
| 461 | 464 |
| 462 invalid_ = invalid; | 465 invalid_ = invalid; |
| 463 | 466 |
| 464 UpdateBorder(); | 467 UpdateBorder(); |
| 465 SchedulePaint(); | 468 SchedulePaint(); |
| 466 } | 469 } |
| 467 | 470 |
| 468 int Combobox::GetArrowButtonWidth() const { | |
| 469 return GetDisclosureArrowLeftPadding() + | |
| 470 ArrowSize().width() + | |
| 471 GetDisclosureArrowRightPadding(); | |
| 472 } | |
| 473 | |
| 474 void Combobox::Layout() { | 471 void Combobox::Layout() { |
| 475 PrefixDelegate::Layout(); | 472 PrefixDelegate::Layout(); |
| 476 | 473 |
| 477 gfx::Insets insets = GetInsets(); | 474 gfx::Insets insets = GetInsets(); |
| 478 int text_button_width = 0; | 475 int text_button_width = 0; |
| 479 int arrow_button_width = 0; | 476 int arrow_button_width = 0; |
| 480 | 477 |
| 481 switch (style_) { | 478 switch (style_) { |
| 482 case STYLE_NORMAL: { | 479 case STYLE_NORMAL: { |
| 483 arrow_button_width = width(); | 480 arrow_button_width = width(); |
| 484 break; | 481 break; |
| 485 } | 482 } |
| 486 case STYLE_ACTION: { | 483 case STYLE_ACTION: { |
| 487 arrow_button_width = GetDisclosureArrowLeftPadding() + | 484 arrow_button_width = GetArrowContainerWidth(); |
| 488 ArrowSize().width() + | |
| 489 GetDisclosureArrowRightPadding(); | |
| 490 text_button_width = width() - arrow_button_width; | 485 text_button_width = width() - arrow_button_width; |
| 491 break; | 486 break; |
| 492 } | 487 } |
| 493 } | 488 } |
| 494 | 489 |
| 495 int arrow_button_x = std::max(0, text_button_width); | 490 int arrow_button_x = std::max(0, text_button_width); |
| 496 text_button_->SetBounds(0, 0, std::max(0, text_button_width), height()); | 491 text_button_->SetBounds(0, 0, std::max(0, text_button_width), height()); |
| 497 arrow_button_->SetBounds(arrow_button_x, 0, arrow_button_width, height()); | 492 arrow_button_->SetBounds(arrow_button_x, 0, arrow_button_width, height()); |
| 498 } | 493 } |
| 499 | 494 |
| 495 void Combobox::OnEnabledChanged() { |
| 496 PrefixDelegate::OnEnabledChanged(); |
| 497 arrow_image_ = PlatformStyle::CreateComboboxArrow(enabled(), style_); |
| 498 } |
| 499 |
| 500 int Combobox::GetRowCount() { | 500 int Combobox::GetRowCount() { |
| 501 return model()->GetItemCount(); | 501 return model()->GetItemCount(); |
| 502 } | 502 } |
| 503 | 503 |
| 504 int Combobox::GetSelectedRow() { | 504 int Combobox::GetSelectedRow() { |
| 505 return selected_index_; | 505 return selected_index_; |
| 506 } | 506 } |
| 507 | 507 |
| 508 void Combobox::SetSelectedRow(int row) { | 508 void Combobox::SetSelectedRow(int row) { |
| 509 int prev_index = selected_index_; | 509 int prev_index = selected_index_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 522 | 522 |
| 523 gfx::Size Combobox::GetPreferredSize() const { | 523 gfx::Size Combobox::GetPreferredSize() const { |
| 524 // The preferred size will drive the local bounds which in turn is used to set | 524 // The preferred size will drive the local bounds which in turn is used to set |
| 525 // the minimum width for the dropdown list. | 525 // the minimum width for the dropdown list. |
| 526 gfx::Insets insets = GetInsets(); | 526 gfx::Insets insets = GetInsets(); |
| 527 insets += gfx::Insets(Textfield::kTextPadding, | 527 insets += gfx::Insets(Textfield::kTextPadding, |
| 528 Textfield::kTextPadding, | 528 Textfield::kTextPadding, |
| 529 Textfield::kTextPadding, | 529 Textfield::kTextPadding, |
| 530 Textfield::kTextPadding); | 530 Textfield::kTextPadding); |
| 531 int total_width = std::max(kMinComboboxWidth, content_size_.width()) + | 531 int total_width = std::max(kMinComboboxWidth, content_size_.width()) + |
| 532 insets.width() + GetDisclosureArrowLeftPadding() + | 532 insets.width() + GetArrowContainerWidth(); |
| 533 ArrowSize().width() + GetDisclosureArrowRightPadding(); | |
| 534 return gfx::Size(total_width, content_size_.height() + insets.height()); | 533 return gfx::Size(total_width, content_size_.height() + insets.height()); |
| 535 } | 534 } |
| 536 | 535 |
| 537 const char* Combobox::GetClassName() const { | 536 const char* Combobox::GetClassName() const { |
| 538 return kViewClassName; | 537 return kViewClassName; |
| 539 } | 538 } |
| 540 | 539 |
| 541 bool Combobox::SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) { | 540 bool Combobox::SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) { |
| 542 // Escape should close the drop down list when it is active, not host UI. | 541 // Escape should close the drop down list when it is active, not host UI. |
| 543 if (e.key_code() != ui::VKEY_ESCAPE || | 542 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 : | 730 enabled() ? ui::NativeTheme::kColorId_LabelEnabledColor : |
| 732 ui::NativeTheme::kColorId_LabelDisabledColor); | 731 ui::NativeTheme::kColorId_LabelDisabledColor); |
| 733 | 732 |
| 734 DCHECK_GE(selected_index_, 0); | 733 DCHECK_GE(selected_index_, 0); |
| 735 DCHECK_LT(selected_index_, model()->GetItemCount()); | 734 DCHECK_LT(selected_index_, model()->GetItemCount()); |
| 736 if (selected_index_ < 0 || selected_index_ > model()->GetItemCount()) | 735 if (selected_index_ < 0 || selected_index_ > model()->GetItemCount()) |
| 737 selected_index_ = 0; | 736 selected_index_ = 0; |
| 738 base::string16 text = model()->GetItemAt(selected_index_); | 737 base::string16 text = model()->GetItemAt(selected_index_); |
| 739 | 738 |
| 740 gfx::Size arrow_size = ArrowSize(); | 739 gfx::Size arrow_size = ArrowSize(); |
| 741 int disclosure_arrow_offset = width() - arrow_size.width() - | 740 int disclosure_arrow_offset = width() - GetArrowContainerWidth(); |
| 742 GetDisclosureArrowLeftPadding() - GetDisclosureArrowRightPadding(); | |
| 743 | 741 |
| 744 const gfx::FontList& font_list = Combobox::GetFontList(); | 742 const gfx::FontList& font_list = Combobox::GetFontList(); |
| 745 int text_width = gfx::GetStringWidth(text, font_list); | 743 int text_width = gfx::GetStringWidth(text, font_list); |
| 746 if ((text_width + insets.width()) > disclosure_arrow_offset) | 744 if ((text_width + insets.width()) > disclosure_arrow_offset) |
| 747 text_width = disclosure_arrow_offset - insets.width(); | 745 text_width = disclosure_arrow_offset - insets.width(); |
| 748 | 746 |
| 749 gfx::Rect text_bounds(x, y, text_width, text_height); | 747 gfx::Rect text_bounds(x, y, text_width, text_height); |
| 750 AdjustBoundsForRTLUI(&text_bounds); | 748 AdjustBoundsForRTLUI(&text_bounds); |
| 751 canvas->DrawStringRect(text, font_list, text_color, text_bounds); | 749 canvas->DrawStringRect(text, font_list, text_color, text_bounds); |
| 752 | 750 |
| 753 int arrow_x = disclosure_arrow_offset + GetDisclosureArrowLeftPadding(); | 751 gfx::Rect arrow_bounds(disclosure_arrow_offset, 0, GetArrowContainerWidth(), |
| 754 gfx::Rect arrow_bounds(arrow_x, | 752 height()); |
| 755 height() / 2 - arrow_size.height() / 2, | 753 arrow_bounds = |
| 756 arrow_size.width(), | 754 PositionArrowWithinContainer(arrow_bounds, ArrowSize(), style_); |
| 757 arrow_size.height()); | |
| 758 AdjustBoundsForRTLUI(&arrow_bounds); | 755 AdjustBoundsForRTLUI(&arrow_bounds); |
| 759 | 756 |
| 760 gfx::ImageSkia arrow_image = PlatformStyle::CreateComboboxArrow( | 757 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 } | 758 } |
| 764 | 759 |
| 765 void Combobox::PaintButtons(gfx::Canvas* canvas) { | 760 void Combobox::PaintButtons(gfx::Canvas* canvas) { |
| 766 DCHECK(style_ == STYLE_ACTION); | 761 DCHECK(style_ == STYLE_ACTION); |
| 767 | 762 |
| 768 gfx::ScopedCanvas scoped_canvas(canvas); | 763 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 | 764 |
| 774 bool focused = HasFocus(); | 765 bool focused = HasFocus(); |
| 775 const std::vector<const gfx::ImageSkia*>& arrow_button_images = | 766 const std::vector<const gfx::ImageSkia*>& arrow_button_images = |
| 776 menu_button_images_[focused][ | 767 menu_button_images_[focused][ |
| 777 arrow_button_->state() == Button::STATE_HOVERED ? | 768 arrow_button_->state() == Button::STATE_HOVERED ? |
| 778 Button::STATE_NORMAL : arrow_button_->state()]; | 769 Button::STATE_NORMAL : arrow_button_->state()]; |
| 779 | 770 |
| 780 int text_button_hover_alpha = | 771 int text_button_hover_alpha = |
| 781 text_button_->state() == Button::STATE_PRESSED ? 0 : | 772 text_button_->state() == Button::STATE_PRESSED ? 0 : |
| 782 static_cast<int>(static_cast<TransparentButton*>(text_button_)-> | 773 static_cast<int>(static_cast<TransparentButton*>(text_button_)-> |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 | 861 |
| 871 // This combobox may be deleted by the listener. | 862 // This combobox may be deleted by the listener. |
| 872 base::WeakPtr<Combobox> weak_ptr = weak_ptr_factory_.GetWeakPtr(); | 863 base::WeakPtr<Combobox> weak_ptr = weak_ptr_factory_.GetWeakPtr(); |
| 873 if (listener_) | 864 if (listener_) |
| 874 listener_->OnPerformAction(this); | 865 listener_->OnPerformAction(this); |
| 875 | 866 |
| 876 if (weak_ptr && style_ == STYLE_ACTION) | 867 if (weak_ptr && style_ == STYLE_ACTION) |
| 877 selected_index_ = 0; | 868 selected_index_ = 0; |
| 878 } | 869 } |
| 879 | 870 |
| 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 { | 871 gfx::Size Combobox::ArrowSize() const { |
| 903 return PlatformStyle::CreateComboboxArrow(enabled(), style_).size(); | 872 return arrow_image_.size(); |
| 904 } | 873 } |
| 905 | 874 |
| 906 gfx::Size Combobox::GetContentSize() const { | 875 gfx::Size Combobox::GetContentSize() const { |
| 907 const gfx::FontList& font_list = GetFontList(); | 876 const gfx::FontList& font_list = GetFontList(); |
| 908 | 877 |
| 909 int width = 0; | 878 int width = 0; |
| 910 for (int i = 0; i < model()->GetItemCount(); ++i) { | 879 for (int i = 0; i < model()->GetItemCount(); ++i) { |
| 911 if (model_->IsItemSeparatorAt(i)) | 880 if (model_->IsItemSeparatorAt(i)) |
| 912 continue; | 881 continue; |
| 913 | 882 |
| 914 if (style_ != STYLE_ACTION || i == selected_index_) { | 883 if (style_ != STYLE_ACTION || i == selected_index_) { |
| 915 width = std::max( | 884 width = std::max( |
| 916 width, | 885 width, |
| 917 gfx::GetStringWidth(menu_model_adapter_->GetLabelAt(i), font_list)); | 886 gfx::GetStringWidth(menu_model_adapter_->GetLabelAt(i), font_list)); |
| 918 } | 887 } |
| 919 } | 888 } |
| 920 return gfx::Size(width, font_list.GetHeight()); | 889 return gfx::Size(width, font_list.GetHeight()); |
| 921 } | 890 } |
| 922 | 891 |
| 923 PrefixSelector* Combobox::GetPrefixSelector() { | 892 PrefixSelector* Combobox::GetPrefixSelector() { |
| 924 if (!selector_) | 893 if (!selector_) |
| 925 selector_.reset(new PrefixSelector(this)); | 894 selector_.reset(new PrefixSelector(this)); |
| 926 return selector_.get(); | 895 return selector_.get(); |
| 927 } | 896 } |
| 928 | 897 |
| 898 int Combobox::GetArrowContainerWidth() const { |
| 899 const int kNormalPadding = 7; |
| 900 int padding = style_ == STYLE_NORMAL |
| 901 ? kNormalPadding * 2 |
| 902 : kActionLeftPadding + kActionRightPadding; |
| 903 return ArrowSize().width() + padding; |
| 904 } |
| 905 |
| 929 } // namespace views | 906 } // namespace views |
| OLD | NEW |