Commit 195e49a6 authored by Kurt Catti-Schmidt's avatar Kurt Catti-Schmidt Committed by Commit Bot

Plumb system colors into LayoutThemeDefault

The following CL set up a pipeline to send a map of the system colors
from the browser process to the render process:
https://chromium-review.googlesource.com/c/chromium/src/+/1728056

This change takes those system colors and uses them in
LayoutThemeWin::SystemColor(). This replaces the old logic of making
API calls to get the system colors.

LayoutThemeWin accesses the system colors stored in NativeTheme
through WebThemeEngineDefault.

Unit tests were added for conversions between Blink and NativeTheme
types. This required pulling the static conversion methods into
their own header.

Bug: 970285
Change-Id: I842e5224aa3a97852eda13c3d86f90396262fde9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1793742
Commit-Queue: Kurt Catti-Schmidt <kschmi@microsoft.com>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarKevin Babbitt <kbabbitt@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#699050}
parent 6e422cde
...@@ -72,6 +72,8 @@ target(link_target_type, "child") { ...@@ -72,6 +72,8 @@ target(link_target_type, "child") {
"thread_safe_sender.h", "thread_safe_sender.h",
"webthemeengine_impl_android.cc", "webthemeengine_impl_android.cc",
"webthemeengine_impl_android.h", "webthemeengine_impl_android.h",
"webthemeengine_impl_conversions.cc",
"webthemeengine_impl_conversions.h",
"webthemeengine_impl_default.cc", "webthemeengine_impl_default.cc",
"webthemeengine_impl_default.h", "webthemeengine_impl_default.h",
"webthemeengine_impl_mac.h", "webthemeengine_impl_mac.h",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/child/webthemeengine_impl_conversions.h"
namespace content {
// TODO(https://crbug.com/988434): The mapping functions below are duplicated
// inside Blink and in the Android implementation of WebThemeEngine. They should
// be implemented in one place where dependencies between Blink and
// ui::NativeTheme make sense.
ui::NativeTheme::Part NativeThemePart(blink::WebThemeEngine::Part part) {
switch (part) {
case blink::WebThemeEngine::kPartScrollbarDownArrow:
return ui::NativeTheme::kScrollbarDownArrow;
case blink::WebThemeEngine::kPartScrollbarLeftArrow:
return ui::NativeTheme::kScrollbarLeftArrow;
case blink::WebThemeEngine::kPartScrollbarRightArrow:
return ui::NativeTheme::kScrollbarRightArrow;
case blink::WebThemeEngine::kPartScrollbarUpArrow:
return ui::NativeTheme::kScrollbarUpArrow;
case blink::WebThemeEngine::kPartScrollbarHorizontalThumb:
return ui::NativeTheme::kScrollbarHorizontalThumb;
case blink::WebThemeEngine::kPartScrollbarVerticalThumb:
return ui::NativeTheme::kScrollbarVerticalThumb;
case blink::WebThemeEngine::kPartScrollbarHorizontalTrack:
return ui::NativeTheme::kScrollbarHorizontalTrack;
case blink::WebThemeEngine::kPartScrollbarVerticalTrack:
return ui::NativeTheme::kScrollbarVerticalTrack;
case blink::WebThemeEngine::kPartScrollbarCorner:
return ui::NativeTheme::kScrollbarCorner;
case blink::WebThemeEngine::kPartCheckbox:
return ui::NativeTheme::kCheckbox;
case blink::WebThemeEngine::kPartRadio:
return ui::NativeTheme::kRadio;
case blink::WebThemeEngine::kPartButton:
return ui::NativeTheme::kPushButton;
case blink::WebThemeEngine::kPartTextField:
return ui::NativeTheme::kTextField;
case blink::WebThemeEngine::kPartMenuList:
return ui::NativeTheme::kMenuList;
case blink::WebThemeEngine::kPartSliderTrack:
return ui::NativeTheme::kSliderTrack;
case blink::WebThemeEngine::kPartSliderThumb:
return ui::NativeTheme::kSliderThumb;
case blink::WebThemeEngine::kPartInnerSpinButton:
return ui::NativeTheme::kInnerSpinButton;
case blink::WebThemeEngine::kPartProgressBar:
return ui::NativeTheme::kProgressBar;
default:
return ui::NativeTheme::kScrollbarDownArrow;
}
}
ui::NativeTheme::ScrollbarOverlayColorTheme
NativeThemeScrollbarOverlayColorTheme(
blink::WebScrollbarOverlayColorTheme theme) {
switch (theme) {
case blink::WebScrollbarOverlayColorTheme::
kWebScrollbarOverlayColorThemeLight:
return ui::NativeTheme::ScrollbarOverlayColorThemeLight;
case blink::WebScrollbarOverlayColorTheme::
kWebScrollbarOverlayColorThemeDark:
return ui::NativeTheme::ScrollbarOverlayColorThemeDark;
default:
return ui::NativeTheme::ScrollbarOverlayColorThemeDark;
}
}
ui::NativeTheme::State NativeThemeState(blink::WebThemeEngine::State state) {
switch (state) {
case blink::WebThemeEngine::kStateDisabled:
return ui::NativeTheme::kDisabled;
case blink::WebThemeEngine::kStateHover:
return ui::NativeTheme::kHovered;
case blink::WebThemeEngine::kStateNormal:
return ui::NativeTheme::kNormal;
case blink::WebThemeEngine::kStatePressed:
return ui::NativeTheme::kPressed;
default:
return ui::NativeTheme::kDisabled;
}
}
ui::NativeTheme::ColorScheme NativeColorScheme(
blink::WebColorScheme color_scheme) {
switch (color_scheme) {
case blink::WebColorScheme::kLight:
return ui::NativeTheme::ColorScheme::kLight;
case blink::WebColorScheme::kDark:
return ui::NativeTheme::ColorScheme::kDark;
}
}
ui::NativeTheme::SystemThemeColor NativeSystemThemeColor(
blink::WebThemeEngine::SystemThemeColor theme_color) {
switch (theme_color) {
case blink::WebThemeEngine::SystemThemeColor::kButtonFace:
return ui::NativeTheme::SystemThemeColor::kButtonFace;
case blink::WebThemeEngine::SystemThemeColor::kButtonText:
return ui::NativeTheme::SystemThemeColor::kButtonText;
case blink::WebThemeEngine::SystemThemeColor::kGrayText:
return ui::NativeTheme::SystemThemeColor::kGrayText;
case blink::WebThemeEngine::SystemThemeColor::kHighlight:
return ui::NativeTheme::SystemThemeColor::kHighlight;
case blink::WebThemeEngine::SystemThemeColor::kHighlightText:
return ui::NativeTheme::SystemThemeColor::kHighlightText;
case blink::WebThemeEngine::SystemThemeColor::kHotlight:
return ui::NativeTheme::SystemThemeColor::kHotlight;
case blink::WebThemeEngine::SystemThemeColor::kWindow:
return ui::NativeTheme::SystemThemeColor::kWindow;
case blink::WebThemeEngine::SystemThemeColor::kWindowText:
return ui::NativeTheme::SystemThemeColor::kWindowText;
default:
return ui::NativeTheme::SystemThemeColor::kNotSupported;
}
}
} // namespace content
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_CHILD_WEBTHEMEENGINE_IMPL_CONVERSIONS_H_
#define CONTENT_CHILD_WEBTHEMEENGINE_IMPL_CONVERSIONS_H_
#include "content/child/webthemeengine_impl_default.h"
#include "content/common/content_export.h"
#include "ui/native_theme/native_theme.h"
namespace content {
CONTENT_EXPORT ui::NativeTheme::Part NativeThemePart(
blink::WebThemeEngine::Part part);
CONTENT_EXPORT ui::NativeTheme::ScrollbarOverlayColorTheme
NativeThemeScrollbarOverlayColorTheme(
blink::WebScrollbarOverlayColorTheme theme);
CONTENT_EXPORT ui::NativeTheme::State NativeThemeState(
blink::WebThemeEngine::State state);
CONTENT_EXPORT ui::NativeTheme::ColorScheme NativeColorScheme(
blink::WebColorScheme color_scheme);
CONTENT_EXPORT ui::NativeTheme::SystemThemeColor NativeSystemThemeColor(
blink::WebThemeEngine::SystemThemeColor theme_color);
} // namespace content
#endif // CONTENT_CHILD_WEBTHEMEENGINE_IMPL_CONVERSIONS_H_
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "content/child/webthemeengine_impl_default.h" #include "content/child/webthemeengine_impl_default.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "content/child/webthemeengine_impl_conversions.h"
#include "skia/ext/platform_canvas.h" #include "skia/ext/platform_canvas.h"
#include "third_party/blink/public/platform/web_rect.h" #include "third_party/blink/public/platform/web_rect.h"
#include "third_party/blink/public/platform/web_size.h" #include "third_party/blink/public/platform/web_size.h"
...@@ -35,92 +36,6 @@ int32_t g_horizontal_arrow_bitmap_width; ...@@ -35,92 +36,6 @@ int32_t g_horizontal_arrow_bitmap_width;
} // namespace } // namespace
// TODO(https://crbug.com/988434): The mapping functions below are duplicated
// inside Blink and in the Android implementation of WebThemeEngine. They should
// be implemented in one place where dependencies between Blink and
// ui::NativeTheme make sense.
static ui::NativeTheme::Part NativeThemePart(
WebThemeEngine::Part part) {
switch (part) {
case WebThemeEngine::kPartScrollbarDownArrow:
return ui::NativeTheme::kScrollbarDownArrow;
case WebThemeEngine::kPartScrollbarLeftArrow:
return ui::NativeTheme::kScrollbarLeftArrow;
case WebThemeEngine::kPartScrollbarRightArrow:
return ui::NativeTheme::kScrollbarRightArrow;
case WebThemeEngine::kPartScrollbarUpArrow:
return ui::NativeTheme::kScrollbarUpArrow;
case WebThemeEngine::kPartScrollbarHorizontalThumb:
return ui::NativeTheme::kScrollbarHorizontalThumb;
case WebThemeEngine::kPartScrollbarVerticalThumb:
return ui::NativeTheme::kScrollbarVerticalThumb;
case WebThemeEngine::kPartScrollbarHorizontalTrack:
return ui::NativeTheme::kScrollbarHorizontalTrack;
case WebThemeEngine::kPartScrollbarVerticalTrack:
return ui::NativeTheme::kScrollbarVerticalTrack;
case WebThemeEngine::kPartScrollbarCorner:
return ui::NativeTheme::kScrollbarCorner;
case WebThemeEngine::kPartCheckbox:
return ui::NativeTheme::kCheckbox;
case WebThemeEngine::kPartRadio:
return ui::NativeTheme::kRadio;
case WebThemeEngine::kPartButton:
return ui::NativeTheme::kPushButton;
case WebThemeEngine::kPartTextField:
return ui::NativeTheme::kTextField;
case WebThemeEngine::kPartMenuList:
return ui::NativeTheme::kMenuList;
case WebThemeEngine::kPartSliderTrack:
return ui::NativeTheme::kSliderTrack;
case WebThemeEngine::kPartSliderThumb:
return ui::NativeTheme::kSliderThumb;
case WebThemeEngine::kPartInnerSpinButton:
return ui::NativeTheme::kInnerSpinButton;
case WebThemeEngine::kPartProgressBar:
return ui::NativeTheme::kProgressBar;
default:
return ui::NativeTheme::kScrollbarDownArrow;
}
}
static ui::NativeTheme::ScrollbarOverlayColorTheme
NativeThemeScrollbarOverlayColorTheme(WebScrollbarOverlayColorTheme theme) {
switch (theme) {
case WebScrollbarOverlayColorTheme::kWebScrollbarOverlayColorThemeLight:
return ui::NativeTheme::ScrollbarOverlayColorThemeLight;
case WebScrollbarOverlayColorTheme::kWebScrollbarOverlayColorThemeDark:
return ui::NativeTheme::ScrollbarOverlayColorThemeDark;
default:
return ui::NativeTheme::ScrollbarOverlayColorThemeDark;
}
}
static ui::NativeTheme::State NativeThemeState(
WebThemeEngine::State state) {
switch (state) {
case WebThemeEngine::kStateDisabled:
return ui::NativeTheme::kDisabled;
case WebThemeEngine::kStateHover:
return ui::NativeTheme::kHovered;
case WebThemeEngine::kStateNormal:
return ui::NativeTheme::kNormal;
case WebThemeEngine::kStatePressed:
return ui::NativeTheme::kPressed;
default:
return ui::NativeTheme::kDisabled;
}
}
static ui::NativeTheme::ColorScheme NativeColorScheme(
WebColorScheme color_scheme) {
switch (color_scheme) {
case WebColorScheme::kLight:
return ui::NativeTheme::ColorScheme::kLight;
case WebColorScheme::kDark:
return ui::NativeTheme::ColorScheme::kDark;
}
}
static void GetNativeThemeExtraParams( static void GetNativeThemeExtraParams(
WebThemeEngine::Part part, WebThemeEngine::Part part,
WebThemeEngine::State state, WebThemeEngine::State state,
...@@ -297,6 +212,12 @@ blink::WebRect WebThemeEngineDefault::NinePatchAperture(Part part) const { ...@@ -297,6 +212,12 @@ blink::WebRect WebThemeEngineDefault::NinePatchAperture(Part part) const {
NativeThemePart(part)); NativeThemePart(part));
} }
base::Optional<SkColor> WebThemeEngineDefault::GetSystemColor(
blink::WebThemeEngine::SystemThemeColor system_theme_color) const {
return ui::NativeTheme::GetInstanceForWeb()->GetSystemColorFromMap(
NativeSystemThemeColor(system_theme_color));
}
#if defined(OS_WIN) #if defined(OS_WIN)
// static // static
void WebThemeEngineDefault::cacheScrollBarMetrics( void WebThemeEngineDefault::cacheScrollBarMetrics(
......
...@@ -28,6 +28,8 @@ class WebThemeEngineDefault : public blink::WebThemeEngine { ...@@ -28,6 +28,8 @@ class WebThemeEngineDefault : public blink::WebThemeEngine {
bool SupportsNinePatch(Part part) const override; bool SupportsNinePatch(Part part) const override;
blink::WebSize NinePatchCanvasSize(Part part) const override; blink::WebSize NinePatchCanvasSize(Part part) const override;
blink::WebRect NinePatchAperture(Part part) const override; blink::WebRect NinePatchAperture(Part part) const override;
base::Optional<SkColor> GetSystemColor(blink::WebThemeEngine::SystemThemeColor
system_theme_color) const override;
#if defined(OS_WIN) #if defined(OS_WIN)
// Caches the scrollbar metrics. These are retrieved in the browser and passed // Caches the scrollbar metrics. These are retrieved in the browser and passed
// to the renderer in blink::mojom::RendererPreferences because the required // to the renderer in blink::mojom::RendererPreferences because the required
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/child/webthemeengine_impl_conversions.h"
#include <vector>
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/web_theme_engine.h"
namespace content {
TEST(WebThemeEngineTest, NativeSystemThemeColor) {
std::vector<blink::WebThemeEngine::SystemThemeColor> blink_inputs = {
blink::WebThemeEngine::SystemThemeColor::kButtonFace,
blink::WebThemeEngine::SystemThemeColor::kButtonText,
blink::WebThemeEngine::SystemThemeColor::kGrayText,
blink::WebThemeEngine::SystemThemeColor::kHighlight,
blink::WebThemeEngine::SystemThemeColor::kHighlightText,
blink::WebThemeEngine::SystemThemeColor::kHotlight,
blink::WebThemeEngine::SystemThemeColor::kWindow,
blink::WebThemeEngine::SystemThemeColor::kWindowText};
std::vector<ui::NativeTheme::SystemThemeColor> native_theme_outputs = {
ui::NativeTheme::SystemThemeColor::kButtonFace,
ui::NativeTheme::SystemThemeColor::kButtonText,
ui::NativeTheme::SystemThemeColor::kGrayText,
ui::NativeTheme::SystemThemeColor::kHighlight,
ui::NativeTheme::SystemThemeColor::kHighlightText,
ui::NativeTheme::SystemThemeColor::kHotlight,
ui::NativeTheme::SystemThemeColor::kWindow,
ui::NativeTheme::SystemThemeColor::kWindowText};
for (size_t i = 0; i < blink_inputs.size(); ++i)
EXPECT_EQ(NativeSystemThemeColor(blink_inputs[i]), native_theme_outputs[i]);
}
TEST(WebThemeEngineTest, NativeSystemThemePart) {
std::vector<blink::WebThemeEngine::Part> blink_inputs = {
blink::WebThemeEngine::kPartScrollbarDownArrow,
blink::WebThemeEngine::kPartScrollbarLeftArrow,
blink::WebThemeEngine::kPartScrollbarRightArrow,
blink::WebThemeEngine::kPartScrollbarUpArrow,
blink::WebThemeEngine::kPartScrollbarHorizontalThumb,
blink::WebThemeEngine::kPartScrollbarVerticalThumb,
blink::WebThemeEngine::kPartScrollbarHorizontalTrack,
blink::WebThemeEngine::kPartScrollbarVerticalTrack,
blink::WebThemeEngine::kPartScrollbarCorner,
blink::WebThemeEngine::kPartCheckbox,
blink::WebThemeEngine::kPartRadio,
blink::WebThemeEngine::kPartButton,
blink::WebThemeEngine::kPartTextField,
blink::WebThemeEngine::kPartMenuList,
blink::WebThemeEngine::kPartSliderTrack,
blink::WebThemeEngine::kPartSliderThumb,
blink::WebThemeEngine::kPartInnerSpinButton,
blink::WebThemeEngine::kPartProgressBar};
std::vector<ui::NativeTheme::Part> native_theme_outputs = {
ui::NativeTheme::kScrollbarDownArrow,
ui::NativeTheme::kScrollbarLeftArrow,
ui::NativeTheme::kScrollbarRightArrow,
ui::NativeTheme::kScrollbarUpArrow,
ui::NativeTheme::kScrollbarHorizontalThumb,
ui::NativeTheme::kScrollbarVerticalThumb,
ui::NativeTheme::kScrollbarHorizontalTrack,
ui::NativeTheme::kScrollbarVerticalTrack,
ui::NativeTheme::kScrollbarCorner,
ui::NativeTheme::kCheckbox,
ui::NativeTheme::kRadio,
ui::NativeTheme::kPushButton,
ui::NativeTheme::kTextField,
ui::NativeTheme::kMenuList,
ui::NativeTheme::kSliderTrack,
ui::NativeTheme::kSliderThumb,
ui::NativeTheme::kInnerSpinButton,
ui::NativeTheme::kProgressBar};
for (size_t i = 0; i < blink_inputs.size(); ++i)
EXPECT_EQ(NativeThemePart(blink_inputs[i]), native_theme_outputs[i]);
}
TEST(WebThemeEngineTest, NativeSystemThemeState) {
std::vector<blink::WebThemeEngine::State> blink_inputs = {
blink::WebThemeEngine::kStateDisabled,
blink::WebThemeEngine::kStateHover,
blink::WebThemeEngine::kStateNormal,
blink::WebThemeEngine::kStatePressed,
};
std::vector<ui::NativeTheme::State> native_theme_outputs = {
ui::NativeTheme::kDisabled, ui::NativeTheme::kHovered,
ui::NativeTheme::kNormal, ui::NativeTheme::kPressed};
for (size_t i = 0; i < blink_inputs.size(); ++i)
EXPECT_EQ(NativeThemeState(blink_inputs[i]), native_theme_outputs[i]);
}
TEST(WebThemeEngineTest, NativeColorScheme) {
std::vector<blink::WebColorScheme> blink_inputs = {
blink::WebColorScheme::kLight, blink::WebColorScheme::kDark};
std::vector<ui::NativeTheme::ColorScheme> native_theme_outputs = {
ui::NativeTheme::ColorScheme::kLight,
ui::NativeTheme::ColorScheme::kDark};
for (size_t i = 0; i < blink_inputs.size(); ++i)
EXPECT_EQ(NativeColorScheme(blink_inputs[i]), native_theme_outputs[i]);
}
TEST(WebThemeEngineTest, NativeThemeScrollbarOverlayColorTheme) {
std::vector<blink::WebScrollbarOverlayColorTheme> blink_inputs = {
blink::WebScrollbarOverlayColorTheme::kWebScrollbarOverlayColorThemeLight,
blink::WebScrollbarOverlayColorTheme::kWebScrollbarOverlayColorThemeDark};
std::vector<ui::NativeTheme::ScrollbarOverlayColorTheme>
native_theme_outputs = {ui::NativeTheme::ScrollbarOverlayColorThemeLight,
ui::NativeTheme::ScrollbarOverlayColorThemeDark};
for (size_t i = 0; i < blink_inputs.size(); ++i) {
EXPECT_EQ(NativeThemeScrollbarOverlayColorTheme(blink_inputs[i]),
native_theme_outputs[i]);
}
}
} // namespace content
...@@ -1875,6 +1875,7 @@ test("content_unittests") { ...@@ -1875,6 +1875,7 @@ test("content_unittests") {
"../child/dwrite_font_proxy/dwrite_font_proxy_win_unittest.cc", "../child/dwrite_font_proxy/dwrite_font_proxy_win_unittest.cc",
"../child/dwrite_font_proxy/font_fallback_win_unittest.cc", "../child/dwrite_font_proxy/font_fallback_win_unittest.cc",
"../child/font_warmup_win_unittest.cc", "../child/font_warmup_win_unittest.cc",
"../child/webthemeengine_impl_unittest.cc",
"../common/android/gin_java_bridge_value_unittest.cc", "../common/android/gin_java_bridge_value_unittest.cc",
"../common/background_fetch/background_fetch_mojom_traits_unittest.cc", "../common/background_fetch/background_fetch_mojom_traits_unittest.cc",
"../common/common_param_traits_unittest.cc", "../common/common_param_traits_unittest.cc",
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_THEME_ENGINE_H_ #ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_THEME_ENGINE_H_
#define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_THEME_ENGINE_H_ #define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_THEME_ENGINE_H_
#include "base/optional.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "third_party/blink/public/platform/web_color_scheme.h" #include "third_party/blink/public/platform/web_color_scheme.h"
#include "third_party/blink/public/platform/web_rect.h" #include "third_party/blink/public/platform/web_rect.h"
...@@ -81,6 +82,21 @@ class WebThemeEngine { ...@@ -81,6 +82,21 @@ class WebThemeEngine {
kPartProgressBar kPartProgressBar
}; };
enum class SystemThemeColor {
kNotSupported,
kButtonFace,
kButtonText,
kGrayText,
kHighlight,
kHighlightText,
kHotlight,
kMenuHighlight,
kScrollbar,
kWindow,
kWindowText,
kMaxValue = kWindowText,
};
// Extra parameters for drawing the PartScrollbarHorizontalTrack and // Extra parameters for drawing the PartScrollbarHorizontalTrack and
// PartScrollbarVerticalTrack. // PartScrollbarVerticalTrack.
struct ScrollbarTrackExtraParams { struct ScrollbarTrackExtraParams {
...@@ -203,6 +219,11 @@ class WebThemeEngine { ...@@ -203,6 +219,11 @@ class WebThemeEngine {
const WebRect&, const WebRect&,
const ExtraParams*, const ExtraParams*,
blink::WebColorScheme) {} blink::WebColorScheme) {}
virtual base::Optional<SkColor> GetSystemColor(
SystemThemeColor system_theme) const {
return base::nullopt;
}
}; };
} // namespace blink } // namespace blink
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <windows.h> #include <windows.h>
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h" #include "third_party/blink/renderer/platform/runtime_enabled_features.h"
namespace blink { namespace blink {
...@@ -25,45 +26,42 @@ Color LayoutThemeWin::SystemColor(CSSValueID css_value_id, ...@@ -25,45 +26,42 @@ Color LayoutThemeWin::SystemColor(CSSValueID css_value_id,
return LayoutThemeDefault::SystemColor(css_value_id, color_scheme); return LayoutThemeDefault::SystemColor(css_value_id, color_scheme);
} }
int system_index; blink::WebThemeEngine::SystemThemeColor theme_color;
switch (css_value_id) { switch (css_value_id) {
case CSSValueID::kButtonface: case CSSValueID::kButtonface:
system_index = COLOR_BTNFACE; theme_color = blink::WebThemeEngine::SystemThemeColor::kButtonFace;
break; break;
case CSSValueID::kButtontext: case CSSValueID::kButtontext:
system_index = COLOR_BTNTEXT; theme_color = blink::WebThemeEngine::SystemThemeColor::kButtonText;
break; break;
case CSSValueID::kGraytext: case CSSValueID::kGraytext:
system_index = COLOR_GRAYTEXT; theme_color = blink::WebThemeEngine::SystemThemeColor::kGrayText;
break; break;
case CSSValueID::kHighlight: case CSSValueID::kHighlight:
system_index = COLOR_HIGHLIGHT; theme_color = blink::WebThemeEngine::SystemThemeColor::kHighlight;
break; break;
case CSSValueID::kHighlighttext: case CSSValueID::kHighlighttext:
system_index = COLOR_HIGHLIGHTTEXT; theme_color = blink::WebThemeEngine::SystemThemeColor::kHighlightText;
break; break;
case CSSValueID::kLinktext: case CSSValueID::kLinktext:
case CSSValueID::kVisitedtext: case CSSValueID::kVisitedtext:
system_index = COLOR_HOTLIGHT; theme_color = blink::WebThemeEngine::SystemThemeColor::kHotlight;
break; break;
case CSSValueID::kWindow: case CSSValueID::kWindow:
system_index = COLOR_WINDOW; theme_color = blink::WebThemeEngine::SystemThemeColor::kWindow;
break; break;
case CSSValueID::kWindowtext: case CSSValueID::kWindowtext:
system_index = COLOR_WINDOWTEXT; theme_color = blink::WebThemeEngine::SystemThemeColor::kWindowText;
break; break;
default: default:
return LayoutThemeDefault::SystemColor(css_value_id, color_scheme); return LayoutThemeDefault::SystemColor(css_value_id, color_scheme);
} }
return SystemColorBySystemIndex(system_index); const base::Optional<SkColor> system_color =
} Platform::Current()->ThemeEngine()->GetSystemColor(theme_color);
if (system_color == base::nullopt)
Color LayoutThemeWin::SystemColorBySystemIndex(int system_index) { return LayoutThemeDefault::SystemColor(css_value_id, color_scheme);
DWORD system_color = ::GetSysColor(system_index); return Color(system_color.value());
return Color(GetRValue(system_color), GetGValue(system_color),
GetBValue(system_color));
} }
} // namespace blink } // namespace blink
...@@ -15,9 +15,6 @@ class LayoutThemeWin final : public LayoutThemeDefault { ...@@ -15,9 +15,6 @@ class LayoutThemeWin final : public LayoutThemeDefault {
Color SystemColor(CSSValueID css_value_id, Color SystemColor(CSSValueID css_value_id,
WebColorScheme color_scheme) const override; WebColorScheme color_scheme) const override;
private:
static Color SystemColorBySystemIndex(int system_index);
}; };
} // namespace blink } // namespace blink
......
...@@ -84,6 +84,15 @@ NativeTheme::GetSystemColors() const { ...@@ -84,6 +84,15 @@ NativeTheme::GetSystemColors() const {
return system_colors_; return system_colors_;
} }
base::Optional<SkColor> NativeTheme::GetSystemColorFromMap(
SystemThemeColor theme_color) const {
auto color = system_colors_.find(theme_color);
if (color != system_colors_.end())
return color->second;
return base::nullopt;
}
bool NativeTheme::HasDifferentSystemColors( bool NativeTheme::HasDifferentSystemColors(
const std::map<NativeTheme::SystemThemeColor, SkColor>& colors) const { const std::map<NativeTheme::SystemThemeColor, SkColor>& colors) const {
return system_colors_ != colors; return system_colors_ != colors;
......
...@@ -466,6 +466,9 @@ class NATIVE_THEME_EXPORT NativeTheme { ...@@ -466,6 +466,9 @@ class NATIVE_THEME_EXPORT NativeTheme {
virtual const std::map<SystemThemeColor, SkColor>& GetSystemColors() const; virtual const std::map<SystemThemeColor, SkColor>& GetSystemColors() const;
base::Optional<SkColor> GetSystemColorFromMap(
SystemThemeColor theme_color) const;
bool HasDifferentSystemColors( bool HasDifferentSystemColors(
const std::map<SystemThemeColor, SkColor>& colors) const; const std::map<SystemThemeColor, SkColor>& colors) const;
......
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