electron/shell/browser/osr/osr_web_contents_view.cc

219 lines
6 KiB
C++
Raw Normal View History

2016-07-30 19:35:14 +00:00
// Copyright (c) 2016 GitHub, Inc.
2016-07-20 09:30:06 +00:00
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/osr/osr_web_contents_view.h"
2016-07-20 09:30:06 +00:00
#include "content/browser/web_contents/web_contents_impl.h" // nogncheck
#include "content/public/browser/render_view_host.h"
#include "third_party/blink/public/platform/web_screen_info.h"
#include "ui/display/screen.h"
2016-12-20 01:23:41 +00:00
namespace electron {
2016-07-20 09:30:06 +00:00
OffScreenWebContentsView::OffScreenWebContentsView(
2018-04-18 01:55:30 +00:00
bool transparent,
const OnPaintCallback& callback)
: native_window_(nullptr), transparent_(transparent), callback_(callback) {
2016-08-04 06:34:29 +00:00
#if defined(OS_MACOSX)
PlatformCreate();
#endif
2016-07-20 09:30:06 +00:00
}
2016-07-29 12:50:27 +00:00
2016-07-20 09:30:06 +00:00
OffScreenWebContentsView::~OffScreenWebContentsView() {
if (native_window_)
native_window_->RemoveObserver(this);
2016-08-04 06:34:29 +00:00
#if defined(OS_MACOSX)
PlatformDestroy();
#endif
2016-07-20 09:30:06 +00:00
}
2016-07-27 12:36:22 +00:00
void OffScreenWebContentsView::SetWebContents(
content::WebContents* web_contents) {
web_contents_ = web_contents;
2017-04-12 18:54:03 +00:00
chore: bump chromium to bc8f70ed4cfe2262ea833750eaddb (master) (#22649) * chore: bump chromium in DEPS to 9321f32fb1b3af8fdfce55c7bbfacf3f75118dca * Update patches * Update electron_swiftshader_binaries deps https://chromium-review.googlesource.com/c/chromium/src/+/2056931 * Use Promise with RequestPointerLock calls https://chromium-review.googlesource.com/c/chromium/src/+/2069199 * Replace content::CursorInfo with ui::Cursor https://chromium-review.googlesource.com/c/chromium/src/+/1999201 * Convert MaterialDesignController to a true singleton. https://chromium-review.googlesource.com/c/chromium/src/+/2090877 * Drop WebContentsView::RenderViewCreated hook https://chromium-review.googlesource.com/c/chromium/src/+/2093535 * chore: bump chromium in DEPS to 6478123cfa0102ed754c70eb9bbdd391d676a4dd * Splitting context_menu_params.h into separate browser VS common parts. https://chromium-review.googlesource.com/c/chromium/src/+/2097468 * Fix DCHECK on OnThemeChanged() https://chromium-review.googlesource.com/c/chromium/src/+/2090713 * chore: bump chromium in DEPS to b0269bb003f699bc8ea7dcba8b0795ef963696d7 * Remove no longer needed patch * Check PointerLock requests for new options and update accordingly https://chromium-review.googlesource.com/c/chromium/src/+/2071788 * Address issues from review * Fixup compile error * Add additional library files * chore: bump chromium in DEPS to a41285fb8aebc8f70ed4cfe2262ea833750eaddb * Update patches Co-authored-by: John Kleinschmidt <jkleinsc@github.com>
2020-03-14 20:54:14 +00:00
if (GetView())
GetView()->InstallTransparency();
2016-07-27 12:36:22 +00:00
}
void OffScreenWebContentsView::SetNativeWindow(NativeWindow* window) {
if (native_window_)
native_window_->RemoveObserver(this);
native_window_ = window;
if (native_window_)
native_window_->AddObserver(this);
OnWindowResize();
}
void OffScreenWebContentsView::OnWindowResize() {
// In offscreen mode call RenderWidgetHostView's SetSize explicitly
if (GetView())
GetView()->SetSize(GetSize());
}
void OffScreenWebContentsView::OnWindowClosed() {
if (native_window_) {
native_window_->RemoveObserver(this);
native_window_ = nullptr;
}
}
gfx::Size OffScreenWebContentsView::GetSize() {
return native_window_ ? native_window_->GetSize() : gfx::Size();
}
2016-08-04 06:34:29 +00:00
#if !defined(OS_MACOSX)
2016-07-30 18:39:17 +00:00
gfx::NativeView OffScreenWebContentsView::GetNativeView() const {
if (!native_window_)
2018-04-18 01:55:30 +00:00
return gfx::NativeView();
return native_window_->GetNativeView();
2016-07-20 09:30:06 +00:00
}
2016-07-30 18:39:17 +00:00
gfx::NativeView OffScreenWebContentsView::GetContentNativeView() const {
if (!native_window_)
2018-04-18 01:55:30 +00:00
return gfx::NativeView();
return native_window_->GetNativeView();
2016-07-20 09:30:06 +00:00
}
2016-07-30 18:39:17 +00:00
gfx::NativeWindow OffScreenWebContentsView::GetTopLevelNativeWindow() const {
if (!native_window_)
2018-04-18 01:55:30 +00:00
return gfx::NativeWindow();
return native_window_->GetNativeWindow();
2016-07-20 09:30:06 +00:00
}
2016-08-04 06:34:29 +00:00
#endif
2016-07-20 09:30:06 +00:00
2016-07-30 18:39:17 +00:00
void OffScreenWebContentsView::GetContainerBounds(gfx::Rect* out) const {
2016-07-20 09:30:06 +00:00
*out = GetViewBounds();
}
2018-04-18 01:55:30 +00:00
void OffScreenWebContentsView::SizeContents(const gfx::Size& size) {}
2016-07-20 09:30:06 +00:00
2018-04-18 01:55:30 +00:00
void OffScreenWebContentsView::Focus() {}
2016-07-20 09:30:06 +00:00
2018-04-18 01:55:30 +00:00
void OffScreenWebContentsView::SetInitialFocus() {}
2016-07-20 09:30:06 +00:00
2018-04-18 01:55:30 +00:00
void OffScreenWebContentsView::StoreFocus() {}
2016-07-20 09:30:06 +00:00
2018-04-18 01:55:30 +00:00
void OffScreenWebContentsView::RestoreFocus() {}
2016-07-20 09:30:06 +00:00
2018-05-15 01:59:22 +00:00
void OffScreenWebContentsView::FocusThroughTabTraversal(bool reverse) {}
2016-07-30 18:39:17 +00:00
content::DropData* OffScreenWebContentsView::GetDropData() const {
2016-07-20 09:30:06 +00:00
return nullptr;
}
2016-07-30 18:39:17 +00:00
gfx::Rect OffScreenWebContentsView::GetViewBounds() const {
return GetView() ? GetView()->GetViewBounds() : gfx::Rect();
2016-07-20 09:30:06 +00:00
}
void OffScreenWebContentsView::CreateView(gfx::NativeView context) {}
2016-07-20 09:30:06 +00:00
content::RenderWidgetHostViewBase*
2018-04-18 01:55:30 +00:00
OffScreenWebContentsView::CreateViewForWidget(
content::RenderWidgetHost* render_widget_host) {
if (render_widget_host->GetView()) {
return static_cast<content::RenderWidgetHostViewBase*>(
render_widget_host->GetView());
}
2017-03-05 15:18:57 +00:00
return new OffScreenRenderWidgetHostView(
2018-04-18 01:55:30 +00:00
transparent_, painting_, GetFrameRate(), callback_, render_widget_host,
nullptr, GetSize());
}
2016-07-20 09:30:06 +00:00
content::RenderWidgetHostViewBase*
OffScreenWebContentsView::CreateViewForChildWidget(
2016-07-30 18:39:17 +00:00
content::RenderWidgetHost* render_widget_host) {
2018-04-18 01:55:30 +00:00
content::WebContentsImpl* web_contents_impl =
static_cast<content::WebContentsImpl*>(web_contents_);
2017-04-14 21:32:33 +00:00
2018-04-18 01:55:30 +00:00
OffScreenRenderWidgetHostView* view =
static_cast<OffScreenRenderWidgetHostView*>(
web_contents_impl->GetOuterWebContents()
? web_contents_impl->GetOuterWebContents()
->GetRenderWidgetHostView()
: web_contents_impl->GetRenderWidgetHostView());
2017-04-14 21:32:33 +00:00
return new OffScreenRenderWidgetHostView(transparent_, painting_,
view->GetFrameRate(), callback_,
render_widget_host, view, GetSize());
2016-07-20 09:30:06 +00:00
}
2018-04-18 01:55:30 +00:00
void OffScreenWebContentsView::SetPageTitle(const base::string16& title) {}
2016-07-20 09:30:06 +00:00
void OffScreenWebContentsView::RenderViewReady() {}
void OffScreenWebContentsView::RenderViewHostChanged(
content::RenderViewHost* old_host,
content::RenderViewHost* new_host) {}
2016-07-20 09:30:06 +00:00
2018-04-18 01:55:30 +00:00
void OffScreenWebContentsView::SetOverscrollControllerEnabled(bool enabled) {}
2016-07-20 09:30:06 +00:00
#if defined(OS_MACOSX)
bool OffScreenWebContentsView::CloseTabAfterEventTrackingIfNeeded() {
2016-07-20 09:30:06 +00:00
return false;
}
#endif // defined(OS_MACOSX)
void OffScreenWebContentsView::StartDragging(
const content::DropData& drop_data,
blink::WebDragOperationsMask allowed_ops,
const gfx::ImageSkia& image,
const gfx::Vector2d& image_offset,
2017-01-24 05:06:48 +00:00
const content::DragEventSourceInfo& event_info,
content::RenderWidgetHostImpl* source_rwh) {
2016-08-01 10:06:46 +00:00
if (web_contents_)
2017-01-24 05:06:48 +00:00
web_contents_->SystemDragEnded(source_rwh);
}
void OffScreenWebContentsView::UpdateDragCursor(
2018-04-18 01:55:30 +00:00
blink::WebDragOperation operation) {}
void OffScreenWebContentsView::SetPainting(bool painting) {
auto* view = GetView();
painting_ = painting;
if (view != nullptr) {
view->SetPainting(painting);
}
}
bool OffScreenWebContentsView::IsPainting() const {
auto* view = GetView();
if (view != nullptr) {
return view->IsPainting();
} else {
return painting_;
}
}
void OffScreenWebContentsView::SetFrameRate(int frame_rate) {
auto* view = GetView();
frame_rate_ = frame_rate;
if (view != nullptr) {
view->SetFrameRate(frame_rate);
}
}
int OffScreenWebContentsView::GetFrameRate() const {
auto* view = GetView();
if (view != nullptr) {
return view->GetFrameRate();
} else {
return frame_rate_;
}
}
OffScreenRenderWidgetHostView* OffScreenWebContentsView::GetView() const {
if (web_contents_) {
return static_cast<OffScreenRenderWidgetHostView*>(
web_contents_->GetRenderViewHost()->GetWidget()->GetView());
}
return nullptr;
}
} // namespace electron