• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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->x = src->x;
85     target->y = src->y;
86     target->width = src->width;
87     target->height = src->height;
88     target->parent_window = src->parent_window;
89     target->menu = src->menu;
90     target->windowless_rendering_enabled = src->windowless_rendering_enabled;
91     target->shared_texture_enabled = src->shared_texture_enabled;
92     target->external_begin_frame_enabled = src->external_begin_frame_enabled;
93     target->window = src->window;
94   }
95 };
96 
97 ///
98 // Class representing window information.
99 ///
100 class CefWindowInfo : public CefStructBase<CefWindowInfoTraits> {
101  public:
102   typedef CefStructBase<CefWindowInfoTraits> parent;
103 
CefWindowInfo()104   CefWindowInfo() : parent() {}
CefWindowInfo(const cef_window_info_t & r)105   explicit CefWindowInfo(const cef_window_info_t& r) : parent(r) {}
CefWindowInfo(const CefWindowInfo & r)106   explicit CefWindowInfo(const CefWindowInfo& r) : parent(r) {}
107 
108   ///
109   // Create the browser as a child window.
110   ///
SetAsChild(CefWindowHandle parent,RECT windowRect)111   void SetAsChild(CefWindowHandle parent, RECT windowRect) {
112     style =
113         WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_TABSTOP | WS_VISIBLE;
114     parent_window = parent;
115     x = windowRect.left;
116     y = windowRect.top;
117     width = windowRect.right - windowRect.left;
118     height = windowRect.bottom - windowRect.top;
119   }
120 
121   ///
122   // Create the browser as a popup window.
123   ///
SetAsPopup(CefWindowHandle parent,const CefString & windowName)124   void SetAsPopup(CefWindowHandle parent, const CefString& windowName) {
125     style =
126         WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE;
127     parent_window = parent;
128     x = CW_USEDEFAULT;
129     y = CW_USEDEFAULT;
130     width = CW_USEDEFAULT;
131     height = CW_USEDEFAULT;
132 
133     cef_string_copy(windowName.c_str(), windowName.length(), &window_name);
134   }
135 
136   ///
137   // Create the browser using windowless (off-screen) rendering. No window
138   // will be created for the browser and all rendering will occur via the
139   // CefRenderHandler interface. The |parent| value will be used to identify
140   // monitor info and to act as the parent window for dialogs, context menus,
141   // etc. If |parent| is not provided then the main screen monitor will be used
142   // and some functionality that requires a parent window may not function
143   // correctly. In order to create windowless browsers the
144   // CefSettings.windowless_rendering_enabled value must be set to true.
145   // Transparent painting is enabled by default but can be disabled by setting
146   // CefBrowserSettings.background_color to an opaque value.
147   ///
SetAsWindowless(CefWindowHandle parent)148   void SetAsWindowless(CefWindowHandle parent) {
149     windowless_rendering_enabled = TRUE;
150     parent_window = parent;
151   }
152 };
153 
154 #endif  // CEF_INCLUDE_INTERNAL_CEF_WIN_H_
155