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/controls/button/md_text_button.h" | 5 #include "ui/views/controls/button/md_text_button.h" |
| 6 | 6 |
| 7 #include "base/i18n/case_conversion.h" | 7 #include "base/i18n/case_conversion.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "ui/base/material_design/material_design_controller.h" | 9 #include "ui/base/material_design/material_design_controller.h" |
| 10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
| 11 #include "ui/gfx/color_palette.h" | 11 #include "ui/gfx/color_palette.h" |
| 12 #include "ui/gfx/color_utils.h" | 12 #include "ui/gfx/color_utils.h" |
| 13 #include "ui/native_theme/native_theme.h" | 13 #include "ui/native_theme/native_theme.h" |
| 14 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" | 14 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" |
| 15 #include "ui/views/animation/ink_drop_highlight.h" | 15 #include "ui/views/animation/ink_drop_highlight.h" |
| 16 #include "ui/views/animation/ink_drop_impl.h" | 16 #include "ui/views/animation/ink_drop_impl.h" |
| 17 #include "ui/views/animation/ink_drop_painted_layer_delegates.h" | 17 #include "ui/views/animation/ink_drop_painted_layer_delegates.h" |
| 18 #include "ui/views/background.h" | 18 #include "ui/views/background.h" |
| 19 #include "ui/views/border.h" | 19 #include "ui/views/border.h" |
| 20 #include "ui/views/controls/button/blue_button.h" | 20 #include "ui/views/controls/button/blue_button.h" |
| 21 #include "ui/views/controls/focus_ring.h" | 21 #include "ui/views/controls/focus_ring.h" |
| 22 #include "ui/views/painter.h" | 22 #include "ui/views/painter.h" |
| 23 #include "ui/views/style/platform_style.h" | 23 #include "ui/views/style/platform_style.h" |
| 24 #include "ui/views/views_delegate.h" | |
| 24 | 25 |
| 25 namespace views { | 26 namespace views { |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 // Minimum size to reserve for the button contents. | |
| 30 const int kMinWidth = 48; | |
| 31 | |
| 32 LabelButton* CreateButton(ButtonListener* listener, | 30 LabelButton* CreateButton(ButtonListener* listener, |
| 33 const base::string16& text, | 31 const base::string16& text, |
| 34 bool md) { | 32 bool md) { |
| 35 if (md) | 33 if (md) |
| 36 return MdTextButton::Create(listener, text); | 34 return MdTextButton::Create(listener, text); |
| 37 | 35 |
| 38 LabelButton* button = new LabelButton(listener, text); | 36 LabelButton* button = new LabelButton(listener, text); |
| 39 button->SetStyle(CustomButton::STYLE_BUTTON); | 37 button->SetStyle(CustomButton::STYLE_BUTTON); |
| 40 return button; | 38 return button; |
| 41 } | 39 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 } | 186 } |
| 189 | 187 |
| 190 MdTextButton::MdTextButton(ButtonListener* listener) | 188 MdTextButton::MdTextButton(ButtonListener* listener) |
| 191 : LabelButton(listener, base::string16()), | 189 : LabelButton(listener, base::string16()), |
| 192 is_prominent_(false) { | 190 is_prominent_(false) { |
| 193 SetInkDropMode(PlatformStyle::kUseRipples ? InkDropMode::ON | 191 SetInkDropMode(PlatformStyle::kUseRipples ? InkDropMode::ON |
| 194 : InkDropMode::OFF); | 192 : InkDropMode::OFF); |
| 195 set_has_ink_drop_action_on_click(true); | 193 set_has_ink_drop_action_on_click(true); |
| 196 SetHorizontalAlignment(gfx::ALIGN_CENTER); | 194 SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 197 SetFocusForPlatform(); | 195 SetFocusForPlatform(); |
| 198 SetMinSize(gfx::Size(kMinWidth, 0)); | 196 const int minimum_width = |
| 197 ViewsDelegate::GetInstance()->GetDialogButtonMinimumWidth(); | |
| 198 SetMinSize(gfx::Size(minimum_width, 0)); | |
| 199 SetFocusPainter(nullptr); | 199 SetFocusPainter(nullptr); |
| 200 label()->SetAutoColorReadabilityEnabled(false); | 200 label()->SetAutoColorReadabilityEnabled(false); |
| 201 set_request_focus_on_press(false); | 201 set_request_focus_on_press(false); |
| 202 LabelButton::SetFontList(GetMdFontList()); | 202 LabelButton::SetFontList(GetMdFontList()); |
| 203 | 203 |
| 204 set_animate_on_state_change(true); | 204 set_animate_on_state_change(true); |
| 205 | 205 |
| 206 // Paint to a layer so that the canvas is snapped to pixel boundaries (useful | 206 // Paint to a layer so that the canvas is snapped to pixel boundaries (useful |
| 207 // for fractional DSF). | 207 // for fractional DSF). |
| 208 SetPaintToLayer(); | 208 SetPaintToLayer(); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 233 int target_height = std::max(kBaseHeight + size_delta * 2, | 233 int target_height = std::max(kBaseHeight + size_delta * 2, |
| 234 label()->font_list().GetFontSize() * 2); | 234 label()->font_list().GetFontSize() * 2); |
| 235 | 235 |
| 236 int label_height = label()->GetPreferredSize().height(); | 236 int label_height = label()->GetPreferredSize().height(); |
| 237 int top_padding = (target_height - label_height) / 2; | 237 int top_padding = (target_height - label_height) / 2; |
| 238 int bottom_padding = (target_height - label_height + 1) / 2; | 238 int bottom_padding = (target_height - label_height + 1) / 2; |
| 239 DCHECK_EQ(target_height, label_height + top_padding + bottom_padding); | 239 DCHECK_EQ(target_height, label_height + top_padding + bottom_padding); |
| 240 | 240 |
| 241 // TODO(estade): can we get rid of the platform style border hoopla if | 241 // TODO(estade): can we get rid of the platform style border hoopla if |
| 242 // we apply the MD treatment to all buttons, even GTK buttons? | 242 // we apply the MD treatment to all buttons, even GTK buttons? |
| 243 const int kHorizontalPadding = 16; | 243 const int kHorizontalPadding = 16; |
|
Peter Kasting
2017/02/13 23:47:31
Seems like this interacts with the minimum button
Bret
2017/02/16 00:25:02
The problem here is the label width is controlled
| |
| 244 SetBorder(CreateEmptyBorder(top_padding, kHorizontalPadding, bottom_padding, | 244 SetBorder(CreateEmptyBorder(top_padding, kHorizontalPadding, bottom_padding, |
| 245 kHorizontalPadding)); | 245 kHorizontalPadding)); |
| 246 } | 246 } |
| 247 | 247 |
| 248 void MdTextButton::UpdateColors() { | 248 void MdTextButton::UpdateColors() { |
| 249 ui::NativeTheme::ColorId fg_color_id = | 249 ui::NativeTheme::ColorId fg_color_id = |
| 250 is_prominent_ ? ui::NativeTheme::kColorId_TextOnProminentButtonColor | 250 is_prominent_ ? ui::NativeTheme::kColorId_TextOnProminentButtonColor |
| 251 : ui::NativeTheme::kColorId_ButtonEnabledColor; | 251 : ui::NativeTheme::kColorId_ButtonEnabledColor; |
| 252 | 252 |
| 253 ui::NativeTheme* theme = GetNativeTheme(); | 253 ui::NativeTheme* theme = GetNativeTheme(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 stroke_color, gfx::kDisabledControlAlpha); | 297 stroke_color, gfx::kDisabledControlAlpha); |
| 298 } | 298 } |
| 299 | 299 |
| 300 DCHECK_EQ(SK_AlphaOPAQUE, static_cast<int>(SkColorGetA(bg_color))); | 300 DCHECK_EQ(SK_AlphaOPAQUE, static_cast<int>(SkColorGetA(bg_color))); |
| 301 set_background(Background::CreateBackgroundPainter( | 301 set_background(Background::CreateBackgroundPainter( |
| 302 Painter::CreateRoundRectWith1PxBorderPainter(bg_color, stroke_color, | 302 Painter::CreateRoundRectWith1PxBorderPainter(bg_color, stroke_color, |
| 303 kInkDropSmallCornerRadius))); | 303 kInkDropSmallCornerRadius))); |
| 304 } | 304 } |
| 305 | 305 |
| 306 } // namespace views | 306 } // namespace views |
| OLD | NEW |