]> khamidou — GitHub mirrors - electron.git/commitdiff
browser: option to set window background color
authorRobo <hop2deep@gmail.com>
Wed, 21 Oct 2015 10:17:28 +0000 (15:47 +0530)
committerRobo <hop2deep@gmail.com>
Thu, 22 Oct 2015 04:24:29 +0000 (09:54 +0530)
atom/browser/native_window_views.cc
atom/common/options_switches.cc
atom/common/options_switches.h
docs/api/browser-window.md

index e3688235bd4e2b92df899225ef030310f9e1191c..1e4207bf0c6f0efc29fe4084d98aef852f54a715 100644 (file)
@@ -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)
index 8ea16f27b4f8cc85c00a5b35727bb3d34410f937..903c15ee6dd14b9e01a39afba4dbdb94fa76a736 100644 (file)
@@ -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";
 
index 33c2790cc152a998a1a03fdb229eb596da835c17..9887359a502bde33d029e26407abb17d0ecf379c 100644 (file)
@@ -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[];
index fd25f8cdc982650d3e923b629d9c87ac1b454e80..c59fbbdbcb473e34dd0a0bcab9d9ef947503aa5a 100644 (file)
@@ -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).