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

Side by Side Diff: ui/views/controls/button/md_text_button.cc

Issue 1926943002: Introduce new flag to control usage of MD in secondary (not top-chrome) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: new fn name Created 4 years, 7 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/views/controls/button/md_text_button.h ('k') | ui/views/window/dialog_client_view.cc » ('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 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 "ui/base/material_design/material_design_controller.h" 8 #include "ui/base/material_design/material_design_controller.h"
9 #include "ui/gfx/color_utils.h" 9 #include "ui/gfx/color_utils.h"
10 #include "ui/native_theme/native_theme.h" 10 #include "ui/native_theme/native_theme.h"
11 #include "ui/views/background.h" 11 #include "ui/views/background.h"
12 #include "ui/views/border.h" 12 #include "ui/views/border.h"
13 #include "ui/views/painter.h" 13 #include "ui/views/painter.h"
14 14
15 namespace views { 15 namespace views {
16 16
17 namespace { 17 namespace {
18 18
19 // Inset between clickable region border and button contents (text). 19 // Inset between clickable region border and button contents (text).
20 const int kHorizontalPadding = 12; 20 const int kHorizontalPadding = 12;
21 const int kVerticalPadding = 6; 21 const int kVerticalPadding = 6;
22 22
23 // Minimum size to reserve for the button contents. 23 // Minimum size to reserve for the button contents.
24 const int kMinWidth = 48; 24 const int kMinWidth = 48;
25 25
26 LabelButton* CreateButton(ButtonListener* listener,
27 const base::string16& text,
28 bool md) {
29 if (md)
30 return MdTextButton::CreateMdButton(listener, text);
31
32 LabelButton* button = new LabelButton(listener, text);
33 button->SetStyle(CustomButton::STYLE_BUTTON);
34 return button;
35 }
36
26 } // namespace 37 } // namespace
27 38
28 // static 39 // static
29 LabelButton* MdTextButton::CreateStandardButton(ButtonListener* listener, 40 LabelButton* MdTextButton::CreateStandardButton(ButtonListener* listener,
30 const base::string16& text) { 41 const base::string16& text) {
31 if (ui::MaterialDesignController::IsModeMaterial()) 42 return CreateButton(listener, text,
32 return CreateMdButton(listener, text); 43 ui::MaterialDesignController::IsModeMaterial());
33
34 LabelButton* button = new LabelButton(listener, text);
35 button->SetStyle(STYLE_BUTTON);
36 return button;
37 } 44 }
38 45
46 // static
47 LabelButton* MdTextButton::CreateSecondaryUiButton(ButtonListener* listener,
48 const base::string16& text) {
49 return CreateButton(listener, text,
50 ui::MaterialDesignController::IsSecondaryUiMaterial());
51 }
52
53 // static
39 MdTextButton* MdTextButton::CreateMdButton(ButtonListener* listener, 54 MdTextButton* MdTextButton::CreateMdButton(ButtonListener* listener,
40 const base::string16& text) { 55 const base::string16& text) {
41 MdTextButton* button = new MdTextButton(listener); 56 MdTextButton* button = new MdTextButton(listener);
42 button->SetText(text); 57 button->SetText(text);
43 // TODO(estade): can we get rid of the platform style border hoopla if 58 // TODO(estade): can we get rid of the platform style border hoopla if
44 // we apply the MD treatment to all buttons, even GTK buttons? 59 // we apply the MD treatment to all buttons, even GTK buttons?
45 button->SetBorder( 60 button->SetBorder(
46 Border::CreateEmptyBorder(kVerticalPadding, kHorizontalPadding, 61 Border::CreateEmptyBorder(kVerticalPadding, kHorizontalPadding,
47 kVerticalPadding, kHorizontalPadding)); 62 kVerticalPadding, kHorizontalPadding));
48 return button; 63 return button;
(...skipping 13 matching lines...) Expand all
62 } 77 }
63 78
64 SkColor MdTextButton::GetInkDropBaseColor() const { 79 SkColor MdTextButton::GetInkDropBaseColor() const {
65 return color_utils::DeriveDefaultIconColor(label()->enabled_color()); 80 return color_utils::DeriveDefaultIconColor(label()->enabled_color());
66 } 81 }
67 82
68 void MdTextButton::SetText(const base::string16& text) { 83 void MdTextButton::SetText(const base::string16& text) {
69 LabelButton::SetText(base::i18n::ToUpper(text)); 84 LabelButton::SetText(base::i18n::ToUpper(text));
70 } 85 }
71 86
87 void MdTextButton::UpdateStyleToIndicateDefaultStatus() {
88 // Update the call to action state to reflect defaultness. Don't change strong
89 // call to action to weak.
90 if (!is_default())
91 SetCallToAction(NO_CALL_TO_ACTION);
92 else if (cta_ == NO_CALL_TO_ACTION)
93 SetCallToAction(WEAK_CALL_TO_ACTION);
94 }
95
72 MdTextButton::MdTextButton(ButtonListener* listener) 96 MdTextButton::MdTextButton(ButtonListener* listener)
73 : LabelButton(listener, base::string16()), 97 : LabelButton(listener, base::string16()),
74 ink_drop_delegate_(this, this), 98 ink_drop_delegate_(this, this),
75 cta_(NO_CALL_TO_ACTION) { 99 cta_(NO_CALL_TO_ACTION) {
76 set_ink_drop_delegate(&ink_drop_delegate_); 100 set_ink_drop_delegate(&ink_drop_delegate_);
77 set_has_ink_drop_action_on_click(true); 101 set_has_ink_drop_action_on_click(true);
78 SetHorizontalAlignment(gfx::ALIGN_CENTER); 102 SetHorizontalAlignment(gfx::ALIGN_CENTER);
79 Button::ConfigureDefaultFocus(this); 103 Button::ConfigureDefaultFocus(this);
80 SetMinSize(gfx::Size(kMinWidth, 0)); 104 SetMinSize(gfx::Size(kMinWidth, 0));
81 SetFocusPainter(nullptr); 105 SetFocusPainter(nullptr);
(...skipping 23 matching lines...) Expand all
105 cta_ == STRONG_CALL_TO_ACTION 129 cta_ == STRONG_CALL_TO_ACTION
106 ? Background::CreateBackgroundPainter( 130 ? Background::CreateBackgroundPainter(
107 true, Painter::CreateSolidRoundRectPainter( 131 true, Painter::CreateSolidRoundRectPainter(
108 theme->GetSystemColor( 132 theme->GetSystemColor(
109 ui::NativeTheme::kColorId_CallToActionColor), 133 ui::NativeTheme::kColorId_CallToActionColor),
110 kInkDropSmallCornerRadius)) 134 kInkDropSmallCornerRadius))
111 : nullptr); 135 : nullptr);
112 } 136 }
113 137
114 } // namespace views 138 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/md_text_button.h ('k') | ui/views/window/dialog_client_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698