feat: add win.getBackgroundColor() for macOS (#21448)
thanks @vbennich - great work on this 🌟
This commit is contained in:
parent
c1210f8ad3
commit
cf833a7650
10 changed files with 46 additions and 1 deletions
|
@ -1019,6 +1019,11 @@ console.log(win.getBounds())
|
||||||
|
|
||||||
Returns [`Rectangle`](structures/rectangle.md) - The `bounds` of the window as `Object`.
|
Returns [`Rectangle`](structures/rectangle.md) - The `bounds` of the window as `Object`.
|
||||||
|
|
||||||
|
#### `win.getBackgroundColor()`
|
||||||
|
|
||||||
|
Returns `String` - Gets the background color of the window. See [Setting
|
||||||
|
`backgroundColor`](#setting-backgroundcolor).
|
||||||
|
|
||||||
#### `win.setContentBounds(bounds[, animate])`
|
#### `win.setContentBounds(bounds[, animate])`
|
||||||
|
|
||||||
* `bounds` [Rectangle](structures/rectangle.md)
|
* `bounds` [Rectangle](structures/rectangle.md)
|
||||||
|
|
|
@ -56,7 +56,6 @@ class BrowserView : public gin_helper::TrackableObject<BrowserView>,
|
||||||
void SetBounds(const gfx::Rect& bounds);
|
void SetBounds(const gfx::Rect& bounds);
|
||||||
gfx::Rect GetBounds();
|
gfx::Rect GetBounds();
|
||||||
void SetBackgroundColor(const std::string& color_name);
|
void SetBackgroundColor(const std::string& color_name);
|
||||||
|
|
||||||
v8::Local<v8::Value> GetWebContents();
|
v8::Local<v8::Value> GetWebContents();
|
||||||
|
|
||||||
v8::Global<v8::Value> web_contents_;
|
v8::Global<v8::Value> web_contents_;
|
||||||
|
|
|
@ -620,6 +620,10 @@ void TopLevelWindow::SetBackgroundColor(const std::string& color_name) {
|
||||||
window_->SetBackgroundColor(color);
|
window_->SetBackgroundColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string TopLevelWindow::GetBackgroundColor() {
|
||||||
|
return ToRGBHex(window_->GetBackgroundColor());
|
||||||
|
}
|
||||||
|
|
||||||
void TopLevelWindow::SetHasShadow(bool has_shadow) {
|
void TopLevelWindow::SetHasShadow(bool has_shadow) {
|
||||||
window_->SetHasShadow(has_shadow);
|
window_->SetHasShadow(has_shadow);
|
||||||
}
|
}
|
||||||
|
@ -1145,6 +1149,7 @@ void TopLevelWindow::BuildPrototype(v8::Isolate* isolate,
|
||||||
.SetMethod("setKiosk", &TopLevelWindow::SetKiosk)
|
.SetMethod("setKiosk", &TopLevelWindow::SetKiosk)
|
||||||
.SetMethod("isKiosk", &TopLevelWindow::IsKiosk)
|
.SetMethod("isKiosk", &TopLevelWindow::IsKiosk)
|
||||||
.SetMethod("setBackgroundColor", &TopLevelWindow::SetBackgroundColor)
|
.SetMethod("setBackgroundColor", &TopLevelWindow::SetBackgroundColor)
|
||||||
|
.SetMethod("getBackgroundColor", &TopLevelWindow::GetBackgroundColor)
|
||||||
.SetMethod("setHasShadow", &TopLevelWindow::SetHasShadow)
|
.SetMethod("setHasShadow", &TopLevelWindow::SetHasShadow)
|
||||||
.SetMethod("hasShadow", &TopLevelWindow::HasShadow)
|
.SetMethod("hasShadow", &TopLevelWindow::HasShadow)
|
||||||
.SetMethod("setOpacity", &TopLevelWindow::SetOpacity)
|
.SetMethod("setOpacity", &TopLevelWindow::SetOpacity)
|
||||||
|
|
|
@ -155,6 +155,7 @@ class TopLevelWindow : public gin_helper::TrackableObject<TopLevelWindow>,
|
||||||
void SetKiosk(bool kiosk);
|
void SetKiosk(bool kiosk);
|
||||||
bool IsKiosk();
|
bool IsKiosk();
|
||||||
virtual void SetBackgroundColor(const std::string& color_name);
|
virtual void SetBackgroundColor(const std::string& color_name);
|
||||||
|
std::string GetBackgroundColor();
|
||||||
void SetHasShadow(bool has_shadow);
|
void SetHasShadow(bool has_shadow);
|
||||||
bool HasShadow();
|
bool HasShadow();
|
||||||
void SetOpacity(const double opacity);
|
void SetOpacity(const double opacity);
|
||||||
|
|
|
@ -149,6 +149,7 @@ class NativeWindow : public base::SupportsUserData,
|
||||||
virtual void SetKiosk(bool kiosk) = 0;
|
virtual void SetKiosk(bool kiosk) = 0;
|
||||||
virtual bool IsKiosk() = 0;
|
virtual bool IsKiosk() = 0;
|
||||||
virtual void SetBackgroundColor(SkColor color) = 0;
|
virtual void SetBackgroundColor(SkColor color) = 0;
|
||||||
|
virtual SkColor GetBackgroundColor() = 0;
|
||||||
virtual void SetHasShadow(bool has_shadow) = 0;
|
virtual void SetHasShadow(bool has_shadow) = 0;
|
||||||
virtual bool HasShadow() = 0;
|
virtual bool HasShadow() = 0;
|
||||||
virtual void SetOpacity(const double opacity) = 0;
|
virtual void SetOpacity(const double opacity) = 0;
|
||||||
|
|
|
@ -93,6 +93,7 @@ class NativeWindowMac : public NativeWindow {
|
||||||
void SetKiosk(bool kiosk) override;
|
void SetKiosk(bool kiosk) override;
|
||||||
bool IsKiosk() override;
|
bool IsKiosk() override;
|
||||||
void SetBackgroundColor(SkColor color) override;
|
void SetBackgroundColor(SkColor color) override;
|
||||||
|
SkColor GetBackgroundColor() override;
|
||||||
void SetHasShadow(bool has_shadow) override;
|
void SetHasShadow(bool has_shadow) override;
|
||||||
bool HasShadow() override;
|
bool HasShadow() override;
|
||||||
void SetOpacity(const double opacity) override;
|
void SetOpacity(const double opacity) override;
|
||||||
|
|
|
@ -1102,6 +1102,11 @@ void NativeWindowMac::SetBackgroundColor(SkColor color) {
|
||||||
[[[window_ contentView] layer] setBackgroundColor:cgcolor];
|
[[[window_ contentView] layer] setBackgroundColor:cgcolor];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SkColor NativeWindowMac::GetBackgroundColor() {
|
||||||
|
return skia::CGColorRefToSkColor(
|
||||||
|
[[[window_ contentView] layer] backgroundColor]);
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindowMac::SetHasShadow(bool has_shadow) {
|
void NativeWindowMac::SetHasShadow(bool has_shadow) {
|
||||||
[window_ setHasShadow:has_shadow];
|
[window_ setHasShadow:has_shadow];
|
||||||
}
|
}
|
||||||
|
|
|
@ -903,6 +903,10 @@ bool NativeWindowViews::IsKiosk() {
|
||||||
return IsFullscreen();
|
return IsFullscreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SkColor NativeWindowViews::GetBackgroundColor() {
|
||||||
|
return root_view_->background()->get_color();
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindowViews::SetBackgroundColor(SkColor background_color) {
|
void NativeWindowViews::SetBackgroundColor(SkColor background_color) {
|
||||||
// web views' background color.
|
// web views' background color.
|
||||||
root_view_->SetBackground(views::CreateSolidBackground(background_color));
|
root_view_->SetBackground(views::CreateSolidBackground(background_color));
|
||||||
|
|
|
@ -66,6 +66,7 @@ class NativeWindowViews : public NativeWindow,
|
||||||
gfx::Rect GetContentBounds() override;
|
gfx::Rect GetContentBounds() override;
|
||||||
gfx::Size GetContentSize() override;
|
gfx::Size GetContentSize() override;
|
||||||
gfx::Rect GetNormalBounds() override;
|
gfx::Rect GetNormalBounds() override;
|
||||||
|
SkColor GetBackgroundColor() override;
|
||||||
void SetContentSizeConstraints(
|
void SetContentSizeConstraints(
|
||||||
const extensions::SizeConstraints& size_constraints) override;
|
const extensions::SizeConstraints& size_constraints) override;
|
||||||
void SetResizable(bool resizable) override;
|
void SetResizable(bool resizable) override;
|
||||||
|
|
|
@ -834,6 +834,29 @@ describe('BrowserWindow module', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('BrowserWindow.getBackgroundColor()', () => {
|
||||||
|
it('returns default value if no backgroundColor is set', () => {
|
||||||
|
w.destroy()
|
||||||
|
w = new BrowserWindow({})
|
||||||
|
expect(w.getBackgroundColor()).to.equal('#FFFFFF')
|
||||||
|
})
|
||||||
|
it('returns correct value if backgroundColor is set', () => {
|
||||||
|
const backgroundColor = '#BBAAFF'
|
||||||
|
w.destroy()
|
||||||
|
w = new BrowserWindow({
|
||||||
|
backgroundColor: backgroundColor
|
||||||
|
})
|
||||||
|
expect(w.getBackgroundColor()).to.equal(backgroundColor)
|
||||||
|
})
|
||||||
|
it('returns correct value from setBackgroundColor()', () => {
|
||||||
|
const backgroundColor = '#AABBFF'
|
||||||
|
w.destroy()
|
||||||
|
w = new BrowserWindow({})
|
||||||
|
w.setBackgroundColor(backgroundColor)
|
||||||
|
expect(w.getBackgroundColor()).to.equal(backgroundColor)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe(`BrowserWindow.getNormalBounds()`, () => {
|
describe(`BrowserWindow.getNormalBounds()`, () => {
|
||||||
describe(`Normal state`, () => {
|
describe(`Normal state`, () => {
|
||||||
it(`checks normal bounds after resize`, (done) => {
|
it(`checks normal bounds after resize`, (done) => {
|
||||||
|
|
Loading…
Reference in a new issue