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 #ifndef CEF_INCLUDE_INTERNAL_CEF_WIN_H_ 31 #define CEF_INCLUDE_INTERNAL_CEF_WIN_H_ 32 #pragma once 33 34 #include "include/internal/cef_types_win.h" 35 #include "include/internal/cef_types_wrappers.h" 36 37 /// 38 // Handle types. 39 /// 40 #define CefCursorHandle cef_cursor_handle_t 41 #define CefEventHandle cef_event_handle_t 42 #define CefWindowHandle cef_window_handle_t 43 44 struct CefMainArgsTraits { 45 typedef cef_main_args_t struct_type; 46 initCefMainArgsTraits47 static inline void init(struct_type* s) {} clearCefMainArgsTraits48 static inline void clear(struct_type* s) {} 49 setCefMainArgsTraits50 static inline void set(const struct_type* src, 51 struct_type* target, 52 bool copy) { 53 target->instance = src->instance; 54 } 55 }; 56 57 // Class representing CefExecuteProcess arguments. 58 class CefMainArgs : public CefStructBase<CefMainArgsTraits> { 59 public: 60 typedef CefStructBase<CefMainArgsTraits> parent; 61 CefMainArgs()62 CefMainArgs() : parent() {} CefMainArgs(const cef_main_args_t & r)63 explicit CefMainArgs(const cef_main_args_t& r) : parent(r) {} CefMainArgs(const CefMainArgs & r)64 explicit CefMainArgs(const CefMainArgs& r) : parent(r) {} CefMainArgs(HINSTANCE hInstance)65 explicit CefMainArgs(HINSTANCE hInstance) : parent() { instance = hInstance; } 66 }; 67 68 struct CefWindowInfoTraits { 69 typedef cef_window_info_t struct_type; 70 initCefWindowInfoTraits71 static inline void init(struct_type* s) {} 72 clearCefWindowInfoTraits73 static inline void clear(struct_type* s) { 74 cef_string_clear(&s->window_name); 75 } 76 setCefWindowInfoTraits77 static inline void set(const struct_type* src, 78 struct_type* target, 79 bool copy) { 80 target->ex_style = src->ex_style; 81 cef_string_set(src->window_name.str, src->window_name.length, 82 &target->window_name, copy); 83 target->style = src->style; 84 target->bounds = src->bounds; 85 target->parent_window = src->parent_window; 86 target->menu = src->menu; 87 target->windowless_rendering_enabled = src->windowless_rendering_enabled; 88 target->shared_texture_enabled = src->shared_texture_enabled; 89 target->external_begin_frame_enabled = src->external_begin_frame_enabled; 90 target->window = src->window; 91 } 92 }; 93 94 /// 95 // Class representing window information. 96 /// 97 class CefWindowInfo : public CefStructBase<CefWindowInfoTraits> { 98 public: 99 typedef CefStructBase<CefWindowInfoTraits> parent; 100 CefWindowInfo()101 CefWindowInfo() : parent() {} CefWindowInfo(const cef_window_info_t & r)102 explicit CefWindowInfo(const cef_window_info_t& r) : parent(r) {} CefWindowInfo(const CefWindowInfo & r)103 explicit CefWindowInfo(const CefWindowInfo& r) : parent(r) {} 104 105 /// 106 // Create the browser as a child window. 107 /// SetAsChild(CefWindowHandle parent,const CefRect & windowBounds)108 void SetAsChild(CefWindowHandle parent, const CefRect& windowBounds) { 109 style = 110 WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_TABSTOP | WS_VISIBLE; 111 parent_window = parent; 112 bounds = windowBounds; 113 } 114 115 /// 116 // Create the browser as a popup window. 117 /// SetAsPopup(CefWindowHandle parent,const CefString & windowName)118 void SetAsPopup(CefWindowHandle parent, const CefString& windowName) { 119 style = 120 WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE; 121 parent_window = parent; 122 bounds.x = CW_USEDEFAULT; 123 bounds.y = CW_USEDEFAULT; 124 bounds.width = CW_USEDEFAULT; 125 bounds.height = CW_USEDEFAULT; 126 127 cef_string_copy(windowName.c_str(), windowName.length(), &window_name); 128 } 129 130 /// 131 // Create the browser using windowless (off-screen) rendering. No window 132 // will be created for the browser and all rendering will occur via the 133 // CefRenderHandler interface. The |parent| value will be used to identify 134 // monitor info and to act as the parent window for dialogs, context menus, 135 // etc. If |parent| is not provided then the main screen monitor will be used 136 // and some functionality that requires a parent window may not function 137 // correctly. In order to create windowless browsers the 138 // CefSettings.windowless_rendering_enabled value must be set to true. 139 // Transparent painting is enabled by default but can be disabled by setting 140 // CefBrowserSettings.background_color to an opaque value. 141 /// SetAsWindowless(CefWindowHandle parent)142 void SetAsWindowless(CefWindowHandle parent) { 143 windowless_rendering_enabled = TRUE; 144 parent_window = parent; 145 } 146 }; 147 148 #endif // CEF_INCLUDE_INTERNAL_CEF_WIN_H_ 149