From f2cbd7cb36b3461d1e8727f0e91dbe7040a10405 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 18 Jun 2016 22:53:41 +0900 Subject: [PATCH] mac: Add win.beginSheet(sheet)/endSheet(sheet) API --- atom/browser/api/atom_api_window.cc | 14 ++++++++++++++ atom/browser/api/atom_api_window.h | 2 ++ atom/browser/native_window.cc | 6 ++++++ atom/browser/native_window.h | 2 ++ atom/browser/native_window_mac.h | 2 ++ atom/browser/native_window_mac.mm | 12 ++++++++++++ 6 files changed, 38 insertions(+) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index d1263c7e5832..308ff31dea9f 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -723,6 +723,18 @@ bool Window::IsModal() const { return is_modal_; } +void Window::BeginSheet(mate::Handle sheet, mate::Arguments* args) { + if (sheet->IsVisible()) { + args->ThrowError("Sheet window must not be visible"); + return; + } + window_->BeginSheet(sheet->window_.get()); +} + +void Window::EndSheet(mate::Handle sheet) { + window_->EndSheet(sheet->window_.get()); +} + v8::Local Window::GetNativeWindowHandle() { gfx::AcceleratedWidget handle = window_->GetAcceleratedWidget(); return ToBuffer( @@ -793,6 +805,8 @@ void Window::BuildPrototype(v8::Isolate* isolate, .SetMethod("getChildWindows", &Window::GetChildWindows) .SetMethod("setModal", &Window::SetModal) .SetMethod("isModal", &Window::IsModal) + .SetMethod("beginSheet", &Window::BeginSheet) + .SetMethod("endSheet", &Window::EndSheet) .SetMethod("getNativeWindowHandle", &Window::GetNativeWindowHandle) .SetMethod("getBounds", &Window::GetBounds) .SetMethod("setBounds", &Window::SetBounds) diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 003fa5230e96..92b41e775d69 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -168,6 +168,8 @@ class Window : public mate::TrackableObject, std::vector> GetChildWindows() const; void SetModal(bool modal, mate::Arguments* args); bool IsModal() const; + void BeginSheet(mate::Handle sheet, mate::Arguments* args); + void EndSheet(mate::Handle sheet); v8::Local GetNativeWindowHandle(); #if defined(OS_WIN) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 844bbefa9e24..73698b7f4127 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -292,6 +292,12 @@ bool NativeWindow::HasModalDialog() { return has_dialog_attached_; } +void NativeWindow::BeginSheet(NativeWindow* sheet) { +} + +void NativeWindow::EndSheet(NativeWindow* sheet) { +} + void NativeWindow::FocusOnWebView() { web_contents()->GetRenderViewHost()->GetWidget()->Focus(); } diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index a2adb5505c58..120d399ad709 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -162,6 +162,8 @@ class NativeWindow : public base::SupportsUserData, virtual void SetMenu(ui::MenuModel* menu); virtual bool HasModalDialog(); virtual void SetParentWindow(NativeWindow* parent) = 0; + virtual void BeginSheet(NativeWindow* sheet); + virtual void EndSheet(NativeWindow* sheet); virtual gfx::NativeWindow GetNativeWindow() = 0; virtual gfx::AcceleratedWidget GetAcceleratedWidget() = 0; diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 0a783c350e17..357cbd55ff32 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -82,6 +82,8 @@ class NativeWindowMac : public NativeWindow { void SetIgnoreMouseEvents(bool ignore) override; bool HasModalDialog() override; void SetParentWindow(NativeWindow* parent) override; + void BeginSheet(NativeWindow* sheet) override; + void EndSheet(NativeWindow* sheet) override; gfx::NativeWindow GetNativeWindow() override; gfx::AcceleratedWidget GetAcceleratedWidget() override; void SetProgressBar(double progress) override; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index bad2fc7f2436..9e9a948f94c9 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -964,6 +964,18 @@ void NativeWindowMac::SetParentWindow(NativeWindow* parent) { [parent->GetNativeWindow() addChildWindow:window_ ordered:NSWindowAbove]; } +void NativeWindowMac::BeginSheet(NativeWindow* sheet) { + [window_ beginSheet:sheet->GetNativeWindow() + completionHandler:^(NSModalResponse) { + }]; +} + +void NativeWindowMac::EndSheet(NativeWindow* sheet) { + sheet->Hide(); + [window_ endSheet:sheet->GetNativeWindow()]; + sheet->CloseImmediately(); +} + gfx::NativeWindow NativeWindowMac::GetNativeWindow() { return window_; }