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

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

Issue 1817613002: MacViews: draw Mac combobox arrows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove PaintComboboxArrow Created 4 years, 8 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 734 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 AdjustBoundsForRTLUI(&text_bounds); 745 AdjustBoundsForRTLUI(&text_bounds);
746 canvas->DrawStringRect(text, font_list, text_color, text_bounds); 746 canvas->DrawStringRect(text, font_list, text_color, text_bounds);
747 747
748 int arrow_x = disclosure_arrow_offset + GetDisclosureArrowLeftPadding(); 748 int arrow_x = disclosure_arrow_offset + GetDisclosureArrowLeftPadding();
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 gfx::ImageSkia arrow_image = PlatformStyle::CreateComboboxArrow(
756 // STYLE_ACTION isn't properly themed so we have to override the NativeTheme 756 enabled(), style_);
757 // behavior. See crbug.com/384071 757 gfx::Rect image_bounds(arrow_bounds);
758 if (style_ == STYLE_ACTION) { 758 image_bounds.ClampToCenteredSize(arrow_bounds.size());
759 ui::CommonThemePaintComboboxArrow(canvas->sk_canvas(), arrow_bounds); 759 canvas->DrawImageInt(arrow_image, image_bounds.x(), image_bounds.y());
tapted 2016/04/05 08:45:02 I have a theory, that you could write something li
Elly Fong-Jones 2016/04/05 20:04:24 It looks like it exploded on the Windows bots.
tapted 2016/04/06 00:07:08 https://codereview.chromium.org/1863503002/#ps6000
Elly Fong-Jones 2016/04/06 16:20:21 Ya, sorry - I should have realized that these two
760 } else {
761 ui::NativeTheme::ExtraParams ignored;
762 GetNativeTheme()->Paint(canvas->sk_canvas(),
763 ui::NativeTheme::kComboboxArrow,
764 ui::NativeTheme::kNormal,
765 arrow_bounds,
766 ignored);
767 }
768 } 760 }
769 761
770 void Combobox::PaintButtons(gfx::Canvas* canvas) { 762 void Combobox::PaintButtons(gfx::Canvas* canvas) {
771 DCHECK(style_ == STYLE_ACTION); 763 DCHECK(style_ == STYLE_ACTION);
772 764
773 gfx::ScopedCanvas scoped_canvas(canvas); 765 gfx::ScopedCanvas scoped_canvas(canvas);
774 if (base::i18n::IsRTL()) { 766 if (base::i18n::IsRTL()) {
775 canvas->Translate(gfx::Vector2d(width(), 0)); 767 canvas->Translate(gfx::Vector2d(width(), 0));
776 canvas->Scale(-1, 1); 768 canvas->Scale(-1, 1);
777 } 769 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 case STYLE_NORMAL: 890 case STYLE_NORMAL:
899 return kDisclosureArrowRightPadding; 891 return kDisclosureArrowRightPadding;
900 case STYLE_ACTION: 892 case STYLE_ACTION:
901 return kDisclosureArrowButtonRightPadding; 893 return kDisclosureArrowButtonRightPadding;
902 } 894 }
903 NOTREACHED(); 895 NOTREACHED();
904 return 0; 896 return 0;
905 } 897 }
906 898
907 gfx::Size Combobox::ArrowSize() const { 899 gfx::Size Combobox::ArrowSize() const {
908 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 900 return PlatformStyle::CreateComboboxArrow(enabled(), style_).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 } 901 }
924 902
925 gfx::Size Combobox::GetContentSize() const { 903 gfx::Size Combobox::GetContentSize() const {
926 const gfx::FontList& font_list = GetFontList(); 904 const gfx::FontList& font_list = GetFontList();
927 905
928 int width = 0; 906 int width = 0;
929 for (int i = 0; i < model()->GetItemCount(); ++i) { 907 for (int i = 0; i < model()->GetItemCount(); ++i) {
930 if (model_->IsItemSeparatorAt(i)) 908 if (model_->IsItemSeparatorAt(i))
931 continue; 909 continue;
932 910
933 if (style_ != STYLE_ACTION || i == selected_index_) { 911 if (style_ != STYLE_ACTION || i == selected_index_) {
934 width = std::max( 912 width = std::max(
935 width, 913 width,
936 gfx::GetStringWidth(menu_model_adapter_->GetLabelAt(i), font_list)); 914 gfx::GetStringWidth(menu_model_adapter_->GetLabelAt(i), font_list));
937 } 915 }
938 } 916 }
939 return gfx::Size(width, font_list.GetHeight()); 917 return gfx::Size(width, font_list.GetHeight());
940 } 918 }
941 919
942 PrefixSelector* Combobox::GetPrefixSelector() { 920 PrefixSelector* Combobox::GetPrefixSelector() {
943 if (!selector_) 921 if (!selector_)
944 selector_.reset(new PrefixSelector(this)); 922 selector_.reset(new PrefixSelector(this));
945 return selector_.get(); 923 return selector_.get();
946 } 924 }
947 925
948 } // namespace views 926 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698