Add BrowserWindow.setAutoHideCursor for macOS
The `disableAutoHideCursor` BrowserWindow option can be used to control auto-hiding behavior when the window is created. This new API is needed to dynamically change the behavior after the fact.
This commit is contained in:
parent
fb74f5576d
commit
18c49285a8
8 changed files with 45 additions and 0 deletions
|
@ -811,6 +811,10 @@ bool Window::IsVisibleOnAllWorkspaces() {
|
||||||
return window_->IsVisibleOnAllWorkspaces();
|
return window_->IsVisibleOnAllWorkspaces();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::SetAutoHideCursor(bool auto_hide) {
|
||||||
|
window_->SetAutoHideCursor(auto_hide);
|
||||||
|
}
|
||||||
|
|
||||||
void Window::SetVibrancy(mate::Arguments* args) {
|
void Window::SetVibrancy(mate::Arguments* args) {
|
||||||
std::string type;
|
std::string type;
|
||||||
|
|
||||||
|
@ -934,6 +938,9 @@ void Window::BuildPrototype(v8::Isolate* isolate,
|
||||||
&Window::SetVisibleOnAllWorkspaces)
|
&Window::SetVisibleOnAllWorkspaces)
|
||||||
.SetMethod("isVisibleOnAllWorkspaces",
|
.SetMethod("isVisibleOnAllWorkspaces",
|
||||||
&Window::IsVisibleOnAllWorkspaces)
|
&Window::IsVisibleOnAllWorkspaces)
|
||||||
|
#if defined(OS_MACOSX)
|
||||||
|
.SetMethod("setAutoHideCursor", &Window::SetAutoHideCursor)
|
||||||
|
#endif
|
||||||
.SetMethod("setVibrancy", &Window::SetVibrancy)
|
.SetMethod("setVibrancy", &Window::SetVibrancy)
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
.SetMethod("hookWindowMessage", &Window::HookWindowMessage)
|
.SetMethod("hookWindowMessage", &Window::HookWindowMessage)
|
||||||
|
|
|
@ -198,6 +198,8 @@ class Window : public mate::TrackableObject<Window>,
|
||||||
void SetVisibleOnAllWorkspaces(bool visible);
|
void SetVisibleOnAllWorkspaces(bool visible);
|
||||||
bool IsVisibleOnAllWorkspaces();
|
bool IsVisibleOnAllWorkspaces();
|
||||||
|
|
||||||
|
void SetAutoHideCursor(bool auto_hide);
|
||||||
|
|
||||||
void SetVibrancy(mate::Arguments* args);
|
void SetVibrancy(mate::Arguments* args);
|
||||||
|
|
||||||
int32_t ID() const;
|
int32_t ID() const;
|
||||||
|
|
|
@ -333,6 +333,9 @@ void NativeWindow::SetParentWindow(NativeWindow* parent) {
|
||||||
parent_ = parent;
|
parent_ = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeWindow::SetAutoHideCursor(bool auto_hide) {
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindow::SetVibrancy(const std::string& filename) {
|
void NativeWindow::SetVibrancy(const std::string& filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -161,6 +161,8 @@ class NativeWindow : public base::SupportsUserData,
|
||||||
virtual void SetVisibleOnAllWorkspaces(bool visible) = 0;
|
virtual void SetVisibleOnAllWorkspaces(bool visible) = 0;
|
||||||
virtual bool IsVisibleOnAllWorkspaces() = 0;
|
virtual bool IsVisibleOnAllWorkspaces() = 0;
|
||||||
|
|
||||||
|
virtual void SetAutoHideCursor(bool auto_hide);
|
||||||
|
|
||||||
// Vibrancy API
|
// Vibrancy API
|
||||||
virtual void SetVibrancy(const std::string& type);
|
virtual void SetVibrancy(const std::string& type);
|
||||||
|
|
||||||
|
|
|
@ -91,8 +91,12 @@ class NativeWindowMac : public NativeWindow,
|
||||||
void SetProgressBar(double progress, const ProgressState state) override;
|
void SetProgressBar(double progress, const ProgressState state) override;
|
||||||
void SetOverlayIcon(const gfx::Image& overlay,
|
void SetOverlayIcon(const gfx::Image& overlay,
|
||||||
const std::string& description) override;
|
const std::string& description) override;
|
||||||
|
|
||||||
void SetVisibleOnAllWorkspaces(bool visible) override;
|
void SetVisibleOnAllWorkspaces(bool visible) override;
|
||||||
bool IsVisibleOnAllWorkspaces() override;
|
bool IsVisibleOnAllWorkspaces() override;
|
||||||
|
|
||||||
|
void SetAutoHideCursor(bool auto_hide);
|
||||||
|
|
||||||
void SetVibrancy(const std::string& type) override;
|
void SetVibrancy(const std::string& type) override;
|
||||||
|
|
||||||
// content::RenderWidgetHost::InputEventObserver:
|
// content::RenderWidgetHost::InputEventObserver:
|
||||||
|
|
|
@ -1255,6 +1255,10 @@ bool NativeWindowMac::IsVisibleOnAllWorkspaces() {
|
||||||
return collectionBehavior & NSWindowCollectionBehaviorCanJoinAllSpaces;
|
return collectionBehavior & NSWindowCollectionBehaviorCanJoinAllSpaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeWindowMac::SetAutoHideCursor(bool auto_hide) {
|
||||||
|
[window_ setDisableAutoHideCursor:!auto_hide];
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindowMac::SetVibrancy(const std::string& type) {
|
void NativeWindowMac::SetVibrancy(const std::string& type) {
|
||||||
if (!base::mac::IsOSYosemiteOrLater()) return;
|
if (!base::mac::IsOSYosemiteOrLater()) return;
|
||||||
|
|
||||||
|
|
|
@ -1218,6 +1218,12 @@ Returns `BrowserWindow` - The parent window.
|
||||||
|
|
||||||
Returns `BrowserWindow[]` - All child windows.
|
Returns `BrowserWindow[]` - All child windows.
|
||||||
|
|
||||||
|
#### `win.setAutoHideCursor(autoHide)` _macOS_
|
||||||
|
|
||||||
|
* `autoHide` Boolean
|
||||||
|
|
||||||
|
Controls whether to hide cursor when typing.
|
||||||
|
|
||||||
#### `win.setVibrancy(type)` _macOS_
|
#### `win.setVibrancy(type)` _macOS_
|
||||||
|
|
||||||
* `type` String - Can be `appearance-based`, `light`, `dark`, `titlebar`,
|
* `type` String - Can be `appearance-based`, `light`, `dark`, `titlebar`,
|
||||||
|
|
|
@ -506,6 +506,23 @@ describe('browser-window module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('BrowserWindow.setAutoHideCursor(autoHide)', () => {
|
||||||
|
if (process.platform !== 'darwin') {
|
||||||
|
it('is not available on non-macOS platforms', () => {
|
||||||
|
assert.ok(!w.setAutoHideCursor)
|
||||||
|
})
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
it('allows changing cursor auto-hiding', () => {
|
||||||
|
assert.doesNotThrow(() => {
|
||||||
|
w.setAutoHideCursor(false)
|
||||||
|
w.setAutoHideCursor(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('BrowserWindow.setVibrancy(type)', function () {
|
describe('BrowserWindow.setVibrancy(type)', function () {
|
||||||
it('allows setting, changing, and removing the vibrancy', function () {
|
it('allows setting, changing, and removing the vibrancy', function () {
|
||||||
assert.doesNotThrow(function () {
|
assert.doesNotThrow(function () {
|
||||||
|
|
Loading…
Add table
Reference in a new issue