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" |
| 8 #include "chrome/browser/ui/browser_window.h" |
7 #include "chrome/browser/ui/constrained_window_tab_helper.h" | 9 #include "chrome/browser/ui/constrained_window_tab_helper.h" |
8 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 10 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
9 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
10 #include "content/public/browser/web_contents_view.h" | 12 #include "content/public/browser/web_contents_view.h" |
11 #import "third_party/GTM/AppKit/GTMWindowSheetController.h" | 13 #import "third_party/GTM/AppKit/GTMWindowSheetController.h" |
12 | 14 |
13 ConstrainedWindowMacDelegateSystemSheet:: | 15 ConstrainedWindowMacDelegateSystemSheet:: |
14 ConstrainedWindowMacDelegateSystemSheet(id delegate, SEL didEndSelector) | 16 ConstrainedWindowMacDelegateSystemSheet(id delegate, SEL didEndSelector) |
15 : systemSheet_(nil), | 17 : systemSheet_(nil), |
16 delegate_([delegate retain]), | 18 delegate_([delegate retain]), |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 } | 117 } |
116 window = [window parentWindow]; | 118 window = [window parentWindow]; |
117 } | 119 } |
118 | 120 |
119 // It's valid for the window to be nil. For example, background tabs don't | 121 // It's valid for the window to be nil. For example, background tabs don't |
120 // have a window set. However, if a window exists then there should always | 122 // have a window set. However, if a window exists then there should always |
121 // be a window controller that implements the ConstrainedWindowSupport | 123 // be a window controller that implements the ConstrainedWindowSupport |
122 // protocol. | 124 // protocol. |
123 DCHECK(!window || window_controller); | 125 DCHECK(!window || window_controller); |
124 | 126 |
125 if ([window_controller canAttachConstrainedWindow]) | 127 Realize(window_controller); |
126 Realize(window_controller); | |
127 } | 128 } |
128 | 129 |
129 void ConstrainedWindowMac::CloseConstrainedWindow() { | 130 void ConstrainedWindowMac::CloseConstrainedWindow() { |
130 // Protection against reentrancy, which might otherwise become a problem if | 131 // Protection against reentrancy, which might otherwise become a problem if |
131 // DeleteDelegate forcibly closes a constrained window in a way that results | 132 // DeleteDelegate forcibly closes a constrained window in a way that results |
132 // in CloseConstrainedWindow being called again. | 133 // in CloseConstrainedWindow being called again. |
133 if (closing_) | 134 if (closing_) |
134 return; | 135 return; |
135 | 136 |
136 closing_ = true; | 137 closing_ = true; |
137 | 138 |
138 // Note: controller_ can be `nil` here if the sheet was never realized. That's | |
139 // ok. | |
140 [controller_ removeConstrainedWindow:this]; | |
141 delegate_->DeleteDelegate(); | 139 delegate_->DeleteDelegate(); |
142 tab_contents_->constrained_window_tab_helper()->WillClose(this); | 140 tab_contents_->constrained_window_tab_helper()->WillClose(this); |
143 | 141 |
144 delete this; | 142 delete this; |
145 } | 143 } |
146 | 144 |
147 void ConstrainedWindowMac::Realize( | 145 void ConstrainedWindowMac::Realize( |
148 NSWindowController<ConstrainedWindowSupport>* controller) { | 146 NSWindowController<ConstrainedWindowSupport>* controller) { |
149 if (!should_be_visible_) | 147 if (!should_be_visible_) |
150 return; | 148 return; |
151 | 149 |
152 if (controller_ != nil) { | 150 if (controller_ != nil) { |
153 DCHECK(controller_ == controller); | 151 DCHECK(controller_ == controller); |
154 return; | 152 return; |
155 } | 153 } |
156 DCHECK(controller != nil); | 154 DCHECK(controller != nil); |
157 | 155 |
158 // Remember the controller we're adding ourselves to, so that we can later | 156 // Remember the controller we're adding ourselves to, so that we can later |
159 // remove us from it. | 157 // remove us from it. |
160 controller_ = controller; | 158 controller_ = controller; |
161 [controller_ attachConstrainedWindow:this]; | 159 |
| 160 delegate_->RunSheet([controller_ sheetController], |
| 161 [tab_contents_->web_contents()->GetNativeView() superview]); |
162 delegate_->set_sheet_open(true); | 162 delegate_->set_sheet_open(true); |
163 } | 163 } |
| 164 |
| 165 bool ConstrainedWindowMac::GetCanShow() const { |
| 166 Browser* browser = |
| 167 browser::FindBrowserWithWebContents(tab_contents_->web_contents()); |
| 168 if (!browser) |
| 169 return true; |
| 170 return !browser->window()->GetIsShowingInstant(); |
| 171 } |
OLD | NEW |