| 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 "chrome/browser/ui/constrained_window_tab_helper.h" | 13 #include "chrome/browser/ui/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/notification_source.h" | 15 #include "content/public/browser/notification_source.h" |
| 16 #include "content/public/browser/notification_types.h" | 16 #include "content/public/browser/notification_types.h" |
| 17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/browser/web_contents_view.h" | 18 #include "content/public/browser/web_contents_view.h" |
| 19 | 19 |
| 20 ConstrainedWindowMac::ConstrainedWindowMac( | 20 ConstrainedWindowMac::ConstrainedWindowMac( |
| 21 ConstrainedWindowMacDelegate* delegate, | 21 ConstrainedWindowMacDelegate* delegate, |
| 22 content::WebContents* web_contents, | 22 content::WebContents* web_contents, |
| 23 id<ConstrainedWindowSheet> sheet) | 23 id<ConstrainedWindowSheet> sheet) |
| 24 : delegate_(delegate), | 24 : delegate_(delegate), |
| 25 web_contents_(web_contents), | 25 web_contents_(web_contents), |
| 26 sheet_([sheet retain]), | 26 sheet_([sheet retain]), |
| 27 pending_show_(false) { | 27 pending_show_(false) { |
| 28 DCHECK(web_contents); | 28 DCHECK(web_contents); |
| 29 DCHECK(sheet_.get()); | 29 DCHECK(sheet_.get()); |
| 30 ConstrainedWindowTabHelper* constrained_window_tab_helper = | 30 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 31 ConstrainedWindowTabHelper::FromWebContents(web_contents); | 31 WebContentsModalDialogManager::FromWebContents(web_contents); |
| 32 constrained_window_tab_helper->AddDialog(this); | 32 web_contents_modal_dialog_manager->AddDialog(this); |
| 33 | 33 |
| 34 registrar_.Add(this, | 34 registrar_.Add(this, |
| 35 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, | 35 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, |
| 36 content::Source<content::WebContents>(web_contents)); | 36 content::Source<content::WebContents>(web_contents)); |
| 37 } | 37 } |
| 38 | 38 |
| 39 ConstrainedWindowMac::~ConstrainedWindowMac() { | 39 ConstrainedWindowMac::~ConstrainedWindowMac() { |
| 40 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 40 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 41 } | 41 } |
| 42 | 42 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 54 [controller showSheet:sheet_ forParentView:parent_view]; | 54 [controller showSheet:sheet_ forParentView:parent_view]; |
| 55 } | 55 } |
| 56 | 56 |
| 57 void ConstrainedWindowMac::CloseWebContentsModalDialog() { | 57 void ConstrainedWindowMac::CloseWebContentsModalDialog() { |
| 58 // This function may be called even if the constrained window was never shown. | 58 // This function may be called even if the constrained window was never shown. |
| 59 // Unset |pending_show_| to prevent the window from being reshown. | 59 // Unset |pending_show_| to prevent the window from being reshown. |
| 60 pending_show_ = false; | 60 pending_show_ = false; |
| 61 | 61 |
| 62 [[ConstrainedWindowSheetController controllerForSheet:sheet_] | 62 [[ConstrainedWindowSheetController controllerForSheet:sheet_] |
| 63 closeSheet:sheet_]; | 63 closeSheet:sheet_]; |
| 64 ConstrainedWindowTabHelper* constrained_window_tab_helper = | 64 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 65 ConstrainedWindowTabHelper::FromWebContents(web_contents_); | 65 WebContentsModalDialogManager::FromWebContents(web_contents_); |
| 66 constrained_window_tab_helper->WillClose(this); | 66 web_contents_modal_dialog_manager->WillClose(this); |
| 67 if (delegate_) | 67 if (delegate_) |
| 68 delegate_->OnConstrainedWindowClosed(this); | 68 delegate_->OnConstrainedWindowClosed(this); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void ConstrainedWindowMac::FocusWebContentsModalDialog() { |
| 72 } |
| 73 |
| 71 void ConstrainedWindowMac::PulseWebContentsModalDialog() { | 74 void ConstrainedWindowMac::PulseWebContentsModalDialog() { |
| 72 [[ConstrainedWindowSheetController controllerForSheet:sheet_] | 75 [[ConstrainedWindowSheetController controllerForSheet:sheet_] |
| 73 pulseSheet:sheet_]; | 76 pulseSheet:sheet_]; |
| 74 } | 77 } |
| 75 | 78 |
| 76 gfx::NativeWindow ConstrainedWindowMac::GetNativeWindow() { | 79 gfx::NativeWindow ConstrainedWindowMac::GetNativeWindow() { |
| 77 NOTREACHED(); | 80 NOTREACHED(); |
| 78 return nil; | 81 return nil; |
| 79 } | 82 } |
| 80 | 83 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 102 | 105 |
| 103 NSWindow* ConstrainedWindowMac::GetParentWindow() const { | 106 NSWindow* ConstrainedWindowMac::GetParentWindow() const { |
| 104 // Tab contents in a tabbed browser may not be inside a window. For this | 107 // Tab contents in a tabbed browser may not be inside a window. For this |
| 105 // reason use a browser window if possible. | 108 // reason use a browser window if possible. |
| 106 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); | 109 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); |
| 107 if (browser) | 110 if (browser) |
| 108 return browser->window()->GetNativeWindow(); | 111 return browser->window()->GetNativeWindow(); |
| 109 | 112 |
| 110 return web_contents_->GetView()->GetTopLevelNativeWindow(); | 113 return web_contents_->GetView()->GetTopLevelNativeWindow(); |
| 111 } | 114 } |
| OLD | NEW |