diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index e3688235bd4..1e4207bf0c6 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -77,6 +77,29 @@ bool IsAltModifier(const content::NativeWebKeyboardEvent& event) { (modifiers == (Modifiers::AltKey | Modifiers::IsRight)); } +SkColor ParseHexColor(const std::string& name) { + SkColor result = 0xFF000000; + unsigned value = 0; + auto color = name.substr(1); + unsigned length = color.size(); + if (length != 3 && length != 6) + return result; + for (unsigned i = 0; i < length; ++i) { + if (!base::IsHexDigit(color[i])) + return result; + value <<= 4; + value |= (color[i] < 'A' ? color[i] - '0' : (color[i] - 'A' + 10) & 0xF); + } + if (length == 6) { + result |= value; + return result; + } + result |= (value & 0xF00) << 12 | (value & 0xF00) << 8 + | (value & 0xF0) << 8 | (value & 0xF0) << 4 + | (value & 0xF) << 4 | (value & 0xF); + return result; +} + class NativeWindowClientView : public views::ClientView { public: NativeWindowClientView(views::Widget* widget, @@ -205,7 +228,13 @@ NativeWindowViews::NativeWindowViews( // Add web view. SetLayoutManager(new MenuLayout(this, kMenuBarHeight)); - set_background(views::Background::CreateStandardPanelBackground()); + + // web views' background color. + std::string background_color = "#fff"; + options.Get(switches::kBackgroundColor, &background_color); + set_background(views::Background::CreateSolidBackground( + ParseHexColor(background_color))); + AddChildView(web_view_); #if defined(OS_WIN) diff --git a/atom/common/options_switches.cc b/atom/common/options_switches.cc index 8ea16f27b4f..903c15ee6dd 100644 --- a/atom/common/options_switches.cc +++ b/atom/common/options_switches.cc @@ -93,6 +93,9 @@ const char kDisableAutoHideCursor[] = "disable-auto-hide-cursor"; // Use the OS X's standard window instead of the textured window. const char kStandardWindow[] = "standard-window"; +// Default browser window background color. +const char kBackgroundColor[] = "background-color"; + // Path to client certificate. const char kClientCertificate[] = "client-certificate"; diff --git a/atom/common/options_switches.h b/atom/common/options_switches.h index 33c2790cc15..9887359a502 100644 --- a/atom/common/options_switches.h +++ b/atom/common/options_switches.h @@ -47,6 +47,7 @@ extern const char kTransparent[]; extern const char kType[]; extern const char kDisableAutoHideCursor[]; extern const char kStandardWindow[]; +extern const char kBackgroundColor[]; extern const char kClientCertificate[]; extern const char kExperimentalFeatures[]; diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index fd25f8cdc98..c59fbbdbcb4 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -61,6 +61,13 @@ It creates a new `BrowserWindow` with native properties as set by the `options`. key is pressed. * `enable-larger-than-screen` Boolean - Enable the window to be resized larger than screen. +* `background-color` String - Window's background color as Hexadecimal value. +```javascript +var win = new BrowserWindow({ width: 800, height: 600, 'background-color': '#66CD00' }) + +// #abc will be expanded to #aabbcc +var win = new BrowserWindow({ width: 800, height: 600, 'background-color': '#fff' }) +``` * `dark-theme` Boolean - Forces using dark theme for the window, only works on some GTK+3 desktop environments. * `transparent` Boolean - Makes the window [transparent](frameless-window.md).