• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 The Chromium Embedded Framework Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "libcef/browser/osr/browser_platform_delegate_osr.h"
6 
7 #include <utility>
8 
9 #include "libcef/browser/image_impl.h"
10 #include "libcef/browser/osr/osr_accessibility_util.h"
11 #include "libcef/browser/osr/render_widget_host_view_osr.h"
12 #include "libcef/browser/osr/web_contents_view_osr.h"
13 #include "libcef/common/drag_data_impl.h"
14 
15 #include "base/task/current_thread.h"
16 #include "content/browser/renderer_host/render_widget_host_input_event_router.h"
17 #include "content/browser/web_contents/web_contents_impl.h"
18 #include "content/public/browser/render_view_host.h"
19 #include "ui/events/base_event_utils.h"
20 
CefBrowserPlatformDelegateOsr(std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate,bool use_shared_texture,bool use_external_begin_frame)21 CefBrowserPlatformDelegateOsr::CefBrowserPlatformDelegateOsr(
22     std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate,
23     bool use_shared_texture,
24     bool use_external_begin_frame)
25     : native_delegate_(std::move(native_delegate)),
26       use_shared_texture_(use_shared_texture),
27       use_external_begin_frame_(use_external_begin_frame) {
28   native_delegate_->set_windowless_handler(this);
29 }
30 
CreateViewForWebContents(content::WebContentsView ** view,content::RenderViewHostDelegateView ** delegate_view)31 void CefBrowserPlatformDelegateOsr::CreateViewForWebContents(
32     content::WebContentsView** view,
33     content::RenderViewHostDelegateView** delegate_view) {
34   DCHECK(!view_osr_);
35 
36   // Use the OSR view instead of the default platform view.
37   view_osr_ = new CefWebContentsViewOSR(
38       GetBackgroundColor(), use_shared_texture_, use_external_begin_frame_);
39   *view = view_osr_;
40   *delegate_view = view_osr_;
41 }
42 
WebContentsCreated(content::WebContents * web_contents,bool owned)43 void CefBrowserPlatformDelegateOsr::WebContentsCreated(
44     content::WebContents* web_contents,
45     bool owned) {
46   CefBrowserPlatformDelegateAlloy::WebContentsCreated(web_contents, owned);
47 
48   DCHECK(view_osr_);
49   DCHECK(!view_osr_->web_contents());
50 
51   // Associate the WebContents with the OSR view.
52   view_osr_->WebContentsCreated(web_contents);
53 }
54 
RenderViewCreated(content::RenderViewHost * render_view_host)55 void CefBrowserPlatformDelegateOsr::RenderViewCreated(
56     content::RenderViewHost* render_view_host) {
57   if (view_osr_)
58     view_osr_->RenderViewCreated();
59 }
60 
BrowserCreated(CefBrowserHostBase * browser)61 void CefBrowserPlatformDelegateOsr::BrowserCreated(
62     CefBrowserHostBase* browser) {
63   CefBrowserPlatformDelegateAlloy::BrowserCreated(browser);
64 
65   if (browser->IsPopup()) {
66     // Associate the RenderWidget host view with the browser now because the
67     // browser wasn't known at the time that the host view was created.
68     content::RenderViewHost* host = web_contents_->GetRenderViewHost();
69     DCHECK(host);
70     CefRenderWidgetHostViewOSR* view =
71         static_cast<CefRenderWidgetHostViewOSR*>(host->GetWidget()->GetView());
72     // |view| will be null if the popup is a DevTools window.
73     if (view) {
74       view->set_browser_impl(static_cast<AlloyBrowserHostImpl*>(browser));
75     }
76   }
77 }
78 
NotifyBrowserDestroyed()79 void CefBrowserPlatformDelegateOsr::NotifyBrowserDestroyed() {
80   content::RenderViewHost* host = web_contents_->GetRenderViewHost();
81   if (host) {
82     CefRenderWidgetHostViewOSR* view =
83         static_cast<CefRenderWidgetHostViewOSR*>(host->GetWidget()->GetView());
84     if (view) {
85       view->ReleaseCompositor();
86     }
87   }
88 
89   CefBrowserPlatformDelegateAlloy::NotifyBrowserDestroyed();
90 }
91 
BrowserDestroyed(CefBrowserHostBase * browser)92 void CefBrowserPlatformDelegateOsr::BrowserDestroyed(
93     CefBrowserHostBase* browser) {
94   CefBrowserPlatformDelegateAlloy::BrowserDestroyed(browser);
95 
96   view_osr_ = nullptr;
97 }
98 
GetBackgroundColor() const99 SkColor CefBrowserPlatformDelegateOsr::GetBackgroundColor() const {
100   return native_delegate_->GetBackgroundColor();
101 }
102 
WasResized()103 void CefBrowserPlatformDelegateOsr::WasResized() {
104   CefRenderWidgetHostViewOSR* view = GetOSRHostView();
105   if (view)
106     view->WasResized();
107 }
108 
SendKeyEvent(const CefKeyEvent & event)109 void CefBrowserPlatformDelegateOsr::SendKeyEvent(const CefKeyEvent& event) {
110   CefRenderWidgetHostViewOSR* view = GetOSRHostView();
111   if (!view)
112     return;
113 
114   content::NativeWebKeyboardEvent web_event =
115       native_delegate_->TranslateWebKeyEvent(event);
116   view->SendKeyEvent(web_event);
117 }
118 
SendMouseClickEvent(const CefMouseEvent & event,CefBrowserHost::MouseButtonType type,bool mouseUp,int clickCount)119 void CefBrowserPlatformDelegateOsr::SendMouseClickEvent(
120     const CefMouseEvent& event,
121     CefBrowserHost::MouseButtonType type,
122     bool mouseUp,
123     int clickCount) {
124   CefRenderWidgetHostViewOSR* view = GetOSRHostView();
125   if (!view)
126     return;
127 
128   blink::WebMouseEvent web_event = native_delegate_->TranslateWebClickEvent(
129       event, type, mouseUp, clickCount);
130   view->SendMouseEvent(web_event);
131 }
132 
SendMouseMoveEvent(const CefMouseEvent & event,bool mouseLeave)133 void CefBrowserPlatformDelegateOsr::SendMouseMoveEvent(
134     const CefMouseEvent& event,
135     bool mouseLeave) {
136   CefRenderWidgetHostViewOSR* view = GetOSRHostView();
137   if (!view)
138     return;
139 
140   blink::WebMouseEvent web_event =
141       native_delegate_->TranslateWebMoveEvent(event, mouseLeave);
142   view->SendMouseEvent(web_event);
143 }
144 
SendMouseWheelEvent(const CefMouseEvent & event,int deltaX,int deltaY)145 void CefBrowserPlatformDelegateOsr::SendMouseWheelEvent(
146     const CefMouseEvent& event,
147     int deltaX,
148     int deltaY) {
149   CefRenderWidgetHostViewOSR* view = GetOSRHostView();
150   if (!view)
151     return;
152 
153   blink::WebMouseWheelEvent web_event =
154       native_delegate_->TranslateWebWheelEvent(event, deltaX, deltaY);
155   view->SendMouseWheelEvent(web_event);
156 }
157 
SendTouchEvent(const CefTouchEvent & event)158 void CefBrowserPlatformDelegateOsr::SendTouchEvent(const CefTouchEvent& event) {
159   CefRenderWidgetHostViewOSR* view = GetOSRHostView();
160   if (view)
161     view->SendTouchEvent(event);
162 }
163 
SetFocus(bool setFocus)164 void CefBrowserPlatformDelegateOsr::SetFocus(bool setFocus) {
165   CefRenderWidgetHostViewOSR* view = GetOSRHostView();
166   if (view)
167     view->SetFocus(setFocus);
168 }
169 
GetScreenPoint(const gfx::Point & view) const170 gfx::Point CefBrowserPlatformDelegateOsr::GetScreenPoint(
171     const gfx::Point& view) const {
172   CefRefPtr<CefRenderHandler> handler = browser_->client()->GetRenderHandler();
173   if (handler.get()) {
174     int screenX = 0, screenY = 0;
175     if (handler->GetScreenPoint(browser_, view.x(), view.y(), screenX,
176                                 screenY)) {
177       return gfx::Point(screenX, screenY);
178     }
179   }
180   return view;
181 }
182 
ViewText(const std::string & text)183 void CefBrowserPlatformDelegateOsr::ViewText(const std::string& text) {
184   native_delegate_->ViewText(text);
185 }
186 
HandleKeyboardEvent(const content::NativeWebKeyboardEvent & event)187 bool CefBrowserPlatformDelegateOsr::HandleKeyboardEvent(
188     const content::NativeWebKeyboardEvent& event) {
189   return native_delegate_->HandleKeyboardEvent(event);
190 }
191 
GetEventHandle(const content::NativeWebKeyboardEvent & event) const192 CefEventHandle CefBrowserPlatformDelegateOsr::GetEventHandle(
193     const content::NativeWebKeyboardEvent& event) const {
194   return native_delegate_->GetEventHandle(event);
195 }
196 
197 std::unique_ptr<CefFileDialogRunner>
CreateFileDialogRunner()198 CefBrowserPlatformDelegateOsr::CreateFileDialogRunner() {
199   return native_delegate_->CreateFileDialogRunner();
200 }
201 
202 std::unique_ptr<CefJavaScriptDialogRunner>
CreateJavaScriptDialogRunner()203 CefBrowserPlatformDelegateOsr::CreateJavaScriptDialogRunner() {
204   return native_delegate_->CreateJavaScriptDialogRunner();
205 }
206 
207 std::unique_ptr<CefMenuRunner>
CreateMenuRunner()208 CefBrowserPlatformDelegateOsr::CreateMenuRunner() {
209   return native_delegate_->CreateMenuRunner();
210 }
211 
IsWindowless() const212 bool CefBrowserPlatformDelegateOsr::IsWindowless() const {
213   return true;
214 }
215 
WasHidden(bool hidden)216 void CefBrowserPlatformDelegateOsr::WasHidden(bool hidden) {
217   // The WebContentsImpl will notify the OSR view.
218   content::WebContentsImpl* web_contents =
219       static_cast<content::WebContentsImpl*>(web_contents_);
220   if (web_contents) {
221     if (hidden)
222       web_contents->WasHidden();
223     else
224       web_contents->WasShown();
225   }
226 }
227 
NotifyScreenInfoChanged()228 void CefBrowserPlatformDelegateOsr::NotifyScreenInfoChanged() {
229   CefRenderWidgetHostViewOSR* view = GetOSRHostView();
230   if (view)
231     view->OnScreenInfoChanged();
232 }
233 
Invalidate(cef_paint_element_type_t type)234 void CefBrowserPlatformDelegateOsr::Invalidate(cef_paint_element_type_t type) {
235   CefRenderWidgetHostViewOSR* view = GetOSRHostView();
236   if (view)
237     view->Invalidate(type);
238 }
239 
SendExternalBeginFrame()240 void CefBrowserPlatformDelegateOsr::SendExternalBeginFrame() {
241   CefRenderWidgetHostViewOSR* view = GetOSRHostView();
242   if (view)
243     view->SendExternalBeginFrame();
244 }
245 
SetWindowlessFrameRate(int frame_rate)246 void CefBrowserPlatformDelegateOsr::SetWindowlessFrameRate(int frame_rate) {
247   CefRenderWidgetHostViewOSR* view = GetOSRHostView();
248   if (view)
249     view->UpdateFrameRate();
250 }
251 
ImeSetComposition(const CefString & text,const std::vector<CefCompositionUnderline> & underlines,const CefRange & replacement_range,const CefRange & selection_range)252 void CefBrowserPlatformDelegateOsr::ImeSetComposition(
253     const CefString& text,
254     const std::vector<CefCompositionUnderline>& underlines,
255     const CefRange& replacement_range,
256     const CefRange& selection_range) {
257   CefRenderWidgetHostViewOSR* view = GetOSRHostView();
258   if (view) {
259     view->ImeSetComposition(text, underlines, replacement_range,
260                             selection_range);
261   }
262 }
263 
ImeCommitText(const CefString & text,const CefRange & replacement_range,int relative_cursor_pos)264 void CefBrowserPlatformDelegateOsr::ImeCommitText(
265     const CefString& text,
266     const CefRange& replacement_range,
267     int relative_cursor_pos) {
268   CefRenderWidgetHostViewOSR* view = GetOSRHostView();
269   if (view)
270     view->ImeCommitText(text, replacement_range, relative_cursor_pos);
271 }
272 
ImeFinishComposingText(bool keep_selection)273 void CefBrowserPlatformDelegateOsr::ImeFinishComposingText(
274     bool keep_selection) {
275   CefRenderWidgetHostViewOSR* view = GetOSRHostView();
276   if (view)
277     view->ImeFinishComposingText(keep_selection);
278 }
279 
ImeCancelComposition()280 void CefBrowserPlatformDelegateOsr::ImeCancelComposition() {
281   CefRenderWidgetHostViewOSR* view = GetOSRHostView();
282   if (view)
283     view->ImeCancelComposition();
284 }
285 
DragTargetDragEnter(CefRefPtr<CefDragData> drag_data,const CefMouseEvent & event,cef_drag_operations_mask_t allowed_ops)286 void CefBrowserPlatformDelegateOsr::DragTargetDragEnter(
287     CefRefPtr<CefDragData> drag_data,
288     const CefMouseEvent& event,
289     cef_drag_operations_mask_t allowed_ops) {
290   content::WebContentsImpl* web_contents =
291       static_cast<content::WebContentsImpl*>(web_contents_);
292   if (!web_contents)
293     return;
294 
295   if (current_rvh_for_drag_)
296     DragTargetDragLeave();
297 
298   const gfx::Point client_pt(event.x, event.y);
299   gfx::PointF transformed_pt;
300   current_rwh_for_drag_ =
301       web_contents->GetInputEventRouter()
302           ->GetRenderWidgetHostAtPoint(
303               web_contents->GetRenderViewHost()->GetWidget()->GetView(),
304               gfx::PointF(client_pt), &transformed_pt)
305           ->GetWeakPtr();
306   current_rvh_for_drag_ = web_contents->GetRenderViewHost();
307 
308   drag_data_ = drag_data;
309   drag_allowed_ops_ = allowed_ops;
310 
311   CefDragDataImpl* data_impl = static_cast<CefDragDataImpl*>(drag_data.get());
312   base::AutoLock lock_scope(data_impl->lock());
313   content::DropData* drop_data = data_impl->drop_data();
314   const gfx::Point& screen_pt = GetScreenPoint(client_pt);
315   blink::DragOperationsMask ops =
316       static_cast<blink::DragOperationsMask>(allowed_ops);
317   int modifiers = TranslateWebEventModifiers(event.modifiers);
318 
319   current_rwh_for_drag_->FilterDropData(drop_data);
320 
321   // Give the delegate an opportunity to cancel the drag.
322   if (web_contents->GetDelegate() && !web_contents->GetDelegate()->CanDragEnter(
323                                          web_contents, *drop_data, ops)) {
324     drag_data_ = nullptr;
325     return;
326   }
327 
328   current_rwh_for_drag_->DragTargetDragEnter(*drop_data, transformed_pt,
329                                              gfx::PointF(screen_pt), ops,
330                                              modifiers, base::DoNothing());
331 }
332 
DragTargetDragOver(const CefMouseEvent & event,cef_drag_operations_mask_t allowed_ops)333 void CefBrowserPlatformDelegateOsr::DragTargetDragOver(
334     const CefMouseEvent& event,
335     cef_drag_operations_mask_t allowed_ops) {
336   if (!drag_data_)
337     return;
338 
339   content::WebContentsImpl* web_contents =
340       static_cast<content::WebContentsImpl*>(web_contents_);
341   if (!web_contents)
342     return;
343 
344   const gfx::Point client_pt(event.x, event.y);
345   const gfx::Point& screen_pt = GetScreenPoint(client_pt);
346 
347   gfx::PointF transformed_pt;
348   content::RenderWidgetHostImpl* target_rwh =
349       web_contents->GetInputEventRouter()->GetRenderWidgetHostAtPoint(
350           web_contents->GetRenderViewHost()->GetWidget()->GetView(),
351           gfx::PointF(client_pt), &transformed_pt);
352 
353   if (target_rwh != current_rwh_for_drag_.get()) {
354     if (current_rwh_for_drag_) {
355       gfx::PointF transformed_leave_point(client_pt);
356       gfx::PointF transformed_screen_point(screen_pt);
357       static_cast<content::RenderWidgetHostViewBase*>(
358           web_contents->GetRenderWidgetHostView())
359           ->TransformPointToCoordSpaceForView(
360               gfx::PointF(client_pt),
361               static_cast<content::RenderWidgetHostViewBase*>(
362                   current_rwh_for_drag_->GetView()),
363               &transformed_leave_point);
364       static_cast<content::RenderWidgetHostViewBase*>(
365           web_contents->GetRenderWidgetHostView())
366           ->TransformPointToCoordSpaceForView(
367               gfx::PointF(screen_pt),
368               static_cast<content::RenderWidgetHostViewBase*>(
369                   current_rwh_for_drag_->GetView()),
370               &transformed_screen_point);
371       current_rwh_for_drag_->DragTargetDragLeave(transformed_leave_point,
372                                                  transformed_screen_point);
373     }
374     DragTargetDragEnter(drag_data_, event, drag_allowed_ops_);
375   }
376 
377   if (!drag_data_)
378     return;
379 
380   blink::DragOperationsMask ops =
381       static_cast<blink::DragOperationsMask>(allowed_ops);
382   int modifiers = TranslateWebEventModifiers(event.modifiers);
383 
384   target_rwh->DragTargetDragOver(transformed_pt, gfx::PointF(screen_pt), ops,
385                                  modifiers, base::DoNothing());
386 }
387 
DragTargetDragLeave()388 void CefBrowserPlatformDelegateOsr::DragTargetDragLeave() {
389   if (current_rvh_for_drag_ != web_contents_->GetRenderViewHost() ||
390       !drag_data_) {
391     return;
392   }
393 
394   if (current_rwh_for_drag_) {
395     current_rwh_for_drag_->DragTargetDragLeave(gfx::PointF(), gfx::PointF());
396     current_rwh_for_drag_.reset();
397   }
398 
399   drag_data_ = nullptr;
400 }
401 
DragTargetDrop(const CefMouseEvent & event)402 void CefBrowserPlatformDelegateOsr::DragTargetDrop(const CefMouseEvent& event) {
403   if (!drag_data_)
404     return;
405 
406   content::WebContentsImpl* web_contents =
407       static_cast<content::WebContentsImpl*>(web_contents_);
408   if (!web_contents)
409     return;
410 
411   gfx::Point client_pt(event.x, event.y);
412   const gfx::Point& screen_pt = GetScreenPoint(client_pt);
413 
414   gfx::PointF transformed_pt;
415   content::RenderWidgetHostImpl* target_rwh =
416       web_contents->GetInputEventRouter()->GetRenderWidgetHostAtPoint(
417           web_contents->GetRenderViewHost()->GetWidget()->GetView(),
418           gfx::PointF(client_pt), &transformed_pt);
419 
420   if (target_rwh != current_rwh_for_drag_.get()) {
421     if (current_rwh_for_drag_) {
422       gfx::PointF transformed_leave_point(client_pt);
423       gfx::PointF transformed_screen_point(screen_pt);
424       static_cast<content::RenderWidgetHostViewBase*>(
425           web_contents->GetRenderWidgetHostView())
426           ->TransformPointToCoordSpaceForView(
427               gfx::PointF(client_pt),
428               static_cast<content::RenderWidgetHostViewBase*>(
429                   current_rwh_for_drag_->GetView()),
430               &transformed_leave_point);
431       static_cast<content::RenderWidgetHostViewBase*>(
432           web_contents->GetRenderWidgetHostView())
433           ->TransformPointToCoordSpaceForView(
434               gfx::PointF(screen_pt),
435               static_cast<content::RenderWidgetHostViewBase*>(
436                   current_rwh_for_drag_->GetView()),
437               &transformed_screen_point);
438       current_rwh_for_drag_->DragTargetDragLeave(transformed_leave_point,
439                                                  transformed_screen_point);
440     }
441     DragTargetDragEnter(drag_data_, event, drag_allowed_ops_);
442   }
443 
444   if (!drag_data_)
445     return;
446 
447   {
448     CefDragDataImpl* data_impl =
449         static_cast<CefDragDataImpl*>(drag_data_.get());
450     base::AutoLock lock_scope(data_impl->lock());
451     content::DropData* drop_data = data_impl->drop_data();
452     int modifiers = TranslateWebEventModifiers(event.modifiers);
453 
454     target_rwh->DragTargetDrop(*drop_data, transformed_pt,
455                                gfx::PointF(screen_pt), modifiers,
456                                base::DoNothing());
457   }
458 
459   drag_data_ = nullptr;
460 }
461 
StartDragging(const content::DropData & drop_data,blink::DragOperationsMask allowed_ops,const gfx::ImageSkia & image,const gfx::Vector2d & image_offset,const blink::mojom::DragEventSourceInfo & event_info,content::RenderWidgetHostImpl * source_rwh)462 void CefBrowserPlatformDelegateOsr::StartDragging(
463     const content::DropData& drop_data,
464     blink::DragOperationsMask allowed_ops,
465     const gfx::ImageSkia& image,
466     const gfx::Vector2d& image_offset,
467     const blink::mojom::DragEventSourceInfo& event_info,
468     content::RenderWidgetHostImpl* source_rwh) {
469   drag_start_rwh_ = source_rwh->GetWeakPtr();
470 
471   bool handled = false;
472 
473   CefRefPtr<CefRenderHandler> handler =
474       browser_->GetClient()->GetRenderHandler();
475   if (handler.get()) {
476     CefRefPtr<CefImage> cef_image(new CefImageImpl(image));
477     CefPoint cef_image_pos(image_offset.x(), image_offset.y());
478     CefRefPtr<CefDragDataImpl> drag_data(
479         new CefDragDataImpl(drop_data, cef_image, cef_image_pos));
480     drag_data->SetReadOnly(true);
481     base::CurrentThread::ScopedNestableTaskAllower allow;
482     handled = handler->StartDragging(
483         browser_, drag_data.get(),
484         static_cast<CefRenderHandler::DragOperationsMask>(allowed_ops),
485         event_info.location.x(), event_info.location.y());
486   }
487 
488   if (!handled)
489     DragSourceSystemDragEnded();
490 }
491 
UpdateDragCursor(ui::mojom::DragOperation operation)492 void CefBrowserPlatformDelegateOsr::UpdateDragCursor(
493     ui::mojom::DragOperation operation) {
494   CefRefPtr<CefRenderHandler> handler =
495       browser_->GetClient()->GetRenderHandler();
496   if (handler.get()) {
497     handler->UpdateDragCursor(
498         browser_, static_cast<CefRenderHandler::DragOperation>(operation));
499   }
500 }
501 
DragSourceEndedAt(int x,int y,cef_drag_operations_mask_t op)502 void CefBrowserPlatformDelegateOsr::DragSourceEndedAt(
503     int x,
504     int y,
505     cef_drag_operations_mask_t op) {
506   if (!drag_start_rwh_)
507     return;
508 
509   content::WebContentsImpl* web_contents =
510       static_cast<content::WebContentsImpl*>(web_contents_);
511   if (!web_contents)
512     return;
513 
514   content::RenderWidgetHostImpl* source_rwh = drag_start_rwh_.get();
515   const gfx::Point client_loc(gfx::Point(x, y));
516   const gfx::Point& screen_loc = GetScreenPoint(client_loc);
517   ui::mojom::DragOperation drag_op = static_cast<ui::mojom::DragOperation>(op);
518 
519   // |client_loc| and |screen_loc| are in the root coordinate space, for
520   // non-root RenderWidgetHosts they need to be transformed.
521   gfx::PointF transformed_point(client_loc);
522   gfx::PointF transformed_screen_point(screen_loc);
523   if (source_rwh && web_contents->GetRenderWidgetHostView()) {
524     static_cast<content::RenderWidgetHostViewBase*>(
525         web_contents->GetRenderWidgetHostView())
526         ->TransformPointToCoordSpaceForView(
527             gfx::PointF(client_loc),
528             static_cast<content::RenderWidgetHostViewBase*>(
529                 source_rwh->GetView()),
530             &transformed_point);
531     static_cast<content::RenderWidgetHostViewBase*>(
532         web_contents->GetRenderWidgetHostView())
533         ->TransformPointToCoordSpaceForView(
534             gfx::PointF(screen_loc),
535             static_cast<content::RenderWidgetHostViewBase*>(
536                 source_rwh->GetView()),
537             &transformed_screen_point);
538   }
539 
540   web_contents->DragSourceEndedAt(transformed_point.x(), transformed_point.y(),
541                                   transformed_screen_point.x(),
542                                   transformed_screen_point.y(), drag_op,
543                                   source_rwh);
544 }
545 
DragSourceSystemDragEnded()546 void CefBrowserPlatformDelegateOsr::DragSourceSystemDragEnded() {
547   if (!drag_start_rwh_)
548     return;
549 
550   content::WebContentsImpl* web_contents =
551       static_cast<content::WebContentsImpl*>(web_contents_);
552   if (!web_contents)
553     return;
554 
555   web_contents->SystemDragEnded(drag_start_rwh_.get());
556 
557   drag_start_rwh_ = nullptr;
558 }
559 
AccessibilityEventReceived(const content::AXEventNotificationDetails & eventData)560 void CefBrowserPlatformDelegateOsr::AccessibilityEventReceived(
561     const content::AXEventNotificationDetails& eventData) {
562   CefRefPtr<CefRenderHandler> handler = browser_->client()->GetRenderHandler();
563   if (handler.get()) {
564     CefRefPtr<CefAccessibilityHandler> acchandler =
565         handler->GetAccessibilityHandler();
566 
567     if (acchandler.get()) {
568       acchandler->OnAccessibilityTreeChange(
569           osr_accessibility_util::ParseAccessibilityEventData(eventData));
570     }
571   }
572 }
573 
AccessibilityLocationChangesReceived(const std::vector<content::AXLocationChangeNotificationDetails> & locData)574 void CefBrowserPlatformDelegateOsr::AccessibilityLocationChangesReceived(
575     const std::vector<content::AXLocationChangeNotificationDetails>& locData) {
576   CefRefPtr<CefRenderHandler> handler = browser_->client()->GetRenderHandler();
577   if (handler.get()) {
578     CefRefPtr<CefAccessibilityHandler> acchandler =
579         handler->GetAccessibilityHandler();
580 
581     if (acchandler.get()) {
582       acchandler->OnAccessibilityLocationChange(
583           osr_accessibility_util::ParseAccessibilityLocationData(locData));
584     }
585   }
586 }
587 
GetParentWindowHandle() const588 CefWindowHandle CefBrowserPlatformDelegateOsr::GetParentWindowHandle() const {
589   return GetHostWindowHandle();
590 }
591 
GetParentScreenPoint(const gfx::Point & view) const592 gfx::Point CefBrowserPlatformDelegateOsr::GetParentScreenPoint(
593     const gfx::Point& view) const {
594   return GetScreenPoint(view);
595 }
596 
GetOSRHostView() const597 CefRenderWidgetHostViewOSR* CefBrowserPlatformDelegateOsr::GetOSRHostView()
598     const {
599   content::RenderViewHost* host = web_contents_->GetRenderViewHost();
600   if (host) {
601     return static_cast<CefRenderWidgetHostViewOSR*>(
602         host->GetWidget()->GetView());
603   }
604 
605   return nullptr;
606 }
607