OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/browser/ui/cocoa/single_web_contents_dialog_manager_cocoa.h" | 5 #import "chrome/browser/ui/cocoa/single_web_contents_dialog_manager_cocoa.h" |
6 | 6 |
7 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh
eet.h" | 7 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh
eet.h" |
8 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h" | 8 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h" |
9 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" | 9 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" |
10 #include "components/web_modal/web_contents_modal_dialog_host.h" | 10 #include "components/web_modal/web_contents_modal_dialog_host.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 NSWindow* parent_window = | 51 NSWindow* parent_window = |
52 delegate_->GetWebContents()->GetTopLevelNativeWindow(); | 52 delegate_->GetWebContents()->GetTopLevelNativeWindow(); |
53 [[ConstrainedWindowSheetController controllerForParentWindow:parent_window] | 53 [[ConstrainedWindowSheetController controllerForParentWindow:parent_window] |
54 hideSheet]; | 54 hideSheet]; |
55 } | 55 } |
56 | 56 |
57 void SingleWebContentsDialogManagerCocoa::Close() { | 57 void SingleWebContentsDialogManagerCocoa::Close() { |
58 [[ConstrainedWindowSheetController controllerForSheet:sheet_] | 58 [[ConstrainedWindowSheetController controllerForSheet:sheet_] |
59 closeSheet:sheet_]; | 59 closeSheet:sheet_]; |
60 client_->set_manager(nullptr); | 60 client_->set_manager(nullptr); |
| 61 bool dialog_was_open = client_->DialogWasShown(); |
61 client_->OnDialogClosing(); // |client_| might delete itself here. | 62 client_->OnDialogClosing(); // |client_| might delete itself here. |
62 delegate_->WillClose(dialog()); // Deletes |this|. | 63 if (dialog_was_open) |
| 64 delegate_->WillClose(dialog()); // Deletes |this|. |
63 } | 65 } |
64 | 66 |
65 void SingleWebContentsDialogManagerCocoa::Focus() { | 67 void SingleWebContentsDialogManagerCocoa::Focus() { |
66 } | 68 } |
67 | 69 |
68 void SingleWebContentsDialogManagerCocoa::Pulse() { | 70 void SingleWebContentsDialogManagerCocoa::Pulse() { |
69 [[ConstrainedWindowSheetController controllerForSheet:sheet_] | 71 [[ConstrainedWindowSheetController controllerForSheet:sheet_] |
70 pulseSheet:sheet_]; | 72 pulseSheet:sheet_]; |
71 } | 73 } |
72 | 74 |
73 void SingleWebContentsDialogManagerCocoa::HostChanged( | 75 void SingleWebContentsDialogManagerCocoa::HostChanged( |
74 web_modal::WebContentsModalDialogHost* new_host) { | 76 web_modal::WebContentsModalDialogHost* new_host) { |
75 // No need to observe the host. For Cocoa, the constrained window controller | 77 // No need to observe the host. For Cocoa, the constrained window controller |
76 // will reposition the dialog when necessary. The host can also never change. | 78 // will reposition the dialog when necessary. The host can also never change. |
77 // Tabs showing a dialog can not be dragged off a Cocoa browser window. | 79 // Tabs showing a dialog can not be dragged off a Cocoa browser window. |
78 // However, closing a tab with a dialog open will set the host back to null. | 80 // However, closing a tab with a dialog open will set the host back to null. |
79 DCHECK_NE(!!host_, !!new_host); | 81 DCHECK_NE(!!host_, !!new_host); |
80 host_ = new_host; | 82 host_ = new_host; |
81 } | 83 } |
82 | 84 |
83 gfx::NativeWindow SingleWebContentsDialogManagerCocoa::dialog() { | 85 gfx::NativeWindow SingleWebContentsDialogManagerCocoa::dialog() { |
84 return [sheet_ sheetWindow]; | 86 return [sheet_ sheetWindow]; |
85 } | 87 } |
OLD | NEW |