• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   // Sets the insets for this View. |insets| is in parent coordinates, or DIP
227   // screen coordinates if there is no parent.
228   ///
229   /*--cef()--*/
230   virtual void SetInsets(const CefInsets& insets) = 0;
231 
232   ///
233   // Returns the insets for this View in parent coordinates, or DIP screen
234   // coordinates if there is no parent.
235   ///
236   /*--cef()--*/
237   virtual CefInsets GetInsets() = 0;
238 
239   ///
240   // Returns the size this View would like to be if enough space is available.
241   // Size is in parent coordinates, or DIP screen coordinates if there is no
242   // parent.
243   ///
244   /*--cef()--*/
245   virtual CefSize GetPreferredSize() = 0;
246 
247   ///
248   // Size this View to its preferred size. Size is in parent coordinates, or
249   // DIP screen coordinates if there is no parent.
250   ///
251   /*--cef()--*/
252   virtual void SizeToPreferredSize() = 0;
253 
254   ///
255   // Returns the minimum size for this View. Size is in parent coordinates, or
256   // DIP screen coordinates if there is no parent.
257   ///
258   /*--cef()--*/
259   virtual CefSize GetMinimumSize() = 0;
260 
261   ///
262   // Returns the maximum size for this View. Size is in parent coordinates, or
263   // DIP screen coordinates if there is no parent.
264   ///
265   /*--cef()--*/
266   virtual CefSize GetMaximumSize() = 0;
267 
268   ///
269   // Returns the height necessary to display this View with the provided width.
270   ///
271   /*--cef()--*/
272   virtual int GetHeightForWidth(int width) = 0;
273 
274   ///
275   // Indicate that this View and all parent Views require a re-layout. This
276   // ensures the next call to Layout() will propagate to this View even if the
277   // bounds of parent Views do not change.
278   ///
279   /*--cef()--*/
280   virtual void InvalidateLayout() = 0;
281 
282   ///
283   // Sets whether this View is visible. Windows are hidden by default and other
284   // views are visible by default. This View and any parent views must be set as
285   // visible for this View to be drawn in a Window. If this View is set as
286   // hidden then it and any child views will not be drawn and, if any of those
287   // views currently have focus, then focus will also be cleared. Painting is
288   // scheduled as needed. If this View is a Window then calling this method is
289   // equivalent to calling the Window Show() and Hide() methods.
290   ///
291   /*--cef()--*/
292   virtual void SetVisible(bool visible) = 0;
293 
294   ///
295   // Returns whether this View is visible. A view may be visible but still not
296   // drawn in a Window if any parent views are hidden. If this View is a Window
297   // then a return value of true indicates that this Window is currently visible
298   // to the user on-screen. If this View is not a Window then call IsDrawn() to
299   // determine whether this View and all parent views are visible and will be
300   // drawn.
301   ///
302   /*--cef()--*/
303   virtual bool IsVisible() = 0;
304 
305   ///
306   // Returns whether this View is visible and drawn in a Window. A view is drawn
307   // if it and all parent views are visible. If this View is a Window then
308   // calling this method is equivalent to calling IsVisible(). Otherwise, to
309   // determine if the containing Window is visible to the user on-screen call
310   // IsVisible() on the Window.
311   ///
312   /*--cef()--*/
313   virtual bool IsDrawn() = 0;
314 
315   ///
316   // Set whether this View is enabled. A disabled View does not receive keyboard
317   // or mouse inputs. If |enabled| differs from the current value the View will
318   // be repainted. Also, clears focus if the focused View is disabled.
319   ///
320   /*--cef()--*/
321   virtual void SetEnabled(bool enabled) = 0;
322 
323   ///
324   // Returns whether this View is enabled.
325   ///
326   /*--cef()--*/
327   virtual bool IsEnabled() = 0;
328 
329   ///
330   // Sets whether this View is capable of taking focus. It will clear focus if
331   // the focused View is set to be non-focusable. This is false by default so
332   // that a View used as a container does not get the focus.
333   ///
334   /*--cef()--*/
335   virtual void SetFocusable(bool focusable) = 0;
336 
337   ///
338   // Returns true if this View is focusable, enabled and drawn.
339   ///
340   /*--cef()--*/
341   virtual bool IsFocusable() = 0;
342 
343   ///
344   // Return whether this View is focusable when the user requires full keyboard
345   // access, even though it may not be normally focusable.
346   ///
347   /*--cef()--*/
348   virtual bool IsAccessibilityFocusable() = 0;
349 
350   ///
351   // Request keyboard focus. If this View is focusable it will become the
352   // focused View.
353   ///
354   /*--cef()--*/
355   virtual void RequestFocus() = 0;
356 
357   ///
358   // Sets the background color for this View.
359   ///
360   /*--cef()--*/
361   virtual void SetBackgroundColor(cef_color_t color) = 0;
362 
363   ///
364   // Returns the background color for this View.
365   ///
366   /*--cef()--*/
367   virtual cef_color_t GetBackgroundColor() = 0;
368 
369   ///
370   // Convert |point| from this View's coordinate system to DIP screen
371   // coordinates. This View must belong to a Window when calling this method.
372   // Returns true if the conversion is successful or false otherwise. Use
373   // CefDisplay::ConvertPointToPixels() after calling this method if further
374   // conversion to display-specific pixel coordinates is desired.
375   ///
376   /*--cef()--*/
377   virtual bool ConvertPointToScreen(CefPoint& point) = 0;
378 
379   ///
380   // Convert |point| to this View's coordinate system from DIP screen
381   // coordinates. This View must belong to a Window when calling this method.
382   // Returns true if the conversion is successful or false otherwise. Use
383   // CefDisplay::ConvertPointFromPixels() before calling this method if
384   // conversion from display-specific pixel coordinates is necessary.
385   ///
386   /*--cef()--*/
387   virtual bool ConvertPointFromScreen(CefPoint& point) = 0;
388 
389   ///
390   // Convert |point| from this View's coordinate system to that of the Window.
391   // This View must belong to a Window when calling this method. Returns true if
392   // the conversion is successful or false otherwise.
393   ///
394   /*--cef()--*/
395   virtual bool ConvertPointToWindow(CefPoint& point) = 0;
396 
397   ///
398   // Convert |point| to this View's coordinate system from that of the Window.
399   // This View must belong to a Window when calling this method. Returns true if
400   // the conversion is successful or false otherwise.
401   ///
402   /*--cef()--*/
403   virtual bool ConvertPointFromWindow(CefPoint& point) = 0;
404 
405   ///
406   // Convert |point| from this View's coordinate system to that of |view|.
407   // |view| needs to be in the same Window but not necessarily the same view
408   // hierarchy. Returns true if the conversion is successful or false otherwise.
409   ///
410   /*--cef()--*/
411   virtual bool ConvertPointToView(CefRefPtr<CefView> view, CefPoint& point) = 0;
412 
413   ///
414   // Convert |point| to this View's coordinate system from that |view|. |view|
415   // needs to be in the same Window but not necessarily the same view hierarchy.
416   // Returns true if the conversion is successful or false otherwise.
417   ///
418   /*--cef()--*/
419   virtual bool ConvertPointFromView(CefRefPtr<CefView> view,
420                                     CefPoint& point) = 0;
421 };
422 
423 #endif  // CEF_INCLUDE_VIEWS_CEF_VIEW_H_
424