1// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights 2// reserved. Use of this source code is governed by a BSD-style license that 3// can be found in the LICENSE file. 4 5#include "tests/cefclient/browser/temp_window_mac.h" 6 7#include <Cocoa/Cocoa.h> 8 9#include "include/base/cef_logging.h" 10#include "include/cef_app.h" 11 12namespace client { 13 14namespace { 15 16TempWindowMac* g_temp_window = nullptr; 17 18} // namespace 19 20class TempWindowMacImpl { 21 public: 22 TempWindowMacImpl() { 23 // Create a borderless non-visible 1x1 window. 24 window_ = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 1, 1) 25 styleMask:NSBorderlessWindowMask 26 backing:NSBackingStoreBuffered 27 defer:NO]; 28 CHECK(window_); 29 } 30 ~TempWindowMacImpl() { 31 DCHECK(window_); 32 [window_ close]; 33 } 34 35 private: 36 NSWindow* window_; 37 38 friend class TempWindowMac; 39}; 40 41TempWindowMac::TempWindowMac() { 42 DCHECK(!g_temp_window); 43 impl_.reset(new TempWindowMacImpl); 44 g_temp_window = this; 45} 46 47TempWindowMac::~TempWindowMac() { 48 impl_.reset(); 49 g_temp_window = nullptr; 50} 51 52// static 53CefWindowHandle TempWindowMac::GetWindowHandle() { 54 DCHECK(g_temp_window); 55 return CAST_NSVIEW_TO_CEF_WINDOW_HANDLE( 56 g_temp_window->impl_->window_.contentView); 57} 58 59} // namespace client 60