use electron nativewindow

This commit is contained in:
Heilig Benedek 2016-07-27 14:36:22 +02:00
parent 8392ece321
commit a39bb35744
6 changed files with 34 additions and 11 deletions

View file

@ -313,10 +313,12 @@ WebContents::WebContents(v8::Isolate* isolate,
} else { } else {
content::WebContents::CreateParams params(session->browser_context()); content::WebContents::CreateParams params(session->browser_context());
params.view = new OffScreenWebContentsView(); auto view = new OffScreenWebContentsView();
params.delegate_view = (content::RenderViewHostDelegateView *)params.view; params.view = view;
params.delegate_view = view;
web_contents = content::WebContents::Create(params); web_contents = content::WebContents::Create(params);
view->SetWebContents(web_contents);
} }
Observe(web_contents); Observe(web_contents);

View file

@ -1257,13 +1257,13 @@ void NativeWindowViews::HandleKeyboardEvent(
} }
} }
gfx::Size NativeWindowViews::GetMinimumSize() { /*gfx::Size NativeWindowViews::GetMinimumSize() {
return NativeWindow::GetMinimumSize(); return NativeWindow::GetMinimumSize();
} }
gfx::Size NativeWindowViews::GetMaximumSize() { gfx::Size NativeWindowViews::GetMaximumSize() {
return NativeWindow::GetMaximumSize(); return NativeWindow::GetMaximumSize();
} }*/
bool NativeWindowViews::AcceleratorPressed(const ui::Accelerator& accelerator) { bool NativeWindowViews::AcceleratorPressed(const ui::Accelerator& accelerator) {
return accelerator_util::TriggerAcceleratorTableCommand( return accelerator_util::TriggerAcceleratorTableCommand(

View file

@ -9,7 +9,7 @@
namespace atom { namespace atom {
OffScreenWebContentsView::OffScreenWebContentsView() { OffScreenWebContentsView::OffScreenWebContentsView() : web_contents_(nullptr) {
// std::cout << "OffScreenWebContentsView" << std::endl; // std::cout << "OffScreenWebContentsView" << std::endl;
//std::this_thread::sleep_for(std::chrono::milliseconds(10000)); //std::this_thread::sleep_for(std::chrono::milliseconds(10000));
} }
@ -17,6 +17,11 @@ OffScreenWebContentsView::~OffScreenWebContentsView() {
// std::cout << "~OffScreenWebContentsView" << std::endl; // 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. // Returns the native widget that contains the contents of the tab.
gfx::NativeView OffScreenWebContentsView::GetNativeView() const{ gfx::NativeView OffScreenWebContentsView::GetNativeView() const{
// std::cout << "GetNativeView" << std::endl; // std::cout << "GetNativeView" << std::endl;
@ -93,6 +98,7 @@ gfx::Rect OffScreenWebContentsView::GetViewBounds() const{
void OffScreenWebContentsView::CreateView( void OffScreenWebContentsView::CreateView(
const gfx::Size& initial_size, gfx::NativeView context){ const gfx::Size& initial_size, gfx::NativeView context){
std::cout << context << std::endl;
// std::cout << "CreateView" << std::endl; // std::cout << "CreateView" << std::endl;
// std::cout << initial_size.width() << "x" << initial_size.height() << std::endl; // std::cout << initial_size.width() << "x" << initial_size.height() << std::endl;
} }
@ -109,7 +115,8 @@ content::RenderWidgetHostViewBase*
OffScreenWebContentsView::CreateViewForWidget( OffScreenWebContentsView::CreateViewForWidget(
content::RenderWidgetHost* render_widget_host, bool is_guest_view_hack){ content::RenderWidgetHost* render_widget_host, bool is_guest_view_hack){
// std::cout << "CreateViewForWidget" << std::endl; // 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_; return view_;
} }
@ -118,7 +125,8 @@ content::RenderWidgetHostViewBase*
OffScreenWebContentsView::CreateViewForPopupWidget( OffScreenWebContentsView::CreateViewForPopupWidget(
content::RenderWidgetHost* render_widget_host){ content::RenderWidgetHost* render_widget_host){
// std::cout << "CreateViewForPopupWidget" << std::endl; // 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_; return view_;
} }

View file

@ -7,6 +7,7 @@
#include "content/browser/renderer_host/render_view_host_delegate_view.h" #include "content/browser/renderer_host/render_view_host_delegate_view.h"
#include "content/browser/web_contents/web_contents_view.h" #include "content/browser/web_contents/web_contents_view.h"
#include "content/public/browser/web_contents.h"
namespace atom { namespace atom {
@ -15,6 +16,8 @@ class OffScreenWebContentsView : public content::WebContentsView,
public: public:
OffScreenWebContentsView(); OffScreenWebContentsView();
~OffScreenWebContentsView(); ~OffScreenWebContentsView();
void SetWebContents(content::WebContents*);
gfx::NativeView GetNativeView() const override; gfx::NativeView GetNativeView() const override;
gfx::NativeView GetContentNativeView() const override; gfx::NativeView GetContentNativeView() const override;
@ -61,6 +64,7 @@ public:
private: private:
content::RenderWidgetHostViewBase* view_; content::RenderWidgetHostViewBase* view_;
content::WebContents* web_contents_;
}; };
} // namespace atom } // namespace atom

View file

@ -19,6 +19,7 @@
#include "base/location.h" #include "base/location.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/views/widget/widget.h"
#include <iostream> #include <iostream>
#include <chrono> #include <chrono>
#include <thread> #include <thread>
@ -399,8 +400,10 @@ class CefBeginFrameTimer : public cc::DelayBasedTimeSourceClient {
DISALLOW_COPY_AND_ASSIGN(CefBeginFrameTimer); 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)), : render_widget_host_(content::RenderWidgetHostImpl::From(host)),
native_window_(native_window),
software_output_device_(NULL), software_output_device_(NULL),
frame_rate_threshold_ms_(0), frame_rate_threshold_ms_(0),
scale_factor_(1.0f), scale_factor_(1.0f),
@ -417,7 +420,8 @@ OffScreenWindow::OffScreenWindow(content::RenderWidgetHost* host)
root_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); root_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR));
CreatePlatformWidget(); //CreatePlatformWidget();
compositor_widget_ = native_window_->GetAcceleratedWidget();
#if !defined(OS_MACOSX) #if !defined(OS_MACOSX)
// On OS X the ui::Compositor is created/owned by the platform view. // 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 { gfx::NativeView OffScreenWindow::GetNativeView() const {
// std::cout << "GetNativeView" << std::endl; // std::cout << "GetNativeView" << std::endl;
return gfx::NativeView(); auto widget = views::Widget::GetWidgetForNativeWindow(
native_window_->GetNativeWindow());
return widget->GetNativeView();
} }
gfx::NativeViewAccessible OffScreenWindow::GetNativeViewAccessible() { gfx::NativeViewAccessible OffScreenWindow::GetNativeViewAccessible() {

View file

@ -5,6 +5,8 @@
#ifndef ATOM_BROWSER_OSR_WINDOW_H_ #ifndef ATOM_BROWSER_OSR_WINDOW_H_
#define 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/render_widget_host_view_base.h"
#include "content/browser/renderer_host/delegated_frame_host.h" #include "content/browser/renderer_host/delegated_frame_host.h"
#include "content/browser/renderer_host/resize_lock.h" #include "content/browser/renderer_host/resize_lock.h"
@ -66,7 +68,7 @@ public:
typedef base::Callback<void(const gfx::Rect&,int,int,void*)> typedef base::Callback<void(const gfx::Rect&,int,int,void*)>
OnPaintCallback; OnPaintCallback;
OffScreenWindow(content::RenderWidgetHost*); OffScreenWindow(content::RenderWidgetHost*, NativeWindow*);
~OffScreenWindow(); ~OffScreenWindow();
void CreatePlatformWidget(); void CreatePlatformWidget();
@ -196,6 +198,7 @@ private:
void ResizeRootLayer(); void ResizeRootLayer();
content::RenderWidgetHostImpl* render_widget_host_; content::RenderWidgetHostImpl* render_widget_host_;
NativeWindow* native_window_;
std::unique_ptr<CefCopyFrameGenerator> copy_frame_generator_; std::unique_ptr<CefCopyFrameGenerator> copy_frame_generator_;
std::unique_ptr<CefBeginFrameTimer> begin_frame_timer_; std::unique_ptr<CefBeginFrameTimer> begin_frame_timer_;