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.
|
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#ifndef SHELL_BROWSER_OSR_OSR_WEB_CONTENTS_VIEW_H_
|
|
|
|
#define SHELL_BROWSER_OSR_OSR_WEB_CONTENTS_VIEW_H_
|
2016-07-20 09:30:06 +00:00
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/native_window.h"
|
|
|
|
#include "shell/browser/native_window_observer.h"
|
2018-11-30 05:25:02 +00:00
|
|
|
|
2019-04-17 21:10:04 +00:00
|
|
|
#include "content/browser/renderer_host/render_view_host_delegate_view.h" // nogncheck
|
|
|
|
#include "content/browser/web_contents/web_contents_view.h" // nogncheck
|
2016-07-27 12:36:22 +00:00
|
|
|
#include "content/public/browser/web_contents.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/osr/osr_render_widget_host_view.h"
|
2016-07-20 09:30:06 +00:00
|
|
|
|
2020-08-12 18:33:58 +00:00
|
|
|
#if defined(OS_MAC)
|
2016-08-04 06:34:29 +00:00
|
|
|
#ifdef __OBJC__
|
|
|
|
@class OffScreenView;
|
|
|
|
#else
|
|
|
|
class OffScreenView;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2016-07-20 09:30:06 +00:00
|
|
|
|
2016-07-25 13:55:00 +00:00
|
|
|
class OffScreenWebContentsView : public content::WebContentsView,
|
2018-11-30 05:25:02 +00:00
|
|
|
public content::RenderViewHostDelegateView,
|
|
|
|
public NativeWindowObserver {
|
2016-07-31 10:19:56 +00:00
|
|
|
public:
|
2016-08-04 04:03:24 +00:00
|
|
|
OffScreenWebContentsView(bool transparent, const OnPaintCallback& callback);
|
2018-05-04 06:45:12 +00:00
|
|
|
~OffScreenWebContentsView() override;
|
2016-07-29 12:50:27 +00:00
|
|
|
|
2016-07-27 12:36:22 +00:00
|
|
|
void SetWebContents(content::WebContents*);
|
2018-11-30 05:25:02 +00:00
|
|
|
void SetNativeWindow(NativeWindow* window);
|
|
|
|
|
|
|
|
// NativeWindowObserver:
|
|
|
|
void OnWindowResize() override;
|
|
|
|
void OnWindowClosed() override;
|
|
|
|
|
|
|
|
gfx::Size GetSize();
|
2016-07-20 09:30:06 +00:00
|
|
|
|
2016-08-04 04:03:24 +00:00
|
|
|
// content::WebContentsView:
|
2016-07-20 09:30:06 +00:00
|
|
|
gfx::NativeView GetNativeView() const override;
|
|
|
|
gfx::NativeView GetContentNativeView() const override;
|
|
|
|
gfx::NativeWindow GetTopLevelNativeWindow() const override;
|
2020-05-26 20:06:26 +00:00
|
|
|
gfx::Rect GetContainerBounds() const override;
|
2016-07-20 09:30:06 +00:00
|
|
|
void Focus() override;
|
|
|
|
void SetInitialFocus() override;
|
|
|
|
void StoreFocus() override;
|
|
|
|
void RestoreFocus() override;
|
2018-05-15 01:59:22 +00:00
|
|
|
void FocusThroughTabTraversal(bool reverse) override;
|
2016-07-20 09:30:06 +00:00
|
|
|
content::DropData* GetDropData() const override;
|
|
|
|
gfx::Rect GetViewBounds() const override;
|
2019-09-18 19:58:00 +00:00
|
|
|
void CreateView(gfx::NativeView context) override;
|
2016-07-20 09:30:06 +00:00
|
|
|
content::RenderWidgetHostViewBase* CreateViewForWidget(
|
2019-12-11 00:22:35 +00:00
|
|
|
content::RenderWidgetHost* render_widget_host) override;
|
2019-01-30 17:33:32 +00:00
|
|
|
content::RenderWidgetHostViewBase* CreateViewForChildWidget(
|
2016-07-20 09:30:06 +00:00
|
|
|
content::RenderWidgetHost* render_widget_host) override;
|
|
|
|
void SetPageTitle(const base::string16& title) override;
|
2018-10-11 13:14:01 +00:00
|
|
|
void RenderViewReady() override;
|
|
|
|
void RenderViewHostChanged(content::RenderViewHost* old_host,
|
|
|
|
content::RenderViewHost* new_host) override;
|
2016-07-20 09:30:06 +00:00
|
|
|
void SetOverscrollControllerEnabled(bool enabled) override;
|
|
|
|
|
2020-08-12 18:33:58 +00:00
|
|
|
#if defined(OS_MAC)
|
2019-04-17 21:10:04 +00:00
|
|
|
bool CloseTabAfterEventTrackingIfNeeded() override;
|
2016-07-20 09:30:06 +00:00
|
|
|
#endif
|
|
|
|
|
2016-07-29 22:51:19 +00:00
|
|
|
// content::RenderViewHostDelegateView
|
2017-01-24 05:06:48 +00:00
|
|
|
void StartDragging(const content::DropData& drop_data,
|
|
|
|
blink::WebDragOperationsMask allowed_ops,
|
|
|
|
const gfx::ImageSkia& image,
|
|
|
|
const gfx::Vector2d& image_offset,
|
2020-09-21 08:00:36 +00:00
|
|
|
const blink::mojom::DragEventSourceInfo& event_info,
|
2017-01-24 05:06:48 +00:00
|
|
|
content::RenderWidgetHostImpl* source_rwh) override;
|
2016-07-25 13:55:00 +00:00
|
|
|
void UpdateDragCursor(blink::WebDragOperation operation) override;
|
|
|
|
|
2018-01-25 13:46:30 +00:00
|
|
|
void SetPainting(bool painting);
|
|
|
|
bool IsPainting() const;
|
|
|
|
void SetFrameRate(int frame_rate);
|
|
|
|
int GetFrameRate() const;
|
|
|
|
|
2016-07-31 10:19:56 +00:00
|
|
|
private:
|
2020-08-12 18:33:58 +00:00
|
|
|
#if defined(OS_MAC)
|
2016-08-04 06:34:29 +00:00
|
|
|
void PlatformCreate();
|
|
|
|
void PlatformDestroy();
|
|
|
|
#endif
|
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
OffScreenRenderWidgetHostView* GetView() const;
|
|
|
|
|
2018-11-30 05:25:02 +00:00
|
|
|
NativeWindow* native_window_;
|
|
|
|
|
2016-08-01 11:27:39 +00:00
|
|
|
const bool transparent_;
|
2018-05-21 22:18:38 +00:00
|
|
|
bool painting_ = true;
|
|
|
|
int frame_rate_ = 60;
|
2016-08-04 04:03:24 +00:00
|
|
|
OnPaintCallback callback_;
|
2016-08-01 11:27:39 +00:00
|
|
|
|
2016-08-03 04:46:34 +00:00
|
|
|
// Weak refs.
|
2018-05-21 22:18:38 +00:00
|
|
|
content::WebContents* web_contents_ = nullptr;
|
2016-08-04 06:34:29 +00:00
|
|
|
|
2020-08-12 18:33:58 +00:00
|
|
|
#if defined(OS_MAC)
|
2016-08-04 06:34:29 +00:00
|
|
|
OffScreenView* offScreenView_;
|
|
|
|
#endif
|
2016-07-20 09:30:06 +00:00
|
|
|
};
|
2016-07-20 09:32:59 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2016-07-20 09:30:06 +00:00
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#endif // SHELL_BROWSER_OSR_OSR_WEB_CONTENTS_VIEW_H_
|