Merge pull request #3184 from atom/windows-background-color
Make background-color work on Windows
This commit is contained in:
commit
90e3f726e4
9 changed files with 33 additions and 7 deletions
|
@ -385,6 +385,10 @@ bool Window::IsKiosk() {
|
||||||
return window_->IsKiosk();
|
return window_->IsKiosk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::SetBackgroundColor(const std::string& color_name) {
|
||||||
|
window_->SetBackgroundColor(color_name);
|
||||||
|
}
|
||||||
|
|
||||||
void Window::FocusOnWebView() {
|
void Window::FocusOnWebView() {
|
||||||
window_->FocusOnWebView();
|
window_->FocusOnWebView();
|
||||||
}
|
}
|
||||||
|
@ -564,6 +568,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
|
||||||
.SetMethod("setSkipTaskbar", &Window::SetSkipTaskbar)
|
.SetMethod("setSkipTaskbar", &Window::SetSkipTaskbar)
|
||||||
.SetMethod("setKiosk", &Window::SetKiosk)
|
.SetMethod("setKiosk", &Window::SetKiosk)
|
||||||
.SetMethod("isKiosk", &Window::IsKiosk)
|
.SetMethod("isKiosk", &Window::IsKiosk)
|
||||||
|
.SetMethod("setBackgroundColor", &Window::SetBackgroundColor)
|
||||||
.SetMethod("setRepresentedFilename", &Window::SetRepresentedFilename)
|
.SetMethod("setRepresentedFilename", &Window::SetRepresentedFilename)
|
||||||
.SetMethod("getRepresentedFilename", &Window::GetRepresentedFilename)
|
.SetMethod("getRepresentedFilename", &Window::GetRepresentedFilename)
|
||||||
.SetMethod("setDocumentEdited", &Window::SetDocumentEdited)
|
.SetMethod("setDocumentEdited", &Window::SetDocumentEdited)
|
||||||
|
|
|
@ -122,6 +122,7 @@ class Window : public mate::TrackableObject<Window>,
|
||||||
void SetSkipTaskbar(bool skip);
|
void SetSkipTaskbar(bool skip);
|
||||||
void SetKiosk(bool kiosk);
|
void SetKiosk(bool kiosk);
|
||||||
bool IsKiosk();
|
bool IsKiosk();
|
||||||
|
void SetBackgroundColor(const std::string& color_name);
|
||||||
void FocusOnWebView();
|
void FocusOnWebView();
|
||||||
void BlurWebView();
|
void BlurWebView();
|
||||||
bool IsWebViewFocused();
|
bool IsWebViewFocused();
|
||||||
|
|
|
@ -139,6 +139,10 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
|
||||||
if (options.Get(switches::kKiosk, &kiosk) && kiosk) {
|
if (options.Get(switches::kKiosk, &kiosk) && kiosk) {
|
||||||
SetKiosk(kiosk);
|
SetKiosk(kiosk);
|
||||||
}
|
}
|
||||||
|
std::string color;
|
||||||
|
if (options.Get(switches::kBackgroundColor, &color)) {
|
||||||
|
SetBackgroundColor(color);
|
||||||
|
}
|
||||||
std::string title("Electron");
|
std::string title("Electron");
|
||||||
options.Get(switches::kTitle, &title);
|
options.Get(switches::kTitle, &title);
|
||||||
SetTitle(title);
|
SetTitle(title);
|
||||||
|
|
|
@ -134,6 +134,7 @@ class NativeWindow : public base::SupportsUserData,
|
||||||
virtual void SetSkipTaskbar(bool skip) = 0;
|
virtual void SetSkipTaskbar(bool skip) = 0;
|
||||||
virtual void SetKiosk(bool kiosk) = 0;
|
virtual void SetKiosk(bool kiosk) = 0;
|
||||||
virtual bool IsKiosk() = 0;
|
virtual bool IsKiosk() = 0;
|
||||||
|
virtual void SetBackgroundColor(const std::string& color_name) = 0;
|
||||||
virtual void SetRepresentedFilename(const std::string& filename);
|
virtual void SetRepresentedFilename(const std::string& filename);
|
||||||
virtual std::string GetRepresentedFilename();
|
virtual std::string GetRepresentedFilename();
|
||||||
virtual void SetDocumentEdited(bool edited);
|
virtual void SetDocumentEdited(bool edited);
|
||||||
|
|
|
@ -57,6 +57,7 @@ class NativeWindowMac : public NativeWindow {
|
||||||
void SetSkipTaskbar(bool skip) override;
|
void SetSkipTaskbar(bool skip) override;
|
||||||
void SetKiosk(bool kiosk) override;
|
void SetKiosk(bool kiosk) override;
|
||||||
bool IsKiosk() override;
|
bool IsKiosk() override;
|
||||||
|
void SetBackgroundColor(const std::string& color_name) override;
|
||||||
void SetRepresentedFilename(const std::string& filename) override;
|
void SetRepresentedFilename(const std::string& filename) override;
|
||||||
std::string GetRepresentedFilename() override;
|
std::string GetRepresentedFilename() override;
|
||||||
void SetDocumentEdited(bool edited) override;
|
void SetDocumentEdited(bool edited) override;
|
||||||
|
|
|
@ -635,6 +635,9 @@ bool NativeWindowMac::IsKiosk() {
|
||||||
return is_kiosk_;
|
return is_kiosk_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeWindowMac::SetBackgroundColor(const std::string& color_name) {
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindowMac::SetRepresentedFilename(const std::string& filename) {
|
void NativeWindowMac::SetRepresentedFilename(const std::string& filename) {
|
||||||
[window_ setRepresentedFilename:base::SysUTF8ToNSString(filename)];
|
[window_ setRepresentedFilename:base::SysUTF8ToNSString(filename)];
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#elif defined(OS_WIN)
|
#elif defined(OS_WIN)
|
||||||
#include "atom/browser/ui/views/win_frame_view.h"
|
#include "atom/browser/ui/views/win_frame_view.h"
|
||||||
#include "atom/browser/ui/win/atom_desktop_window_tree_host_win.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/base/win/shell.h"
|
||||||
#include "ui/gfx/win/dpi.h"
|
#include "ui/gfx/win/dpi.h"
|
||||||
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
|
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
|
||||||
|
@ -229,12 +230,6 @@ NativeWindowViews::NativeWindowViews(
|
||||||
// Add web view.
|
// Add web view.
|
||||||
SetLayoutManager(new MenuLayout(this, kMenuBarHeight));
|
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)));
|
|
||||||
|
|
||||||
AddChildView(web_view_);
|
AddChildView(web_view_);
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
|
@ -525,6 +520,21 @@ bool NativeWindowViews::IsKiosk() {
|
||||||
return IsFullscreen();
|
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) {
|
void NativeWindowViews::SetMenu(ui::MenuModel* menu_model) {
|
||||||
if (menu_model == nullptr) {
|
if (menu_model == nullptr) {
|
||||||
// Remove accelerators
|
// Remove accelerators
|
||||||
|
|
|
@ -77,6 +77,7 @@ class NativeWindowViews : public NativeWindow,
|
||||||
void SetSkipTaskbar(bool skip) override;
|
void SetSkipTaskbar(bool skip) override;
|
||||||
void SetKiosk(bool kiosk) override;
|
void SetKiosk(bool kiosk) override;
|
||||||
bool IsKiosk() override;
|
bool IsKiosk() override;
|
||||||
|
void SetBackgroundColor(const std::string& color_name) override;
|
||||||
void SetMenu(ui::MenuModel* menu_model) override;
|
void SetMenu(ui::MenuModel* menu_model) override;
|
||||||
gfx::NativeWindow GetNativeWindow() override;
|
gfx::NativeWindow GetNativeWindow() override;
|
||||||
void SetOverlayIcon(const gfx::Image& overlay,
|
void SetOverlayIcon(const gfx::Image& overlay,
|
||||||
|
|
|
@ -62,7 +62,7 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
|
||||||
* `enable-larger-than-screen` Boolean - Enable the window to be resized larger
|
* `enable-larger-than-screen` Boolean - Enable the window to be resized larger
|
||||||
than screen.
|
than screen.
|
||||||
* `background-color` String - Window's background color as Hexadecimal value,
|
* `background-color` String - Window's background color as Hexadecimal value,
|
||||||
like `#66CD00` or `#FFF`. This is only implemented on Linux.
|
like `#66CD00` or `#FFF`. This is only implemented on Linux and Windows.
|
||||||
* `dark-theme` Boolean - Forces using dark theme for the window, only works on
|
* `dark-theme` Boolean - Forces using dark theme for the window, only works on
|
||||||
some GTK+3 desktop environments.
|
some GTK+3 desktop environments.
|
||||||
* `transparent` Boolean - Makes the window [transparent](frameless-window.md).
|
* `transparent` Boolean - Makes the window [transparent](frameless-window.md).
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue