2014-07-01 00:30:29 +02:00
|
|
|
// Copyright (c) 2014 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "libcef/browser/osr/web_contents_view_osr.h"
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
#include "libcef/browser/alloy/alloy_browser_host_impl.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "libcef/browser/osr/render_widget_host_view_osr.h"
|
2022-05-27 11:03:31 +02:00
|
|
|
#include "libcef/browser/osr/touch_selection_controller_client_osr.h"
|
2014-07-01 00:30:29 +02:00
|
|
|
#include "libcef/common/drag_data_impl.h"
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "content/browser/browser_plugin/browser_plugin_embedder.h"
|
|
|
|
#include "content/browser/browser_plugin/browser_plugin_guest.h"
|
|
|
|
#include "content/browser/web_contents/web_contents_impl.h"
|
2014-07-01 00:30:29 +02:00
|
|
|
#include "content/public/browser/render_widget_host.h"
|
|
|
|
|
2018-07-03 02:46:03 +02:00
|
|
|
CefWebContentsViewOSR::CefWebContentsViewOSR(SkColor background_color,
|
|
|
|
bool use_shared_texture,
|
|
|
|
bool use_external_begin_frame)
|
|
|
|
: background_color_(background_color),
|
|
|
|
use_shared_texture_(use_shared_texture),
|
|
|
|
use_external_begin_frame_(use_external_begin_frame),
|
2020-01-15 14:36:24 +01:00
|
|
|
web_contents_(nullptr) {}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefWebContentsViewOSR::~CefWebContentsViewOSR() {}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2017-02-15 22:03:00 +01:00
|
|
|
void CefWebContentsViewOSR::WebContentsCreated(
|
2014-09-30 20:52:26 +02:00
|
|
|
content::WebContents* web_contents) {
|
|
|
|
DCHECK(!web_contents_);
|
|
|
|
web_contents_ = web_contents;
|
2017-02-15 22:03:00 +01:00
|
|
|
|
2020-07-28 05:38:48 +02:00
|
|
|
RenderViewCreated();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWebContentsViewOSR::RenderViewCreated() {
|
|
|
|
if (web_contents_) {
|
|
|
|
auto host = web_contents_->GetRenderViewHost();
|
|
|
|
CefRenderWidgetHostViewOSR* view =
|
|
|
|
static_cast<CefRenderWidgetHostViewOSR*>(host->GetWidget()->GetView());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (view) {
|
2020-07-28 05:38:48 +02:00
|
|
|
view->InstallTransparency();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2020-07-28 05:38:48 +02:00
|
|
|
}
|
2014-09-30 20:52:26 +02:00
|
|
|
}
|
|
|
|
|
2020-07-08 19:23:29 +02:00
|
|
|
gfx::Rect CefWebContentsViewOSR::GetContainerBounds() const {
|
|
|
|
return GetViewBounds();
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2017-07-27 01:19:27 +02:00
|
|
|
void CefWebContentsViewOSR::GotFocus(
|
|
|
|
content::RenderWidgetHostImpl* render_widget_host) {
|
2017-05-12 20:28:25 +02:00
|
|
|
if (web_contents_) {
|
|
|
|
content::WebContentsImpl* web_contents_impl =
|
|
|
|
static_cast<content::WebContentsImpl*>(web_contents_);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (web_contents_impl) {
|
2017-07-27 01:19:27 +02:00
|
|
|
web_contents_impl->NotifyWebContentsFocused(render_widget_host);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-07-27 01:19:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWebContentsViewOSR::LostFocus(
|
|
|
|
content::RenderWidgetHostImpl* render_widget_host) {
|
|
|
|
if (web_contents_) {
|
|
|
|
content::WebContentsImpl* web_contents_impl =
|
|
|
|
static_cast<content::WebContentsImpl*>(web_contents_);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (web_contents_impl) {
|
2017-07-27 01:19:27 +02:00
|
|
|
web_contents_impl->NotifyWebContentsLostFocus(render_widget_host);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWebContentsViewOSR::TakeFocus(bool reverse) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (web_contents_->GetDelegate()) {
|
2017-05-12 20:28:25 +02:00
|
|
|
web_contents_->GetDelegate()->TakeFocus(web_contents_, reverse);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
gfx::Rect CefWebContentsViewOSR::GetViewBounds() const {
|
2017-02-10 23:44:11 +01:00
|
|
|
CefRenderWidgetHostViewOSR* view = GetView();
|
|
|
|
return view ? view->GetViewBounds() : gfx::Rect();
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
content::RenderWidgetHostViewBase* CefWebContentsViewOSR::CreateViewForWidget(
|
2020-02-10 18:10:17 +01:00
|
|
|
content::RenderWidgetHost* render_widget_host) {
|
2014-07-01 00:30:29 +02:00
|
|
|
if (render_widget_host->GetView()) {
|
|
|
|
return static_cast<content::RenderWidgetHostViewBase*>(
|
|
|
|
render_widget_host->GetView());
|
|
|
|
}
|
|
|
|
|
2020-02-10 18:10:17 +01:00
|
|
|
return new CefRenderWidgetHostViewOSR(background_color_, use_shared_texture_,
|
|
|
|
use_external_begin_frame_,
|
|
|
|
render_widget_host, nullptr);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2015-06-11 17:00:05 +02:00
|
|
|
// Called for popup and fullscreen widgets.
|
2014-07-01 00:30:29 +02:00
|
|
|
content::RenderWidgetHostViewBase*
|
2018-10-02 14:14:11 +02:00
|
|
|
CefWebContentsViewOSR::CreateViewForChildWidget(
|
2014-07-01 00:30:29 +02:00
|
|
|
content::RenderWidgetHost* render_widget_host) {
|
2017-02-10 23:44:11 +01:00
|
|
|
CefRenderWidgetHostViewOSR* view = GetView();
|
|
|
|
CHECK(view);
|
|
|
|
|
2018-07-03 02:46:03 +02:00
|
|
|
return new CefRenderWidgetHostViewOSR(background_color_, use_shared_texture_,
|
|
|
|
use_external_begin_frame_,
|
2020-02-10 18:10:17 +01:00
|
|
|
render_widget_host, view);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2022-05-27 11:03:31 +02:00
|
|
|
void CefWebContentsViewOSR::ShowContextMenu(
|
|
|
|
content::RenderFrameHost& render_frame_host,
|
|
|
|
const content::ContextMenuParams& params) {
|
|
|
|
auto selection_controller_client = GetSelectionControllerClient();
|
|
|
|
if (selection_controller_client &&
|
|
|
|
selection_controller_client->HandleContextMenu(params)) {
|
|
|
|
// Context menu display, if any, will be handled via
|
|
|
|
// AlloyWebContentsViewDelegate::ShowContextMenu.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto browser = GetBrowser()) {
|
|
|
|
browser->ShowContextMenu(params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
void CefWebContentsViewOSR::StartDragging(
|
|
|
|
const content::DropData& drop_data,
|
2023-10-19 20:08:48 +02:00
|
|
|
const url::Origin& source_origin,
|
2020-10-08 21:54:42 +02:00
|
|
|
blink::DragOperationsMask allowed_ops,
|
2014-07-01 00:30:29 +02:00
|
|
|
const gfx::ImageSkia& image,
|
2022-09-26 21:30:45 +02:00
|
|
|
const gfx::Vector2d& cursor_offset,
|
|
|
|
const gfx::Rect& drag_obj_rect,
|
2020-10-08 21:54:42 +02:00
|
|
|
const blink::mojom::DragEventSourceInfo& event_info,
|
2016-11-23 21:54:29 +01:00
|
|
|
content::RenderWidgetHostImpl* source_rwh) {
|
2020-09-22 21:54:02 +02:00
|
|
|
CefRefPtr<AlloyBrowserHostImpl> browser = GetBrowser();
|
2016-11-23 21:54:29 +01:00
|
|
|
if (browser.get()) {
|
2022-09-26 21:30:45 +02:00
|
|
|
browser->StartDragging(drop_data, allowed_ops, image, cursor_offset,
|
2016-11-23 21:54:29 +01:00
|
|
|
event_info, source_rwh);
|
|
|
|
} else if (web_contents_) {
|
2020-07-08 19:23:29 +02:00
|
|
|
static_cast<content::WebContentsImpl*>(web_contents_)
|
|
|
|
->SystemDragEnded(source_rwh);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-19 20:08:48 +02:00
|
|
|
void CefWebContentsViewOSR::UpdateDragOperation(
|
|
|
|
ui::mojom::DragOperation operation,
|
|
|
|
bool document_is_handling_drag) {
|
2020-09-22 21:54:02 +02:00
|
|
|
CefRefPtr<AlloyBrowserHostImpl> browser = GetBrowser();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser.get()) {
|
2023-10-19 20:08:48 +02:00
|
|
|
browser->UpdateDragOperation(operation, document_is_handling_drag);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-02-10 23:44:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRenderWidgetHostViewOSR* CefWebContentsViewOSR::GetView() const {
|
|
|
|
if (web_contents_) {
|
|
|
|
return static_cast<CefRenderWidgetHostViewOSR*>(
|
|
|
|
web_contents_->GetRenderViewHost()->GetWidget()->GetView());
|
2015-07-16 23:40:01 +02:00
|
|
|
}
|
2017-02-10 23:44:11 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
2015-07-16 23:40:01 +02:00
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
AlloyBrowserHostImpl* CefWebContentsViewOSR::GetBrowser() const {
|
2017-02-10 23:44:11 +01:00
|
|
|
CefRenderWidgetHostViewOSR* view = GetView();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (view) {
|
2017-02-10 23:44:11 +01:00
|
|
|
return view->browser_impl().get();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-02-10 23:44:11 +01:00
|
|
|
return nullptr;
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
2022-05-27 11:03:31 +02:00
|
|
|
|
|
|
|
CefTouchSelectionControllerClientOSR*
|
|
|
|
CefWebContentsViewOSR::GetSelectionControllerClient() const {
|
|
|
|
CefRenderWidgetHostViewOSR* view = GetView();
|
|
|
|
return view ? view->selection_controller_client() : nullptr;
|
|
|
|
}
|