Commit 4b3484ef authored by Robert Liao's avatar Robert Liao Committed by Commit Bot

Breakup GetAuraColor() to Make Control Flow Obvious

This change moves long switch statements into separate helper functions
to make it easier to see GetAuraColor's control flow.

BUG=

Change-Id: I203ee8dc54020e4ce60924511363a5cb19269e26
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2108821
Commit-Queue: Robert Liao <robliao@chromium.org>
Auto-Submit: Robert Liao <robliao@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751721}
parent 5801a67a
......@@ -5,6 +5,7 @@
#include "ui/native_theme/common_theme.h"
#include "base/logging.h"
#include "base/optional.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
......@@ -17,15 +18,11 @@
namespace ui {
SkColor GetAuraColor(NativeTheme::ColorId color_id,
const NativeTheme* base_theme,
NativeTheme::ColorScheme color_scheme) {
if (color_scheme == NativeTheme::ColorScheme::kDefault)
color_scheme = base_theme->GetDefaultSystemColorScheme();
namespace {
// High contrast overrides the normal colors for certain ColorIds to be much
// darker or lighter.
if (base_theme->UsesHighContrastColors()) {
base::Optional<SkColor> GetHighContrastColor(
NativeTheme::ColorId color_id,
NativeTheme::ColorScheme color_scheme) {
switch (color_id) {
case NativeTheme::kColorId_ButtonUncheckedColor:
case NativeTheme::kColorId_MenuBorderColor:
......@@ -42,18 +39,17 @@ SkColor GetAuraColor(NativeTheme::ColorId color_id,
? gfx::kGoogleBlue100
: gfx::kGoogleBlue900;
default:
break;
}
return base::nullopt;
}
}
if (color_scheme == NativeTheme::ColorScheme::kDark) {
base::Optional<SkColor> GetDarkSchemeColor(NativeTheme::ColorId color_id) {
switch (color_id) {
// Dialogs
case NativeTheme::kColorId_WindowBackground:
case NativeTheme::kColorId_DialogBackground:
case NativeTheme::kColorId_BubbleBackground:
return color_utils::AlphaBlend(SK_ColorWHITE, gfx::kGoogleGrey900,
0.04f);
return color_utils::AlphaBlend(SK_ColorWHITE, gfx::kGoogleGrey900, 0.04f);
case NativeTheme::kColorId_DialogForeground:
return gfx::kGoogleGrey500;
case NativeTheme::kColorId_BubbleFooterBackground:
......@@ -103,8 +99,7 @@ SkColor GetAuraColor(NativeTheme::ColorId color_id,
// Dropdown
case NativeTheme::kColorId_DropdownBackgroundColor:
return color_utils::AlphaBlend(SK_ColorWHITE, gfx::kGoogleGrey900,
0.04f);
return color_utils::AlphaBlend(SK_ColorWHITE, gfx::kGoogleGrey900, 0.04f);
case NativeTheme::kColorId_DropdownForegroundColor:
return gfx::kGoogleGrey200;
case NativeTheme::kColorId_DropdownSelectedForegroundColor:
......@@ -143,8 +138,7 @@ SkColor GetAuraColor(NativeTheme::ColorId color_id,
// Table
case NativeTheme::kColorId_TableBackground:
case NativeTheme::kColorId_TableBackgroundAlternate:
return color_utils::AlphaBlend(SK_ColorWHITE, gfx::kGoogleGrey900,
0.04f);
return color_utils::AlphaBlend(SK_ColorWHITE, gfx::kGoogleGrey900, 0.04f);
case NativeTheme::kColorId_TableText:
case NativeTheme::kColorId_TableSelectedText:
case NativeTheme::kColorId_TableSelectedTextUnfocused:
......@@ -155,8 +149,7 @@ SkColor GetAuraColor(NativeTheme::ColorId color_id,
case NativeTheme::kColorId_TextfieldSelectionColor:
return gfx::kGoogleGrey200;
case NativeTheme::kColorId_TextfieldReadOnlyBackground: {
return color_utils::AlphaBlend(SK_ColorWHITE, gfx::kGoogleGrey900,
0.04f);
return color_utils::AlphaBlend(SK_ColorWHITE, gfx::kGoogleGrey900, 0.04f);
}
case NativeTheme::kColorId_TextfieldSelectionBackgroundFocused:
return gfx::kGoogleBlue800;
......@@ -167,8 +160,7 @@ SkColor GetAuraColor(NativeTheme::ColorId color_id,
// Tree
case NativeTheme::kColorId_TreeBackground:
return color_utils::AlphaBlend(SK_ColorWHITE, gfx::kGoogleGrey900,
0.04f);
return color_utils::AlphaBlend(SK_ColorWHITE, gfx::kGoogleGrey900, 0.04f);
case NativeTheme::kColorId_TreeText:
case NativeTheme::kColorId_TreeSelectedText:
case NativeTheme::kColorId_TreeSelectedTextUnfocused:
......@@ -189,10 +181,13 @@ SkColor GetAuraColor(NativeTheme::ColorId color_id,
case NativeTheme::kColorId_DefaultIconColor:
return gfx::kGoogleGrey500;
default:
break;
}
return base::nullopt;
}
}
SkColor GetDefaultColor(NativeTheme::ColorId color_id,
const NativeTheme* base_theme,
NativeTheme::ColorScheme color_scheme) {
constexpr SkColor kPrimaryTextColor = gfx::kGoogleGrey900;
......@@ -495,11 +490,38 @@ SkColor GetAuraColor(NativeTheme::ColorId color_id,
NativeTheme::kColorId_BubbleFooterBackground);
case NativeTheme::kColorId_NumColors:
break;
}
// Keeping the kColorId_NumColors case instead of using the default case
// allows ColorId additions to trigger compile error for an incomplete
// switch enumeration.
NOTREACHED();
return gfx::kPlaceholderColor;
}
}
} // namespace
SkColor GetAuraColor(NativeTheme::ColorId color_id,
const NativeTheme* base_theme,
NativeTheme::ColorScheme color_scheme) {
if (color_scheme == NativeTheme::ColorScheme::kDefault)
color_scheme = base_theme->GetDefaultSystemColorScheme();
// High contrast overrides the normal colors for certain ColorIds to be much
// darker or lighter.
if (base_theme->UsesHighContrastColors()) {
base::Optional<SkColor> color =
GetHighContrastColor(color_id, color_scheme);
if (color.has_value())
return color.value();
}
if (color_scheme == NativeTheme::ColorScheme::kDark) {
base::Optional<SkColor> color = GetDarkSchemeColor(color_id);
if (color.has_value())
return color.value();
}
return GetDefaultColor(color_id, base_theme, color_scheme);
}
void CommonThemePaintMenuItemBackground(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment