2015-11-17 19:20:13 +01:00
|
|
|
// Copyright 2015 The Chromium Embedded Framework Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/browser/osr/browser_platform_delegate_osr.h"
|
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
#include <utility>
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "libcef/browser/browser_host_impl.h"
|
2017-05-11 20:22:21 +02:00
|
|
|
#include "libcef/browser/image_impl.h"
|
2017-05-12 20:28:25 +02:00
|
|
|
#include "libcef/browser/osr/osr_accessibility_util.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "libcef/browser/osr/render_widget_host_view_osr.h"
|
|
|
|
#include "libcef/browser/osr/web_contents_view_osr.h"
|
|
|
|
#include "libcef/common/drag_data_impl.h"
|
|
|
|
|
2018-05-18 12:45:18 +02:00
|
|
|
#include "base/message_loop/message_loop_current.h"
|
2016-11-23 21:54:29 +01:00
|
|
|
#include "content/browser/renderer_host/render_widget_host_input_event_router.h"
|
|
|
|
#include "content/browser/web_contents/web_contents_impl.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "content/public/browser/render_view_host.h"
|
|
|
|
|
|
|
|
CefBrowserPlatformDelegateOsr::CefBrowserPlatformDelegateOsr(
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate)
|
2017-05-17 11:29:28 +02:00
|
|
|
: native_delegate_(std::move(native_delegate)), view_osr_(nullptr) {
|
2015-11-17 19:20:13 +01:00
|
|
|
native_delegate_->set_windowless_handler(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::CreateViewForWebContents(
|
|
|
|
content::WebContentsView** view,
|
|
|
|
content::RenderViewHostDelegateView** delegate_view) {
|
|
|
|
DCHECK(!view_osr_);
|
|
|
|
|
|
|
|
// Use the OSR view instead of the default platform view.
|
2017-04-20 21:28:17 +02:00
|
|
|
view_osr_ = new CefWebContentsViewOSR(GetBackgroundColor());
|
2015-11-17 19:20:13 +01:00
|
|
|
*view = view_osr_;
|
|
|
|
*delegate_view = view_osr_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::WebContentsCreated(
|
|
|
|
content::WebContents* web_contents) {
|
|
|
|
DCHECK(view_osr_);
|
|
|
|
DCHECK(!view_osr_->web_contents());
|
|
|
|
|
|
|
|
// Associate the WebContents with the OSR view.
|
2017-02-15 22:03:00 +01:00
|
|
|
view_osr_->WebContentsCreated(web_contents);
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::BrowserCreated(
|
|
|
|
CefBrowserHostImpl* browser) {
|
|
|
|
CefBrowserPlatformDelegate::BrowserCreated(browser);
|
|
|
|
|
|
|
|
if (browser->IsPopup()) {
|
|
|
|
// Associate the RenderWidget host view with the browser now because the
|
|
|
|
// browser wasn't known at the time that the host view was created.
|
|
|
|
content::RenderViewHost* host =
|
|
|
|
browser->web_contents()->GetRenderViewHost();
|
|
|
|
DCHECK(host);
|
|
|
|
CefRenderWidgetHostViewOSR* view =
|
|
|
|
static_cast<CefRenderWidgetHostViewOSR*>(host->GetWidget()->GetView());
|
|
|
|
// |view| will be null if the popup is a DevTools window.
|
|
|
|
if (view)
|
|
|
|
view->set_browser_impl(browser);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::BrowserDestroyed(
|
|
|
|
CefBrowserHostImpl* browser) {
|
|
|
|
CefBrowserPlatformDelegate::BrowserDestroyed(browser);
|
|
|
|
|
|
|
|
view_osr_ = nullptr;
|
|
|
|
}
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
SkColor CefBrowserPlatformDelegateOsr::GetBackgroundColor() const {
|
|
|
|
return native_delegate_->GetBackgroundColor();
|
|
|
|
}
|
|
|
|
|
2018-05-17 10:58:21 +02:00
|
|
|
void CefBrowserPlatformDelegateOsr::SynchronizeVisualProperties() {
|
2015-11-17 19:20:13 +01:00
|
|
|
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
|
|
|
|
if (view)
|
2018-05-17 10:58:21 +02:00
|
|
|
view->SynchronizeVisualProperties();
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::SendKeyEvent(
|
|
|
|
const content::NativeWebKeyboardEvent& event) {
|
|
|
|
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
|
|
|
|
if (view)
|
|
|
|
view->SendKeyEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::SendMouseEvent(
|
|
|
|
const blink::WebMouseEvent& event) {
|
|
|
|
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
|
|
|
|
if (view)
|
|
|
|
view->SendMouseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::SendMouseWheelEvent(
|
|
|
|
const blink::WebMouseWheelEvent& event) {
|
|
|
|
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
|
|
|
|
if (view)
|
|
|
|
view->SendMouseWheelEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::SendFocusEvent(bool setFocus) {
|
|
|
|
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
|
|
|
|
if (view)
|
|
|
|
view->SendFocusEvent(setFocus);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Point CefBrowserPlatformDelegateOsr::GetScreenPoint(
|
|
|
|
const gfx::Point& view) const {
|
|
|
|
CefRefPtr<CefRenderHandler> handler = browser_->client()->GetRenderHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
int screenX = 0, screenY = 0;
|
2017-05-17 11:29:28 +02:00
|
|
|
if (handler->GetScreenPoint(browser_, view.x(), view.y(), screenX,
|
|
|
|
screenY)) {
|
2015-11-17 19:20:13 +01:00
|
|
|
return gfx::Point(screenX, screenY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::ViewText(const std::string& text) {
|
|
|
|
native_delegate_->ViewText(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::HandleKeyboardEvent(
|
|
|
|
const content::NativeWebKeyboardEvent& event) {
|
|
|
|
native_delegate_->HandleKeyboardEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::HandleExternalProtocol(const GURL& url) {
|
|
|
|
native_delegate_->HandleExternalProtocol(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::TranslateKeyEvent(
|
|
|
|
content::NativeWebKeyboardEvent& result,
|
|
|
|
const CefKeyEvent& key_event) const {
|
|
|
|
native_delegate_->TranslateKeyEvent(result, key_event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::TranslateClickEvent(
|
|
|
|
blink::WebMouseEvent& result,
|
|
|
|
const CefMouseEvent& mouse_event,
|
|
|
|
CefBrowserHost::MouseButtonType type,
|
2017-05-17 11:29:28 +02:00
|
|
|
bool mouseUp,
|
|
|
|
int clickCount) const {
|
2015-11-17 19:20:13 +01:00
|
|
|
native_delegate_->TranslateClickEvent(result, mouse_event, type, mouseUp,
|
|
|
|
clickCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::TranslateMoveEvent(
|
|
|
|
blink::WebMouseEvent& result,
|
|
|
|
const CefMouseEvent& mouse_event,
|
|
|
|
bool mouseLeave) const {
|
|
|
|
native_delegate_->TranslateMoveEvent(result, mouse_event, mouseLeave);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::TranslateWheelEvent(
|
|
|
|
blink::WebMouseWheelEvent& result,
|
|
|
|
const CefMouseEvent& mouse_event,
|
2017-05-17 11:29:28 +02:00
|
|
|
int deltaX,
|
|
|
|
int deltaY) const {
|
2015-11-17 19:20:13 +01:00
|
|
|
native_delegate_->TranslateWheelEvent(result, mouse_event, deltaX, deltaY);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefEventHandle CefBrowserPlatformDelegateOsr::GetEventHandle(
|
|
|
|
const content::NativeWebKeyboardEvent& event) const {
|
|
|
|
return native_delegate_->GetEventHandle(event);
|
|
|
|
}
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefFileDialogRunner>
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserPlatformDelegateOsr::CreateFileDialogRunner() {
|
2015-11-17 19:20:13 +01:00
|
|
|
return native_delegate_->CreateFileDialogRunner();
|
|
|
|
}
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefJavaScriptDialogRunner>
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserPlatformDelegateOsr::CreateJavaScriptDialogRunner() {
|
2015-11-17 19:20:13 +01:00
|
|
|
return native_delegate_->CreateJavaScriptDialogRunner();
|
|
|
|
}
|
|
|
|
|
2017-03-03 23:37:23 +01:00
|
|
|
std::unique_ptr<CefMenuRunner>
|
|
|
|
CefBrowserPlatformDelegateOsr::CreateMenuRunner() {
|
2015-11-17 19:20:13 +01:00
|
|
|
return native_delegate_->CreateMenuRunner();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBrowserPlatformDelegateOsr::IsWindowless() const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
bool CefBrowserPlatformDelegateOsr::IsViewsHosted() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
void CefBrowserPlatformDelegateOsr::WasHidden(bool hidden) {
|
|
|
|
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
|
|
|
|
if (view) {
|
|
|
|
if (hidden)
|
|
|
|
view->Hide();
|
|
|
|
else
|
|
|
|
view->Show();
|
|
|
|
}
|
2017-07-05 20:51:46 +02:00
|
|
|
|
|
|
|
// Also notify the WebContentsImpl for consistency.
|
|
|
|
content::WebContentsImpl* web_contents =
|
|
|
|
static_cast<content::WebContentsImpl*>(browser_->web_contents());
|
|
|
|
if (web_contents) {
|
|
|
|
if (hidden)
|
|
|
|
web_contents->WasHidden();
|
|
|
|
else
|
|
|
|
web_contents->WasShown();
|
|
|
|
}
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::NotifyScreenInfoChanged() {
|
|
|
|
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
|
|
|
|
if (view)
|
|
|
|
view->OnScreenInfoChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::Invalidate(cef_paint_element_type_t type) {
|
|
|
|
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
|
|
|
|
if (view)
|
|
|
|
view->Invalidate(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::SetWindowlessFrameRate(int frame_rate) {
|
|
|
|
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
|
|
|
|
if (view)
|
|
|
|
view->UpdateFrameRate();
|
|
|
|
}
|
|
|
|
|
2016-10-28 18:11:24 +02:00
|
|
|
void CefBrowserPlatformDelegateOsr::ImeSetComposition(
|
|
|
|
const CefString& text,
|
|
|
|
const std::vector<CefCompositionUnderline>& underlines,
|
|
|
|
const CefRange& replacement_range,
|
|
|
|
const CefRange& selection_range) {
|
|
|
|
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
|
|
|
|
if (view) {
|
2017-05-17 11:29:28 +02:00
|
|
|
view->ImeSetComposition(text, underlines, replacement_range,
|
|
|
|
selection_range);
|
2016-10-28 18:11:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::ImeCommitText(
|
|
|
|
const CefString& text,
|
|
|
|
const CefRange& replacement_range,
|
|
|
|
int relative_cursor_pos) {
|
|
|
|
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
|
|
|
|
if (view)
|
|
|
|
view->ImeCommitText(text, replacement_range, relative_cursor_pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::ImeFinishComposingText(
|
|
|
|
bool keep_selection) {
|
|
|
|
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
|
|
|
|
if (view)
|
|
|
|
view->ImeFinishComposingText(keep_selection);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::ImeCancelComposition() {
|
|
|
|
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
|
|
|
|
if (view)
|
|
|
|
view->ImeCancelComposition();
|
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
void CefBrowserPlatformDelegateOsr::DragTargetDragEnter(
|
|
|
|
CefRefPtr<CefDragData> drag_data,
|
|
|
|
const CefMouseEvent& event,
|
|
|
|
cef_drag_operations_mask_t allowed_ops) {
|
2016-11-23 21:54:29 +01:00
|
|
|
content::WebContentsImpl* web_contents =
|
|
|
|
static_cast<content::WebContentsImpl*>(browser_->web_contents());
|
|
|
|
if (!web_contents)
|
2015-11-17 19:20:13 +01:00
|
|
|
return;
|
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
if (current_rvh_for_drag_)
|
|
|
|
DragTargetDragLeave();
|
|
|
|
|
|
|
|
const gfx::Point client_pt(event.x, event.y);
|
2017-12-07 22:44:24 +01:00
|
|
|
gfx::PointF transformed_pt;
|
2016-11-23 21:54:29 +01:00
|
|
|
current_rwh_for_drag_ =
|
2017-05-17 11:29:28 +02:00
|
|
|
web_contents->GetInputEventRouter()
|
|
|
|
->GetRenderWidgetHostAtPoint(
|
|
|
|
web_contents->GetRenderViewHost()->GetWidget()->GetView(),
|
2017-12-07 22:44:24 +01:00
|
|
|
gfx::PointF(client_pt), &transformed_pt)
|
2017-05-17 11:29:28 +02:00
|
|
|
->GetWeakPtr();
|
2016-11-23 21:54:29 +01:00
|
|
|
current_rvh_for_drag_ = web_contents->GetRenderViewHost();
|
|
|
|
|
2016-06-21 00:59:23 +02:00
|
|
|
drag_data_ = drag_data;
|
2016-11-23 21:54:29 +01:00
|
|
|
drag_allowed_ops_ = allowed_ops;
|
2016-06-21 00:59:23 +02:00
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
CefDragDataImpl* data_impl = static_cast<CefDragDataImpl*>(drag_data.get());
|
|
|
|
base::AutoLock lock_scope(data_impl->lock());
|
2016-06-21 00:59:23 +02:00
|
|
|
content::DropData* drop_data = data_impl->drop_data();
|
2015-11-17 19:20:13 +01:00
|
|
|
const gfx::Point& screen_pt = GetScreenPoint(client_pt);
|
|
|
|
blink::WebDragOperationsMask ops =
|
|
|
|
static_cast<blink::WebDragOperationsMask>(allowed_ops);
|
|
|
|
int modifiers = TranslateModifiers(event.modifiers);
|
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
current_rwh_for_drag_->FilterDropData(drop_data);
|
|
|
|
|
|
|
|
// Give the delegate an opportunity to cancel the drag.
|
2017-05-17 11:29:28 +02:00
|
|
|
if (web_contents->GetDelegate() && !web_contents->GetDelegate()->CanDragEnter(
|
|
|
|
web_contents, *drop_data, ops)) {
|
2016-11-23 21:54:29 +01:00
|
|
|
drag_data_ = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-07 22:44:24 +01:00
|
|
|
current_rwh_for_drag_->DragTargetDragEnter(
|
|
|
|
*drop_data, transformed_pt, gfx::PointF(screen_pt), ops, modifiers);
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::DragTargetDragOver(
|
|
|
|
const CefMouseEvent& event,
|
|
|
|
cef_drag_operations_mask_t allowed_ops) {
|
2016-11-23 21:54:29 +01:00
|
|
|
if (!drag_data_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
content::WebContentsImpl* web_contents =
|
|
|
|
static_cast<content::WebContentsImpl*>(browser_->web_contents());
|
|
|
|
if (!web_contents)
|
2015-11-17 19:20:13 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
const gfx::Point client_pt(event.x, event.y);
|
2017-03-03 23:37:23 +01:00
|
|
|
const gfx::Point& screen_pt = GetScreenPoint(client_pt);
|
|
|
|
|
2017-12-07 22:44:24 +01:00
|
|
|
gfx::PointF transformed_pt;
|
2016-11-23 21:54:29 +01:00
|
|
|
content::RenderWidgetHostImpl* target_rwh =
|
|
|
|
web_contents->GetInputEventRouter()->GetRenderWidgetHostAtPoint(
|
2017-12-07 22:44:24 +01:00
|
|
|
web_contents->GetRenderViewHost()->GetWidget()->GetView(),
|
|
|
|
gfx::PointF(client_pt), &transformed_pt);
|
2016-11-23 21:54:29 +01:00
|
|
|
|
|
|
|
if (target_rwh != current_rwh_for_drag_.get()) {
|
2017-03-03 23:37:23 +01:00
|
|
|
if (current_rwh_for_drag_) {
|
2017-12-07 22:44:24 +01:00
|
|
|
gfx::PointF transformed_leave_point(client_pt);
|
|
|
|
gfx::PointF transformed_screen_point(screen_pt);
|
2017-03-03 23:37:23 +01:00
|
|
|
static_cast<content::RenderWidgetHostViewBase*>(
|
|
|
|
web_contents->GetRenderWidgetHostView())
|
|
|
|
->TransformPointToCoordSpaceForView(
|
2017-12-07 22:44:24 +01:00
|
|
|
gfx::PointF(client_pt),
|
2017-03-03 23:37:23 +01:00
|
|
|
static_cast<content::RenderWidgetHostViewBase*>(
|
|
|
|
current_rwh_for_drag_->GetView()),
|
|
|
|
&transformed_leave_point);
|
|
|
|
static_cast<content::RenderWidgetHostViewBase*>(
|
|
|
|
web_contents->GetRenderWidgetHostView())
|
|
|
|
->TransformPointToCoordSpaceForView(
|
2017-12-07 22:44:24 +01:00
|
|
|
gfx::PointF(screen_pt),
|
2017-03-03 23:37:23 +01:00
|
|
|
static_cast<content::RenderWidgetHostViewBase*>(
|
|
|
|
current_rwh_for_drag_->GetView()),
|
|
|
|
&transformed_screen_point);
|
|
|
|
current_rwh_for_drag_->DragTargetDragLeave(transformed_leave_point,
|
|
|
|
transformed_screen_point);
|
|
|
|
}
|
2016-11-23 21:54:29 +01:00
|
|
|
DragTargetDragEnter(drag_data_, event, drag_allowed_ops_);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!drag_data_)
|
|
|
|
return;
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
blink::WebDragOperationsMask ops =
|
|
|
|
static_cast<blink::WebDragOperationsMask>(allowed_ops);
|
|
|
|
int modifiers = TranslateModifiers(event.modifiers);
|
|
|
|
|
2017-12-07 22:44:24 +01:00
|
|
|
target_rwh->DragTargetDragOver(transformed_pt, gfx::PointF(screen_pt), ops,
|
|
|
|
modifiers);
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::DragTargetDragLeave() {
|
2016-11-23 21:54:29 +01:00
|
|
|
if (current_rvh_for_drag_ != browser_->web_contents()->GetRenderViewHost() ||
|
|
|
|
!drag_data_) {
|
2015-11-17 19:20:13 +01:00
|
|
|
return;
|
2016-11-23 21:54:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (current_rwh_for_drag_) {
|
2017-12-07 22:44:24 +01:00
|
|
|
current_rwh_for_drag_->DragTargetDragLeave(gfx::PointF(), gfx::PointF());
|
2016-11-23 21:54:29 +01:00
|
|
|
current_rwh_for_drag_.reset();
|
|
|
|
}
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
drag_data_ = nullptr;
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::DragTargetDrop(const CefMouseEvent& event) {
|
2016-11-23 21:54:29 +01:00
|
|
|
if (!drag_data_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
content::WebContentsImpl* web_contents =
|
|
|
|
static_cast<content::WebContentsImpl*>(browser_->web_contents());
|
|
|
|
if (!web_contents)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gfx::Point client_pt(event.x, event.y);
|
2017-03-03 23:37:23 +01:00
|
|
|
const gfx::Point& screen_pt = GetScreenPoint(client_pt);
|
|
|
|
|
2017-12-07 22:44:24 +01:00
|
|
|
gfx::PointF transformed_pt;
|
2016-11-23 21:54:29 +01:00
|
|
|
content::RenderWidgetHostImpl* target_rwh =
|
|
|
|
web_contents->GetInputEventRouter()->GetRenderWidgetHostAtPoint(
|
2017-12-07 22:44:24 +01:00
|
|
|
web_contents->GetRenderViewHost()->GetWidget()->GetView(),
|
|
|
|
gfx::PointF(client_pt), &transformed_pt);
|
2016-11-23 21:54:29 +01:00
|
|
|
|
|
|
|
if (target_rwh != current_rwh_for_drag_.get()) {
|
2017-03-03 23:37:23 +01:00
|
|
|
if (current_rwh_for_drag_) {
|
2017-12-07 22:44:24 +01:00
|
|
|
gfx::PointF transformed_leave_point(client_pt);
|
|
|
|
gfx::PointF transformed_screen_point(screen_pt);
|
2017-03-03 23:37:23 +01:00
|
|
|
static_cast<content::RenderWidgetHostViewBase*>(
|
|
|
|
web_contents->GetRenderWidgetHostView())
|
|
|
|
->TransformPointToCoordSpaceForView(
|
2017-12-07 22:44:24 +01:00
|
|
|
gfx::PointF(client_pt),
|
2017-03-03 23:37:23 +01:00
|
|
|
static_cast<content::RenderWidgetHostViewBase*>(
|
|
|
|
current_rwh_for_drag_->GetView()),
|
|
|
|
&transformed_leave_point);
|
|
|
|
static_cast<content::RenderWidgetHostViewBase*>(
|
|
|
|
web_contents->GetRenderWidgetHostView())
|
|
|
|
->TransformPointToCoordSpaceForView(
|
2017-12-07 22:44:24 +01:00
|
|
|
gfx::PointF(screen_pt),
|
2017-03-03 23:37:23 +01:00
|
|
|
static_cast<content::RenderWidgetHostViewBase*>(
|
|
|
|
current_rwh_for_drag_->GetView()),
|
|
|
|
&transformed_screen_point);
|
|
|
|
current_rwh_for_drag_->DragTargetDragLeave(transformed_leave_point,
|
|
|
|
transformed_screen_point);
|
|
|
|
}
|
2016-11-23 21:54:29 +01:00
|
|
|
DragTargetDragEnter(drag_data_, event, drag_allowed_ops_);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!drag_data_)
|
2015-11-17 19:20:13 +01:00
|
|
|
return;
|
|
|
|
|
2016-06-21 00:59:23 +02:00
|
|
|
{
|
|
|
|
CefDragDataImpl* data_impl =
|
|
|
|
static_cast<CefDragDataImpl*>(drag_data_.get());
|
|
|
|
base::AutoLock lock_scope(data_impl->lock());
|
|
|
|
content::DropData* drop_data = data_impl->drop_data();
|
|
|
|
int modifiers = TranslateModifiers(event.modifiers);
|
|
|
|
|
2017-12-07 22:44:24 +01:00
|
|
|
target_rwh->DragTargetDrop(*drop_data, transformed_pt,
|
|
|
|
gfx::PointF(screen_pt), modifiers);
|
2016-06-21 00:59:23 +02:00
|
|
|
}
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2016-06-21 00:59:23 +02:00
|
|
|
drag_data_ = nullptr;
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
void CefBrowserPlatformDelegateOsr::StartDragging(
|
|
|
|
const content::DropData& drop_data,
|
|
|
|
blink::WebDragOperationsMask allowed_ops,
|
|
|
|
const gfx::ImageSkia& image,
|
|
|
|
const gfx::Vector2d& image_offset,
|
|
|
|
const content::DragEventSourceInfo& event_info,
|
|
|
|
content::RenderWidgetHostImpl* source_rwh) {
|
|
|
|
drag_start_rwh_ = source_rwh->GetWeakPtr();
|
|
|
|
|
|
|
|
bool handled = false;
|
|
|
|
|
|
|
|
CefRefPtr<CefRenderHandler> handler =
|
|
|
|
browser_->GetClient()->GetRenderHandler();
|
|
|
|
if (handler.get()) {
|
2017-05-11 20:22:21 +02:00
|
|
|
CefRefPtr<CefImage> cef_image(new CefImageImpl(image));
|
|
|
|
CefPoint cef_image_pos(image_offset.x(), image_offset.y());
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefDragDataImpl> drag_data(
|
|
|
|
new CefDragDataImpl(drop_data, cef_image, cef_image_pos));
|
2016-11-23 21:54:29 +01:00
|
|
|
drag_data->SetReadOnly(true);
|
2018-05-18 12:45:18 +02:00
|
|
|
base::MessageLoopCurrent::ScopedNestableTaskAllower allow;
|
2016-11-23 21:54:29 +01:00
|
|
|
handled = handler->StartDragging(
|
2017-05-17 11:29:28 +02:00
|
|
|
browser_, drag_data.get(),
|
2016-11-23 21:54:29 +01:00
|
|
|
static_cast<CefRenderHandler::DragOperationsMask>(allowed_ops),
|
2017-05-17 11:29:28 +02:00
|
|
|
event_info.event_location.x(), event_info.event_location.y());
|
2016-11-23 21:54:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!handled)
|
|
|
|
DragSourceSystemDragEnded();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::UpdateDragCursor(
|
|
|
|
blink::WebDragOperation operation) {
|
|
|
|
CefRefPtr<CefRenderHandler> handler =
|
|
|
|
browser_->GetClient()->GetRenderHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
handler->UpdateDragCursor(
|
|
|
|
browser_, static_cast<CefRenderHandler::DragOperation>(operation));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
void CefBrowserPlatformDelegateOsr::DragSourceEndedAt(
|
2017-05-17 11:29:28 +02:00
|
|
|
int x,
|
|
|
|
int y,
|
2015-11-17 19:20:13 +01:00
|
|
|
cef_drag_operations_mask_t op) {
|
2016-11-23 21:54:29 +01:00
|
|
|
if (!drag_start_rwh_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
content::WebContentsImpl* web_contents =
|
|
|
|
static_cast<content::WebContentsImpl*>(browser_->web_contents());
|
|
|
|
if (!web_contents)
|
2015-11-17 19:20:13 +01:00
|
|
|
return;
|
|
|
|
|
2017-03-03 23:37:23 +01:00
|
|
|
content::RenderWidgetHostImpl* source_rwh = drag_start_rwh_.get();
|
|
|
|
const gfx::Point client_loc(gfx::Point(x, y));
|
|
|
|
const gfx::Point& screen_loc = GetScreenPoint(client_loc);
|
2015-11-17 19:20:13 +01:00
|
|
|
blink::WebDragOperation drag_op = static_cast<blink::WebDragOperation>(op);
|
|
|
|
|
2017-03-03 23:37:23 +01:00
|
|
|
// |client_loc| and |screen_loc| are in the root coordinate space, for
|
|
|
|
// non-root RenderWidgetHosts they need to be transformed.
|
2017-12-07 22:44:24 +01:00
|
|
|
gfx::PointF transformed_point(client_loc);
|
|
|
|
gfx::PointF transformed_screen_point(screen_loc);
|
2017-03-03 23:37:23 +01:00
|
|
|
if (source_rwh && web_contents->GetRenderWidgetHostView()) {
|
|
|
|
static_cast<content::RenderWidgetHostViewBase*>(
|
|
|
|
web_contents->GetRenderWidgetHostView())
|
|
|
|
->TransformPointToCoordSpaceForView(
|
2017-12-07 22:44:24 +01:00
|
|
|
gfx::PointF(client_loc),
|
2017-03-03 23:37:23 +01:00
|
|
|
static_cast<content::RenderWidgetHostViewBase*>(
|
|
|
|
source_rwh->GetView()),
|
|
|
|
&transformed_point);
|
|
|
|
static_cast<content::RenderWidgetHostViewBase*>(
|
|
|
|
web_contents->GetRenderWidgetHostView())
|
|
|
|
->TransformPointToCoordSpaceForView(
|
2017-12-07 22:44:24 +01:00
|
|
|
gfx::PointF(screen_loc),
|
2017-03-03 23:37:23 +01:00
|
|
|
static_cast<content::RenderWidgetHostViewBase*>(
|
|
|
|
source_rwh->GetView()),
|
|
|
|
&transformed_screen_point);
|
|
|
|
}
|
|
|
|
|
|
|
|
web_contents->DragSourceEndedAt(transformed_point.x(), transformed_point.y(),
|
|
|
|
transformed_screen_point.x(),
|
|
|
|
transformed_screen_point.y(), drag_op,
|
|
|
|
source_rwh);
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::DragSourceSystemDragEnded() {
|
2016-11-23 21:54:29 +01:00
|
|
|
if (!drag_start_rwh_)
|
2015-11-17 19:20:13 +01:00
|
|
|
return;
|
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
content::WebContents* web_contents = browser_->web_contents();
|
|
|
|
if (!web_contents)
|
|
|
|
return;
|
|
|
|
|
|
|
|
web_contents->SystemDragEnded(drag_start_rwh_.get());
|
|
|
|
|
|
|
|
drag_start_rwh_ = nullptr;
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
|
2017-05-12 20:28:25 +02:00
|
|
|
void CefBrowserPlatformDelegateOsr::AccessibilityEventReceived(
|
2018-06-08 18:53:10 +02:00
|
|
|
const content::AXEventNotificationDetails& eventData) {
|
2017-05-12 20:28:25 +02:00
|
|
|
CefRefPtr<CefRenderHandler> handler = browser_->client()->GetRenderHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
CefRefPtr<CefAccessibilityHandler> acchandler =
|
|
|
|
handler->GetAccessibilityHandler();
|
|
|
|
|
|
|
|
if (acchandler.get()) {
|
|
|
|
acchandler->OnAccessibilityTreeChange(
|
|
|
|
osr_accessibility_util::ParseAccessibilityEventData(eventData));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateOsr::AccessibilityLocationChangesReceived(
|
|
|
|
const std::vector<content::AXLocationChangeNotificationDetails>& locData) {
|
|
|
|
CefRefPtr<CefRenderHandler> handler = browser_->client()->GetRenderHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
CefRefPtr<CefAccessibilityHandler> acchandler =
|
|
|
|
handler->GetAccessibilityHandler();
|
|
|
|
|
|
|
|
if (acchandler.get()) {
|
|
|
|
acchandler->OnAccessibilityLocationChange(
|
|
|
|
osr_accessibility_util::ParseAccessibilityLocationData(locData));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
CefWindowHandle CefBrowserPlatformDelegateOsr::GetParentWindowHandle() const {
|
|
|
|
return GetHostWindowHandle();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Point CefBrowserPlatformDelegateOsr::GetParentScreenPoint(
|
|
|
|
const gfx::Point& view) const {
|
|
|
|
return GetScreenPoint(view);
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRenderWidgetHostViewOSR* CefBrowserPlatformDelegateOsr::GetOSRHostView()
|
|
|
|
const {
|
2015-11-17 19:20:13 +01:00
|
|
|
content::WebContents* web_contents = browser_->web_contents();
|
|
|
|
CefRenderWidgetHostViewOSR* fs_view =
|
|
|
|
static_cast<CefRenderWidgetHostViewOSR*>(
|
|
|
|
web_contents->GetFullscreenRenderWidgetHostView());
|
|
|
|
if (fs_view)
|
|
|
|
return fs_view;
|
|
|
|
|
|
|
|
content::RenderViewHost* host = web_contents->GetRenderViewHost();
|
|
|
|
if (host) {
|
|
|
|
return static_cast<CefRenderWidgetHostViewOSR*>(
|
|
|
|
host->GetWidget()->GetView());
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|