Home | History | Annotate | Download | only in cocoa
      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
      3 // found in the LICENSE file.
      4 
      5 #import <Cocoa/Cocoa.h>
      6 
      7 #include "ui/base/cocoa/focus_window_set.h"
      8 
      9 namespace ui {
     10 
     11 void FocusWindowSet(const std::set<NSWindow*>& windows) {
     12   NSArray* ordered_windows = [NSApp orderedWindows];
     13   NSWindow* frontmost_window = nil;
     14   NSWindow* frontmost_miniaturized_window = nil;
     15   for (int i = [ordered_windows count] - 1; i >= 0; i--) {
     16     NSWindow* win = [ordered_windows objectAtIndex:i];
     17     if (windows.find(win) != windows.end()) {
     18       if ([win isVisible]) {
     19         [win orderFront:nil];
     20         frontmost_window = win;
     21       } else if ([win isMiniaturized]) {
     22         frontmost_miniaturized_window = win;
     23       }
     24     }
     25   }
     26   if (!frontmost_window && frontmost_miniaturized_window) {
     27     [frontmost_miniaturized_window deminiaturize:nil];
     28     frontmost_window = frontmost_miniaturized_window;
     29   }
     30   if (frontmost_window) {
     31     [NSApp activateIgnoringOtherApps:YES];
     32     [frontmost_window makeMainWindow];
     33     [frontmost_window makeKeyWindow];
     34   }
     35 }
     36 
     37 }  // namespace ui
     38