| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/web_contents_modal_dialog_manager_cocoa.h" |
| 6 |
| 7 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh
eet.h" |
| 8 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" |
| 9 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
| 5 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 10 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 6 | 11 |
| 7 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h" | 12 using web_modal::NativeWebContentsModalDialog; |
| 8 #include "components/web_modal/single_web_contents_dialog_manager.h" | 13 using web_modal::SingleWebContentsDialogManagerDelegate; |
| 9 | 14 |
| 10 using web_modal::NativeWebContentsModalDialog; | 15 WebContentsModalDialogManagerCocoa::WebContentsModalDialogManagerCocoa( |
| 16 id<ConstrainedWindowSheet> sheet, |
| 17 web_modal::SingleWebContentsDialogManagerDelegate* delegate) |
| 18 : sheet_([sheet retain]), delegate_(delegate), shown_(false) { |
| 19 } |
| 11 | 20 |
| 12 namespace { | 21 WebContentsModalDialogManagerCocoa::~WebContentsModalDialogManagerCocoa() { |
| 22 } |
| 13 | 23 |
| 14 class NativeWebContentsModalDialogManagerCocoa | 24 void WebContentsModalDialogManagerCocoa::AddObserver(Observer* observer) { |
| 15 : public web_modal::SingleWebContentsDialogManager { | 25 observers_.AddObserver(observer); |
| 16 public: | 26 } |
| 17 NativeWebContentsModalDialogManagerCocoa( | |
| 18 NativeWebContentsModalDialog dialog) | |
| 19 : dialog_(dialog) { | |
| 20 } | |
| 21 | 27 |
| 22 ~NativeWebContentsModalDialogManagerCocoa() override {} | 28 void WebContentsModalDialogManagerCocoa::RemoveObserver(Observer* observer) { |
| 29 observers_.RemoveObserver(observer); |
| 30 } |
| 23 | 31 |
| 24 // SingleWebContentsDialogManager overrides | 32 void WebContentsModalDialogManagerCocoa::Show() { |
| 25 void Show() override { | 33 if (shown_) |
| 26 GetConstrainedWindowMac(dialog())->ShowWebContentsModalDialog(); | 34 return; |
| 27 } | |
| 28 | 35 |
| 29 void Hide() override {} | 36 content::WebContents* web_contents = delegate_->GetWebContents(); |
| 37 NSWindow* parent_window = web_contents->GetTopLevelNativeWindow(); |
| 38 NSView* parent_view = GetSheetParentViewForWebContents(web_contents); |
| 39 if (!parent_window || !parent_view) |
| 40 return; |
| 30 | 41 |
| 31 void Close() override { | 42 shown_ = true; |
| 32 GetConstrainedWindowMac(dialog())->CloseWebContentsModalDialog(); | 43 [[ConstrainedWindowSheetController controllerForParentWindow:parent_window] |
| 33 } | 44 showSheet:sheet_ forParentView:parent_view]; |
| 45 } |
| 34 | 46 |
| 35 void Focus() override { | 47 void WebContentsModalDialogManagerCocoa::Hide() { |
| 36 GetConstrainedWindowMac(dialog())->FocusWebContentsModalDialog(); | 48 } |
| 37 } | |
| 38 | 49 |
| 39 void Pulse() override { | 50 void WebContentsModalDialogManagerCocoa::Close() { |
| 40 GetConstrainedWindowMac(dialog())->PulseWebContentsModalDialog(); | 51 [[ConstrainedWindowSheetController controllerForSheet:sheet_] |
| 41 } | 52 closeSheet:sheet_]; |
| 53 FOR_EACH_OBSERVER(Observer, observers_, OnDialogClosing()); |
| 54 delegate_->WillClose(dialog()); |
| 55 } |
| 42 | 56 |
| 43 void HostChanged(web_modal::WebContentsModalDialogHost* new_host) override {} | 57 void WebContentsModalDialogManagerCocoa::Focus() { |
| 58 } |
| 44 | 59 |
| 45 NativeWebContentsModalDialog dialog() override { return dialog_; } | 60 void WebContentsModalDialogManagerCocoa::Pulse() { |
| 61 [[ConstrainedWindowSheetController controllerForSheet:sheet_] |
| 62 pulseSheet:sheet_]; |
| 63 } |
| 46 | 64 |
| 47 private: | 65 void WebContentsModalDialogManagerCocoa::HostChanged( |
| 48 static ConstrainedWindowMac* GetConstrainedWindowMac( | 66 web_modal::WebContentsModalDialogHost* new_host) { |
| 49 NativeWebContentsModalDialog dialog) { | 67 } |
| 50 return static_cast<ConstrainedWindowMac*>(dialog); | |
| 51 } | |
| 52 | 68 |
| 53 // In mac this is a pointer to a ConstrainedWindowMac. | 69 NativeWebContentsModalDialog WebContentsModalDialogManagerCocoa::dialog() { |
| 54 // TODO(gbillock): Replace this casting system with a more typesafe call path. | 70 return [sheet_ sheetWindow]; |
| 55 NativeWebContentsModalDialog dialog_; | 71 } |
| 56 | |
| 57 DISALLOW_COPY_AND_ASSIGN(NativeWebContentsModalDialogManagerCocoa); | |
| 58 }; | |
| 59 | |
| 60 } // namespace | |
| 61 | 72 |
| 62 namespace web_modal { | 73 namespace web_modal { |
| 63 | 74 |
| 64 SingleWebContentsDialogManager* | 75 SingleWebContentsDialogManager* |
| 65 WebContentsModalDialogManager::CreateNativeWebModalManager( | 76 WebContentsModalDialogManager::CreateNativeWebModalManager( |
| 66 NativeWebContentsModalDialog dialog, | 77 NativeWebContentsModalDialog dialog, |
| 67 SingleWebContentsDialogManagerDelegate* native_delegate) { | 78 SingleWebContentsDialogManagerDelegate* delegate) { |
| 68 return new NativeWebContentsModalDialogManagerCocoa(dialog); | 79 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet( |
| 80 [[CustomConstrainedWindowSheet alloc] initWithCustomWindow:dialog]); |
| 81 return new WebContentsModalDialogManagerCocoa(sheet, delegate); |
| 69 } | 82 } |
| 70 | 83 |
| 71 } // namespace web_modal | 84 } // namespace web_modal |
| OLD | NEW |