]> khamidou — GitHub mirrors - electron.git/commitdiff
win: Set native window's background color
authorCheng Zhao <zcbenz@gmail.com>
Fri, 23 Oct 2015 03:17:14 +0000 (11:17 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 23 Oct 2015 03:17:14 +0000 (11:17 +0800)
atom/browser/native_window_views.cc

index 1e4207bf0c6f0efc29fe4084d98aef852f54a715..ab4df82df75dd5acff5fa1b5c17fa90c4da63232 100644 (file)
@@ -42,6 +42,7 @@
 #elif defined(OS_WIN)
 #include "atom/browser/ui/views/win_frame_view.h"
 #include "atom/browser/ui/win/atom_desktop_window_tree_host_win.h"
+#include "skia/ext/skia_utils_win.h"
 #include "ui/base/win/shell.h"
 #include "ui/gfx/win/dpi.h"
 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
@@ -230,14 +231,22 @@ NativeWindowViews::NativeWindowViews(
   SetLayoutManager(new MenuLayout(this, kMenuBarHeight));
 
   // web views' background color.
-  std::string background_color = "#fff";
-  options.Get(switches::kBackgroundColor, &background_color);
-  set_background(views::Background::CreateSolidBackground(
-      ParseHexColor(background_color)));
+  SkColor background_color = SK_ColorWHITE;
+  std::string color_name;
+  if (options.Get(switches::kBackgroundColor, &color_name))
+    background_color = ParseHexColor(color_name);
+  set_background(views::Background::CreateSolidBackground(background_color));
 
   AddChildView(web_view_);
 
 #if defined(OS_WIN)
+  // Set the background color of native window.
+  HBRUSH brush = CreateSolidBrush(skia::SkColorToCOLORREF(background_color));
+  ULONG_PTR previous_brush = SetClassLongPtr(
+      GetAcceleratedWidget(), GCLP_HBRBACKGROUND, (LONG)brush);
+  if (previous_brush)
+    DeleteObject((HBRUSH)previous_brush);
+
   // Save initial window state.
   if (fullscreen)
     last_window_state_ = ui::SHOW_STATE_FULLSCREEN;