Merge pull request #3168 from deepak1556/window_background_color_patch
browser: option to set window background color
This commit is contained in:
commit
15e0248d82
4 changed files with 41 additions and 1 deletions
|
@ -77,6 +77,29 @@ bool IsAltModifier(const content::NativeWebKeyboardEvent& event) {
|
||||||
(modifiers == (Modifiers::AltKey | Modifiers::IsRight));
|
(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 {
|
class NativeWindowClientView : public views::ClientView {
|
||||||
public:
|
public:
|
||||||
NativeWindowClientView(views::Widget* widget,
|
NativeWindowClientView(views::Widget* widget,
|
||||||
|
@ -205,7 +228,13 @@ NativeWindowViews::NativeWindowViews(
|
||||||
|
|
||||||
// Add web view.
|
// Add web view.
|
||||||
SetLayoutManager(new MenuLayout(this, kMenuBarHeight));
|
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_);
|
AddChildView(web_view_);
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
|
|
|
@ -93,6 +93,9 @@ const char kDisableAutoHideCursor[] = "disable-auto-hide-cursor";
|
||||||
// Use the OS X's standard window instead of the textured window.
|
// Use the OS X's standard window instead of the textured window.
|
||||||
const char kStandardWindow[] = "standard-window";
|
const char kStandardWindow[] = "standard-window";
|
||||||
|
|
||||||
|
// Default browser window background color.
|
||||||
|
const char kBackgroundColor[] = "background-color";
|
||||||
|
|
||||||
// Path to client certificate.
|
// Path to client certificate.
|
||||||
const char kClientCertificate[] = "client-certificate";
|
const char kClientCertificate[] = "client-certificate";
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@ extern const char kTransparent[];
|
||||||
extern const char kType[];
|
extern const char kType[];
|
||||||
extern const char kDisableAutoHideCursor[];
|
extern const char kDisableAutoHideCursor[];
|
||||||
extern const char kStandardWindow[];
|
extern const char kStandardWindow[];
|
||||||
|
extern const char kBackgroundColor[];
|
||||||
extern const char kClientCertificate[];
|
extern const char kClientCertificate[];
|
||||||
|
|
||||||
extern const char kExperimentalFeatures[];
|
extern const char kExperimentalFeatures[];
|
||||||
|
|
|
@ -61,6 +61,13 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
|
||||||
key is pressed.
|
key is pressed.
|
||||||
* `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.
|
||||||
|
```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
|
* `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