1 // Copyright (c) 2016 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 // 32 // The contents of this file must follow a specific format in order to 33 // support the CEF translator tool. See the translator.README.txt file in the 34 // tools directory for more information. 35 // 36 37 #ifndef CEF_INCLUDE_VIEWS_CEF_WINDOW_H_ 38 #define CEF_INCLUDE_VIEWS_CEF_WINDOW_H_ 39 #pragma once 40 41 #include "include/cef_image.h" 42 #include "include/cef_menu_model.h" 43 #include "include/views/cef_display.h" 44 #include "include/views/cef_overlay_controller.h" 45 #include "include/views/cef_panel.h" 46 #include "include/views/cef_window_delegate.h" 47 48 /// 49 // A Window is a top-level Window/widget in the Views hierarchy. By default it 50 // will have a non-client area with title bar, icon and buttons that supports 51 // moving and resizing. All size and position values are in density independent 52 // pixels (DIP) unless otherwise indicated. Methods must be called on the 53 // browser process UI thread unless otherwise indicated. 54 /// 55 /*--cef(source=library)--*/ 56 class CefWindow : public CefPanel { 57 public: 58 /// 59 // Create a new Window. 60 /// 61 /*--cef(optional_param=delegate)--*/ 62 static CefRefPtr<CefWindow> CreateTopLevelWindow( 63 CefRefPtr<CefWindowDelegate> delegate); 64 65 /// 66 // Show the Window. 67 /// 68 /*--cef()--*/ 69 virtual void Show() = 0; 70 71 /// 72 // Hide the Window. 73 /// 74 /*--cef()--*/ 75 virtual void Hide() = 0; 76 77 /// 78 // Sizes the Window to |size| and centers it in the current display. 79 /// 80 /*--cef()--*/ 81 virtual void CenterWindow(const CefSize& size) = 0; 82 83 /// 84 // Close the Window. 85 /// 86 /*--cef()--*/ 87 virtual void Close() = 0; 88 89 /// 90 // Returns true if the Window has been closed. 91 /// 92 /*--cef()--*/ 93 virtual bool IsClosed() = 0; 94 95 /// 96 // Activate the Window, assuming it already exists and is visible. 97 /// 98 /*--cef()--*/ 99 virtual void Activate() = 0; 100 101 /// 102 // Deactivate the Window, making the next Window in the Z order the active 103 // Window. 104 /// 105 /*--cef()--*/ 106 virtual void Deactivate() = 0; 107 108 /// 109 // Returns whether the Window is the currently active Window. 110 /// 111 /*--cef()--*/ 112 virtual bool IsActive() = 0; 113 114 /// 115 // Bring this Window to the top of other Windows in the Windowing system. 116 /// 117 /*--cef()--*/ 118 virtual void BringToTop() = 0; 119 120 /// 121 // Set the Window to be on top of other Windows in the Windowing system. 122 /// 123 /*--cef()--*/ 124 virtual void SetAlwaysOnTop(bool on_top) = 0; 125 126 /// 127 // Returns whether the Window has been set to be on top of other Windows in 128 // the Windowing system. 129 /// 130 /*--cef()--*/ 131 virtual bool IsAlwaysOnTop() = 0; 132 133 /// 134 // Maximize the Window. 135 /// 136 /*--cef()--*/ 137 virtual void Maximize() = 0; 138 139 /// 140 // Minimize the Window. 141 /// 142 /*--cef()--*/ 143 virtual void Minimize() = 0; 144 145 /// 146 // Restore the Window. 147 /// 148 /*--cef()--*/ 149 virtual void Restore() = 0; 150 151 /// 152 // Set fullscreen Window state. 153 /// 154 /*--cef()--*/ 155 virtual void SetFullscreen(bool fullscreen) = 0; 156 157 /// 158 // Returns true if the Window is maximized. 159 /// 160 /*--cef()--*/ 161 virtual bool IsMaximized() = 0; 162 163 /// 164 // Returns true if the Window is minimized. 165 /// 166 /*--cef()--*/ 167 virtual bool IsMinimized() = 0; 168 169 /// 170 // Returns true if the Window is fullscreen. 171 /// 172 /*--cef()--*/ 173 virtual bool IsFullscreen() = 0; 174 175 /// 176 // Set the Window title. 177 /// 178 /*--cef(optional_param=title)--*/ 179 virtual void SetTitle(const CefString& title) = 0; 180 181 /// 182 // Get the Window title. 183 /// 184 /*--cef()--*/ 185 virtual CefString GetTitle() = 0; 186 187 /// 188 // Set the Window icon. This should be a 16x16 icon suitable for use in the 189 // Windows's title bar. 190 /// 191 /*--cef()--*/ 192 virtual void SetWindowIcon(CefRefPtr<CefImage> image) = 0; 193 194 /// 195 // Get the Window icon. 196 /// 197 /*--cef()--*/ 198 virtual CefRefPtr<CefImage> GetWindowIcon() = 0; 199 200 /// 201 // Set the Window App icon. This should be a larger icon for use in the host 202 // environment app switching UI. On Windows, this is the ICON_BIG used in 203 // Alt-Tab list and Windows taskbar. The Window icon will be used by default 204 // if no Window App icon is specified. 205 /// 206 /*--cef()--*/ 207 virtual void SetWindowAppIcon(CefRefPtr<CefImage> image) = 0; 208 209 /// 210 // Get the Window App icon. 211 /// 212 /*--cef()--*/ 213 virtual CefRefPtr<CefImage> GetWindowAppIcon() = 0; 214 215 /// 216 // Add a View that will be overlayed on the Window contents with absolute 217 // positioning and high z-order. Positioning is controlled by |docking_mode| 218 // as described below. The returned CefOverlayController object is used to 219 // control the overlay. Overlays are hidden by default. 220 // 221 // With CEF_DOCKING_MODE_CUSTOM: 222 // 1. The overlay is initially hidden, sized to |view|'s preferred size, and 223 // positioned in the top-left corner. 224 // 2. Optionally change the overlay position and/or size by calling 225 // CefOverlayController methods. 226 // 3. Call CefOverlayController::SetVisible(true) to show the overlay. 227 // 4. The overlay will be automatically re-sized if |view|'s layout changes. 228 // Optionally change the overlay position and/or size when 229 // OnLayoutChanged is called on the Window's delegate to indicate a 230 // change in Window bounds. 231 // 232 // With other docking modes: 233 // 1. The overlay is initially hidden, sized to |view|'s preferred size, and 234 // positioned based on |docking_mode|. 235 // 2. Call CefOverlayController::SetVisible(true) to show the overlay. 236 // 3. The overlay will be automatically re-sized if |view|'s layout changes 237 // and re-positioned as appropriate when the Window resizes. 238 // 239 // Overlays created by this method will receive a higher z-order then any 240 // child Views added previously. It is therefore recommended to call this 241 // method last after all other child Views have been added so that the overlay 242 // displays as the top-most child of the Window. 243 /// 244 /*--cef()--*/ 245 virtual CefRefPtr<CefOverlayController> AddOverlayView( 246 CefRefPtr<CefView> view, 247 cef_docking_mode_t docking_mode) = 0; 248 249 /// 250 // Show a menu with contents |menu_model|. |screen_point| specifies the menu 251 // position in screen coordinates. |anchor_position| specifies how the menu 252 // will be anchored relative to |screen_point|. 253 /// 254 /*--cef()--*/ 255 virtual void ShowMenu(CefRefPtr<CefMenuModel> menu_model, 256 const CefPoint& screen_point, 257 cef_menu_anchor_position_t anchor_position) = 0; 258 259 /// 260 // Cancel the menu that is currently showing, if any. 261 /// 262 /*--cef()--*/ 263 virtual void CancelMenu() = 0; 264 265 /// 266 // Returns the Display that most closely intersects the bounds of this Window. 267 // May return NULL if this Window is not currently displayed. 268 /// 269 /*--cef()--*/ 270 virtual CefRefPtr<CefDisplay> GetDisplay() = 0; 271 272 /// 273 // Returns the bounds (size and position) of this Window's client area. 274 // Position is in screen coordinates. 275 /// 276 /*--cef()--*/ 277 virtual CefRect GetClientAreaBoundsInScreen() = 0; 278 279 /// 280 // Set the regions where mouse events will be intercepted by this Window to 281 // support drag operations. Call this method with an empty vector to clear the 282 // draggable regions. The draggable region bounds should be in window 283 // coordinates. 284 /// 285 /*--cef(optional_param=regions)--*/ 286 virtual void SetDraggableRegions( 287 const std::vector<CefDraggableRegion>& regions) = 0; 288 289 /// 290 // Retrieve the platform window handle for this Window. 291 /// 292 /*--cef()--*/ 293 virtual CefWindowHandle GetWindowHandle() = 0; 294 295 /// 296 // Simulate a key press. |key_code| is the VKEY_* value from Chromium's 297 // ui/events/keycodes/keyboard_codes.h header (VK_* values on Windows). 298 // |event_flags| is some combination of EVENTFLAG_SHIFT_DOWN, 299 // EVENTFLAG_CONTROL_DOWN and/or EVENTFLAG_ALT_DOWN. This method is exposed 300 // primarily for testing purposes. 301 /// 302 /*--cef()--*/ 303 virtual void SendKeyPress(int key_code, uint32 event_flags) = 0; 304 305 /// 306 // Simulate a mouse move. The mouse cursor will be moved to the specified 307 // (screen_x, screen_y) position. This method is exposed primarily for testing 308 // purposes. 309 /// 310 /*--cef()--*/ 311 virtual void SendMouseMove(int screen_x, int screen_y) = 0; 312 313 /// 314 // Simulate mouse down and/or mouse up events. |button| is the mouse button 315 // type. If |mouse_down| is true a mouse down event will be sent. If 316 // |mouse_up| is true a mouse up event will be sent. If both are true a mouse 317 // down event will be sent followed by a mouse up event (equivalent to 318 // clicking the mouse button). The events will be sent using the current 319 // cursor position so make sure to call SendMouseMove() first to position the 320 // mouse. This method is exposed primarily for testing purposes. 321 /// 322 /*--cef()--*/ 323 virtual void SendMouseEvents(cef_mouse_button_type_t button, 324 bool mouse_down, 325 bool mouse_up) = 0; 326 /// 327 // Set the keyboard accelerator for the specified |command_id|. |key_code| can 328 // be any virtual key or character value. CefWindowDelegate::OnAccelerator 329 // will be called if the keyboard combination is triggered while this window 330 // has focus. 331 /// 332 /*--cef()--*/ 333 virtual void SetAccelerator(int command_id, 334 int key_code, 335 bool shift_pressed, 336 bool ctrl_pressed, 337 bool alt_pressed) = 0; 338 339 /// 340 // Remove the keyboard accelerator for the specified |command_id|. 341 /// 342 /*--cef()--*/ 343 virtual void RemoveAccelerator(int command_id) = 0; 344 345 /// 346 // Remove all keyboard accelerators. 347 /// 348 /*--cef()--*/ 349 virtual void RemoveAllAccelerators() = 0; 350 }; 351 352 #endif // CEF_INCLUDE_VIEWS_CEF_WINDOW_H_ 353