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

Side by Side Diff: chrome/browser/ui/cocoa/panels/panel_window_controller_cocoa.mm

Issue 1040993005: [Mac] A more robust way to ensure panels avoid key status on window close (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: static Created 5 years, 8 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
« no previous file with comments | « chrome/browser/ui/cocoa/panels/panel_cocoa_browsertest.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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
49 @interface PanelWindowControllerCocoa (PanelsCanBecomeKey) 54 @interface PanelWindowControllerCocoa (PanelsCanBecomeKey)
50 // Internal helper method for extracting the total number of panel windows 55 // 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. 56 // from the panel manager. Used to decide if panel can become the key window.
52 - (int)numPanels; 57 - (int)numPanels;
53 @end 58 @end
54 59
55 @implementation PanelWindowCocoaImpl 60 @implementation PanelWindowCocoaImpl
56 // The panels cannot be reduced to 3-px windows on the edge of the screen 61 // 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 62 // 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' 63 // of the titlebar visible, so the user could still grab it. We do 'restore'
(...skipping 22 matching lines...) Expand all
81 86
82 BrowserCrApplication* app = base::mac::ObjCCast<BrowserCrApplication>( 87 BrowserCrApplication* app = base::mac::ObjCCast<BrowserCrApplication>(
83 [BrowserCrApplication sharedApplication]); 88 [BrowserCrApplication sharedApplication]);
84 89
85 // A Panel window can become the key window only in limited scenarios. 90 // A Panel window can become the key window only in limited scenarios.
86 // This prevents the system from always preferring a Panel window due 91 // This prevents the system from always preferring a Panel window due
87 // to its higher priority NSWindowLevel when selecting a window to make key. 92 // to its higher priority NSWindowLevel when selecting a window to make key.
88 return ([app isHandlingSendEvent] && [[app currentEvent] window] == self) || 93 return ([app isHandlingSendEvent] && [[app currentEvent] window] == self) ||
89 [controller activationRequestedByPanel] || 94 [controller activationRequestedByPanel] ||
90 [app isCyclingWindows] || 95 [app isCyclingWindows] ||
96 [self isKeyWindow] ||
91 [app previousKeyWindow] == self || 97 [app previousKeyWindow] == self ||
92 [[app windows] count] == static_cast<NSUInteger>([controller numPanels]); 98 [[app windows] count] == static_cast<NSUInteger>([controller numPanels]);
93 } 99 }
94 100
95 - (void)performMiniaturize:(id)sender { 101 - (void)performMiniaturize:(id)sender {
96 [[self windowController] minimizeButtonClicked:0]; 102 [[self windowController] minimizeButtonClicked:0];
97 } 103 }
98 104
99 - (void)mouseMoved:(NSEvent*)event { 105 - (void)mouseMoved:(NSEvent*)event {
100 // Cocoa does not support letting the application determine the edges that 106 // Cocoa does not support letting the application determine the edges that
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 @implementation PanelWindowControllerCocoa 167 @implementation PanelWindowControllerCocoa
162 168
163 - (id)initWithPanel:(PanelCocoa*)window { 169 - (id)initWithPanel:(PanelCocoa*)window {
164 NSString* nibpath = 170 NSString* nibpath =
165 [base::mac::FrameworkBundle() pathForResource:@"Panel" ofType:@"nib"]; 171 [base::mac::FrameworkBundle() pathForResource:@"Panel" ofType:@"nib"];
166 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { 172 if ((self = [super initWithWindowNibPath:nibpath owner:self])) {
167 windowShim_.reset(window); 173 windowShim_.reset(window);
168 animateOnBoundsChange_ = YES; 174 animateOnBoundsChange_ = YES;
169 canBecomeKeyWindow_ = YES; 175 canBecomeKeyWindow_ = YES;
170 activationRequestedByPanel_ = NO; 176 activationRequestedByPanel_ = NO;
177
178 // Leaky singleton. Initialized when the first panel is created.
179 static WindowCloseWatcher* watcher = [[WindowCloseWatcher alloc] init];
180 (void)watcher; // Suppress the unused variable warning.
171 } 181 }
172 return self; 182 return self;
173 } 183 }
174 184
175 - (Panel*)panel { 185 - (Panel*)panel {
176 return windowShim_->panel(); 186 return windowShim_->panel();
177 } 187 }
178 188
179 - (void)awakeFromNib { 189 - (void)awakeFromNib {
180 NSWindow* window = [self window]; 190 NSWindow* window = [self window];
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { 930 - (NSRect)contentRectForFrameRect:(NSRect)frameRect {
921 NSRect contentRect = [[[self window] contentView] convertRect:frameRect 931 NSRect contentRect = [[[self window] contentView] convertRect:frameRect
922 fromView:nil]; 932 fromView:nil];
923 contentRect.size.height -= panel::kTitlebarHeight; 933 contentRect.size.height -= panel::kTitlebarHeight;
924 if (contentRect.size.height < 0) 934 if (contentRect.size.height < 0)
925 contentRect.size.height = 0; 935 contentRect.size.height = 0;
926 return contentRect; 936 return contentRect;
927 } 937 }
928 938
929 @end 939 @end
940
941 @implementation WindowCloseWatcher
942
943 - (id)init {
944 if ((self = [super init])) {
945 [[NSNotificationCenter defaultCenter]
946 addObserver:self
947 selector:@selector(windowWillClose:)
948 name:NSWindowWillCloseNotification
949 object:nil];
950 }
951 return self;
952 }
953
954 - (void)windowWillClose:(NSNotification*)notification {
955 // If it looks like a panel may (refuse to) become key after this window is
956 // closed, then explicitly set the topmost browser window on the active space
957 // to be key (if there is one). Otherwise AppKit will stop looking for windows
958 // to make key once it encounters the panel.
959 id closingWindow = [notification object];
960 BOOL orderNext = NO;
961 for (NSWindow* window : [NSApp orderedWindows]) {
962 if ([window isEqual:closingWindow] || ![window isOnActiveSpace])
963 continue;
964
965 if ([window isKindOfClass:[PanelWindowCocoaImpl class]] &&
966 ![window canBecomeKeyWindow]) {
967 orderNext = YES;
968 continue;
969 }
970
971 if (orderNext) {
972 if (![window canBecomeKeyWindow])
973 continue;
974
975 [window makeKeyWindow];
976 }
977 return;
978 }
979 }
980
981 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/panels/panel_cocoa_browsertest.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698