]> khamidou — GitHub mirrors - electron.git/commitdiff
Add setBackgroundColor method
authorCheng Zhao <zcbenz@gmail.com>
Fri, 23 Oct 2015 03:35:33 +0000 (11:35 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 23 Oct 2015 03:35:33 +0000 (11:35 +0800)
atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h
atom/browser/native_window.cc
atom/browser/native_window.h
atom/browser/native_window_mac.h
atom/browser/native_window_mac.mm
atom/browser/native_window_views.cc
atom/browser/native_window_views.h

index c4beaace67285cfe1ded02f57c93dd0fa95c38b5..62994c9c93d417c04c4a1f6b15d4aebef26615e9 100644 (file)
@@ -385,6 +385,10 @@ bool Window::IsKiosk() {
   return window_->IsKiosk();
 }
 
+void Window::SetBackgroundColor(const std::string& color_name) {
+  window_->SetBackgroundColor(color_name);
+}
+
 void Window::FocusOnWebView() {
   window_->FocusOnWebView();
 }
@@ -564,6 +568,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
       .SetMethod("setSkipTaskbar", &Window::SetSkipTaskbar)
       .SetMethod("setKiosk", &Window::SetKiosk)
       .SetMethod("isKiosk", &Window::IsKiosk)
+      .SetMethod("setBackgroundColor", &Window::SetBackgroundColor)
       .SetMethod("setRepresentedFilename", &Window::SetRepresentedFilename)
       .SetMethod("getRepresentedFilename", &Window::GetRepresentedFilename)
       .SetMethod("setDocumentEdited", &Window::SetDocumentEdited)
index d2886b5fac9476925fa86a99ddf5140b78eff18c..8a8ff266a883306bc3f5cd5df934a9bd205e4ce3 100644 (file)
@@ -122,6 +122,7 @@ class Window : public mate::TrackableObject<Window>,
   void SetSkipTaskbar(bool skip);
   void SetKiosk(bool kiosk);
   bool IsKiosk();
+  void SetBackgroundColor(const std::string& color_name);
   void FocusOnWebView();
   void BlurWebView();
   bool IsWebViewFocused();
index 8f3af83885f17280cc2b7add58c02e29c053172c..c19bcdf467f3948e04f0d905a6499a55069c1a46 100644 (file)
@@ -139,6 +139,10 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
   if (options.Get(switches::kKiosk, &kiosk) && kiosk) {
     SetKiosk(kiosk);
   }
+  std::string color;
+  if (options.Get(switches::kBackgroundColor, &color)) {
+    SetBackgroundColor(color);
+  }
   std::string title("Electron");
   options.Get(switches::kTitle, &title);
   SetTitle(title);
index 67bac88f32d45a3c9274f32b4ea33c47326fd884..37a59ff8a9e4361ed4a0e709c8174dae1af1550f 100644 (file)
@@ -134,6 +134,7 @@ class NativeWindow : public base::SupportsUserData,
   virtual void SetSkipTaskbar(bool skip) = 0;
   virtual void SetKiosk(bool kiosk) = 0;
   virtual bool IsKiosk() = 0;
+  virtual void SetBackgroundColor(const std::string& color_name) = 0;
   virtual void SetRepresentedFilename(const std::string& filename);
   virtual std::string GetRepresentedFilename();
   virtual void SetDocumentEdited(bool edited);
index 7a97032d75ff042f27b91bd24ee35110a43c4208..08f9198e4ff1c9b7dccc303387a238f2af7f37d7 100644 (file)
@@ -57,6 +57,7 @@ class NativeWindowMac : public NativeWindow {
   void SetSkipTaskbar(bool skip) override;
   void SetKiosk(bool kiosk) override;
   bool IsKiosk() override;
+  void SetBackgroundColor(const std::string& color_name) override;
   void SetRepresentedFilename(const std::string& filename) override;
   std::string GetRepresentedFilename() override;
   void SetDocumentEdited(bool edited) override;
index 9724930c4885acf46c30789aa3203ac5acecebd3..28c8a5ae59a0814ec8a05f9294ab32d222ab7273 100644 (file)
@@ -635,6 +635,9 @@ bool NativeWindowMac::IsKiosk() {
   return is_kiosk_;
 }
 
+void NativeWindowMac::SetBackgroundColor(const std::string& color_name) {
+}
+
 void NativeWindowMac::SetRepresentedFilename(const std::string& filename) {
   [window_ setRepresentedFilename:base::SysUTF8ToNSString(filename)];
 }
index ab4df82df75dd5acff5fa1b5c17fa90c4da63232..876058789d0f6863becf63f4eed8524baf45b466 100644 (file)
@@ -230,23 +230,9 @@ NativeWindowViews::NativeWindowViews(
   // Add web view.
   SetLayoutManager(new MenuLayout(this, kMenuBarHeight));
 
-  // web views' 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;
@@ -534,6 +520,21 @@ bool NativeWindowViews::IsKiosk() {
   return IsFullscreen();
 }
 
+void NativeWindowViews::SetBackgroundColor(const std::string& color_name) {
+  // web views' background color.
+  SkColor background_color = ParseHexColor(color_name);
+  set_background(views::Background::CreateSolidBackground(background_color));
+
+#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);
+#endif
+}
+
 void NativeWindowViews::SetMenu(ui::MenuModel* menu_model) {
   if (menu_model == nullptr) {
     // Remove accelerators
index 0014acd073c172fc904668faeeb697325eb1af35..6c47c74331d009c3c81c93a6906a1f7243b6695b 100644 (file)
@@ -77,6 +77,7 @@ class NativeWindowViews : public NativeWindow,
   void SetSkipTaskbar(bool skip) override;
   void SetKiosk(bool kiosk) override;
   bool IsKiosk() override;
+  void SetBackgroundColor(const std::string& color_name) override;
   void SetMenu(ui::MenuModel* menu_model) override;
   gfx::NativeWindow GetNativeWindow() override;
   void SetOverlayIcon(const gfx::Image& overlay,