| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h" | 5 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/ui/browser_finder.h" | 8 #include "chrome/browser/ui/browser_finder.h" |
| 9 #include "chrome/browser/ui/browser_window.h" | 9 #include "chrome/browser/ui/browser_window.h" |
| 10 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet.h" | 10 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet.h" |
| 11 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" | 11 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" |
| 12 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" | 12 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
| 13 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 13 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/browser/web_contents_view.h" | 16 #include "content/public/browser/web_contents_view.h" |
| 17 | 17 |
| 18 using web_modal::WebContentsModalDialogManager; | 18 using web_modal::WebContentsModalDialogManager; |
| 19 using web_modal::NativeWebContentsModalDialog; | 19 using web_modal::NativeWebContentsModalDialog; |
| 20 | 20 |
| 21 ConstrainedWindowMac::ConstrainedWindowMac( | 21 ConstrainedWindowMac::ConstrainedWindowMac( |
| 22 ConstrainedWindowMacDelegate* delegate, | 22 ConstrainedWindowMacDelegate* delegate, |
| 23 content::WebContents* web_contents, | 23 content::WebContents* web_contents, |
| 24 id<ConstrainedWindowSheet> sheet) | 24 id<ConstrainedWindowSheet> sheet) |
| 25 : delegate_(delegate), | 25 : delegate_(delegate), |
| 26 web_contents_(web_contents), | 26 web_contents_(web_contents), |
| 27 sheet_([sheet retain]), | 27 sheet_([sheet retain]), |
| 28 shown_(false) { | 28 shown_(false), |
| 29 closing_(false) { |
| 29 DCHECK(web_contents); | 30 DCHECK(web_contents); |
| 30 DCHECK(sheet_.get()); | 31 DCHECK(sheet_.get()); |
| 31 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 32 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 32 WebContentsModalDialogManager::FromWebContents(web_contents); | 33 WebContentsModalDialogManager::FromWebContents(web_contents); |
| 33 web_contents_modal_dialog_manager->ShowDialog(this); | 34 web_contents_modal_dialog_manager->ShowDialog(this); |
| 34 } | 35 } |
| 35 | 36 |
| 36 ConstrainedWindowMac::~ConstrainedWindowMac() { | 37 ConstrainedWindowMac::~ConstrainedWindowMac() { |
| 37 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 38 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 38 } | 39 } |
| 39 | 40 |
| 40 void ConstrainedWindowMac::ShowWebContentsModalDialog() { | 41 void ConstrainedWindowMac::ShowWebContentsModalDialog() { |
| 41 if (shown_) | 42 if (shown_) |
| 42 return; | 43 return; |
| 43 | 44 |
| 44 NSWindow* parent_window = GetParentWindow(); | 45 NSWindow* parent_window = GetParentWindow(); |
| 45 NSView* parent_view = GetSheetParentViewForWebContents(web_contents_); | 46 NSView* parent_view = GetSheetParentViewForWebContents(web_contents_); |
| 46 if (!parent_window || !parent_view) | 47 if (!parent_window || !parent_view) |
| 47 return; | 48 return; |
| 48 | 49 |
| 49 shown_ = true; | 50 shown_ = true; |
| 50 ConstrainedWindowSheetController* controller = | 51 ConstrainedWindowSheetController* controller = |
| 51 [ConstrainedWindowSheetController | 52 [ConstrainedWindowSheetController |
| 52 controllerForParentWindow:parent_window]; | 53 controllerForParentWindow:parent_window]; |
| 53 [controller showSheet:sheet_ forParentView:parent_view]; | 54 [controller showSheet:sheet_ forParentView:parent_view]; |
| 54 } | 55 } |
| 55 | 56 |
| 56 void ConstrainedWindowMac::CloseWebContentsModalDialog() { | 57 void ConstrainedWindowMac::CloseWebContentsModalDialog() { |
| 58 if (closing_) |
| 59 return; |
| 60 |
| 61 closing_ = true; |
| 57 [[ConstrainedWindowSheetController controllerForSheet:sheet_] | 62 [[ConstrainedWindowSheetController controllerForSheet:sheet_] |
| 58 closeSheet:sheet_]; | 63 closeSheet:sheet_]; |
| 59 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 64 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 60 WebContentsModalDialogManager::FromWebContents(web_contents_); | 65 WebContentsModalDialogManager::FromWebContents(web_contents_); |
| 61 web_contents_modal_dialog_manager->WillClose(this); | 66 web_contents_modal_dialog_manager->WillClose(this); |
| 62 if (delegate_) | 67 if (delegate_) |
| 63 delegate_->OnConstrainedWindowClosed(this); | 68 delegate_->OnConstrainedWindowClosed(this); |
| 64 } | 69 } |
| 65 | 70 |
| 66 void ConstrainedWindowMac::FocusWebContentsModalDialog() { | 71 void ConstrainedWindowMac::FocusWebContentsModalDialog() { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 88 | 93 |
| 89 NSWindow* ConstrainedWindowMac::GetParentWindow() const { | 94 NSWindow* ConstrainedWindowMac::GetParentWindow() const { |
| 90 // Tab contents in a tabbed browser may not be inside a window. For this | 95 // Tab contents in a tabbed browser may not be inside a window. For this |
| 91 // reason use a browser window if possible. | 96 // reason use a browser window if possible. |
| 92 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); | 97 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); |
| 93 if (browser) | 98 if (browser) |
| 94 return browser->window()->GetNativeWindow(); | 99 return browser->window()->GetNativeWindow(); |
| 95 | 100 |
| 96 return web_contents_->GetView()->GetTopLevelNativeWindow(); | 101 return web_contents_->GetView()->GetTopLevelNativeWindow(); |
| 97 } | 102 } |
| OLD | NEW |