• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that
3 // can be found in the LICENSE file.
4 
5 #ifndef CEF_TESTS_CEFCLIENT_BROWSER_BROWSER_WINDOW_OSR_GTK_H_
6 #define CEF_TESTS_CEFCLIENT_BROWSER_BROWSER_WINDOW_OSR_GTK_H_
7 #pragma once
8 
9 #include "include/base/cef_lock.h"
10 
11 #include "tests/cefclient/browser/browser_window.h"
12 #include "tests/cefclient/browser/client_handler_osr.h"
13 #include "tests/cefclient/browser/osr_renderer.h"
14 
15 namespace client {
16 
17 // Represents a native child window hosting a single off-screen browser
18 // instance. The methods of this class must be called on the main thread unless
19 // otherwise indicated.
20 class BrowserWindowOsrGtk : public BrowserWindow,
21                             public ClientHandlerOsr::OsrDelegate {
22  public:
23   typedef void* CefXIDeviceEvent;
24 
25   // Constructor may be called on any thread.
26   // |delegate| must outlive this object.
27   BrowserWindowOsrGtk(BrowserWindow::Delegate* delegate,
28                       const std::string& startup_url,
29                       const OsrRendererSettings& settings);
30 
31   // Called from RootWindowGtk::CreateRootWindow before CreateBrowser.
32   void set_xdisplay(XDisplay* xdisplay);
33 
34   // BrowserWindow methods.
35   void CreateBrowser(ClientWindowHandle parent_handle,
36                      const CefRect& rect,
37                      const CefBrowserSettings& settings,
38                      CefRefPtr<CefDictionaryValue> extra_info,
39                      CefRefPtr<CefRequestContext> request_context) override;
40   void GetPopupConfig(CefWindowHandle temp_handle,
41                       CefWindowInfo& windowInfo,
42                       CefRefPtr<CefClient>& client,
43                       CefBrowserSettings& settings) override;
44   void ShowPopup(ClientWindowHandle parent_handle,
45                  int x,
46                  int y,
47                  size_t width,
48                  size_t height) override;
49   void Show() override;
50   void Hide() override;
51   void SetBounds(int x, int y, size_t width, size_t height) override;
52   void SetFocus(bool focus) override;
53   void SetDeviceScaleFactor(float device_scale_factor) override;
54   float GetDeviceScaleFactor() const override;
55   ClientWindowHandle GetWindowHandle() const override;
56 
57   // ClientHandlerOsr::OsrDelegate methods.
58   void OnAfterCreated(CefRefPtr<CefBrowser> browser) override;
59   void OnBeforeClose(CefRefPtr<CefBrowser> browser) override;
60   bool GetRootScreenRect(CefRefPtr<CefBrowser> browser, CefRect& rect) override;
61   void GetViewRect(CefRefPtr<CefBrowser> browser, CefRect& rect) override;
62   bool GetScreenPoint(CefRefPtr<CefBrowser> browser,
63                       int viewX,
64                       int viewY,
65                       int& screenX,
66                       int& screenY) override;
67   bool GetScreenInfo(CefRefPtr<CefBrowser> browser,
68                      CefScreenInfo& screen_info) override;
69   void OnPopupShow(CefRefPtr<CefBrowser> browser, bool show) override;
70   void OnPopupSize(CefRefPtr<CefBrowser> browser, const CefRect& rect) override;
71   void OnPaint(CefRefPtr<CefBrowser> browser,
72                CefRenderHandler::PaintElementType type,
73                const CefRenderHandler::RectList& dirtyRects,
74                const void* buffer,
75                int width,
76                int height) override;
77   void OnCursorChange(CefRefPtr<CefBrowser> browser,
78                       CefCursorHandle cursor,
79                       cef_cursor_type_t type,
80                       const CefCursorInfo& custom_cursor_info) override;
81   bool StartDragging(CefRefPtr<CefBrowser> browser,
82                      CefRefPtr<CefDragData> drag_data,
83                      CefRenderHandler::DragOperationsMask allowed_ops,
84                      int x,
85                      int y) override;
86   void UpdateDragCursor(CefRefPtr<CefBrowser> browser,
87                         CefRenderHandler::DragOperation operation) override;
88   void OnImeCompositionRangeChanged(
89       CefRefPtr<CefBrowser> browser,
90       const CefRange& selection_range,
91       const CefRenderHandler::RectList& character_bounds) override;
92   void UpdateAccessibilityTree(CefRefPtr<CefValue> value) override;
93   void UpdateAccessibilityLocation(CefRefPtr<CefValue> value) override;
94 
95  private:
96   ~BrowserWindowOsrGtk();
97 
98   // Create the GTK GlArea.
99   void Create(ClientWindowHandle parent_handle);
100 
101   // Signal handlers for the GTK GlArea.
102   static gint SizeAllocation(GtkWidget* widget,
103                              GtkAllocation* allocation,
104                              BrowserWindowOsrGtk* self);
105   static gint ClickEvent(GtkWidget* widget,
106                          GdkEventButton* event,
107                          BrowserWindowOsrGtk* self);
108   static gint KeyEvent(GtkWidget* widget,
109                        GdkEventKey* event,
110                        BrowserWindowOsrGtk* self);
111   static gint MoveEvent(GtkWidget* widget,
112                         GdkEventMotion* event,
113                         BrowserWindowOsrGtk* self);
114   static gint ScrollEvent(GtkWidget* widget,
115                           GdkEventScroll* event,
116                           BrowserWindowOsrGtk* self);
117   static gint FocusEvent(GtkWidget* widget,
118                          GdkEventFocus* event,
119                          BrowserWindowOsrGtk* self);
120   static gboolean TouchEvent(GtkWidget* widget,
121                              GdkEventTouch* event,
122                              BrowserWindowOsrGtk* self);
123 
124   void RegisterTouch();
125 
126   bool IsOverPopupWidget(int x, int y) const;
127   int GetPopupXOffset() const;
128   int GetPopupYOffset() const;
129   void ApplyPopupOffset(int& x, int& y) const;
130 
131   void EnableGL();
132   void DisableGL();
133 
134   // Drag & drop
135   void RegisterDragDrop();
136   void UnregisterDragDrop();
137   void DragReset();
138   static void DragBegin(GtkWidget* widget,
139                         GdkDragContext* drag_context,
140                         BrowserWindowOsrGtk* self);
141   static void DragDataGet(GtkWidget* widget,
142                           GdkDragContext* drag_context,
143                           GtkSelectionData* data,
144                           guint info,
145                           guint time,
146                           BrowserWindowOsrGtk* self);
147   static void DragEnd(GtkWidget* widget,
148                       GdkDragContext* drag_context,
149                       BrowserWindowOsrGtk* self);
150   static gboolean DragMotion(GtkWidget* widget,
151                              GdkDragContext* drag_context,
152                              gint x,
153                              gint y,
154                              guint time,
155                              BrowserWindowOsrGtk* self);
156   static void DragLeave(GtkWidget* widget,
157                         GdkDragContext* drag_context,
158                         guint time,
159                         BrowserWindowOsrGtk* self);
160   static gboolean DragFailed(GtkWidget* widget,
161                              GdkDragContext* drag_context,
162                              GtkDragResult result,
163                              BrowserWindowOsrGtk* self);
164   static gboolean DragDrop(GtkWidget* widget,
165                            GdkDragContext* drag_context,
166                            gint x,
167                            gint y,
168                            guint time,
169                            BrowserWindowOsrGtk* self);
170   static void DragDataReceived(GtkWidget* widget,
171                                GdkDragContext* drag_context,
172                                gint x,
173                                gint y,
174                                GtkSelectionData* data,
175                                guint info,
176                                guint time,
177                                BrowserWindowOsrGtk* self);
178   static GdkFilterReturn EventFilter(GdkXEvent* gdk_xevent,
179                                      GdkEvent* event,
180                                      gpointer data);
181 
182   XDisplay* xdisplay_;
183 
184   // Members only accessed on the UI thread.
185   OsrRenderer renderer_;
186   bool gl_enabled_;
187   bool painting_popup_;
188 
189   // Members only accessed on the main thread.
190   bool hidden_;
191 
192   // Members protected by the GDK global lock.
193   ClientWindowHandle glarea_;
194 
195   // Drag & drop
196   GdkEvent* drag_trigger_event_;  // mouse event, a possible trigger for drag
197   CefRefPtr<CefDragData> drag_data_;
198   CefRenderHandler::DragOperation drag_operation_;
199   GdkDragContext* drag_context_;
200   GtkTargetList* drag_targets_;
201   bool drag_leave_;
202   bool drag_drop_;
203 
204   mutable base::Lock lock_;
205 
206   // Access to these members must be protected by |lock_|.
207   float device_scale_factor_;
208 
209   DISALLOW_COPY_AND_ASSIGN(BrowserWindowOsrGtk);
210 };
211 
212 }  // namespace client
213 
214 #endif  // CEF_TESTS_CEFCLIENT_BROWSER_BROWSER_WINDOW_OSR_GTK_H_
215