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 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 618 if (e.key_code() == ui::VKEY_SPACE && style_ == STYLE_ACTION) | 618 if (e.key_code() == ui::VKEY_SPACE && style_ == STYLE_ACTION) |
| 619 OnPerformAction(); | 619 OnPerformAction(); |
| 620 | 620 |
| 621 return false; | 621 return false; |
| 622 } | 622 } |
| 623 | 623 |
| 624 void Combobox::OnPaint(gfx::Canvas* canvas) { | 624 void Combobox::OnPaint(gfx::Canvas* canvas) { |
| 625 switch (style_) { | 625 switch (style_) { |
| 626 case STYLE_NORMAL: { | 626 case STYLE_NORMAL: { |
| 627 OnPaintBackground(canvas); | 627 OnPaintBackground(canvas); |
| 628 // Painting the arrow background needs to happen before PaintText applies | |
| 629 // a clip rect to |canvas| so the background can touch the border. | |
| 630 PaintArrowBackground(canvas); | |
| 628 PaintText(canvas); | 631 PaintText(canvas); |
| 629 OnPaintBorder(canvas); | 632 OnPaintBorder(canvas); |
| 630 break; | 633 break; |
| 631 } | 634 } |
| 632 case STYLE_ACTION: { | 635 case STYLE_ACTION: { |
| 633 PaintButtons(canvas); | 636 PaintButtons(canvas); |
| 634 PaintText(canvas); | 637 PaintText(canvas); |
| 635 break; | 638 break; |
| 636 } | 639 } |
| 637 } | 640 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 706 gfx::Insets insets = GetInsets(); | 709 gfx::Insets insets = GetInsets(); |
| 707 insets += gfx::Insets(0, Textfield::kTextPadding, 0, Textfield::kTextPadding); | 710 insets += gfx::Insets(0, Textfield::kTextPadding, 0, Textfield::kTextPadding); |
| 708 | 711 |
| 709 gfx::ScopedCanvas scoped_canvas(canvas); | 712 gfx::ScopedCanvas scoped_canvas(canvas); |
| 710 canvas->ClipRect(GetContentsBounds()); | 713 canvas->ClipRect(GetContentsBounds()); |
| 711 | 714 |
| 712 int x = insets.left(); | 715 int x = insets.left(); |
| 713 int y = insets.top(); | 716 int y = insets.top(); |
| 714 int text_height = height() - insets.height(); | 717 int text_height = height() - insets.height(); |
| 715 SkColor text_color = GetNativeTheme()->GetSystemColor( | 718 SkColor text_color = GetNativeTheme()->GetSystemColor( |
| 716 ui::NativeTheme::kColorId_LabelEnabledColor); | 719 enabled() ? ui::NativeTheme::kColorId_LabelEnabledColor : |
| 720 ui::NativeTheme::kColorId_LabelDisabledColor); | |
| 717 | 721 |
| 718 DCHECK_GE(selected_index_, 0); | 722 DCHECK_GE(selected_index_, 0); |
| 719 DCHECK_LT(selected_index_, model()->GetItemCount()); | 723 DCHECK_LT(selected_index_, model()->GetItemCount()); |
| 720 if (selected_index_ < 0 || selected_index_ > model()->GetItemCount()) | 724 if (selected_index_ < 0 || selected_index_ > model()->GetItemCount()) |
| 721 selected_index_ = 0; | 725 selected_index_ = 0; |
| 722 base::string16 text = model()->GetItemAt(selected_index_); | 726 base::string16 text = model()->GetItemAt(selected_index_); |
| 723 | 727 |
| 724 gfx::Size arrow_size = ArrowSize(); | 728 gfx::Size arrow_size = ArrowSize(); |
| 725 int disclosure_arrow_offset = width() - arrow_size.width() - | 729 int disclosure_arrow_offset = width() - arrow_size.width() - |
| 726 GetDisclosureArrowLeftPadding() - GetDisclosureArrowRightPadding(); | 730 GetDisclosureArrowLeftPadding() - GetDisclosureArrowRightPadding(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 806 if (0 < arrow_button_hover_alpha) { | 810 if (0 < arrow_button_hover_alpha) { |
| 807 canvas->SaveLayerAlpha(arrow_button_hover_alpha); | 811 canvas->SaveLayerAlpha(arrow_button_hover_alpha); |
| 808 const std::vector<const gfx::ImageSkia*>& arrow_button_hovered_images = | 812 const std::vector<const gfx::ImageSkia*>& arrow_button_hovered_images = |
| 809 menu_button_images_[focused][Button::STATE_HOVERED]; | 813 menu_button_images_[focused][Button::STATE_HOVERED]; |
| 810 PaintArrowButton(canvas, arrow_button_hovered_images, | 814 PaintArrowButton(canvas, arrow_button_hovered_images, |
| 811 arrow_button_->x(), height()); | 815 arrow_button_->x(), height()); |
| 812 canvas->Restore(); | 816 canvas->Restore(); |
| 813 } | 817 } |
| 814 } | 818 } |
| 815 | 819 |
| 820 void Combobox::PaintArrowBackground(gfx::Canvas* canvas) { | |
| 821 gfx::ScopedCanvas scoped_canvas(canvas); | |
|
tapted
2016/03/22 11:20:26
This is a lot of code for something Mac-specific -
Elly Fong-Jones
2016/03/22 22:05:10
Done.
| |
| 822 | |
| 823 if (base::i18n::IsRTL()) { | |
| 824 canvas->Translate(gfx::Vector2d(width(), 0)); | |
| 825 canvas->Scale(-1, 1); | |
| 826 } | |
| 827 | |
| 828 gfx::Rect bounds = GetLocalBounds(); | |
| 829 gfx::Size arrow_size = ArrowSize(); | |
| 830 int disclosure_arrow_offset = width() - arrow_size.width() - | |
| 831 GetDisclosureArrowLeftPadding() - GetDisclosureArrowRightPadding(); | |
| 832 bounds.Inset(disclosure_arrow_offset, 0, 0, 0); | |
| 833 | |
| 834 ui::NativeTheme::State state = | |
| 835 HasFocus() ? ui::NativeTheme::kHovered : ui::NativeTheme::kNormal; | |
| 836 GetNativeTheme()->Paint(canvas->sk_canvas(), | |
| 837 ui::NativeTheme::kComboboxArrowBackground, | |
| 838 state, | |
| 839 bounds, | |
| 840 ui::NativeTheme::ExtraParams()); | |
| 841 } | |
| 842 | |
| 816 void Combobox::ShowDropDownMenu(ui::MenuSourceType source_type) { | 843 void Combobox::ShowDropDownMenu(ui::MenuSourceType source_type) { |
| 817 gfx::Rect lb = GetLocalBounds(); | 844 gfx::Rect lb = GetLocalBounds(); |
| 818 gfx::Point menu_position(lb.origin()); | 845 gfx::Point menu_position(lb.origin()); |
| 819 | 846 |
| 820 if (style_ == STYLE_NORMAL) { | 847 if (style_ == STYLE_NORMAL) { |
| 821 // Inset the menu's requested position so the border of the menu lines up | 848 // Inset the menu's requested position so the border of the menu lines up |
| 822 // with the border of the combobox. | 849 // with the border of the combobox. |
| 823 menu_position.set_x(menu_position.x() + kMenuBorderWidthLeft); | 850 menu_position.set_x(menu_position.x() + kMenuBorderWidthLeft); |
| 824 menu_position.set_y(menu_position.y() + kMenuBorderWidthTop); | 851 menu_position.set_y(menu_position.y() + kMenuBorderWidthTop); |
| 825 } | 852 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 928 return gfx::Size(width, font_list.GetHeight()); | 955 return gfx::Size(width, font_list.GetHeight()); |
| 929 } | 956 } |
| 930 | 957 |
| 931 PrefixSelector* Combobox::GetPrefixSelector() { | 958 PrefixSelector* Combobox::GetPrefixSelector() { |
| 932 if (!selector_) | 959 if (!selector_) |
| 933 selector_.reset(new PrefixSelector(this)); | 960 selector_.reset(new PrefixSelector(this)); |
| 934 return selector_.get(); | 961 return selector_.get(); |
| 935 } | 962 } |
| 936 | 963 |
| 937 } // namespace views | 964 } // namespace views |
| OLD | NEW |