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

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

Issue 2964453002: Use style::CONTEXT_TEXTFIELD for Combobox and Textfield (Closed)
Patch Set: Rebase on top of https://codereview.chromium.org/2957263002 Created 3 years, 5 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_F_H); 88 MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_F_H);
89 const int kFocusedPressedMenuButtonImages[] = 89 const int kFocusedPressedMenuButtonImages[] =
90 MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_F_P); 90 MENU_IMAGE_GRID(IDR_COMBOBOX_BUTTON_F_P);
91 91
92 #undef MENU_IMAGE_GRID 92 #undef MENU_IMAGE_GRID
93 93
94 bool UseMd() { 94 bool UseMd() {
95 return ui::MaterialDesignController::IsSecondaryUiMaterial(); 95 return ui::MaterialDesignController::IsSecondaryUiMaterial();
96 } 96 }
97 97
98 SkColor GetTextColorForEnableState(bool enabled, ui::NativeTheme* theme) {
99 return style::GetColor(style::CONTEXT_TEXTFIELD,
100 enabled ? style::STYLE_PRIMARY : style::STYLE_DISABLED,
101 theme);
102 }
103
98 gfx::Rect PositionArrowWithinContainer(const gfx::Rect& container_bounds, 104 gfx::Rect PositionArrowWithinContainer(const gfx::Rect& container_bounds,
99 const gfx::Size& arrow_size, 105 const gfx::Size& arrow_size,
100 Combobox::Style style) { 106 Combobox::Style style) {
101 gfx::Rect bounds(container_bounds); 107 gfx::Rect bounds(container_bounds);
102 if (style == Combobox::STYLE_ACTION) { 108 if (style == Combobox::STYLE_ACTION) {
103 // This positions the arrow horizontally. The later call to 109 // This positions the arrow horizontally. The later call to
104 // ClampToCenteredSize will position it vertically without touching the 110 // ClampToCenteredSize will position it vertically without touching the
105 // horizontal position. 111 // horizontal position.
106 bounds.Inset(kActionLeftPadding, 0, kActionRightPadding, 0); 112 bounds.Inset(kActionLeftPadding, 0, kActionRightPadding, 0);
107 DCHECK_EQ(bounds.width(), arrow_size.width()); 113 DCHECK_EQ(bounds.width(), arrow_size.width());
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 void Combobox::PaintText(gfx::Canvas* canvas) { 814 void Combobox::PaintText(gfx::Canvas* canvas) {
809 gfx::Insets insets = GetInsets(); 815 gfx::Insets insets = GetInsets();
810 insets += gfx::Insets(0, Textfield::kTextPadding, 0, Textfield::kTextPadding); 816 insets += gfx::Insets(0, Textfield::kTextPadding, 0, Textfield::kTextPadding);
811 817
812 gfx::ScopedCanvas scoped_canvas(canvas); 818 gfx::ScopedCanvas scoped_canvas(canvas);
813 canvas->ClipRect(GetContentsBounds()); 819 canvas->ClipRect(GetContentsBounds());
814 820
815 int x = insets.left(); 821 int x = insets.left();
816 int y = insets.top(); 822 int y = insets.top();
817 int text_height = height() - insets.height(); 823 int text_height = height() - insets.height();
818 SkColor text_color = GetNativeTheme()->GetSystemColor( 824 SkColor text_color = GetTextColorForEnableState(enabled(), GetNativeTheme());
819 UseMd() ? (enabled() ? ui::NativeTheme::kColorId_TextfieldDefaultColor
820 : ui::NativeTheme::kColorId_TextfieldReadOnlyColor)
821 : (enabled() ? ui::NativeTheme::kColorId_LabelEnabledColor
822 : ui::NativeTheme::kColorId_LabelDisabledColor));
823
824 DCHECK_GE(selected_index_, 0); 825 DCHECK_GE(selected_index_, 0);
825 DCHECK_LT(selected_index_, model()->GetItemCount()); 826 DCHECK_LT(selected_index_, model()->GetItemCount());
826 if (selected_index_ < 0 || selected_index_ > model()->GetItemCount()) 827 if (selected_index_ < 0 || selected_index_ > model()->GetItemCount())
827 selected_index_ = 0; 828 selected_index_ = 0;
828 base::string16 text = model()->GetItemAt(selected_index_); 829 base::string16 text = model()->GetItemAt(selected_index_);
829 830
830 int disclosure_arrow_offset = width() - GetArrowContainerWidth(); 831 int disclosure_arrow_offset = width() - GetArrowContainerWidth();
831 832
832 const gfx::FontList& font_list = Combobox::GetFontList(); 833 const gfx::FontList& font_list = Combobox::GetFontList();
833 int text_width = gfx::GetStringWidth(text, font_list); 834 int text_width = gfx::GetStringWidth(text, font_list);
(...skipping 22 matching lines...) Expand all
856 // This epsilon makes sure that all the aliasing pixels are slightly more 857 // This epsilon makes sure that all the aliasing pixels are slightly more
857 // than half full. Otherwise, rounding issues cause some to be considered 858 // than half full. Otherwise, rounding issues cause some to be considered
858 // slightly less than half full and come out a little lighter. 859 // slightly less than half full and come out a little lighter.
859 const SkScalar kEpsilon = 0.0001f; 860 const SkScalar kEpsilon = 0.0001f;
860 path.moveTo(x - kEpsilon, y); 861 path.moveTo(x - kEpsilon, y);
861 path.rLineTo(height, height); 862 path.rLineTo(height, height);
862 path.rLineTo(2 * kEpsilon, 0); 863 path.rLineTo(2 * kEpsilon, 0);
863 path.rLineTo(height, -height); 864 path.rLineTo(height, -height);
864 path.close(); 865 path.close();
865 cc::PaintFlags flags; 866 cc::PaintFlags flags;
866 SkColor arrow_color = GetNativeTheme()->GetSystemColor( 867 SkColor arrow_color = GetTextColorForEnableState(true, GetNativeTheme());
867 ui::NativeTheme::kColorId_ButtonEnabledColor);
868 if (!enabled()) 868 if (!enabled())
869 arrow_color = SkColorSetA(arrow_color, gfx::kDisabledControlAlpha); 869 arrow_color = SkColorSetA(arrow_color, gfx::kDisabledControlAlpha);
870 flags.setColor(arrow_color); 870 flags.setColor(arrow_color);
871 flags.setAntiAlias(true); 871 flags.setAntiAlias(true);
872 canvas->DrawPath(path, flags); 872 canvas->DrawPath(path, flags);
873 } else { 873 } else {
874 canvas->DrawImageInt(arrow_image_, arrow_bounds.x(), arrow_bounds.y()); 874 canvas->DrawImageInt(arrow_image_, arrow_bounds.x(), arrow_bounds.y());
875 } 875 }
876 } 876 }
877 877
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 constexpr int kMdPaddingWidth = 8; 1014 constexpr int kMdPaddingWidth = 8;
1015 constexpr int kNormalPaddingWidth = 7; 1015 constexpr int kNormalPaddingWidth = 7;
1016 int arrow_pad = UseMd() ? kMdPaddingWidth : kNormalPaddingWidth; 1016 int arrow_pad = UseMd() ? kMdPaddingWidth : kNormalPaddingWidth;
1017 int padding = style_ == STYLE_NORMAL 1017 int padding = style_ == STYLE_NORMAL
1018 ? arrow_pad * 2 1018 ? arrow_pad * 2
1019 : kActionLeftPadding + kActionRightPadding; 1019 : kActionLeftPadding + kActionRightPadding;
1020 return ArrowSize().width() + padding; 1020 return ArrowSize().width() + padding;
1021 } 1021 }
1022 1022
1023 } // namespace views 1023 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/cocoa/bridged_native_widget_unittest.mm ('k') | ui/views/controls/textfield/textfield.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698