| 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_mac.h" | 5 #include "chrome/browser/ui/cocoa/constrained_window_mac.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/browser_finder.h" | 7 #include "chrome/browser/ui/browser_finder.h" |
| 8 #include "chrome/browser/ui/browser_window.h" | 8 #include "chrome/browser/ui/browser_window.h" |
| 9 #include "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" | 9 #include "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
| 10 #include "chrome/browser/ui/constrained_window_tab_helper.h" | 10 #include "chrome/browser/ui/constrained_window_tab_helper.h" |
| 11 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
| 12 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
| 13 #include "content/public/browser/web_contents_view.h" | 12 #include "content/public/browser/web_contents_view.h" |
| 14 #import "third_party/GTM/AppKit/GTMWindowSheetController.h" | 13 #import "third_party/GTM/AppKit/GTMWindowSheetController.h" |
| 15 | 14 |
| 16 ConstrainedWindowMacDelegateSystemSheet:: | 15 ConstrainedWindowMacDelegateSystemSheet:: |
| 17 ConstrainedWindowMacDelegateSystemSheet(id delegate, SEL didEndSelector) | 16 ConstrainedWindowMacDelegateSystemSheet(id delegate, SEL didEndSelector) |
| 18 : systemSheet_(nil), | 17 : systemSheet_(nil), |
| 19 delegate_([delegate retain]), | 18 delegate_([delegate retain]), |
| 20 didEndSelector_(didEndSelector) {} | 19 didEndSelector_(didEndSelector) {} |
| 21 | 20 |
| 22 ConstrainedWindowMacDelegateSystemSheet:: | 21 ConstrainedWindowMacDelegateSystemSheet:: |
| 23 ~ConstrainedWindowMacDelegateSystemSheet() {} | 22 ~ConstrainedWindowMacDelegateSystemSheet() {} |
| 24 | 23 |
| 25 void ConstrainedWindowMacDelegateSystemSheet::set_sheet(id sheet) { | 24 void ConstrainedWindowMacDelegateSystemSheet::set_sheet(id sheet) { |
| 26 systemSheet_.reset([sheet retain]); | 25 systemSheet_.reset([sheet retain]); |
| 27 } | 26 } |
| 28 | 27 |
| 29 NSArray* ConstrainedWindowMacDelegateSystemSheet::GetSheetParameters( | 28 NSArray* ConstrainedWindowMacDelegateSystemSheet::GetSheetParameters( |
| 30 id delegate, | 29 id delegate, |
| 31 SEL didEndSelector) { | 30 SEL didEndSelector) { |
| 32 return [NSArray arrayWithObjects: | 31 return |
| 33 [NSNull null], // window, must be [NSNull null] | 32 @[[NSNull null], // window, must be [NSNull null] |
| 34 delegate, | 33 delegate, |
| 35 [NSValue valueWithPointer:didEndSelector], | 34 [NSValue valueWithPointer:didEndSelector], |
| 36 [NSValue valueWithPointer:NULL], // context info for didEndSelector_. | 35 [NSValue valueWithPointer:NULL]]; // context info for didEndSelector_. |
| 37 nil]; | |
| 38 } | 36 } |
| 39 | 37 |
| 40 void ConstrainedWindowMacDelegateSystemSheet::RunSheet( | 38 void ConstrainedWindowMacDelegateSystemSheet::RunSheet( |
| 41 GTMWindowSheetController* sheetController, | 39 GTMWindowSheetController* sheetController, |
| 42 NSView* view) { | 40 NSView* view) { |
| 43 NSArray* params = GetSheetParameters(delegate_.get(), didEndSelector_); | 41 NSArray* params = GetSheetParameters(delegate_.get(), didEndSelector_); |
| 44 [sheetController beginSystemSheet:systemSheet_ | 42 [sheetController beginSystemSheet:systemSheet_ |
| 45 modalForView:view | 43 modalForView:view |
| 46 withParameters:params]; | 44 withParameters:params]; |
| 47 } | 45 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 GTMWindowSheetController* sheetController, | 79 GTMWindowSheetController* sheetController, |
| 82 NSView* view) { | 80 NSView* view) { |
| 83 [sheetController beginSheet:customSheet_.get() | 81 [sheetController beginSheet:customSheet_.get() |
| 84 modalForView:view | 82 modalForView:view |
| 85 modalDelegate:delegate_.get() | 83 modalDelegate:delegate_.get() |
| 86 didEndSelector:didEndSelector_ | 84 didEndSelector:didEndSelector_ |
| 87 contextInfo:NULL]; | 85 contextInfo:NULL]; |
| 88 } | 86 } |
| 89 | 87 |
| 90 ConstrainedWindowMac::ConstrainedWindowMac( | 88 ConstrainedWindowMac::ConstrainedWindowMac( |
| 91 TabContents* tab_contents, ConstrainedWindowMacDelegate* delegate) | 89 content::WebContents* web_contents, ConstrainedWindowMacDelegate* delegate) |
| 92 : tab_contents_(tab_contents), | 90 : web_contents_(web_contents), |
| 93 delegate_(delegate), | 91 delegate_(delegate), |
| 94 controller_(nil), | 92 controller_(nil), |
| 95 should_be_visible_(false), | 93 should_be_visible_(false), |
| 96 closing_(false) { | 94 closing_(false) { |
| 97 DCHECK(tab_contents); | 95 DCHECK(web_contents); |
| 98 DCHECK(delegate); | 96 DCHECK(delegate); |
| 97 ConstrainedWindowTabHelper::CreateForWebContents(web_contents); |
| 99 | 98 |
| 100 ConstrainedWindowTabHelper* constrained_window_tab_helper = | 99 ConstrainedWindowTabHelper* constrained_window_tab_helper = |
| 101 ConstrainedWindowTabHelper::FromWebContents(tab_contents->web_contents()); | 100 ConstrainedWindowTabHelper::FromWebContents(web_contents); |
| 102 constrained_window_tab_helper->AddConstrainedDialog(this); | 101 constrained_window_tab_helper->AddConstrainedDialog(this); |
| 103 } | 102 } |
| 104 | 103 |
| 105 ConstrainedWindowMac::~ConstrainedWindowMac() {} | 104 ConstrainedWindowMac::~ConstrainedWindowMac() {} |
| 106 | 105 |
| 107 void ConstrainedWindowMac::ShowConstrainedWindow() { | 106 void ConstrainedWindowMac::ShowConstrainedWindow() { |
| 108 should_be_visible_ = true; | 107 should_be_visible_ = true; |
| 109 // The WebContents only has a native window if it is currently visible. In | 108 // The WebContents only has a native window if it is currently visible. In |
| 110 // this case, open the sheet now. Else, Realize() will be called later, when | 109 // this case, open the sheet now. Else, Realize() will be called later, when |
| 111 // our tab becomes visible. | 110 // our tab becomes visible. |
| 112 NSWindow* window = | 111 NSWindow* window = web_contents_->GetView()->GetTopLevelNativeWindow(); |
| 113 tab_contents_->web_contents()->GetView()->GetTopLevelNativeWindow(); | |
| 114 NSWindowController<ConstrainedWindowSupport>* window_controller = nil; | 112 NSWindowController<ConstrainedWindowSupport>* window_controller = nil; |
| 115 while (window) { | 113 while (window) { |
| 116 if ([[window windowController] conformsToProtocol: | 114 if ([[window windowController] conformsToProtocol: |
| 117 @protocol(ConstrainedWindowSupport)]) { | 115 @protocol(ConstrainedWindowSupport)]) { |
| 118 window_controller = [window windowController]; | 116 window_controller = [window windowController]; |
| 119 break; | 117 break; |
| 120 } | 118 } |
| 121 window = [window parentWindow]; | 119 window = [window parentWindow]; |
| 122 } | 120 } |
| 123 | 121 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 135 // Protection against reentrancy, which might otherwise become a problem if | 133 // Protection against reentrancy, which might otherwise become a problem if |
| 136 // DeleteDelegate forcibly closes a constrained window in a way that results | 134 // DeleteDelegate forcibly closes a constrained window in a way that results |
| 137 // in CloseConstrainedWindow being called again. | 135 // in CloseConstrainedWindow being called again. |
| 138 if (closing_) | 136 if (closing_) |
| 139 return; | 137 return; |
| 140 | 138 |
| 141 closing_ = true; | 139 closing_ = true; |
| 142 | 140 |
| 143 delegate_->DeleteDelegate(); | 141 delegate_->DeleteDelegate(); |
| 144 ConstrainedWindowTabHelper* constrained_window_tab_helper = | 142 ConstrainedWindowTabHelper* constrained_window_tab_helper = |
| 145 ConstrainedWindowTabHelper::FromWebContents( | 143 ConstrainedWindowTabHelper::FromWebContents(web_contents_); |
| 146 tab_contents_->web_contents()); | |
| 147 constrained_window_tab_helper->WillClose(this); | 144 constrained_window_tab_helper->WillClose(this); |
| 148 | 145 |
| 149 delete this; | 146 delete this; |
| 150 } | 147 } |
| 151 | 148 |
| 152 bool ConstrainedWindowMac::CanShowConstrainedWindow() { | 149 bool ConstrainedWindowMac::CanShowConstrainedWindow() { |
| 153 Browser* browser = | 150 Browser* browser = browser::FindBrowserWithWebContents(web_contents_); |
| 154 browser::FindBrowserWithWebContents(tab_contents_->web_contents()); | |
| 155 if (!browser) | 151 if (!browser) |
| 156 return true; | 152 return true; |
| 157 return !browser->window()->IsInstantTabShowing(); | 153 return !browser->window()->IsInstantTabShowing(); |
| 158 } | 154 } |
| 159 | 155 |
| 160 void ConstrainedWindowMac::Realize( | 156 void ConstrainedWindowMac::Realize( |
| 161 NSWindowController<ConstrainedWindowSupport>* controller) { | 157 NSWindowController<ConstrainedWindowSupport>* controller) { |
| 162 if (!should_be_visible_) | 158 if (!should_be_visible_) |
| 163 return; | 159 return; |
| 164 | 160 |
| 165 if (controller_ != nil) { | 161 if (controller_ != nil) { |
| 166 DCHECK(controller_ == controller); | 162 DCHECK(controller_ == controller); |
| 167 return; | 163 return; |
| 168 } | 164 } |
| 169 DCHECK(controller != nil); | 165 DCHECK(controller != nil); |
| 170 | 166 |
| 171 // Remember the controller we're adding ourselves to, so that we can later | 167 // Remember the controller we're adding ourselves to, so that we can later |
| 172 // remove us from it. | 168 // remove us from it. |
| 173 controller_ = controller; | 169 controller_ = controller; |
| 174 delegate_->RunSheet([controller_ sheetController], | 170 delegate_->RunSheet([controller_ sheetController], |
| 175 GetSheetParentViewForTabContents(tab_contents_)); | 171 GetSheetParentViewForWebContents(web_contents_)); |
| 176 delegate_->set_sheet_open(true); | 172 delegate_->set_sheet_open(true); |
| 177 } | 173 } |
| OLD | NEW |