| Index: chrome/browser/ui/cocoa/web_contents_modal_dialog_manager_cocoa.mm
|
| diff --git a/chrome/browser/ui/cocoa/web_contents_modal_dialog_manager_cocoa.mm b/chrome/browser/ui/cocoa/web_contents_modal_dialog_manager_cocoa.mm
|
| index 5d025f6c8f6e5d865c7591cc6d5070712107f76d..83187c5f6f8da60dd643a29778202b7a7e1aed09 100644
|
| --- a/chrome/browser/ui/cocoa/web_contents_modal_dialog_manager_cocoa.mm
|
| +++ b/chrome/browser/ui/cocoa/web_contents_modal_dialog_manager_cocoa.mm
|
| @@ -2,70 +2,83 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "components/web_modal/web_contents_modal_dialog_manager.h"
|
| +#import "chrome/browser/ui/cocoa/web_contents_modal_dialog_manager_cocoa.h"
|
|
|
| -#include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h"
|
| -#include "components/web_modal/single_web_contents_dialog_manager.h"
|
| +#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sheet.h"
|
| +#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_controller.h"
|
| +#import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
|
| +#include "components/web_modal/web_contents_modal_dialog_manager.h"
|
|
|
| using web_modal::NativeWebContentsModalDialog;
|
| +using web_modal::SingleWebContentsDialogManagerDelegate;
|
|
|
| -namespace {
|
| -
|
| -class NativeWebContentsModalDialogManagerCocoa
|
| - : public web_modal::SingleWebContentsDialogManager {
|
| - public:
|
| - NativeWebContentsModalDialogManagerCocoa(
|
| - NativeWebContentsModalDialog dialog)
|
| - : dialog_(dialog) {
|
| - }
|
| +WebContentsModalDialogManagerCocoa::WebContentsModalDialogManagerCocoa(
|
| + id<ConstrainedWindowSheet> sheet,
|
| + web_modal::SingleWebContentsDialogManagerDelegate* delegate)
|
| + : sheet_([sheet retain]), delegate_(delegate), shown_(false) {
|
| +}
|
|
|
| - ~NativeWebContentsModalDialogManagerCocoa() override {}
|
| +WebContentsModalDialogManagerCocoa::~WebContentsModalDialogManagerCocoa() {
|
| +}
|
|
|
| - // SingleWebContentsDialogManager overrides
|
| - void Show() override {
|
| - GetConstrainedWindowMac(dialog())->ShowWebContentsModalDialog();
|
| - }
|
| +void WebContentsModalDialogManagerCocoa::AddObserver(Observer* observer) {
|
| + observers_.AddObserver(observer);
|
| +}
|
|
|
| - void Hide() override {}
|
| +void WebContentsModalDialogManagerCocoa::RemoveObserver(Observer* observer) {
|
| + observers_.RemoveObserver(observer);
|
| +}
|
|
|
| - void Close() override {
|
| - GetConstrainedWindowMac(dialog())->CloseWebContentsModalDialog();
|
| - }
|
| +void WebContentsModalDialogManagerCocoa::Show() {
|
| + if (shown_)
|
| + return;
|
|
|
| - void Focus() override {
|
| - GetConstrainedWindowMac(dialog())->FocusWebContentsModalDialog();
|
| - }
|
| + content::WebContents* web_contents = delegate_->GetWebContents();
|
| + NSWindow* parent_window = web_contents->GetTopLevelNativeWindow();
|
| + NSView* parent_view = GetSheetParentViewForWebContents(web_contents);
|
| + if (!parent_window || !parent_view)
|
| + return;
|
|
|
| - void Pulse() override {
|
| - GetConstrainedWindowMac(dialog())->PulseWebContentsModalDialog();
|
| - }
|
| + shown_ = true;
|
| + [[ConstrainedWindowSheetController controllerForParentWindow:parent_window]
|
| + showSheet:sheet_ forParentView:parent_view];
|
| +}
|
|
|
| - void HostChanged(web_modal::WebContentsModalDialogHost* new_host) override {}
|
| +void WebContentsModalDialogManagerCocoa::Hide() {
|
| +}
|
|
|
| - NativeWebContentsModalDialog dialog() override { return dialog_; }
|
| +void WebContentsModalDialogManagerCocoa::Close() {
|
| + [[ConstrainedWindowSheetController controllerForSheet:sheet_]
|
| + closeSheet:sheet_];
|
| + FOR_EACH_OBSERVER(Observer, observers_, OnDialogClosing());
|
| + delegate_->WillClose(dialog());
|
| +}
|
|
|
| - private:
|
| - static ConstrainedWindowMac* GetConstrainedWindowMac(
|
| - NativeWebContentsModalDialog dialog) {
|
| - return static_cast<ConstrainedWindowMac*>(dialog);
|
| - }
|
| +void WebContentsModalDialogManagerCocoa::Focus() {
|
| +}
|
|
|
| - // In mac this is a pointer to a ConstrainedWindowMac.
|
| - // TODO(gbillock): Replace this casting system with a more typesafe call path.
|
| - NativeWebContentsModalDialog dialog_;
|
| +void WebContentsModalDialogManagerCocoa::Pulse() {
|
| + [[ConstrainedWindowSheetController controllerForSheet:sheet_]
|
| + pulseSheet:sheet_];
|
| +}
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(NativeWebContentsModalDialogManagerCocoa);
|
| -};
|
| +void WebContentsModalDialogManagerCocoa::HostChanged(
|
| + web_modal::WebContentsModalDialogHost* new_host) {
|
| +}
|
|
|
| -} // namespace
|
| +NativeWebContentsModalDialog WebContentsModalDialogManagerCocoa::dialog() {
|
| + return [sheet_ sheetWindow];
|
| +}
|
|
|
| namespace web_modal {
|
|
|
| SingleWebContentsDialogManager*
|
| - WebContentsModalDialogManager::CreateNativeWebModalManager(
|
| - NativeWebContentsModalDialog dialog,
|
| - SingleWebContentsDialogManagerDelegate* native_delegate) {
|
| - return new NativeWebContentsModalDialogManagerCocoa(dialog);
|
| +WebContentsModalDialogManager::CreateNativeWebModalManager(
|
| + NativeWebContentsModalDialog dialog,
|
| + SingleWebContentsDialogManagerDelegate* delegate) {
|
| + base::scoped_nsobject<CustomConstrainedWindowSheet> sheet(
|
| + [[CustomConstrainedWindowSheet alloc] initWithCustomWindow:dialog]);
|
| + return new WebContentsModalDialogManagerCocoa(sheet, delegate);
|
| }
|
|
|
| } // namespace web_modal
|
|
|