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

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

Issue 10823176: Cocoa: Support constrained windows for platform apps (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment Created 8 years, 4 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 #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
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)]) {
Robert Sesek 2012/08/06 22:18:34 nit: indent4 from here
sail 2012/08/09 00:25:54 Done.
113 window_controller = [window windowController];
114 break;
115 }
116 window = [window parentWindow];
jeremya 2012/08/05 22:32:47 If the window is the TopLevelNativeWindow, will it
sail 2012/08/09 00:25:54 No, the parent will be nil.
jeremya 2012/08/09 00:32:48 Then why check here? if [window parentWindow] is a
sail 2012/08/09 00:40:42 The idea is that we want the window controller of
117 }
118
119 DCHECK(window_controller);
jeremya 2012/08/05 22:32:47 Are we guaranteed a controller that conforms to Co
Robert Sesek 2012/08/06 22:18:34 That'll happen with the if-check below because you
120 if ([window_controller canAttachConstrainedWindow])
121 Realize(window_controller);
114 } 122 }
115 123
116 void ConstrainedWindowMac::CloseConstrainedWindow() { 124 void ConstrainedWindowMac::CloseConstrainedWindow() {
117 // Protection against reentrancy, which might otherwise become a problem if 125 // Protection against reentrancy, which might otherwise become a problem if
118 // DeleteDelegate forcibly closes a constrained window in a way that results 126 // DeleteDelegate forcibly closes a constrained window in a way that results
119 // in CloseConstrainedWindow being called again. 127 // in CloseConstrainedWindow being called again.
120 if (closing_) 128 if (closing_)
121 return; 129 return;
122 130
123 closing_ = true; 131 closing_ = true;
124 132
125 // Note: controller_ can be `nil` here if the sheet was never realized. That's 133 // Note: controller_ can be `nil` here if the sheet was never realized. That's
126 // ok. 134 // ok.
127 [controller_ removeConstrainedWindow:this]; 135 [controller_ removeConstrainedWindow:this];
128 delegate_->DeleteDelegate(); 136 delegate_->DeleteDelegate();
129 tab_contents_->constrained_window_tab_helper()->WillClose(this); 137 tab_contents_->constrained_window_tab_helper()->WillClose(this);
130 138
131 delete this; 139 delete this;
132 } 140 }
133 141
134 void ConstrainedWindowMac::Realize(BrowserWindowController* controller) { 142 void ConstrainedWindowMac::Realize(
143 NSWindowController<ConstrainedWindowSupport>* controller) {
135 if (!should_be_visible_) 144 if (!should_be_visible_)
136 return; 145 return;
137 146
138 if (controller_ != nil) { 147 if (controller_ != nil) {
139 DCHECK(controller_ == controller); 148 DCHECK(controller_ == controller);
140 return; 149 return;
141 } 150 }
142 DCHECK(controller != nil); 151 DCHECK(controller != nil);
143 152
144 // Remember the controller we're adding ourselves to, so that we can later 153 // Remember the controller we're adding ourselves to, so that we can later
145 // remove us from it. 154 // remove us from it.
146 controller_ = controller; 155 controller_ = controller;
147 [controller_ attachConstrainedWindow:this]; 156 [controller_ attachConstrainedWindow:this];
148 delegate_->set_sheet_open(true); 157 delegate_->set_sheet_open(true);
149 } 158 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698