• 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 #include "tests/cefclient/browser/client_handler_osr.h"
6 
7 #include "include/base/cef_callback.h"
8 #include "include/wrapper/cef_closure_task.h"
9 #include "include/wrapper/cef_helpers.h"
10 
11 namespace client {
12 
ClientHandlerOsr(Delegate * delegate,OsrDelegate * osr_delegate,const std::string & startup_url)13 ClientHandlerOsr::ClientHandlerOsr(Delegate* delegate,
14                                    OsrDelegate* osr_delegate,
15                                    const std::string& startup_url)
16     : ClientHandler(delegate, true, startup_url), osr_delegate_(osr_delegate) {
17   DCHECK(osr_delegate_);
18 }
19 
DetachOsrDelegate()20 void ClientHandlerOsr::DetachOsrDelegate() {
21   if (!CefCurrentlyOn(TID_UI)) {
22     // Execute this method on the UI thread.
23     CefPostTask(TID_UI,
24                 base::BindOnce(&ClientHandlerOsr::DetachOsrDelegate, this));
25     return;
26   }
27 
28   DCHECK(osr_delegate_);
29   osr_delegate_ = nullptr;
30 }
31 
OnAfterCreated(CefRefPtr<CefBrowser> browser)32 void ClientHandlerOsr::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
33   CEF_REQUIRE_UI_THREAD();
34   if (osr_delegate_)
35     osr_delegate_->OnAfterCreated(browser);
36   ClientHandler::OnAfterCreated(browser);
37 }
38 
OnBeforeClose(CefRefPtr<CefBrowser> browser)39 void ClientHandlerOsr::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
40   CEF_REQUIRE_UI_THREAD();
41   if (osr_delegate_)
42     osr_delegate_->OnBeforeClose(browser);
43   ClientHandler::OnBeforeClose(browser);
44 }
45 
GetRootScreenRect(CefRefPtr<CefBrowser> browser,CefRect & rect)46 bool ClientHandlerOsr::GetRootScreenRect(CefRefPtr<CefBrowser> browser,
47                                          CefRect& rect) {
48   CEF_REQUIRE_UI_THREAD();
49   if (!osr_delegate_)
50     return false;
51   return osr_delegate_->GetRootScreenRect(browser, rect);
52 }
53 
GetViewRect(CefRefPtr<CefBrowser> browser,CefRect & rect)54 void ClientHandlerOsr::GetViewRect(CefRefPtr<CefBrowser> browser,
55                                    CefRect& rect) {
56   CEF_REQUIRE_UI_THREAD();
57   if (!osr_delegate_) {
58     // Never return an empty rectangle.
59     rect.width = rect.height = 1;
60     return;
61   }
62   osr_delegate_->GetViewRect(browser, rect);
63 }
64 
GetScreenPoint(CefRefPtr<CefBrowser> browser,int viewX,int viewY,int & screenX,int & screenY)65 bool ClientHandlerOsr::GetScreenPoint(CefRefPtr<CefBrowser> browser,
66                                       int viewX,
67                                       int viewY,
68                                       int& screenX,
69                                       int& screenY) {
70   CEF_REQUIRE_UI_THREAD();
71   if (!osr_delegate_)
72     return false;
73   return osr_delegate_->GetScreenPoint(browser, viewX, viewY, screenX, screenY);
74 }
75 
GetScreenInfo(CefRefPtr<CefBrowser> browser,CefScreenInfo & screen_info)76 bool ClientHandlerOsr::GetScreenInfo(CefRefPtr<CefBrowser> browser,
77                                      CefScreenInfo& screen_info) {
78   CEF_REQUIRE_UI_THREAD();
79   if (!osr_delegate_)
80     return false;
81   return osr_delegate_->GetScreenInfo(browser, screen_info);
82 }
83 
OnPopupShow(CefRefPtr<CefBrowser> browser,bool show)84 void ClientHandlerOsr::OnPopupShow(CefRefPtr<CefBrowser> browser, bool show) {
85   CEF_REQUIRE_UI_THREAD();
86   if (!osr_delegate_)
87     return;
88   return osr_delegate_->OnPopupShow(browser, show);
89 }
90 
OnPopupSize(CefRefPtr<CefBrowser> browser,const CefRect & rect)91 void ClientHandlerOsr::OnPopupSize(CefRefPtr<CefBrowser> browser,
92                                    const CefRect& rect) {
93   CEF_REQUIRE_UI_THREAD();
94   if (!osr_delegate_)
95     return;
96   return osr_delegate_->OnPopupSize(browser, rect);
97 }
98 
OnPaint(CefRefPtr<CefBrowser> browser,PaintElementType type,const RectList & dirtyRects,const void * buffer,int width,int height)99 void ClientHandlerOsr::OnPaint(CefRefPtr<CefBrowser> browser,
100                                PaintElementType type,
101                                const RectList& dirtyRects,
102                                const void* buffer,
103                                int width,
104                                int height) {
105   CEF_REQUIRE_UI_THREAD();
106   if (!osr_delegate_)
107     return;
108   osr_delegate_->OnPaint(browser, type, dirtyRects, buffer, width, height);
109 }
110 
OnAcceleratedPaint(CefRefPtr<CefBrowser> browser,CefRenderHandler::PaintElementType type,const CefRenderHandler::RectList & dirtyRects,void * share_handle)111 void ClientHandlerOsr::OnAcceleratedPaint(
112     CefRefPtr<CefBrowser> browser,
113     CefRenderHandler::PaintElementType type,
114     const CefRenderHandler::RectList& dirtyRects,
115     void* share_handle) {
116   CEF_REQUIRE_UI_THREAD();
117   if (!osr_delegate_)
118     return;
119   osr_delegate_->OnAcceleratedPaint(browser, type, dirtyRects, share_handle);
120 }
121 
StartDragging(CefRefPtr<CefBrowser> browser,CefRefPtr<CefDragData> drag_data,CefRenderHandler::DragOperationsMask allowed_ops,int x,int y)122 bool ClientHandlerOsr::StartDragging(
123     CefRefPtr<CefBrowser> browser,
124     CefRefPtr<CefDragData> drag_data,
125     CefRenderHandler::DragOperationsMask allowed_ops,
126     int x,
127     int y) {
128   CEF_REQUIRE_UI_THREAD();
129   if (!osr_delegate_)
130     return false;
131   return osr_delegate_->StartDragging(browser, drag_data, allowed_ops, x, y);
132 }
133 
UpdateDragCursor(CefRefPtr<CefBrowser> browser,CefRenderHandler::DragOperation operation)134 void ClientHandlerOsr::UpdateDragCursor(
135     CefRefPtr<CefBrowser> browser,
136     CefRenderHandler::DragOperation operation) {
137   CEF_REQUIRE_UI_THREAD();
138   if (!osr_delegate_)
139     return;
140   osr_delegate_->UpdateDragCursor(browser, operation);
141 }
142 
OnImeCompositionRangeChanged(CefRefPtr<CefBrowser> browser,const CefRange & selection_range,const CefRenderHandler::RectList & character_bounds)143 void ClientHandlerOsr::OnImeCompositionRangeChanged(
144     CefRefPtr<CefBrowser> browser,
145     const CefRange& selection_range,
146     const CefRenderHandler::RectList& character_bounds) {
147   CEF_REQUIRE_UI_THREAD();
148   if (!osr_delegate_)
149     return;
150   osr_delegate_->OnImeCompositionRangeChanged(browser, selection_range,
151                                               character_bounds);
152 }
153 
OnAccessibilityTreeChange(CefRefPtr<CefValue> value)154 void ClientHandlerOsr::OnAccessibilityTreeChange(CefRefPtr<CefValue> value) {
155   CEF_REQUIRE_UI_THREAD();
156   if (!osr_delegate_)
157     return;
158   osr_delegate_->UpdateAccessibilityTree(value);
159 }
160 
OnCursorChange(CefRefPtr<CefBrowser> browser,CefCursorHandle cursor,cef_cursor_type_t type,const CefCursorInfo & custom_cursor_info)161 bool ClientHandlerOsr::OnCursorChange(CefRefPtr<CefBrowser> browser,
162                                       CefCursorHandle cursor,
163                                       cef_cursor_type_t type,
164                                       const CefCursorInfo& custom_cursor_info) {
165   CEF_REQUIRE_UI_THREAD();
166   if (ClientHandler::OnCursorChange(browser, cursor, type,
167                                     custom_cursor_info)) {
168     return true;
169   }
170   if (osr_delegate_) {
171     osr_delegate_->OnCursorChange(browser, cursor, type, custom_cursor_info);
172   }
173   return true;
174 }
175 
OnAccessibilityLocationChange(CefRefPtr<CefValue> value)176 void ClientHandlerOsr::OnAccessibilityLocationChange(
177     CefRefPtr<CefValue> value) {
178   CEF_REQUIRE_UI_THREAD();
179   if (!osr_delegate_)
180     return;
181   osr_delegate_->UpdateAccessibilityLocation(value);
182 }
183 
184 }  // namespace client
185