github.com/ckxng/wakeup@v0.0.0-20190105202853-90356a5f5a15/include/internal/cef_win.h (about) 1 // Copyright (c) 2008 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 31 #ifndef CEF_INCLUDE_INTERNAL_CEF_WIN_H_ 32 #define CEF_INCLUDE_INTERNAL_CEF_WIN_H_ 33 #pragma once 34 35 #if defined(OS_WIN) 36 #include <windows.h> 37 #include "include/internal/cef_types_win.h" 38 #include "include/internal/cef_types_wrappers.h" 39 40 /// 41 // Atomic increment and decrement. 42 /// 43 #define CefAtomicIncrement(p) InterlockedIncrement(p) 44 #define CefAtomicDecrement(p) InterlockedDecrement(p) 45 46 /// 47 // Critical section wrapper. 48 /// 49 class CefCriticalSection { 50 public: 51 CefCriticalSection() { 52 memset(&m_sec, 0, sizeof(CRITICAL_SECTION)); 53 InitializeCriticalSection(&m_sec); 54 } 55 virtual ~CefCriticalSection() { 56 DeleteCriticalSection(&m_sec); 57 } 58 void Lock() { 59 EnterCriticalSection(&m_sec); 60 } 61 void Unlock() { 62 LeaveCriticalSection(&m_sec); 63 } 64 65 CRITICAL_SECTION m_sec; 66 }; 67 68 /// 69 // Handle types. 70 /// 71 #define CefCursorHandle cef_cursor_handle_t 72 #define CefEventHandle cef_event_handle_t 73 #define CefWindowHandle cef_window_handle_t 74 #define CefTextInputContext cef_text_input_context_t 75 76 struct CefMainArgsTraits { 77 typedef cef_main_args_t struct_type; 78 79 static inline void init(struct_type* s) {} 80 static inline void clear(struct_type* s) {} 81 82 static inline void set(const struct_type* src, struct_type* target, 83 bool copy) { 84 target->instance = src->instance; 85 } 86 }; 87 88 // Class representing CefExecuteProcess arguments. 89 class CefMainArgs : public CefStructBase<CefMainArgsTraits> { 90 public: 91 typedef CefStructBase<CefMainArgsTraits> parent; 92 93 CefMainArgs() : parent() {} 94 explicit CefMainArgs(const cef_main_args_t& r) : parent(r) {} 95 explicit CefMainArgs(const CefMainArgs& r) : parent(r) {} 96 explicit CefMainArgs(HINSTANCE hInstance) : parent() { 97 instance = hInstance; 98 } 99 }; 100 101 struct CefWindowInfoTraits { 102 typedef cef_window_info_t struct_type; 103 104 static inline void init(struct_type* s) {} 105 106 static inline void clear(struct_type* s) { 107 cef_string_clear(&s->window_name); 108 } 109 110 static inline void set(const struct_type* src, struct_type* target, 111 bool copy) { 112 target->ex_style = src->ex_style; 113 cef_string_set(src->window_name.str, src->window_name.length, 114 &target->window_name, copy); 115 target->style = src->style; 116 target->x = src->x; 117 target->y = src->y; 118 target->width = src->width; 119 target->height = src->height; 120 target->parent_window = src->parent_window; 121 target->menu = src->menu; 122 target->window = src->window; 123 target->transparent_painting = src->transparent_painting; 124 target->window_rendering_disabled = src->window_rendering_disabled; 125 } 126 }; 127 128 /// 129 // Class representing window information. 130 /// 131 class CefWindowInfo : public CefStructBase<CefWindowInfoTraits> { 132 public: 133 typedef CefStructBase<CefWindowInfoTraits> parent; 134 135 CefWindowInfo() : parent() {} 136 explicit CefWindowInfo(const cef_window_info_t& r) : parent(r) {} 137 explicit CefWindowInfo(const CefWindowInfo& r) : parent(r) {} 138 139 void SetAsChild(HWND hWndParent, RECT windowRect) { 140 style = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_TABSTOP | 141 WS_VISIBLE; 142 parent_window = hWndParent; 143 x = windowRect.left; 144 y = windowRect.top; 145 width = windowRect.right - windowRect.left; 146 height = windowRect.bottom - windowRect.top; 147 } 148 149 void SetAsPopup(HWND hWndParent, const CefString& windowName) { 150 style = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | 151 WS_VISIBLE; 152 parent_window = hWndParent; 153 x = CW_USEDEFAULT; 154 y = CW_USEDEFAULT; 155 width = CW_USEDEFAULT; 156 height = CW_USEDEFAULT; 157 158 cef_string_copy(windowName.c_str(), windowName.length(), &window_name); 159 } 160 161 void SetTransparentPainting(BOOL transparentPainting) { 162 transparent_painting = transparentPainting; 163 } 164 165 void SetAsOffScreen(HWND hWndParent) { 166 window_rendering_disabled = TRUE; 167 parent_window = hWndParent; 168 } 169 }; 170 171 #endif // OS_WIN 172 173 #endif // CEF_INCLUDE_INTERNAL_CEF_WIN_H_