Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1058)

Side by Side Diff: chrome/browser/ui/cocoa/constrained_window_mac.mm

Issue 10871082: Constrained Windows Cocoa: Part 4 Refactor ConstrainedWindowSupport (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address review comments Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 if (window_controller)
126 Realize(window_controller); 128 Realize(window_controller);
127 } 129 }
128 130
129 void ConstrainedWindowMac::CloseConstrainedWindow() { 131 void ConstrainedWindowMac::CloseConstrainedWindow() {
130 // Protection against reentrancy, which might otherwise become a problem if 132 // Protection against reentrancy, which might otherwise become a problem if
131 // DeleteDelegate forcibly closes a constrained window in a way that results 133 // DeleteDelegate forcibly closes a constrained window in a way that results
132 // in CloseConstrainedWindow being called again. 134 // in CloseConstrainedWindow being called again.
133 if (closing_) 135 if (closing_)
134 return; 136 return;
135 137
136 closing_ = true; 138 closing_ = true;
137 139
138 // Note: controller_ can be `nil` here if the sheet was never realized. That's
139 // ok.
140 [controller_ removeConstrainedWindow:this];
141 delegate_->DeleteDelegate(); 140 delegate_->DeleteDelegate();
142 tab_contents_->constrained_window_tab_helper()->WillClose(this); 141 tab_contents_->constrained_window_tab_helper()->WillClose(this);
143 142
144 delete this; 143 delete this;
145 } 144 }
146 145
146 bool ConstrainedWindowMac::CanShowConstrainedWindow() {
147 Browser* browser =
148 browser::FindBrowserWithWebContents(tab_contents_->web_contents());
149 if (!browser)
150 return true;
151 return !browser->window()->IsInstantTabShowing();
152 }
153
147 void ConstrainedWindowMac::Realize( 154 void ConstrainedWindowMac::Realize(
148 NSWindowController<ConstrainedWindowSupport>* controller) { 155 NSWindowController<ConstrainedWindowSupport>* controller) {
149 if (!should_be_visible_) 156 if (!should_be_visible_)
150 return; 157 return;
151 158
152 if (controller_ != nil) { 159 if (controller_ != nil) {
153 DCHECK(controller_ == controller); 160 DCHECK(controller_ == controller);
154 return; 161 return;
155 } 162 }
156 DCHECK(controller != nil); 163 DCHECK(controller != nil);
157 164
158 // Remember the controller we're adding ourselves to, so that we can later 165 // Remember the controller we're adding ourselves to, so that we can later
159 // remove us from it. 166 // remove us from it.
160 controller_ = controller; 167 controller_ = controller;
161 [controller_ attachConstrainedWindow:this]; 168 delegate_->RunSheet([controller_ sheetController],
169 [tab_contents_->web_contents()->GetNativeView() superview]);
162 delegate_->set_sheet_open(true); 170 delegate_->set_sheet_open(true);
163 } 171 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698