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
3 // found in the LICENSE file.
5 #import "chrome/browser/ui/cocoa/single_web_contents_dialog_manager_cocoa.h"
7 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sheet.h"
8 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h"
9 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_controller.h"
10 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
11 #include "components/web_modal/web_contents_modal_dialog_manager.h"
13 using web_modal::SingleWebContentsDialogManagerDelegate;
15 SingleWebContentsDialogManagerCocoa::SingleWebContentsDialogManagerCocoa(
16 ConstrainedWindowMac* client,
17 id<ConstrainedWindowSheet> sheet,
18 web_modal::SingleWebContentsDialogManagerDelegate* delegate)
20 sheet_([sheet retain]),
24 client->set_manager(this);
27 SingleWebContentsDialogManagerCocoa::~SingleWebContentsDialogManagerCocoa() {
30 void SingleWebContentsDialogManagerCocoa::Show() {
34 content::WebContents* web_contents = delegate_->GetWebContents();
35 NSWindow* parent_window = web_contents->GetTopLevelNativeWindow();
36 NSView* parent_view = GetSheetParentViewForWebContents(web_contents);
37 if (!parent_window || !parent_view)
41 [[ConstrainedWindowSheetController controllerForParentWindow:parent_window]
42 showSheet:sheet_ forParentView:parent_view];
45 void SingleWebContentsDialogManagerCocoa::Hide() {
48 void SingleWebContentsDialogManagerCocoa::Close() {
49 [[ConstrainedWindowSheetController controllerForSheet:sheet_]
52 client_->set_manager(nullptr);
53 client_->OnDialogClosing(); // |client_| might delete itself here.
56 delegate_->WillClose(dialog());
59 void SingleWebContentsDialogManagerCocoa::Focus() {
62 void SingleWebContentsDialogManagerCocoa::Pulse() {
63 [[ConstrainedWindowSheetController controllerForSheet:sheet_]
67 void SingleWebContentsDialogManagerCocoa::HostChanged(
68 web_modal::WebContentsModalDialogHost* new_host) {
71 gfx::NativeWindow SingleWebContentsDialogManagerCocoa::dialog() {
72 return [sheet_ sheetWindow];
77 SingleWebContentsDialogManager*
78 WebContentsModalDialogManager::CreateNativeWebModalManager(
79 gfx::NativeWindow dialog,
80 SingleWebContentsDialogManagerDelegate* delegate) {
81 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet(
82 [[CustomConstrainedWindowSheet alloc] initWithCustomWindow:dialog]);
83 return new SingleWebContentsDialogManagerCocoa(nullptr, sheet, delegate);
86 } // namespace web_modal