Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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::GetComboboxShoulderWidth(Combobox::Style style) { | |
| 106 const int kNormalPadding = 7; | |
| 107 const int kActionPadding = 11; | |
| 108 int padding = | |
| 109 style == Combobox::STYLE_NORMAL ? kNormalPadding * 2 : kActionPadding * 2; | |
| 110 int image_width = CreateComboboxArrow(true, style).size().width(); | |
|
tapted
2016/04/22 13:46:52
I don't think the .size() is needed, same below. B
Elly Fong-Jones
2016/04/25 14:30:51
Okay.
The reason why it wasn't statically compute
| |
| 111 return padding + image_width; | |
| 112 } | |
| 113 | |
| 114 // static | |
| 115 int PlatformStyle::GetMenuButtonShoulderWidth() { | |
| 116 const int kPadding = 7; | |
| 117 return kPadding * 2 + CreateMenuButtonArrow(true).size().width(); | |
| 118 } | |
| 119 | |
| 86 #if !defined(DESKTOP_LINUX) && !defined(OS_MACOSX) | 120 #if !defined(DESKTOP_LINUX) && !defined(OS_MACOSX) |
| 87 // static | 121 // static |
| 88 void PlatformStyle::ApplyLabelButtonTextStyle( | 122 void PlatformStyle::ApplyLabelButtonTextStyle( |
| 89 Label* label, | 123 Label* label, |
| 90 ButtonColorByState* color_by_state) { | 124 ButtonColorByState* color_by_state) { |
| 91 ButtonColorByState& colors = *color_by_state; | 125 ButtonColorByState& colors = *color_by_state; |
| 92 colors[Button::STATE_NORMAL] = kStyleButtonTextColor; | 126 colors[Button::STATE_NORMAL] = kStyleButtonTextColor; |
| 93 colors[Button::STATE_HOVERED] = kStyleButtonTextColor; | 127 colors[Button::STATE_HOVERED] = kStyleButtonTextColor; |
| 94 colors[Button::STATE_PRESSED] = kStyleButtonTextColor; | 128 colors[Button::STATE_PRESSED] = kStyleButtonTextColor; |
| 95 | 129 |
| 96 const ui::NativeTheme* theme = label->GetNativeTheme(); | 130 const ui::NativeTheme* theme = label->GetNativeTheme(); |
| 97 label->SetBackgroundColor( | 131 label->SetBackgroundColor( |
| 98 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonBackgroundColor)); | 132 theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonBackgroundColor)); |
| 99 label->SetAutoColorReadabilityEnabled(false); | 133 label->SetAutoColorReadabilityEnabled(false); |
| 100 label->SetShadows(gfx::ShadowValues( | 134 label->SetShadows(gfx::ShadowValues( |
| 101 1, gfx::ShadowValue(gfx::Vector2d(0, 1), 0, kStyleButtonShadowColor))); | 135 1, gfx::ShadowValue(gfx::Vector2d(0, 1), 0, kStyleButtonShadowColor))); |
| 102 } | 136 } |
| 103 #endif | 137 #endif |
| 104 | 138 |
| 105 #if !defined(DESKTOP_LINUX) | 139 #if !defined(DESKTOP_LINUX) |
| 106 // static | 140 // static |
| 107 std::unique_ptr<Border> PlatformStyle::CreateThemedLabelButtonBorder( | 141 std::unique_ptr<Border> PlatformStyle::CreateThemedLabelButtonBorder( |
| 108 LabelButton* button) { | 142 LabelButton* button) { |
| 109 return button->CreateDefaultBorder(); | 143 return button->CreateDefaultBorder(); |
| 110 } | 144 } |
| 111 #endif | 145 #endif |
| 112 | 146 |
| 113 } // namespace views | 147 } // namespace views |
| OLD | NEW |