Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / single_web_contents_dialog_manager_cocoa.mm
blobe03e70f5ca68f91d0abdd80f865ac704b47f277a
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)
19     : client_(client),
20       sheet_([sheet retain]),
21       delegate_(delegate),
22       shown_(false) {
23   if (client)
24     client->set_manager(this);
27 SingleWebContentsDialogManagerCocoa::~SingleWebContentsDialogManagerCocoa() {
30 void SingleWebContentsDialogManagerCocoa::Show() {
31   if (shown_)
32     return;
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)
38     return;
40   shown_ = true;
41   [[ConstrainedWindowSheetController controllerForParentWindow:parent_window]
42       showSheet:sheet_ forParentView:parent_view];
45 void SingleWebContentsDialogManagerCocoa::Hide() {
48 void SingleWebContentsDialogManagerCocoa::Close() {
49   [[ConstrainedWindowSheetController controllerForSheet:sheet_]
50       closeSheet:sheet_];
51   if (client_) {
52     client_->set_manager(nullptr);
53     client_->OnDialogClosing();  // |client_| might delete itself here.
54     client_ = nullptr;
55   }
56   delegate_->WillClose(dialog());
59 void SingleWebContentsDialogManagerCocoa::Focus() {
62 void SingleWebContentsDialogManagerCocoa::Pulse() {
63   [[ConstrainedWindowSheetController controllerForSheet:sheet_]
64       pulseSheet:sheet_];
67 void SingleWebContentsDialogManagerCocoa::HostChanged(
68     web_modal::WebContentsModalDialogHost* new_host) {
71 gfx::NativeWindow SingleWebContentsDialogManagerCocoa::dialog() {
72   return [sheet_ sheetWindow];
75 namespace web_modal {
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