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

Side by Side Diff: chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_controller.mm

Issue 2551773002: MacViews: Exploring removal of window-modal sheets.
Patch Set: Created 4 years 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
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 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con troller.h" 5 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con troller.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/mac/sdk_forward_declarations.h" 10 #include "base/mac/sdk_forward_declarations.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 - (id)initWithParentWindow:(NSWindow*)parentWindow { 127 - (id)initWithParentWindow:(NSWindow*)parentWindow {
128 if ((self = [super init])) { 128 if ((self = [super init])) {
129 parentWindow_.reset([parentWindow retain]); 129 parentWindow_.reset([parentWindow retain]);
130 sheets_.reset([[NSMutableArray alloc] init]); 130 sheets_.reset([[NSMutableArray alloc] init]);
131 131
132 [[NSNotificationCenter defaultCenter] 132 [[NSNotificationCenter defaultCenter]
133 addObserver:self 133 addObserver:self
134 selector:@selector(onParentWindowWillClose:) 134 selector:@selector(onParentWindowWillClose:)
135 name:NSWindowWillCloseNotification 135 name:NSWindowWillCloseNotification
136 object:parentWindow_]; 136 object:parentWindow_];
137
138 // Observe the parent window's size.
139 [[NSNotificationCenter defaultCenter]
140 addObserver:self
141 selector:@selector(onParentWindowSizeDidChange:)
142 name:NSWindowDidResizeNotification
143 object:parentWindow_];
137 } 144 }
138 return self; 145 return self;
139 } 146 }
140 147
141 - (web_modal::WebContentsModalDialogHost*)dialogHost { 148 - (web_modal::WebContentsModalDialogHost*)dialogHost {
142 if (!dialogHost_) 149 if (!dialogHost_)
143 dialogHost_.reset(new WebContentsModalDialogHostCocoa(self)); 150 dialogHost_.reset(new WebContentsModalDialogHostCocoa(self));
144 return dialogHost_.get(); 151 return dialogHost_.get();
145 } 152 }
146 153
(...skipping 15 matching lines...) Expand all
162 // |parentView|, so sheet info could be created already. 169 // |parentView|, so sheet info could be created already.
163 ConstrainedWindowSheetInfo* existingInfo = 170 ConstrainedWindowSheetInfo* existingInfo =
164 [self findSheetInfoForParentView:activeView_]; 171 [self findSheetInfoForParentView:activeView_];
165 if (existingInfo) { 172 if (existingInfo) {
166 DCHECK([[existingInfo sheet] isEqual:sheet]); 173 DCHECK([[existingInfo sheet] isEqual:sheet]);
167 [self updateSheetPosition:activeView_]; 174 [self updateSheetPosition:activeView_];
168 [existingInfo showSheet]; 175 [existingInfo showSheet];
169 return; 176 return;
170 } 177 }
171 178
172 // Observe the parent window's size.
173 [[NSNotificationCenter defaultCenter]
174 addObserver:self
175 selector:@selector(onParentWindowSizeDidChange:)
176 name:NSWindowDidResizeNotification
177 object:parentWindow_];
178
179 // Create an invisible overlay window. 179 // Create an invisible overlay window.
180 NSRect rect = [self overlayWindowFrameForParentView:parentView]; 180 NSRect rect = [self overlayWindowFrameForParentView:parentView];
181 base::scoped_nsobject<NSWindow> overlayWindow( 181 base::scoped_nsobject<NSWindow> overlayWindow(
182 [[CWSheetOverlayWindow alloc] initWithContentRect:rect controller:self]); 182 [[CWSheetOverlayWindow alloc] initWithContentRect:rect controller:self]);
183 [parentWindow_ addChildWindow:overlayWindow 183 [parentWindow_ addChildWindow:overlayWindow
184 ordered:NSWindowAbove]; 184 ordered:NSWindowAbove];
185 185
186 // Add an entry for the sheet. 186 // Add an entry for the sheet.
187 base::scoped_nsobject<ConstrainedWindowSheetInfo> info( 187 base::scoped_nsobject<ConstrainedWindowSheetInfo> info(
188 [[ConstrainedWindowSheetInfo alloc] initWithSheet:sheet 188 [[ConstrainedWindowSheetInfo alloc] initWithSheet:sheet
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 - (ConstrainedWindowSheetInfo*) 260 - (ConstrainedWindowSheetInfo*)
261 findSheetInfoForSheet:(id<ConstrainedWindowSheet>)sheet { 261 findSheetInfoForSheet:(id<ConstrainedWindowSheet>)sheet {
262 for (ConstrainedWindowSheetInfo* info in sheets_.get()) { 262 for (ConstrainedWindowSheetInfo* info in sheets_.get()) {
263 if ([sheet isEqual:[info sheet]]) 263 if ([sheet isEqual:[info sheet]])
264 return info; 264 return info;
265 } 265 }
266 return NULL; 266 return NULL;
267 } 267 }
268 268
269 - (void)onParentWindowWillClose:(NSNotification*)note { 269 - (void)onParentWindowWillClose:(NSNotification*)note {
270 [[NSNotificationCenter defaultCenter] 270 [[NSNotificationCenter defaultCenter] removeObserver:self];
271 removeObserver:self
272 name:NSWindowWillCloseNotification
273 object:parentWindow_];
274 271
275 // Close all sheets. 272 // Close all sheets.
276 NSArray* sheets = [NSArray arrayWithArray:sheets_]; 273 NSArray* sheets = [NSArray arrayWithArray:sheets_];
277 for (ConstrainedWindowSheetInfo* info in sheets) 274 for (ConstrainedWindowSheetInfo* info in sheets)
278 [self closeSheet:info withAnimation:NO]; 275 [self closeSheet:info withAnimation:NO];
279 276
280 dialogHost_.reset(); 277 dialogHost_.reset();
281 278
282 // Delete this instance. 279 // Delete this instance.
283 [g_sheetControllers removeObjectForKey:GetKeyForParentWindow(parentWindow_)]; 280 [g_sheetControllers removeObjectForKey:GetKeyForParentWindow(parentWindow_)];
284 if (![g_sheetControllers count]) { 281 if (![g_sheetControllers count]) {
285 [g_sheetControllers release]; 282 [g_sheetControllers release];
286 g_sheetControllers = nil; 283 g_sheetControllers = nil;
287 } 284 }
288 } 285 }
289 286
290 - (void)onParentWindowSizeDidChange:(NSNotification*)note { 287 - (void)onParentWindowSizeDidChange:(NSNotification*)note {
291 if (isSheetHiddenForFullscreen_) 288 if (isSheetHiddenForFullscreen_)
292 return; 289 return;
293 290
294 [self updateSheetPosition:activeView_]; 291 [self updateSheetPosition:activeView_];
292 if (dialogHost_)
293 dialogHost_->OnPositionRequiresUpdate();
295 } 294 }
296 295
297 - (void)updateSheetPosition:(NSView*)parentView { 296 - (void)updateSheetPosition:(NSView*)parentView {
298 ConstrainedWindowSheetInfo* info = 297 ConstrainedWindowSheetInfo* info =
299 [self findSheetInfoForParentView:parentView]; 298 [self findSheetInfoForParentView:parentView];
300 if (!info) 299 if (!info)
301 return; 300 return;
302 301
303 NSRect rect = [self overlayWindowFrameForParentView:parentView]; 302 NSRect rect = [self overlayWindowFrameForParentView:parentView];
304 [[info overlayWindow] setFrame:rect display:YES]; 303 [[info overlayWindow] setFrame:rect display:YES];
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 break; 342 break;
344 } 343 }
345 } 344 }
346 } 345 }
347 346
348 - (void)closeSheet:(ConstrainedWindowSheetInfo*)info 347 - (void)closeSheet:(ConstrainedWindowSheetInfo*)info
349 withAnimation:(BOOL)withAnimation { 348 withAnimation:(BOOL)withAnimation {
350 if (![sheets_ containsObject:info]) 349 if (![sheets_ containsObject:info])
351 return; 350 return;
352 351
353 [[NSNotificationCenter defaultCenter]
354 removeObserver:self
355 name:NSWindowDidResizeNotification
356 object:parentWindow_];
357
358 if ([activeView_ isEqual:[info parentView]]) 352 if ([activeView_ isEqual:[info parentView]])
359 activeView_.reset(); 353 activeView_.reset();
360 354
361 [parentWindow_ removeChildWindow:[info overlayWindow]]; 355 [parentWindow_ removeChildWindow:[info overlayWindow]];
362 [[info sheet] closeSheetWithAnimation:withAnimation]; 356 [[info sheet] closeSheetWithAnimation:withAnimation];
363 [[info overlayWindow] close]; 357 [[info overlayWindow] close];
364 [sheets_ removeObject:info]; 358 [sheets_ removeObject:info];
365 } 359 }
366 360
367 @end 361 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm ('k') | chrome/browser/ui/cocoa/profiles/user_manager_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698