feat: add evt listeners for SetAlwaysOnTop (#14951)

* feat: add evt listeners for SetAlwaysOnTop

* only emit one event on AlwaysOnTop change

* docs: add new alwaysontop event

* dont emit if theres no change

* address feedback from review
This commit is contained in:
Shelley Vohr 2018-10-04 11:02:16 -07:00 committed by Charles Kerr
parent d810f08b75
commit 27bbf6a3c6
7 changed files with 24 additions and 0 deletions

View file

@ -262,6 +262,10 @@ void TopLevelWindow::OnWindowLeaveHtmlFullScreen() {
Emit("leave-html-full-screen");
}
void TopLevelWindow::OnWindowAlwaysOnTopChanged() {
Emit("always-on-top-changed", IsAlwaysOnTop());
}
void TopLevelWindow::OnExecuteWindowsCommand(const std::string& command_name) {
Emit("app-command", command_name);
}

View file

@ -77,6 +77,7 @@ class TopLevelWindow : public mate::TrackableObject<TopLevelWindow>,
void OnWindowLeaveFullScreen() override;
void OnWindowEnterHtmlFullScreen() override;
void OnWindowLeaveHtmlFullScreen() override;
void OnWindowAlwaysOnTopChanged() override;
void OnExecuteWindowsCommand(const std::string& command_name) override;
void OnTouchBarItemResult(const std::string& item_id,
const base::DictionaryValue& details) override;

View file

@ -537,6 +537,11 @@ void NativeWindow::NotifyWindowLeaveHtmlFullScreen() {
observer.OnWindowLeaveHtmlFullScreen();
}
void NativeWindow::NotifyWindowAlwaysOnTopChanged() {
for (NativeWindowObserver& observer : observers_)
observer.OnWindowAlwaysOnTopChanged();
}
void NativeWindow::NotifyWindowExecuteWindowsCommand(
const std::string& command) {
for (NativeWindowObserver& observer : observers_)

View file

@ -254,6 +254,7 @@ class NativeWindow : public base::SupportsUserData,
void NotifyWindowLeaveFullScreen();
void NotifyWindowEnterHtmlFullScreen();
void NotifyWindowLeaveHtmlFullScreen();
void NotifyWindowAlwaysOnTopChanged();
void NotifyWindowExecuteWindowsCommand(const std::string& command);
void NotifyTouchBarItemInteraction(const std::string& item_id,
const base::DictionaryValue& details);

View file

@ -83,6 +83,7 @@ class NativeWindowObserver {
virtual void OnWindowLeaveFullScreen() {}
virtual void OnWindowEnterHtmlFullScreen() {}
virtual void OnWindowLeaveHtmlFullScreen() {}
virtual void OnWindowAlwaysOnTopChanged() {}
virtual void OnTouchBarItemResult(const std::string& item_id,
const base::DictionaryValue& details) {}
virtual void OnNewWindowForTab() {}

View file

@ -706,6 +706,9 @@ void NativeWindowViews::SetAlwaysOnTop(bool top,
const std::string& level,
int relativeLevel,
std::string* error) {
if (top != widget()->IsAlwaysOnTop())
NativeWindow::NotifyWindowAlwaysOnTopChanged();
widget()->SetAlwaysOnTop(top);
}

View file

@ -542,6 +542,15 @@ Emitted when the window enters a full-screen state triggered by HTML API.
Emitted when the window leaves a full-screen state triggered by HTML API.
#### Event: 'always-on-top-changed' _macOS_
Returns:
* `event` Event
* `isAlwaysOnTop` Boolean
Emitted when the window is set or unset to show always on top of other windows.
#### Event: 'app-command' _Windows_
Returns: