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" |
11 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_in
fo.h" | 11 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_in
fo.h" |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 // Maps parent windows to sheet controllers. | 15 // Maps parent windows to sheet controllers. |
16 NSMutableDictionary* g_sheetControllers; | 16 NSMutableDictionary* g_sheetControllers; |
17 | 17 |
18 // Get a value for the given window that can be used as a key in a dictionary. | 18 // Get a value for the given window that can be used as a key in a dictionary. |
19 NSValue* GetKeyForParentWindow(NSWindow* parent_window) { | 19 NSValue* GetKeyForParentWindow(NSWindow* parent_window) { |
20 return [NSValue valueWithNonretainedObject:parent_window]; | 20 return [NSValue valueWithNonretainedObject:parent_window]; |
21 } | 21 } |
22 | 22 |
23 } // namespace | 23 } // namespace |
24 | 24 |
25 // An invisible overlay window placed on top of the sheet's parent view. | 25 // An invisible overlay window placed on top of the sheet's parent view. |
26 // This window blocks interaction with the underlying view. | 26 // This window blocks interaction with the underlying view. |
27 @interface CWSheetOverlayWindow : NSWindow { | 27 @interface CWSheetOverlayWindow : NSWindow { |
28 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)onParentViewFrameDidChange:(NSNotification*)note; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 @implementation ConstrainedWindowSheetController | 71 @implementation ConstrainedWindowSheetController |
72 | 72 |
73 + (ConstrainedWindowSheetController*) | 73 + (ConstrainedWindowSheetController*) |
74 controllerForParentWindow:(NSWindow*)parentWindow { | 74 controllerForParentWindow:(NSWindow*)parentWindow { |
75 DCHECK(parentWindow); | 75 DCHECK(parentWindow); |
76 ConstrainedWindowSheetController* controller = | 76 ConstrainedWindowSheetController* controller = |
77 [g_sheetControllers objectForKey:GetKeyForParentWindow(parentWindow)]; | 77 [g_sheetControllers objectForKey:GetKeyForParentWindow(parentWindow)]; |
78 if (controller) | 78 if (controller) |
79 return controller; | 79 return controller; |
80 | 80 |
81 scoped_nsobject<ConstrainedWindowSheetController> new_controller( | 81 base::scoped_nsobject<ConstrainedWindowSheetController> new_controller( |
82 [[ConstrainedWindowSheetController alloc] | 82 [[ConstrainedWindowSheetController alloc] |
83 initWithParentWindow:parentWindow]); | 83 initWithParentWindow:parentWindow]); |
84 if (!g_sheetControllers) | 84 if (!g_sheetControllers) |
85 g_sheetControllers = [[NSMutableDictionary alloc] init]; | 85 g_sheetControllers = [[NSMutableDictionary alloc] init]; |
86 [g_sheetControllers setObject:new_controller | 86 [g_sheetControllers setObject:new_controller |
87 forKey:GetKeyForParentWindow(parentWindow)]; | 87 forKey:GetKeyForParentWindow(parentWindow)]; |
88 return new_controller; | 88 return new_controller; |
89 } | 89 } |
90 | 90 |
91 + (ConstrainedWindowSheetController*) | 91 + (ConstrainedWindowSheetController*) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 // Observer the parent view's frame. | 133 // Observer the parent view's frame. |
134 [parentView setPostsFrameChangedNotifications:YES]; | 134 [parentView setPostsFrameChangedNotifications:YES]; |
135 [[NSNotificationCenter defaultCenter] | 135 [[NSNotificationCenter defaultCenter] |
136 addObserver:self | 136 addObserver:self |
137 selector:@selector(onParentViewFrameDidChange:) | 137 selector:@selector(onParentViewFrameDidChange:) |
138 name:NSViewFrameDidChangeNotification | 138 name:NSViewFrameDidChangeNotification |
139 object:parentView]; | 139 object:parentView]; |
140 | 140 |
141 // Create an invisible overlay window. | 141 // Create an invisible overlay window. |
142 NSRect rect = [self overlayWindowFrameForParentView:parentView]; | 142 NSRect rect = [self overlayWindowFrameForParentView:parentView]; |
143 scoped_nsobject<NSWindow> overlayWindow( | 143 base::scoped_nsobject<NSWindow> overlayWindow( |
144 [[CWSheetOverlayWindow alloc] initWithContentRect:rect | 144 [[CWSheetOverlayWindow alloc] initWithContentRect:rect controller:self]); |
145 controller:self]); | |
146 [parentWindow_ addChildWindow:overlayWindow | 145 [parentWindow_ addChildWindow:overlayWindow |
147 ordered:NSWindowAbove]; | 146 ordered:NSWindowAbove]; |
148 | 147 |
149 // Add an entry for the sheet. | 148 // Add an entry for the sheet. |
150 scoped_nsobject<ConstrainedWindowSheetInfo> info( | 149 base::scoped_nsobject<ConstrainedWindowSheetInfo> info( |
151 [[ConstrainedWindowSheetInfo alloc] initWithSheet:sheet | 150 [[ConstrainedWindowSheetInfo alloc] initWithSheet:sheet |
152 parentView:parentView | 151 parentView:parentView |
153 overlayWindow:overlayWindow]); | 152 overlayWindow:overlayWindow]); |
154 [sheets_ addObject:info]; | 153 [sheets_ addObject:info]; |
155 | 154 |
156 // Show or hide the sheet. | 155 // Show or hide the sheet. |
157 if ([activeView_ isEqual:parentView]) | 156 if ([activeView_ isEqual:parentView]) |
158 [info showSheet]; | 157 [info showSheet]; |
159 else | 158 else |
160 [info hideSheet]; | 159 [info hideSheet]; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 name:NSViewFrameDidChangeNotification | 296 name:NSViewFrameDidChangeNotification |
298 object:[info parentView]]; | 297 object:[info parentView]]; |
299 | 298 |
300 [parentWindow_ removeChildWindow:[info overlayWindow]]; | 299 [parentWindow_ removeChildWindow:[info overlayWindow]]; |
301 [[info sheet] closeSheetWithAnimation:withAnimation]; | 300 [[info sheet] closeSheetWithAnimation:withAnimation]; |
302 [[info overlayWindow] close]; | 301 [[info overlayWindow] close]; |
303 [sheets_ removeObject:info]; | 302 [sheets_ removeObject:info]; |
304 } | 303 } |
305 | 304 |
306 @end | 305 @end |
OLD | NEW |