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

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

Issue 23737003: Mac: Fix window raising for multiple desktops (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix PlatformAppReopenWithWindows test Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/app_controller_mac_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 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
12 // is only ever deminiaturized if ALL windows on ALL workspaces are
13 // miniaturized. (This callback runs before AppKit picks its own
14 // window to deminiaturize, so we get to pick one from the right set.)
15 //
16 // In addition, limit to the windows on the current
17 // workspace. Otherwise we jump spaces haphazardly.
18 //
19 // NOTE: This is not perfect. If clicking the dock icon resulted in
20 // switching spaces, isOnActiveSpace gives the answer for the PREVIOUS
21 // space. This means that we actually raise the wrong space's
22 // windows. This seems to still work okay.
23 //
24 // However, if we decide to deminiaturize a window instead, that
25 // results in switching spaces and switching back. Fortunately, this
26 // only 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,
28 // we deminiaturize the browser, and that triggers switching back.
11 void FocusWindowSet(const std::set<NSWindow*>& windows) { 29 void FocusWindowSet(const std::set<NSWindow*>& windows) {
12 NSArray* ordered_windows = [NSApp orderedWindows]; 30 NSArray* ordered_windows = [NSApp orderedWindows];
13 NSWindow* frontmost_window = nil; 31 NSWindow* frontmost_window = nil;
14 NSWindow* frontmost_miniaturized_window = nil; 32 NSWindow* frontmost_miniaturized_window = nil;
33 bool all_miniaturized = true;
15 for (int i = [ordered_windows count] - 1; i >= 0; i--) { 34 for (int i = [ordered_windows count] - 1; i >= 0; i--) {
16 NSWindow* win = [ordered_windows objectAtIndex:i]; 35 NSWindow* win = [ordered_windows objectAtIndex:i];
17 if (windows.find(win) != windows.end()) { 36 if (windows.find(win) != windows.end()) {
18 if ([win isVisible]) { 37 if ([win isMiniaturized]) {
19 [win orderFront:nil];
20 frontmost_window = win;
21 } else if ([win isMiniaturized]) {
22 frontmost_miniaturized_window = win; 38 frontmost_miniaturized_window = win;
39 } else if ([win isVisible]) {
40 all_miniaturized = false;
jackhou1 2013/09/02 06:07:23 Could this be: } else if ([win isVisible])
davidben 2013/09/03 20:01:53 That seems to cause it to get a bit confused. If f
41 if ([win isOnActiveSpace]) {
42 [win orderFront:nil];
43 frontmost_window = win;
44 }
23 } 45 }
24 } 46 }
25 } 47 }
26 if (!frontmost_window && frontmost_miniaturized_window) { 48 if (all_miniaturized && frontmost_miniaturized_window) {
27 [frontmost_miniaturized_window deminiaturize:nil]; 49 [frontmost_miniaturized_window deminiaturize:nil];
28 frontmost_window = frontmost_miniaturized_window; 50 frontmost_window = frontmost_miniaturized_window;
29 } 51 }
30 if (frontmost_window) { 52 if (frontmost_window) {
31 [NSApp activateIgnoringOtherApps:YES]; 53 [NSApp activateIgnoringOtherApps:YES];
32 [frontmost_window makeMainWindow]; 54 [frontmost_window makeMainWindow];
33 [frontmost_window makeKeyWindow]; 55 [frontmost_window makeKeyWindow];
34 } 56 }
35 } 57 }
36 58
37 } // namespace ui 59 } // namespace ui
OLDNEW
« no previous file with comments | « chrome/browser/app_controller_mac_browsertest.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698