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/render_widget_host_view_osr.h"
|
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
2019-07-16 22:09:04 +02:00
|
|
|
#include "libcef/browser/browser_host_impl.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "libcef/browser/osr/osr_util.h"
|
2019-03-13 22:27:37 +01:00
|
|
|
#include "libcef/browser/osr/synthetic_gesture_target_osr.h"
|
2019-07-16 22:09:04 +02:00
|
|
|
#include "libcef/browser/osr/video_consumer_osr.h"
|
2014-07-01 00:30:29 +02:00
|
|
|
#include "libcef/browser/thread_util.h"
|
|
|
|
|
|
|
|
#include "base/callback_helpers.h"
|
2015-01-01 17:51:56 +01:00
|
|
|
#include "base/command_line.h"
|
2016-04-27 22:38:52 +02:00
|
|
|
#include "base/memory/ptr_util.h"
|
2018-04-09 19:48:23 +02:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2018-10-02 14:14:11 +02:00
|
|
|
#include "base/task/post_task.h"
|
2015-06-06 00:06:48 +02:00
|
|
|
#include "cc/base/switches.h"
|
2018-03-20 21:15:08 +01:00
|
|
|
#include "components/viz/common/features.h"
|
2019-11-12 17:11:44 +01:00
|
|
|
#include "components/viz/common/frame_sinks/begin_frame_args.h"
|
2017-10-20 19:45:20 +02:00
|
|
|
#include "components/viz/common/frame_sinks/copy_output_request.h"
|
2017-09-06 23:40:58 +02:00
|
|
|
#include "components/viz/common/frame_sinks/delay_based_time_source.h"
|
2017-07-27 01:19:27 +02:00
|
|
|
#include "components/viz/common/gl_helper.h"
|
2017-12-07 22:44:24 +01:00
|
|
|
#include "components/viz/common/switches.h"
|
2015-04-20 13:11:11 +02:00
|
|
|
#include "content/browser/bad_message.h"
|
2014-07-01 00:30:29 +02:00
|
|
|
#include "content/browser/compositor/image_transport_factory.h"
|
2016-10-27 17:02:56 +02:00
|
|
|
#include "content/browser/frame_host/render_widget_host_view_guest.h"
|
2019-10-01 15:55:16 +02:00
|
|
|
#include "content/browser/gpu/gpu_data_manager_impl.h"
|
2018-09-14 11:18:10 +02:00
|
|
|
#include "content/browser/renderer_host/cursor_manager.h"
|
2018-10-24 22:37:39 +02:00
|
|
|
#include "content/browser/renderer_host/delegated_frame_host.h"
|
2014-07-01 00:30:29 +02:00
|
|
|
#include "content/browser/renderer_host/dip_util.h"
|
2019-02-25 22:17:28 +01:00
|
|
|
#include "content/browser/renderer_host/input/motion_event_web.h"
|
2019-02-21 01:42:36 +01:00
|
|
|
#include "content/browser/renderer_host/input/synthetic_gesture_target_base.h"
|
2016-05-25 01:35:43 +02:00
|
|
|
#include "content/browser/renderer_host/render_widget_host_delegate.h"
|
2014-07-01 00:30:29 +02:00
|
|
|
#include "content/browser/renderer_host/render_widget_host_impl.h"
|
2019-02-25 22:17:28 +01:00
|
|
|
#include "content/browser/renderer_host/render_widget_host_input_event_router.h"
|
|
|
|
#include "content/common/content_switches_internal.h"
|
2016-10-28 18:11:24 +02:00
|
|
|
#include "content/common/input_messages.h"
|
2015-01-01 17:51:56 +01:00
|
|
|
#include "content/common/view_messages.h"
|
2018-10-02 14:14:11 +02:00
|
|
|
#include "content/public/browser/browser_task_traits.h"
|
2015-01-01 17:51:56 +01:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
2014-07-01 00:30:29 +02:00
|
|
|
#include "content/public/browser/context_factory.h"
|
2018-03-20 21:15:08 +01:00
|
|
|
#include "content/public/browser/render_process_host.h"
|
2014-07-01 00:30:29 +02:00
|
|
|
#include "content/public/browser/render_view_host.h"
|
2015-01-01 17:51:56 +01:00
|
|
|
#include "content/public/common/content_switches.h"
|
2017-03-03 23:37:23 +01:00
|
|
|
#include "media/base/video_frame.h"
|
2019-09-04 17:13:32 +02:00
|
|
|
#include "ui/base/cursor/types/cursor_types.h"
|
2019-07-16 19:59:21 +02:00
|
|
|
#include "ui/compositor/compositor.h"
|
2019-02-25 22:17:28 +01:00
|
|
|
#include "ui/events/blink/blink_event_util.h"
|
|
|
|
#include "ui/events/gesture_detection/gesture_provider_config_helper.h"
|
|
|
|
#include "ui/events/gesture_detection/motion_event.h"
|
2014-12-13 21:18:31 +01:00
|
|
|
#include "ui/gfx/geometry/dip_util.h"
|
2014-07-01 00:30:29 +02:00
|
|
|
#include "ui/gfx/geometry/size_conversions.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2018-07-03 02:46:03 +02:00
|
|
|
// The maximum number of damage rects to cache for outstanding frame requests
|
|
|
|
// (for OnAcceleratedPaint).
|
|
|
|
const size_t kMaxDamageRects = 10;
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
const float kDefaultScaleFactor = 1.0;
|
|
|
|
|
2016-10-17 20:14:44 +02:00
|
|
|
static content::ScreenInfo ScreenInfoFrom(const CefScreenInfo& src) {
|
|
|
|
content::ScreenInfo screenInfo;
|
|
|
|
screenInfo.device_scale_factor = src.device_scale_factor;
|
|
|
|
screenInfo.depth = src.depth;
|
|
|
|
screenInfo.depth_per_component = src.depth_per_component;
|
|
|
|
screenInfo.is_monochrome = src.is_monochrome ? true : false;
|
2017-05-17 11:29:28 +02:00
|
|
|
screenInfo.rect =
|
|
|
|
gfx::Rect(src.rect.x, src.rect.y, src.rect.width, src.rect.height);
|
|
|
|
screenInfo.available_rect =
|
|
|
|
gfx::Rect(src.available_rect.x, src.available_rect.y,
|
|
|
|
src.available_rect.width, src.available_rect.height);
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2016-10-17 20:14:44 +02:00
|
|
|
return screenInfo;
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2018-10-24 22:37:39 +02:00
|
|
|
class CefDelegatedFrameHostClient : public content::DelegatedFrameHostClient {
|
|
|
|
public:
|
|
|
|
explicit CefDelegatedFrameHostClient(CefRenderWidgetHostViewOSR* view)
|
|
|
|
: view_(view) {}
|
|
|
|
|
|
|
|
ui::Layer* DelegatedFrameHostGetLayer() const override {
|
|
|
|
return view_->GetRootLayer();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DelegatedFrameHostIsVisible() const override {
|
|
|
|
// Called indirectly from DelegatedFrameHost::WasShown.
|
|
|
|
return view_->IsShowing();
|
|
|
|
}
|
|
|
|
|
|
|
|
SkColor DelegatedFrameHostGetGutterColor() const override {
|
|
|
|
// When making an element on the page fullscreen the element's background
|
|
|
|
// may not match the page's, so use black as the gutter color to avoid
|
|
|
|
// flashes of brighter colors during the transition.
|
|
|
|
if (view_->render_widget_host()->delegate() &&
|
|
|
|
view_->render_widget_host()->delegate()->IsFullscreenForCurrentTab()) {
|
|
|
|
return SK_ColorBLACK;
|
|
|
|
}
|
|
|
|
return *view_->GetBackgroundColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnBeginFrame(base::TimeTicks frame_time) override {
|
|
|
|
// TODO(cef): Maybe we can use this method in combination with
|
|
|
|
// OnSetNeedsBeginFrames() instead of using CefBeginFrameTimer.
|
|
|
|
// See https://codereview.chromium.org/1841083007.
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnFrameTokenChanged(uint32_t frame_token) override {
|
|
|
|
view_->render_widget_host()->DidProcessFrame(frame_token);
|
|
|
|
}
|
|
|
|
|
|
|
|
float GetDeviceScaleFactor() const override {
|
|
|
|
return view_->GetDeviceScaleFactor();
|
|
|
|
}
|
|
|
|
|
2018-11-30 23:21:07 +01:00
|
|
|
std::vector<viz::SurfaceId> CollectSurfaceIdsForEviction() override {
|
|
|
|
return view_->render_widget_host()->CollectSurfaceIdsForEviction();
|
|
|
|
}
|
2018-11-03 02:15:09 +01:00
|
|
|
|
2018-12-26 16:12:11 +01:00
|
|
|
void InvalidateLocalSurfaceIdOnEviction() override {}
|
|
|
|
|
2019-03-13 22:27:37 +01:00
|
|
|
bool ShouldShowStaleContentOnEviction() override { return false; }
|
2019-02-01 17:42:40 +01:00
|
|
|
|
2018-10-24 22:37:39 +02:00
|
|
|
private:
|
|
|
|
CefRenderWidgetHostViewOSR* const view_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefDelegatedFrameHostClient);
|
|
|
|
};
|
|
|
|
|
2019-02-25 22:17:28 +01:00
|
|
|
ui::GestureProvider::Config CreateGestureProviderConfig() {
|
|
|
|
ui::GestureProvider::Config config = ui::GetGestureProviderConfig(
|
|
|
|
ui::GestureProviderConfigType::CURRENT_PLATFORM);
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
|
|
|
ui::LatencyInfo CreateLatencyInfo(const blink::WebInputEvent& event) {
|
|
|
|
ui::LatencyInfo latency_info;
|
|
|
|
// The latency number should only be added if the timestamp is valid.
|
|
|
|
base::TimeTicks time = event.TimeStamp();
|
|
|
|
if (!time.is_null()) {
|
|
|
|
latency_info.AddLatencyNumberWithTimestamp(
|
2019-09-04 17:13:32 +02:00
|
|
|
ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, time);
|
2019-02-25 22:17:28 +01:00
|
|
|
}
|
|
|
|
return latency_info;
|
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
} // namespace
|
|
|
|
|
2015-01-01 17:51:56 +01:00
|
|
|
CefRenderWidgetHostViewOSR::CefRenderWidgetHostViewOSR(
|
2017-04-20 21:28:17 +02:00
|
|
|
SkColor background_color,
|
2018-07-03 02:46:03 +02:00
|
|
|
bool use_shared_texture,
|
|
|
|
bool use_external_begin_frame,
|
2015-06-11 17:00:05 +02:00
|
|
|
content::RenderWidgetHost* widget,
|
2017-03-03 23:37:23 +01:00
|
|
|
CefRenderWidgetHostViewOSR* parent_host_view,
|
|
|
|
bool is_guest_view_hack)
|
2018-04-19 17:44:42 +02:00
|
|
|
: content::RenderWidgetHostViewBase(widget),
|
|
|
|
background_color_(background_color),
|
2016-11-23 18:26:50 +01:00
|
|
|
frame_rate_threshold_us_(0),
|
2019-11-26 19:26:54 +01:00
|
|
|
host_display_client_(nullptr),
|
2014-07-01 00:30:29 +02:00
|
|
|
hold_resize_(false),
|
|
|
|
pending_resize_(false),
|
2019-03-18 22:04:21 +01:00
|
|
|
pending_resize_force_(false),
|
2014-07-01 00:30:29 +02:00
|
|
|
render_widget_host_(content::RenderWidgetHostImpl::From(widget)),
|
2015-06-11 17:00:05 +02:00
|
|
|
has_parent_(parent_host_view != NULL),
|
|
|
|
parent_host_view_(parent_host_view),
|
2014-07-01 00:30:29 +02:00
|
|
|
popup_host_view_(NULL),
|
2015-06-11 17:00:05 +02:00
|
|
|
child_host_view_(NULL),
|
2019-07-16 22:09:04 +02:00
|
|
|
is_showing_(false),
|
2014-07-01 00:30:29 +02:00
|
|
|
is_destroyed_(false),
|
2019-02-25 22:17:28 +01:00
|
|
|
pinch_zoom_enabled_(content::IsPinchToZoomEnabled()),
|
2014-09-27 01:48:19 +02:00
|
|
|
is_scroll_offset_changed_pending_(false),
|
2018-06-16 00:19:14 +02:00
|
|
|
mouse_wheel_phase_handler_(this),
|
2019-02-25 22:17:28 +01:00
|
|
|
gesture_provider_(CreateGestureProviderConfig(), this),
|
|
|
|
forward_touch_to_popup_(false),
|
2014-07-01 00:30:29 +02:00
|
|
|
weak_ptr_factory_(this) {
|
|
|
|
DCHECK(render_widget_host_);
|
2016-10-27 17:02:56 +02:00
|
|
|
DCHECK(!render_widget_host_->GetView());
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2017-06-23 21:06:37 +02:00
|
|
|
current_device_scale_factor_ = kDefaultScaleFactor;
|
|
|
|
|
2017-02-10 23:44:11 +01:00
|
|
|
if (parent_host_view_) {
|
|
|
|
browser_impl_ = parent_host_view_->browser_impl();
|
|
|
|
DCHECK(browser_impl_);
|
|
|
|
} else if (content::RenderViewHost::From(render_widget_host_)) {
|
|
|
|
// CefBrowserHostImpl might not be created at this time for popups.
|
2014-07-01 00:30:29 +02:00
|
|
|
browser_impl_ = CefBrowserHostImpl::GetBrowserForHost(
|
|
|
|
content::RenderViewHost::From(render_widget_host_));
|
|
|
|
}
|
|
|
|
|
2018-11-03 02:15:09 +01:00
|
|
|
local_surface_id_allocator_.GenerateId();
|
2018-11-30 23:21:07 +01:00
|
|
|
local_surface_id_allocation_ =
|
|
|
|
local_surface_id_allocator_.GetCurrentLocalSurfaceIdAllocation();
|
2018-10-24 22:37:39 +02:00
|
|
|
delegated_frame_host_client_.reset(new CefDelegatedFrameHostClient(this));
|
2017-10-20 19:45:20 +02:00
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
// Matching the attributes from BrowserCompositorMac.
|
|
|
|
delegated_frame_host_ = std::make_unique<content::DelegatedFrameHost>(
|
2018-10-24 22:37:39 +02:00
|
|
|
AllocateFrameSinkId(is_guest_view_hack),
|
|
|
|
delegated_frame_host_client_.get(),
|
2019-03-18 22:02:37 +01:00
|
|
|
false /* should_register_frame_sink_id */);
|
2016-10-21 21:52:29 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
root_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR));
|
2016-07-06 21:34:09 +02:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
bool opaque = SkColorGetA(background_color_) == SK_AlphaOPAQUE;
|
|
|
|
GetRootLayer()->SetFillsBoundsOpaquely(opaque);
|
|
|
|
GetRootLayer()->SetColor(background_color_);
|
|
|
|
|
2018-07-03 02:46:03 +02:00
|
|
|
external_begin_frame_enabled_ = use_external_begin_frame;
|
|
|
|
|
2017-03-03 23:37:23 +01:00
|
|
|
content::ImageTransportFactory* factory =
|
|
|
|
content::ImageTransportFactory::GetInstance();
|
|
|
|
ui::ContextFactoryPrivate* context_factory_private =
|
|
|
|
factory->GetContextFactoryPrivate();
|
2019-07-16 22:09:04 +02:00
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
// Matching the attributes from RecyclableCompositorMac.
|
2018-07-03 02:46:03 +02:00
|
|
|
compositor_.reset(new ui::Compositor(
|
|
|
|
context_factory_private->AllocateFrameSinkId(),
|
|
|
|
content::GetContextFactory(), context_factory_private,
|
2019-01-17 10:56:52 +01:00
|
|
|
base::ThreadTaskRunnerHandle::Get(), false /* enable_pixel_canvas */,
|
2019-11-12 17:11:44 +01:00
|
|
|
use_external_begin_frame));
|
2019-07-16 22:09:04 +02:00
|
|
|
compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget);
|
2018-07-03 02:46:03 +02:00
|
|
|
|
2015-01-01 17:51:56 +01:00
|
|
|
compositor_->SetDelegate(this);
|
2014-07-01 00:30:29 +02:00
|
|
|
compositor_->SetRootLayer(root_layer_.get());
|
2019-03-18 22:02:37 +01:00
|
|
|
compositor_->AddChildFrameSink(GetFrameSinkId());
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2019-11-26 20:04:19 +01:00
|
|
|
content::RenderWidgetHostImpl* render_widget_host_impl =
|
|
|
|
content::RenderWidgetHostImpl::From(render_widget_host_);
|
|
|
|
if (render_widget_host_impl)
|
|
|
|
render_widget_host_impl->SetCompositorForFlingScheduler(compositor_.get());
|
|
|
|
|
2014-11-18 20:29:26 +01:00
|
|
|
if (browser_impl_.get())
|
2018-05-20 15:51:42 +02:00
|
|
|
ResizeRootLayer(false);
|
2017-01-25 18:34:18 +01:00
|
|
|
|
2018-09-14 11:18:10 +02:00
|
|
|
cursor_manager_.reset(new content::CursorManager(this));
|
|
|
|
|
2017-01-25 18:34:18 +01:00
|
|
|
// Do this last because it may result in a call to SetNeedsBeginFrames.
|
|
|
|
render_widget_host_->SetView(this);
|
2019-02-26 17:49:41 +01:00
|
|
|
|
|
|
|
if (GetTextInputManager())
|
|
|
|
GetTextInputManager()->AddObserver(this);
|
2019-02-25 22:17:28 +01:00
|
|
|
|
|
|
|
if (render_widget_host_->delegate() &&
|
|
|
|
render_widget_host_->delegate()->GetInputEventRouter()) {
|
|
|
|
render_widget_host_->delegate()->GetInputEventRouter()->AddFrameSinkIdOwner(
|
|
|
|
GetFrameSinkId(), this);
|
|
|
|
}
|
2019-07-16 22:09:04 +02:00
|
|
|
|
|
|
|
if (!render_widget_host_->is_hidden()) {
|
|
|
|
Show();
|
|
|
|
}
|
|
|
|
|
2019-10-01 15:55:16 +02:00
|
|
|
if (!content::GpuDataManagerImpl::GetInstance()->IsGpuCompositingDisabled()) {
|
2019-07-16 22:09:04 +02:00
|
|
|
video_consumer_.reset(new CefVideoConsumerOSR(this));
|
|
|
|
video_consumer_->SetActive(true);
|
|
|
|
video_consumer_->SetFrameRate(
|
|
|
|
base::TimeDelta::FromMicroseconds(frame_rate_threshold_us_));
|
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRenderWidgetHostViewOSR::~CefRenderWidgetHostViewOSR() {
|
2014-09-04 19:53:40 +02:00
|
|
|
// Marking the DelegatedFrameHost as removed from the window hierarchy is
|
|
|
|
// necessary to remove all connections to its old ui::Compositor.
|
2019-10-01 15:55:16 +02:00
|
|
|
if (is_showing_) {
|
|
|
|
delegated_frame_host_->WasHidden(
|
|
|
|
content::DelegatedFrameHost::HiddenCause::kOther);
|
|
|
|
}
|
2018-09-04 11:43:21 +02:00
|
|
|
delegated_frame_host_->DetachFromCompositor();
|
2014-09-04 19:53:40 +02:00
|
|
|
|
2019-07-16 22:09:04 +02:00
|
|
|
delegated_frame_host_.reset(nullptr);
|
|
|
|
compositor_.reset(nullptr);
|
|
|
|
root_layer_.reset(nullptr);
|
2014-09-04 19:53:40 +02:00
|
|
|
|
2019-07-16 22:09:04 +02:00
|
|
|
DCHECK(!parent_host_view_);
|
|
|
|
DCHECK(!popup_host_view_);
|
|
|
|
DCHECK(!child_host_view_);
|
2015-08-17 21:48:57 +02:00
|
|
|
DCHECK(guest_host_views_.empty());
|
2019-02-26 17:49:41 +01:00
|
|
|
|
|
|
|
if (text_input_manager_)
|
|
|
|
text_input_manager_->RemoveObserver(this);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2015-06-11 17:00:05 +02:00
|
|
|
// Called for full-screen widgets.
|
2014-07-01 00:30:29 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::InitAsChild(gfx::NativeView parent_view) {
|
2015-06-11 17:00:05 +02:00
|
|
|
DCHECK(parent_host_view_);
|
2017-02-10 23:44:11 +01:00
|
|
|
DCHECK(browser_impl_);
|
2015-06-11 17:00:05 +02:00
|
|
|
|
|
|
|
if (parent_host_view_->child_host_view_) {
|
|
|
|
// Cancel the previous popup widget.
|
2015-08-17 21:48:57 +02:00
|
|
|
parent_host_view_->child_host_view_->CancelWidget();
|
2015-06-11 17:00:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
parent_host_view_->set_child_host_view(this);
|
|
|
|
|
2015-08-20 21:28:48 +02:00
|
|
|
// The parent view should not render while the full-screen view exists.
|
|
|
|
parent_host_view_->Hide();
|
|
|
|
|
2018-05-20 15:51:42 +02:00
|
|
|
ResizeRootLayer(false);
|
2015-06-11 17:00:05 +02:00
|
|
|
Show();
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::SetSize(const gfx::Size& size) {}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::SetBounds(const gfx::Rect& rect) {}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2019-06-05 16:15:45 +02:00
|
|
|
gfx::NativeView CefRenderWidgetHostViewOSR::GetNativeView() {
|
2014-07-01 00:30:29 +02:00
|
|
|
return gfx::NativeView();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::NativeViewAccessible
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRenderWidgetHostViewOSR::GetNativeViewAccessible() {
|
2014-07-01 00:30:29 +02:00
|
|
|
return gfx::NativeViewAccessible();
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::Focus() {}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2019-06-05 16:15:45 +02:00
|
|
|
bool CefRenderWidgetHostViewOSR::HasFocus() {
|
2014-07-01 00:30:29 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-06-05 16:15:45 +02:00
|
|
|
bool CefRenderWidgetHostViewOSR::IsSurfaceAvailableForCopy() {
|
2017-03-03 23:37:23 +01:00
|
|
|
return GetDelegatedFrameHost()->CanCopyFromCompositingSurface();
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::Show() {
|
2015-02-04 19:10:14 +01:00
|
|
|
if (is_showing_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
is_showing_ = true;
|
2016-07-06 21:34:09 +02:00
|
|
|
|
2018-09-04 11:43:21 +02:00
|
|
|
delegated_frame_host_->AttachToCompositor(compositor_.get());
|
2018-11-30 23:21:07 +01:00
|
|
|
delegated_frame_host_->WasShown(
|
|
|
|
GetLocalSurfaceIdAllocation().local_surface_id(),
|
2019-07-16 19:59:21 +02:00
|
|
|
GetRootLayer()->bounds().size(), base::nullopt);
|
2016-07-06 21:34:09 +02:00
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
// Note that |render_widget_host_| will retrieve size parameters from the
|
|
|
|
// DelegatedFrameHost, so it must have WasShown called after.
|
2016-07-06 21:34:09 +02:00
|
|
|
if (render_widget_host_)
|
2019-07-16 19:59:21 +02:00
|
|
|
render_widget_host_->WasShown(
|
|
|
|
base::nullopt /* record_tab_switch_time_request */);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::Hide() {
|
2015-02-04 19:10:14 +01:00
|
|
|
if (!is_showing_)
|
|
|
|
return;
|
|
|
|
|
2019-04-15 19:25:30 +02:00
|
|
|
is_showing_ = false;
|
|
|
|
|
2015-02-04 19:10:14 +01:00
|
|
|
if (browser_impl_.get())
|
|
|
|
browser_impl_->CancelContextMenu();
|
|
|
|
|
|
|
|
if (render_widget_host_)
|
|
|
|
render_widget_host_->WasHidden();
|
2016-07-06 21:34:09 +02:00
|
|
|
|
2019-10-01 15:55:16 +02:00
|
|
|
GetDelegatedFrameHost()->WasHidden(
|
|
|
|
content::DelegatedFrameHost::HiddenCause::kOther);
|
2018-09-04 11:43:21 +02:00
|
|
|
GetDelegatedFrameHost()->DetachFromCompositor();
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefRenderWidgetHostViewOSR::IsShowing() {
|
|
|
|
return is_showing_;
|
|
|
|
}
|
|
|
|
|
2019-01-17 10:56:52 +01:00
|
|
|
void CefRenderWidgetHostViewOSR::EnsureSurfaceSynchronizedForWebTest() {
|
2018-05-16 11:28:49 +02:00
|
|
|
++latest_capture_sequence_number_;
|
2018-05-17 10:58:21 +02:00
|
|
|
SynchronizeVisualProperties();
|
2018-05-16 11:28:49 +02:00
|
|
|
}
|
|
|
|
|
2019-06-05 16:15:45 +02:00
|
|
|
gfx::Rect CefRenderWidgetHostViewOSR::GetViewBounds() {
|
2014-07-01 00:30:29 +02:00
|
|
|
if (IsPopupWidget())
|
|
|
|
return popup_position_;
|
|
|
|
|
2014-09-27 01:48:19 +02:00
|
|
|
if (!browser_impl_.get())
|
2014-07-01 00:30:29 +02:00
|
|
|
return gfx::Rect();
|
|
|
|
|
|
|
|
CefRect rc;
|
2015-01-26 01:57:01 +01:00
|
|
|
CefRefPtr<CefRenderHandler> handler =
|
|
|
|
browser_impl_->GetClient()->GetRenderHandler();
|
2018-09-25 15:40:02 +02:00
|
|
|
CHECK(handler);
|
|
|
|
|
|
|
|
handler->GetViewRect(browser_impl_.get(), rc);
|
|
|
|
CHECK_GT(rc.width, 0);
|
|
|
|
CHECK_GT(rc.height, 0);
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
return gfx::Rect(rc.x, rc.y, rc.width, rc.height);
|
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
void CefRenderWidgetHostViewOSR::SetBackgroundColor(SkColor color) {
|
2017-04-20 21:28:17 +02:00
|
|
|
// The renderer will feed its color back to us with the first CompositorFrame.
|
|
|
|
// We short-cut here to show a sensible color before that happens.
|
|
|
|
UpdateBackgroundColorFromRenderer(color);
|
|
|
|
|
|
|
|
DCHECK(SkColorGetA(color) == SK_AlphaOPAQUE ||
|
|
|
|
SkColorGetA(color) == SK_AlphaTRANSPARENT);
|
2019-01-17 10:56:52 +01:00
|
|
|
content::RenderWidgetHostViewBase::SetBackgroundColor(color);
|
2017-04-20 21:28:17 +02:00
|
|
|
}
|
2015-12-03 21:15:32 +01:00
|
|
|
|
2019-06-05 16:15:45 +02:00
|
|
|
base::Optional<SkColor> CefRenderWidgetHostViewOSR::GetBackgroundColor() {
|
2017-04-20 21:28:17 +02:00
|
|
|
return background_color_;
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2019-01-17 10:56:52 +01:00
|
|
|
void CefRenderWidgetHostViewOSR::UpdateBackgroundColor() {}
|
2018-05-21 14:54:08 +02:00
|
|
|
|
2019-10-01 15:55:16 +02:00
|
|
|
bool CefRenderWidgetHostViewOSR::LockMouse(bool request_unadjusted_movement) {
|
2014-07-01 00:30:29 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::UnlockMouse() {}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2018-04-19 17:44:42 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::TakeFallbackContentFrom(
|
|
|
|
content::RenderWidgetHostView* view) {
|
|
|
|
DCHECK(!static_cast<RenderWidgetHostViewBase*>(view)
|
|
|
|
->IsRenderWidgetHostViewChildFrame());
|
|
|
|
DCHECK(!static_cast<RenderWidgetHostViewBase*>(view)
|
|
|
|
->IsRenderWidgetHostViewGuest());
|
|
|
|
CefRenderWidgetHostViewOSR* view_cef =
|
|
|
|
static_cast<CefRenderWidgetHostViewOSR*>(view);
|
2018-05-21 14:54:08 +02:00
|
|
|
SetBackgroundColor(view_cef->background_color_);
|
2018-04-19 17:44:42 +02:00
|
|
|
if (GetDelegatedFrameHost() && view_cef->GetDelegatedFrameHost()) {
|
|
|
|
GetDelegatedFrameHost()->TakeFallbackContentFrom(
|
|
|
|
view_cef->GetDelegatedFrameHost());
|
|
|
|
}
|
|
|
|
host()->GetContentRenderingTimeoutFrom(view_cef->host());
|
|
|
|
}
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::DidCreateNewRendererCompositorFrameSink(
|
2017-09-06 23:40:58 +02:00
|
|
|
viz::mojom::CompositorFrameSinkClient* renderer_compositor_frame_sink) {
|
2019-07-16 22:09:04 +02:00
|
|
|
NOTREACHED();
|
2018-07-03 02:46:03 +02:00
|
|
|
}
|
|
|
|
|
2019-07-16 22:09:04 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::OnPresentCompositorFrame() {}
|
2017-04-20 21:28:17 +02:00
|
|
|
|
2020-01-08 13:33:57 +01:00
|
|
|
void CefRenderWidgetHostViewOSR::OnDidUpdateVisualPropertiesComplete(
|
|
|
|
const cc::RenderFrameMetadata& metadata) {
|
|
|
|
bool force = false;
|
|
|
|
if (metadata.local_surface_id_allocation) {
|
|
|
|
force = local_surface_id_allocator_.UpdateFromChild(
|
|
|
|
*metadata.local_surface_id_allocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
SynchronizeVisualProperties(force);
|
|
|
|
}
|
|
|
|
|
2019-01-29 21:52:46 +01:00
|
|
|
void CefRenderWidgetHostViewOSR::AddDamageRect(uint32_t sequence,
|
2018-07-03 02:46:03 +02:00
|
|
|
const gfx::Rect& rect) {
|
|
|
|
// Associate the given damage rect with the presentation token.
|
|
|
|
// For OnAcceleratedPaint we'll lookup the corresponding damage area based on
|
|
|
|
// the frame token which is passed back to OnPresentCompositorFrame.
|
|
|
|
base::AutoLock lock_scope(damage_rect_lock_);
|
|
|
|
|
|
|
|
// We assume our presentation_token is a counter. Since we're using an ordered
|
|
|
|
// map we can enforce a max size and remove oldest from the front. Worst case,
|
|
|
|
// if a damage rect isn't associated, we can simply pass the entire view size.
|
|
|
|
while (damage_rects_.size() >= kMaxDamageRects) {
|
|
|
|
damage_rects_.erase(damage_rects_.begin());
|
|
|
|
}
|
2019-01-29 21:52:46 +01:00
|
|
|
damage_rects_[sequence] = rect;
|
2018-07-03 02:46:03 +02:00
|
|
|
}
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::SubmitCompositorFrame(
|
2017-07-27 01:19:27 +02:00
|
|
|
const viz::LocalSurfaceId& local_surface_id,
|
2017-12-07 22:44:24 +01:00
|
|
|
viz::CompositorFrame frame,
|
2018-06-01 21:16:26 +02:00
|
|
|
base::Optional<viz::HitTestRegionList> hit_test_region_list) {
|
2019-07-16 22:09:04 +02:00
|
|
|
NOTREACHED();
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2018-09-04 11:43:21 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::ResetFallbackToFirstNavigationSurface() {
|
|
|
|
GetDelegatedFrameHost()->ResetFallbackToFirstNavigationSurface();
|
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::InitAsPopup(
|
|
|
|
content::RenderWidgetHostView* parent_host_view,
|
|
|
|
const gfx::Rect& pos) {
|
2015-06-11 17:00:05 +02:00
|
|
|
DCHECK_EQ(parent_host_view_, parent_host_view);
|
2017-02-10 23:44:11 +01:00
|
|
|
DCHECK(browser_impl_);
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
if (parent_host_view_->popup_host_view_) {
|
|
|
|
// Cancel the previous popup widget.
|
2015-08-17 21:48:57 +02:00
|
|
|
parent_host_view_->popup_host_view_->CancelWidget();
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
parent_host_view_->set_popup_host_view(this);
|
2015-01-26 01:57:01 +01:00
|
|
|
|
|
|
|
CefRefPtr<CefRenderHandler> handler =
|
|
|
|
browser_impl_->GetClient()->GetRenderHandler();
|
2018-09-25 15:40:02 +02:00
|
|
|
CHECK(handler);
|
|
|
|
|
|
|
|
handler->OnPopupShow(browser_impl_.get(), true);
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
popup_position_ = pos;
|
|
|
|
|
2015-01-01 17:51:56 +01:00
|
|
|
CefRect widget_pos(pos.x(), pos.y(), pos.width(), pos.height());
|
2015-01-26 01:57:01 +01:00
|
|
|
if (handler.get())
|
|
|
|
handler->OnPopupSize(browser_impl_.get(), widget_pos);
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2019-07-16 22:09:04 +02:00
|
|
|
if (video_consumer_) {
|
|
|
|
video_consumer_->SizeChanged();
|
|
|
|
}
|
|
|
|
|
2018-05-20 15:51:42 +02:00
|
|
|
ResizeRootLayer(false);
|
2019-07-16 22:09:04 +02:00
|
|
|
|
2015-02-04 19:10:14 +01:00
|
|
|
Show();
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::InitAsFullscreen(
|
|
|
|
content::RenderWidgetHostView* reference_host_view) {
|
|
|
|
NOTREACHED() << "Fullscreen widgets are not supported in OSR";
|
|
|
|
}
|
|
|
|
|
2017-02-10 23:44:11 +01:00
|
|
|
// Called for the "platform view" created by WebContentsViewGuest and owned by
|
|
|
|
// RenderWidgetHostViewGuest.
|
|
|
|
void CefRenderWidgetHostViewOSR::InitAsGuest(
|
|
|
|
content::RenderWidgetHostView* parent_host_view,
|
|
|
|
content::RenderWidgetHostViewGuest* guest_view) {
|
|
|
|
DCHECK_EQ(parent_host_view_, parent_host_view);
|
|
|
|
DCHECK(browser_impl_);
|
|
|
|
|
|
|
|
parent_host_view_->AddGuestHostView(this);
|
|
|
|
parent_host_view_->RegisterGuestViewFrameSwappedCallback(guest_view);
|
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::UpdateCursor(
|
|
|
|
const content::WebCursor& cursor) {
|
2018-11-30 23:21:07 +01:00
|
|
|
TRACE_EVENT0("cef", "CefRenderWidgetHostViewOSR::UpdateCursor");
|
2014-09-27 01:48:19 +02:00
|
|
|
if (!browser_impl_.get())
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
|
|
|
|
2015-01-26 01:57:01 +01:00
|
|
|
CefRefPtr<CefRenderHandler> handler =
|
|
|
|
browser_impl_->GetClient()->GetRenderHandler();
|
2018-09-25 15:40:02 +02:00
|
|
|
CHECK(handler);
|
2015-01-26 01:57:01 +01:00
|
|
|
|
2019-06-05 16:15:45 +02:00
|
|
|
const content::CursorInfo& cursor_info = cursor.info();
|
2014-11-24 22:56:12 +01:00
|
|
|
|
|
|
|
const cef_cursor_type_t cursor_type =
|
|
|
|
static_cast<cef_cursor_type_t>(cursor_info.type);
|
|
|
|
CefCursorInfo custom_cursor_info;
|
2019-09-04 17:13:32 +02:00
|
|
|
if (cursor_info.type == ui::CursorType::kCustom) {
|
2014-11-24 22:56:12 +01:00
|
|
|
custom_cursor_info.hotspot.x = cursor_info.hotspot.x();
|
|
|
|
custom_cursor_info.hotspot.y = cursor_info.hotspot.y();
|
|
|
|
custom_cursor_info.image_scale_factor = cursor_info.image_scale_factor;
|
|
|
|
custom_cursor_info.buffer = cursor_info.custom_image.getPixels();
|
|
|
|
custom_cursor_info.size.width = cursor_info.custom_image.width();
|
|
|
|
custom_cursor_info.size.height = cursor_info.custom_image.height();
|
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
#if defined(USE_AURA)
|
2019-06-05 16:15:45 +02:00
|
|
|
content::WebCursor web_cursor(cursor_info);
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
ui::PlatformCursor platform_cursor;
|
2019-09-04 17:13:32 +02:00
|
|
|
if (cursor_info.type == ui::CursorType::kCustom) {
|
2018-11-30 23:21:07 +01:00
|
|
|
ui::Cursor ui_cursor(ui::CursorType::kCustom);
|
|
|
|
SkBitmap bitmap;
|
|
|
|
gfx::Point hotspot;
|
|
|
|
float scale_factor;
|
|
|
|
web_cursor.CreateScaledBitmapAndHotspotFromCustomData(&bitmap, &hotspot,
|
|
|
|
&scale_factor);
|
|
|
|
ui_cursor.set_custom_bitmap(bitmap);
|
|
|
|
ui_cursor.set_custom_hotspot(hotspot);
|
|
|
|
ui_cursor.set_device_scale_factor(scale_factor);
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
// |web_cursor| owns the resulting |platform_cursor|.
|
2018-11-30 23:21:07 +01:00
|
|
|
platform_cursor = web_cursor.GetPlatformCursor(ui_cursor);
|
2014-07-01 00:30:29 +02:00
|
|
|
} else {
|
2015-11-17 19:20:13 +01:00
|
|
|
platform_cursor = GetPlatformCursor(cursor_info.type);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2015-01-26 01:57:01 +01:00
|
|
|
handler->OnCursorChange(browser_impl_.get(), platform_cursor, cursor_type,
|
|
|
|
custom_cursor_info);
|
2014-07-01 00:30:29 +02:00
|
|
|
#elif defined(OS_MACOSX)
|
|
|
|
// |web_cursor| owns the resulting |native_cursor|.
|
2019-06-05 16:15:45 +02:00
|
|
|
content::WebCursor web_cursor(cursor);
|
2014-07-01 00:30:29 +02:00
|
|
|
CefCursorHandle native_cursor = web_cursor.GetNativeCursor();
|
2015-01-26 01:57:01 +01:00
|
|
|
handler->OnCursorChange(browser_impl_.get(), native_cursor, cursor_type,
|
|
|
|
custom_cursor_info);
|
2014-07-01 00:30:29 +02:00
|
|
|
#else
|
|
|
|
// TODO(port): Implement this method to work on other platforms as part of
|
|
|
|
// off-screen rendering support.
|
|
|
|
NOTREACHED();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-09-14 11:18:10 +02:00
|
|
|
content::CursorManager* CefRenderWidgetHostViewOSR::GetCursorManager() {
|
|
|
|
return cursor_manager_.get();
|
|
|
|
}
|
|
|
|
|
2019-02-25 22:17:28 +01:00
|
|
|
void CefRenderWidgetHostViewOSR::SetIsLoading(bool is_loading) {
|
|
|
|
if (!is_loading)
|
|
|
|
return;
|
|
|
|
// Make sure gesture detection is fresh.
|
|
|
|
gesture_provider_.ResetDetection();
|
|
|
|
forward_touch_to_popup_ = false;
|
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2019-07-16 19:59:21 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::RenderProcessGone() {
|
2014-11-19 01:25:08 +01:00
|
|
|
Destroy();
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::Destroy() {
|
|
|
|
if (!is_destroyed_) {
|
|
|
|
is_destroyed_ = true;
|
|
|
|
|
2015-06-11 17:00:05 +02:00
|
|
|
if (has_parent_) {
|
2015-08-17 21:48:57 +02:00
|
|
|
CancelWidget();
|
2014-07-01 00:30:29 +02:00
|
|
|
} else {
|
|
|
|
if (popup_host_view_)
|
2015-08-17 21:48:57 +02:00
|
|
|
popup_host_view_->CancelWidget();
|
2015-06-11 17:00:05 +02:00
|
|
|
if (child_host_view_)
|
2015-08-17 21:48:57 +02:00
|
|
|
child_host_view_->CancelWidget();
|
2017-06-23 21:06:37 +02:00
|
|
|
if (!guest_host_views_.empty()) {
|
|
|
|
// Guest RWHVs will be destroyed when the associated RWHVGuest is
|
|
|
|
// destroyed. This parent RWHV may be destroyed first, so disassociate
|
|
|
|
// the guest RWHVs here without destroying them.
|
|
|
|
for (auto guest_host_view : guest_host_views_)
|
|
|
|
guest_host_view->parent_host_view_ = nullptr;
|
|
|
|
guest_host_views_.clear();
|
|
|
|
}
|
2015-02-04 19:10:14 +01:00
|
|
|
Hide();
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::SetTooltipText(
|
|
|
|
const base::string16& tooltip_text) {
|
2014-09-27 01:48:19 +02:00
|
|
|
if (!browser_impl_.get())
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
CefString tooltip(tooltip_text);
|
|
|
|
CefRefPtr<CefDisplayHandler> handler =
|
|
|
|
browser_impl_->GetClient()->GetDisplayHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
handler->OnTooltip(browser_impl_.get(), tooltip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-05 16:15:45 +02:00
|
|
|
gfx::Size CefRenderWidgetHostViewOSR::GetCompositorViewportPixelSize() {
|
2017-12-18 20:37:36 +01:00
|
|
|
return gfx::ScaleToCeiledSize(GetRequestedRendererSize(),
|
|
|
|
current_device_scale_factor_);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-16 11:28:49 +02:00
|
|
|
uint32_t CefRenderWidgetHostViewOSR::GetCaptureSequenceNumber() const {
|
|
|
|
return latest_capture_sequence_number_;
|
|
|
|
}
|
|
|
|
|
2017-03-03 23:37:23 +01:00
|
|
|
void CefRenderWidgetHostViewOSR::CopyFromSurface(
|
2018-03-20 21:15:08 +01:00
|
|
|
const gfx::Rect& src_rect,
|
|
|
|
const gfx::Size& output_size,
|
|
|
|
base::OnceCallback<void(const SkBitmap&)> callback) {
|
|
|
|
GetDelegatedFrameHost()->CopyFromCompositingSurface(src_rect, output_size,
|
|
|
|
std::move(callback));
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2019-06-05 16:15:45 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::GetScreenInfo(content::ScreenInfo* results) {
|
2018-03-20 21:15:08 +01:00
|
|
|
if (!browser_impl_.get())
|
|
|
|
return;
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
CefScreenInfo screen_info(kDefaultScaleFactor, 0, 0, false, CefRect(),
|
|
|
|
CefRect());
|
|
|
|
|
|
|
|
CefRefPtr<CefRenderHandler> handler =
|
|
|
|
browser_impl_->client()->GetRenderHandler();
|
2018-09-25 15:40:02 +02:00
|
|
|
CHECK(handler);
|
|
|
|
if (!handler->GetScreenInfo(browser_impl_.get(), screen_info) ||
|
|
|
|
screen_info.rect.width == 0 || screen_info.rect.height == 0 ||
|
|
|
|
screen_info.available_rect.width == 0 ||
|
|
|
|
screen_info.available_rect.height == 0) {
|
2018-03-20 21:15:08 +01:00
|
|
|
// If a screen rectangle was not provided, try using the view rectangle
|
2018-07-03 02:46:03 +02:00
|
|
|
// instead. Otherwise, popup views may be drawn incorrectly, or not at
|
|
|
|
// all.
|
2018-03-20 21:15:08 +01:00
|
|
|
CefRect screenRect;
|
2018-09-25 15:40:02 +02:00
|
|
|
handler->GetViewRect(browser_impl_.get(), screenRect);
|
|
|
|
CHECK_GT(screenRect.width, 0);
|
|
|
|
CHECK_GT(screenRect.height, 0);
|
2018-03-20 21:15:08 +01:00
|
|
|
|
2018-09-25 15:40:02 +02:00
|
|
|
if (screen_info.rect.width == 0 || screen_info.rect.height == 0) {
|
2018-03-20 21:15:08 +01:00
|
|
|
screen_info.rect = screenRect;
|
2018-09-25 15:40:02 +02:00
|
|
|
}
|
2018-03-20 21:15:08 +01:00
|
|
|
|
2018-09-25 15:40:02 +02:00
|
|
|
if (screen_info.available_rect.width == 0 ||
|
|
|
|
screen_info.available_rect.height == 0) {
|
2018-03-20 21:15:08 +01:00
|
|
|
screen_info.available_rect = screenRect;
|
2018-09-25 15:40:02 +02:00
|
|
|
}
|
2018-03-20 21:15:08 +01:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
*results = ScreenInfoFrom(screen_info);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2018-07-24 00:32:02 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::TransformPointToRootSurface(
|
|
|
|
gfx::PointF* point) {}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
gfx::Rect CefRenderWidgetHostViewOSR::GetBoundsInRootWindow() {
|
2014-09-27 01:48:19 +02:00
|
|
|
if (!browser_impl_.get())
|
2014-07-01 00:30:29 +02:00
|
|
|
return gfx::Rect();
|
|
|
|
|
|
|
|
CefRect rc;
|
2015-01-26 01:57:01 +01:00
|
|
|
CefRefPtr<CefRenderHandler> handler =
|
|
|
|
browser_impl_->client()->GetRenderHandler();
|
2018-09-25 15:40:02 +02:00
|
|
|
CHECK(handler);
|
|
|
|
if (handler->GetRootScreenRect(browser_impl_.get(), rc))
|
2014-07-01 00:30:29 +02:00
|
|
|
return gfx::Rect(rc.x, rc.y, rc.width, rc.height);
|
2017-07-27 01:19:27 +02:00
|
|
|
return GetViewBounds();
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2019-11-26 19:42:34 +01:00
|
|
|
#if !defined(OS_MACOSX)
|
|
|
|
viz::ScopedSurfaceIdAllocator
|
|
|
|
CefRenderWidgetHostViewOSR::DidUpdateVisualProperties(
|
|
|
|
const cc::RenderFrameMetadata& metadata) {
|
2020-01-08 13:33:57 +01:00
|
|
|
base::OnceCallback<void()> allocation_task = base::BindOnce(
|
|
|
|
&CefRenderWidgetHostViewOSR::OnDidUpdateVisualPropertiesComplete,
|
|
|
|
weak_ptr_factory_.GetWeakPtr(), metadata);
|
2019-11-26 19:42:34 +01:00
|
|
|
return viz::ScopedSurfaceIdAllocator(std::move(allocation_task));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
viz::SurfaceId CefRenderWidgetHostViewOSR::GetCurrentSurfaceId() const {
|
|
|
|
return GetDelegatedFrameHost()
|
|
|
|
? GetDelegatedFrameHost()->GetCurrentSurfaceId()
|
|
|
|
: viz::SurfaceId();
|
|
|
|
}
|
|
|
|
|
2014-09-04 19:53:40 +02:00
|
|
|
content::BrowserAccessibilityManager*
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRenderWidgetHostViewOSR::CreateBrowserAccessibilityManager(
|
|
|
|
content::BrowserAccessibilityDelegate* delegate,
|
|
|
|
bool for_root_frame) {
|
2014-09-04 19:53:40 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-10-28 18:11:24 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::ImeSetComposition(
|
|
|
|
const CefString& text,
|
|
|
|
const std::vector<CefCompositionUnderline>& underlines,
|
|
|
|
const CefRange& replacement_range,
|
|
|
|
const CefRange& selection_range) {
|
2018-11-30 23:21:07 +01:00
|
|
|
TRACE_EVENT0("cef", "CefRenderWidgetHostViewOSR::ImeSetComposition");
|
2016-10-28 18:11:24 +02:00
|
|
|
if (!render_widget_host_)
|
|
|
|
return;
|
|
|
|
|
2017-09-06 23:40:58 +02:00
|
|
|
std::vector<ui::ImeTextSpan> web_underlines;
|
2016-10-28 18:11:24 +02:00
|
|
|
web_underlines.reserve(underlines.size());
|
|
|
|
for (const CefCompositionUnderline& line : underlines) {
|
2017-09-06 23:40:58 +02:00
|
|
|
web_underlines.push_back(ui::ImeTextSpan(
|
|
|
|
ui::ImeTextSpan::Type::kComposition, line.range.from, line.range.to,
|
2018-04-19 17:44:42 +02:00
|
|
|
line.thick ? ui::ImeTextSpan::Thickness::kThick
|
|
|
|
: ui::ImeTextSpan::Thickness::kThin,
|
2019-01-28 18:12:22 +01:00
|
|
|
line.background_color, line.color, std::vector<std::string>()));
|
2016-10-28 18:11:24 +02:00
|
|
|
}
|
|
|
|
gfx::Range range(replacement_range.from, replacement_range.to);
|
|
|
|
|
|
|
|
// Start Monitoring for composition updates before we set.
|
|
|
|
RequestImeCompositionUpdate(true);
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
render_widget_host_->ImeSetComposition(
|
|
|
|
text, web_underlines, range, selection_range.from, selection_range.to);
|
2016-10-28 18:11:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::ImeCommitText(
|
|
|
|
const CefString& text,
|
|
|
|
const CefRange& replacement_range,
|
|
|
|
int relative_cursor_pos) {
|
2018-11-30 23:21:07 +01:00
|
|
|
TRACE_EVENT0("cef", "CefRenderWidgetHostViewOSR::ImeCommitText");
|
2016-10-28 18:11:24 +02:00
|
|
|
if (!render_widget_host_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gfx::Range range(replacement_range.from, replacement_range.to);
|
2017-09-06 23:40:58 +02:00
|
|
|
render_widget_host_->ImeCommitText(text, std::vector<ui::ImeTextSpan>(),
|
2017-07-27 01:19:27 +02:00
|
|
|
range, relative_cursor_pos);
|
2016-10-28 18:11:24 +02:00
|
|
|
|
|
|
|
// Stop Monitoring for composition updates after we are done.
|
|
|
|
RequestImeCompositionUpdate(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::ImeFinishComposingText(bool keep_selection) {
|
2018-11-30 23:21:07 +01:00
|
|
|
TRACE_EVENT0("cef", "CefRenderWidgetHostViewOSR::ImeFinishComposingText");
|
2016-10-28 18:11:24 +02:00
|
|
|
if (!render_widget_host_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
render_widget_host_->ImeFinishComposingText(keep_selection);
|
|
|
|
|
|
|
|
// Stop Monitoring for composition updates after we are done.
|
|
|
|
RequestImeCompositionUpdate(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::ImeCancelComposition() {
|
2018-11-30 23:21:07 +01:00
|
|
|
TRACE_EVENT0("cef", "CefRenderWidgetHostViewOSR::ImeCancelComposition");
|
2016-10-28 18:11:24 +02:00
|
|
|
if (!render_widget_host_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
render_widget_host_->ImeCancelComposition();
|
|
|
|
|
|
|
|
// Stop Monitoring for composition updates after we are done.
|
|
|
|
RequestImeCompositionUpdate(false);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2018-04-09 19:48:23 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::SelectionChanged(const base::string16& text,
|
|
|
|
size_t offset,
|
|
|
|
const gfx::Range& range) {
|
|
|
|
RenderWidgetHostViewBase::SelectionChanged(text, offset, range);
|
|
|
|
|
|
|
|
if (!browser_impl_.get())
|
|
|
|
return;
|
|
|
|
|
|
|
|
CefString selected_text;
|
|
|
|
if (!range.is_empty() && !text.empty()) {
|
|
|
|
size_t pos = range.GetMin() - offset;
|
|
|
|
size_t n = range.length();
|
|
|
|
if (pos + n <= text.length())
|
|
|
|
selected_text = text.substr(pos, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefRenderHandler> handler =
|
|
|
|
browser_impl_->GetClient()->GetRenderHandler();
|
2018-09-25 15:40:02 +02:00
|
|
|
CHECK(handler);
|
|
|
|
|
|
|
|
CefRange cef_range(range.start(), range.end());
|
|
|
|
handler->OnTextSelectionChanged(browser_impl_.get(), selected_text,
|
|
|
|
cef_range);
|
2018-04-09 19:48:23 +02:00
|
|
|
}
|
|
|
|
|
2018-11-30 23:21:07 +01:00
|
|
|
const viz::LocalSurfaceIdAllocation&
|
|
|
|
CefRenderWidgetHostViewOSR::GetLocalSurfaceIdAllocation() const {
|
|
|
|
return local_surface_id_allocation_;
|
2018-05-31 22:34:44 +02:00
|
|
|
}
|
|
|
|
|
2018-07-24 00:32:02 +02:00
|
|
|
const viz::FrameSinkId& CefRenderWidgetHostViewOSR::GetFrameSinkId() const {
|
2018-05-31 22:34:44 +02:00
|
|
|
return GetDelegatedFrameHost()->frame_sink_id();
|
|
|
|
}
|
|
|
|
|
2019-02-25 22:17:28 +01:00
|
|
|
viz::FrameSinkId CefRenderWidgetHostViewOSR::GetRootFrameSinkId() {
|
|
|
|
return compositor_->frame_sink_id();
|
|
|
|
}
|
|
|
|
|
2019-02-21 01:42:36 +01:00
|
|
|
std::unique_ptr<content::SyntheticGestureTarget>
|
|
|
|
CefRenderWidgetHostViewOSR::CreateSyntheticGestureTarget() {
|
2019-03-13 22:27:37 +01:00
|
|
|
return std::make_unique<CefSyntheticGestureTargetOSR>(host());
|
2019-02-21 01:42:36 +01:00
|
|
|
}
|
|
|
|
|
2016-08-31 13:25:56 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::SetNeedsBeginFrames(bool enabled) {
|
2015-08-17 21:48:57 +02:00
|
|
|
SetFrameRate();
|
|
|
|
|
2019-11-26 19:26:54 +01:00
|
|
|
if (host_display_client_) {
|
|
|
|
host_display_client_->SetActive(enabled);
|
|
|
|
}
|
2015-01-01 17:51:56 +01:00
|
|
|
}
|
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
void CefRenderWidgetHostViewOSR::SetWantsAnimateOnlyBeginFrames() {
|
|
|
|
if (GetDelegatedFrameHost()) {
|
|
|
|
GetDelegatedFrameHost()->SetWantsAnimateOnlyBeginFrames();
|
|
|
|
}
|
2017-06-23 21:06:37 +02:00
|
|
|
}
|
|
|
|
|
2017-03-03 23:37:23 +01:00
|
|
|
bool CefRenderWidgetHostViewOSR::TransformPointToCoordSpaceForView(
|
2017-12-07 22:44:24 +01:00
|
|
|
const gfx::PointF& point,
|
2017-03-03 23:37:23 +01:00
|
|
|
RenderWidgetHostViewBase* target_view,
|
2019-03-13 22:27:37 +01:00
|
|
|
gfx::PointF* transformed_point) {
|
2017-03-03 23:37:23 +01:00
|
|
|
if (target_view == this) {
|
|
|
|
*transformed_point = point;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-08 13:32:05 +01:00
|
|
|
return target_view->TransformPointToLocalCoordSpace(
|
|
|
|
point, GetCurrentSurfaceId(), transformed_point);
|
2017-03-03 23:37:23 +01:00
|
|
|
}
|
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
void CefRenderWidgetHostViewOSR::DidNavigate() {
|
2018-05-20 15:51:42 +02:00
|
|
|
// With surface synchronization enabled we need to force synchronization on
|
|
|
|
// first navigation.
|
|
|
|
ResizeRootLayer(true);
|
2018-03-20 21:15:08 +01:00
|
|
|
if (delegated_frame_host_)
|
|
|
|
delegated_frame_host_->DidNavigate();
|
|
|
|
}
|
|
|
|
|
2019-11-12 17:11:44 +01:00
|
|
|
void CefRenderWidgetHostViewOSR::OnFrameComplete(
|
|
|
|
const viz::BeginFrameAck& ack) {
|
2018-07-03 02:46:03 +02:00
|
|
|
// TODO(cef): is there something we need to track with this notification?
|
|
|
|
}
|
|
|
|
|
2019-07-16 22:09:04 +02:00
|
|
|
std::unique_ptr<viz::HostDisplayClient>
|
|
|
|
CefRenderWidgetHostViewOSR::CreateHostDisplayClient() {
|
|
|
|
host_display_client_ =
|
|
|
|
new CefHostDisplayClientOSR(this, gfx::kNullAcceleratedWidget);
|
|
|
|
host_display_client_->SetActive(true);
|
|
|
|
return base::WrapUnique(host_display_client_);
|
2015-01-01 17:51:56 +01:00
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
bool CefRenderWidgetHostViewOSR::InstallTransparency() {
|
2018-05-21 14:54:08 +02:00
|
|
|
if (background_color_ == SK_ColorTRANSPARENT) {
|
|
|
|
SetBackgroundColor(background_color_);
|
2019-07-16 22:09:04 +02:00
|
|
|
if (compositor_) {
|
|
|
|
compositor_->SetBackgroundColor(background_color_);
|
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-18 22:04:21 +01:00
|
|
|
void CefRenderWidgetHostViewOSR::SynchronizeVisualProperties(bool force) {
|
2014-07-01 00:30:29 +02:00
|
|
|
if (hold_resize_) {
|
|
|
|
if (!pending_resize_)
|
|
|
|
pending_resize_ = true;
|
2019-03-18 22:04:21 +01:00
|
|
|
if (force)
|
|
|
|
pending_resize_force_ = true;
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-18 22:04:21 +01:00
|
|
|
ResizeRootLayer(force);
|
2016-08-31 13:25:56 +02:00
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::OnScreenInfoChanged() {
|
2018-11-30 23:21:07 +01:00
|
|
|
TRACE_EVENT0("cef", "CefRenderWidgetHostViewOSR::OnScreenInfoChanged");
|
2014-07-01 00:30:29 +02:00
|
|
|
if (!render_widget_host_)
|
|
|
|
return;
|
|
|
|
|
2019-02-27 20:44:31 +01:00
|
|
|
SynchronizeVisualProperties();
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
if (render_widget_host_->delegate())
|
|
|
|
render_widget_host_->delegate()->SendScreenRects();
|
|
|
|
else
|
|
|
|
render_widget_host_->SendScreenRects();
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
render_widget_host_->NotifyScreenInfoChanged();
|
2018-03-20 21:15:08 +01:00
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
// We might want to change the cursor scale factor here as well - see the
|
2018-07-03 02:46:03 +02:00
|
|
|
// cache for the current_cursor_, as passed by UpdateCursor from the
|
|
|
|
// renderer in the rwhv_aura (current_cursor_.SetScaleFactor)
|
2015-08-17 21:48:57 +02:00
|
|
|
|
|
|
|
// Notify the guest hosts if any.
|
|
|
|
for (auto guest_host_view : guest_host_views_)
|
|
|
|
guest_host_view->OnScreenInfoChanged();
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::Invalidate(
|
|
|
|
CefBrowserHost::PaintElementType type) {
|
2018-11-30 23:21:07 +01:00
|
|
|
TRACE_EVENT1("cef", "CefRenderWidgetHostViewOSR::Invalidate", "type", type);
|
2014-07-01 00:30:29 +02:00
|
|
|
if (!IsPopupWidget() && type == PET_POPUP) {
|
|
|
|
if (popup_host_view_)
|
|
|
|
popup_host_view_->Invalidate(type);
|
|
|
|
return;
|
|
|
|
}
|
2019-07-16 22:09:04 +02:00
|
|
|
InvalidateInternal(gfx::Rect(SizeInPixels()));
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2018-07-03 02:46:03 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::SendExternalBeginFrame() {
|
|
|
|
DCHECK(external_begin_frame_enabled_);
|
|
|
|
|
|
|
|
base::TimeTicks frame_time = base::TimeTicks::Now();
|
|
|
|
base::TimeTicks deadline = base::TimeTicks();
|
|
|
|
base::TimeDelta interval = viz::BeginFrameArgs::DefaultInterval();
|
|
|
|
|
|
|
|
viz::BeginFrameArgs begin_frame_args = viz::BeginFrameArgs::Create(
|
|
|
|
BEGINFRAME_FROM_HERE, begin_frame_source_.source_id(),
|
|
|
|
begin_frame_number_, frame_time, deadline, interval,
|
|
|
|
viz::BeginFrameArgs::NORMAL);
|
|
|
|
|
|
|
|
DCHECK(begin_frame_args.IsValid());
|
|
|
|
begin_frame_number_++;
|
|
|
|
|
2019-03-18 22:07:02 +01:00
|
|
|
if (render_widget_host_)
|
|
|
|
render_widget_host_->ProgressFlingIfNeeded(frame_time);
|
|
|
|
|
2019-07-19 01:30:29 +02:00
|
|
|
compositor_->context_factory_private()->IssueExternalBeginFrame(
|
2019-11-12 17:11:44 +01:00
|
|
|
compositor_.get(), begin_frame_args, /* force= */ true,
|
|
|
|
base::BindOnce(&CefRenderWidgetHostViewOSR::OnFrameComplete,
|
|
|
|
weak_ptr_factory_.GetWeakPtr()));
|
2018-07-03 02:46:03 +02:00
|
|
|
|
|
|
|
if (!IsPopupWidget() && popup_host_view_) {
|
|
|
|
popup_host_view_->SendExternalBeginFrame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::SendKeyEvent(
|
|
|
|
const content::NativeWebKeyboardEvent& event) {
|
2018-11-30 23:21:07 +01:00
|
|
|
TRACE_EVENT0("cef", "CefRenderWidgetHostViewOSR::SendKeyEvent");
|
2017-06-30 22:30:30 +02:00
|
|
|
if (render_widget_host_ && render_widget_host_->GetView()) {
|
|
|
|
// Direct routing requires that events go directly to the View.
|
2018-02-15 01:12:09 +01:00
|
|
|
render_widget_host_->ForwardKeyboardEventWithLatencyInfo(
|
2017-06-30 22:30:30 +02:00
|
|
|
event, ui::LatencyInfo(event.GetType() == blink::WebInputEvent::kChar ||
|
|
|
|
event.GetType() ==
|
|
|
|
blink::WebInputEvent::kRawKeyDown
|
|
|
|
? ui::SourceEventType::KEY_PRESS
|
|
|
|
: ui::SourceEventType::OTHER));
|
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::SendMouseEvent(
|
|
|
|
const blink::WebMouseEvent& event) {
|
2018-11-30 23:21:07 +01:00
|
|
|
TRACE_EVENT0("cef", "CefRenderWidgetHostViewOSR::SendMouseEvent");
|
2014-07-01 00:30:29 +02:00
|
|
|
if (!IsPopupWidget()) {
|
2017-04-20 21:28:17 +02:00
|
|
|
if (browser_impl_.get() &&
|
|
|
|
event.GetType() == blink::WebMouseEvent::kMouseDown) {
|
2014-07-01 00:30:29 +02:00
|
|
|
browser_impl_->CancelContextMenu();
|
2017-04-20 21:28:17 +02:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2017-06-23 21:06:37 +02:00
|
|
|
if (popup_host_view_) {
|
|
|
|
if (popup_host_view_->popup_position_.Contains(
|
|
|
|
event.PositionInWidget().x, event.PositionInWidget().y)) {
|
|
|
|
blink::WebMouseEvent popup_event(event);
|
|
|
|
popup_event.SetPositionInWidget(
|
|
|
|
event.PositionInWidget().x - popup_host_view_->popup_position_.x(),
|
|
|
|
event.PositionInWidget().y - popup_host_view_->popup_position_.y());
|
|
|
|
popup_event.SetPositionInScreen(popup_event.PositionInWidget().x,
|
|
|
|
popup_event.PositionInWidget().y);
|
|
|
|
|
|
|
|
popup_host_view_->SendMouseEvent(popup_event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (!guest_host_views_.empty()) {
|
|
|
|
for (auto guest_host_view : guest_host_views_) {
|
|
|
|
if (!guest_host_view->render_widget_host_ ||
|
|
|
|
!guest_host_view->render_widget_host_->GetView()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const gfx::Rect& guest_bounds =
|
|
|
|
guest_host_view->render_widget_host_->GetView()->GetViewBounds();
|
|
|
|
if (guest_bounds.Contains(event.PositionInWidget().x,
|
|
|
|
event.PositionInWidget().y)) {
|
|
|
|
blink::WebMouseEvent guest_event(event);
|
|
|
|
guest_event.SetPositionInWidget(
|
|
|
|
event.PositionInWidget().x - guest_bounds.x(),
|
|
|
|
event.PositionInWidget().y - guest_bounds.y());
|
|
|
|
guest_event.SetPositionInScreen(guest_event.PositionInWidget().x,
|
|
|
|
guest_event.PositionInWidget().y);
|
|
|
|
|
|
|
|
guest_host_view->SendMouseEvent(guest_event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
}
|
2017-06-23 21:06:37 +02:00
|
|
|
|
|
|
|
if (render_widget_host_ && render_widget_host_->GetView()) {
|
2020-01-08 13:32:05 +01:00
|
|
|
if (ShouldRouteEvents()) {
|
|
|
|
// RouteMouseEvent wants non-const pointer to WebMouseEvent, but it only
|
|
|
|
// forwards it to RenderWidgetTargeter::FindTargetAndDispatch as a const
|
|
|
|
// reference, so const_cast here is safe.
|
|
|
|
render_widget_host_->delegate()->GetInputEventRouter()->RouteMouseEvent(
|
|
|
|
this, const_cast<blink::WebMouseEvent*>(&event),
|
|
|
|
ui::LatencyInfo(ui::SourceEventType::OTHER));
|
|
|
|
} else {
|
|
|
|
render_widget_host_->GetView()->ProcessMouseEvent(
|
|
|
|
event, ui::LatencyInfo(ui::SourceEventType::OTHER));
|
|
|
|
}
|
2017-06-23 21:06:37 +02:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::SendMouseWheelEvent(
|
|
|
|
const blink::WebMouseWheelEvent& event) {
|
2018-11-30 23:21:07 +01:00
|
|
|
TRACE_EVENT0("cef", "CefRenderWidgetHostViewOSR::SendMouseWheelEvent");
|
2018-06-16 00:19:14 +02:00
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
if (!IsPopupWidget()) {
|
2014-09-27 01:48:19 +02:00
|
|
|
if (browser_impl_.get())
|
2014-07-01 00:30:29 +02:00
|
|
|
browser_impl_->CancelContextMenu();
|
|
|
|
|
|
|
|
if (popup_host_view_) {
|
2017-04-20 21:28:17 +02:00
|
|
|
if (popup_host_view_->popup_position_.Contains(
|
2020-01-08 16:02:22 +01:00
|
|
|
event.PositionInWidget().x, event.PositionInWidget().y)) {
|
|
|
|
blink::WebMouseWheelEvent popup_mouse_wheel_event(event);
|
2018-06-16 00:19:14 +02:00
|
|
|
popup_mouse_wheel_event.SetPositionInWidget(
|
2020-01-08 16:02:22 +01:00
|
|
|
event.PositionInWidget().x - popup_host_view_->popup_position_.x(),
|
|
|
|
event.PositionInWidget().y - popup_host_view_->popup_position_.y());
|
2018-06-16 00:19:14 +02:00
|
|
|
popup_mouse_wheel_event.SetPositionInScreen(
|
|
|
|
popup_mouse_wheel_event.PositionInWidget().x,
|
|
|
|
popup_mouse_wheel_event.PositionInWidget().y);
|
|
|
|
|
|
|
|
popup_host_view_->SendMouseWheelEvent(popup_mouse_wheel_event);
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
// Scrolling outside of the popup widget so destroy it.
|
2018-07-03 02:46:03 +02:00
|
|
|
// Execute asynchronously to avoid deleting the widget from inside
|
|
|
|
// some other callback.
|
2017-05-17 11:29:28 +02:00
|
|
|
CEF_POST_TASK(
|
|
|
|
CEF_UIT,
|
2015-08-17 21:48:57 +02:00
|
|
|
base::Bind(&CefRenderWidgetHostViewOSR::CancelWidget,
|
2014-07-01 00:30:29 +02:00
|
|
|
popup_host_view_->weak_ptr_factory_.GetWeakPtr()));
|
|
|
|
}
|
2017-06-23 21:06:37 +02:00
|
|
|
} else if (!guest_host_views_.empty()) {
|
|
|
|
for (auto guest_host_view : guest_host_views_) {
|
|
|
|
if (!guest_host_view->render_widget_host_ ||
|
|
|
|
!guest_host_view->render_widget_host_->GetView()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const gfx::Rect& guest_bounds =
|
|
|
|
guest_host_view->render_widget_host_->GetView()->GetViewBounds();
|
2020-01-08 16:02:22 +01:00
|
|
|
if (guest_bounds.Contains(event.PositionInWidget().x,
|
|
|
|
event.PositionInWidget().y)) {
|
|
|
|
blink::WebMouseWheelEvent guest_mouse_wheel_event(event);
|
2018-06-16 00:19:14 +02:00
|
|
|
guest_mouse_wheel_event.SetPositionInWidget(
|
2020-01-08 16:02:22 +01:00
|
|
|
event.PositionInWidget().x - guest_bounds.x(),
|
|
|
|
event.PositionInWidget().y - guest_bounds.y());
|
2018-06-16 00:19:14 +02:00
|
|
|
guest_mouse_wheel_event.SetPositionInScreen(
|
|
|
|
guest_mouse_wheel_event.PositionInWidget().x,
|
|
|
|
guest_mouse_wheel_event.PositionInWidget().y);
|
|
|
|
|
|
|
|
guest_host_view->SendMouseWheelEvent(guest_mouse_wheel_event);
|
2017-06-23 21:06:37 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
}
|
2017-06-23 21:06:37 +02:00
|
|
|
|
|
|
|
if (render_widget_host_ && render_widget_host_->GetView()) {
|
2020-01-08 16:02:22 +01:00
|
|
|
blink::WebMouseWheelEvent mouse_wheel_event(event);
|
|
|
|
|
|
|
|
mouse_wheel_phase_handler_.SendWheelEndForTouchpadScrollingIfNeeded(false);
|
|
|
|
mouse_wheel_phase_handler_.AddPhaseIfNeededAndScheduleEndEvent(
|
|
|
|
mouse_wheel_event, false);
|
|
|
|
|
2020-01-08 13:32:05 +01:00
|
|
|
if (ShouldRouteEvents()) {
|
|
|
|
render_widget_host_->delegate()
|
|
|
|
->GetInputEventRouter()
|
|
|
|
->RouteMouseWheelEvent(
|
|
|
|
this, const_cast<blink::WebMouseWheelEvent*>(&mouse_wheel_event),
|
|
|
|
ui::LatencyInfo(ui::SourceEventType::WHEEL));
|
|
|
|
} else {
|
|
|
|
render_widget_host_->GetView()->ProcessMouseWheelEvent(
|
|
|
|
mouse_wheel_event, ui::LatencyInfo(ui::SourceEventType::WHEEL));
|
|
|
|
}
|
2017-06-23 21:06:37 +02:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2019-02-25 22:17:28 +01:00
|
|
|
void CefRenderWidgetHostViewOSR::SendTouchEvent(const CefTouchEvent& event) {
|
|
|
|
TRACE_EVENT0("cef", "CefRenderWidgetHostViewOSR::SendTouchEvent");
|
|
|
|
|
|
|
|
if (!IsPopupWidget() && popup_host_view_) {
|
|
|
|
if (!forward_touch_to_popup_ && event.type == CEF_TET_PRESSED &&
|
|
|
|
pointer_state_.GetPointerCount() == 0) {
|
|
|
|
forward_touch_to_popup_ =
|
|
|
|
popup_host_view_->popup_position_.Contains(event.x, event.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (forward_touch_to_popup_) {
|
|
|
|
CefTouchEvent popup_event(event);
|
|
|
|
popup_event.x -= popup_host_view_->popup_position_.x();
|
|
|
|
popup_event.y -= popup_host_view_->popup_position_.y();
|
|
|
|
popup_host_view_->SendTouchEvent(popup_event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the touch event first.
|
|
|
|
if (!pointer_state_.OnTouch(event))
|
|
|
|
return;
|
|
|
|
|
|
|
|
ui::FilteredGestureProvider::TouchHandlingResult result =
|
|
|
|
gesture_provider_.OnTouchEvent(pointer_state_);
|
|
|
|
|
|
|
|
blink::WebTouchEvent touch_event = ui::CreateWebTouchEventFromMotionEvent(
|
|
|
|
pointer_state_, result.moved_beyond_slop_region, false);
|
|
|
|
|
|
|
|
pointer_state_.CleanupRemovedTouchPoints(event);
|
|
|
|
|
|
|
|
// Set unchanged touch point to StateStationary for touchmove and
|
|
|
|
// touchcancel to make sure only send one ack per WebTouchEvent.
|
|
|
|
if (!result.succeeded)
|
|
|
|
pointer_state_.MarkUnchangedTouchPointsAsStationary(&touch_event, event);
|
|
|
|
|
|
|
|
if (!render_widget_host_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ui::LatencyInfo latency_info = CreateLatencyInfo(touch_event);
|
|
|
|
if (ShouldRouteEvents()) {
|
|
|
|
render_widget_host_->delegate()->GetInputEventRouter()->RouteTouchEvent(
|
|
|
|
this, &touch_event, latency_info);
|
|
|
|
} else {
|
|
|
|
render_widget_host_->ForwardTouchEventWithLatencyInfo(touch_event,
|
|
|
|
latency_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool touch_end = touch_event.GetType() == blink::WebInputEvent::kTouchEnd ||
|
|
|
|
touch_event.GetType() == blink::WebInputEvent::kTouchCancel;
|
|
|
|
|
|
|
|
if (touch_end && IsPopupWidget() && parent_host_view_ &&
|
|
|
|
parent_host_view_->popup_host_view_ == this) {
|
|
|
|
parent_host_view_->forward_touch_to_popup_ = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefRenderWidgetHostViewOSR::ShouldRouteEvents() const {
|
|
|
|
if (!render_widget_host_->delegate())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Do not route events that are currently targeted to page popups such as
|
|
|
|
// <select> element drop-downs, since these cannot contain cross-process
|
|
|
|
// frames.
|
|
|
|
if (!render_widget_host_->delegate()->IsWidgetForMainFrame(
|
|
|
|
render_widget_host_)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !!render_widget_host_->delegate()->GetInputEventRouter();
|
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::SendFocusEvent(bool focus) {
|
|
|
|
if (!render_widget_host_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
content::RenderWidgetHostImpl* widget =
|
|
|
|
content::RenderWidgetHostImpl::From(render_widget_host_);
|
|
|
|
if (focus) {
|
|
|
|
widget->GotFocus();
|
|
|
|
widget->SetActive(true);
|
|
|
|
} else {
|
2014-09-27 01:48:19 +02:00
|
|
|
if (browser_impl_.get())
|
2014-07-01 00:30:29 +02:00
|
|
|
browser_impl_->CancelContextMenu();
|
|
|
|
|
|
|
|
widget->SetActive(false);
|
2017-07-27 01:19:27 +02:00
|
|
|
widget->LostFocus();
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-26 17:49:41 +01:00
|
|
|
void CefRenderWidgetHostViewOSR::OnUpdateTextInputStateCalled(
|
|
|
|
content::TextInputManager* text_input_manager,
|
|
|
|
content::RenderWidgetHostViewBase* updated_view,
|
|
|
|
bool did_update_state) {
|
|
|
|
const content::TextInputState* state =
|
|
|
|
text_input_manager->GetTextInputState();
|
|
|
|
if (state && !state->show_ime_if_needed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CefRenderHandler::TextInputMode mode = CEF_TEXT_INPUT_MODE_NONE;
|
|
|
|
if (state && state->type != ui::TEXT_INPUT_TYPE_NONE) {
|
|
|
|
static_assert(
|
|
|
|
static_cast<int>(CEF_TEXT_INPUT_MODE_MAX) ==
|
|
|
|
static_cast<int>(ui::TEXT_INPUT_MODE_MAX),
|
|
|
|
"Enum values in cef_text_input_mode_t must match ui::TextInputMode");
|
|
|
|
mode = static_cast<CefRenderHandler::TextInputMode>(state->mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefRenderHandler> handler =
|
|
|
|
browser_impl_->GetClient()->GetRenderHandler();
|
|
|
|
CHECK(handler);
|
|
|
|
|
|
|
|
handler->OnVirtualKeyboardRequested(browser_impl_->GetBrowser(), mode);
|
|
|
|
}
|
|
|
|
|
2019-02-25 22:17:28 +01:00
|
|
|
void CefRenderWidgetHostViewOSR::ProcessAckedTouchEvent(
|
|
|
|
const content::TouchEventWithLatencyInfo& touch,
|
|
|
|
content::InputEventAckState ack_result) {
|
|
|
|
const bool event_consumed =
|
|
|
|
ack_result == content::INPUT_EVENT_ACK_STATE_CONSUMED;
|
|
|
|
gesture_provider_.OnTouchEventAck(touch.event.unique_touch_event_id,
|
|
|
|
event_consumed, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::OnGestureEvent(
|
|
|
|
const ui::GestureEventData& gesture) {
|
|
|
|
if ((gesture.type() == ui::ET_GESTURE_PINCH_BEGIN ||
|
|
|
|
gesture.type() == ui::ET_GESTURE_PINCH_UPDATE ||
|
|
|
|
gesture.type() == ui::ET_GESTURE_PINCH_END) &&
|
|
|
|
!pinch_zoom_enabled_) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
blink::WebGestureEvent web_event =
|
|
|
|
ui::CreateWebGestureEventFromGestureEventData(gesture);
|
|
|
|
|
|
|
|
// without this check, forwarding gestures does not work!
|
|
|
|
if (web_event.GetType() == blink::WebInputEvent::kUndefined)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ui::LatencyInfo latency_info = CreateLatencyInfo(web_event);
|
|
|
|
if (ShouldRouteEvents()) {
|
|
|
|
render_widget_host_->delegate()->GetInputEventRouter()->RouteGestureEvent(
|
|
|
|
this, &web_event, latency_info);
|
|
|
|
} else {
|
|
|
|
render_widget_host_->ForwardGestureEventWithLatencyInfo(web_event,
|
|
|
|
latency_info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-13 17:43:50 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::UpdateFrameRate() {
|
2016-11-23 18:26:50 +01:00
|
|
|
frame_rate_threshold_us_ = 0;
|
2015-05-13 17:43:50 +02:00
|
|
|
SetFrameRate();
|
2015-08-17 21:48:57 +02:00
|
|
|
|
|
|
|
// Notify the guest hosts if any.
|
|
|
|
for (auto guest_host_view : guest_host_views_)
|
|
|
|
guest_host_view->UpdateFrameRate();
|
2015-05-13 17:43:50 +02:00
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::HoldResize() {
|
|
|
|
if (!hold_resize_)
|
|
|
|
hold_resize_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::ReleaseResize() {
|
|
|
|
if (!hold_resize_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
hold_resize_ = false;
|
|
|
|
if (pending_resize_) {
|
2019-03-18 22:04:21 +01:00
|
|
|
bool force = pending_resize_force_;
|
2014-07-01 00:30:29 +02:00
|
|
|
pending_resize_ = false;
|
2019-03-18 22:04:21 +01:00
|
|
|
pending_resize_force_ = false;
|
2018-05-17 10:58:21 +02:00
|
|
|
CEF_POST_TASK(
|
|
|
|
CEF_UIT,
|
|
|
|
base::Bind(&CefRenderWidgetHostViewOSR::SynchronizeVisualProperties,
|
2019-03-18 22:04:21 +01:00
|
|
|
weak_ptr_factory_.GetWeakPtr(), force));
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-16 22:09:04 +02:00
|
|
|
gfx::Size CefRenderWidgetHostViewOSR::SizeInPixels() {
|
|
|
|
return gfx::ConvertSizeToPixel(current_device_scale_factor_,
|
|
|
|
GetViewBounds().size());
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
void CefRenderWidgetHostViewOSR::SetActive(bool active) {}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::ShowDefinitionForSelection() {}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::SpeakSelection() {}
|
|
|
|
#endif
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::OnPaint(const gfx::Rect& damage_rect,
|
2019-07-16 22:09:04 +02:00
|
|
|
const gfx::Size& pixel_size,
|
|
|
|
const void* pixels) {
|
2018-11-30 23:21:07 +01:00
|
|
|
TRACE_EVENT0("cef", "CefRenderWidgetHostViewOSR::OnPaint");
|
2015-01-01 17:51:56 +01:00
|
|
|
|
2020-01-08 13:33:06 +01:00
|
|
|
// Workaround for https://bitbucket.org/chromiumembedded/cef/issues/2817
|
|
|
|
if (!is_showing_) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-16 22:09:04 +02:00
|
|
|
if (!pixels) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-26 01:57:01 +01:00
|
|
|
CefRefPtr<CefRenderHandler> handler =
|
|
|
|
browser_impl_->client()->GetRenderHandler();
|
2018-09-25 15:40:02 +02:00
|
|
|
CHECK(handler);
|
2015-01-26 01:57:01 +01:00
|
|
|
|
2018-05-17 10:58:21 +02:00
|
|
|
// Don't execute SynchronizeVisualProperties while the OnPaint callback is
|
|
|
|
// pending.
|
2015-01-01 17:51:56 +01:00
|
|
|
HoldResize();
|
|
|
|
|
2019-07-16 22:09:04 +02:00
|
|
|
gfx::Rect rect_in_pixels(0, 0, pixel_size.width(), pixel_size.height());
|
|
|
|
rect_in_pixels.Intersect(damage_rect);
|
2015-01-01 17:51:56 +01:00
|
|
|
|
|
|
|
CefRenderHandler::RectList rcList;
|
2019-07-16 22:09:04 +02:00
|
|
|
rcList.push_back(CefRect(rect_in_pixels.x(), rect_in_pixels.y(),
|
|
|
|
rect_in_pixels.width(), rect_in_pixels.height()));
|
2015-01-01 17:51:56 +01:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
handler->OnPaint(browser_impl_.get(), IsPopupWidget() ? PET_POPUP : PET_VIEW,
|
2019-07-16 22:09:04 +02:00
|
|
|
rcList, pixels, pixel_size.width(), pixel_size.height());
|
2015-01-01 17:51:56 +01:00
|
|
|
|
|
|
|
ReleaseResize();
|
|
|
|
}
|
|
|
|
|
2016-07-21 23:21:32 +02:00
|
|
|
ui::Layer* CefRenderWidgetHostViewOSR::GetRootLayer() const {
|
|
|
|
return root_layer_.get();
|
|
|
|
}
|
|
|
|
|
2016-07-06 21:34:09 +02:00
|
|
|
content::DelegatedFrameHost* CefRenderWidgetHostViewOSR::GetDelegatedFrameHost()
|
|
|
|
const {
|
|
|
|
return delegated_frame_host_.get();
|
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::SetFrameRate() {
|
2015-08-17 21:48:57 +02:00
|
|
|
CefRefPtr<CefBrowserHostImpl> browser;
|
|
|
|
if (parent_host_view_) {
|
|
|
|
// Use the same frame rate as the embedding browser.
|
|
|
|
browser = parent_host_view_->browser_impl_;
|
|
|
|
} else {
|
|
|
|
browser = browser_impl_;
|
|
|
|
}
|
|
|
|
CHECK(browser);
|
2015-01-01 17:51:56 +01:00
|
|
|
|
|
|
|
// Only set the frame rate one time.
|
2016-11-23 18:26:50 +01:00
|
|
|
if (frame_rate_threshold_us_ != 0)
|
2015-01-01 17:51:56 +01:00
|
|
|
return;
|
|
|
|
|
2019-07-16 22:09:04 +02:00
|
|
|
int frame_rate =
|
|
|
|
osr_util::ClampFrameRate(browser->settings().windowless_frame_rate);
|
2018-07-03 02:46:03 +02:00
|
|
|
|
2016-11-23 18:26:50 +01:00
|
|
|
frame_rate_threshold_us_ = 1000000 / frame_rate;
|
2015-01-01 17:51:56 +01:00
|
|
|
|
2019-07-19 01:30:29 +02:00
|
|
|
if (compositor_) {
|
|
|
|
compositor_->SetDisplayVSyncParameters(
|
2019-07-16 19:59:21 +02:00
|
|
|
base::TimeTicks::Now(),
|
|
|
|
base::TimeDelta::FromMicroseconds(frame_rate_threshold_us_));
|
|
|
|
}
|
2015-01-01 17:51:56 +01:00
|
|
|
|
2019-07-16 22:09:04 +02:00
|
|
|
if (video_consumer_) {
|
|
|
|
video_consumer_->SetFrameRate(
|
|
|
|
base::TimeDelta::FromMicroseconds(frame_rate_threshold_us_));
|
2015-01-01 17:51:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::SetDeviceScaleFactor() {
|
2016-08-31 13:25:56 +02:00
|
|
|
float new_scale_factor = kDefaultScaleFactor;
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
if (browser_impl_.get()) {
|
|
|
|
CefScreenInfo screen_info(kDefaultScaleFactor, 0, 0, false, CefRect(),
|
|
|
|
CefRect());
|
2015-01-26 01:57:01 +01:00
|
|
|
CefRefPtr<CefRenderHandler> handler =
|
|
|
|
browser_impl_->client()->GetRenderHandler();
|
2018-09-25 15:40:02 +02:00
|
|
|
CHECK(handler);
|
|
|
|
if (handler->GetScreenInfo(browser_impl_.get(), screen_info)) {
|
2016-08-31 13:25:56 +02:00
|
|
|
new_scale_factor = screen_info.device_scale_factor;
|
2015-01-01 17:51:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-23 21:06:37 +02:00
|
|
|
current_device_scale_factor_ = new_scale_factor;
|
2016-08-31 13:25:56 +02:00
|
|
|
|
|
|
|
// Notify the guest hosts if any.
|
|
|
|
for (auto guest_host_view : guest_host_views_) {
|
2017-06-30 22:30:30 +02:00
|
|
|
content::RenderWidgetHostImpl* rwhi = guest_host_view->render_widget_host();
|
|
|
|
if (!rwhi)
|
|
|
|
continue;
|
|
|
|
if (rwhi->GetView())
|
|
|
|
rwhi->GetView()->set_current_device_scale_factor(new_scale_factor);
|
2016-08-31 13:25:56 +02:00
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-20 15:51:42 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::ResizeRootLayer(bool force) {
|
2014-11-18 20:29:26 +01:00
|
|
|
SetFrameRate();
|
2015-12-03 21:22:44 +01:00
|
|
|
|
2017-06-23 21:06:37 +02:00
|
|
|
const float orgScaleFactor = current_device_scale_factor_;
|
2015-01-01 17:51:56 +01:00
|
|
|
SetDeviceScaleFactor();
|
2017-06-23 21:06:37 +02:00
|
|
|
const bool scaleFactorDidChange =
|
|
|
|
(orgScaleFactor != current_device_scale_factor_);
|
2014-11-18 20:29:26 +01:00
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
gfx::Size size;
|
|
|
|
if (!IsPopupWidget())
|
|
|
|
size = GetViewBounds().size();
|
|
|
|
else
|
|
|
|
size = popup_position_.size();
|
2014-11-18 20:29:26 +01:00
|
|
|
|
2018-05-20 15:51:42 +02:00
|
|
|
if (!force && !scaleFactorDidChange &&
|
|
|
|
size == GetRootLayer()->bounds().size()) {
|
2014-11-18 20:29:26 +01:00
|
|
|
return;
|
2018-05-20 15:51:42 +02:00
|
|
|
}
|
2014-11-18 20:29:26 +01:00
|
|
|
|
2018-05-31 22:34:44 +02:00
|
|
|
GetRootLayer()->SetBounds(gfx::Rect(size));
|
|
|
|
|
2015-01-01 17:51:56 +01:00
|
|
|
const gfx::Size& size_in_pixels =
|
2017-06-23 21:06:37 +02:00
|
|
|
gfx::ConvertSizeToPixel(current_device_scale_factor_, size);
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2018-11-03 02:15:09 +01:00
|
|
|
local_surface_id_allocator_.GenerateId();
|
2018-11-30 23:21:07 +01:00
|
|
|
local_surface_id_allocation_ =
|
|
|
|
local_surface_id_allocator_.GetCurrentLocalSurfaceIdAllocation();
|
2017-10-20 19:45:20 +02:00
|
|
|
|
2019-07-19 01:30:29 +02:00
|
|
|
if (compositor_) {
|
2019-07-16 22:09:04 +02:00
|
|
|
compositor_local_surface_id_allocator_.GenerateId();
|
2019-07-19 01:30:29 +02:00
|
|
|
compositor_->SetScaleAndSize(current_device_scale_factor_, size_in_pixels,
|
|
|
|
compositor_local_surface_id_allocator_
|
|
|
|
.GetCurrentLocalSurfaceIdAllocation());
|
2018-05-31 22:34:44 +02:00
|
|
|
}
|
2018-03-20 21:15:08 +01:00
|
|
|
|
2018-06-08 18:53:10 +02:00
|
|
|
GetDelegatedFrameHost()->EmbedSurface(
|
2018-11-30 23:21:07 +01:00
|
|
|
local_surface_id_allocation_.local_surface_id(), size,
|
|
|
|
cc::DeadlinePolicy::UseDefaultDeadline());
|
2018-03-20 21:15:08 +01:00
|
|
|
|
|
|
|
// Note that |render_widget_host_| will retrieve resize parameters from the
|
2018-05-17 10:58:21 +02:00
|
|
|
// DelegatedFrameHost, so it must have SynchronizeVisualProperties called
|
|
|
|
// after.
|
2019-02-25 22:17:28 +01:00
|
|
|
if (render_widget_host_)
|
2019-07-16 22:09:04 +02:00
|
|
|
render_widget_host_->SynchronizeVisualProperties();
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2015-08-17 21:48:57 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::CancelWidget() {
|
2014-07-01 00:30:29 +02:00
|
|
|
if (render_widget_host_)
|
|
|
|
render_widget_host_->LostCapture();
|
|
|
|
|
2015-02-04 19:10:14 +01:00
|
|
|
Hide();
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2015-08-17 21:48:57 +02:00
|
|
|
if (IsPopupWidget() && browser_impl_.get()) {
|
2015-01-26 01:57:01 +01:00
|
|
|
CefRefPtr<CefRenderHandler> handler =
|
|
|
|
browser_impl_->client()->GetRenderHandler();
|
2018-09-25 15:40:02 +02:00
|
|
|
CHECK(handler);
|
|
|
|
handler->OnPopupShow(browser_impl_.get(), false);
|
2014-07-01 00:30:29 +02:00
|
|
|
browser_impl_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parent_host_view_) {
|
2015-08-20 21:28:48 +02:00
|
|
|
if (parent_host_view_->popup_host_view_ == this) {
|
2015-08-17 21:48:57 +02:00
|
|
|
parent_host_view_->set_popup_host_view(NULL);
|
2015-08-20 21:28:48 +02:00
|
|
|
} else if (parent_host_view_->child_host_view_ == this) {
|
2015-08-17 21:48:57 +02:00
|
|
|
parent_host_view_->set_child_host_view(NULL);
|
2015-08-20 21:28:48 +02:00
|
|
|
|
|
|
|
// Start rendering the parent view again.
|
|
|
|
parent_host_view_->Show();
|
|
|
|
} else {
|
2015-08-17 21:48:57 +02:00
|
|
|
parent_host_view_->RemoveGuestHostView(this);
|
2015-08-20 21:28:48 +02:00
|
|
|
}
|
2015-06-11 17:00:05 +02:00
|
|
|
parent_host_view_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (render_widget_host_ && !is_destroyed_) {
|
|
|
|
is_destroyed_ = true;
|
2017-06-23 21:06:37 +02:00
|
|
|
|
2018-07-03 02:46:03 +02:00
|
|
|
// Don't delete the RWHI manually while owned by a scoped_ptr in RVHI.
|
|
|
|
// This matches a CHECK() in RenderWidgetHostImpl::Destroy().
|
2017-06-23 21:06:37 +02:00
|
|
|
const bool also_delete = !render_widget_host_->owner_delegate();
|
|
|
|
|
2015-06-11 17:00:05 +02:00
|
|
|
// Results in a call to Destroy().
|
2017-06-23 21:06:37 +02:00
|
|
|
render_widget_host_->ShutdownAndDestroyWidget(also_delete);
|
2015-06-11 17:00:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-27 01:48:19 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::OnScrollOffsetChanged() {
|
|
|
|
if (browser_impl_.get()) {
|
|
|
|
CefRefPtr<CefRenderHandler> handler =
|
|
|
|
browser_impl_->client()->GetRenderHandler();
|
2018-09-25 15:40:02 +02:00
|
|
|
CHECK(handler);
|
|
|
|
handler->OnScrollOffsetChanged(browser_impl_.get(), last_scroll_offset_.x(),
|
|
|
|
last_scroll_offset_.y());
|
2014-09-27 01:48:19 +02:00
|
|
|
}
|
|
|
|
is_scroll_offset_changed_pending_ = false;
|
|
|
|
}
|
2016-10-27 17:02:56 +02:00
|
|
|
|
2017-02-10 23:44:11 +01:00
|
|
|
void CefRenderWidgetHostViewOSR::AddGuestHostView(
|
|
|
|
CefRenderWidgetHostViewOSR* guest_host) {
|
|
|
|
guest_host_views_.insert(guest_host);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::RemoveGuestHostView(
|
|
|
|
CefRenderWidgetHostViewOSR* guest_host) {
|
|
|
|
guest_host_views_.erase(guest_host);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::RegisterGuestViewFrameSwappedCallback(
|
|
|
|
content::RenderWidgetHostViewGuest* guest_host_view) {
|
2018-03-20 21:15:08 +01:00
|
|
|
guest_host_view->RegisterFrameSwappedCallback(base::BindOnce(
|
|
|
|
&CefRenderWidgetHostViewOSR::OnGuestViewFrameSwapped,
|
|
|
|
weak_ptr_factory_.GetWeakPtr(), base::Unretained(guest_host_view)));
|
2017-06-30 22:30:30 +02:00
|
|
|
guest_host_view->set_current_device_scale_factor(
|
|
|
|
current_device_scale_factor_);
|
2017-02-10 23:44:11 +01:00
|
|
|
}
|
|
|
|
|
2016-10-27 17:02:56 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::OnGuestViewFrameSwapped(
|
|
|
|
content::RenderWidgetHostViewGuest* guest_host_view) {
|
2017-06-23 21:06:37 +02:00
|
|
|
InvalidateInternal(gfx::ConvertRectToPixel(current_device_scale_factor_,
|
|
|
|
guest_host_view->GetViewBounds()));
|
2016-10-27 17:02:56 +02:00
|
|
|
|
|
|
|
RegisterGuestViewFrameSwappedCallback(guest_host_view);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::InvalidateInternal(
|
|
|
|
const gfx::Rect& bounds_in_pixels) {
|
2019-07-16 22:09:04 +02:00
|
|
|
if (video_consumer_) {
|
|
|
|
video_consumer_->SizeChanged();
|
2019-11-26 19:26:54 +01:00
|
|
|
} else if (host_display_client_) {
|
2019-07-16 22:09:04 +02:00
|
|
|
OnPaint(bounds_in_pixels, host_display_client_->GetPixelSize(),
|
|
|
|
host_display_client_->GetPixelMemory());
|
2016-10-27 17:02:56 +02:00
|
|
|
}
|
|
|
|
}
|
2016-10-28 18:11:24 +02:00
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::RequestImeCompositionUpdate(
|
|
|
|
bool start_monitoring) {
|
|
|
|
if (!render_widget_host_)
|
|
|
|
return;
|
2017-04-20 21:28:17 +02:00
|
|
|
render_widget_host_->RequestCompositionUpdates(false, start_monitoring);
|
2016-10-28 18:11:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::ImeCompositionRangeChanged(
|
|
|
|
const gfx::Range& range,
|
|
|
|
const std::vector<gfx::Rect>& character_bounds) {
|
|
|
|
if (browser_impl_.get()) {
|
|
|
|
CefRange cef_range(range.start(), range.end());
|
|
|
|
CefRenderHandler::RectList rcList;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < character_bounds.size(); ++i) {
|
|
|
|
rcList.push_back(CefRect(character_bounds[i].x(), character_bounds[i].y(),
|
|
|
|
character_bounds[i].width(),
|
|
|
|
character_bounds[i].height()));
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefRenderHandler> handler =
|
|
|
|
browser_impl_->GetClient()->GetRenderHandler();
|
2018-09-25 15:40:02 +02:00
|
|
|
CHECK(handler);
|
|
|
|
handler->OnImeCompositionRangeChanged(browser_impl_->GetBrowser(),
|
|
|
|
cef_range, rcList);
|
2016-10-28 18:11:24 +02:00
|
|
|
}
|
|
|
|
}
|
2017-03-03 23:37:23 +01:00
|
|
|
|
2017-07-27 01:19:27 +02:00
|
|
|
viz::FrameSinkId CefRenderWidgetHostViewOSR::AllocateFrameSinkId(
|
2017-03-03 23:37:23 +01:00
|
|
|
bool is_guest_view_hack) {
|
|
|
|
// GuestViews have two RenderWidgetHostViews and so we need to make sure
|
|
|
|
// we don't have FrameSinkId collisions.
|
|
|
|
// The FrameSinkId generated here must be unique with FrameSinkId allocated
|
|
|
|
// in ContextFactoryPrivate.
|
|
|
|
content::ImageTransportFactory* factory =
|
|
|
|
content::ImageTransportFactory::GetInstance();
|
|
|
|
return is_guest_view_hack
|
2017-05-17 11:29:28 +02:00
|
|
|
? factory->GetContextFactoryPrivate()->AllocateFrameSinkId()
|
2019-07-16 22:09:04 +02:00
|
|
|
: render_widget_host_->GetFrameSinkId();
|
2017-03-03 23:37:23 +01:00
|
|
|
}
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::UpdateBackgroundColorFromRenderer(
|
|
|
|
SkColor color) {
|
2018-05-21 14:54:08 +02:00
|
|
|
if (color == background_color_)
|
2017-04-20 21:28:17 +02:00
|
|
|
return;
|
|
|
|
background_color_ = color;
|
|
|
|
|
|
|
|
bool opaque = SkColorGetA(color) == SK_AlphaOPAQUE;
|
|
|
|
GetRootLayer()->SetFillsBoundsOpaquely(opaque);
|
|
|
|
GetRootLayer()->SetColor(color);
|
|
|
|
}
|