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

Side by Side Diff: ui/base/cocoa/focus_window_set.mm

Issue 37253004: Mac: delay window raising until space transitions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Missing comma Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/app_controller_mac.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #include "ui/base/cocoa/focus_window_set.h" 7 #include "ui/base/cocoa/focus_window_set.h"
8 8
9 namespace ui { 9 namespace ui {
10 10
11 // This attempts to match OS X's native behavior, namely that a window 11 // This attempts to match OS X's native behavior, namely that a window
12 // is only ever deminiaturized if ALL windows on ALL workspaces are 12 // is only ever deminiaturized if ALL windows on ALL workspaces are
13 // miniaturized. (This callback runs before AppKit picks its own 13 // miniaturized. (This callback runs before AppKit picks its own
14 // window to deminiaturize, so we get to pick one from the right set.) 14 // window to deminiaturize, so we get to pick one from the right set.)
15 // 15 //
16 // In addition, limit to the windows on the current 16 // In addition, limit to the windows on the current
17 // workspace. Otherwise we jump spaces haphazardly. 17 // workspace. Otherwise we jump spaces haphazardly.
18 // 18 //
19 // NOTE: This is not perfect. If clicking the dock icon resulted in 19 // NOTE: If this is called in the
20 // switching spaces, isOnActiveSpace gives the answer for the PREVIOUS 20 // applicationShouldHandleReopen:hasVisibleWindows: hook when clicking
21 // space. This means that we actually raise the wrong space's 21 // the dock icon, and that caused OS X to begin switch spaces,
22 // windows. This seems to still work okay. 22 // isOnActiveSpace gives the answer for the PREVIOUS space. This means
23 // that we actually raise and focus the wrong space's windows, leaving
24 // the new key window off-screen. To detect this, check if the key
25 // window prior to calling is on an active space.
23 // 26 //
24 // However, if we decide to deminiaturize a window instead, that 27 // Also, if we decide to deminiaturize a window during a space switch,
25 // results in switching spaces and switching back. Fortunately, this 28 // that can switch spaces and then switch back. Fortunately, this only
26 // only happens if, say, space 1 contains an app, space 2 contains a 29 // happens if, say, space 1 contains an app, space 2 contains a
27 // miniaturized browser. We click the icon, OS X switches to space 1, 30 // miniaturized browser. We click the icon, OS X switches to space 1,
28 // we deminiaturize the browser, and that triggers switching back. 31 // we deminiaturize the browser, and that triggers switching back.
32 //
33 // TODO(davidben): To limit those cases, consider preferentially
34 // deminiaturizing a window on the current space.
29 void FocusWindowSet(const std::set<NSWindow*>& windows, 35 void FocusWindowSet(const std::set<NSWindow*>& windows,
30 bool allow_workspace_switch) { 36 bool allow_workspace_switch) {
31 NSArray* ordered_windows = [NSApp orderedWindows]; 37 NSArray* ordered_windows = [NSApp orderedWindows];
32 NSWindow* frontmost_window = nil; 38 NSWindow* frontmost_window = nil;
33 NSWindow* frontmost_window_all_spaces = nil; 39 NSWindow* frontmost_window_all_spaces = nil;
34 NSWindow* frontmost_miniaturized_window = nil; 40 NSWindow* frontmost_miniaturized_window = nil;
35 bool all_miniaturized = true; 41 bool all_miniaturized = true;
36 for (int i = [ordered_windows count] - 1; i >= 0; i--) { 42 for (int i = [ordered_windows count] - 1; i >= 0; i--) {
37 NSWindow* win = [ordered_windows objectAtIndex:i]; 43 NSWindow* win = [ordered_windows objectAtIndex:i];
38 if (windows.find(win) != windows.end()) { 44 if (windows.find(win) != windows.end()) {
(...skipping 20 matching lines...) Expand all
59 [frontmost_window orderFront:nil]; 65 [frontmost_window orderFront:nil];
60 } 66 }
61 if (frontmost_window) { 67 if (frontmost_window) {
62 [NSApp activateIgnoringOtherApps:YES]; 68 [NSApp activateIgnoringOtherApps:YES];
63 [frontmost_window makeMainWindow]; 69 [frontmost_window makeMainWindow];
64 [frontmost_window makeKeyWindow]; 70 [frontmost_window makeKeyWindow];
65 } 71 }
66 } 72 }
67 73
68 } // namespace ui 74 } // namespace ui
OLDNEW
« no previous file with comments | « chrome/browser/app_controller_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698