Support backgroundColor for window on mac
This commit is contained in:
parent
1b0da44f38
commit
239baa3e9a
5 changed files with 36 additions and 27 deletions
|
@ -551,4 +551,27 @@ void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback,
|
||||||
callback.Run(bitmap);
|
callback.Run(bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SkColor NativeWindow::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;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -265,6 +265,9 @@ class NativeWindow : public base::SupportsUserData,
|
||||||
void BeforeUnloadDialogCancelled() override;
|
void BeforeUnloadDialogCancelled() override;
|
||||||
bool OnMessageReceived(const IPC::Message& message) override;
|
bool OnMessageReceived(const IPC::Message& message) override;
|
||||||
|
|
||||||
|
// Parse hex color like "#FFF" or "#EFEFEF"
|
||||||
|
SkColor ParseHexColor(const std::string& name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Schedule a notification unresponsive event.
|
// Schedule a notification unresponsive event.
|
||||||
void ScheduleUnresponsiveEvent(int ms);
|
void ScheduleUnresponsiveEvent(int ms);
|
||||||
|
|
|
@ -418,7 +418,7 @@ NativeWindowMac::NativeWindowMac(
|
||||||
if (transparent()) {
|
if (transparent()) {
|
||||||
// Make window has transparent background.
|
// Make window has transparent background.
|
||||||
[window_ setOpaque:NO];
|
[window_ setOpaque:NO];
|
||||||
[window_ setHasShadow:NO];
|
// Setting the background color to clear will also hide the shadow.
|
||||||
[window_ setBackgroundColor:[NSColor clearColor]];
|
[window_ setBackgroundColor:[NSColor clearColor]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -706,6 +706,12 @@ bool NativeWindowMac::IsKiosk() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::SetBackgroundColor(const std::string& color_name) {
|
void NativeWindowMac::SetBackgroundColor(const std::string& color_name) {
|
||||||
|
SkColor background_color = NativeWindow::ParseHexColor(color_name);
|
||||||
|
NSColor *color = [NSColor colorWithCalibratedRed:SkColorGetR(background_color)
|
||||||
|
green:SkColorGetG(background_color)
|
||||||
|
blue:SkColorGetB(background_color)
|
||||||
|
alpha:1.0];
|
||||||
|
[window_ setBackgroundColor:color];
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::SetRepresentedFilename(const std::string& filename) {
|
void NativeWindowMac::SetRepresentedFilename(const std::string& filename) {
|
||||||
|
|
|
@ -73,29 +73,6 @@ 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,
|
||||||
|
@ -519,7 +496,7 @@ bool NativeWindowViews::IsKiosk() {
|
||||||
|
|
||||||
void NativeWindowViews::SetBackgroundColor(const std::string& color_name) {
|
void NativeWindowViews::SetBackgroundColor(const std::string& color_name) {
|
||||||
// web views' background color.
|
// web views' background color.
|
||||||
SkColor background_color = ParseHexColor(color_name);
|
SkColor background_color = NativeWindow::ParseHexColor(color_name);
|
||||||
set_background(views::Background::CreateSolidBackground(background_color));
|
set_background(views::Background::CreateSolidBackground(background_color));
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
|
|
|
@ -74,8 +74,8 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
|
||||||
* `enableLargerThanScreen` Boolean - Enable the window to be resized larger
|
* `enableLargerThanScreen` Boolean - Enable the window to be resized larger
|
||||||
than screen. Default is `false`.
|
than screen. Default is `false`.
|
||||||
* `backgroundColor` String - Window's background color as Hexadecimal value,
|
* `backgroundColor` String - Window's background color as Hexadecimal value,
|
||||||
like `#66CD00` or `#FFF`. This is only implemented on Linux and Windows.
|
like `#66CD00` or `#FFF`. Default is `#000` (black) for Linux and Windows,
|
||||||
Default is `#000` (black).
|
`#FFF` for Mac (or clear if transparent).
|
||||||
* `darkTheme` Boolean - Forces using dark theme for the window, only works on
|
* `darkTheme` Boolean - Forces using dark theme for the window, only works on
|
||||||
some GTK+3 desktop environments. Default is `false`.
|
some GTK+3 desktop environments. Default is `false`.
|
||||||
* `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