Add BrowserWindow.getOpacity for consistency
This commit is contained in:
parent
7df5182901
commit
7570ec9d39
9 changed files with 29 additions and 2 deletions
|
@ -635,6 +635,10 @@ void Window::SetOpacity(const double opacity) {
|
||||||
window_->SetOpacity(opacity);
|
window_->SetOpacity(opacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double Window::GetOpacity() {
|
||||||
|
return window_->GetOpacity();
|
||||||
|
}
|
||||||
|
|
||||||
void Window::FocusOnWebView() {
|
void Window::FocusOnWebView() {
|
||||||
window_->FocusOnWebView();
|
window_->FocusOnWebView();
|
||||||
}
|
}
|
||||||
|
@ -1061,6 +1065,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
|
||||||
.SetMethod("setHasShadow", &Window::SetHasShadow)
|
.SetMethod("setHasShadow", &Window::SetHasShadow)
|
||||||
.SetMethod("hasShadow", &Window::HasShadow)
|
.SetMethod("hasShadow", &Window::HasShadow)
|
||||||
.SetMethod("setOpacity", &Window::SetOpacity)
|
.SetMethod("setOpacity", &Window::SetOpacity)
|
||||||
|
.SetMethod("getOpacity", &Window::GetOpacity)
|
||||||
.SetMethod("setRepresentedFilename", &Window::SetRepresentedFilename)
|
.SetMethod("setRepresentedFilename", &Window::SetRepresentedFilename)
|
||||||
.SetMethod("getRepresentedFilename", &Window::GetRepresentedFilename)
|
.SetMethod("getRepresentedFilename", &Window::GetRepresentedFilename)
|
||||||
.SetMethod("setDocumentEdited", &Window::SetDocumentEdited)
|
.SetMethod("setDocumentEdited", &Window::SetDocumentEdited)
|
||||||
|
|
|
@ -162,6 +162,7 @@ class Window : public mate::TrackableObject<Window>,
|
||||||
void SetHasShadow(bool has_shadow);
|
void SetHasShadow(bool has_shadow);
|
||||||
bool HasShadow();
|
bool HasShadow();
|
||||||
void SetOpacity(const double opacity);
|
void SetOpacity(const double opacity);
|
||||||
|
double GetOpacity();
|
||||||
void FocusOnWebView();
|
void FocusOnWebView();
|
||||||
void BlurWebView();
|
void BlurWebView();
|
||||||
bool IsWebViewFocused();
|
bool IsWebViewFocused();
|
||||||
|
|
|
@ -142,6 +142,7 @@ class NativeWindow : public base::SupportsUserData,
|
||||||
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;
|
||||||
|
virtual double GetOpacity() = 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);
|
||||||
|
|
|
@ -84,6 +84,7 @@ class NativeWindowMac : public NativeWindow,
|
||||||
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;
|
||||||
|
double GetOpacity() 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;
|
||||||
|
|
|
@ -1507,6 +1507,10 @@ void NativeWindowMac::SetOpacity(const double opacity) {
|
||||||
[window_ setAlphaValue:opacity];
|
[window_ setAlphaValue:opacity];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double NativeWindowMac::GetOpacity() {
|
||||||
|
return [window_ alphaValue];
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindowMac::SetRepresentedFilename(const std::string& filename) {
|
void NativeWindowMac::SetRepresentedFilename(const std::string& filename) {
|
||||||
[window_ setRepresentedFilename:base::SysUTF8ToNSString(filename)];
|
[window_ setRepresentedFilename:base::SysUTF8ToNSString(filename)];
|
||||||
}
|
}
|
||||||
|
|
|
@ -825,6 +825,11 @@ void NativeWindowViews::SetOpacity(const double opacity) {
|
||||||
}
|
}
|
||||||
::SetLayeredWindowAttributes(hwnd, 0, opacity * 255, LWA_ALPHA);
|
::SetLayeredWindowAttributes(hwnd, 0, opacity * 255, LWA_ALPHA);
|
||||||
#endif
|
#endif
|
||||||
|
opacity_ = opacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
double NativeWindowViews::GetOpacity() {
|
||||||
|
return opacity_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowViews::SetIgnoreMouseEvents(bool ignore, bool forward) {
|
void NativeWindowViews::SetIgnoreMouseEvents(bool ignore, bool forward) {
|
||||||
|
|
|
@ -105,6 +105,7 @@ class NativeWindowViews : public NativeWindow,
|
||||||
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;
|
||||||
|
double GetOpacity() override;
|
||||||
void SetIgnoreMouseEvents(bool ignore, bool forward) override;
|
void SetIgnoreMouseEvents(bool ignore, bool forward) override;
|
||||||
void SetContentProtection(bool enable) override;
|
void SetContentProtection(bool enable) override;
|
||||||
void SetFocusable(bool focusable) override;
|
void SetFocusable(bool focusable) override;
|
||||||
|
@ -295,6 +296,7 @@ class NativeWindowViews : public NativeWindow,
|
||||||
bool fullscreenable_;
|
bool fullscreenable_;
|
||||||
std::string title_;
|
std::string title_;
|
||||||
gfx::Size widget_size_;
|
gfx::Size widget_size_;
|
||||||
|
double opacity_ = 1.0;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(NativeWindowViews);
|
DISALLOW_COPY_AND_ASSIGN(NativeWindowViews);
|
||||||
};
|
};
|
||||||
|
|
|
@ -205,7 +205,7 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
|
||||||
`#FFF` (white).
|
`#FFF` (white).
|
||||||
* `hasShadow` Boolean (optional) - Whether window should have a shadow. This is only
|
* `hasShadow` Boolean (optional) - Whether window should have a shadow. This is only
|
||||||
implemented on macOS. Default is `true`.
|
implemented on macOS. Default is `true`.
|
||||||
* `opacity` Double (optional) - Set the initial opacity of the window, between 0.0 (fully
|
* `opacity` Number (optional) - Set the initial opacity of the window, between 0.0 (fully
|
||||||
transparent) and 1.0 (fully opaque). This is only implemented on Windows and macOS.
|
transparent) and 1.0 (fully opaque). This is only implemented on Windows and macOS.
|
||||||
* `darkTheme` Boolean (optional) - Forces using dark theme for the window, only works on
|
* `darkTheme` Boolean (optional) - 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`.
|
||||||
|
@ -1210,10 +1210,14 @@ On Windows and Linux always returns
|
||||||
|
|
||||||
#### `win.setOpacity(opacity)` _Windows_ _macOS_
|
#### `win.setOpacity(opacity)` _Windows_ _macOS_
|
||||||
|
|
||||||
* `opacity` Double - between 0.0 (fully transparent) and 1.0 (fully opaque)
|
* `opacity` Number - between 0.0 (fully transparent) and 1.0 (fully opaque)
|
||||||
|
|
||||||
Sets the opacity of the window. On Linux does nothing.
|
Sets the opacity of the window. On Linux does nothing.
|
||||||
|
|
||||||
|
#### `win.getOpacity()` _Windows_ _macOS_
|
||||||
|
|
||||||
|
Returns `Number` - between 0.0 (fully transparent) and 1.0 (fully opaque)
|
||||||
|
|
||||||
#### `win.setThumbarButtons(buttons)` _Windows_
|
#### `win.setThumbarButtons(buttons)` _Windows_
|
||||||
|
|
||||||
* `buttons` [ThumbarButton[]](structures/thumbar-button.md)
|
* `buttons` [ThumbarButton[]](structures/thumbar-button.md)
|
||||||
|
|
|
@ -804,13 +804,17 @@ describe('BrowserWindow module', function () {
|
||||||
height: 400,
|
height: 400,
|
||||||
opacity: 0.5
|
opacity: 0.5
|
||||||
})
|
})
|
||||||
|
assert.equal(w.getOpacity(), 0.5)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('allows setting the opacity', function () {
|
it('allows setting the opacity', function () {
|
||||||
assert.doesNotThrow(function () {
|
assert.doesNotThrow(function () {
|
||||||
w.setOpacity(0.0)
|
w.setOpacity(0.0)
|
||||||
|
assert.equal(w.getOpacity(), 0.0)
|
||||||
w.setOpacity(0.5)
|
w.setOpacity(0.5)
|
||||||
|
assert.equal(w.getOpacity(), 0.5)
|
||||||
w.setOpacity(1.0)
|
w.setOpacity(1.0)
|
||||||
|
assert.equal(w.getOpacity(), 1.0)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue