Commit c5be32fa authored by Eike Ziller's avatar Eike Ziller

Help: Provide native WebView backend on Mac

Run Qt Creator with environment variable QTC_HELPVIEWER_BACKEND to
* 'native' to get the WebView based one on Mac
* 'textbrowser' to get the QTextBrowser based one

Defaults to use QWebView if QtWebKit is available, or QTextBrowser if
not, like before.

Change-Id: If0660782b18ff3d89301fa7bcaf4e2e2fb69627d
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent 62a83b2b
......@@ -82,7 +82,9 @@ QWidget *GeneralSettingsPage::widget()
m_ui->sizeComboBox->setEditable(false);
m_ui->styleComboBox->setEditable(false);
m_font = qvariant_cast<QFont>(HelpManager::customValue(QLatin1String("font"), m_font));
QVariant fontSetting = LocalHelpManager::engineFontSettings();
if (fontSetting.isValid())
m_font = fontSetting.value<QFont>();
updateFontSize();
updateFontStyle();
......@@ -155,7 +157,7 @@ void GeneralSettingsPage::apply()
if (newFont != m_font) {
m_font = newFont;
HelpManager::setCustomValue(QLatin1String("font"), newFont);
HelpManager::setCustomValue(Constants::FontKey, newFont);
emit fontChanged();
}
......
......@@ -68,5 +68,14 @@ FORMS += docsettingspage.ui \
generalsettingspage.ui \
remotehelpfilter.ui
macx:minQtVersion(5, 2, 0) {
DEFINES += QTC_MAC_NATIVE_HELPVIEWER
QT += macextras
HEADERS += macwebkithelpviewer.h
OBJECTIVE_SOURCES += macwebkithelpviewer.mm
LIBS += -framework WebKit -framework AppKit
}
RESOURCES += help.qrc
include(../../shared/help/help.pri)
......@@ -54,6 +54,7 @@ static const QLatin1String DefaultZoomFactor("0.0");
static const QLatin1String AboutBlank("about:blank");
static const QLatin1String WeAddedFilterKey("UnfilteredFilterInserted");
static const QLatin1String PreviousFilterNameKey("UnfilteredFilterName");
static const QLatin1String FontKey("font");
const int P_MODE_HELP = 70;
const char ID_MODE_HELP [] = "Help";
......
......@@ -48,6 +48,10 @@
#include "searchtaskhandler.h"
#include "textbrowserhelpviewer.h"
#ifdef QTC_MAC_NATIVE_HELPVIEWER
#include "macwebkithelpviewer.h"
#endif
#include <bookmarkmanager.h>
#include <contentwindow.h>
#include <indexwindow.h>
......@@ -638,14 +642,27 @@ void HelpPlugin::resetRightPaneScale()
HelpViewer *HelpPlugin::createHelpViewer(qreal zoom)
{
HelpViewer *viewer = 0;
const QString backend = QLatin1String(qgetenv("QTC_HELPVIEWER_BACKEND"));
if (backend.compare(QLatin1String("native"), Qt::CaseInsensitive) == 0) {
#ifdef QTC_MAC_NATIVE_HELPVIEWER
viewer = new MacWebKitHelpViewer(zoom);
#endif
} else if (backend.compare(QLatin1String("textbrowser"), Qt::CaseInsensitive) == 0) {
viewer = new TextBrowserHelpViewer(zoom);
} else {
#ifndef QT_NO_WEBKIT
if (qgetenv("QTC_FORCE_TEXTBROWSER").isEmpty())
return new QtWebKitHelpViewer(zoom);
else
return new TextBrowserHelpViewer(zoom);
viewer = new QtWebKitHelpViewer(zoom);
#else
return new TextBrowserHelpViewer(zoom);
viewer = new TextBrowserHelpViewer(zoom);
#endif
}
// initialize font
QVariant fontSetting = LocalHelpManager::engineFontSettings();
if (fontSetting.isValid())
viewer->setViewerFont(fontSetting.value<QFont>());
return viewer;
}
void HelpPlugin::activateHelpMode()
......@@ -729,11 +746,11 @@ void HelpPlugin::fontChanged()
if (!m_helpViewerForSideBar)
createRightPaneContextViewer();
const QHelpEngine &engine = LocalHelpManager::helpEngine();
QFont font = qvariant_cast<QFont>(engine.customValue(QLatin1String("font"),
m_helpViewerForSideBar->viewerFont()));
QVariant fontSetting = LocalHelpManager::engineFontSettings();
QFont font = fontSetting.isValid() ? fontSetting.value<QFont>()
: m_helpViewerForSideBar->viewerFont();
m_helpViewerForSideBar->setFont(font);
m_helpViewerForSideBar->setViewerFont(font);
const int count = OpenPagesManager::instance().pageCount();
for (int i = 0; i < count; ++i) {
if (HelpViewer *viewer = CentralWidget::instance()->viewerAt(i))
......
......@@ -60,7 +60,6 @@ public:
virtual qreal scale() const = 0;
virtual QString title() const = 0;
virtual void setTitle(const QString &title) = 0;
virtual QUrl source() const = 0;
virtual void setSource(const QUrl &url) = 0;
......
......@@ -29,7 +29,8 @@
#include "localhelpmanager.h"
#include <bookmarkmanager.h>
#include "bookmarkmanager.h"
#include "helpconstants.h"
#include <app/app_version.h>
#include <coreplugin/helpmanager.h>
......@@ -40,6 +41,8 @@
using namespace Help::Internal;
static LocalHelpManager *m_instance = 0;
QMutex LocalHelpManager::m_guiMutex;
QHelpEngine* LocalHelpManager::m_guiEngine = 0;
......@@ -51,6 +54,7 @@ LocalHelpManager::LocalHelpManager(QObject *parent)
, m_guiNeedsSetup(true)
, m_needsCollectionFile(true)
{
m_instance = this;
}
LocalHelpManager::~LocalHelpManager()
......@@ -65,6 +69,11 @@ LocalHelpManager::~LocalHelpManager()
m_guiEngine = 0;
}
LocalHelpManager *LocalHelpManager::instance()
{
return m_instance;
}
void LocalHelpManager::setupGuiHelpEngine()
{
if (m_needsCollectionFile) {
......@@ -110,3 +119,16 @@ BookmarkManager& LocalHelpManager::bookmarkManager()
}
return *m_bookmarkManager;
}
QVariant LocalHelpManager::engineFontSettings()
{
return helpEngine().customValue(Constants::FontKey, QVariant());
}
QByteArray LocalHelpManager::helpData(const QUrl &url)
{
const QHelpEngineCore &engine = helpEngine();
return engine.findFile(url).isValid() ? engine.fileData(url)
: tr("Could not load \"%1\".").arg(url.toString()).toUtf8();
}
......@@ -48,12 +48,18 @@ public:
LocalHelpManager(QObject *parent = 0);
~LocalHelpManager();
static LocalHelpManager *instance();
void setupGuiHelpEngine();
void setEngineNeedsUpdate();
static QHelpEngine& helpEngine();
static BookmarkManager& bookmarkManager();
static QVariant engineFontSettings();
Q_INVOKABLE QByteArray helpData(const QUrl &url);
private:
bool m_guiNeedsSetup;
bool m_needsCollectionFile;
......
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef MACWEBKITHELPVIEWER_H
#define MACWEBKITHELPVIEWER_H
#include "helpviewer.h"
#include <QMacCocoaViewContainer>
Q_FORWARD_DECLARE_OBJC_CLASS(DOMNode);
Q_FORWARD_DECLARE_OBJC_CLASS(DOMRange);
Q_FORWARD_DECLARE_OBJC_CLASS(NSString);
Q_FORWARD_DECLARE_OBJC_CLASS(WebView);
namespace Help {
namespace Internal {
class MacWebKitHelpViewer;
class MacWebKitHelpWidgetPrivate;
class MacResponderHack : public QObject
{
Q_OBJECT
public:
MacResponderHack(QObject *parent);
private slots:
void responderHack(QWidget *old, QWidget *now);
};
class MacWebKitHelpWidget : public QMacCocoaViewContainer
{
Q_OBJECT
public:
MacWebKitHelpWidget(MacWebKitHelpViewer *parent);
~MacWebKitHelpWidget();
void setOpenInNewWindowActionVisible(bool visible);
WebView *webView() const;
protected:
void hideEvent(QHideEvent *);
void showEvent(QShowEvent *);
private:
MacWebKitHelpWidgetPrivate *d;
};
class MacWebKitHelpViewer : public HelpViewer
{
Q_OBJECT
public:
explicit MacWebKitHelpViewer(qreal zoom, QWidget *parent = 0);
~MacWebKitHelpViewer();
QFont viewerFont() const;
void setViewerFont(const QFont &font);
void scaleUp();
void scaleDown();
void resetScale();
qreal scale() const;
QString title() const;
QUrl source() const;
void setSource(const QUrl &url);
void scrollToAnchor(const QString &anchor);
void highlightId(const QString &id) { Q_UNUSED(id) }
void setHtml(const QString &html);
QString selectedText() const;
bool isForwardAvailable() const;
bool isBackwardAvailable() const;
void addBackHistoryItems(QMenu *backMenu);
void addForwardHistoryItems(QMenu *forwardMenu);
void setOpenInNewWindowActionVisible(bool visible);
bool findText(const QString &text, Core::FindFlags flags,
bool incremental, bool fromSearch, bool *wrapped = 0);
MacWebKitHelpWidget *widget() const { return m_widget; }
public slots:
void copy();
void stop();
void forward();
void backward();
void print(QPrinter *printer);
public slots:
void slotLoadStarted();
void slotLoadFinished();
private slots:
void goToHistoryItem();
private:
DOMRange *findText(NSString *text, bool forward, bool caseSensitive, DOMNode *startNode,
int startOffset);
MacWebKitHelpWidget *m_widget;
};
} // namespace Internal
} // namespace Help
#endif // MACWEBKITHELPVIEWER_H
This diff is collapsed.
......@@ -196,7 +196,7 @@ HelpViewer *OpenPagesManager::createPageFromSearch(const QUrl &url)
HelpViewer *OpenPagesManager::createPage(const QUrl &url, bool fromSearch)
{
if (HelpViewer::launchWithExternalApp(url))
if (url.isValid() && HelpViewer::launchWithExternalApp(url))
return 0;
m_model->addPage(url);
......
......@@ -77,7 +77,8 @@ void OpenPagesModel::addPage(const QUrl &url, qreal zoom)
connect(page, SIGNAL(titleChanged()), this, SLOT(handleTitleChanged()));
m_pages << page;
endInsertRows();
page->setSource(url);
if (url.isValid())
page->setSource(url);
}
void OpenPagesModel::removePage(int index)
......
......@@ -451,18 +451,13 @@ QtWebKitHelpViewer::QtWebKitHelpViewer(qreal zoom, QWidget *parent)
connect(m_webView->page(), SIGNAL(printRequested(QWebFrame*)), this, SIGNAL(printRequested()));
connect(m_webView, SIGNAL(backwardAvailable(bool)), this, SIGNAL(backwardAvailable(bool)));
connect(m_webView, SIGNAL(forwardAvailable(bool)), this, SIGNAL(forwardAvailable(bool)));
setViewerFont(viewerFont());
}
QFont QtWebKitHelpViewer::viewerFont() const
{
QWebSettings* webSettings = QWebSettings::globalSettings();
QFont font(QApplication::font().family(),
QWebSettings* webSettings = m_webView->settings();
return QFont(webSettings->fontFamily(QWebSettings::StandardFont),
webSettings->fontSize(QWebSettings::DefaultFontSize));
const QHelpEngineCore &engine = LocalHelpManager::helpEngine();
return qvariant_cast<QFont>(engine.customValue(QLatin1String("font"),
font));
}
void QtWebKitHelpViewer::setViewerFont(const QFont &font)
......@@ -497,11 +492,6 @@ QString QtWebKitHelpViewer::title() const
return m_webView->title();
}
void QtWebKitHelpViewer::setTitle(const QString &title)
{
Q_UNUSED(title)
}
QUrl QtWebKitHelpViewer::source() const
{
return m_webView->url();
......
......@@ -59,7 +59,6 @@ public:
qreal scale() const;
QString title() const;
void setTitle(const QString &title);
QUrl source() const;
void setSource(const QUrl &url);
......
......@@ -64,11 +64,6 @@ TextBrowserHelpViewer::TextBrowserHelpViewer(qreal zoom, QWidget *parent)
p.color(QPalette::Active, QPalette::HighlightedText));
setPalette(p);
// ???
QFont font = viewerFont();
font.setPointSize(int(font.pointSize() + zoom));
setViewerFont(font);
connect(m_textBrowser, SIGNAL(sourceChanged(QUrl)), this, SIGNAL(titleChanged()));
connect(m_textBrowser, SIGNAL(forwardAvailable(bool)), this, SIGNAL(forwardAvailable(bool)));
connect(m_textBrowser, SIGNAL(backwardAvailable(bool)), this, SIGNAL(backwardAvailable(bool)));
......@@ -80,18 +75,14 @@ TextBrowserHelpViewer::~TextBrowserHelpViewer()
QFont TextBrowserHelpViewer::viewerFont() const
{
const QHelpEngineCore &engine = LocalHelpManager::helpEngine();
return qvariant_cast<QFont>(engine.customValue(QLatin1String("font"),
qApp->font()));
return m_textBrowser->font();
}
void TextBrowserHelpViewer::setViewerFont(const QFont &newFont)
{
if (font() != newFont) {
m_textBrowser->forceFont = true;
m_textBrowser->setFont(newFont);
m_textBrowser->forceFont = false;
}
m_textBrowser->forceFont = true;
m_textBrowser->setFont(newFont);
m_textBrowser->forceFont = false;
}
void TextBrowserHelpViewer::scaleUp()
......@@ -124,11 +115,6 @@ QString TextBrowserHelpViewer::title() const
return m_textBrowser->documentTitle();
}
void TextBrowserHelpViewer::setTitle(const QString &title)
{
m_textBrowser->setDocumentTitle(title);
}
QUrl TextBrowserHelpViewer::source() const
{
return m_textBrowser->source();
......
......@@ -59,7 +59,6 @@ public:
qreal scale() const;
QString title() const;
void setTitle(const QString &title);
QUrl source() const;
void setSource(const QUrl &url);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment