mac: Add win.beginSheet(sheet)/endSheet(sheet) API

This commit is contained in:
Cheng Zhao 2016-06-18 22:53:41 +09:00
parent 2c5f4aadfb
commit f2cbd7cb36
6 changed files with 38 additions and 0 deletions

View file

@ -723,6 +723,18 @@ bool Window::IsModal() const {
return is_modal_;
}
void Window::BeginSheet(mate::Handle<Window> 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<Window> sheet) {
window_->EndSheet(sheet->window_.get());
}
v8::Local<v8::Value> 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)

View file

@ -168,6 +168,8 @@ class Window : public mate::TrackableObject<Window>,
std::vector<v8::Local<v8::Object>> GetChildWindows() const;
void SetModal(bool modal, mate::Arguments* args);
bool IsModal() const;
void BeginSheet(mate::Handle<Window> sheet, mate::Arguments* args);
void EndSheet(mate::Handle<Window> sheet);
v8::Local<v8::Value> GetNativeWindowHandle();
#if defined(OS_WIN)

View file

@ -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();
}

View file

@ -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;

View file

@ -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;

View file

@ -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_;
}