|
| 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 | +#include "include/cef_base.h" |
| 35 | + |
| 36 | +#if defined(OS_MACOSX) && defined(__OBJC__) |
| 37 | + |
| 38 | +#ifdef BUILDING_CEF_SHARED |
| 39 | + |
| 40 | +// Use the existing CrAppProtocol definition. |
| 41 | +#import "base/message_pump_mac.h" |
| 42 | + |
| 43 | +// Use the existing CrAppControlProtocol definition. |
| 44 | +#import "base/mac/scoped_sending_event.h" |
| 45 | + |
| 46 | +// Use the existing UnderlayableSurface definition. |
| 47 | +#import "ui/base/cocoa/underlay_opengl_hosting_window.h" |
| 48 | + |
| 49 | +// Use the existing empty protocol definitions. |
| 50 | +#import "base/mac/cocoa_protocols.h" |
| 51 | + |
| 52 | +#else // BUILDING_CEF_SHARED |
| 53 | + |
| 54 | +#import <AppKit/AppKit.h> |
| 55 | +#import <Cocoa/Cocoa.h> |
| 56 | + |
| 57 | +// Copy of definition from base/message_pump_mac.h. |
| 58 | +@protocol CrAppProtocol |
| 59 | +// Must return true if -[NSApplication sendEvent:] is currently on the stack. |
| 60 | +- (BOOL)isHandlingSendEvent; |
| 61 | +@end |
| 62 | + |
| 63 | +// Copy of definition from base/mac/scoped_sending_event.h. |
| 64 | +@protocol CrAppControlProtocol<CrAppProtocol> |
| 65 | +- (void)setHandlingSendEvent:(BOOL)handlingSendEvent; |
| 66 | +@end |
| 67 | + |
| 68 | +// Copy of definition from ui/base/cocoa/underlay_opengl_hosting_window.h. |
| 69 | +// Common base class for windows that host a OpenGL surface that renders under |
| 70 | +// the window. Contains methods relating to hole punching so that the OpenGL |
| 71 | +// surface is visible through the window. |
| 72 | +@interface UnderlayOpenGLHostingWindow : NSWindow |
| 73 | +@end |
| 74 | + |
| 75 | +// The Mac OS X 10.6 SDK introduced new protocols used for delegates. These |
| 76 | +// protocol defintions were not present in earlier releases of the Mac OS X |
| 77 | +// SDK. In order to support building against the new SDK, which requires |
| 78 | +// delegates to conform to these protocols, and earlier SDKs, which do not |
| 79 | +// define these protocols at all, this file will provide empty protocol |
| 80 | +// definitions when used with earlier SDK versions. |
| 81 | + |
| 82 | +#if !defined(MAC_OS_X_VERSION_10_6) || \ |
| 83 | +MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6 |
| 84 | + |
| 85 | +#define DEFINE_EMPTY_PROTOCOL(p) \ |
| 86 | +@protocol p \ |
| 87 | +@end |
| 88 | + |
| 89 | +DEFINE_EMPTY_PROTOCOL(NSAlertDelegate) |
| 90 | +DEFINE_EMPTY_PROTOCOL(NSApplicationDelegate) |
| 91 | +DEFINE_EMPTY_PROTOCOL(NSControlTextEditingDelegate) |
| 92 | +DEFINE_EMPTY_PROTOCOL(NSMatrixDelegate) |
| 93 | +DEFINE_EMPTY_PROTOCOL(NSMenuDelegate) |
| 94 | +DEFINE_EMPTY_PROTOCOL(NSOpenSavePanelDelegate) |
| 95 | +DEFINE_EMPTY_PROTOCOL(NSOutlineViewDataSource) |
| 96 | +DEFINE_EMPTY_PROTOCOL(NSOutlineViewDelegate) |
| 97 | +DEFINE_EMPTY_PROTOCOL(NSSpeechSynthesizerDelegate) |
| 98 | +DEFINE_EMPTY_PROTOCOL(NSSplitViewDelegate) |
| 99 | +DEFINE_EMPTY_PROTOCOL(NSTableViewDataSource) |
| 100 | +DEFINE_EMPTY_PROTOCOL(NSTableViewDelegate) |
| 101 | +DEFINE_EMPTY_PROTOCOL(NSTextFieldDelegate) |
| 102 | +DEFINE_EMPTY_PROTOCOL(NSTextViewDelegate) |
| 103 | +DEFINE_EMPTY_PROTOCOL(NSWindowDelegate) |
| 104 | + |
| 105 | +#undef DEFINE_EMPTY_PROTOCOL |
| 106 | + |
| 107 | +#endif |
| 108 | + |
| 109 | +#endif // BUILDING_CEF_SHARED |
| 110 | + |
| 111 | +// All CEF client applications must subclass NSApplication and implement this |
| 112 | +// protocol. |
| 113 | +@protocol CefAppProtocol<CrAppControlProtocol> |
| 114 | +@end |
| 115 | + |
| 116 | +// Controls the state of |isHandlingSendEvent| in the event loop so that it is |
| 117 | +// reset properly. |
| 118 | +class CefScopedSendingEvent { |
| 119 | + public: |
| 120 | + CefScopedSendingEvent() |
| 121 | + : app_(static_cast<NSApplication<CefAppProtocol>*>( |
| 122 | + [NSApplication sharedApplication])), |
| 123 | + handling_([app_ isHandlingSendEvent]) { |
| 124 | + [app_ setHandlingSendEvent:YES]; |
| 125 | + } |
| 126 | + ~CefScopedSendingEvent() { |
| 127 | + [app_ setHandlingSendEvent:handling_]; |
| 128 | + } |
| 129 | + |
| 130 | + private: |
| 131 | + NSApplication<CefAppProtocol>* app_; |
| 132 | + BOOL handling_; |
| 133 | +}; |
| 134 | + |
| 135 | +#endif // defined(OS_MACOSX) && defined(__OBJC__) |
| 136 | + |
| 137 | +#endif // CEF_INCLUDE_CEF_APPLICATION_MAC_H_ |
0 commit comments