From a39bb357446b0774d0ffe4f187b11b905238ebfb Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Wed, 27 Jul 2016 14:36:22 +0200 Subject: [PATCH] use electron nativewindow --- atom/browser/api/atom_api_web_contents.cc | 6 ++++-- atom/browser/native_window_views.cc | 4 ++-- atom/browser/osr_web_contents_view.cc | 14 +++++++++++--- atom/browser/osr_web_contents_view.h | 4 ++++ atom/browser/osr_window.cc | 12 +++++++++--- atom/browser/osr_window.h | 5 ++++- 6 files changed, 34 insertions(+), 11 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 54911a2a3baa..ed746fa6e739 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -313,10 +313,12 @@ WebContents::WebContents(v8::Isolate* isolate, } else { content::WebContents::CreateParams params(session->browser_context()); - params.view = new OffScreenWebContentsView(); - params.delegate_view = (content::RenderViewHostDelegateView *)params.view; + auto view = new OffScreenWebContentsView(); + params.view = view; + params.delegate_view = view; web_contents = content::WebContents::Create(params); + view->SetWebContents(web_contents); } Observe(web_contents); diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 5aeb7d436a26..066bca0b55f1 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -1257,13 +1257,13 @@ void NativeWindowViews::HandleKeyboardEvent( } } -gfx::Size NativeWindowViews::GetMinimumSize() { +/*gfx::Size NativeWindowViews::GetMinimumSize() { return NativeWindow::GetMinimumSize(); } gfx::Size NativeWindowViews::GetMaximumSize() { return NativeWindow::GetMaximumSize(); -} +}*/ bool NativeWindowViews::AcceleratorPressed(const ui::Accelerator& accelerator) { return accelerator_util::TriggerAcceleratorTableCommand( diff --git a/atom/browser/osr_web_contents_view.cc b/atom/browser/osr_web_contents_view.cc index a7cc4b652b65..a05153eb7317 100644 --- a/atom/browser/osr_web_contents_view.cc +++ b/atom/browser/osr_web_contents_view.cc @@ -9,7 +9,7 @@ namespace atom { -OffScreenWebContentsView::OffScreenWebContentsView() { +OffScreenWebContentsView::OffScreenWebContentsView() : web_contents_(nullptr) { // std::cout << "OffScreenWebContentsView" << std::endl; //std::this_thread::sleep_for(std::chrono::milliseconds(10000)); } @@ -17,6 +17,11 @@ OffScreenWebContentsView::~OffScreenWebContentsView() { // std::cout << "~OffScreenWebContentsView" << std::endl; } +void OffScreenWebContentsView::SetWebContents( + content::WebContents* web_contents) { + web_contents_ = web_contents; +} + // Returns the native widget that contains the contents of the tab. gfx::NativeView OffScreenWebContentsView::GetNativeView() const{ // std::cout << "GetNativeView" << std::endl; @@ -93,6 +98,7 @@ gfx::Rect OffScreenWebContentsView::GetViewBounds() const{ void OffScreenWebContentsView::CreateView( const gfx::Size& initial_size, gfx::NativeView context){ + std::cout << context << std::endl; // std::cout << "CreateView" << std::endl; // std::cout << initial_size.width() << "x" << initial_size.height() << std::endl; } @@ -109,7 +115,8 @@ content::RenderWidgetHostViewBase* OffScreenWebContentsView::CreateViewForWidget( content::RenderWidgetHost* render_widget_host, bool is_guest_view_hack){ // std::cout << "CreateViewForWidget" << std::endl; - view_ = new OffScreenWindow(render_widget_host); + auto relay = NativeWindowRelay::FromWebContents(web_contents_); + view_ = new OffScreenWindow(render_widget_host, relay->window.get()); return view_; } @@ -118,7 +125,8 @@ content::RenderWidgetHostViewBase* OffScreenWebContentsView::CreateViewForPopupWidget( content::RenderWidgetHost* render_widget_host){ // std::cout << "CreateViewForPopupWidget" << std::endl; - view_ = new OffScreenWindow(render_widget_host); + auto relay = NativeWindowRelay::FromWebContents(web_contents_); + view_ = new OffScreenWindow(render_widget_host, relay->window.get()); return view_; } diff --git a/atom/browser/osr_web_contents_view.h b/atom/browser/osr_web_contents_view.h index 543b9c4e28d5..4f1c358c075a 100644 --- a/atom/browser/osr_web_contents_view.h +++ b/atom/browser/osr_web_contents_view.h @@ -7,6 +7,7 @@ #include "content/browser/renderer_host/render_view_host_delegate_view.h" #include "content/browser/web_contents/web_contents_view.h" +#include "content/public/browser/web_contents.h" namespace atom { @@ -15,6 +16,8 @@ class OffScreenWebContentsView : public content::WebContentsView, public: OffScreenWebContentsView(); ~OffScreenWebContentsView(); + + void SetWebContents(content::WebContents*); gfx::NativeView GetNativeView() const override; gfx::NativeView GetContentNativeView() const override; @@ -61,6 +64,7 @@ public: private: content::RenderWidgetHostViewBase* view_; + content::WebContents* web_contents_; }; } // namespace atom diff --git a/atom/browser/osr_window.cc b/atom/browser/osr_window.cc index d78251ba62b1..4233d224e49f 100644 --- a/atom/browser/osr_window.cc +++ b/atom/browser/osr_window.cc @@ -19,6 +19,7 @@ #include "base/location.h" #include "base/time/time.h" #include "ui/gfx/native_widget_types.h" +#include "ui/views/widget/widget.h" #include #include #include @@ -399,8 +400,10 @@ class CefBeginFrameTimer : public cc::DelayBasedTimeSourceClient { DISALLOW_COPY_AND_ASSIGN(CefBeginFrameTimer); }; -OffScreenWindow::OffScreenWindow(content::RenderWidgetHost* host) +OffScreenWindow::OffScreenWindow( + content::RenderWidgetHost* host, NativeWindow* native_window) : render_widget_host_(content::RenderWidgetHostImpl::From(host)), + native_window_(native_window), software_output_device_(NULL), frame_rate_threshold_ms_(0), scale_factor_(1.0f), @@ -417,7 +420,8 @@ OffScreenWindow::OffScreenWindow(content::RenderWidgetHost* host) root_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); - CreatePlatformWidget(); + //CreatePlatformWidget(); + compositor_widget_ = native_window_->GetAcceleratedWidget(); #if !defined(OS_MACOSX) // On OS X the ui::Compositor is created/owned by the platform view. @@ -547,7 +551,9 @@ gfx::Vector2dF OffScreenWindow::GetLastScrollOffset() const { gfx::NativeView OffScreenWindow::GetNativeView() const { // std::cout << "GetNativeView" << std::endl; - return gfx::NativeView(); + auto widget = views::Widget::GetWidgetForNativeWindow( + native_window_->GetNativeWindow()); + return widget->GetNativeView(); } gfx::NativeViewAccessible OffScreenWindow::GetNativeViewAccessible() { diff --git a/atom/browser/osr_window.h b/atom/browser/osr_window.h index 4fefa4a62ac9..e851a545d5e9 100644 --- a/atom/browser/osr_window.h +++ b/atom/browser/osr_window.h @@ -5,6 +5,8 @@ #ifndef ATOM_BROWSER_OSR_WINDOW_H_ #define ATOM_BROWSER_OSR_WINDOW_H_ +#include "atom/browser/native_window.h" + #include "content/browser/renderer_host/render_widget_host_view_base.h" #include "content/browser/renderer_host/delegated_frame_host.h" #include "content/browser/renderer_host/resize_lock.h" @@ -66,7 +68,7 @@ public: typedef base::Callback OnPaintCallback; - OffScreenWindow(content::RenderWidgetHost*); + OffScreenWindow(content::RenderWidgetHost*, NativeWindow*); ~OffScreenWindow(); void CreatePlatformWidget(); @@ -196,6 +198,7 @@ private: void ResizeRootLayer(); content::RenderWidgetHostImpl* render_widget_host_; + NativeWindow* native_window_; std::unique_ptr copy_frame_generator_; std::unique_ptr begin_frame_timer_;