Skip to content

Commit a9d1024

Browse files
Refactor the UpdateColorsForBrave into UpdateBackgroundColor & UpdateTextColor
1 parent 1b95856 commit a9d1024

File tree

2 files changed

+61
-67
lines changed

2 files changed

+61
-67
lines changed

chromium_src/ui/views/controls/button/md_text_button.cc

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
#include "ui/views/view_class_properties.h"
2626

2727
// To be called from MdTextButtonBase::UpdateColors().
28-
#define BRAVE_MD_TEXT_BUTTON_UPDATE_COLORS \
29-
UpdateColorsForBrave(); \
30-
UpdateIconForBrave();
28+
#define BRAVE_MD_TEXT_BUTTON_UPDATE_COLORS UpdateIconForBrave();
3129

3230
#define MdTextButton MdTextButtonBase
3331
#include "src/ui/views/controls/button/md_text_button.cc"
@@ -207,10 +205,59 @@ void MdTextButton::SetLoading(bool loading) {
207205
UpdateColors();
208206
}
209207

208+
void MdTextButton::UpdateTextColor() {
209+
MdTextButtonBase::UpdateTextColor();
210+
211+
// Once we update the buttons across Brave to use the new style, we can remove
212+
// this branch.
213+
if (kind_ == kOld) {
214+
if (GetProminent())
215+
return;
216+
const ui::NativeTheme* theme = GetNativeTheme();
217+
// Override different text hover color
218+
if (theme->GetPlatformHighContrastColorScheme() !=
219+
ui::NativeTheme::PlatformHighContrastColorScheme::kDark) {
220+
SetTextColor(ButtonState::STATE_HOVERED, kBraveBrandColor);
221+
SetTextColor(ButtonState::STATE_PRESSED, kBraveBrandColor);
222+
}
223+
return;
224+
}
225+
226+
auto colors = GetButtonColors();
227+
SetTextColor(GetVisualState(), colors.text_color);
228+
}
229+
210230
void MdTextButton::UpdateBackgroundColor() {
211-
// Handled via |UpdateColorsForBrave|.
231+
// Once we update the buttons across Brave to use the new style, we can remove
232+
// this branch.
212233
if (kind_ == kOld) {
213234
MdTextButtonBase::UpdateBackgroundColor();
235+
236+
// We don't modify the Prominent button at all.
237+
if (GetProminent()) {
238+
return;
239+
}
240+
241+
// Override border color for hover on non-prominent
242+
if (GetState() == ButtonState::STATE_PRESSED ||
243+
GetState() == ButtonState::STATE_HOVERED) {
244+
// First, get the same background fill color that MdTextButtonBase does.
245+
// It is unfortunate to copy these lines almost as-is. Consider otherwise
246+
// patching it in via a #define.
247+
SkColor bg_color =
248+
GetColorProvider()->GetColor(ui::kColorDialogBackground);
249+
if (GetBgColorOverride()) {
250+
bg_color = *GetBgColorOverride();
251+
}
252+
if (GetState() == STATE_PRESSED) {
253+
bg_color = GetNativeTheme()->GetSystemButtonPressedColor(bg_color);
254+
}
255+
// The only thing that differs for Brave is the stroke color
256+
SkColor stroke_color = kBraveBrandColor;
257+
SetBackground(CreateBackgroundFromPainter(
258+
Painter::CreateRoundRectWith1PxBorderPainter(bg_color, stroke_color,
259+
GetCornerRadius())));
260+
}
214261
return;
215262
}
216263

@@ -224,49 +271,6 @@ void MdTextButton::UpdateBackgroundColor() {
224271
colors.background_color, colors.stroke_color, GetCornerRadius())));
225272
}
226273

227-
void MdTextButton::UpdateOldColorsForBrave() {
228-
if (GetProminent()) {
229-
return;
230-
}
231-
232-
const ui::NativeTheme* theme = GetNativeTheme();
233-
// Override different text hover color
234-
if (theme->GetPlatformHighContrastColorScheme() !=
235-
ui::NativeTheme::PlatformHighContrastColorScheme::kDark) {
236-
SetTextColor(ButtonState::STATE_HOVERED, kBraveBrandColor);
237-
SetTextColor(ButtonState::STATE_PRESSED, kBraveBrandColor);
238-
}
239-
// Override border color for hover on non-prominent
240-
if (GetState() == ButtonState::STATE_PRESSED ||
241-
GetState() == ButtonState::STATE_HOVERED) {
242-
// First, get the same background fill color that MdTextButtonBase does.
243-
// It is undfortunate to copy these lines almost as-is. Consider otherwise
244-
// patching it in via a #define.
245-
SkColor bg_color = GetColorProvider()->GetColor(ui::kColorDialogBackground);
246-
if (GetBgColorOverride()) {
247-
bg_color = *GetBgColorOverride();
248-
}
249-
if (GetState() == STATE_PRESSED) {
250-
bg_color = GetNativeTheme()->GetSystemButtonPressedColor(bg_color);
251-
}
252-
// The only thing that differs for Brave is the stroke color
253-
SkColor stroke_color = kBraveBrandColor;
254-
SetBackground(CreateBackgroundFromPainter(
255-
Painter::CreateRoundRectWith1PxBorderPainter(bg_color, stroke_color,
256-
GetCornerRadius())));
257-
}
258-
}
259-
260-
// To be called from MdTextButtonBase::UpdateColors().
261-
void MdTextButton::UpdateColorsForBrave() {
262-
if (GetKind() == Kind::kOld) {
263-
UpdateOldColorsForBrave();
264-
return;
265-
}
266-
267-
SetTextColor(GetVisualState(), );
268-
}
269-
270274
void MdTextButton::UpdateIconForBrave() {
271275
if (icon_) {
272276
SetImageModel(

chromium_src/ui/views/controls/button/md_text_button.h

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,25 @@
66
#ifndef BRAVE_CHROMIUM_SRC_UI_VIEWS_CONTROLS_BUTTON_MD_TEXT_BUTTON_H_
77
#define BRAVE_CHROMIUM_SRC_UI_VIEWS_CONTROLS_BUTTON_MD_TEXT_BUTTON_H_
88

9-
#include "include/core/SkColor.h"
109
#include "third_party/abseil-cpp/absl/types/optional.h"
10+
#include "third_party/skia/include/core/SkColor.h"
1111
#include "ui/gfx/vector_icon_types.h"
1212
#include "ui/views/controls/button/label_button.h"
1313

1414
// Rename MdTextButton to MdTextButtonBase
1515
#define MdTextButton MdTextButtonBase
1616

17-
// Define a Brave-specific method to be called from UpdateColors() to extend its
18-
// functionality instead of defining UpdateColors() "virtual" and overriding it
19-
// in our version of the MdTextButton class because there are some subclasses
20-
// that define their own UpdateColors() method (OmniboxChipButton) now, which
21-
// would not work with the virtual + override approach.
22-
// Note: We redefine UpdateBackgroundColor because we want it to be protected.
23-
#define UpdateBackgroundColor \
24-
UpdateBackgroundColor_Unused(); \
25-
\
26-
protected: \
27-
virtual void UpdateColorsForBrave() = 0; \
28-
virtual void UpdateIconForBrave() = 0; \
29-
void UpdateBackgroundColor
17+
// Redefine UpdateTextColor as protected virtual so we can override it.
18+
#define UpdateTextColor \
19+
UpdateTextColor_Unused(); \
20+
\
21+
protected: \
22+
virtual void UpdateIconForBrave() = 0; \
23+
virtual void UpdateTextColor
3024

3125
#include "src/ui/views/controls/button/md_text_button.h"
3226

33-
#undef UpdateBackgroundColor
27+
#undef UpdateTextColor
3428
#undef MdTextButton
3529

3630
namespace views {
@@ -66,13 +60,9 @@ class VIEWS_EXPORT MdTextButton : public MdTextButtonBase {
6660
bool GetLoading() const;
6761
void SetLoading(bool loading);
6862

69-
// Until we decide to update the whole UI to use the new Leo colors, we
70-
// need to keep this logic around. Currently the new colors are opt-in only.
71-
void UpdateOldColorsForBrave();
72-
7363
// MdTextButtonBase:
64+
void UpdateTextColor() override;
7465
void UpdateBackgroundColor() override;
75-
void UpdateColorsForBrave() override;
7666
void UpdateIconForBrave() override;
7767

7868
protected:

0 commit comments

Comments
 (0)