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 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 749 gfx::Rect arrow_bounds(arrow_x, | 749 gfx::Rect arrow_bounds(arrow_x, |
| 750 height() / 2 - arrow_size.height() / 2, | 750 height() / 2 - arrow_size.height() / 2, |
| 751 arrow_size.width(), | 751 arrow_size.width(), |
| 752 arrow_size.height()); | 752 arrow_size.height()); |
| 753 AdjustBoundsForRTLUI(&arrow_bounds); | 753 AdjustBoundsForRTLUI(&arrow_bounds); |
| 754 | 754 |
| 755 // TODO(estade): hack alert! Remove this direct call into CommonTheme. For now | 755 // TODO(estade): hack alert! Remove this direct call into CommonTheme. For now |
| 756 // STYLE_ACTION isn't properly themed so we have to override the NativeTheme | 756 // STYLE_ACTION isn't properly themed so we have to override the NativeTheme |
| 757 // behavior. See crbug.com/384071 | 757 // behavior. See crbug.com/384071 |
| 758 if (style_ == STYLE_ACTION) { | 758 if (style_ == STYLE_ACTION) { |
| 759 ui::CommonThemePaintComboboxArrow(canvas->sk_canvas(), arrow_bounds); | 759 ui::CommonThemePaintComboboxArrow(canvas->sk_canvas(), arrow_bounds); |
|
tapted
2016/03/29 04:16:36
I think this is the only caller now, and the metho
Elly Fong-Jones
2016/04/04 17:09:55
Done.
| |
| 760 } else { | 760 } else { |
| 761 ui::NativeTheme::ExtraParams ignored; | 761 gfx::ImageSkia arrow_image = PlatformStyle::CreateComboboxArrow( |
| 762 GetNativeTheme()->Paint(canvas->sk_canvas(), | 762 enabled()); |
| 763 ui::NativeTheme::kComboboxArrow, | 763 gfx::Rect image_bounds(arrow_bounds); |
| 764 ui::NativeTheme::kNormal, | 764 image_bounds.Inset((arrow_bounds.width() - arrow_image.width()) / 2, |
|
tapted
2016/03/29 04:16:36
I think this is the same as
image_bounds.ClampToC
Elly Fong-Jones
2016/04/04 17:09:55
Done.
| |
| 765 arrow_bounds, | 765 (arrow_bounds.height() - arrow_image.height()) / 2); |
| 766 ignored); | 766 canvas->DrawImageInt(arrow_image, image_bounds.x(), image_bounds.y()); |
| 767 } | 767 } |
| 768 } | 768 } |
| 769 | 769 |
| 770 void Combobox::PaintButtons(gfx::Canvas* canvas) { | 770 void Combobox::PaintButtons(gfx::Canvas* canvas) { |
| 771 DCHECK(style_ == STYLE_ACTION); | 771 DCHECK(style_ == STYLE_ACTION); |
| 772 | 772 |
| 773 gfx::ScopedCanvas scoped_canvas(canvas); | 773 gfx::ScopedCanvas scoped_canvas(canvas); |
| 774 if (base::i18n::IsRTL()) { | 774 if (base::i18n::IsRTL()) { |
| 775 canvas->Translate(gfx::Vector2d(width(), 0)); | 775 canvas->Translate(gfx::Vector2d(width(), 0)); |
| 776 canvas->Scale(-1, 1); | 776 canvas->Scale(-1, 1); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 898 case STYLE_NORMAL: | 898 case STYLE_NORMAL: |
| 899 return kDisclosureArrowRightPadding; | 899 return kDisclosureArrowRightPadding; |
| 900 case STYLE_ACTION: | 900 case STYLE_ACTION: |
| 901 return kDisclosureArrowButtonRightPadding; | 901 return kDisclosureArrowButtonRightPadding; |
| 902 } | 902 } |
| 903 NOTREACHED(); | 903 NOTREACHED(); |
| 904 return 0; | 904 return 0; |
| 905 } | 905 } |
| 906 | 906 |
| 907 gfx::Size Combobox::ArrowSize() const { | 907 gfx::Size Combobox::ArrowSize() const { |
| 908 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 908 return PlatformStyle::CreateComboboxArrow(enabled()).size(); |
| 909 // TODO(estade): hack alert! This should always use GetNativeTheme(). For now | |
| 910 // STYLE_ACTION isn't properly themed so we have to override the NativeTheme | |
| 911 // behavior. See crbug.com/384071 | |
| 912 const ui::NativeTheme* native_theme_for_arrow = | |
| 913 style_ == STYLE_ACTION ? ui::NativeThemeAura::instance() | |
| 914 : GetNativeTheme(); | |
| 915 #else | |
| 916 const ui::NativeTheme* native_theme_for_arrow = GetNativeTheme(); | |
| 917 #endif | |
| 918 | |
| 919 ui::NativeTheme::ExtraParams ignored; | |
| 920 return native_theme_for_arrow->GetPartSize(ui::NativeTheme::kComboboxArrow, | |
| 921 ui::NativeTheme::kNormal, | |
| 922 ignored); | |
| 923 } | 909 } |
| 924 | 910 |
| 925 gfx::Size Combobox::GetContentSize() const { | 911 gfx::Size Combobox::GetContentSize() const { |
| 926 const gfx::FontList& font_list = GetFontList(); | 912 const gfx::FontList& font_list = GetFontList(); |
| 927 | 913 |
| 928 int width = 0; | 914 int width = 0; |
| 929 for (int i = 0; i < model()->GetItemCount(); ++i) { | 915 for (int i = 0; i < model()->GetItemCount(); ++i) { |
| 930 if (model_->IsItemSeparatorAt(i)) | 916 if (model_->IsItemSeparatorAt(i)) |
| 931 continue; | 917 continue; |
| 932 | 918 |
| 933 if (style_ != STYLE_ACTION || i == selected_index_) { | 919 if (style_ != STYLE_ACTION || i == selected_index_) { |
| 934 width = std::max( | 920 width = std::max( |
| 935 width, | 921 width, |
| 936 gfx::GetStringWidth(menu_model_adapter_->GetLabelAt(i), font_list)); | 922 gfx::GetStringWidth(menu_model_adapter_->GetLabelAt(i), font_list)); |
| 937 } | 923 } |
| 938 } | 924 } |
| 939 return gfx::Size(width, font_list.GetHeight()); | 925 return gfx::Size(width, font_list.GetHeight()); |
| 940 } | 926 } |
| 941 | 927 |
| 942 PrefixSelector* Combobox::GetPrefixSelector() { | 928 PrefixSelector* Combobox::GetPrefixSelector() { |
| 943 if (!selector_) | 929 if (!selector_) |
| 944 selector_.reset(new PrefixSelector(this)); | 930 selector_.reset(new PrefixSelector(this)); |
| 945 return selector_.get(); | 931 return selector_.get(); |
| 946 } | 932 } |
| 947 | 933 |
| 948 } // namespace views | 934 } // namespace views |
| OLD | NEW |