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_VIEW_H_ 38 #define CEF_INCLUDE_VIEWS_CEF_VIEW_H_ 39 #pragma once 40 41 #include "include/views/cef_view_delegate.h" 42 43 class CefBrowserView; 44 class CefButton; 45 class CefPanel; 46 class CefScrollView; 47 class CefTextfield; 48 class CefWindow; 49 50 /// 51 // A View is a rectangle within the views View hierarchy. It is the base class 52 // for all Views. All size and position values are in density independent pixels 53 // (DIP) unless otherwise indicated. Methods must be called on the browser 54 // process UI thread unless otherwise indicated. 55 /// 56 /*--cef(source=library)--*/ 57 class CefView : public CefBaseRefCounted { 58 public: 59 /// 60 // Returns this View as a BrowserView or NULL if this is not a BrowserView. 61 /// 62 /*--cef()--*/ 63 virtual CefRefPtr<CefBrowserView> AsBrowserView() = 0; 64 65 /// 66 // Returns this View as a Button or NULL if this is not a Button. 67 /// 68 /*--cef()--*/ 69 virtual CefRefPtr<CefButton> AsButton() = 0; 70 71 /// 72 // Returns this View as a Panel or NULL if this is not a Panel. 73 /// 74 /*--cef()--*/ 75 virtual CefRefPtr<CefPanel> AsPanel() = 0; 76 77 /// 78 // Returns this View as a ScrollView or NULL if this is not a ScrollView. 79 /// 80 /*--cef()--*/ 81 virtual CefRefPtr<CefScrollView> AsScrollView() = 0; 82 83 /// 84 // Returns this View as a Textfield or NULL if this is not a Textfield. 85 /// 86 /*--cef()--*/ 87 virtual CefRefPtr<CefTextfield> AsTextfield() = 0; 88 89 /// 90 // Returns the type of this View as a string. Used primarily for testing 91 // purposes. 92 /// 93 /*--cef()--*/ 94 virtual CefString GetTypeString() = 0; 95 96 /// 97 // Returns a string representation of this View which includes the type and 98 // various type-specific identifying attributes. If |include_children| is true 99 // any child Views will also be included. Used primarily for testing purposes. 100 /// 101 /*--cef()--*/ 102 virtual CefString ToString(bool include_children) = 0; 103 104 /// 105 // Returns true if this View is valid. 106 /// 107 /*--cef()--*/ 108 virtual bool IsValid() = 0; 109 110 /// 111 // Returns true if this View is currently attached to another View. A View can 112 // only be attached to one View at a time. 113 /// 114 /*--cef()--*/ 115 virtual bool IsAttached() = 0; 116 117 /// 118 // Returns true if this View is the same as |that| View. 119 /// 120 /*--cef()--*/ 121 virtual bool IsSame(CefRefPtr<CefView> that) = 0; 122 123 /// 124 // Returns the delegate associated with this View, if any. 125 /// 126 /*--cef()--*/ 127 virtual CefRefPtr<CefViewDelegate> GetDelegate() = 0; 128 129 /// 130 // Returns the top-level Window hosting this View, if any. 131 /// 132 /*--cef()--*/ 133 virtual CefRefPtr<CefWindow> GetWindow() = 0; 134 135 /// 136 // Returns the ID for this View. 137 /// 138 /*--cef()--*/ 139 virtual int GetID() = 0; 140 141 /// 142 // Sets the ID for this View. ID should be unique within the subtree that you 143 // intend to search for it. 0 is the default ID for views. 144 /// 145 /*--cef()--*/ 146 virtual void SetID(int id) = 0; 147 148 /// 149 // Returns the group id of this View, or -1 if not set. 150 /// 151 /*--cef()--*/ 152 virtual int GetGroupID() = 0; 153 154 /// 155 // A group id is used to tag Views which are part of the same logical group. 156 // Focus can be moved between views with the same group using the arrow keys. 157 // The group id is immutable once it's set. 158 /// 159 /*--cef()--*/ 160 virtual void SetGroupID(int group_id) = 0; 161 162 /// 163 // Returns the View that contains this View, if any. 164 /// 165 /*--cef()--*/ 166 virtual CefRefPtr<CefView> GetParentView() = 0; 167 168 /// 169 // Recursively descends the view tree starting at this View, and returns the 170 // first child that it encounters with the given ID. Returns NULL if no 171 // matching child view is found. 172 /// 173 /*--cef()--*/ 174 virtual CefRefPtr<CefView> GetViewForID(int id) = 0; 175 176 /// 177 // Sets the bounds (size and position) of this View. |bounds| is in parent 178 // coordinates, or DIP screen coordinates if there is no parent. 179 /// 180 /*--cef()--*/ 181 virtual void SetBounds(const CefRect& bounds) = 0; 182 183 /// 184 // Returns the bounds (size and position) of this View in parent coordinates, 185 // or DIP screen coordinates if there is no parent. 186 /// 187 /*--cef()--*/ 188 virtual CefRect GetBounds() = 0; 189 190 /// 191 // Returns the bounds (size and position) of this View in DIP screen 192 // coordinates. 193 /// 194 /*--cef()--*/ 195 virtual CefRect GetBoundsInScreen() = 0; 196 197 /// 198 // Sets the size of this View without changing the position. |size| in 199 // parent coordinates, or DIP screen coordinates if there is no parent. 200 /// 201 /*--cef()--*/ 202 virtual void SetSize(const CefSize& size) = 0; 203 204 /// 205 // Returns the size of this View in parent coordinates, or DIP screen 206 // coordinates if there is no parent. 207 /// 208 /*--cef()--*/ 209 virtual CefSize GetSize() = 0; 210 211 /// 212 // Sets the position of this View without changing the size. |position| is in 213 // parent coordinates, or DIP screen coordinates if there is no parent. 214 /// 215 /*--cef()--*/ 216 virtual void SetPosition(const CefPoint& position) = 0; 217 218 /// 219 // Returns the position of this View. Position is in parent coordinates, or 220 // DIP screen coordinates if there is no parent. 221 /// 222 /*--cef()--*/ 223 virtual CefPoint GetPosition() = 0; 224 225 /// 226 // Returns the size this View would like to be if enough space is available. 227 // Size is in parent coordinates, or DIP screen coordinates if there is no 228 // parent. 229 /// 230 /*--cef()--*/ 231 virtual CefSize GetPreferredSize() = 0; 232 233 /// 234 // Size this View to its preferred size. Size is in parent coordinates, or 235 // DIP screen coordinates if there is no parent. 236 /// 237 /*--cef()--*/ 238 virtual void SizeToPreferredSize() = 0; 239 240 /// 241 // Returns the minimum size for this View. Size is in parent coordinates, or 242 // DIP screen coordinates if there is no parent. 243 /// 244 /*--cef()--*/ 245 virtual CefSize GetMinimumSize() = 0; 246 247 /// 248 // Returns the maximum size for this View. Size is in parent coordinates, or 249 // DIP screen coordinates if there is no parent. 250 /// 251 /*--cef()--*/ 252 virtual CefSize GetMaximumSize() = 0; 253 254 /// 255 // Returns the height necessary to display this View with the provided width. 256 /// 257 /*--cef()--*/ 258 virtual int GetHeightForWidth(int width) = 0; 259 260 /// 261 // Indicate that this View and all parent Views require a re-layout. This 262 // ensures the next call to Layout() will propagate to this View even if the 263 // bounds of parent Views do not change. 264 /// 265 /*--cef()--*/ 266 virtual void InvalidateLayout() = 0; 267 268 /// 269 // Sets whether this View is visible. Windows are hidden by default and other 270 // views are visible by default. This View and any parent views must be set as 271 // visible for this View to be drawn in a Window. If this View is set as 272 // hidden then it and any child views will not be drawn and, if any of those 273 // views currently have focus, then focus will also be cleared. Painting is 274 // scheduled as needed. If this View is a Window then calling this method is 275 // equivalent to calling the Window Show() and Hide() methods. 276 /// 277 /*--cef()--*/ 278 virtual void SetVisible(bool visible) = 0; 279 280 /// 281 // Returns whether this View is visible. A view may be visible but still not 282 // drawn in a Window if any parent views are hidden. If this View is a Window 283 // then a return value of true indicates that this Window is currently visible 284 // to the user on-screen. If this View is not a Window then call IsDrawn() to 285 // determine whether this View and all parent views are visible and will be 286 // drawn. 287 /// 288 /*--cef()--*/ 289 virtual bool IsVisible() = 0; 290 291 /// 292 // Returns whether this View is visible and drawn in a Window. A view is drawn 293 // if it and all parent views are visible. If this View is a Window then 294 // calling this method is equivalent to calling IsVisible(). Otherwise, to 295 // determine if the containing Window is visible to the user on-screen call 296 // IsVisible() on the Window. 297 /// 298 /*--cef()--*/ 299 virtual bool IsDrawn() = 0; 300 301 /// 302 // Set whether this View is enabled. A disabled View does not receive keyboard 303 // or mouse inputs. If |enabled| differs from the current value the View will 304 // be repainted. Also, clears focus if the focused View is disabled. 305 /// 306 /*--cef()--*/ 307 virtual void SetEnabled(bool enabled) = 0; 308 309 /// 310 // Returns whether this View is enabled. 311 /// 312 /*--cef()--*/ 313 virtual bool IsEnabled() = 0; 314 315 /// 316 // Sets whether this View is capable of taking focus. It will clear focus if 317 // the focused View is set to be non-focusable. This is false by default so 318 // that a View used as a container does not get the focus. 319 /// 320 /*--cef()--*/ 321 virtual void SetFocusable(bool focusable) = 0; 322 323 /// 324 // Returns true if this View is focusable, enabled and drawn. 325 /// 326 /*--cef()--*/ 327 virtual bool IsFocusable() = 0; 328 329 /// 330 // Return whether this View is focusable when the user requires full keyboard 331 // access, even though it may not be normally focusable. 332 /// 333 /*--cef()--*/ 334 virtual bool IsAccessibilityFocusable() = 0; 335 336 /// 337 // Request keyboard focus. If this View is focusable it will become the 338 // focused View. 339 /// 340 /*--cef()--*/ 341 virtual void RequestFocus() = 0; 342 343 /// 344 // Sets the background color for this View. 345 /// 346 /*--cef()--*/ 347 virtual void SetBackgroundColor(cef_color_t color) = 0; 348 349 /// 350 // Returns the background color for this View. 351 /// 352 /*--cef()--*/ 353 virtual cef_color_t GetBackgroundColor() = 0; 354 355 /// 356 // Convert |point| from this View's coordinate system to DIP screen 357 // coordinates. This View must belong to a Window when calling this method. 358 // Returns true if the conversion is successful or false otherwise. Use 359 // CefDisplay::ConvertPointToPixels() after calling this method if further 360 // conversion to display-specific pixel coordinates is desired. 361 /// 362 /*--cef()--*/ 363 virtual bool ConvertPointToScreen(CefPoint& point) = 0; 364 365 /// 366 // Convert |point| to this View's coordinate system from DIP screen 367 // coordinates. This View must belong to a Window when calling this method. 368 // Returns true if the conversion is successful or false otherwise. Use 369 // CefDisplay::ConvertPointFromPixels() before calling this method if 370 // conversion from display-specific pixel coordinates is necessary. 371 /// 372 /*--cef()--*/ 373 virtual bool ConvertPointFromScreen(CefPoint& point) = 0; 374 375 /// 376 // Convert |point| from this View's coordinate system to that of the Window. 377 // This View must belong to a Window when calling this method. Returns true if 378 // the conversion is successful or false otherwise. 379 /// 380 /*--cef()--*/ 381 virtual bool ConvertPointToWindow(CefPoint& point) = 0; 382 383 /// 384 // Convert |point| to this View's coordinate system from that of the Window. 385 // This View must belong to a Window when calling this method. Returns true if 386 // the conversion is successful or false otherwise. 387 /// 388 /*--cef()--*/ 389 virtual bool ConvertPointFromWindow(CefPoint& point) = 0; 390 391 /// 392 // Convert |point| from this View's coordinate system to that of |view|. 393 // |view| needs to be in the same Window but not necessarily the same view 394 // hierarchy. Returns true if the conversion is successful or false otherwise. 395 /// 396 /*--cef()--*/ 397 virtual bool ConvertPointToView(CefRefPtr<CefView> view, CefPoint& point) = 0; 398 399 /// 400 // Convert |point| to this View's coordinate system from that |view|. |view| 401 // needs to be in the same Window but not necessarily the same view hierarchy. 402 // Returns true if the conversion is successful or false otherwise. 403 /// 404 /*--cef()--*/ 405 virtual bool ConvertPointFromView(CefRefPtr<CefView> view, 406 CefPoint& point) = 0; 407 }; 408 409 #endif // CEF_INCLUDE_VIEWS_CEF_VIEW_H_ 410