summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Rossi <pierre.rossi@digia.com>2013-06-12 09:57:11 +0200
committerPierre Rossi <pierre.rossi@digia.com>2013-06-12 16:08:45 +0200
commit0f0c301265d0acd2ea15769b0930eb4054e54a3d (patch)
tree7b75c7b87f6f89374746b8e2b8973b134da84df4
parent6c455978062b8e39e7a8815c95b39c0aefc8da74 (diff)
Start simplifying WebContentsDelegateQt
Mostly removing duplicated code so far.
-rw-r--r--lib/lib.pro1
-rw-r--r--lib/qquickwebcontentsview.cpp7
-rw-r--r--lib/qwebcontentsview.cpp9
-rw-r--r--lib/web_contents_delegate_qt.cpp112
-rw-r--r--lib/web_contents_delegate_qt.h15
-rw-r--r--shared/native_view_container_qt.h2
6 files changed, 34 insertions, 112 deletions
diff --git a/lib/lib.pro b/lib/lib.pro
index f86bf8ac6..92b5e61b6 100644
--- a/lib/lib.pro
+++ b/lib/lib.pro
@@ -36,5 +36,6 @@ HEADERS = \
resource_context_qt.h \
url_request_context_getter_qt.h \
web_contents_delegate_qt.h \
+ web_contents_view_qt.h \
web_engine_context.h
diff --git a/lib/qquickwebcontentsview.cpp b/lib/qquickwebcontentsview.cpp
index 06ba95b79..154f4ea5e 100644
--- a/lib/qquickwebcontentsview.cpp
+++ b/lib/qquickwebcontentsview.cpp
@@ -51,9 +51,9 @@
#include "browser_context_qt.h"
#include "content_browser_client_qt.h"
#include "web_contents_delegate_qt.h"
+#include "web_contents_view_qt.h"
#include "web_engine_context.h"
-#include <QWidget>
#include <QUrl>
void QQuickWebContentsView::registerType()
@@ -76,7 +76,10 @@ QQuickWebContentsView::QQuickWebContentsView()
d->context = WebEngineContext::current();
content::BrowserContext* browser_context = static_cast<ContentBrowserClientQt*>(content::GetContentClient()->browser())->browser_context();
- d->webContentsDelegate.reset(WebContentsDelegateQt::CreateNewWindow(browser_context, GURL(std::string("http://qt-project.org/")), NULL, MSG_ROUTING_NONE, gfx::Size(), this));
+ d->webContentsDelegate.reset(WebContentsDelegateQt::CreateNewWindow(browser_context, GURL(std::string("http://qt-project.org/")), NULL, MSG_ROUTING_NONE, gfx::Size()));
+ WebContentsViewQt* content_view = static_cast<WebContentsViewQt*>(d->webContentsDelegate->web_contents()->GetView());
+ QQuickItem* windowContainer = content_view->windowContainer()->qQuickItem();
+ windowContainer->setParentItem(this);
}
QQuickWebContentsView::~QQuickWebContentsView()
diff --git a/lib/qwebcontentsview.cpp b/lib/qwebcontentsview.cpp
index 1f23fb0d1..35eed1823 100644
--- a/lib/qwebcontentsview.cpp
+++ b/lib/qwebcontentsview.cpp
@@ -51,8 +51,10 @@
#include "browser_context_qt.h"
#include "content_browser_client_qt.h"
#include "web_contents_delegate_qt.h"
+#include "web_contents_view_qt.h"
#include "web_engine_context.h"
+#include <QVBoxLayout>
#include <QWidget>
#include <QUrl>
@@ -70,7 +72,12 @@ QWebContentsView::QWebContentsView()
d->context = WebEngineContext::current();
content::BrowserContext* browser_context = static_cast<ContentBrowserClientQt*>(content::GetContentClient()->browser())->browser_context();
- d->webContentsDelegate.reset(WebContentsDelegateQt::CreateNewWindow(browser_context, GURL(std::string("http://qt-project.org/")), NULL, MSG_ROUTING_NONE, gfx::Size(), this));
+ d->webContentsDelegate.reset(WebContentsDelegateQt::CreateNewWindow(browser_context, GURL(std::string("http://qt-project.org/")), NULL, MSG_ROUTING_NONE, gfx::Size()));
+ QVBoxLayout *layout = new QVBoxLayout;
+ setLayout(layout);
+
+ WebContentsViewQt* content_view = static_cast<WebContentsViewQt*>(d->webContentsDelegate->web_contents()->GetView());
+ layout->addLayout(content_view->windowContainer()->widget());
}
QWebContentsView::~QWebContentsView()
diff --git a/lib/web_contents_delegate_qt.cpp b/lib/web_contents_delegate_qt.cpp
index 646728fa5..db470c7e4 100644
--- a/lib/web_contents_delegate_qt.cpp
+++ b/lib/web_contents_delegate_qt.cpp
@@ -61,10 +61,10 @@ static const int kTestWindowHeight = 600;
std::vector<WebContentsDelegateQt*> WebContentsDelegateQt::m_windows;
-WebContentsDelegateQt::WebContentsDelegateQt(content::WebContents* web_contents, QWebContentsView* contentsView)
- : m_contentsView(contentsView)
- , m_quickContentsView(NULL)
+WebContentsDelegateQt::WebContentsDelegateQt(content::WebContents* web_contents)
+ : m_webContents(web_contents)
{
+ m_webContents->SetDelegate(this);
// const CommandLine& command_line = *CommandLine::ForCurrentProcess();
// registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
// Source<WebContents>(web_contents));
@@ -76,74 +76,28 @@ WebContentsDelegateQt::WebContentsDelegateQt(content::WebContents* web_contents,
// }
}
-WebContentsDelegateQt::WebContentsDelegateQt(content::WebContents* web_contents, QQuickWebContentsView* contentsView)
- : m_contentsView(NULL)
- , m_quickContentsView(contentsView)
-{
- // const CommandLine& command_line = *CommandLine::ForCurrentProcess();
- // registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
- // Source<WebContents>(web_contents));
- m_windows.push_back(this);
-
- // if (!shell_created_callback_.is_null()) {
- // shell_created_callback_.Run(this);
- // shell_created_callback_.Reset();
- // }
-}
-
-WebContentsDelegateQt* WebContentsDelegateQt::commonCreate(content::WebContents* web_contents, const gfx::Size& initial_size, WebContentsDelegateQt* delegate)
-{
- delegate->PlatformCreateWindow(initial_size.width(), initial_size.height());
-
- delegate->m_webContents.reset(web_contents);
- web_contents->SetDelegate(delegate);
-
- delegate->PlatformSetContents();
- delegate->PlatformResizeSubViews();
-
- return delegate;
-}
-
-content::WebContents* commonCreateWebContents(content::WebContents::CreateParams& create_params, int routing_id, const gfx::Size& initial_size)
+WebContentsDelegateQt* WebContentsDelegateQt::CreateNewWindow(content::BrowserContext* browser_context, const GURL& url, content::SiteInstance* site_instance, int routing_id, const gfx::Size& initial_size)
{
+ content::WebContents::CreateParams create_params(browser_context, site_instance);
create_params.routing_id = routing_id;
if (!initial_size.IsEmpty())
create_params.initial_size = initial_size;
else
create_params.initial_size = gfx::Size(kTestWindowWidth, kTestWindowHeight);
- return content::WebContents::Create(create_params);
-}
-
-WebContentsDelegateQt* WebContentsDelegateQt::Create(content::WebContents* web_contents, const gfx::Size& initial_size, QWebContentsView* contentsView)
-{
- WebContentsDelegateQt* delegate = new WebContentsDelegateQt(web_contents, contentsView);
- return commonCreate(web_contents, initial_size, delegate);
-}
-
-WebContentsDelegateQt* WebContentsDelegateQt::Create(content::WebContents* web_contents, const gfx::Size& initial_size, QQuickWebContentsView* contentsView)
-{
- WebContentsDelegateQt* delegate = new WebContentsDelegateQt(web_contents, contentsView);
- return commonCreate(web_contents, initial_size, delegate);
-}
+ content::WebContents::Create(create_params);
+ content::WebContents* web_contents = content::WebContents::Create(create_params);
+ WebContentsDelegateQt* delegate = new WebContentsDelegateQt(web_contents);
-WebContentsDelegateQt* WebContentsDelegateQt::CreateNewWindow(content::BrowserContext* browser_context, const GURL& url, content::SiteInstance* site_instance, int routing_id, const gfx::Size& initial_size, QWebContentsView* contentsView)
-{
- content::WebContents::CreateParams create_params(browser_context, site_instance);
- content::WebContents* web_contents = commonCreateWebContents(create_params, routing_id, initial_size);
- WebContentsDelegateQt* contentsDelegate = Create(web_contents, create_params.initial_size, contentsView);
- if (!url.is_empty())
- contentsDelegate->LoadURL(url);
- return contentsDelegate;
-}
+ content::RendererPreferences* rendererPrefs = delegate->m_webContents->GetMutableRendererPrefs();
+ rendererPrefs->use_custom_colors = true;
+ // Qt returns a flash time (the whole cycle) in ms, chromium expects just the interval in seconds
+ const int qtCursorFlashTime = QGuiApplication::styleHints()->cursorFlashTime();
+ rendererPrefs->caret_blink_interval = 0.5 * static_cast<double>(qtCursorFlashTime) / 1000;
+ delegate->m_webContents->GetRenderViewHost()->SyncRendererPrefs();
-WebContentsDelegateQt* WebContentsDelegateQt::CreateNewWindow(content::BrowserContext* browser_context, const GURL& url, content::SiteInstance* site_instance, int routing_id, const gfx::Size& initial_size, QQuickWebContentsView* contentsView)
-{
- content::WebContents::CreateParams create_params(browser_context, site_instance);
- content::WebContents* web_contents = commonCreateWebContents(create_params, routing_id, initial_size);
- WebContentsDelegateQt* contentsDelegate = Create(web_contents, create_params.initial_size, contentsView);
if (!url.is_empty())
- contentsDelegate->LoadURL(url);
- return contentsDelegate;
+ delegate->LoadURL(url);
+ return delegate;
}
content::WebContents* WebContentsDelegateQt::web_contents()
@@ -151,40 +105,6 @@ content::WebContents* WebContentsDelegateQt::web_contents()
return m_webContents.get();
}
-void WebContentsDelegateQt::PlatformCreateWindow(int width, int height)
-{
- if (m_contentsView) {
- // The layout is used in PlatformSetContents.
- QVBoxLayout* layout = new QVBoxLayout;
- m_contentsView->setLayout(layout);
- }
-}
-
-void WebContentsDelegateQt::PlatformSetContents()
-{
- content::RendererPreferences* rendererPrefs = m_webContents->GetMutableRendererPrefs();
- rendererPrefs->use_custom_colors = true;
- // Qt returns a flash time (the whole cycle) in ms, chromium expects just the interval in seconds
- const int qtCursorFlashTime = QGuiApplication::styleHints()->cursorFlashTime();
- rendererPrefs->caret_blink_interval = 0.5 * static_cast<double>(qtCursorFlashTime) / 1000;
- m_webContents->GetRenderViewHost()->SyncRendererPrefs();
-
- if (m_contentsView) {
- WebContentsViewQt* content_view = static_cast<WebContentsViewQt*>(m_webContents->GetView());
- QVBoxLayout* layout = qobject_cast<QVBoxLayout*>(m_contentsView->layout());
- if (layout)
- layout->addLayout(content_view->windowContainer()->widget());
- } else if (m_quickContentsView) {
- WebContentsViewQt* content_view = static_cast<WebContentsViewQt*>(m_webContents->GetView());
- QQuickItem* windowContainer = content_view->windowContainer()->qQuickItem();
- windowContainer->setParentItem(m_quickContentsView);
- }
-}
-
-void WebContentsDelegateQt::PlatformResizeSubViews()
-{
-
-}
void WebContentsDelegateQt::GoBackOrForward(int offset) {
m_webContents->GetController().GoToOffset(offset);
diff --git a/lib/web_contents_delegate_qt.h b/lib/web_contents_delegate_qt.h
index 9042bd470..4f289269e 100644
--- a/lib/web_contents_delegate_qt.h
+++ b/lib/web_contents_delegate_qt.h
@@ -45,6 +45,7 @@
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/web_contents_delegate.h"
+
namespace content {
class BrowserContext;
class SiteInstance;
@@ -57,10 +58,7 @@ class WebContentsDelegateQt : public content::WebContentsDelegate
, public content::NotificationObserver
{
public:
- static WebContentsDelegateQt* Create(content::WebContents*, const gfx::Size& initial_size, QWebContentsView*);
- static WebContentsDelegateQt* Create(content::WebContents*, const gfx::Size& initial_size, QQuickWebContentsView*);
- static WebContentsDelegateQt* CreateNewWindow(content::BrowserContext*, const GURL&, content::SiteInstance*, int routing_id, const gfx::Size& initial_size, QWebContentsView*);
- static WebContentsDelegateQt* CreateNewWindow(content::BrowserContext*, const GURL&, content::SiteInstance*, int routing_id, const gfx::Size& initial_size, QQuickWebContentsView*);
+ static WebContentsDelegateQt* CreateNewWindow(content::BrowserContext*, const GURL&, content::SiteInstance*, int routing_id, const gfx::Size& initial_size);
content::WebContents* web_contents();
void LoadURL(const GURL&);
void LoadURLForFrame(const GURL&, const std::string& frame_name);
@@ -71,15 +69,8 @@ public:
virtual void Observe(int, const content::NotificationSource&, const content::NotificationDetails&);
private:
- static WebContentsDelegateQt* commonCreate(content::WebContents* web_contents, const gfx::Size& initial_size, WebContentsDelegateQt* delegate);
- WebContentsDelegateQt(content::WebContents*, QWebContentsView*);
- WebContentsDelegateQt(content::WebContents*, QQuickWebContentsView*);
- void PlatformCreateWindow(int width, int height);
- void PlatformSetContents();
- void PlatformResizeSubViews();
+ WebContentsDelegateQt(content::WebContents*);
- QWebContentsView* m_contentsView;
- QQuickWebContentsView* m_quickContentsView;
scoped_ptr<content::WebContents> m_webContents;
static std::vector<WebContentsDelegateQt*> m_windows;
diff --git a/shared/native_view_container_qt.h b/shared/native_view_container_qt.h
index 6937d146d..fbb29ee85 100644
--- a/shared/native_view_container_qt.h
+++ b/shared/native_view_container_qt.h
@@ -15,7 +15,7 @@ public:
: m_embeddable(0)
, m_currentQQuickNativeView(0)
, m_currentQWidgetNativeView(0)
- , m_isQQuick(false)
+ , m_isQQuick(!qgetenv("QQUICKWEBENGINE").isNull())
{
}