| 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 #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 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet.h" | 10 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 base::scoped_nsobject<ConstrainedWindowSheetController> controller_; | 28 base::scoped_nsobject<ConstrainedWindowSheetController> controller_; |
| 29 } | 29 } |
| 30 @end | 30 @end |
| 31 | 31 |
| 32 @interface ConstrainedWindowSheetController () | 32 @interface ConstrainedWindowSheetController () |
| 33 - (id)initWithParentWindow:(NSWindow*)parentWindow; | 33 - (id)initWithParentWindow:(NSWindow*)parentWindow; |
| 34 - (ConstrainedWindowSheetInfo*)findSheetInfoForParentView:(NSView*)parentView; | 34 - (ConstrainedWindowSheetInfo*)findSheetInfoForParentView:(NSView*)parentView; |
| 35 - (ConstrainedWindowSheetInfo*) | 35 - (ConstrainedWindowSheetInfo*) |
| 36 findSheetInfoForSheet:(id<ConstrainedWindowSheet>)sheet; | 36 findSheetInfoForSheet:(id<ConstrainedWindowSheet>)sheet; |
| 37 - (void)onParentWindowWillClose:(NSNotification*)note; | 37 - (void)onParentWindowWillClose:(NSNotification*)note; |
| 38 - (void)onParentViewFrameDidChange:(NSNotification*)note; | 38 - (void)onParentWindowSizeDidChange:(NSNotification*)note; |
| 39 - (void)updateSheetPosition:(NSView*)parentView; | 39 - (void)updateSheetPosition:(NSView*)parentView; |
| 40 - (NSRect)overlayWindowFrameForParentView:(NSView*)parentView; | 40 - (NSRect)overlayWindowFrameForParentView:(NSView*)parentView; |
| 41 - (NSPoint)originForSheetSize:(NSSize)sheetSize | 41 - (NSPoint)originForSheetSize:(NSSize)sheetSize |
| 42 inContainerRect:(NSRect)containerRect; | 42 inContainerRect:(NSRect)containerRect; |
| 43 - (void)onOverlayWindowMouseDown:(CWSheetOverlayWindow*)overlayWindow; | 43 - (void)onOverlayWindowMouseDown:(CWSheetOverlayWindow*)overlayWindow; |
| 44 - (void)closeSheet:(ConstrainedWindowSheetInfo*)info | 44 - (void)closeSheet:(ConstrainedWindowSheetInfo*)info |
| 45 withAnimation:(BOOL)withAnimation; | 45 withAnimation:(BOOL)withAnimation; |
| 46 @end | 46 @end |
| 47 | 47 |
| 48 @implementation CWSheetOverlayWindow | 48 @implementation CWSheetOverlayWindow |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 return self; | 123 return self; |
| 124 } | 124 } |
| 125 | 125 |
| 126 - (void)showSheet:(id<ConstrainedWindowSheet>)sheet | 126 - (void)showSheet:(id<ConstrainedWindowSheet>)sheet |
| 127 forParentView:(NSView*)parentView { | 127 forParentView:(NSView*)parentView { |
| 128 DCHECK(sheet); | 128 DCHECK(sheet); |
| 129 DCHECK(parentView); | 129 DCHECK(parentView); |
| 130 if (!activeView_.get()) | 130 if (!activeView_.get()) |
| 131 activeView_.reset([parentView retain]); | 131 activeView_.reset([parentView retain]); |
| 132 | 132 |
| 133 // Observer the parent view's frame. | 133 // Observe the parent window's size. |
| 134 [parentView setPostsFrameChangedNotifications:YES]; | |
| 135 [[NSNotificationCenter defaultCenter] | 134 [[NSNotificationCenter defaultCenter] |
| 136 addObserver:self | 135 addObserver:self |
| 137 selector:@selector(onParentViewFrameDidChange:) | 136 selector:@selector(onParentWindowSizeDidChange:) |
| 138 name:NSViewFrameDidChangeNotification | 137 name:NSWindowDidResizeNotification |
| 139 object:parentView]; | 138 object:parentWindow_]; |
| 140 | 139 |
| 141 // Create an invisible overlay window. | 140 // Create an invisible overlay window. |
| 142 NSRect rect = [self overlayWindowFrameForParentView:parentView]; | 141 NSRect rect = [self overlayWindowFrameForParentView:parentView]; |
| 143 base::scoped_nsobject<NSWindow> overlayWindow( | 142 base::scoped_nsobject<NSWindow> overlayWindow( |
| 144 [[CWSheetOverlayWindow alloc] initWithContentRect:rect controller:self]); | 143 [[CWSheetOverlayWindow alloc] initWithContentRect:rect controller:self]); |
| 145 [parentWindow_ addChildWindow:overlayWindow | 144 [parentWindow_ addChildWindow:overlayWindow |
| 146 ordered:NSWindowAbove]; | 145 ordered:NSWindowAbove]; |
| 147 | 146 |
| 148 // Add an entry for the sheet. | 147 // Add an entry for the sheet. |
| 149 base::scoped_nsobject<ConstrainedWindowSheetInfo> info( | 148 base::scoped_nsobject<ConstrainedWindowSheetInfo> info( |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 [self closeSheet:info withAnimation:NO]; | 220 [self closeSheet:info withAnimation:NO]; |
| 222 | 221 |
| 223 // Delete this instance. | 222 // Delete this instance. |
| 224 [g_sheetControllers removeObjectForKey:GetKeyForParentWindow(parentWindow_)]; | 223 [g_sheetControllers removeObjectForKey:GetKeyForParentWindow(parentWindow_)]; |
| 225 if (![g_sheetControllers count]) { | 224 if (![g_sheetControllers count]) { |
| 226 [g_sheetControllers release]; | 225 [g_sheetControllers release]; |
| 227 g_sheetControllers = nil; | 226 g_sheetControllers = nil; |
| 228 } | 227 } |
| 229 } | 228 } |
| 230 | 229 |
| 231 - (void)onParentViewFrameDidChange:(NSNotification*)note { | 230 - (void)onParentWindowSizeDidChange:(NSNotification*)note { |
| 232 NSView* parentView = [note object]; | 231 [self updateSheetPosition:activeView_]; |
| 233 if (![activeView_ isEqual:parentView]) | |
| 234 return; | |
| 235 [self updateSheetPosition:parentView]; | |
| 236 } | 232 } |
| 237 | 233 |
| 238 - (void)updateSheetPosition:(NSView*)parentView { | 234 - (void)updateSheetPosition:(NSView*)parentView { |
| 239 ConstrainedWindowSheetInfo* info = | 235 ConstrainedWindowSheetInfo* info = |
| 240 [self findSheetInfoForParentView:parentView]; | 236 [self findSheetInfoForParentView:parentView]; |
| 241 if (!info) | 237 if (!info) |
| 242 return; | 238 return; |
| 243 | 239 |
| 244 NSRect rect = [self overlayWindowFrameForParentView:parentView]; | 240 NSRect rect = [self overlayWindowFrameForParentView:parentView]; |
| 245 [[info overlayWindow] setFrame:rect display:YES]; | 241 [[info overlayWindow] setFrame:rect display:YES]; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 } | 282 } |
| 287 } | 283 } |
| 288 | 284 |
| 289 - (void)closeSheet:(ConstrainedWindowSheetInfo*)info | 285 - (void)closeSheet:(ConstrainedWindowSheetInfo*)info |
| 290 withAnimation:(BOOL)withAnimation { | 286 withAnimation:(BOOL)withAnimation { |
| 291 if (![sheets_ containsObject:info]) | 287 if (![sheets_ containsObject:info]) |
| 292 return; | 288 return; |
| 293 | 289 |
| 294 [[NSNotificationCenter defaultCenter] | 290 [[NSNotificationCenter defaultCenter] |
| 295 removeObserver:self | 291 removeObserver:self |
| 296 name:NSViewFrameDidChangeNotification | 292 name:NSWindowDidResizeNotification |
| 297 object:[info parentView]]; | 293 object:parentWindow_]; |
| 298 | 294 |
| 299 [parentWindow_ removeChildWindow:[info overlayWindow]]; | 295 [parentWindow_ removeChildWindow:[info overlayWindow]]; |
| 300 [[info sheet] closeSheetWithAnimation:withAnimation]; | 296 [[info sheet] closeSheetWithAnimation:withAnimation]; |
| 301 [[info overlayWindow] close]; | 297 [[info overlayWindow] close]; |
| 302 [sheets_ removeObject:info]; | 298 [sheets_ removeObject:info]; |
| 303 } | 299 } |
| 304 | 300 |
| 305 @end | 301 @end |
| OLD | NEW |