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 27 matching lines...) Expand all Loading... |
38 return; | 38 return; |
39 | 39 |
40 NSView* parent_view = host_->GetHostView(); | 40 NSView* parent_view = host_->GetHostView(); |
41 // Note that simply [parent_view window] for an inactive tab is nil. However, | 41 // Note that simply [parent_view window] for an inactive tab is nil. However, |
42 // the following should always be non-nil for all WebContents containers. | 42 // the following should always be non-nil for all WebContents containers. |
43 NSWindow* parent_window = | 43 NSWindow* parent_window = |
44 delegate_->GetWebContents()->GetTopLevelNativeWindow(); | 44 delegate_->GetWebContents()->GetTopLevelNativeWindow(); |
45 | 45 |
46 [[ConstrainedWindowSheetController controllerForParentWindow:parent_window] | 46 [[ConstrainedWindowSheetController controllerForParentWindow:parent_window] |
47 showSheet:sheet_ forParentView:parent_view]; | 47 showSheet:sheet_ forParentView:parent_view]; |
| 48 dialog(); |
48 } | 49 } |
49 | 50 |
50 void SingleWebContentsDialogManagerCocoa::Hide() { | 51 void SingleWebContentsDialogManagerCocoa::Hide() { |
51 NSWindow* parent_window = | 52 NSWindow* parent_window = |
52 delegate_->GetWebContents()->GetTopLevelNativeWindow(); | 53 delegate_->GetWebContents()->GetTopLevelNativeWindow(); |
53 [[ConstrainedWindowSheetController controllerForParentWindow:parent_window] | 54 [[ConstrainedWindowSheetController controllerForParentWindow:parent_window] |
54 hideSheet:sheet_]; | 55 hideSheet:sheet_]; |
55 } | 56 } |
56 | 57 |
57 void SingleWebContentsDialogManagerCocoa::Close() { | 58 void SingleWebContentsDialogManagerCocoa::Close() { |
(...skipping 18 matching lines...) Expand all Loading... |
76 web_modal::WebContentsModalDialogHost* new_host) { | 77 web_modal::WebContentsModalDialogHost* new_host) { |
77 // No need to observe the host. For Cocoa, the constrained window controller | 78 // No need to observe the host. For Cocoa, the constrained window controller |
78 // will reposition the dialog when necessary. The host can also never change. | 79 // will reposition the dialog when necessary. The host can also never change. |
79 // Tabs showing a dialog can not be dragged off a Cocoa browser window. | 80 // Tabs showing a dialog can not be dragged off a Cocoa browser window. |
80 // However, closing a tab with a dialog open will set the host back to null. | 81 // However, closing a tab with a dialog open will set the host back to null. |
81 DCHECK_NE(!!host_, !!new_host); | 82 DCHECK_NE(!!host_, !!new_host); |
82 host_ = new_host; | 83 host_ = new_host; |
83 } | 84 } |
84 | 85 |
85 gfx::NativeWindow SingleWebContentsDialogManagerCocoa::dialog() { | 86 gfx::NativeWindow SingleWebContentsDialogManagerCocoa::dialog() { |
86 return [sheet_ sheetWindow]; | 87 // Update |dialog_| if unpopulated or if the sheetWindow has changed. |
| 88 if (!dialog_ || ([sheet_ sheetWindow] && dialog_ != [sheet_ sheetWindow])) |
| 89 dialog_ = [sheet_ sheetWindow]; |
| 90 return dialog_; |
87 } | 91 } |
OLD | NEW |