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 #include "chrome/browser/ui/cocoa/panels/panel_window_controller_cocoa.h" | 5 #include "chrome/browser/ui/cocoa/panels/panel_window_controller_cocoa.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 28 matching lines...) Expand all Loading... | |
39 | 39 |
40 using content::WebContents; | 40 using content::WebContents; |
41 | 41 |
42 const int kMinimumWindowSize = 1; | 42 const int kMinimumWindowSize = 1; |
43 const double kBoundsAnimationSpeedPixelsPerSecond = 1000; | 43 const double kBoundsAnimationSpeedPixelsPerSecond = 1000; |
44 const double kBoundsAnimationMaxDurationSeconds = 0.18; | 44 const double kBoundsAnimationMaxDurationSeconds = 0.18; |
45 | 45 |
46 // Edge thickness to trigger user resizing via system, in screen pixels. | 46 // Edge thickness to trigger user resizing via system, in screen pixels. |
47 const double kWidthOfMouseResizeArea = 15.0; | 47 const double kWidthOfMouseResizeArea = 15.0; |
48 | 48 |
49 // Notification observer to prevent panels becoming key when windows are closed. | |
50 @interface WindowCloseWatcher : NSObject | |
51 - (void)windowWillClose:(NSNotification*)notification; | |
52 @end | |
53 | |
54 namespace { | |
55 | |
56 // Leaky singleton. Initialized when the first panel is created. | |
57 WindowCloseWatcher* g_window_close_watcher = nil; | |
58 | |
59 } | |
60 | |
49 @interface PanelWindowControllerCocoa (PanelsCanBecomeKey) | 61 @interface PanelWindowControllerCocoa (PanelsCanBecomeKey) |
50 // Internal helper method for extracting the total number of panel windows | 62 // Internal helper method for extracting the total number of panel windows |
51 // from the panel manager. Used to decide if panel can become the key window. | 63 // from the panel manager. Used to decide if panel can become the key window. |
52 - (int)numPanels; | 64 - (int)numPanels; |
53 @end | 65 @end |
54 | 66 |
55 @implementation PanelWindowCocoaImpl | 67 @implementation PanelWindowCocoaImpl |
56 // The panels cannot be reduced to 3-px windows on the edge of the screen | 68 // The panels cannot be reduced to 3-px windows on the edge of the screen |
57 // active area (above Dock). Default constraining logic makes at least a height | 69 // active area (above Dock). Default constraining logic makes at least a height |
58 // of the titlebar visible, so the user could still grab it. We do 'restore' | 70 // of the titlebar visible, so the user could still grab it. We do 'restore' |
(...skipping 22 matching lines...) Expand all Loading... | |
81 | 93 |
82 BrowserCrApplication* app = base::mac::ObjCCast<BrowserCrApplication>( | 94 BrowserCrApplication* app = base::mac::ObjCCast<BrowserCrApplication>( |
83 [BrowserCrApplication sharedApplication]); | 95 [BrowserCrApplication sharedApplication]); |
84 | 96 |
85 // A Panel window can become the key window only in limited scenarios. | 97 // A Panel window can become the key window only in limited scenarios. |
86 // This prevents the system from always preferring a Panel window due | 98 // This prevents the system from always preferring a Panel window due |
87 // to its higher priority NSWindowLevel when selecting a window to make key. | 99 // to its higher priority NSWindowLevel when selecting a window to make key. |
88 return ([app isHandlingSendEvent] && [[app currentEvent] window] == self) || | 100 return ([app isHandlingSendEvent] && [[app currentEvent] window] == self) || |
89 [controller activationRequestedByPanel] || | 101 [controller activationRequestedByPanel] || |
90 [app isCyclingWindows] || | 102 [app isCyclingWindows] || |
103 [self isKeyWindow] || | |
tapted
2015/03/31 11:34:10
This case is encountered when there are multiple p
| |
91 [app previousKeyWindow] == self || | 104 [app previousKeyWindow] == self || |
92 [[app windows] count] == static_cast<NSUInteger>([controller numPanels]); | 105 [[app windows] count] == static_cast<NSUInteger>([controller numPanels]); |
93 } | 106 } |
94 | 107 |
95 - (void)performMiniaturize:(id)sender { | 108 - (void)performMiniaturize:(id)sender { |
96 [[self windowController] minimizeButtonClicked:0]; | 109 [[self windowController] minimizeButtonClicked:0]; |
97 } | 110 } |
98 | 111 |
99 - (void)mouseMoved:(NSEvent*)event { | 112 - (void)mouseMoved:(NSEvent*)event { |
100 // Cocoa does not support letting the application determine the edges that | 113 // Cocoa does not support letting the application determine the edges that |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 @implementation PanelWindowControllerCocoa | 174 @implementation PanelWindowControllerCocoa |
162 | 175 |
163 - (id)initWithPanel:(PanelCocoa*)window { | 176 - (id)initWithPanel:(PanelCocoa*)window { |
164 NSString* nibpath = | 177 NSString* nibpath = |
165 [base::mac::FrameworkBundle() pathForResource:@"Panel" ofType:@"nib"]; | 178 [base::mac::FrameworkBundle() pathForResource:@"Panel" ofType:@"nib"]; |
166 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { | 179 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { |
167 windowShim_.reset(window); | 180 windowShim_.reset(window); |
168 animateOnBoundsChange_ = YES; | 181 animateOnBoundsChange_ = YES; |
169 canBecomeKeyWindow_ = YES; | 182 canBecomeKeyWindow_ = YES; |
170 activationRequestedByPanel_ = NO; | 183 activationRequestedByPanel_ = NO; |
184 | |
185 if (!g_window_close_watcher) | |
Mark Mentovai
2015/03/31 13:13:31
Doesn’t need to be global. You can just write
s
tapted
2015/03/31 23:55:29
Ooh - I didn't think of that. It results in
`erro
| |
186 g_window_close_watcher = [[WindowCloseWatcher alloc] init]; | |
171 } | 187 } |
172 return self; | 188 return self; |
173 } | 189 } |
174 | 190 |
175 - (Panel*)panel { | 191 - (Panel*)panel { |
176 return windowShim_->panel(); | 192 return windowShim_->panel(); |
177 } | 193 } |
178 | 194 |
179 - (void)awakeFromNib { | 195 - (void)awakeFromNib { |
180 NSWindow* window = [self window]; | 196 NSWindow* window = [self window]; |
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
920 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { | 936 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { |
921 NSRect contentRect = [[[self window] contentView] convertRect:frameRect | 937 NSRect contentRect = [[[self window] contentView] convertRect:frameRect |
922 fromView:nil]; | 938 fromView:nil]; |
923 contentRect.size.height -= panel::kTitlebarHeight; | 939 contentRect.size.height -= panel::kTitlebarHeight; |
924 if (contentRect.size.height < 0) | 940 if (contentRect.size.height < 0) |
925 contentRect.size.height = 0; | 941 contentRect.size.height = 0; |
926 return contentRect; | 942 return contentRect; |
927 } | 943 } |
928 | 944 |
929 @end | 945 @end |
946 | |
947 @implementation WindowCloseWatcher | |
948 | |
949 - (id)init { | |
950 if ((self = [super init])) { | |
951 [[NSNotificationCenter defaultCenter] | |
952 addObserver:self | |
953 selector:@selector(windowWillClose:) | |
954 name:NSWindowWillCloseNotification | |
955 object:nil]; | |
956 } | |
957 return self; | |
958 } | |
959 | |
960 - (void)windowWillClose:(NSNotification*)notification { | |
961 // If it looks like a panel may (refuse to) become key after this window is | |
962 // closed, then explicitly set the topmost browser window on the active space | |
963 // to be key (if there is one). Otherwise AppKit will stop looking for windows | |
964 // to make key once it encounters the panel. | |
965 id closingWindow = [notification object]; | |
966 BOOL orderNext = NO; | |
967 for (NSWindow* window : [NSApp orderedWindows]) { | |
968 if ([window isEqual:closingWindow] || ![window isOnActiveSpace]) | |
969 continue; | |
970 | |
971 if ([window isKindOfClass:[PanelWindowCocoaImpl class]] && | |
972 ![window canBecomeKeyWindow]) { | |
973 orderNext = YES; | |
974 continue; | |
975 } | |
976 | |
977 if (orderNext) { | |
978 if (![window canBecomeKeyWindow]) | |
979 continue; | |
980 | |
981 [window makeKeyWindow]; | |
982 } | |
983 return; | |
984 } | |
985 } | |
986 | |
987 @end | |
OLD | NEW |