• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 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_CEF_RENDER_HANDLER_H_
38 #define CEF_INCLUDE_CEF_RENDER_HANDLER_H_
39 #pragma once
40 
41 #include <vector>
42 
43 #include "include/cef_accessibility_handler.h"
44 #include "include/cef_base.h"
45 #include "include/cef_browser.h"
46 #include "include/cef_drag_data.h"
47 
48 ///
49 // Implement this interface to handle events when window rendering is disabled.
50 // The methods of this class will be called on the UI thread.
51 ///
52 /*--cef(source=client)--*/
53 class CefRenderHandler : public virtual CefBaseRefCounted {
54  public:
55   typedef cef_drag_operations_mask_t DragOperation;
56   typedef cef_drag_operations_mask_t DragOperationsMask;
57   typedef cef_paint_element_type_t PaintElementType;
58   typedef std::vector<CefRect> RectList;
59   typedef cef_text_input_mode_t TextInputMode;
60 
61   ///
62   // Return the handler for accessibility notifications. If no handler is
63   // provided the default implementation will be used.
64   ///
65   /*--cef()--*/
GetAccessibilityHandler()66   virtual CefRefPtr<CefAccessibilityHandler> GetAccessibilityHandler() {
67     return nullptr;
68   }
69 
70   ///
71   // Called to retrieve the root window rectangle in screen coordinates. Return
72   // true if the rectangle was provided. If this method returns false the
73   // rectangle from GetViewRect will be used.
74   ///
75   /*--cef()--*/
GetRootScreenRect(CefRefPtr<CefBrowser> browser,CefRect & rect)76   virtual bool GetRootScreenRect(CefRefPtr<CefBrowser> browser, CefRect& rect) {
77     return false;
78   }
79 
80   ///
81   // Called to retrieve the view rectangle which is relative to screen
82   // coordinates. This method must always provide a non-empty rectangle.
83   ///
84   /*--cef()--*/
85   virtual void GetViewRect(CefRefPtr<CefBrowser> browser, CefRect& rect) = 0;
86 
87   ///
88   // Called to retrieve the translation from view coordinates to actual screen
89   // coordinates. Return true if the screen coordinates were provided.
90   ///
91   /*--cef()--*/
GetScreenPoint(CefRefPtr<CefBrowser> browser,int viewX,int viewY,int & screenX,int & screenY)92   virtual bool GetScreenPoint(CefRefPtr<CefBrowser> browser,
93                               int viewX,
94                               int viewY,
95                               int& screenX,
96                               int& screenY) {
97     return false;
98   }
99 
100   ///
101   // Called to allow the client to fill in the CefScreenInfo object with
102   // appropriate values. Return true if the |screen_info| structure has been
103   // modified.
104   //
105   // If the screen info rectangle is left empty the rectangle from GetViewRect
106   // will be used. If the rectangle is still empty or invalid popups may not be
107   // drawn correctly.
108   ///
109   /*--cef()--*/
GetScreenInfo(CefRefPtr<CefBrowser> browser,CefScreenInfo & screen_info)110   virtual bool GetScreenInfo(CefRefPtr<CefBrowser> browser,
111                              CefScreenInfo& screen_info) {
112     return false;
113   }
114 
115   ///
116   // Called when the browser wants to show or hide the popup widget. The popup
117   // should be shown if |show| is true and hidden if |show| is false.
118   ///
119   /*--cef()--*/
OnPopupShow(CefRefPtr<CefBrowser> browser,bool show)120   virtual void OnPopupShow(CefRefPtr<CefBrowser> browser, bool show) {}
121 
122   ///
123   // Called when the browser wants to move or resize the popup widget. |rect|
124   // contains the new location and size in view coordinates.
125   ///
126   /*--cef()--*/
OnPopupSize(CefRefPtr<CefBrowser> browser,const CefRect & rect)127   virtual void OnPopupSize(CefRefPtr<CefBrowser> browser, const CefRect& rect) {
128   }
129 
130   ///
131   // Called when an element should be painted. Pixel values passed to this
132   // method are scaled relative to view coordinates based on the value of
133   // CefScreenInfo.device_scale_factor returned from GetScreenInfo. |type|
134   // indicates whether the element is the view or the popup widget. |buffer|
135   // contains the pixel data for the whole image. |dirtyRects| contains the set
136   // of rectangles in pixel coordinates that need to be repainted. |buffer| will
137   // be |width|*|height|*4 bytes in size and represents a BGRA image with an
138   // upper-left origin. This method is only called when
139   // CefWindowInfo::shared_texture_enabled is set to false.
140   ///
141   /*--cef()--*/
142   virtual void OnPaint(CefRefPtr<CefBrowser> browser,
143                        PaintElementType type,
144                        const RectList& dirtyRects,
145                        const void* buffer,
146                        int width,
147                        int height) = 0;
148 
149   ///
150   // Called when an element has been rendered to the shared texture handle.
151   // |type| indicates whether the element is the view or the popup widget.
152   // |dirtyRects| contains the set of rectangles in pixel coordinates that need
153   // to be repainted. |shared_handle| is the handle for a D3D11 Texture2D that
154   // can be accessed via ID3D11Device using the OpenSharedResource method. This
155   // method is only called when CefWindowInfo::shared_texture_enabled is set to
156   // true, and is currently only supported on Windows.
157   ///
158   /*--cef()--*/
OnAcceleratedPaint(CefRefPtr<CefBrowser> browser,PaintElementType type,const RectList & dirtyRects,void * shared_handle)159   virtual void OnAcceleratedPaint(CefRefPtr<CefBrowser> browser,
160                                   PaintElementType type,
161                                   const RectList& dirtyRects,
162                                   void* shared_handle) {}
163 
164   ///
165   // Called when the user starts dragging content in the web view. Contextual
166   // information about the dragged content is supplied by |drag_data|.
167   // (|x|, |y|) is the drag start location in screen coordinates.
168   // OS APIs that run a system message loop may be used within the
169   // StartDragging call.
170   //
171   // Return false to abort the drag operation. Don't call any of
172   // CefBrowserHost::DragSource*Ended* methods after returning false.
173   //
174   // Return true to handle the drag operation. Call
175   // CefBrowserHost::DragSourceEndedAt and DragSourceSystemDragEnded either
176   // synchronously or asynchronously to inform the web view that the drag
177   // operation has ended.
178   ///
179   /*--cef()--*/
StartDragging(CefRefPtr<CefBrowser> browser,CefRefPtr<CefDragData> drag_data,DragOperationsMask allowed_ops,int x,int y)180   virtual bool StartDragging(CefRefPtr<CefBrowser> browser,
181                              CefRefPtr<CefDragData> drag_data,
182                              DragOperationsMask allowed_ops,
183                              int x,
184                              int y) {
185     return false;
186   }
187 
188   ///
189   // Called when the web view wants to update the mouse cursor during a
190   // drag & drop operation. |operation| describes the allowed operation
191   // (none, move, copy, link).
192   ///
193   /*--cef()--*/
UpdateDragCursor(CefRefPtr<CefBrowser> browser,DragOperation operation)194   virtual void UpdateDragCursor(CefRefPtr<CefBrowser> browser,
195                                 DragOperation operation) {}
196 
197   ///
198   // Called when the scroll offset has changed.
199   ///
200   /*--cef()--*/
OnScrollOffsetChanged(CefRefPtr<CefBrowser> browser,double x,double y)201   virtual void OnScrollOffsetChanged(CefRefPtr<CefBrowser> browser,
202                                      double x,
203                                      double y) {}
204 
205   ///
206   // Called when the IME composition range has changed. |selected_range| is the
207   // range of characters that have been selected. |character_bounds| is the
208   // bounds of each character in view coordinates.
209   ///
210   /*--cef()--*/
OnImeCompositionRangeChanged(CefRefPtr<CefBrowser> browser,const CefRange & selected_range,const RectList & character_bounds)211   virtual void OnImeCompositionRangeChanged(CefRefPtr<CefBrowser> browser,
212                                             const CefRange& selected_range,
213                                             const RectList& character_bounds) {}
214 
215   ///
216   // Called when text selection has changed for the specified |browser|.
217   // |selected_text| is the currently selected text and |selected_range| is
218   // the character range.
219   ///
220   /*--cef(optional_param=selected_text,optional_param=selected_range)--*/
OnTextSelectionChanged(CefRefPtr<CefBrowser> browser,const CefString & selected_text,const CefRange & selected_range)221   virtual void OnTextSelectionChanged(CefRefPtr<CefBrowser> browser,
222                                       const CefString& selected_text,
223                                       const CefRange& selected_range) {}
224 
225   ///
226   // Called when an on-screen keyboard should be shown or hidden for the
227   // specified |browser|. |input_mode| specifies what kind of keyboard
228   // should be opened. If |input_mode| is CEF_TEXT_INPUT_MODE_NONE, any
229   // existing keyboard for this browser should be hidden.
230   ///
231   /*--cef()--*/
OnVirtualKeyboardRequested(CefRefPtr<CefBrowser> browser,TextInputMode input_mode)232   virtual void OnVirtualKeyboardRequested(CefRefPtr<CefBrowser> browser,
233                                           TextInputMode input_mode) {}
234 };
235 
236 #endif  // CEF_INCLUDE_CEF_RENDER_HANDLER_H_
237