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>
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
#include "libcef/browser/browser_host_impl.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "libcef/browser/osr/osr_util.h"
|
|
|
|
#include "libcef/browser/osr/software_output_device_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"
|
2015-06-06 00:06:48 +02:00
|
|
|
#include "cc/base/switches.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"
|
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"
|
2014-07-01 00:30:29 +02:00
|
|
|
#include "content/browser/renderer_host/dip_util.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"
|
2017-05-17 11:29:28 +02:00
|
|
|
#include "content/browser/renderer_host/render_widget_host_view_frame_subscriber.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"
|
|
|
|
#include "content/public/browser/browser_thread.h"
|
2014-07-01 00:30:29 +02:00
|
|
|
#include "content/public/browser/context_factory.h"
|
|
|
|
#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"
|
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 {
|
|
|
|
|
|
|
|
const float kDefaultScaleFactor = 1.0;
|
|
|
|
|
|
|
|
// The maximum number of retry counts if frame capture fails.
|
|
|
|
const int kFrameRetryLimit = 2;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2015-01-01 17:51:56 +01:00
|
|
|
// Used for managing copy requests when GPU compositing is enabled. Based on
|
|
|
|
// RendererOverridesHandler::InnerSwapCompositorFrame and
|
|
|
|
// DelegatedFrameHost::CopyFromCompositingSurface.
|
|
|
|
class CefCopyFrameGenerator {
|
|
|
|
public:
|
2016-11-23 18:26:50 +01:00
|
|
|
CefCopyFrameGenerator(int frame_rate_threshold_us,
|
2015-01-01 17:51:56 +01:00
|
|
|
CefRenderWidgetHostViewOSR* view)
|
2016-11-23 18:26:50 +01:00
|
|
|
: view_(view),
|
2017-05-17 11:29:28 +02:00
|
|
|
frame_retry_count_(0),
|
2016-11-23 18:26:50 +01:00
|
|
|
next_frame_time_(base::TimeTicks::Now()),
|
|
|
|
frame_duration_(
|
|
|
|
base::TimeDelta::FromMicroseconds(frame_rate_threshold_us)),
|
2017-05-17 11:29:28 +02:00
|
|
|
weak_ptr_factory_(this) {}
|
|
|
|
|
2016-11-23 18:26:50 +01:00
|
|
|
void GenerateCopyFrame(const gfx::Rect& damage_rect) {
|
2015-01-01 17:51:56 +01:00
|
|
|
if (!view_->render_widget_host())
|
|
|
|
return;
|
|
|
|
// The below code is similar in functionality to
|
|
|
|
// DelegatedFrameHost::CopyFromCompositingSurface but we reuse the same
|
|
|
|
// SkBitmap in the GPU codepath and avoid scaling where possible.
|
2016-11-23 18:26:50 +01:00
|
|
|
// Let the compositor copy into a new SkBitmap
|
2017-09-06 23:40:58 +02:00
|
|
|
std::unique_ptr<viz::CopyOutputRequest> request =
|
2017-10-20 19:45:20 +02:00
|
|
|
std::make_unique<viz::CopyOutputRequest>(
|
|
|
|
viz::CopyOutputRequest::ResultFormat::RGBA_BITMAP,
|
|
|
|
base::Bind(
|
|
|
|
&CefCopyFrameGenerator::CopyFromCompositingSurfaceHasResult,
|
|
|
|
weak_ptr_factory_.GetWeakPtr(), damage_rect));
|
2015-01-01 17:51:56 +01:00
|
|
|
|
|
|
|
request->set_area(gfx::Rect(view_->GetPhysicalBackingSize()));
|
2016-07-21 23:21:32 +02:00
|
|
|
view_->GetRootLayer()->RequestCopyOfOutput(std::move(request));
|
2015-01-01 17:51:56 +01:00
|
|
|
}
|
|
|
|
|
2016-11-23 18:26:50 +01:00
|
|
|
void set_frame_rate_threshold_us(int frame_rate_threshold_us) {
|
|
|
|
frame_duration_ =
|
|
|
|
base::TimeDelta::FromMicroseconds(frame_rate_threshold_us);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-01-01 17:51:56 +01:00
|
|
|
void CopyFromCompositingSurfaceHasResult(
|
|
|
|
const gfx::Rect& damage_rect,
|
2017-09-06 23:40:58 +02:00
|
|
|
std::unique_ptr<viz::CopyOutputResult> result) {
|
2015-01-01 17:51:56 +01:00
|
|
|
if (result->IsEmpty() || result->size().IsEmpty() ||
|
|
|
|
!view_->render_widget_host()) {
|
|
|
|
OnCopyFrameCaptureFailure(damage_rect);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-20 19:45:20 +02:00
|
|
|
std::unique_ptr<SkBitmap> source =
|
|
|
|
std::make_unique<SkBitmap>(result->AsSkBitmap());
|
2015-01-01 17:51:56 +01:00
|
|
|
DCHECK(source);
|
2017-10-20 19:45:20 +02:00
|
|
|
|
2015-01-01 17:51:56 +01:00
|
|
|
if (source) {
|
2016-11-23 18:26:50 +01:00
|
|
|
std::shared_ptr<SkBitmap> bitmap(std::move(source));
|
|
|
|
|
|
|
|
base::TimeTicks now = base::TimeTicks::Now();
|
|
|
|
base::TimeDelta next_frame_in = next_frame_time_ - now;
|
|
|
|
if (next_frame_in > frame_duration_ / 4) {
|
|
|
|
next_frame_time_ += frame_duration_;
|
|
|
|
content::BrowserThread::PostDelayedTask(
|
|
|
|
CEF_UIT, FROM_HERE,
|
|
|
|
base::Bind(&CefCopyFrameGenerator::OnCopyFrameCaptureSuccess,
|
|
|
|
weak_ptr_factory_.GetWeakPtr(), damage_rect, bitmap),
|
|
|
|
next_frame_in);
|
|
|
|
} else {
|
|
|
|
next_frame_time_ = now + frame_duration_;
|
|
|
|
OnCopyFrameCaptureSuccess(damage_rect, bitmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset the frame retry count on successful frame generation.
|
|
|
|
frame_retry_count_ = 0;
|
2015-01-01 17:51:56 +01:00
|
|
|
} else {
|
|
|
|
OnCopyFrameCaptureFailure(damage_rect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void OnCopyFrameCaptureFailure(const gfx::Rect& damage_rect) {
|
2015-01-01 17:51:56 +01:00
|
|
|
const bool force_frame = (++frame_retry_count_ <= kFrameRetryLimit);
|
2016-11-23 18:26:50 +01:00
|
|
|
if (force_frame) {
|
|
|
|
// Retry with the same |damage_rect|.
|
|
|
|
CEF_POST_TASK(CEF_UIT,
|
|
|
|
base::Bind(&CefCopyFrameGenerator::GenerateCopyFrame,
|
|
|
|
weak_ptr_factory_.GetWeakPtr(), damage_rect));
|
|
|
|
}
|
2015-01-01 17:51:56 +01:00
|
|
|
}
|
|
|
|
|
2017-05-31 17:33:30 +02:00
|
|
|
void OnCopyFrameCaptureSuccess(const gfx::Rect& damage_rect,
|
2016-11-23 18:26:50 +01:00
|
|
|
std::shared_ptr<SkBitmap> bitmap) {
|
|
|
|
view_->OnPaint(damage_rect, bitmap->width(), bitmap->height(),
|
|
|
|
bitmap->getPixels());
|
2015-01-01 17:51:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRenderWidgetHostViewOSR* view_;
|
|
|
|
int frame_retry_count_;
|
2016-11-23 18:26:50 +01:00
|
|
|
base::TimeTicks next_frame_time_;
|
|
|
|
base::TimeDelta frame_duration_;
|
2015-01-01 17:51:56 +01:00
|
|
|
|
|
|
|
base::WeakPtrFactory<CefCopyFrameGenerator> weak_ptr_factory_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefCopyFrameGenerator);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Used to control the VSync rate in subprocesses when BeginFrame scheduling is
|
|
|
|
// enabled.
|
2017-09-06 23:40:58 +02:00
|
|
|
class CefBeginFrameTimer : public viz::DelayBasedTimeSourceClient {
|
2015-01-01 17:51:56 +01:00
|
|
|
public:
|
2016-11-23 18:26:50 +01:00
|
|
|
CefBeginFrameTimer(int frame_rate_threshold_us, const base::Closure& callback)
|
2015-01-01 17:51:56 +01:00
|
|
|
: callback_(callback) {
|
2017-09-06 23:40:58 +02:00
|
|
|
time_source_.reset(new viz::DelayBasedTimeSource(
|
2016-07-21 23:21:32 +02:00
|
|
|
content::BrowserThread::GetTaskRunnerForThread(CEF_UIT).get()));
|
2016-06-21 00:59:23 +02:00
|
|
|
time_source_->SetTimebaseAndInterval(
|
|
|
|
base::TimeTicks(),
|
2016-11-23 18:26:50 +01:00
|
|
|
base::TimeDelta::FromMicroseconds(frame_rate_threshold_us));
|
2015-01-01 17:51:56 +01:00
|
|
|
time_source_->SetClient(this);
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void SetActive(bool active) { time_source_->SetActive(active); }
|
2015-01-01 17:51:56 +01:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
bool IsActive() const { return time_source_->Active(); }
|
2015-01-01 17:51:56 +01:00
|
|
|
|
2016-11-23 18:26:50 +01:00
|
|
|
void SetFrameRateThresholdUs(int frame_rate_threshold_us) {
|
2015-05-13 17:43:50 +02:00
|
|
|
time_source_->SetTimebaseAndInterval(
|
2015-07-24 02:06:56 +02:00
|
|
|
base::TimeTicks::Now(),
|
2016-11-23 18:26:50 +01:00
|
|
|
base::TimeDelta::FromMicroseconds(frame_rate_threshold_us));
|
2015-05-13 17:43:50 +02:00
|
|
|
}
|
|
|
|
|
2015-01-01 17:51:56 +01:00
|
|
|
private:
|
|
|
|
// cc::TimerSourceClient implementation.
|
2017-05-17 11:29:28 +02:00
|
|
|
void OnTimerTick() override { callback_.Run(); }
|
2015-01-01 17:51:56 +01:00
|
|
|
|
|
|
|
const base::Closure callback_;
|
2017-09-06 23:40:58 +02:00
|
|
|
std::unique_ptr<viz::DelayBasedTimeSource> time_source_;
|
2015-01-01 17:51:56 +01:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefBeginFrameTimer);
|
|
|
|
};
|
|
|
|
|
|
|
|
CefRenderWidgetHostViewOSR::CefRenderWidgetHostViewOSR(
|
2017-04-20 21:28:17 +02:00
|
|
|
SkColor background_color,
|
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)
|
2017-04-20 21:28:17 +02:00
|
|
|
: background_color_(background_color),
|
2016-11-23 18:26:50 +01:00
|
|
|
frame_rate_threshold_us_(0),
|
2016-07-06 21:34:09 +02:00
|
|
|
#if !defined(OS_MACOSX)
|
2015-01-01 17:51:56 +01:00
|
|
|
compositor_widget_(gfx::kNullAcceleratedWidget),
|
2016-07-06 21:34:09 +02:00
|
|
|
#endif
|
2015-01-01 17:51:56 +01:00
|
|
|
software_output_device_(NULL),
|
2014-07-01 00:30:29 +02:00
|
|
|
hold_resize_(false),
|
|
|
|
pending_resize_(false),
|
|
|
|
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),
|
2015-12-03 20:48:26 +01:00
|
|
|
is_showing_(!render_widget_host_->is_hidden()),
|
2014-07-01 00:30:29 +02:00
|
|
|
is_destroyed_(false),
|
2014-09-27 01:48:19 +02:00
|
|
|
is_scroll_offset_changed_pending_(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_));
|
|
|
|
}
|
|
|
|
|
2017-10-20 19:45:20 +02:00
|
|
|
local_surface_id_ = local_surface_id_allocator_.GenerateId();
|
|
|
|
|
2016-07-06 21:34:09 +02:00
|
|
|
#if !defined(OS_MACOSX)
|
2016-10-21 21:52:29 +02:00
|
|
|
delegated_frame_host_ = base::MakeUnique<content::DelegatedFrameHost>(
|
2017-10-20 19:45:20 +02:00
|
|
|
AllocateFrameSinkId(is_guest_view_hack), this,
|
|
|
|
false /* enable_surface_synchronization */);
|
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
|
|
|
#endif
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2017-03-03 23:37:23 +01:00
|
|
|
PlatformCreateCompositorWidget(is_guest_view_hack);
|
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_);
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
#if !defined(OS_MACOSX)
|
2017-03-03 23:37:23 +01:00
|
|
|
// On macOS the ui::Compositor is created/owned by the platform view.
|
|
|
|
content::ImageTransportFactory* factory =
|
|
|
|
content::ImageTransportFactory::GetInstance();
|
|
|
|
ui::ContextFactoryPrivate* context_factory_private =
|
|
|
|
factory->GetContextFactoryPrivate();
|
2014-07-01 00:30:29 +02:00
|
|
|
compositor_.reset(
|
2017-01-23 18:36:54 +01:00
|
|
|
new ui::Compositor(context_factory_private->AllocateFrameSinkId(),
|
|
|
|
content::GetContextFactory(), context_factory_private,
|
2017-07-27 01:19:27 +02:00
|
|
|
base::ThreadTaskRunnerHandle::Get(),
|
2017-09-06 23:40:58 +02:00
|
|
|
false /* enable_surface_synchronization */,
|
|
|
|
false /* enable_pixel_canvas */));
|
2015-11-10 21:18:16 +01:00
|
|
|
compositor_->SetAcceleratedWidget(compositor_widget_);
|
2015-01-01 17:51:56 +01:00
|
|
|
compositor_->SetDelegate(this);
|
2014-07-01 00:30:29 +02:00
|
|
|
compositor_->SetRootLayer(root_layer_.get());
|
2016-07-06 21:34:09 +02:00
|
|
|
#endif
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2014-11-18 20:29:26 +01:00
|
|
|
if (browser_impl_.get())
|
2014-07-01 00:30:29 +02:00
|
|
|
ResizeRootLayer();
|
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);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRenderWidgetHostViewOSR::~CefRenderWidgetHostViewOSR() {
|
2016-07-06 21:34:09 +02:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
if (is_showing_)
|
|
|
|
browser_compositor_->SetRenderWidgetHostIsHidden(true);
|
|
|
|
#else
|
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.
|
|
|
|
if (is_showing_)
|
|
|
|
delegated_frame_host_->WasHidden();
|
2015-02-04 19:10:14 +01:00
|
|
|
delegated_frame_host_->ResetCompositor();
|
2016-07-06 21:34:09 +02:00
|
|
|
#endif
|
2014-09-04 19:53:40 +02:00
|
|
|
|
|
|
|
PlatformDestroyCompositorWidget();
|
|
|
|
|
2015-01-01 17:51:56 +01:00
|
|
|
if (copy_frame_generator_.get())
|
|
|
|
copy_frame_generator_.reset(NULL);
|
|
|
|
|
2016-07-06 21:34:09 +02:00
|
|
|
#if !defined(OS_MACOSX)
|
2014-07-01 00:30:29 +02:00
|
|
|
delegated_frame_host_.reset(NULL);
|
|
|
|
compositor_.reset(NULL);
|
|
|
|
root_layer_.reset(NULL);
|
2016-07-06 21:34:09 +02:00
|
|
|
#endif
|
2015-08-17 21:48:57 +02:00
|
|
|
|
|
|
|
DCHECK(parent_host_view_ == NULL);
|
|
|
|
DCHECK(popup_host_view_ == NULL);
|
|
|
|
DCHECK(child_host_view_ == NULL);
|
|
|
|
DCHECK(guest_host_views_.empty());
|
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();
|
|
|
|
|
2015-06-11 17:00:05 +02:00
|
|
|
ResizeRootLayer();
|
|
|
|
Show();
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
content::RenderWidgetHost* CefRenderWidgetHostViewOSR::GetRenderWidgetHost()
|
|
|
|
const {
|
2014-07-01 00:30:29 +02:00
|
|
|
return render_widget_host_;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-09-27 01:48:19 +02:00
|
|
|
gfx::Vector2dF CefRenderWidgetHostViewOSR::GetLastScrollOffset() const {
|
|
|
|
return last_scroll_offset_;
|
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
gfx::NativeView CefRenderWidgetHostViewOSR::GetNativeView() const {
|
|
|
|
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
|
|
|
|
|
|
|
bool CefRenderWidgetHostViewOSR::HasFocus() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefRenderWidgetHostViewOSR::IsSurfaceAvailableForCopy() const {
|
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
|
|
|
|
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
browser_compositor_->SetRenderWidgetHostIsHidden(false);
|
|
|
|
#else
|
2015-02-04 19:10:14 +01:00
|
|
|
delegated_frame_host_->SetCompositor(compositor_.get());
|
|
|
|
delegated_frame_host_->WasShown(ui::LatencyInfo());
|
2016-07-06 21:34:09 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (render_widget_host_)
|
|
|
|
render_widget_host_->WasShown(ui::LatencyInfo());
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::Hide() {
|
2015-02-04 19:10:14 +01:00
|
|
|
if (!is_showing_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (browser_impl_.get())
|
|
|
|
browser_impl_->CancelContextMenu();
|
|
|
|
|
|
|
|
if (render_widget_host_)
|
|
|
|
render_widget_host_->WasHidden();
|
2016-07-06 21:34:09 +02:00
|
|
|
|
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
browser_compositor_->SetRenderWidgetHostIsHidden(true);
|
|
|
|
#else
|
|
|
|
GetDelegatedFrameHost()->WasHidden();
|
|
|
|
GetDelegatedFrameHost()->ResetCompositor();
|
|
|
|
#endif
|
|
|
|
|
2015-02-04 19:10:14 +01:00
|
|
|
is_showing_ = false;
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefRenderWidgetHostViewOSR::IsShowing() {
|
|
|
|
return is_showing_;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Rect CefRenderWidgetHostViewOSR::GetViewBounds() const {
|
|
|
|
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();
|
|
|
|
if (handler.get())
|
|
|
|
handler->GetViewRect(browser_impl_.get(), rc);
|
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);
|
|
|
|
if (render_widget_host_) {
|
2017-05-17 11:29:28 +02:00
|
|
|
render_widget_host_->SetBackgroundOpaque(SkColorGetA(color) ==
|
|
|
|
SK_AlphaOPAQUE);
|
2017-04-20 21:28:17 +02:00
|
|
|
}
|
|
|
|
}
|
2015-12-03 21:15:32 +01:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
SkColor CefRenderWidgetHostViewOSR::background_color() const {
|
|
|
|
return background_color_;
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefRenderWidgetHostViewOSR::LockMouse() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::UnlockMouse() {}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
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) {
|
2017-04-20 21:28:17 +02:00
|
|
|
renderer_compositor_frame_sink_ = renderer_compositor_frame_sink;
|
|
|
|
if (GetDelegatedFrameHost()) {
|
|
|
|
GetDelegatedFrameHost()->DidCreateNewRendererCompositorFrameSink(
|
|
|
|
renderer_compositor_frame_sink_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::SubmitCompositorFrame(
|
2017-07-27 01:19:27 +02:00
|
|
|
const viz::LocalSurfaceId& local_surface_id,
|
2017-10-20 19:45:20 +02:00
|
|
|
viz::CompositorFrame frame) {
|
2014-07-01 00:30:29 +02:00
|
|
|
TRACE_EVENT0("libcef", "CefRenderWidgetHostViewOSR::OnSwapCompositorFrame");
|
2014-09-27 01:48:19 +02:00
|
|
|
|
2016-07-06 21:34:09 +02:00
|
|
|
if (frame.metadata.root_scroll_offset != last_scroll_offset_) {
|
|
|
|
last_scroll_offset_ = frame.metadata.root_scroll_offset;
|
2014-09-27 01:48:19 +02:00
|
|
|
|
|
|
|
if (!is_scroll_offset_changed_pending_) {
|
|
|
|
// Send the notification asnychronously.
|
2017-05-17 11:29:28 +02:00
|
|
|
CEF_POST_TASK(
|
|
|
|
CEF_UIT,
|
2014-09-27 01:48:19 +02:00
|
|
|
base::Bind(&CefRenderWidgetHostViewOSR::OnScrollOffsetChanged,
|
|
|
|
weak_ptr_factory_.GetWeakPtr()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-23 18:36:54 +01:00
|
|
|
if (!frame.render_pass_list.empty()) {
|
2015-01-01 17:51:56 +01:00
|
|
|
if (software_output_device_) {
|
|
|
|
if (!begin_frame_timer_.get()) {
|
|
|
|
// If BeginFrame scheduling is enabled SoftwareOutputDevice activity
|
|
|
|
// will be controlled via OnSetNeedsBeginFrames. Otherwise, activate
|
|
|
|
// the SoftwareOutputDevice now (when the first frame is generated).
|
|
|
|
software_output_device_->SetActive(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The compositor will draw directly to the SoftwareOutputDevice which
|
|
|
|
// then calls OnPaint.
|
2017-04-20 21:28:17 +02:00
|
|
|
// We would normally call BrowserCompositorMac::SubmitCompositorFrame on
|
2017-03-03 23:37:23 +01:00
|
|
|
// macOS, however it contains compositor resize logic that we don't want.
|
2017-02-06 22:24:25 +01:00
|
|
|
// Consequently we instead call the SwapDelegatedFrame method directly.
|
2017-04-20 21:28:17 +02:00
|
|
|
GetDelegatedFrameHost()->SubmitCompositorFrame(local_surface_id,
|
|
|
|
std::move(frame));
|
2017-05-17 11:29:28 +02:00
|
|
|
} else {
|
2015-01-01 17:51:56 +01:00
|
|
|
if (!copy_frame_generator_.get()) {
|
|
|
|
copy_frame_generator_.reset(
|
2016-11-23 18:26:50 +01:00
|
|
|
new CefCopyFrameGenerator(frame_rate_threshold_us_, this));
|
2015-01-01 17:51:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Determine the damage rectangle for the current frame. This is the same
|
|
|
|
// calculation that SwapDelegatedFrame uses.
|
2017-10-20 19:45:20 +02:00
|
|
|
viz::RenderPass* root_pass = frame.render_pass_list.back().get();
|
2015-01-01 17:51:56 +01:00
|
|
|
gfx::Size frame_size = root_pass->output_rect.size();
|
2015-10-09 17:23:12 +02:00
|
|
|
gfx::Rect damage_rect =
|
|
|
|
gfx::ToEnclosingRect(gfx::RectF(root_pass->damage_rect));
|
2015-01-01 17:51:56 +01:00
|
|
|
damage_rect.Intersect(gfx::Rect(frame_size));
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
// We would normally call BrowserCompositorMac::SubmitCompositorFrame on
|
2017-03-03 23:37:23 +01:00
|
|
|
// macOS, however it contains compositor resize logic that we don't want.
|
2017-02-06 22:24:25 +01:00
|
|
|
// Consequently we instead call the SwapDelegatedFrame method directly.
|
2017-04-20 21:28:17 +02:00
|
|
|
GetDelegatedFrameHost()->SubmitCompositorFrame(local_surface_id,
|
|
|
|
std::move(frame));
|
2015-01-01 17:51:56 +01:00
|
|
|
|
|
|
|
// Request a copy of the last compositor frame which will eventually call
|
|
|
|
// OnPaint asynchronously.
|
2016-11-23 18:26:50 +01:00
|
|
|
copy_frame_generator_->GenerateCopyFrame(damage_rect);
|
2015-01-01 17:51:56 +01:00
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-09 17:23:12 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::ClearCompositorFrame() {
|
2016-07-06 21:34:09 +02:00
|
|
|
GetDelegatedFrameHost()->ClearDelegatedFrame();
|
2015-10-09 17:23:12 +02:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
if (handler.get())
|
|
|
|
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
|
|
|
|
|
|
|
ResizeRootLayer();
|
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) {
|
|
|
|
TRACE_EVENT0("libcef", "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();
|
|
|
|
if (!handler.get())
|
|
|
|
return;
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
content::CursorInfo cursor_info;
|
2014-11-24 22:56:12 +01:00
|
|
|
cursor.GetCursorInfo(&cursor_info);
|
|
|
|
|
|
|
|
const cef_cursor_type_t cursor_type =
|
|
|
|
static_cast<cef_cursor_type_t>(cursor_info.type);
|
|
|
|
CefCursorInfo custom_cursor_info;
|
|
|
|
if (cursor.IsCustom()) {
|
|
|
|
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)
|
|
|
|
content::WebCursor web_cursor = cursor;
|
|
|
|
|
|
|
|
ui::PlatformCursor platform_cursor;
|
|
|
|
if (web_cursor.IsCustom()) {
|
|
|
|
// |web_cursor| owns the resulting |platform_cursor|.
|
|
|
|
platform_cursor = web_cursor.GetPlatformCursor();
|
|
|
|
} 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|.
|
|
|
|
content::WebCursor web_cursor = cursor;
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::SetIsLoading(bool is_loading) {}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::RenderProcessGone(
|
|
|
|
base::TerminationStatus status,
|
|
|
|
int error_code) {
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Size CefRenderWidgetHostViewOSR::GetRequestedRendererSize() const {
|
2016-07-06 21:34:09 +02:00
|
|
|
return GetDelegatedFrameHost()->GetRequestedRendererSize();
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Size CefRenderWidgetHostViewOSR::GetPhysicalBackingSize() const {
|
2017-06-23 21:06:37 +02:00
|
|
|
return gfx::ConvertSizeToPixel(current_device_scale_factor_,
|
|
|
|
GetRequestedRendererSize());
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2017-03-03 23:37:23 +01:00
|
|
|
void CefRenderWidgetHostViewOSR::CopyFromSurface(
|
2014-07-01 00:30:29 +02:00
|
|
|
const gfx::Rect& src_subrect,
|
|
|
|
const gfx::Size& dst_size,
|
2015-10-09 17:23:12 +02:00
|
|
|
const content::ReadbackRequestCallback& callback,
|
2014-09-04 19:53:40 +02:00
|
|
|
const SkColorType color_type) {
|
2017-05-17 11:29:28 +02:00
|
|
|
GetDelegatedFrameHost()->CopyFromCompositingSurface(src_subrect, dst_size,
|
|
|
|
callback, color_type);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2017-03-03 23:37:23 +01:00
|
|
|
void CefRenderWidgetHostViewOSR::CopyFromSurfaceToVideoFrame(
|
2014-07-01 00:30:29 +02:00
|
|
|
const gfx::Rect& src_subrect,
|
2017-03-03 23:37:23 +01:00
|
|
|
scoped_refptr<media::VideoFrame> target,
|
2015-12-09 17:10:16 +01:00
|
|
|
const base::Callback<void(const gfx::Rect&, bool)>& callback) {
|
2016-07-06 21:34:09 +02:00
|
|
|
GetDelegatedFrameHost()->CopyFromCompositingSurfaceToVideoFrame(
|
2014-07-01 00:30:29 +02:00
|
|
|
src_subrect, target, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::BeginFrameSubscription(
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<content::RenderWidgetHostViewFrameSubscriber> subscriber) {
|
2016-07-06 21:34:09 +02:00
|
|
|
GetDelegatedFrameHost()->BeginFrameSubscription(std::move(subscriber));
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::EndFrameSubscription() {
|
2016-07-06 21:34:09 +02:00
|
|
|
GetDelegatedFrameHost()->EndFrameSubscription();
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefRenderWidgetHostViewOSR::HasAcceleratedSurface(
|
|
|
|
const gfx::Size& desired_size) {
|
|
|
|
// CEF doesn't use GetBackingStore for accelerated pages, so it doesn't
|
|
|
|
// matter what is returned here as GetBackingStore is the only caller of this
|
|
|
|
// method.
|
|
|
|
NOTREACHED();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
if (handler.get() && 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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-10-10 19:54:35 +02:00
|
|
|
#if defined(TOOLKIT_VIEWS) || defined(USE_AURA)
|
|
|
|
void CefRenderWidgetHostViewOSR::ShowDisambiguationPopup(
|
|
|
|
const gfx::Rect& rect_pixels,
|
2017-05-17 11:29:28 +02:00
|
|
|
const SkBitmap& zoomed_bitmap) {}
|
2014-10-10 19:54:35 +02:00
|
|
|
#endif
|
|
|
|
|
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) {
|
|
|
|
TRACE_EVENT0("libcef", "CefRenderWidgetHostViewOSR::ImeSetComposition");
|
|
|
|
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,
|
|
|
|
line.color, line.thick ? true : false, line.background_color));
|
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) {
|
|
|
|
TRACE_EVENT0("libcef", "CefRenderWidgetHostViewOSR::ImeCommitText");
|
|
|
|
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) {
|
|
|
|
TRACE_EVENT0("libcef", "CefRenderWidgetHostViewOSR::ImeFinishComposingText");
|
|
|
|
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() {
|
|
|
|
TRACE_EVENT0("libcef", "CefRenderWidgetHostViewOSR::ImeCancelComposition");
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-08-31 13:25:56 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::SetNeedsBeginFrames(bool enabled) {
|
2015-08-17 21:48:57 +02:00
|
|
|
SetFrameRate();
|
|
|
|
|
2015-01-01 17:51:56 +01:00
|
|
|
// Start/stop the timer that sends BeginFrame requests.
|
|
|
|
begin_frame_timer_->SetActive(enabled);
|
|
|
|
if (software_output_device_) {
|
|
|
|
// When the SoftwareOutputDevice is active it will call OnPaint for each
|
|
|
|
// frame. If the SoftwareOutputDevice is deactivated while an invalidation
|
|
|
|
// region is pending it will call OnPaint immediately.
|
|
|
|
software_output_device_->SetActive(enabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-30 22:30:30 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::ProcessKeyboardEvent(
|
|
|
|
const content::NativeWebKeyboardEvent& event,
|
|
|
|
const ui::LatencyInfo& latency) {
|
|
|
|
render_widget_host_->ForwardKeyboardEventWithLatencyInfo(event, latency);
|
|
|
|
}
|
|
|
|
|
2017-06-23 21:06:37 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::ProcessMouseEvent(
|
|
|
|
const blink::WebMouseEvent& event,
|
|
|
|
const ui::LatencyInfo& latency) {
|
|
|
|
render_widget_host_->ForwardMouseEventWithLatencyInfo(event, latency);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::ProcessMouseWheelEvent(
|
|
|
|
const blink::WebMouseWheelEvent& event,
|
|
|
|
const ui::LatencyInfo& latency) {
|
|
|
|
render_widget_host_->ForwardWheelEventWithLatencyInfo(event, latency);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::ProcessTouchEvent(
|
|
|
|
const blink::WebTouchEvent& event,
|
|
|
|
const ui::LatencyInfo& latency) {
|
|
|
|
render_widget_host_->ForwardTouchEventWithLatencyInfo(event, latency);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::ProcessGestureEvent(
|
|
|
|
const blink::WebGestureEvent& event,
|
|
|
|
const ui::LatencyInfo& latency) {
|
|
|
|
render_widget_host_->ForwardGestureEventWithLatencyInfo(event, latency);
|
|
|
|
}
|
|
|
|
|
2017-03-03 23:37:23 +01:00
|
|
|
bool CefRenderWidgetHostViewOSR::TransformPointToLocalCoordSpace(
|
|
|
|
const gfx::Point& point,
|
2017-07-27 01:19:27 +02:00
|
|
|
const viz::SurfaceId& original_surface,
|
2017-03-03 23:37:23 +01:00
|
|
|
gfx::Point* transformed_point) {
|
|
|
|
// Transformations use physical pixels rather than DIP, so conversion
|
|
|
|
// is necessary.
|
2017-06-23 21:06:37 +02:00
|
|
|
gfx::Point point_in_pixels =
|
|
|
|
gfx::ConvertPointToPixel(current_device_scale_factor_, point);
|
2017-03-03 23:37:23 +01:00
|
|
|
if (!GetDelegatedFrameHost()->TransformPointToLocalCoordSpace(
|
|
|
|
point_in_pixels, original_surface, transformed_point)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*transformed_point =
|
2017-06-23 21:06:37 +02:00
|
|
|
gfx::ConvertPointToDIP(current_device_scale_factor_, *transformed_point);
|
2017-03-03 23:37:23 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefRenderWidgetHostViewOSR::TransformPointToCoordSpaceForView(
|
|
|
|
const gfx::Point& point,
|
|
|
|
RenderWidgetHostViewBase* target_view,
|
|
|
|
gfx::Point* transformed_point) {
|
|
|
|
if (target_view == this) {
|
|
|
|
*transformed_point = point;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// In TransformPointToLocalCoordSpace() there is a Point-to-Pixel conversion,
|
|
|
|
// but it is not necessary here because the final target view is responsible
|
|
|
|
// for converting before computing the final transform.
|
|
|
|
return GetDelegatedFrameHost()->TransformPointToCoordSpaceForView(
|
|
|
|
point, target_view, transformed_point);
|
|
|
|
}
|
|
|
|
|
2017-10-20 19:45:20 +02:00
|
|
|
std::unique_ptr<viz::SoftwareOutputDevice>
|
2015-01-01 17:51:56 +01:00
|
|
|
CefRenderWidgetHostViewOSR::CreateSoftwareOutputDevice(
|
|
|
|
ui::Compositor* compositor) {
|
2016-07-06 21:34:09 +02:00
|
|
|
DCHECK_EQ(GetCompositor(), compositor);
|
2015-01-01 17:51:56 +01:00
|
|
|
DCHECK(!copy_frame_generator_);
|
|
|
|
DCHECK(!software_output_device_);
|
|
|
|
software_output_device_ = new CefSoftwareOutputDeviceOSR(
|
2017-04-20 21:28:17 +02:00
|
|
|
compositor, background_color() == SK_ColorTRANSPARENT,
|
2015-01-01 17:51:56 +01:00
|
|
|
base::Bind(&CefRenderWidgetHostViewOSR::OnPaint,
|
|
|
|
weak_ptr_factory_.GetWeakPtr()));
|
2016-04-27 22:38:52 +02:00
|
|
|
return base::WrapUnique(software_output_device_);
|
2015-01-01 17:51:56 +01:00
|
|
|
}
|
|
|
|
|
2016-07-21 23:21:32 +02:00
|
|
|
#if !defined(OS_MACOSX)
|
2016-06-21 00:59:23 +02:00
|
|
|
|
2015-02-04 19:10:14 +01:00
|
|
|
ui::Layer* CefRenderWidgetHostViewOSR::DelegatedFrameHostGetLayer() const {
|
2016-07-06 21:34:09 +02:00
|
|
|
return GetRootLayer();
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2015-02-04 19:10:14 +01:00
|
|
|
bool CefRenderWidgetHostViewOSR::DelegatedFrameHostIsVisible() const {
|
|
|
|
return !render_widget_host_->is_hidden();
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2016-05-25 01:35:43 +02:00
|
|
|
SkColor CefRenderWidgetHostViewOSR::DelegatedFrameHostGetGutterColor(
|
|
|
|
SkColor color) const {
|
|
|
|
// 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 (render_widget_host_->delegate() &&
|
2016-06-21 00:59:23 +02:00
|
|
|
render_widget_host_->delegate()->IsFullscreenForCurrentTab()) {
|
2016-05-25 01:35:43 +02:00
|
|
|
return SK_ColorBLACK;
|
|
|
|
}
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
gfx::Size CefRenderWidgetHostViewOSR::DelegatedFrameHostDesiredSizeInDIP()
|
|
|
|
const {
|
2016-07-06 21:34:09 +02:00
|
|
|
return GetRootLayer()->bounds().size();
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2015-02-04 19:10:14 +01:00
|
|
|
bool CefRenderWidgetHostViewOSR::DelegatedFrameCanCreateResizeLock() const {
|
|
|
|
return !render_widget_host_->auto_resize_enabled();
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
std::unique_ptr<content::CompositorResizeLock>
|
|
|
|
CefRenderWidgetHostViewOSR::DelegatedFrameHostCreateResizeLock() {
|
|
|
|
HoldResize();
|
2015-02-04 19:10:14 +01:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
const gfx::Size& desired_size = GetRootLayer()->bounds().size();
|
|
|
|
return base::MakeUnique<content::CompositorResizeLock>(this, desired_size);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2017-10-20 19:45:20 +02:00
|
|
|
viz::LocalSurfaceId CefRenderWidgetHostViewOSR::GetLocalSurfaceId() const {
|
|
|
|
return local_surface_id_;
|
|
|
|
}
|
|
|
|
|
2017-07-27 01:19:27 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::OnBeginFrame() {
|
2016-05-25 01:35:43 +02:00
|
|
|
// TODO(cef): Maybe we can use this method in combination with
|
|
|
|
// OnSetNeedsBeginFrames() instead of using CefBeginFrameTimer.
|
|
|
|
// See https://codereview.chromium.org/1841083007.
|
|
|
|
}
|
|
|
|
|
2016-07-21 23:21:32 +02:00
|
|
|
bool CefRenderWidgetHostViewOSR::IsAutoResizeEnabled() const {
|
|
|
|
return render_widget_host_->auto_resize_enabled();
|
|
|
|
}
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
std::unique_ptr<ui::CompositorLock>
|
|
|
|
CefRenderWidgetHostViewOSR::GetCompositorLock(
|
|
|
|
ui::CompositorLockClient* client) {
|
|
|
|
return GetCompositor()->GetCompositorLock(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::CompositorResizeLockEnded() {
|
|
|
|
ReleaseResize();
|
|
|
|
}
|
|
|
|
|
2016-07-21 23:21:32 +02:00
|
|
|
#endif // !defined(OS_MACOSX)
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
bool CefRenderWidgetHostViewOSR::InstallTransparency() {
|
2017-04-20 21:28:17 +02:00
|
|
|
if (background_color() == SK_ColorTRANSPARENT) {
|
2017-10-20 19:45:20 +02:00
|
|
|
SetBackgroundColor(background_color());
|
2016-07-06 21:34:09 +02:00
|
|
|
#if defined(OS_MACOSX)
|
2017-10-20 19:45:20 +02:00
|
|
|
browser_compositor_->SetBackgroundColor(background_color());
|
2016-07-06 21:34:09 +02:00
|
|
|
#else
|
2017-10-20 19:45:20 +02:00
|
|
|
compositor_->SetBackgroundColor(background_color());
|
2016-07-06 21:34:09 +02:00
|
|
|
#endif
|
2014-07-01 00:30:29 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::WasResized() {
|
|
|
|
if (hold_resize_) {
|
|
|
|
if (!pending_resize_)
|
|
|
|
pending_resize_ = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResizeRootLayer();
|
|
|
|
if (render_widget_host_)
|
|
|
|
render_widget_host_->WasResized();
|
2016-07-06 21:34:09 +02:00
|
|
|
GetDelegatedFrameHost()->WasResized();
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2016-10-17 20:14:44 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::GetScreenInfo(content::ScreenInfo* results) {
|
2016-08-31 13:25:56 +02:00
|
|
|
if (!browser_impl_.get())
|
|
|
|
return;
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefScreenInfo screen_info(kDefaultScaleFactor, 0, 0, false, CefRect(),
|
|
|
|
CefRect());
|
2016-08-31 13:25:56 +02:00
|
|
|
|
|
|
|
CefRefPtr<CefRenderHandler> handler =
|
|
|
|
browser_impl_->client()->GetRenderHandler();
|
|
|
|
if (handler.get() &&
|
|
|
|
(!handler->GetScreenInfo(browser_impl_.get(), screen_info) ||
|
2017-05-17 11:29:28 +02:00
|
|
|
screen_info.rect.width == 0 || screen_info.rect.height == 0 ||
|
|
|
|
screen_info.available_rect.width == 0 ||
|
|
|
|
screen_info.available_rect.height == 0)) {
|
2016-08-31 13:25:56 +02:00
|
|
|
// If a screen rectangle was not provided, try using the view rectangle
|
|
|
|
// instead. Otherwise, popup views may be drawn incorrectly, or not at all.
|
|
|
|
CefRect screenRect;
|
|
|
|
if (!handler->GetViewRect(browser_impl_.get(), screenRect)) {
|
|
|
|
NOTREACHED();
|
|
|
|
screenRect = CefRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (screen_info.rect.width == 0 && screen_info.rect.height == 0)
|
|
|
|
screen_info.rect = screenRect;
|
|
|
|
|
|
|
|
if (screen_info.available_rect.width == 0 &&
|
|
|
|
screen_info.available_rect.height == 0)
|
|
|
|
screen_info.available_rect = screenRect;
|
|
|
|
}
|
|
|
|
|
2016-10-17 20:14:44 +02:00
|
|
|
*results = ScreenInfoFrom(screen_info);
|
2016-08-31 13:25:56 +02:00
|
|
|
}
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::OnScreenInfoChanged() {
|
|
|
|
TRACE_EVENT0("libcef", "CefRenderWidgetHostViewOSR::OnScreenInfoChanged");
|
|
|
|
if (!render_widget_host_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// TODO(OSR): Update the backing store.
|
|
|
|
|
|
|
|
render_widget_host_->NotifyScreenInfoChanged();
|
|
|
|
// We might want to change the cursor scale factor here as well - see the
|
|
|
|
// 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) {
|
|
|
|
TRACE_EVENT1("libcef", "CefRenderWidgetHostViewOSR::Invalidate", "type",
|
2017-05-17 11:29:28 +02:00
|
|
|
type);
|
2014-07-01 00:30:29 +02:00
|
|
|
if (!IsPopupWidget() && type == PET_POPUP) {
|
|
|
|
if (popup_host_view_)
|
|
|
|
popup_host_view_->Invalidate(type);
|
|
|
|
return;
|
|
|
|
}
|
2014-12-02 12:23:57 +01:00
|
|
|
|
2016-10-27 17:02:56 +02:00
|
|
|
InvalidateInternal(gfx::Rect(GetPhysicalBackingSize()));
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::SendKeyEvent(
|
|
|
|
const content::NativeWebKeyboardEvent& event) {
|
|
|
|
TRACE_EVENT0("libcef", "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.
|
|
|
|
render_widget_host_->GetView()->ProcessKeyboardEvent(
|
|
|
|
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) {
|
|
|
|
TRACE_EVENT0("libcef", "CefRenderWidgetHostViewOSR::SendMouseEvent");
|
|
|
|
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()) {
|
|
|
|
// Direct routing requires that mouse events go directly to the View.
|
|
|
|
render_widget_host_->GetView()->ProcessMouseEvent(
|
|
|
|
event, ui::LatencyInfo(ui::SourceEventType::OTHER));
|
|
|
|
}
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::SendMouseWheelEvent(
|
|
|
|
const blink::WebMouseWheelEvent& event) {
|
|
|
|
TRACE_EVENT0("libcef", "CefRenderWidgetHostViewOSR::SendMouseWheelEvent");
|
|
|
|
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(
|
2017-05-17 11:29:28 +02:00
|
|
|
event.PositionInWidget().x, event.PositionInWidget().y)) {
|
2014-07-01 00:30:29 +02:00
|
|
|
blink::WebMouseWheelEvent popup_event(event);
|
2017-04-20 21:28:17 +02:00
|
|
|
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);
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
popup_host_view_->SendMouseWheelEvent(popup_event);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
// Scrolling outside of the popup widget so destroy it.
|
|
|
|
// 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();
|
|
|
|
if (guest_bounds.Contains(event.PositionInWidget().x,
|
|
|
|
event.PositionInWidget().y)) {
|
|
|
|
blink::WebMouseWheelEvent 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->SendMouseWheelEvent(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()) {
|
|
|
|
// Direct routing requires that mouse events go directly to the View.
|
|
|
|
render_widget_host_->GetView()->ProcessMouseWheelEvent(
|
|
|
|
event, ui::LatencyInfo(ui::SourceEventType::WHEEL));
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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_) {
|
|
|
|
pending_resize_ = false;
|
2017-05-17 11:29:28 +02:00
|
|
|
CEF_POST_TASK(CEF_UIT, base::Bind(&CefRenderWidgetHostViewOSR::WasResized,
|
|
|
|
weak_ptr_factory_.GetWeakPtr()));
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::OnPaint(const gfx::Rect& damage_rect,
|
|
|
|
int bitmap_width,
|
|
|
|
int bitmap_height,
|
|
|
|
void* bitmap_pixels) {
|
2015-01-01 17:51:56 +01:00
|
|
|
TRACE_EVENT0("libcef", "CefRenderWidgetHostViewOSR::OnPaint");
|
|
|
|
|
2015-01-26 01:57:01 +01:00
|
|
|
CefRefPtr<CefRenderHandler> handler =
|
|
|
|
browser_impl_->client()->GetRenderHandler();
|
|
|
|
if (!handler.get())
|
|
|
|
return;
|
|
|
|
|
2015-01-01 17:51:56 +01:00
|
|
|
// Don't execute WasResized while the OnPaint callback is pending.
|
|
|
|
HoldResize();
|
|
|
|
|
|
|
|
gfx::Rect rect_in_bitmap(0, 0, bitmap_width, bitmap_height);
|
|
|
|
rect_in_bitmap.Intersect(damage_rect);
|
|
|
|
|
|
|
|
CefRenderHandler::RectList rcList;
|
|
|
|
rcList.push_back(CefRect(rect_in_bitmap.x(), rect_in_bitmap.y(),
|
|
|
|
rect_in_bitmap.width(), rect_in_bitmap.height()));
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
handler->OnPaint(browser_impl_.get(), IsPopupWidget() ? PET_POPUP : PET_VIEW,
|
|
|
|
rcList, bitmap_pixels, bitmap_width, bitmap_height);
|
2015-01-01 17:51:56 +01:00
|
|
|
|
|
|
|
ReleaseResize();
|
|
|
|
}
|
|
|
|
|
2016-07-06 21:34:09 +02:00
|
|
|
#if !defined(OS_MACOSX)
|
2016-07-21 23:21:32 +02:00
|
|
|
|
2016-07-06 21:34:09 +02:00
|
|
|
ui::Compositor* CefRenderWidgetHostViewOSR::GetCompositor() const {
|
|
|
|
return compositor_.get();
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !defined(OS_MACOSX)
|
|
|
|
|
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;
|
|
|
|
|
2015-05-13 17:43:50 +02:00
|
|
|
const int frame_rate =
|
2015-11-17 19:20:13 +01:00
|
|
|
osr_util::ClampFrameRate(browser->settings().windowless_frame_rate);
|
2016-11-23 18:26:50 +01:00
|
|
|
frame_rate_threshold_us_ = 1000000 / frame_rate;
|
2015-01-01 17:51:56 +01:00
|
|
|
|
|
|
|
// Configure the VSync interval for the browser process.
|
2016-07-06 21:34:09 +02:00
|
|
|
GetCompositor()->vsync_manager()->SetAuthoritativeVSyncInterval(
|
2016-11-23 18:26:50 +01:00
|
|
|
base::TimeDelta::FromMicroseconds(frame_rate_threshold_us_));
|
2015-01-01 17:51:56 +01:00
|
|
|
|
2015-05-13 17:43:50 +02:00
|
|
|
if (copy_frame_generator_.get()) {
|
2016-11-23 18:26:50 +01:00
|
|
|
copy_frame_generator_->set_frame_rate_threshold_us(
|
|
|
|
frame_rate_threshold_us_);
|
2015-05-13 17:43:50 +02:00
|
|
|
}
|
|
|
|
|
2016-10-17 20:14:44 +02:00
|
|
|
if (begin_frame_timer_.get()) {
|
2016-11-23 18:26:50 +01:00
|
|
|
begin_frame_timer_->SetFrameRateThresholdUs(frame_rate_threshold_us_);
|
2016-10-17 20:14:44 +02:00
|
|
|
} else {
|
|
|
|
begin_frame_timer_.reset(new CefBeginFrameTimer(
|
2016-11-23 18:26:50 +01:00
|
|
|
frame_rate_threshold_us_,
|
2016-10-17 20:14:44 +02:00
|
|
|
base::Bind(&CefRenderWidgetHostViewOSR::OnBeginFrameTimerTick,
|
2017-05-17 11:29:28 +02:00
|
|
|
weak_ptr_factory_.GetWeakPtr())));
|
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();
|
2017-05-17 11:29:28 +02:00
|
|
|
if (handler.get() &&
|
|
|
|
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
|
|
|
|
|
|
|
if (render_widget_host_ && render_widget_host_->delegate())
|
2017-05-17 11:29:28 +02:00
|
|
|
render_widget_host_->delegate()->UpdateDeviceScaleFactor(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->delegate())
|
|
|
|
rwhi->delegate()->UpdateDeviceScaleFactor(new_scale_factor);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderWidgetHostViewOSR::ResizeRootLayer() {
|
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
|
|
|
|
2016-07-06 21:34:09 +02:00
|
|
|
if (!scaleFactorDidChange && size == GetRootLayer()->bounds().size())
|
2014-11-18 20:29:26 +01:00
|
|
|
return;
|
|
|
|
|
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
|
|
|
|
2017-10-20 19:45:20 +02:00
|
|
|
local_surface_id_ = local_surface_id_allocator_.GenerateId();
|
|
|
|
|
2016-07-06 21:34:09 +02:00
|
|
|
GetRootLayer()->SetBounds(gfx::Rect(size));
|
2017-06-23 21:06:37 +02:00
|
|
|
GetCompositor()->SetScaleAndSize(current_device_scale_factor_,
|
|
|
|
size_in_pixels);
|
2016-08-17 17:29:38 +02:00
|
|
|
PlatformResizeCompositorWidget(size_in_pixels);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2015-01-01 17:51:56 +01:00
|
|
|
void CefRenderWidgetHostViewOSR::OnBeginFrameTimerTick() {
|
|
|
|
const base::TimeTicks frame_time = base::TimeTicks::Now();
|
|
|
|
const base::TimeDelta vsync_period =
|
2016-11-23 18:26:50 +01:00
|
|
|
base::TimeDelta::FromMicroseconds(frame_rate_threshold_us_);
|
2015-01-01 17:51:56 +01:00
|
|
|
SendBeginFrame(frame_time, vsync_period);
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2015-01-01 17:51:56 +01:00
|
|
|
void CefRenderWidgetHostViewOSR::SendBeginFrame(base::TimeTicks frame_time,
|
|
|
|
base::TimeDelta vsync_period) {
|
|
|
|
TRACE_EVENT1("libcef", "CefRenderWidgetHostViewOSR::SendBeginFrame",
|
|
|
|
"frame_time_us", frame_time.ToInternalValue());
|
2014-12-02 12:23:57 +01:00
|
|
|
|
2015-01-01 17:51:56 +01:00
|
|
|
base::TimeTicks display_time = frame_time + vsync_period;
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2015-01-01 17:51:56 +01:00
|
|
|
// TODO(brianderson): Use adaptive draw-time estimation.
|
|
|
|
base::TimeDelta estimated_browser_composite_time =
|
|
|
|
base::TimeDelta::FromMicroseconds(
|
|
|
|
(1.0f * base::Time::kMicrosecondsPerSecond) / (3.0f * 60));
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2015-01-01 17:51:56 +01:00
|
|
|
base::TimeTicks deadline = display_time - estimated_browser_composite_time;
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2017-09-06 23:40:58 +02:00
|
|
|
const viz::BeginFrameArgs& begin_frame_args = viz::BeginFrameArgs::Create(
|
2017-05-17 11:29:28 +02:00
|
|
|
BEGINFRAME_FROM_HERE, begin_frame_source_.source_id(),
|
|
|
|
begin_frame_number_, frame_time, deadline, vsync_period,
|
2017-09-06 23:40:58 +02:00
|
|
|
viz::BeginFrameArgs::NORMAL);
|
2017-01-23 18:36:54 +01:00
|
|
|
DCHECK(begin_frame_args.IsValid());
|
|
|
|
begin_frame_number_++;
|
|
|
|
|
2017-07-27 01:19:27 +02:00
|
|
|
if (renderer_compositor_frame_sink_)
|
|
|
|
renderer_compositor_frame_sink_->OnBeginFrame(begin_frame_args);
|
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();
|
|
|
|
if (handler.get())
|
|
|
|
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
|
|
|
|
|
|
|
// Don't delete the RWHI manually while owned by a scoped_ptr in RVHI. This
|
|
|
|
// matches a CHECK() in RenderWidgetHostImpl::Destroy().
|
|
|
|
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();
|
2015-03-06 18:50:14 +01:00
|
|
|
if (handler.get()) {
|
|
|
|
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) {
|
2017-05-17 11:29:28 +02:00
|
|
|
guest_host_view->RegisterFrameSwappedCallback(
|
|
|
|
base::MakeUnique<base::Closure>(base::Bind(
|
|
|
|
&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) {
|
|
|
|
if (software_output_device_) {
|
|
|
|
software_output_device_->OnPaint(bounds_in_pixels);
|
|
|
|
} else if (copy_frame_generator_.get()) {
|
2016-11-23 18:26:50 +01:00
|
|
|
copy_frame_generator_->GenerateCopyFrame(bounds_in_pixels);
|
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();
|
|
|
|
if (handler.get()) {
|
|
|
|
handler->OnImeCompositionRangeChanged(browser_impl_->GetBrowser(),
|
|
|
|
cef_range, rcList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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()
|
2017-07-27 01:19:27 +02:00
|
|
|
: viz::FrameSinkId(base::checked_cast<uint32_t>(
|
|
|
|
render_widget_host_->GetProcess()->GetID()),
|
|
|
|
base::checked_cast<uint32_t>(
|
|
|
|
render_widget_host_->GetRoutingID()));
|
2017-03-03 23:37:23 +01:00
|
|
|
}
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::UpdateBackgroundColorFromRenderer(
|
|
|
|
SkColor color) {
|
|
|
|
if (color == background_color())
|
|
|
|
return;
|
|
|
|
background_color_ = color;
|
|
|
|
|
|
|
|
bool opaque = SkColorGetA(color) == SK_AlphaOPAQUE;
|
|
|
|
GetRootLayer()->SetFillsBoundsOpaquely(opaque);
|
|
|
|
GetRootLayer()->SetColor(color);
|
|
|
|
}
|