browser: option to set window background color

This commit is contained in:
Robo 2015-10-21 15:47:28 +05:30
parent 73f4aa1113
commit 9411508d3e
4 changed files with 41 additions and 1 deletions

View 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)

View 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";

View 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[];

View 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).