From 663f8f4b54d619614d3ee6ee263261d82c76155d Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 10 Oct 2016 14:31:06 -0700 Subject: [PATCH] Add systemPreferences.getColor on Windows --- atom/browser/api/atom_api_system_preferences.cc | 1 + atom/browser/api/atom_api_system_preferences.h | 1 + .../browser/api/atom_api_system_preferences_win.cc | 81 ++++++++++++++++++++++ 3 files changed, 83 insertions(+) diff --git a/atom/browser/api/atom_api_system_preferences.cc b/atom/browser/api/atom_api_system_preferences.cc index 96efe80..7bdc4fe 100644 --- a/atom/browser/api/atom_api_system_preferences.cc +++ b/atom/browser/api/atom_api_system_preferences.cc @@ -52,6 +52,7 @@ void SystemPreferences::BuildPrototype( #if defined(OS_WIN) .SetMethod("getAccentColor", &SystemPreferences::GetAccentColor) .SetMethod("isAeroGlassEnabled", &SystemPreferences::IsAeroGlassEnabled) + .SetMethod("getColor", &SystemPreferences::GetColor) #elif defined(OS_MACOSX) .SetMethod("postNotification", &SystemPreferences::PostNotification) diff --git a/atom/browser/api/atom_api_system_preferences.h b/atom/browser/api/atom_api_system_preferences.h index 1c00bfe..ee55601 100644 --- a/atom/browser/api/atom_api_system_preferences.h +++ b/atom/browser/api/atom_api_system_preferences.h @@ -44,6 +44,7 @@ class SystemPreferences : public mate::EventEmitter "DwmGetColorizationColor"); std::string GetAccentColor(); + std::string GetColor(const std::string& color, mate::Arguments* args); void InitializeWindow(); diff --git a/atom/browser/api/atom_api_system_preferences_win.cc b/atom/browser/api/atom_api_system_preferences_win.cc index c157d52..83878c1 100644 --- a/atom/browser/api/atom_api_system_preferences_win.cc +++ b/atom/browser/api/atom_api_system_preferences_win.cc @@ -4,8 +4,10 @@ #include "atom/browser/api/atom_api_system_preferences.h" +#include "atom/common/color_util.h" #include "base/win/wrapped_window_proc.h" #include "ui/base/win/shell.h" +#include "ui/gfx/color_utils.h" #include "ui/gfx/win/hwnd_util.h" namespace atom { @@ -41,6 +43,85 @@ std::string SystemPreferences::GetAccentColor() { return hexColorDWORDToRGBA(color); } +std::string SystemPreferences::GetColor(const std::string& color, + mate::Arguments* args) { + int id; + if (color == "3d-dark-shadow") { + id = COLOR_3DDKSHADOW; + } else if (color == "3d-face") { + id = COLOR_3DFACE; + } else if (color == "3d-highlight") { + id = COLOR_3DHIGHLIGHT; + } else if (color == "3d-light") { + id = COLOR_3DLIGHT; + } else if (color == "3d-shadow") { + id = COLOR_3DSHADOW; + } else if (color == "active-border") { + id = COLOR_ACTIVEBORDER; + } else if (color == "active-caption") { + id = COLOR_ACTIVECAPTION; + } else if (color == "active-caption-gradient") { + id = COLOR_GRADIENTACTIVECAPTION; + } else if (color == "app-workspace") { + id = COLOR_APPWORKSPACE; + } else if (color == "background") { + id = COLOR_BACKGROUND; + } else if (color == "button-face") { + id = COLOR_BTNFACE; + } else if (color == "button-highlight") { + id = COLOR_BTNHIGHLIGHT; + } else if (color == "button-shadow") { + id = COLOR_BTNSHADOW; + } else if (color == "button-text") { + id = COLOR_BTNTEXT; + } else if (color == "caption-text") { + id = COLOR_CAPTIONTEXT; + } else if (color == "desktop") { + id = COLOR_DESKTOP; + } else if (color == "disabled-text") { + id = COLOR_GRAYTEXT; + } else if (color == "highlight") { + id = COLOR_HIGHLIGHT; + } else if (color == "highlight-text") { + id = COLOR_HIGHLIGHTTEXT; + } else if (color == "hotlight") { + id = COLOR_HOTLIGHT; + } else if (color == "inactive-border") { + id = COLOR_INACTIVEBORDER; + } else if (color == "inactive-caption") { + id = COLOR_INACTIVECAPTION; + } else if (color == "inactive-caption-gradient") { + id = COLOR_GRADIENTINACTIVECAPTION; + } else if (color == "inactive-caption-text") { + id = COLOR_INACTIVECAPTIONTEXT; + } else if (color == "info-background") { + id = COLOR_INFOBK; + } else if (color == "info-text") { + id = COLOR_INFOTEXT; + } else if (color == "menu") { + id = COLOR_MENU; + } else if (color == "menu-highlight") { + id = COLOR_MENUHILIGHT; + } else if (color == "menubar") { + id = COLOR_MENUBAR; + } else if (color == "menu-text") { + id = COLOR_MENUTEXT; + } else if (color == "scrollbar") { + id = COLOR_SCROLLBAR; + } else if (color == "window") { + id = COLOR_WINDOW; + } else if (color == "window-frame") { + id = COLOR_WINDOWFRAME; + } else if (color == "window-text") { + id = COLOR_WINDOWTEXT; + } else { + args->ThrowError("Unknown color: " + color); + return ""; + } + + return ToRGBHex(color_utils::GetSysSkColor(id)); +} + void SystemPreferences::InitializeWindow() { invertered_color_scheme_ = IsInvertedColorScheme(); -- 2.7.4