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 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | |
8 #include "chrome/browser/ui/constrained_window_tab_helper.h" | 7 #include "chrome/browser/ui/constrained_window_tab_helper.h" |
9 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 8 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
10 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
11 #include "content/public/browser/web_contents_view.h" | 10 #include "content/public/browser/web_contents_view.h" |
12 #import "third_party/GTM/AppKit/GTMWindowSheetController.h" | 11 #import "third_party/GTM/AppKit/GTMWindowSheetController.h" |
13 | 12 |
14 ConstrainedWindowMacDelegateSystemSheet:: | 13 ConstrainedWindowMacDelegateSystemSheet:: |
15 ConstrainedWindowMacDelegateSystemSheet(id delegate, SEL didEndSelector) | 14 ConstrainedWindowMacDelegateSystemSheet(id delegate, SEL didEndSelector) |
16 : systemSheet_(nil), | 15 : systemSheet_(nil), |
17 delegate_([delegate retain]), | 16 delegate_([delegate retain]), |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 tab_contents->constrained_window_tab_helper()->AddConstrainedDialog(this); | 97 tab_contents->constrained_window_tab_helper()->AddConstrainedDialog(this); |
99 } | 98 } |
100 | 99 |
101 ConstrainedWindowMac::~ConstrainedWindowMac() {} | 100 ConstrainedWindowMac::~ConstrainedWindowMac() {} |
102 | 101 |
103 void ConstrainedWindowMac::ShowConstrainedWindow() { | 102 void ConstrainedWindowMac::ShowConstrainedWindow() { |
104 should_be_visible_ = true; | 103 should_be_visible_ = true; |
105 // The WebContents only has a native window if it is currently visible. In | 104 // The WebContents only has a native window if it is currently visible. In |
106 // this case, open the sheet now. Else, Realize() will be called later, when | 105 // this case, open the sheet now. Else, Realize() will be called later, when |
107 // our tab becomes visible. | 106 // our tab becomes visible. |
108 NSWindow* browserWindow = | 107 NSWindow* window = |
109 tab_contents_->web_contents()->GetView()->GetTopLevelNativeWindow(); | 108 tab_contents_->web_contents()->GetView()->GetTopLevelNativeWindow(); |
110 BrowserWindowController* browser_controller = | 109 NSWindowController<ConstrainedWindowSupport>* window_controller = nil; |
111 [BrowserWindowController browserWindowControllerForWindow:browserWindow]; | 110 while (window) { |
112 if ([browser_controller canAttachConstrainedWindow]) | 111 if ([[window windowController] conformsToProtocol: |
113 Realize(browser_controller); | 112 @protocol(ConstrainedWindowSupport)]) { |
| 113 window_controller = [window windowController]; |
| 114 break; |
| 115 } |
| 116 window = [window parentWindow]; |
| 117 } |
| 118 |
| 119 // 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 |
| 121 // be a window controller that implements the ConstrainedWindowSupport |
| 122 // protocol. |
| 123 DCHECK(!window || window_controller); |
| 124 |
| 125 if ([window_controller canAttachConstrainedWindow]) |
| 126 Realize(window_controller); |
114 } | 127 } |
115 | 128 |
116 void ConstrainedWindowMac::CloseConstrainedWindow() { | 129 void ConstrainedWindowMac::CloseConstrainedWindow() { |
117 // Protection against reentrancy, which might otherwise become a problem if | 130 // Protection against reentrancy, which might otherwise become a problem if |
118 // DeleteDelegate forcibly closes a constrained window in a way that results | 131 // DeleteDelegate forcibly closes a constrained window in a way that results |
119 // in CloseConstrainedWindow being called again. | 132 // in CloseConstrainedWindow being called again. |
120 if (closing_) | 133 if (closing_) |
121 return; | 134 return; |
122 | 135 |
123 closing_ = true; | 136 closing_ = true; |
124 | 137 |
125 // Note: controller_ can be `nil` here if the sheet was never realized. That's | 138 // Note: controller_ can be `nil` here if the sheet was never realized. That's |
126 // ok. | 139 // ok. |
127 [controller_ removeConstrainedWindow:this]; | 140 [controller_ removeConstrainedWindow:this]; |
128 delegate_->DeleteDelegate(); | 141 delegate_->DeleteDelegate(); |
129 tab_contents_->constrained_window_tab_helper()->WillClose(this); | 142 tab_contents_->constrained_window_tab_helper()->WillClose(this); |
130 | 143 |
131 delete this; | 144 delete this; |
132 } | 145 } |
133 | 146 |
134 void ConstrainedWindowMac::Realize(BrowserWindowController* controller) { | 147 void ConstrainedWindowMac::Realize( |
| 148 NSWindowController<ConstrainedWindowSupport>* controller) { |
135 if (!should_be_visible_) | 149 if (!should_be_visible_) |
136 return; | 150 return; |
137 | 151 |
138 if (controller_ != nil) { | 152 if (controller_ != nil) { |
139 DCHECK(controller_ == controller); | 153 DCHECK(controller_ == controller); |
140 return; | 154 return; |
141 } | 155 } |
142 DCHECK(controller != nil); | 156 DCHECK(controller != nil); |
143 | 157 |
144 // Remember the controller we're adding ourselves to, so that we can later | 158 // Remember the controller we're adding ourselves to, so that we can later |
145 // remove us from it. | 159 // remove us from it. |
146 controller_ = controller; | 160 controller_ = controller; |
147 [controller_ attachConstrainedWindow:this]; | 161 [controller_ attachConstrainedWindow:this]; |
148 delegate_->set_sheet_open(true); | 162 delegate_->set_sheet_open(true); |
149 } | 163 } |
OLD | NEW |