From 398159d941942886b40105680820f497e5ca90a5 Mon Sep 17 00:00:00 2001 From: Zeno Albisser Date: Mon, 17 Jun 2013 15:57:43 +0200 Subject: Add initial API layer for QtQuick and connect the signals accordingly. --- lib/web_contents_delegate_qt.cpp | 56 ++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 17 deletions(-) (limited to 'lib/web_contents_delegate_qt.cpp') diff --git a/lib/web_contents_delegate_qt.cpp b/lib/web_contents_delegate_qt.cpp index 71f3e6d9c..d4aad13a0 100644 --- a/lib/web_contents_delegate_qt.cpp +++ b/lib/web_contents_delegate_qt.cpp @@ -41,8 +41,14 @@ #include "web_contents_delegate_qt.h" +#include "content/public/browser/navigation_controller.h" +#include "content/public/browser/navigation_entry.h" +#include "content/public/browser/notification_source.h" +#include "content/public/browser/notification_details.h" +#include "content/public/browser/notification_types.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" +#include "content/public/browser/invalidate_type.h" #include "content/public/common/renderer_preferences.h" #include @@ -51,13 +57,8 @@ static const int kTestWindowWidth = 800; static const int kTestWindowHeight = 600; -WebContentsDelegateQt::WebContentsDelegateQt(content::WebContents* web_contents) - : m_webContents(web_contents) -{ - m_webContents->SetDelegate(this); -} - -WebContentsDelegateQt* WebContentsDelegateQt::CreateNewWindow(content::BrowserContext* browser_context, content::SiteInstance* site_instance, int routing_id, const gfx::Size& initial_size) +WebContentsDelegateQt::WebContentsDelegateQt(QObject* webContentsView, content::BrowserContext* browser_context, content::SiteInstance* site_instance, int routing_id, const gfx::Size& initial_size) + : m_webContentsView(webContentsView) { content::WebContents::CreateParams create_params(browser_context, site_instance); create_params.routing_id = routing_id; @@ -65,26 +66,47 @@ WebContentsDelegateQt* WebContentsDelegateQt::CreateNewWindow(content::BrowserCo create_params.initial_size = initial_size; else create_params.initial_size = gfx::Size(kTestWindowWidth, kTestWindowHeight); - content::WebContents::Create(create_params); - content::WebContents* web_contents = content::WebContents::Create(create_params); - WebContentsDelegateQt* delegate = new WebContentsDelegateQt(web_contents); - content::RendererPreferences* rendererPrefs = delegate->m_webContents->GetMutableRendererPrefs(); + m_webContents.reset(content::WebContents::Create(create_params)); + + 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(qtCursorFlashTime) / 1000; - delegate->m_webContents->GetRenderViewHost()->SyncRendererPrefs(); + m_webContents->GetRenderViewHost()->SyncRendererPrefs(); - return delegate; + m_webContents->SetDelegate(this); + m_registrar.Add(this, content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, content::Source(m_webContents.get())); } -content::WebContents* WebContentsDelegateQt::web_contents() +void WebContentsDelegateQt::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { - return m_webContents.get(); + if (type == content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED) { + std::pair* title = content::Details >(details).ptr(); + + if (title->first) { + string16 text = title->first->GetTitle(); + QString title = QString::fromUtf16(text.data()); + Q_EMIT titleChanged(title); + } + } } -void WebContentsDelegateQt::Observe(int, const content::NotificationSource&, const content::NotificationDetails&) +void WebContentsDelegateQt::NavigationStateChanged(const content::WebContents* source, unsigned changed_flags) { - // IMPLEMENT THIS!!!! + if (changed_flags & content::INVALIDATE_TYPE_URL) + Q_EMIT urlChanged(); } + +void WebContentsDelegateQt::LoadingStateChanged(content::WebContents* source) +{ + Q_EMIT loadingStateChanged(); +} + +content::WebContents* WebContentsDelegateQt::web_contents() +{ + return m_webContents.get(); +} + + -- cgit v1.2.3