macOS: Use sheet window as modal window

This commit is contained in:
Cheng Zhao 2016-06-20 14:49:24 +09:00
parent 1866dbe608
commit e33e4be257
8 changed files with 81 additions and 112 deletions

View file

@ -76,8 +76,7 @@ v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) {
} // namespace
Window::Window(v8::Isolate* isolate, const mate::Dictionary& options)
: is_modal_(false) {
Window::Window(v8::Isolate* isolate, const mate::Dictionary& options) {
// Use options.webPreferences to create WebContents.
mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
options.Get(options::kWebPreferences, &web_preferences);
@ -312,6 +311,10 @@ void Window::Show() {
}
void Window::ShowInactive() {
// This method doesn't make sense for modal window..
if (IsModal())
return;
window_->ShowInactive();
}
@ -696,6 +699,11 @@ void Window::SetAspectRatio(double aspect_ratio, mate::Arguments* args) {
void Window::SetParentWindow(v8::Local<v8::Value> value,
mate::Arguments* args) {
if (IsModal()) {
args->ThrowError("Can not be called for modal window");
return;
}
mate::Handle<Window> parent;
if (value->IsNull()) {
RemoveFromParentChildWindows();
@ -721,43 +729,8 @@ std::vector<v8::Local<v8::Object>> Window::GetChildWindows() const {
return child_windows_.Values(isolate());
}
void Window::SetModal(bool modal, mate::Arguments* args) {
if (parent_window_.IsEmpty()) {
args->ThrowError("setModal can only be called for child window");
return;
}
mate::Handle<Window> parent;
if (!mate::ConvertFromV8(isolate(), GetParentWindow(), &parent)) {
args->ThrowError("Invalid parent window"); // should never happen
return;
}
if (modal == is_modal_)
return;
if (modal)
parent->Disable();
else
parent->Enable();
window_->SetModal(modal);
is_modal_ = modal;
}
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());
return window_->is_modal();
}
v8::Local<v8::Value> Window::GetNativeWindowHandle() {
@ -794,10 +767,8 @@ void Window::RemoveFromParentChildWindows() {
return;
parent->child_windows_.Remove(ID());
if (IsModal()) {
if (IsModal())
parent->Enable();
is_modal_ = false;
}
}
// static
@ -828,10 +799,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
.SetMethod("setParentWindow", &Window::SetParentWindow)
.SetMethod("getParentWindow", &Window::GetParentWindow)
.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)