Add events to manage sheets of macOS BrowserWindow

This commit is contained in:
Yuya Ochiai 2017-04-04 01:44:26 +09:00
parent 3af50b92ca
commit 75184046f6
8 changed files with 101 additions and 0 deletions

View file

@ -298,6 +298,16 @@ void Window::OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) {
}
#endif
#if defined(OS_MACOSX)
void Window::OnWindowSheetBegin() {
Emit("sheet-begin");
}
void Window::OnWindowSheetEnd() {
Emit("sheet-end");
}
#endif
// static
mate::WrappableBase* Window::New(mate::Arguments* args) {
if (!Browser::Get()->is_ready()) {

View file

@ -93,6 +93,11 @@ class Window : public mate::TrackableObject<Window>,
void OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) override;
#endif
#if defined(OS_MACOSX)
void OnWindowSheetBegin() override;
void OnWindowSheetEnd() override;
#endif
private:
void Init(v8::Isolate* isolate,
v8::Local<v8::Object> wrapper,

View file

@ -590,6 +590,18 @@ void NativeWindow::NotifyWindowMessage(
}
#endif
#if defined(OS_MACOSX)
void NativeWindow::NotifyWindowSheetBegin() {
for (NativeWindowObserver& observer : observers_)
observer.OnWindowSheetBegin();
}
void NativeWindow::NotifyWindowSheetEnd() {
for (NativeWindowObserver& observer : observers_)
observer.OnWindowSheetEnd();
}
#endif
std::unique_ptr<SkRegion> NativeWindow::DraggableRegionsToSkRegion(
const std::vector<DraggableRegion>& regions) {
std::unique_ptr<SkRegion> sk_region(new SkRegion);

View file

@ -245,6 +245,11 @@ class NativeWindow : public base::SupportsUserData,
void NotifyWindowMessage(UINT message, WPARAM w_param, LPARAM l_param);
#endif
#if defined(OS_MACOSX)
void NotifyWindowSheetBegin();
void NotifyWindowSheetEnd();
#endif
void AddObserver(NativeWindowObserver* obs) {
observers_.AddObserver(obs);
}

View file

@ -313,6 +313,14 @@ bool ScopedDisableResize::disable_resize_ = false;
return rect;
}
- (void)windowWillBeginSheet:(NSNotification *)notification {
shell_->NotifyWindowSheetBegin();
}
- (void)windowDidEndSheet:(NSNotification *)notification {
shell_->NotifyWindowSheetEnd();
}
@end
@interface AtomPreviewItem : NSObject <QLPreviewItem>

View file

@ -79,6 +79,11 @@ class NativeWindowObserver {
virtual void OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) {}
#endif
#if defined(OS_MACOSX)
virtual void OnWindowSheetBegin() {}
virtual void OnWindowSheetEnd() {}
#endif
// Called when renderer is hung.
virtual void OnRendererUnresponsive() {}

View file

@ -498,6 +498,14 @@ Returns:
Emitted on 3-finger swipe. Possible directions are `up`, `right`, `down`, `left`.
#### Event: 'sheet-begin' _macOS_
Emitted when the window opens a sheet.
#### Event: 'sheet-end' _macOS_
Emitted when the window has closed a sheet.
### Static Methods
The `BrowserWindow` class has the following static methods:

View file

@ -1191,6 +1191,54 @@ describe('BrowserWindow module', function () {
})
})
describe('sheet-begin event', function () {
if (process.platform !== 'darwin') {
return
}
let sheet = null
afterEach(function () {
return closeWindow(sheet, {assertSingleWindow: false}).then(function () { sheet = null })
})
it('emits when window opens a sheet', function (done) {
w.show()
w.once('sheet-begin', function () {
sheet.close()
done()
})
sheet = new BrowserWindow({
modal: true,
parent: w
})
})
})
describe('sheet-end event', function () {
if (process.platform !== 'darwin') {
return
}
let sheet = null
afterEach(function () {
return closeWindow(sheet, {assertSingleWindow: false}).then(function () { sheet = null })
})
it('emits when window has closed a sheet', function (done) {
w.show()
sheet = new BrowserWindow({
modal: true,
parent: w
})
w.once('sheet-end', function () {
done()
})
sheet.close()
})
})
describe('beginFrameSubscription method', function () {
// This test is too slow, only test it on CI.
if (!isCI) return