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

Side by Side Diff: ui/views/style/platform_style.cc

Issue 1904753002: MenuButton: support Mac look & feel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix RTL support 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/style/platform_style.h" 5 #include "ui/views/style/platform_style.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "ui/base/material_design/material_design_controller.h" 9 #include "ui/base/material_design/material_design_controller.h"
10 #include "ui/base/resource/resource_bundle.h" 10 #include "ui/base/resource/resource_bundle.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 std::unique_ptr<FocusableBorder> PlatformStyle::CreateComboboxBorder() { 49 std::unique_ptr<FocusableBorder> PlatformStyle::CreateComboboxBorder() {
50 return base::WrapUnique(new FocusableBorder()); 50 return base::WrapUnique(new FocusableBorder());
51 } 51 }
52 52
53 // static 53 // static
54 std::unique_ptr<Background> PlatformStyle::CreateComboboxBackground() { 54 std::unique_ptr<Background> PlatformStyle::CreateComboboxBackground() {
55 return nullptr; 55 return nullptr;
56 } 56 }
57 57
58 // static 58 // static
59 std::unique_ptr<Background> PlatformStyle::CreateMenuButtonBackground() {
60 return nullptr;
61 }
62
63 // static
64 std::unique_ptr<FocusableBorder> PlatformStyle::CreateMenuButtonBorder() {
65 return base::WrapUnique(new FocusableBorder());
66 }
67
68 // static
59 std::unique_ptr<LabelButtonBorder> PlatformStyle::CreateLabelButtonBorder( 69 std::unique_ptr<LabelButtonBorder> PlatformStyle::CreateLabelButtonBorder(
60 Button::ButtonStyle style) { 70 Button::ButtonStyle style) {
61 if (!ui::MaterialDesignController::IsModeMaterial() || 71 if (!ui::MaterialDesignController::IsModeMaterial() ||
62 style != Button::STYLE_TEXTBUTTON) { 72 style != Button::STYLE_TEXTBUTTON) {
63 return base::WrapUnique(new LabelButtonAssetBorder(style)); 73 return base::WrapUnique(new LabelButtonAssetBorder(style));
64 } 74 }
65 75
66 std::unique_ptr<LabelButtonBorder> border(new views::LabelButtonBorder()); 76 std::unique_ptr<LabelButtonBorder> border(new views::LabelButtonBorder());
67 border->set_insets(views::LabelButtonAssetBorder::GetDefaultInsetsForStyle( 77 border->set_insets(views::LabelButtonAssetBorder::GetDefaultInsetsForStyle(
68 Button::STYLE_TEXTBUTTON)); 78 Button::STYLE_TEXTBUTTON));
69 return border; 79 return border;
70 } 80 }
71 81
72 // static 82 // static
83 gfx::ImageSkia PlatformStyle::CreateMenuButtonArrow(bool is_enabled) {
84 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
85 return *rb.GetImageSkiaNamed(IDR_MENU_DROPARROW);
86 }
87
88 // static
73 std::unique_ptr<ScrollBar> PlatformStyle::CreateScrollBar(bool is_horizontal) { 89 std::unique_ptr<ScrollBar> PlatformStyle::CreateScrollBar(bool is_horizontal) {
74 return base::WrapUnique(new NativeScrollBar(is_horizontal)); 90 return base::WrapUnique(new NativeScrollBar(is_horizontal));
75 } 91 }
76 92
77 // static 93 // static
78 SkColor PlatformStyle::TextColorForButton( 94 SkColor PlatformStyle::TextColorForButton(
79 const ButtonColorByState& color_by_state, 95 const ButtonColorByState& color_by_state,
80 const LabelButton& button) { 96 const LabelButton& button) {
81 return color_by_state[button.state()]; 97 return color_by_state[button.state()];
82 } 98 }
83 99
84 #endif // OS_MACOSX 100 #endif // OS_MACOSX
85 101
102 // This definition is used even on Mac, but Mac has its own
103 // CreateComboboxArrow() so it will return something different on Mac.
104 // static
105 int PlatformStyle::GetComboboxArrowWidth(Combobox::Style style) {
106 const int kNormalLeftPadding = 7;
107 const int kNormalRightPadding = 7;
tapted 2016/04/21 06:06:46 I think we can collapse the left/right and just ca
Elly Fong-Jones 2016/04/21 15:30:27 Done.
108 const int kActionLeftPadding = 11;
109 const int kActionRightPadding = 12;
110 int padding = style == Combobox::STYLE_NORMAL
111 ? kNormalLeftPadding + kNormalRightPadding
112 : kActionLeftPadding + kActionRightPadding;
113 int image_width = CreateComboboxArrow(true, style).size().width();
114 return padding + image_width;
115 }
116
117 // static
118 int PlatformStyle::GetMenuButtonArrowWidth() {
119 const int kLeftPadding = 7;
120 const int kRightPadding = 7;
121 return kLeftPadding + kRightPadding +
122 CreateMenuButtonArrow(true).size().width();
123 }
124
86 #if !defined(DESKTOP_LINUX) && !defined(OS_MACOSX) 125 #if !defined(DESKTOP_LINUX) && !defined(OS_MACOSX)
87 // static 126 // static
88 void PlatformStyle::ApplyLabelButtonTextStyle( 127 void PlatformStyle::ApplyLabelButtonTextStyle(
89 Label* label, 128 Label* label,
90 ButtonColorByState* color_by_state) { 129 ButtonColorByState* color_by_state) {
91 ButtonColorByState& colors = *color_by_state; 130 ButtonColorByState& colors = *color_by_state;
92 colors[Button::STATE_NORMAL] = kStyleButtonTextColor; 131 colors[Button::STATE_NORMAL] = kStyleButtonTextColor;
93 colors[Button::STATE_HOVERED] = kStyleButtonTextColor; 132 colors[Button::STATE_HOVERED] = kStyleButtonTextColor;
94 colors[Button::STATE_PRESSED] = kStyleButtonTextColor; 133 colors[Button::STATE_PRESSED] = kStyleButtonTextColor;
95 134
96 const ui::NativeTheme* theme = label->GetNativeTheme(); 135 const ui::NativeTheme* theme = label->GetNativeTheme();
97 label->SetBackgroundColor( 136 label->SetBackgroundColor(
98 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonBackgroundColor)); 137 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonBackgroundColor));
99 label->SetAutoColorReadabilityEnabled(false); 138 label->SetAutoColorReadabilityEnabled(false);
100 label->SetShadows(gfx::ShadowValues( 139 label->SetShadows(gfx::ShadowValues(
101 1, gfx::ShadowValue(gfx::Vector2d(0, 1), 0, kStyleButtonShadowColor))); 140 1, gfx::ShadowValue(gfx::Vector2d(0, 1), 0, kStyleButtonShadowColor)));
102 } 141 }
103 #endif 142 #endif
104 143
105 #if !defined(DESKTOP_LINUX) 144 #if !defined(DESKTOP_LINUX)
106 // static 145 // static
107 std::unique_ptr<Border> PlatformStyle::CreateThemedLabelButtonBorder( 146 std::unique_ptr<Border> PlatformStyle::CreateThemedLabelButtonBorder(
108 LabelButton* button) { 147 LabelButton* button) {
109 return button->CreateDefaultBorder(); 148 return button->CreateDefaultBorder();
110 } 149 }
111 #endif 150 #endif
112 151
113 } // namespace views 152 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698