electron/atom/browser/osr/osr_web_contents_view.cc

221 lines
6.2 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 "atom/browser/osr/osr_web_contents_view.h"
2016-07-20 09:30:06 +00:00
#include "content/public/browser/render_view_host.h"
2016-12-20 01:23:41 +00:00
#include "third_party/WebKit/public/platform/WebScreenInfo.h"
#include "ui/display/screen.h"
2016-12-20 01:23:41 +00:00
2016-07-20 09:30:06 +00:00
namespace atom {
OffScreenWebContentsView::OffScreenWebContentsView(
bool transparent, const OnPaintCallback& callback)
2016-08-03 04:46:34 +00:00
: transparent_(transparent),
callback_(callback),
2016-08-03 04:46:34 +00:00
web_contents_(nullptr) {
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() {
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;
}
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 (!web_contents_) return gfx::NativeView();
auto relay = NativeWindowRelay::FromWebContents(web_contents_);
if (!relay) return gfx::NativeView();
return relay->window->GetNativeView();
2016-07-20 09:30:06 +00:00
}
2016-07-30 18:39:17 +00:00
gfx::NativeView OffScreenWebContentsView::GetContentNativeView() const {
if (!web_contents_) return gfx::NativeView();
auto relay = NativeWindowRelay::FromWebContents(web_contents_);
if (!relay) return gfx::NativeView();
return relay->window->GetNativeView();
2016-07-20 09:30:06 +00:00
}
2016-07-30 18:39:17 +00:00
gfx::NativeWindow OffScreenWebContentsView::GetTopLevelNativeWindow() const {
if (!web_contents_) return gfx::NativeWindow();
auto relay = NativeWindowRelay::FromWebContents(web_contents_);
if (!relay) return gfx::NativeWindow();
return relay->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();
}
2016-07-30 18:39:17 +00:00
void OffScreenWebContentsView::SizeContents(const gfx::Size& size) {
2016-07-20 09:30:06 +00:00
}
2016-07-30 18:39:17 +00:00
void OffScreenWebContentsView::Focus() {
2016-07-20 09:30:06 +00:00
}
2016-07-30 18:39:17 +00:00
void OffScreenWebContentsView::SetInitialFocus() {
2016-07-20 09:30:06 +00:00
}
2016-07-30 18:39:17 +00:00
void OffScreenWebContentsView::StoreFocus() {
2016-07-20 09:30:06 +00:00
}
2016-07-30 18:39:17 +00:00
void OffScreenWebContentsView::RestoreFocus() {
2016-07-20 09:30:06 +00:00
}
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
}
2016-07-30 18:39:17 +00:00
void OffScreenWebContentsView::CreateView(const gfx::Size& initial_size,
gfx::NativeView context) {
2016-07-20 09:30:06 +00:00
}
content::RenderWidgetHostViewBase*
OffScreenWebContentsView::CreateViewForWidget(
content::RenderWidgetHost* render_widget_host, bool is_guest_view_hack) {
if (render_widget_host->GetView()) {
return static_cast<content::RenderWidgetHostViewBase*>(
render_widget_host->GetView());
}
2016-07-27 12:36:22 +00:00
auto relay = NativeWindowRelay::FromWebContents(web_contents_);
return new OffScreenRenderWidgetHostView(
transparent_,
callback_,
render_widget_host,
nullptr,
relay->window.get());
}
content::RenderWidgetHostViewBase*
OffScreenWebContentsView::CreateViewForWidget(
content::RenderWidgetHost* render_widget_host,
content::RenderWidgetHost* embedder_render_widget_host) {
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());
}
auto relay = NativeWindowRelay::FromWebContents(web_contents_);
return new OffScreenRenderWidgetHostView(
transparent_,
callback_,
render_widget_host,
embedder_host_view,
relay->window.get());
2016-07-20 09:30:06 +00:00
}
content::RenderWidgetHostViewBase*
OffScreenWebContentsView::CreateViewForPopupWidget(
2016-07-30 18:39:17 +00:00
content::RenderWidgetHost* render_widget_host) {
2016-07-27 12:36:22 +00:00
auto relay = NativeWindowRelay::FromWebContents(web_contents_);
return new OffScreenRenderWidgetHostView(
transparent_,
callback_,
render_widget_host,
GetView(),
relay->window.get());
2016-07-20 09:30:06 +00:00
}
2016-07-30 18:39:17 +00:00
void OffScreenWebContentsView::SetPageTitle(const base::string16& title) {
2016-07-20 09:30:06 +00:00
}
2016-07-30 18:39:17 +00:00
void OffScreenWebContentsView::RenderViewCreated(
content::RenderViewHost* host) {
if (GetView())
GetView()->InstallTransparency();
2016-07-20 09:30:06 +00:00
}
2016-07-30 18:39:17 +00:00
void OffScreenWebContentsView::RenderViewSwappedIn(
content::RenderViewHost* host) {
2016-07-20 09:30:06 +00:00
}
2016-07-30 18:39:17 +00:00
void OffScreenWebContentsView::SetOverscrollControllerEnabled(bool enabled) {
2016-07-20 09:30:06 +00:00
}
2016-11-30 07:30:03 +00:00
void OffScreenWebContentsView::GetScreenInfo(
2017-01-24 05:06:48 +00:00
content::ScreenInfo* screen_info) const {
screen_info->depth = 24;
screen_info->depth_per_component = 8;
screen_info->orientation_angle = 0;
screen_info->orientation_type =
content::SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY;
if (GetView()) {
screen_info->rect = gfx::Rect(GetView()->size());
screen_info->available_rect = gfx::Rect(GetView()->size());
screen_info->device_scale_factor = GetView()->scale_factor();
} else {
const display::Display display =
display::Screen::GetScreen()->GetPrimaryDisplay();
screen_info->rect = display.bounds();
screen_info->available_rect = display.work_area();
screen_info->device_scale_factor = display.device_scale_factor();
}
2016-11-30 07:30:03 +00:00
}
2016-07-20 09:30:06 +00:00
#if defined(OS_MACOSX)
void OffScreenWebContentsView::SetAllowOtherViews(bool allow) {
}
bool OffScreenWebContentsView::GetAllowOtherViews() const {
return false;
}
bool OffScreenWebContentsView::IsEventTracking() const {
return false;
}
void OffScreenWebContentsView::CloseTabAfterEventTracking() {
}
#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(
blink::WebDragOperation operation) {
}
OffScreenRenderWidgetHostView* OffScreenWebContentsView::GetView() const {
if (web_contents_) {
return static_cast<OffScreenRenderWidgetHostView*>(
web_contents_->GetRenderViewHost()->GetWidget()->GetView());
}
return nullptr;
}
2016-07-20 09:30:06 +00:00
} // namespace atom