1 // Copyright (c) 2011 Marshall A. Greenblatt. All rights reserved. 2 // 3 // Redistribution and use in source and binary forms, with or without 4 // modification, are permitted provided that the following conditions are 5 // met: 6 // 7 // * Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // * Redistributions in binary form must reproduce the above 10 // copyright notice, this list of conditions and the following disclaimer 11 // in the documentation and/or other materials provided with the 12 // distribution. 13 // * Neither the name of Google Inc. nor the name Chromium Embedded 14 // Framework nor the names of its contributors may be used to endorse 15 // or promote products derived from this software without specific prior 16 // written permission. 17 // 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 30 #ifndef CEF_INCLUDE_CEF_APPLICATION_MAC_H_ 31 #define CEF_INCLUDE_CEF_APPLICATION_MAC_H_ 32 #pragma once 33 34 #ifdef __cplusplus 35 #include "include/cef_base.h" 36 #endif // __cplusplus 37 38 #if defined(OS_MAC) && defined(__OBJC__) 39 40 #ifdef USING_CHROMIUM_INCLUDES 41 42 // Use the existing CrAppControlProtocol definition. 43 #import "base/mac/scoped_sending_event.h" 44 45 // Use the existing CrAppProtocol definition. 46 #import "base/message_loop/message_pump_mac.h" 47 48 // Use the existing UnderlayableSurface definition. 49 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" 50 51 // Use the existing empty protocol definitions. 52 #import "base/mac/cocoa_protocols.h" 53 54 // Use the existing empty protocol definitions. 55 #import "base/mac/sdk_forward_declarations.h" 56 57 #else // USING_CHROMIUM_INCLUDES 58 59 #import <AppKit/AppKit.h> 60 #import <Cocoa/Cocoa.h> 61 62 // Copy of definition from base/message_loop/message_pump_mac.h. 63 @protocol CrAppProtocol 64 // Must return true if -[NSApplication sendEvent:] is currently on the stack. 65 - (BOOL)isHandlingSendEvent; 66 @end 67 68 // Copy of definition from base/mac/scoped_sending_event.h. 69 @protocol CrAppControlProtocol<CrAppProtocol> 70 - (void)setHandlingSendEvent:(BOOL)handlingSendEvent; 71 @end 72 73 // Copy of definition from ui/base/cocoa/underlay_opengl_hosting_window.h. 74 // Common base class for windows that host a OpenGL surface that renders under 75 // the window. Contains methods relating to hole punching so that the OpenGL 76 // surface is visible through the window. 77 @interface UnderlayOpenGLHostingWindow : NSWindow 78 @end 79 80 #endif // USING_CHROMIUM_INCLUDES 81 82 // All CEF client applications must subclass NSApplication and implement this 83 // protocol. 84 @protocol CefAppProtocol<CrAppControlProtocol> 85 @end 86 87 #ifdef __cplusplus 88 89 // Controls the state of |isHandlingSendEvent| in the event loop so that it is 90 // reset properly. 91 class CefScopedSendingEvent { 92 public: CefScopedSendingEvent()93 CefScopedSendingEvent() 94 : app_(static_cast<NSApplication<CefAppProtocol>*>( 95 [NSApplication sharedApplication])), 96 handling_([app_ isHandlingSendEvent]) { 97 [app_ setHandlingSendEvent:YES]; 98 } ~CefScopedSendingEvent()99 ~CefScopedSendingEvent() { [app_ setHandlingSendEvent:handling_]; } 100 101 private: 102 NSApplication<CefAppProtocol>* app_; 103 BOOL handling_; 104 }; 105 106 #endif // __cplusplus 107 108 #endif // defined(OS_MAC) && defined(__OBJC__) 109 110 #endif // CEF_INCLUDE_CEF_APPLICATION_MAC_H_ 111