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

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

Issue 1863503002: test hypothesis (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: zappity 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
« no previous file with comments | « ui/native_theme/native_theme_win.cc ('k') | ui/views/style/platform_style.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 DCHECK_EQ(image_bounds.x(), arrow_bounds.x());
760 } else { 760 DCHECK_EQ(image_bounds.y(), arrow_bounds.y());
761 ui::NativeTheme::ExtraParams ignored; 761 canvas->DrawImageInt(arrow_image, image_bounds.x(), image_bounds.y());
762 GetNativeTheme()->Paint(canvas->sk_canvas(),
763 ui::NativeTheme::kComboboxArrow,
764 ui::NativeTheme::kNormal,
765 arrow_bounds,
766 ignored);
767 }
768 } 762 }
769 763
770 void Combobox::PaintButtons(gfx::Canvas* canvas) { 764 void Combobox::PaintButtons(gfx::Canvas* canvas) {
771 DCHECK(style_ == STYLE_ACTION); 765 DCHECK(style_ == STYLE_ACTION);
772 766
773 gfx::ScopedCanvas scoped_canvas(canvas); 767 gfx::ScopedCanvas scoped_canvas(canvas);
774 if (base::i18n::IsRTL()) { 768 if (base::i18n::IsRTL()) {
775 canvas->Translate(gfx::Vector2d(width(), 0)); 769 canvas->Translate(gfx::Vector2d(width(), 0));
776 canvas->Scale(-1, 1); 770 canvas->Scale(-1, 1);
777 } 771 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 case STYLE_NORMAL: 892 case STYLE_NORMAL:
899 return kDisclosureArrowRightPadding; 893 return kDisclosureArrowRightPadding;
900 case STYLE_ACTION: 894 case STYLE_ACTION:
901 return kDisclosureArrowButtonRightPadding; 895 return kDisclosureArrowButtonRightPadding;
902 } 896 }
903 NOTREACHED(); 897 NOTREACHED();
904 return 0; 898 return 0;
905 } 899 }
906 900
907 gfx::Size Combobox::ArrowSize() const { 901 gfx::Size Combobox::ArrowSize() const {
908 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 902 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 } 903 }
924 904
925 gfx::Size Combobox::GetContentSize() const { 905 gfx::Size Combobox::GetContentSize() const {
926 const gfx::FontList& font_list = GetFontList(); 906 const gfx::FontList& font_list = GetFontList();
927 907
928 int width = 0; 908 int width = 0;
929 for (int i = 0; i < model()->GetItemCount(); ++i) { 909 for (int i = 0; i < model()->GetItemCount(); ++i) {
930 if (model_->IsItemSeparatorAt(i)) 910 if (model_->IsItemSeparatorAt(i))
931 continue; 911 continue;
932 912
933 if (style_ != STYLE_ACTION || i == selected_index_) { 913 if (style_ != STYLE_ACTION || i == selected_index_) {
934 width = std::max( 914 width = std::max(
935 width, 915 width,
936 gfx::GetStringWidth(menu_model_adapter_->GetLabelAt(i), font_list)); 916 gfx::GetStringWidth(menu_model_adapter_->GetLabelAt(i), font_list));
937 } 917 }
938 } 918 }
939 return gfx::Size(width, font_list.GetHeight()); 919 return gfx::Size(width, font_list.GetHeight());
940 } 920 }
941 921
942 PrefixSelector* Combobox::GetPrefixSelector() { 922 PrefixSelector* Combobox::GetPrefixSelector() {
943 if (!selector_) 923 if (!selector_)
944 selector_.reset(new PrefixSelector(this)); 924 selector_.reset(new PrefixSelector(this));
945 return selector_.get(); 925 return selector_.get();
946 } 926 }
947 927
948 } // namespace views 928 } // namespace views
OLDNEW
« no previous file with comments | « ui/native_theme/native_theme_win.cc ('k') | ui/views/style/platform_style.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698