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

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 noop image_bounds 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 canvas->DrawImageInt(arrow_image, arrow_bounds.x(), arrow_bounds.y());
758 if (style_ == STYLE_ACTION) {
759 ui::CommonThemePaintComboboxArrow(canvas->sk_canvas(), arrow_bounds);
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 } 758 }
769 759
770 void Combobox::PaintButtons(gfx::Canvas* canvas) { 760 void Combobox::PaintButtons(gfx::Canvas* canvas) {
771 DCHECK(style_ == STYLE_ACTION); 761 DCHECK(style_ == STYLE_ACTION);
772 762
773 gfx::ScopedCanvas scoped_canvas(canvas); 763 gfx::ScopedCanvas scoped_canvas(canvas);
774 if (base::i18n::IsRTL()) { 764 if (base::i18n::IsRTL()) {
775 canvas->Translate(gfx::Vector2d(width(), 0)); 765 canvas->Translate(gfx::Vector2d(width(), 0));
776 canvas->Scale(-1, 1); 766 canvas->Scale(-1, 1);
777 } 767 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 case STYLE_NORMAL: 888 case STYLE_NORMAL:
899 return kDisclosureArrowRightPadding; 889 return kDisclosureArrowRightPadding;
900 case STYLE_ACTION: 890 case STYLE_ACTION:
901 return kDisclosureArrowButtonRightPadding; 891 return kDisclosureArrowButtonRightPadding;
902 } 892 }
903 NOTREACHED(); 893 NOTREACHED();
904 return 0; 894 return 0;
905 } 895 }
906 896
907 gfx::Size Combobox::ArrowSize() const { 897 gfx::Size Combobox::ArrowSize() const {
908 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 898 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 } 899 }
924 900
925 gfx::Size Combobox::GetContentSize() const { 901 gfx::Size Combobox::GetContentSize() const {
926 const gfx::FontList& font_list = GetFontList(); 902 const gfx::FontList& font_list = GetFontList();
927 903
928 int width = 0; 904 int width = 0;
929 for (int i = 0; i < model()->GetItemCount(); ++i) { 905 for (int i = 0; i < model()->GetItemCount(); ++i) {
930 if (model_->IsItemSeparatorAt(i)) 906 if (model_->IsItemSeparatorAt(i))
931 continue; 907 continue;
932 908
933 if (style_ != STYLE_ACTION || i == selected_index_) { 909 if (style_ != STYLE_ACTION || i == selected_index_) {
934 width = std::max( 910 width = std::max(
935 width, 911 width,
936 gfx::GetStringWidth(menu_model_adapter_->GetLabelAt(i), font_list)); 912 gfx::GetStringWidth(menu_model_adapter_->GetLabelAt(i), font_list));
937 } 913 }
938 } 914 }
939 return gfx::Size(width, font_list.GetHeight()); 915 return gfx::Size(width, font_list.GetHeight());
940 } 916 }
941 917
942 PrefixSelector* Combobox::GetPrefixSelector() { 918 PrefixSelector* Combobox::GetPrefixSelector() {
943 if (!selector_) 919 if (!selector_)
944 selector_.reset(new PrefixSelector(this)); 920 selector_.reset(new PrefixSelector(this));
945 return selector_.get(); 921 return selector_.get();
946 } 922 }
947 923
948 } // namespace views 924 } // 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