bd10b19b0c
* chore: bump chromium in DEPS to 97.0.4678.0 * chore: bump chromium in DEPS to 97.0.4679.0 * chore: bump chromium in DEPS to 97.0.4680.0 * chore: bump chromium in DEPS to 97.0.4681.0 * chore: bump chromium in DEPS to 97.0.4682.0 * chore: update patches * 3234737: Disable -Wunused-but-set-variable Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3234737 * 3216953: Reland "Move task-related files from base/ to base/task/" Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3216953 * 3202710: TimeDelta factory function migration. Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3202710 * 3226841: Rename WCO::RenderProcessGone to PrimaryMainFrameRenderProcessGone Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3226841 * 3212165: blink/gin: changes blink to load snapshot based on runtime information Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3212165 * 3220292: Deprecate returning a GURL from GURL::GetOrigin() Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3220292 * 3231995: build: Enable -Wbitwise-instead-of-logical everywhere except iOS and Windows Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3231995 * 3205121: Remove base::DictionaryValue::GetDouble Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3205121 * 3208413: [flags] Make --js-flags settings have priority over V8 features Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3208413 * chore: bump chromium in DEPS to 97.0.4683.0 * chore: update patches * 3188834: Combine RWHVBase GetCurrentDeviceScaleFactor/GetDeviceScaleFactor Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3188834 * chore: update process_singleton patches * chore: bump chromium in DEPS to 97.0.4684.0 * chore: update patches * chore: bump chromium in DEPS to 97.0.4685.0 * chore: update patches * chore: bump chromium in DEPS to 97.0.4686.0 * chore: update patches * chore: bump chromium in DEPS to 97.0.4687.0 * chore: update patches * chore: bump chromium in DEPS to 97.0.4688.0 * chore: update patches * 3247722: Use correct source_site_instance if navigating via context menu Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3247722 Update signature of HandleContextMenu() * 3247722: Use correct source_site_instance if navigating via context menu Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3247722 Update signature of HandleContextMenu() * 3223422: Remove PP_ISOLATEDFILESYSTEMTYPE_PRIVATE_PLUGINPRIVATE enum option Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3223422 sync pepper_plugin_support.patch with upstream * chore: bump chromium in DEPS to 97.0.4689.0 * 3247791: ax_mac_merge: Merge AX Math attribute implementations Xref: ax_mac_merge: Merge AX Math attribute implementations chore: fix minor patch shear in #includes * 3243425: Add VisibleTimeRequestTrigger helper class Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3243425 chore: fix minor patch shear in #includes * chore: regen chromium patches * fixup! 3247722: Use correct source_site_instance if navigating via context menu * chore: bump chromium in DEPS to 97.0.4690.0 * 3188659: Window Placement: make GetScreenInfo(s) const Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3188659 simple sync GetScreenInfo with upstream refactor * chore: update patches * chore: bump chromium in DEPS to 97.0.4690.4 * chore: bump chromium in DEPS to 97.0.4692.0 * 3198073: ozone: //content: clean up from USE_X11 Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3198073 Fixing patch shear. Nothing to see here. * 3252338: Remove label images checkbox from chrome://accessibility page Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3252338 Part of our a11y patch is no longer needed due to upstream label removal * 3258183: Remove DISALLOW_IMPLICIT_CONSTRUCTORS() definition Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3258183 Replace our use of the macro with explicitly-deleted class methods. See https://chromium-review.googlesource.com/c/chromium/src/+/3256952 for upstream examples of this same replacement. * chore: update patches * 3247295: Unwind SecurityStyleExplanations Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3247295 update GetSecurityStyle() signature and impl to match upstream changes * 3259578: media: grabs lock to ensure video output when occluded Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3259578 Add stub for new upstream virtual method OnCapturerCountChanged() * fixup! 3247295: Unwind SecurityStyleExplanations * 3238504: Fix up drag image is not shown from bookmark bar Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3238504 SetDragImage() no longer takes a widget argument * 3217452: [devtools] Add getSyncInformation host binding Xref: https://chromium-review.googlesource.com/c/chromium/src/+/3217452 Add stub for new upstream method GetSyncInformation(). Stub sends info back to caller saying that syncing is disabled. * chore: bump chromium in DEPS to 98.0.4693.0 * chore: bump chromium in DEPS to 98.0.4694.0 * chore: bump chromium in DEPS to 98.0.4695.0 * chore: bump chromium in DEPS to 98.0.4696.0 * chore: bump chromium in DEPS to 98.0.4697.0 * chore: bump chromium in DEPS to 98.0.4699.0 * chore: bump chromium in DEPS to 98.0.4701.0 * chore: bump chromium in DEPS to 98.0.4703.0 * chore: bump chromium in DEPS to 98.0.4705.0 * chore: bump chromium in DEPS to 98.0.4706.0 * chore: update patches * 3279210: Rename "base/macros.h" => "base/ignore_result.h" https://chromium-review.googlesource.com/c/chromium/src/+/3279210 * 3259964: Remove all DISALLOW_COPY_AND_ASSIGNs https://chromium-review.googlesource.com/c/chromium/src/+/3259964 * 3269029: blink/gin: sets histogram callbacks during isolate creation https://chromium-review.googlesource.com/c/chromium/src/+/3269029 * fixup after rebase * [content] Make ContentMainParams and MainFunctionParams move-only https://chromium-review.googlesource.com/c/chromium/src/+/3244976 * 3255305: Stop sending the securityStateChanged event and unwind https://chromium-review.googlesource.com/c/chromium/src/+/3255305 * [Blink] Add promise support to WebLocalFrame::RequestExecuteScript() https://chromium-review.googlesource.com/c/chromium/src/+/3230010 * 3256162: Simplify RWHV Show and ShowWithVisibility handling https://chromium-review.googlesource.com/c/chromium/src/+/3256162 * 3263824: ozone: //ui/base: clean up from USE_X11 1/* https://chromium-review.googlesource.com/c/chromium/src/+/3263824 * Request or cancel RecordContentToPresentationTimeRequest during capture https://chromium-review.googlesource.com/c/chromium/src/+/3256802 * appcache: remove BrowsingData/quota references https://chromium-review.googlesource.com/c/chromium/src/+/3255725 * [Autofill] Don't show Autofill dropdown if overlaps with permissions https://chromium-review.googlesource.com/c/chromium/src/+/3236729 * Rename to_different_document to should_show_loading_ui in LoadingStateChanged() callbacks https://chromium-review.googlesource.com/c/chromium/src/+/3268574 * cleanup patch * fixup [content] Make ContentMainParams and MainFunctionParams move-only * 3279210: Rename "base/macros.h" => "base/ignore_result.h" https://chromium-review.googlesource.com/c/chromium/src/+/3279210 * ozone: //chrome/browser clean up from USE_X11 https://chromium-review.googlesource.com/c/chromium/src/+/3186490 Refs: https://github.com/electron/electron/issues/31382 * chore: update support_mixed_sandbox_with_zygote.patch * Enable -Wunused-but-set-variable. Refs https://chromium-review.googlesource.com/c/chromium/src/+/3234737 * fixup! ozone: //ui/base: clean up from USE_X11 1/* * fixup! ozone: //chrome/browser clean up from USE_X11 * chore: fix deprecation warning in libuv * chore: fixup for lint * 3251161: Reland "Make the Clang update.py script require Python 3" https://chromium-review.googlesource.com/c/chromium/src/+/3251161 * fixup: Enable -Wunused-but-set-variable. * [base][win] Rename DIR_APP_DATA to DIR_ROAMING_APP_DATA https://chromium-review.googlesource.com/c/chromium/src/+/3262369 * Replace sandbox::policy::SandboxType with mojom Sandbox enum https://chromium-review.googlesource.com/c/chromium/src/+/3213677 * fixup: [content] Make ContentMainParams and MainFunctionParams move-only * build: ensure angle has a full git checkout available to it * fixup: [base][win] Rename DIR_APP_DATA to DIR_ROAMING_APP_DATA * fixup lint * [unseasoned-pdf] Dispatch 'afterprint' event in PDF plugin frame https://chromium-review.googlesource.com/c/chromium/src/+/3223434 * fixup: [Autofill] Don't show Autofill dropdown if overlaps with permissions * 3217591: Move browser UI CSS color parsing to own file part 2/2 https://chromium-review.googlesource.com/c/chromium/src/+/3217591 * Make kNoSandboxAndElevatedPrivileges only available to utilities https://chromium-review.googlesource.com/c/chromium/src/+/3276784 * 3211575: [modules] Change ScriptOrModule to custom Struct https://chromium-review.googlesource.com/c/v8/v8/+/3211575 * Address review feedback * chore: update patches * 3211575: [modules] Change ScriptOrModule to custom Struct https://chromium-review.googlesource.com/c/v8/v8/+/3211575 * fix: unused variable compat * chore: remove redundant patch * fixup for 3262517: Re-enable WindowCaptureMacV2 https://chromium-review.googlesource.com/c/chromium/src/+/3262517 * chore: cleanup todo The functions added in https://chromium-review.googlesource.com/c/chromium/src/+/3256802 are not used by offscreen rendering. * fixup: update mas_no_private_api.patch * 3216879: [PA] Make features::kPartitionAllocLazyCommit to be PartitionOptions::LazyCommit Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3216879 Fixes up commit b2f1aca95604ec61649808c846657454097e6935 * chore: cleanup support_mixed_sandbox_with_zygote.patch * test: use window focus event instead of delay to wait for webContents focus Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: VerteDinde <khammond@slack-corp.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
1075 lines
34 KiB
C++
1075 lines
34 KiB
C++
// Copyright (c) 2016 GitHub, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "shell/browser/osr/osr_render_widget_host_view.h"
|
|
|
|
#include <algorithm>
|
|
#include <memory>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
#include "base/callback_helpers.h"
|
|
#include "base/location.h"
|
|
#include "base/memory/ptr_util.h"
|
|
#include "base/task/post_task.h"
|
|
#include "base/task/single_thread_task_runner.h"
|
|
#include "base/time/time.h"
|
|
#include "components/viz/common/features.h"
|
|
#include "components/viz/common/frame_sinks/begin_frame_args.h"
|
|
#include "components/viz/common/frame_sinks/copy_output_request.h"
|
|
#include "components/viz/common/frame_sinks/delay_based_time_source.h"
|
|
#include "components/viz/common/quads/compositor_render_pass.h"
|
|
#include "content/browser/renderer_host/cursor_manager.h" // nogncheck
|
|
#include "content/browser/renderer_host/input/synthetic_gesture_target.h" // nogncheck
|
|
#include "content/browser/renderer_host/render_widget_host_delegate.h" // nogncheck
|
|
#include "content/browser/renderer_host/render_widget_host_owner_delegate.h" // nogncheck
|
|
#include "content/public/browser/browser_task_traits.h"
|
|
#include "content/public/browser/browser_thread.h"
|
|
#include "content/public/browser/context_factory.h"
|
|
#include "content/public/browser/gpu_data_manager.h"
|
|
#include "content/public/browser/render_process_host.h"
|
|
#include "gpu/command_buffer/client/gl_helper.h"
|
|
#include "media/base/video_frame.h"
|
|
#include "third_party/abseil-cpp/absl/types/optional.h"
|
|
#include "third_party/blink/public/common/input/web_input_event.h"
|
|
#include "third_party/skia/include/core/SkCanvas.h"
|
|
#include "ui/compositor/compositor.h"
|
|
#include "ui/compositor/layer.h"
|
|
#include "ui/compositor/layer_type.h"
|
|
#include "ui/display/screen.h"
|
|
#include "ui/events/base_event_utils.h"
|
|
#include "ui/events/event_constants.h"
|
|
#include "ui/gfx/canvas.h"
|
|
#include "ui/gfx/geometry/dip_util.h"
|
|
#include "ui/gfx/geometry/size_conversions.h"
|
|
#include "ui/gfx/image/image_skia.h"
|
|
#include "ui/gfx/native_widget_types.h"
|
|
#include "ui/gfx/skbitmap_operations.h"
|
|
#include "ui/latency/latency_info.h"
|
|
|
|
namespace electron {
|
|
|
|
namespace {
|
|
|
|
const float kDefaultScaleFactor = 1.0;
|
|
|
|
ui::MouseEvent UiMouseEventFromWebMouseEvent(blink::WebMouseEvent event) {
|
|
ui::EventType type = ui::EventType::ET_UNKNOWN;
|
|
switch (event.GetType()) {
|
|
case blink::WebInputEvent::Type::kMouseDown:
|
|
type = ui::EventType::ET_MOUSE_PRESSED;
|
|
break;
|
|
case blink::WebInputEvent::Type::kMouseUp:
|
|
type = ui::EventType::ET_MOUSE_RELEASED;
|
|
break;
|
|
case blink::WebInputEvent::Type::kMouseMove:
|
|
type = ui::EventType::ET_MOUSE_MOVED;
|
|
break;
|
|
case blink::WebInputEvent::Type::kMouseEnter:
|
|
type = ui::EventType::ET_MOUSE_ENTERED;
|
|
break;
|
|
case blink::WebInputEvent::Type::kMouseLeave:
|
|
type = ui::EventType::ET_MOUSE_EXITED;
|
|
break;
|
|
case blink::WebInputEvent::Type::kMouseWheel:
|
|
type = ui::EventType::ET_MOUSEWHEEL;
|
|
break;
|
|
default:
|
|
type = ui::EventType::ET_UNKNOWN;
|
|
break;
|
|
}
|
|
|
|
int button_flags = 0;
|
|
switch (event.button) {
|
|
case blink::WebMouseEvent::Button::kBack:
|
|
button_flags |= ui::EventFlags::EF_BACK_MOUSE_BUTTON;
|
|
break;
|
|
case blink::WebMouseEvent::Button::kForward:
|
|
button_flags |= ui::EventFlags::EF_FORWARD_MOUSE_BUTTON;
|
|
break;
|
|
case blink::WebMouseEvent::Button::kLeft:
|
|
button_flags |= ui::EventFlags::EF_LEFT_MOUSE_BUTTON;
|
|
break;
|
|
case blink::WebMouseEvent::Button::kMiddle:
|
|
button_flags |= ui::EventFlags::EF_MIDDLE_MOUSE_BUTTON;
|
|
break;
|
|
case blink::WebMouseEvent::Button::kRight:
|
|
button_flags |= ui::EventFlags::EF_RIGHT_MOUSE_BUTTON;
|
|
break;
|
|
default:
|
|
button_flags = 0;
|
|
break;
|
|
}
|
|
|
|
ui::MouseEvent ui_event(type,
|
|
gfx::Point(std::floor(event.PositionInWidget().x()),
|
|
std::floor(event.PositionInWidget().y())),
|
|
gfx::Point(std::floor(event.PositionInWidget().x()),
|
|
std::floor(event.PositionInWidget().y())),
|
|
ui::EventTimeForNow(), button_flags, button_flags);
|
|
ui_event.SetClickCount(event.click_count);
|
|
|
|
return ui_event;
|
|
}
|
|
|
|
ui::MouseWheelEvent UiMouseWheelEventFromWebMouseEvent(
|
|
blink::WebMouseWheelEvent event) {
|
|
return ui::MouseWheelEvent(UiMouseEventFromWebMouseEvent(event),
|
|
std::floor(event.delta_x),
|
|
std::floor(event.delta_y));
|
|
}
|
|
|
|
} // namespace
|
|
|
|
class ElectronDelegatedFrameHostClient
|
|
: public content::DelegatedFrameHostClient {
|
|
public:
|
|
explicit ElectronDelegatedFrameHostClient(OffScreenRenderWidgetHostView* view)
|
|
: view_(view) {}
|
|
|
|
// disable copy
|
|
ElectronDelegatedFrameHostClient(const ElectronDelegatedFrameHostClient&) =
|
|
delete;
|
|
ElectronDelegatedFrameHostClient& operator=(
|
|
const ElectronDelegatedFrameHostClient&) = delete;
|
|
|
|
ui::Layer* DelegatedFrameHostGetLayer() const override {
|
|
return view_->GetRootLayer();
|
|
}
|
|
|
|
bool DelegatedFrameHostIsVisible() const override {
|
|
return view_->IsShowing();
|
|
}
|
|
|
|
SkColor DelegatedFrameHostGetGutterColor() const override {
|
|
if (view_->render_widget_host()->delegate() &&
|
|
view_->render_widget_host()->delegate()->IsFullscreen()) {
|
|
return SK_ColorWHITE;
|
|
}
|
|
return *view_->GetBackgroundColor();
|
|
}
|
|
|
|
void OnFrameTokenChanged(uint32_t frame_token,
|
|
base::TimeTicks activation_time) override {
|
|
view_->render_widget_host()->DidProcessFrame(frame_token, activation_time);
|
|
}
|
|
|
|
float GetDeviceScaleFactor() const override {
|
|
return view_->GetDeviceScaleFactor();
|
|
}
|
|
|
|
std::vector<viz::SurfaceId> CollectSurfaceIdsForEviction() override {
|
|
return view_->render_widget_host()->CollectSurfaceIdsForEviction();
|
|
}
|
|
|
|
bool ShouldShowStaleContentOnEviction() override { return false; }
|
|
|
|
void InvalidateLocalSurfaceIdOnEviction() override {}
|
|
|
|
private:
|
|
OffScreenRenderWidgetHostView* const view_;
|
|
};
|
|
|
|
OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(
|
|
bool transparent,
|
|
bool painting,
|
|
int frame_rate,
|
|
const OnPaintCallback& callback,
|
|
content::RenderWidgetHost* host,
|
|
OffScreenRenderWidgetHostView* parent_host_view,
|
|
gfx::Size initial_size)
|
|
: content::RenderWidgetHostViewBase(host),
|
|
render_widget_host_(content::RenderWidgetHostImpl::From(host)),
|
|
parent_host_view_(parent_host_view),
|
|
transparent_(transparent),
|
|
callback_(callback),
|
|
frame_rate_(frame_rate),
|
|
size_(initial_size),
|
|
painting_(painting),
|
|
cursor_manager_(std::make_unique<content::CursorManager>(this)),
|
|
mouse_wheel_phase_handler_(this),
|
|
backing_(std::make_unique<SkBitmap>()) {
|
|
DCHECK(render_widget_host_);
|
|
DCHECK(!render_widget_host_->GetView());
|
|
|
|
// Initialize a screen_infos_ struct as needed, to cache the scale factor.
|
|
if (screen_infos_.screen_infos.empty()) {
|
|
UpdateScreenInfo();
|
|
}
|
|
screen_infos_.mutable_current().device_scale_factor = kDefaultScaleFactor;
|
|
|
|
delegated_frame_host_allocator_.GenerateId();
|
|
delegated_frame_host_surface_id_ =
|
|
delegated_frame_host_allocator_.GetCurrentLocalSurfaceId();
|
|
compositor_allocator_.GenerateId();
|
|
compositor_surface_id_ = compositor_allocator_.GetCurrentLocalSurfaceId();
|
|
|
|
delegated_frame_host_client_ =
|
|
std::make_unique<ElectronDelegatedFrameHostClient>(this);
|
|
delegated_frame_host_ = std::make_unique<content::DelegatedFrameHost>(
|
|
AllocateFrameSinkId(), delegated_frame_host_client_.get(),
|
|
true /* should_register_frame_sink_id */);
|
|
|
|
root_layer_ = std::make_unique<ui::Layer>(ui::LAYER_SOLID_COLOR);
|
|
|
|
bool opaque = SkColorGetA(background_color_) == SK_AlphaOPAQUE;
|
|
GetRootLayer()->SetFillsBoundsOpaquely(opaque);
|
|
GetRootLayer()->SetColor(background_color_);
|
|
|
|
ui::ContextFactory* context_factory = content::GetContextFactory();
|
|
compositor_ = std::make_unique<ui::Compositor>(
|
|
context_factory->AllocateFrameSinkId(), context_factory,
|
|
base::ThreadTaskRunnerHandle::Get(), false /* enable_pixel_canvas */,
|
|
false /* use_external_begin_frame_control */);
|
|
compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget);
|
|
compositor_->SetDelegate(this);
|
|
compositor_->SetRootLayer(root_layer_.get());
|
|
|
|
ResizeRootLayer(false);
|
|
render_widget_host_->SetView(this);
|
|
|
|
if (content::GpuDataManager::GetInstance()->HardwareAccelerationEnabled()) {
|
|
video_consumer_ = std::make_unique<OffScreenVideoConsumer>(
|
|
this, base::BindRepeating(&OffScreenRenderWidgetHostView::OnPaint,
|
|
weak_ptr_factory_.GetWeakPtr()));
|
|
video_consumer_->SetActive(IsPainting());
|
|
video_consumer_->SetFrameRate(GetFrameRate());
|
|
}
|
|
}
|
|
|
|
OffScreenRenderWidgetHostView::~OffScreenRenderWidgetHostView() {
|
|
// 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(
|
|
content::DelegatedFrameHost::HiddenCause::kOther);
|
|
delegated_frame_host_->DetachFromCompositor();
|
|
|
|
delegated_frame_host_.reset();
|
|
compositor_.reset();
|
|
root_layer_.reset();
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::InitAsChild(gfx::NativeView) {
|
|
DCHECK(parent_host_view_);
|
|
|
|
if (parent_host_view_->child_host_view_) {
|
|
parent_host_view_->child_host_view_->CancelWidget();
|
|
}
|
|
|
|
parent_host_view_->set_child_host_view(this);
|
|
parent_host_view_->Hide();
|
|
|
|
ResizeRootLayer(false);
|
|
SetPainting(parent_host_view_->IsPainting());
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::SetSize(const gfx::Size& size) {
|
|
size_ = size;
|
|
SynchronizeVisualProperties();
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::SetBounds(const gfx::Rect& new_bounds) {
|
|
SetSize(new_bounds.size());
|
|
}
|
|
|
|
gfx::NativeView OffScreenRenderWidgetHostView::GetNativeView() {
|
|
return gfx::NativeView();
|
|
}
|
|
|
|
gfx::NativeViewAccessible
|
|
OffScreenRenderWidgetHostView::GetNativeViewAccessible() {
|
|
return gfx::NativeViewAccessible();
|
|
}
|
|
|
|
ui::TextInputClient* OffScreenRenderWidgetHostView::GetTextInputClient() {
|
|
return nullptr;
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::Focus() {}
|
|
|
|
bool OffScreenRenderWidgetHostView::HasFocus() {
|
|
return false;
|
|
}
|
|
|
|
bool OffScreenRenderWidgetHostView::IsSurfaceAvailableForCopy() {
|
|
return GetDelegatedFrameHost()->CanCopyFromCompositingSurface();
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::ShowWithVisibility(
|
|
content::PageVisibilityState /*page_visibility*/) {
|
|
if (is_showing_)
|
|
return;
|
|
|
|
is_showing_ = true;
|
|
|
|
delegated_frame_host_->AttachToCompositor(compositor_.get());
|
|
delegated_frame_host_->WasShown(GetLocalSurfaceId(),
|
|
GetRootLayer()->bounds().size(), {});
|
|
|
|
if (render_widget_host_)
|
|
render_widget_host_->WasShown({});
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::Hide() {
|
|
if (!is_showing_)
|
|
return;
|
|
|
|
if (render_widget_host_)
|
|
render_widget_host_->WasHidden();
|
|
|
|
// TODO(deermichel): correct or kOther?
|
|
GetDelegatedFrameHost()->WasHidden(
|
|
content::DelegatedFrameHost::HiddenCause::kOccluded);
|
|
GetDelegatedFrameHost()->DetachFromCompositor();
|
|
|
|
is_showing_ = false;
|
|
}
|
|
|
|
bool OffScreenRenderWidgetHostView::IsShowing() {
|
|
return is_showing_;
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::EnsureSurfaceSynchronizedForWebTest() {
|
|
++latest_capture_sequence_number_;
|
|
SynchronizeVisualProperties();
|
|
}
|
|
|
|
gfx::Rect OffScreenRenderWidgetHostView::GetViewBounds() {
|
|
if (IsPopupWidget())
|
|
return popup_position_;
|
|
|
|
return gfx::Rect(size_);
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::SetBackgroundColor(SkColor color) {
|
|
// 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);
|
|
|
|
if (render_widget_host_ && render_widget_host_->owner_delegate()) {
|
|
render_widget_host_->owner_delegate()->SetBackgroundOpaque(
|
|
SkColorGetA(color) == SK_AlphaOPAQUE);
|
|
}
|
|
}
|
|
|
|
absl::optional<SkColor> OffScreenRenderWidgetHostView::GetBackgroundColor() {
|
|
return background_color_;
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::UpdateBackgroundColor() {}
|
|
|
|
gfx::Size OffScreenRenderWidgetHostView::GetVisibleViewportSize() {
|
|
return size_;
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::SetInsets(const gfx::Insets& insets) {}
|
|
|
|
blink::mojom::PointerLockResult OffScreenRenderWidgetHostView::LockMouse(
|
|
bool request_unadjusted_movement) {
|
|
return blink::mojom::PointerLockResult::kUnsupportedOptions;
|
|
}
|
|
|
|
blink::mojom::PointerLockResult OffScreenRenderWidgetHostView::ChangeMouseLock(
|
|
bool request_unadjusted_movement) {
|
|
return blink::mojom::PointerLockResult::kUnsupportedOptions;
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::UnlockMouse() {}
|
|
|
|
void OffScreenRenderWidgetHostView::TakeFallbackContentFrom(
|
|
content::RenderWidgetHostView* view) {
|
|
DCHECK(!static_cast<content::RenderWidgetHostViewBase*>(view)
|
|
->IsRenderWidgetHostViewChildFrame());
|
|
auto* view_osr = static_cast<OffScreenRenderWidgetHostView*>(view);
|
|
SetBackgroundColor(view_osr->background_color_);
|
|
if (GetDelegatedFrameHost() && view_osr->GetDelegatedFrameHost()) {
|
|
GetDelegatedFrameHost()->TakeFallbackContentFrom(
|
|
view_osr->GetDelegatedFrameHost());
|
|
}
|
|
host()->GetContentRenderingTimeoutFrom(view_osr->host());
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::ResetFallbackToFirstNavigationSurface() {
|
|
GetDelegatedFrameHost()->ResetFallbackToFirstNavigationSurface();
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::InitAsPopup(
|
|
content::RenderWidgetHostView* parent_host_view,
|
|
const gfx::Rect& pos,
|
|
const gfx::Rect& anchor_rect) {
|
|
DCHECK_EQ(parent_host_view_, parent_host_view);
|
|
DCHECK_EQ(widget_type_, content::WidgetType::kPopup);
|
|
|
|
if (parent_host_view_->popup_host_view_) {
|
|
parent_host_view_->popup_host_view_->CancelWidget();
|
|
}
|
|
|
|
parent_host_view_->set_popup_host_view(this);
|
|
parent_callback_ =
|
|
base::BindRepeating(&OffScreenRenderWidgetHostView::OnPopupPaint,
|
|
parent_host_view_->weak_ptr_factory_.GetWeakPtr());
|
|
|
|
popup_position_ = pos;
|
|
|
|
ResizeRootLayer(false);
|
|
SetPainting(parent_host_view_->IsPainting());
|
|
if (video_consumer_) {
|
|
video_consumer_->SizeChanged();
|
|
}
|
|
Show();
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::UpdateCursor(const content::WebCursor&) {}
|
|
|
|
content::CursorManager* OffScreenRenderWidgetHostView::GetCursorManager() {
|
|
return cursor_manager_.get();
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::SetIsLoading(bool loading) {}
|
|
|
|
void OffScreenRenderWidgetHostView::TextInputStateChanged(
|
|
const ui::mojom::TextInputState& params) {}
|
|
|
|
void OffScreenRenderWidgetHostView::ImeCancelComposition() {}
|
|
|
|
void OffScreenRenderWidgetHostView::RenderProcessGone() {
|
|
Destroy();
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::Destroy() {
|
|
if (!is_destroyed_) {
|
|
is_destroyed_ = true;
|
|
|
|
if (parent_host_view_ != nullptr) {
|
|
CancelWidget();
|
|
} else {
|
|
if (popup_host_view_)
|
|
popup_host_view_->CancelWidget();
|
|
if (child_host_view_)
|
|
child_host_view_->CancelWidget();
|
|
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();
|
|
}
|
|
for (auto* proxy_view : proxy_views_)
|
|
proxy_view->RemoveObserver();
|
|
Hide();
|
|
}
|
|
}
|
|
|
|
delete this;
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::UpdateTooltipUnderCursor(
|
|
const std::u16string&) {}
|
|
|
|
uint32_t OffScreenRenderWidgetHostView::GetCaptureSequenceNumber() const {
|
|
return latest_capture_sequence_number_;
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::CopyFromSurface(
|
|
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));
|
|
}
|
|
|
|
display::ScreenInfo OffScreenRenderWidgetHostView::GetScreenInfo() const {
|
|
display::ScreenInfo screen_info;
|
|
screen_info.depth = 24;
|
|
screen_info.depth_per_component = 8;
|
|
screen_info.orientation_angle = 0;
|
|
screen_info.device_scale_factor = GetDeviceScaleFactor();
|
|
screen_info.orientation_type =
|
|
display::mojom::ScreenOrientation::kLandscapePrimary;
|
|
screen_info.rect = gfx::Rect(size_);
|
|
screen_info.available_rect = gfx::Rect(size_);
|
|
return screen_info;
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::TransformPointToRootSurface(
|
|
gfx::PointF* point) {}
|
|
|
|
gfx::Rect OffScreenRenderWidgetHostView::GetBoundsInRootWindow() {
|
|
return gfx::Rect(size_);
|
|
}
|
|
|
|
absl::optional<content::DisplayFeature>
|
|
OffScreenRenderWidgetHostView::GetDisplayFeature() {
|
|
return absl::nullopt;
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::SetDisplayFeatureForTesting(
|
|
const content::DisplayFeature* display_feature) {}
|
|
|
|
viz::SurfaceId OffScreenRenderWidgetHostView::GetCurrentSurfaceId() const {
|
|
return GetDelegatedFrameHost()
|
|
? GetDelegatedFrameHost()->GetCurrentSurfaceId()
|
|
: viz::SurfaceId();
|
|
}
|
|
|
|
std::unique_ptr<content::SyntheticGestureTarget>
|
|
OffScreenRenderWidgetHostView::CreateSyntheticGestureTarget() {
|
|
NOTIMPLEMENTED();
|
|
return nullptr;
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::ImeCompositionRangeChanged(
|
|
const gfx::Range&,
|
|
const std::vector<gfx::Rect>&) {}
|
|
|
|
gfx::Size OffScreenRenderWidgetHostView::GetCompositorViewportPixelSize() {
|
|
return gfx::ScaleToCeiledSize(GetRequestedRendererSize(),
|
|
GetDeviceScaleFactor());
|
|
}
|
|
|
|
ui::Compositor* OffScreenRenderWidgetHostView::GetCompositor() {
|
|
return compositor_.get();
|
|
}
|
|
|
|
content::RenderWidgetHostViewBase*
|
|
OffScreenRenderWidgetHostView::CreateViewForWidget(
|
|
content::RenderWidgetHost* render_widget_host,
|
|
content::RenderWidgetHost* embedder_render_widget_host,
|
|
content::WebContentsView* web_contents_view) {
|
|
if (render_widget_host->GetView()) {
|
|
return static_cast<content::RenderWidgetHostViewBase*>(
|
|
render_widget_host->GetView());
|
|
}
|
|
|
|
OffScreenRenderWidgetHostView* embedder_host_view = nullptr;
|
|
if (embedder_render_widget_host) {
|
|
embedder_host_view = static_cast<OffScreenRenderWidgetHostView*>(
|
|
embedder_render_widget_host->GetView());
|
|
}
|
|
|
|
return new OffScreenRenderWidgetHostView(
|
|
transparent_, true, embedder_host_view->GetFrameRate(), callback_,
|
|
render_widget_host, embedder_host_view, size());
|
|
}
|
|
|
|
const viz::FrameSinkId& OffScreenRenderWidgetHostView::GetFrameSinkId() const {
|
|
return GetDelegatedFrameHost()->frame_sink_id();
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::DidNavigate() {
|
|
ResizeRootLayer(true);
|
|
if (delegated_frame_host_)
|
|
delegated_frame_host_->DidNavigate();
|
|
}
|
|
|
|
bool OffScreenRenderWidgetHostView::TransformPointToCoordSpaceForView(
|
|
const gfx::PointF& point,
|
|
RenderWidgetHostViewBase* target_view,
|
|
gfx::PointF* transformed_point) {
|
|
if (target_view == this) {
|
|
*transformed_point = point;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::CancelWidget() {
|
|
if (render_widget_host_)
|
|
render_widget_host_->LostCapture();
|
|
Hide();
|
|
|
|
if (parent_host_view_) {
|
|
if (parent_host_view_->popup_host_view_ == this) {
|
|
parent_host_view_->set_popup_host_view(nullptr);
|
|
} else if (parent_host_view_->child_host_view_ == this) {
|
|
parent_host_view_->set_child_host_view(nullptr);
|
|
parent_host_view_->Show();
|
|
} else {
|
|
parent_host_view_->RemoveGuestHostView(this);
|
|
}
|
|
parent_host_view_ = nullptr;
|
|
}
|
|
|
|
if (render_widget_host_ && !is_destroyed_) {
|
|
is_destroyed_ = true;
|
|
// Results in a call to Destroy().
|
|
render_widget_host_->ShutdownAndDestroyWidget(true);
|
|
}
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::AddGuestHostView(
|
|
OffScreenRenderWidgetHostView* guest_host) {
|
|
guest_host_views_.insert(guest_host);
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::RemoveGuestHostView(
|
|
OffScreenRenderWidgetHostView* guest_host) {
|
|
guest_host_views_.erase(guest_host);
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::AddViewProxy(OffscreenViewProxy* proxy) {
|
|
proxy->SetObserver(this);
|
|
proxy_views_.insert(proxy);
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::RemoveViewProxy(OffscreenViewProxy* proxy) {
|
|
proxy->RemoveObserver();
|
|
proxy_views_.erase(proxy);
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::ProxyViewDestroyed(
|
|
OffscreenViewProxy* proxy) {
|
|
proxy_views_.erase(proxy);
|
|
Invalidate();
|
|
}
|
|
|
|
bool OffScreenRenderWidgetHostView::IsOffscreen() const {
|
|
return true;
|
|
}
|
|
|
|
std::unique_ptr<viz::HostDisplayClient>
|
|
OffScreenRenderWidgetHostView::CreateHostDisplayClient(
|
|
ui::Compositor* compositor) {
|
|
host_display_client_ = new OffScreenHostDisplayClient(
|
|
gfx::kNullAcceleratedWidget,
|
|
base::BindRepeating(&OffScreenRenderWidgetHostView::OnPaint,
|
|
weak_ptr_factory_.GetWeakPtr()));
|
|
host_display_client_->SetActive(IsPainting());
|
|
return base::WrapUnique(host_display_client_);
|
|
}
|
|
|
|
bool OffScreenRenderWidgetHostView::InstallTransparency() {
|
|
if (transparent_) {
|
|
SetBackgroundColor(SkColor());
|
|
compositor_->SetBackgroundColor(SK_ColorTRANSPARENT);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
#if defined(OS_MAC)
|
|
void OffScreenRenderWidgetHostView::SetActive(bool active) {}
|
|
|
|
void OffScreenRenderWidgetHostView::ShowDefinitionForSelection() {}
|
|
|
|
void OffScreenRenderWidgetHostView::SpeakSelection() {}
|
|
|
|
void OffScreenRenderWidgetHostView::SetWindowFrameInScreen(
|
|
const gfx::Rect& rect) {}
|
|
|
|
void OffScreenRenderWidgetHostView::ShowSharePicker(
|
|
const std::string& title,
|
|
const std::string& text,
|
|
const std::string& url,
|
|
const std::vector<std::string>& file_paths,
|
|
blink::mojom::ShareService::ShareCallback callback) {}
|
|
|
|
bool OffScreenRenderWidgetHostView::UpdateNSViewAndDisplay() {
|
|
return false;
|
|
}
|
|
#endif
|
|
|
|
void OffScreenRenderWidgetHostView::OnPaint(const gfx::Rect& damage_rect,
|
|
const SkBitmap& bitmap) {
|
|
backing_ = std::make_unique<SkBitmap>();
|
|
backing_->allocN32Pixels(bitmap.width(), bitmap.height(), !transparent_);
|
|
bitmap.readPixels(backing_->pixmap());
|
|
|
|
if (IsPopupWidget() && parent_callback_) {
|
|
parent_callback_.Run(this->popup_position_);
|
|
} else {
|
|
CompositeFrame(damage_rect);
|
|
}
|
|
}
|
|
|
|
gfx::Size OffScreenRenderWidgetHostView::SizeInPixels() {
|
|
float sf = GetDeviceScaleFactor();
|
|
if (IsPopupWidget()) {
|
|
return gfx::ToFlooredSize(
|
|
gfx::ConvertSizeToPixels(popup_position_.size(), sf));
|
|
} else {
|
|
return gfx::ToFlooredSize(
|
|
gfx::ConvertSizeToPixels(GetViewBounds().size(), sf));
|
|
}
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::CompositeFrame(
|
|
const gfx::Rect& damage_rect) {
|
|
HoldResize();
|
|
|
|
gfx::Size size_in_pixels = SizeInPixels();
|
|
|
|
SkBitmap frame;
|
|
|
|
// Optimize for the case when there is no popup
|
|
if (proxy_views_.empty() && !popup_host_view_) {
|
|
frame = GetBacking();
|
|
} else {
|
|
float sf = GetDeviceScaleFactor();
|
|
frame.allocN32Pixels(size_in_pixels.width(), size_in_pixels.height(),
|
|
false);
|
|
if (!GetBacking().drawsNothing()) {
|
|
SkCanvas canvas(frame);
|
|
canvas.writePixels(GetBacking(), 0, 0);
|
|
|
|
if (popup_host_view_ && !popup_host_view_->GetBacking().drawsNothing()) {
|
|
gfx::Rect rect = popup_host_view_->popup_position_;
|
|
gfx::Point origin_in_pixels =
|
|
gfx::ToFlooredPoint(gfx::ConvertPointToPixels(rect.origin(), sf));
|
|
canvas.writePixels(popup_host_view_->GetBacking(), origin_in_pixels.x(),
|
|
origin_in_pixels.y());
|
|
}
|
|
|
|
for (auto* proxy_view : proxy_views_) {
|
|
gfx::Rect rect = proxy_view->GetBounds();
|
|
gfx::Point origin_in_pixels =
|
|
gfx::ToFlooredPoint(gfx::ConvertPointToPixels(rect.origin(), sf));
|
|
canvas.writePixels(*proxy_view->GetBitmap(), origin_in_pixels.x(),
|
|
origin_in_pixels.y());
|
|
}
|
|
}
|
|
}
|
|
|
|
paint_callback_running_ = true;
|
|
callback_.Run(gfx::IntersectRects(gfx::Rect(size_in_pixels), damage_rect),
|
|
frame);
|
|
paint_callback_running_ = false;
|
|
|
|
ReleaseResize();
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::OnPopupPaint(const gfx::Rect& damage_rect) {
|
|
InvalidateBounds(gfx::ToEnclosingRect(
|
|
gfx::ConvertRectToPixels(damage_rect, GetDeviceScaleFactor())));
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::OnProxyViewPaint(
|
|
const gfx::Rect& damage_rect) {
|
|
InvalidateBounds(gfx::ToEnclosingRect(
|
|
gfx::ConvertRectToPixels(damage_rect, GetDeviceScaleFactor())));
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::HoldResize() {
|
|
if (!hold_resize_)
|
|
hold_resize_ = true;
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::ReleaseResize() {
|
|
if (!hold_resize_)
|
|
return;
|
|
|
|
hold_resize_ = false;
|
|
if (pending_resize_) {
|
|
pending_resize_ = false;
|
|
base::PostTask(
|
|
FROM_HERE, {content::BrowserThread::UI},
|
|
base::BindOnce(
|
|
&OffScreenRenderWidgetHostView::SynchronizeVisualProperties,
|
|
weak_ptr_factory_.GetWeakPtr()));
|
|
}
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::SynchronizeVisualProperties() {
|
|
if (hold_resize_) {
|
|
if (!pending_resize_)
|
|
pending_resize_ = true;
|
|
return;
|
|
}
|
|
|
|
ResizeRootLayer(true);
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::SendMouseEvent(
|
|
const blink::WebMouseEvent& event) {
|
|
for (auto* proxy_view : proxy_views_) {
|
|
gfx::Rect bounds = proxy_view->GetBounds();
|
|
if (bounds.Contains(event.PositionInWidget().x(),
|
|
event.PositionInWidget().y())) {
|
|
blink::WebMouseEvent proxy_event(event);
|
|
proxy_event.SetPositionInWidget(
|
|
proxy_event.PositionInWidget().x() - bounds.x(),
|
|
proxy_event.PositionInWidget().y() - bounds.y());
|
|
|
|
ui::MouseEvent ui_event = UiMouseEventFromWebMouseEvent(proxy_event);
|
|
proxy_view->OnEvent(&ui_event);
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (!IsPopupWidget()) {
|
|
if (popup_host_view_ &&
|
|
popup_host_view_->popup_position_.Contains(
|
|
event.PositionInWidget().x(), event.PositionInWidget().y())) {
|
|
blink::WebMouseEvent popup_event(event);
|
|
popup_event.SetPositionInWidget(
|
|
popup_event.PositionInWidget().x() -
|
|
popup_host_view_->popup_position_.x(),
|
|
popup_event.PositionInWidget().y() -
|
|
popup_host_view_->popup_position_.y());
|
|
|
|
popup_host_view_->ProcessMouseEvent(popup_event, ui::LatencyInfo());
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (!render_widget_host_)
|
|
return;
|
|
render_widget_host_->ForwardMouseEvent(event);
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::SendMouseWheelEvent(
|
|
const blink::WebMouseWheelEvent& event) {
|
|
for (auto* proxy_view : proxy_views_) {
|
|
gfx::Rect bounds = proxy_view->GetBounds();
|
|
if (bounds.Contains(event.PositionInWidget().x(),
|
|
event.PositionInWidget().y())) {
|
|
blink::WebMouseWheelEvent proxy_event(event);
|
|
proxy_event.SetPositionInWidget(
|
|
proxy_event.PositionInWidget().x() - bounds.x(),
|
|
proxy_event.PositionInWidget().y() - bounds.y());
|
|
|
|
ui::MouseWheelEvent ui_event =
|
|
UiMouseWheelEventFromWebMouseEvent(proxy_event);
|
|
proxy_view->OnEvent(&ui_event);
|
|
return;
|
|
}
|
|
}
|
|
|
|
blink::WebMouseWheelEvent mouse_wheel_event(event);
|
|
|
|
bool should_route_event =
|
|
render_widget_host_->delegate() &&
|
|
render_widget_host_->delegate()->GetInputEventRouter();
|
|
mouse_wheel_phase_handler_.SendWheelEndForTouchpadScrollingIfNeeded(
|
|
should_route_event);
|
|
mouse_wheel_phase_handler_.AddPhaseIfNeededAndScheduleEndEvent(
|
|
mouse_wheel_event, false);
|
|
|
|
if (!IsPopupWidget()) {
|
|
if (popup_host_view_) {
|
|
if (popup_host_view_->popup_position_.Contains(
|
|
mouse_wheel_event.PositionInWidget().x(),
|
|
mouse_wheel_event.PositionInWidget().y())) {
|
|
blink::WebMouseWheelEvent popup_mouse_wheel_event(mouse_wheel_event);
|
|
popup_mouse_wheel_event.SetPositionInWidget(
|
|
mouse_wheel_event.PositionInWidget().x() -
|
|
popup_host_view_->popup_position_.x(),
|
|
mouse_wheel_event.PositionInWidget().y() -
|
|
popup_host_view_->popup_position_.y());
|
|
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);
|
|
return;
|
|
} else {
|
|
// Scrolling outside of the popup widget so destroy it.
|
|
// Execute asynchronously to avoid deleting the widget from inside some
|
|
// other callback.
|
|
base::PostTask(
|
|
FROM_HERE, {content::BrowserThread::UI},
|
|
base::BindOnce(&OffScreenRenderWidgetHostView::CancelWidget,
|
|
popup_host_view_->weak_ptr_factory_.GetWeakPtr()));
|
|
}
|
|
} 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(mouse_wheel_event.PositionInWidget().x(),
|
|
mouse_wheel_event.PositionInWidget().y())) {
|
|
blink::WebMouseWheelEvent guest_mouse_wheel_event(mouse_wheel_event);
|
|
guest_mouse_wheel_event.SetPositionInWidget(
|
|
mouse_wheel_event.PositionInWidget().x() - guest_bounds.x(),
|
|
mouse_wheel_event.PositionInWidget().y() - guest_bounds.y());
|
|
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);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (!render_widget_host_)
|
|
return;
|
|
render_widget_host_->ForwardWheelEvent(event);
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::SetPainting(bool painting) {
|
|
painting_ = painting;
|
|
|
|
if (popup_host_view_) {
|
|
popup_host_view_->SetPainting(painting);
|
|
}
|
|
|
|
for (auto* guest_host_view : guest_host_views_)
|
|
guest_host_view->SetPainting(painting);
|
|
|
|
if (video_consumer_) {
|
|
video_consumer_->SetActive(IsPainting());
|
|
} else if (host_display_client_) {
|
|
host_display_client_->SetActive(IsPainting());
|
|
}
|
|
}
|
|
|
|
bool OffScreenRenderWidgetHostView::IsPainting() const {
|
|
return painting_;
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::SetFrameRate(int frame_rate) {
|
|
if (parent_host_view_) {
|
|
if (parent_host_view_->GetFrameRate() == GetFrameRate())
|
|
return;
|
|
|
|
frame_rate_ = parent_host_view_->GetFrameRate();
|
|
} else {
|
|
if (frame_rate <= 0)
|
|
frame_rate = 1;
|
|
if (frame_rate > 240)
|
|
frame_rate = 240;
|
|
|
|
frame_rate_ = frame_rate;
|
|
}
|
|
|
|
SetupFrameRate(true);
|
|
|
|
if (video_consumer_) {
|
|
video_consumer_->SetFrameRate(GetFrameRate());
|
|
}
|
|
|
|
for (auto* guest_host_view : guest_host_views_)
|
|
guest_host_view->SetFrameRate(frame_rate);
|
|
}
|
|
|
|
int OffScreenRenderWidgetHostView::GetFrameRate() const {
|
|
return frame_rate_;
|
|
}
|
|
|
|
ui::Layer* OffScreenRenderWidgetHostView::GetRootLayer() const {
|
|
return root_layer_.get();
|
|
}
|
|
|
|
const viz::LocalSurfaceId& OffScreenRenderWidgetHostView::GetLocalSurfaceId()
|
|
const {
|
|
return delegated_frame_host_surface_id_;
|
|
}
|
|
|
|
content::DelegatedFrameHost*
|
|
OffScreenRenderWidgetHostView::GetDelegatedFrameHost() const {
|
|
return delegated_frame_host_.get();
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::SetupFrameRate(bool force) {
|
|
if (!force && frame_rate_threshold_us_ != 0)
|
|
return;
|
|
|
|
frame_rate_threshold_us_ = 1000000 / frame_rate_;
|
|
|
|
if (compositor_) {
|
|
compositor_->SetDisplayVSyncParameters(
|
|
base::TimeTicks::Now(), base::Microseconds(frame_rate_threshold_us_));
|
|
}
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::Invalidate() {
|
|
InvalidateBounds(gfx::Rect(GetRequestedRendererSize()));
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::InvalidateBounds(const gfx::Rect& bounds) {
|
|
CompositeFrame(bounds);
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::ResizeRootLayer(bool force) {
|
|
SetupFrameRate(false);
|
|
|
|
display::Display display =
|
|
display::Screen::GetScreen()->GetDisplayNearestView(GetNativeView());
|
|
const float scaleFactor = display.device_scale_factor();
|
|
float sf = GetDeviceScaleFactor();
|
|
const bool scaleFactorDidChange = scaleFactor != sf;
|
|
|
|
// Initialize a screen_infos_ struct as needed, to cache the scale factor.
|
|
if (screen_infos_.screen_infos.empty()) {
|
|
UpdateScreenInfo();
|
|
}
|
|
screen_infos_.mutable_current().device_scale_factor = scaleFactor;
|
|
|
|
gfx::Size size;
|
|
if (!IsPopupWidget())
|
|
size = GetViewBounds().size();
|
|
else
|
|
size = popup_position_.size();
|
|
|
|
if (!force && !scaleFactorDidChange &&
|
|
size == GetRootLayer()->bounds().size())
|
|
return;
|
|
|
|
GetRootLayer()->SetBounds(gfx::Rect(size));
|
|
|
|
const gfx::Size& size_in_pixels =
|
|
gfx::ToFlooredSize(gfx::ConvertSizeToPixels(size, sf));
|
|
|
|
if (compositor_) {
|
|
compositor_allocator_.GenerateId();
|
|
compositor_surface_id_ = compositor_allocator_.GetCurrentLocalSurfaceId();
|
|
compositor_->SetScaleAndSize(sf, size_in_pixels, compositor_surface_id_);
|
|
}
|
|
|
|
delegated_frame_host_allocator_.GenerateId();
|
|
delegated_frame_host_surface_id_ =
|
|
delegated_frame_host_allocator_.GetCurrentLocalSurfaceId();
|
|
|
|
GetDelegatedFrameHost()->EmbedSurface(
|
|
delegated_frame_host_surface_id_, size,
|
|
cc::DeadlinePolicy::UseDefaultDeadline());
|
|
|
|
// Note that |render_widget_host_| will retrieve resize parameters from the
|
|
// DelegatedFrameHost, so it must have SynchronizeVisualProperties called
|
|
// after.
|
|
if (render_widget_host_) {
|
|
render_widget_host_->SynchronizeVisualProperties();
|
|
}
|
|
}
|
|
|
|
viz::FrameSinkId OffScreenRenderWidgetHostView::AllocateFrameSinkId() {
|
|
return viz::FrameSinkId(
|
|
base::checked_cast<uint32_t>(render_widget_host_->GetProcess()->GetID()),
|
|
base::checked_cast<uint32_t>(render_widget_host_->GetRoutingID()));
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::UpdateBackgroundColorFromRenderer(
|
|
SkColor color) {
|
|
if (color == background_color_)
|
|
return;
|
|
background_color_ = color;
|
|
|
|
bool opaque = SkColorGetA(color) == SK_AlphaOPAQUE;
|
|
GetRootLayer()->SetFillsBoundsOpaquely(opaque);
|
|
GetRootLayer()->SetColor(color);
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::NotifyHostAndDelegateOnWasShown(
|
|
blink::mojom::RecordContentToVisibleTimeRequestPtr) {
|
|
NOTREACHED();
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::RequestPresentationTimeFromHostOrDelegate(
|
|
blink::mojom::RecordContentToVisibleTimeRequestPtr) {
|
|
NOTREACHED();
|
|
}
|
|
|
|
void OffScreenRenderWidgetHostView::
|
|
CancelPresentationTimeRequestForHostAndDelegate() {
|
|
NOTREACHED();
|
|
}
|
|
|
|
} // namespace electron
|