aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt8
-rw-r--r--src/kvirc/ui/KviWebPackageManagementDialog.cpp124
-rw-r--r--src/kvirc/ui/KviWebPackageManagementDialog.h26
-rw-r--r--src/modules/help/HelpWidget.cpp20
-rw-r--r--src/modules/help/HelpWidget.h6
-rw-r--r--src/modules/help/HelpWindow.cpp3
-rw-r--r--src/modules/help/HelpWindow.h4
-rw-r--r--src/modules/objects/KvsObject_webView.cpp1026
-rw-r--r--src/modules/objects/KvsObject_webView.h104
-rw-r--r--src/modules/objects/KvsObject_widget.h4
10 files changed, 364 insertions, 961 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 872c4f8c3..eeffbcbbf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -471,10 +471,10 @@ endif()
# Qt WebKit support
if(WANT_QTWEBKIT)
- find_package(Qt5WebKitWidgets)
- if(Qt5WebKitWidgets_FOUND)
- list(APPEND qt5_kvirc_modules Qt5::WebKitWidgets)
- include_directories(${Qt5WebKitWidgets_INCLUDE_DIRS})
+ find_package(Qt5WebEngineWidgets)
+ if(Qt5WebEngineWidgets_FOUND)
+ list(APPEND qt5_kvirc_modules Qt5::WebEngineWidgets)
+ include_directories(${Qt5WebEngineWidgets_INCLUDE_DIRS})
set(COMPILE_WEBKIT_SUPPORT 1)
endif()
endif()
diff --git a/src/kvirc/ui/KviWebPackageManagementDialog.cpp b/src/kvirc/ui/KviWebPackageManagementDialog.cpp
index 318c0fa33..edb1d41b1 100644
--- a/src/kvirc/ui/KviWebPackageManagementDialog.cpp
+++ b/src/kvirc/ui/KviWebPackageManagementDialog.cpp
@@ -44,15 +44,12 @@
#include <QTimer>
#include <QClipboard>
#include <QHBoxLayout>
-#include <QWebView>
+#include <QWebEngineView>
#include <QVBoxLayout>
#include <QToolBar>
#include <QFile>
#include <QProgressBar>
#include <QDir>
-#include <QWebView>
-#include <QWebFrame>
-#include <QWebElement>
#include <QUrl>
#include <QShowEvent>
@@ -60,7 +57,7 @@ KviWebPackageManagementDialog::KviWebPackageManagementDialog(QWidget * pParent)
: QWidget(pParent)
{
setAttribute(Qt::WA_DeleteOnClose);
-
+ setMinimumSize(600, 500);
setWindowIcon(QIcon(*(g_pIconManager->getBigIcon(KVI_BIGICON_WWW))));
m_pLayout = new QVBoxLayout(this);
@@ -83,25 +80,29 @@ KviWebPackageManagementDialog::KviWebPackageManagementDialog(QWidget * pParent)
hbox->addWidget(m_pProgressBar);
hbox->setAlignment(m_pProgressBar, Qt::AlignRight);
- m_pWebView = new QWebView(this);
+ m_pWebView = new QWebEngineView(this);
+ // we managing the links
+ m_pWebView->setPage(new KviWebPackagePage());
+
m_pLayout->addWidget(m_pWebView);
m_pLayout->setStretchFactor(m_pWebView, 10); // must take most space
// disable context menu
m_pWebView->setContextMenuPolicy(Qt::NoContextMenu);
- m_pToolBar->addAction(m_pWebView->pageAction(QWebPage::Back));
- m_pToolBar->addAction(m_pWebView->pageAction(QWebPage::Forward));
+ m_pToolBar->addAction(m_pWebView->pageAction(QWebEnginePage::Back));
+ m_pToolBar->addAction(m_pWebView->pageAction(QWebEnginePage::Forward));
//connect(pWebView,SIGNAL(loadStarted()),this,SLOT(slotLoadStarted()));
connect(m_pWebView, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished(bool)));
connect(m_pWebView, SIGNAL(loadProgress(int)), this, SLOT(slotLoadProgress(int)));
connect(m_pWebView->page(), SIGNAL(linkClicked(const QUrl &)), this, SLOT(slotLinkClicked(const QUrl &)));
-
- // we managing the links
- m_pWebView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
}
KviWebPackageManagementDialog::~KviWebPackageManagementDialog()
- = default;
+{
+ KviWebPackagePage *tmp = (KviWebPackagePage*) m_pWebView->page();
+ m_pWebView->setPage(nullptr);
+ tmp->deleteLater();
+}
void KviWebPackageManagementDialog::setPackagePageUrl(const QString & szUrl)
{
@@ -113,7 +114,7 @@ void KviWebPackageManagementDialog::slotLoadFinished(bool bOk)
{
if(!bOk)
{
- qDebug("Error loading page"); // fixme: add warning dialog return;
+ qDebug("Error loading page"); // fixme: add warning dialog
return;
}
@@ -123,38 +124,37 @@ void KviWebPackageManagementDialog::slotLoadFinished(bool bOk)
if(!isVisible())
show();
- // main frame
- QWebFrame * pFrame = m_pWebView->page()->mainFrame();
-
- // search for all item_entry div
- QWebElementCollection elementscollection = pFrame->documentElement().findAll("div.item_entry");
+ m_pWebView->page()->runJavaScript("var items = "" \
+ Array.from(document.querySelectorAll(\"div.item_entry\")).forEach( \
+ function(element, index, array) { \
+ items += index + \"|\" + element.querySelector(\"span.item_id\").innerText + \"|\" + element.querySelector(\"span.item_version\").innerText + \"\\n\" \
+ })",
+ [this](const QVariant &items) {
+ QStringList elementscollection = items.toString().split("\n", Qt::SkipEmptyParts);
+ foreach(const QString element, elementscollection)
+ {
+ QStringList tmp = element.split("|");
+ if(tmp.size() != 3)
+ continue;
- // if this is null something is wrong
- if(elementscollection.count())
- {
- foreach(QWebElement element, elementscollection)
- {
- // web element 'title'
- QWebElement eId = element.findFirst("span.item_id");
- // string title
- QString szId = eId.toPlainText();
- // number version
- QString szVersion = element.findFirst("span.item_version").toPlainText();
- //QString t=szLocalThemesPath+szTitle+"-"+szVersion;
- // is the theme installed?
+ // web element 'title'
+ QString szIndex = tmp.at(0);
+ // string title
+ QString szId = tmp.at(1);
+ // number version
+ QString szVersion = tmp.at(2);
+ // is the theme installed?
+ if(packageIsInstalled(szId, szVersion))
+ {
+ // change the background color to highlight the item
+ m_pWebView->page()->runJavaScript(QString("var item = document.querySelectorAll(\"div.item_entry\")[%1]; \
+ item.querySelector(\"div.item_identification\").style.background = \"none repeat scroll 0 0 #3cd543\"; \
+ item.querySelector(\"a.item_download_link\").innerText = \"Reinstall\";").arg(szIndex));
+ }
- if(packageIsInstalled(szId, szVersion))
- {
- // yeah: change the background color for highlight the item
- element.findFirst("div.item_identification").setStyleProperty("background", "none repeat scroll 0 0 #3cd543");
- // then change the 'install' text into 'uninstall'
- QWebElement eDownload = element.findFirst("a.item_download_link");
- eDownload.setPlainText("Uninstall");
- // why use a c++ var when we can use the web page for store it? :-D
- eDownload.setAttribute("Installed", QString("1"));
}
}
- }
+ );
}
void KviWebPackageManagementDialog::slotLinkClicked(const QUrl & url)
{
@@ -163,42 +163,22 @@ void KviWebPackageManagementDialog::slotLinkClicked(const QUrl & url)
return;
QString szScheme = url.scheme();
// it's an ftp link?
- if(!KviQString::equalCI(szScheme, "ftp"))
+ if(KviQString::equalCI(szScheme, "ftp"))
{
+ // one download at once
+ m_bBusy = true;
+
+ QNetworkRequest req(url);
+ QNetworkReply * pReply = KviNetworkAccessManager::getInstance()->get(req);
+ connect(pReply, SIGNAL(finished()), this, SLOT(slotCommandFinished()));
+ connect(pReply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(slotDataTransferProgress(qint64, qint64)));
+
m_pProgressBar->show();
- m_pWebView->load(url);
return;
}
- // let's search for the 'a' tag
- QWebElementCollection elementscollection = m_pWebView->page()->mainFrame()->findAllElements("a.item_download_link");
- if(elementscollection.count() == 0)
- return;
-
- foreach(QWebElement element, elementscollection)
- {
- // check the href to find the item
- if(!KviQString::equalCI(element.attribute("href"), url.toString()))
- continue;
-
- // check the hidden attribute for installed item
- if(element.attribute("Installed").isEmpty())
- {
- // one download at once
- m_bBusy = true;
-
- QNetworkRequest req(url);
- QNetworkReply * pReply = KviNetworkAccessManager::getInstance()->get(req);
- connect(pReply, SIGNAL(finished()), this, SLOT(slotCommandFinished()));
- connect(pReply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(slotDataTransferProgress(qint64, qint64)));
-
- m_pProgressBar->show();
- }
- else
- {
- qDebug("uninstall theme"); //to be continued
- }
- }
+ m_pProgressBar->show();
+ m_pWebView->load(url);
}
void KviWebPackageManagementDialog::slotDataTransferProgress(qint64 iDone, qint64 iTotal)
diff --git a/src/kvirc/ui/KviWebPackageManagementDialog.h b/src/kvirc/ui/KviWebPackageManagementDialog.h
index af2804daa..7152e43eb 100644
--- a/src/kvirc/ui/KviWebPackageManagementDialog.h
+++ b/src/kvirc/ui/KviWebPackageManagementDialog.h
@@ -30,14 +30,36 @@
#ifdef COMPILE_WEBKIT_SUPPORT
#include <QWidget>
+#include <QWebEnginePage>
class QToolBar;
class QVBoxLayout;
-class QWebView;
+class QWebEngineView;
class QFile;
class QProgressBar;
class QUrl;
+class KviWebPackagePage : public QWebEnginePage
+{
+ Q_OBJECT
+public:
+ KviWebPackagePage(QObject* parent = 0) : QWebEnginePage(parent){}
+
+ bool acceptNavigationRequest(const QUrl & url, QWebEnginePage::NavigationType type, bool)
+ {
+ if (type == QWebEnginePage::NavigationTypeLinkClicked)
+ {
+ emit linkClicked(url);
+ return false;
+ }
+ return true;
+ }
+
+signals:
+ void linkClicked(const QUrl&);
+
+};
+
///
/// \class KviWebPackageManagementDialog
/// \brief The KviWebPackageManagementDialog class
@@ -63,7 +85,7 @@ public:
private:
QToolBar * m_pToolBar;
QVBoxLayout * m_pLayout;
- QWebView * m_pWebView;
+ QWebEngineView * m_pWebView;
bool m_bBusy;
QProgressBar * m_pProgressBar;
QString m_szPackagePageUrl;
diff --git a/src/modules/help/HelpWidget.cpp b/src/modules/help/HelpWidget.cpp
index 51d0a4220..5bd05fcca 100644
--- a/src/modules/help/HelpWidget.cpp
+++ b/src/modules/help/HelpWidget.cpp
@@ -49,8 +49,6 @@ extern KviPointerList<HelpWidget> * g_pHelpWidgetList;
#include <QShortcut>
#include <QAction>
-#define HIGHLIGHT_FLAGS QWebPage::HighlightAllOccurrences
-
HelpWidget::HelpWidget(QWidget * par, bool bIsStandalone)
: QWidget(par)
{
@@ -74,7 +72,7 @@ HelpWidget::HelpWidget(QWidget * par, bool bIsStandalone)
m_pLayout->addWidget(m_pToolBar);
// webview
- m_pTextBrowser = new QWebView(this);
+ m_pTextBrowser = new QWebEngineView(this);
m_pTextBrowser->setObjectName("text_browser");
m_pTextBrowser->setStyleSheet("QTextBrowser { background-color:white; color:black; }");
m_pLayout->addWidget(m_pTextBrowser);
@@ -101,10 +99,10 @@ HelpWidget::HelpWidget(QWidget * par, bool bIsStandalone)
m_pToolBar->addAction(*g_pIconManager->getBigIcon(KVI_BIGICON_HELPINDEX), __tr2qs("Show index"), this, SLOT(showIndex()));
QAction * pAction;
- pAction = m_pTextBrowser->pageAction(QWebPage::Back);
+ pAction = m_pTextBrowser->pageAction(QWebEnginePage::Back);
pAction->setIcon(*g_pIconManager->getBigIcon(KVI_BIGICON_HELPBACK));
m_pToolBar->addAction(pAction);
- pAction = m_pTextBrowser->pageAction(QWebPage::Forward);
+ pAction = m_pTextBrowser->pageAction(QWebEnginePage::Forward);
pAction->setIcon(*g_pIconManager->getBigIcon(KVI_BIGICON_HELPFORWARD));
m_pToolBar->addAction(pAction);
@@ -120,7 +118,7 @@ HelpWidget::HelpWidget(QWidget * par, bool bIsStandalone)
void HelpWidget::slotCopy()
{
- m_pTextBrowser->triggerPageAction(QWebPage::Copy);
+ m_pTextBrowser->triggerPageAction(QWebEnginePage::Copy);
}
void HelpWidget::slotShowHideFind()
@@ -128,7 +126,7 @@ void HelpWidget::slotShowHideFind()
if(m_pToolBarHighlight->isVisible())
{
m_pToolBarHighlight->hide();
- m_pTextBrowser->findText("", HIGHLIGHT_FLAGS);
+ m_pTextBrowser->findText("");
}
else
{
@@ -139,18 +137,18 @@ void HelpWidget::slotShowHideFind()
void HelpWidget::slotLoadFinished(bool)
{
- m_pTextBrowser->findText(m_pFindText->text(), HIGHLIGHT_FLAGS);
+ m_pTextBrowser->findText(m_pFindText->text());
}
void HelpWidget::slotTextChanged(const QString szFind)
{
- m_pTextBrowser->findText("", HIGHLIGHT_FLAGS);
- m_pTextBrowser->findText(szFind, HIGHLIGHT_FLAGS);
+ m_pTextBrowser->findText("");
+ m_pTextBrowser->findText(szFind);
}
void HelpWidget::slotFindPrev()
{
- m_pTextBrowser->findText(m_pFindText->text(), QWebPage::FindBackward);
+ m_pTextBrowser->findText(m_pFindText->text(), QWebEnginePage::FindBackward);
}
void HelpWidget::slotFindNext()
diff --git a/src/modules/help/HelpWidget.h b/src/modules/help/HelpWidget.h
index 75a91c683..49469f633 100644
--- a/src/modules/help/HelpWidget.h
+++ b/src/modules/help/HelpWidget.h
@@ -28,7 +28,7 @@
#include "kvi_settings.h"
#ifdef COMPILE_WEBKIT_SUPPORT
-#include <QtWebKitWidgets/QWebView>
+#include <QWebEngineView>
#else
#include <QTextBrowser>
#endif
@@ -53,7 +53,7 @@ private:
QToolBar * m_pToolBar;
QToolBar * m_pToolBarHighlight;
QLineEdit * m_pFindText;
- QWebView * m_pTextBrowser;
+ QWebEngineView * m_pTextBrowser;
#else
QVBoxLayout * m_pLayout;
QToolBar * m_pToolBar;
@@ -77,7 +77,7 @@ protected slots:
#endif
public:
#ifdef COMPILE_WEBKIT_SUPPORT
- QWebView * textBrowser()
+ QWebEngineView * textBrowser()
{
return m_pTextBrowser;
}
diff --git a/src/modules/help/HelpWindow.cpp b/src/modules/help/HelpWindow.cpp
index 3f0219df9..308580023 100644
--- a/src/modules/help/HelpWindow.cpp
+++ b/src/modules/help/HelpWindow.cpp
@@ -52,6 +52,7 @@ HelpWindow::HelpWindow(const char * name)
: KviWindow(KviWindow::Help, name)
{
g_pHelpWindowList->append(this);
+ setMinimumSize(600, 500);
m_pSplitter = new KviTalSplitter(Qt::Horizontal, this);
m_pSplitter->setObjectName("main_splitter");
m_pSplitter->setChildrenCollapsible(false);
@@ -268,7 +269,7 @@ void HelpWindow::startSearch()
}
#ifdef COMPILE_WEBKIT_SUPPORT
-QWebView * HelpWindow::textBrowser()
+QWebEngineView * HelpWindow::textBrowser()
#else
QTextBrowser * HelpWindow::textBrowser()
#endif
diff --git a/src/modules/help/HelpWindow.h b/src/modules/help/HelpWindow.h
index 865fb5fee..bdd115f33 100644
--- a/src/modules/help/HelpWindow.h
+++ b/src/modules/help/HelpWindow.h
@@ -32,7 +32,7 @@
#include <QTabWidget>
#ifdef COMPILE_WEBKIT_SUPPORT
-#include <QtWebKitWidgets/QWebView>
+#include <QWebEngineView>
#else
class QTextBrowser;
#endif
@@ -80,7 +80,7 @@ protected:
public:
#ifdef COMPILE_WEBKIT_SUPPORT
- QWebView * textBrowser();
+ QWebEngineView * textBrowser();
#else
QTextBrowser * textBrowser();
#endif
diff --git a/src/modules/objects/KvsObject_webView.cpp b/src/modules/objects/KvsObject_webView.cpp
index d61077532..470bfca0d 100644
--- a/src/modules/objects/KvsObject_webView.cpp
+++ b/src/modules/objects/KvsObject_webView.cpp
@@ -34,140 +34,233 @@
#include <QMenu>
#if defined(COMPILE_WEBKIT_SUPPORT)
-#include <QWebView>
-#include <QWebSettings>
-#include <QWebElement>
+#include <QWebEngineProfile>
+#include <QWebEngineView>
+#include <QWebEngineSettings>
+#include <QWebEngineDownloadItem>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QPixmap>
-#include <QFile>
+#include <QFileInfo>
#include <QSize>
#include <QPoint>
#include <QVariant>
#include <QToolTip>
static int g_iDownloadId = 1;
-KviKvsDownloadHandler::KviKvsDownloadHandler(KvsObject_webView * pParent, QFile * pFile, QNetworkReply * pNetReply, int iId)
+KviKvsDownloadHandler::KviKvsDownloadHandler(KvsObject_webView * pParent, QString &szFilePath, QWebEngineDownloadItem * pDownload, int iId)
: QObject(pParent)
{
-
m_Id = iId;
m_pParentScript = pParent;
- m_pReply = pNetReply;
- m_pFile = pFile;
- connect(m_pReply, SIGNAL(finished()), this, SLOT(slotReplyFinished()));
- connect(m_pReply, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
+ m_pDownload = pDownload;
+ connect(m_pDownload, SIGNAL(finished()), this, SLOT(slotFinished()));
+ connect(m_pDownload, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(slotDownloadProgress(qint64, qint64)));
+
+ QFileInfo oFi(szFilePath);
+ m_pDownload->setDownloadDirectory(oFi.absolutePath());
+ m_pDownload->setDownloadFileName(oFi.fileName());
+ m_pDownload->accept();
}
-void KviKvsDownloadHandler::slotReplyFinished()
+void KviKvsDownloadHandler::slotFinished()
{
KviKvsVariantList params(new KviKvsVariant((kvs_int_t)m_Id));
m_pParentScript->callFunction(m_pParentScript, "downloadCompletedEvent", &params);
- m_pFile->close();
- delete m_pFile;
- m_pFile = nullptr;
- m_pReply->deleteLater();
- m_pReply = nullptr;
+ m_pDownload->deleteLater();
+ m_pDownload = nullptr;
this->deleteLater();
}
KviKvsDownloadHandler::~KviKvsDownloadHandler()
{
- if(m_pFile)
- {
- m_pFile->close();
- delete m_pFile;
- m_pFile = nullptr;
- }
- if(m_pReply)
+ if(m_pDownload)
{
- delete m_pReply;
- m_pReply = nullptr;
+ delete m_pDownload;
+ m_pDownload = nullptr;
}
}
-void KviKvsDownloadHandler::slotReadyRead()
+void KviKvsDownloadHandler::slotDownloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{
- QVariant vSize = m_pReply->header(QNetworkRequest::ContentLengthHeader);
- int iSize = 0;
- if(!vSize.isNull())
- {
- bool bOk;
- iSize = vSize.toInt(&bOk);
- }
-
- QByteArray bytes = m_pReply->readAll();
- KviKvsVariantList params(new KviKvsVariant((kvs_int_t)bytes.count()),
- new KviKvsVariant((kvs_int_t)m_Id), new KviKvsVariant((kvs_int_t)iSize));
+ KviKvsVariantList params(new KviKvsVariant((kvs_int_t)bytesReceived),
+ new KviKvsVariant((kvs_int_t)m_Id), new KviKvsVariant((kvs_int_t)bytesTotal));
m_pParentScript->callFunction(m_pParentScript, "downloadProgressEvent", &params);
- m_pFile->write(bytes);
}
const char * const webattributes_tbl[] = {
+ "AutoLoadImages",
"JavascriptEnabled",
- "PluginsEnabled",
"JavascriptCanOpenWindows",
"JavascriptCanAccessClipboard",
- "ZoomTextOnly",
- "LocalContentCanAccessFileUrls"
+ "LinksIncludedInFocusChain",
+ "LocalStorageEnabled",
+ "LocalContentCanAccessRemoteUrls",
+ "XSSAuditingEnabled",
+ "SpatialNavigationEnabled",
+ "LocalContentCanAccessFileUrls",
+ "HyperlinkAuditingEnabled",
+ "ScrollAnimatorEnabled",
+ "ErrorPageEnabled",
+ "PluginsEnabled",
+ "FullScreenSupportEnabled",
+ "ScreenCaptureEnabled",
+ "WebGLEnabled",
+ "Accelerated2dCanvasEnabled",
+ "AutoLoadIconsForPage",
+ "TouchIconsEnabled",
+ "FocusOnNavigationEnabled",
+ "PrintElementBackgrounds",
+ "AllowRunningInsecureContent",
+ "AllowGeolocationOnInsecureOrigins",
+ "AllowWindowActivationFromJavaScript",
+ "ShowScrollBars",
+ "PlaybackRequiresUserGesture",
+ "JavascriptCanPaste",
+ "WebRTCPublicInterfacesOnly",
+ "DnsPrefetchEnabled",
+ "PdfViewerEnabled"
};
-const QWebSettings::WebAttribute webattributes_cod[] = {
- QWebSettings::JavascriptEnabled,
- QWebSettings::PluginsEnabled,
- QWebSettings::JavascriptCanOpenWindows,
- QWebSettings::JavascriptCanAccessClipboard,
- QWebSettings::ZoomTextOnly,
- QWebSettings::LocalContentCanAccessFileUrls
+const QWebEngineSettings::WebAttribute webattributes_cod[] = {
+ QWebEngineSettings::AutoLoadImages,
+ QWebEngineSettings::JavascriptEnabled,
+ QWebEngineSettings::JavascriptCanOpenWindows,
+ QWebEngineSettings::JavascriptCanAccessClipboard,
+ QWebEngineSettings::LinksIncludedInFocusChain,
+ QWebEngineSettings::LocalStorageEnabled,
+ QWebEngineSettings::LocalContentCanAccessRemoteUrls,
+ QWebEngineSettings::XSSAuditingEnabled,
+ QWebEngineSettings::SpatialNavigationEnabled,
+ QWebEngineSettings::LocalContentCanAccessFileUrls,
+ QWebEngineSettings::HyperlinkAuditingEnabled,
+ QWebEngineSettings::ScrollAnimatorEnabled,
+ QWebEngineSettings::ErrorPageEnabled,
+ QWebEngineSettings::PluginsEnabled,
+ QWebEngineSettings::FullScreenSupportEnabled,
+ QWebEngineSettings::ScreenCaptureEnabled,
+ QWebEngineSettings::WebGLEnabled,
+ QWebEngineSettings::Accelerated2dCanvasEnabled,
+ QWebEngineSettings::AutoLoadIconsForPage,
+ QWebEngineSettings::TouchIconsEnabled,
+ QWebEngineSettings::FocusOnNavigationEnabled,
+ QWebEngineSettings::PrintElementBackgrounds,
+ QWebEngineSettings::AllowRunningInsecureContent,
+ QWebEngineSettings::AllowGeolocationOnInsecureOrigins,
+ QWebEngineSettings::AllowWindowActivationFromJavaScript,
+ QWebEngineSettings::ShowScrollBars,
+ QWebEngineSettings::PlaybackRequiresUserGesture,
+ QWebEngineSettings::JavascriptCanPaste,
+ QWebEngineSettings::WebRTCPublicInterfacesOnly,
+ QWebEngineSettings::DnsPrefetchEnabled,
+ QWebEngineSettings::PdfViewerEnabled
};
const char * const findflag_tbl[] = {
"FindBackward",
- "FindCaseSensitively",
- "FindWrapsAroundDocument",
- "HighlightAllOccurrences"
+ "FindCaseSensitively"
};
-const QWebPage::FindFlag findflag_cod[] = {
- QWebPage::FindBackward,
- QWebPage::FindCaseSensitively,
- QWebPage::FindWrapsAroundDocument,
- QWebPage::HighlightAllOccurrences
+const QWebEnginePage::FindFlag findflag_cod[] = {
+ QWebEnginePage::FindBackward,
+ QWebEnginePage::FindCaseSensitively
};
-const QWebPage::WebAction actions_cod[] = {
- QWebPage::OpenLink,
- QWebPage::DownloadLinkToDisk,
- QWebPage::CopyLinkToClipboard,
- QWebPage::OpenImageInNewWindow,
- QWebPage::DownloadImageToDisk,
- QWebPage::CopyImageToClipboard,
- QWebPage::Back,
- QWebPage::Forward,
- QWebPage::Stop,
- QWebPage::Reload,
- QWebPage::Cut,
- QWebPage::Copy,
- QWebPage::Paste,
- QWebPage::InspectElement,
- QWebPage::SelectAll
+const QWebEnginePage::WebAction actions_cod[] = {
+ QWebEnginePage::NoWebAction,
+ QWebEnginePage::Back,
+ QWebEnginePage::Forward,
+ QWebEnginePage::Stop,
+ QWebEnginePage::Reload,
+ QWebEnginePage::ReloadAndBypassCache,
+ QWebEnginePage::Cut,
+ QWebEnginePage::Copy,
+ QWebEnginePage::Paste,
+ QWebEnginePage::Undo,
+ QWebEnginePage::Redo,
+ QWebEnginePage::SelectAll,
+ QWebEnginePage::PasteAndMatchStyle,
+ QWebEnginePage::OpenLinkInThisWindow,
+ QWebEnginePage::OpenLinkInNewWindow,
+ QWebEnginePage::OpenLinkInNewTab,
+ QWebEnginePage::OpenLinkInNewBackgroundTab,
+ QWebEnginePage::CopyLinkToClipboard,
+ QWebEnginePage::CopyImageToClipboard,
+ QWebEnginePage::CopyImageUrlToClipboard,
+ QWebEnginePage::CopyMediaUrlToClipboard,
+ QWebEnginePage::ToggleMediaControls,
+ QWebEnginePage::ToggleMediaLoop,
+ QWebEnginePage::ToggleMediaPlayPause,
+ QWebEnginePage::ToggleMediaMute,
+ QWebEnginePage::DownloadLinkToDisk,
+ QWebEnginePage::DownloadImageToDisk,
+ QWebEnginePage::DownloadMediaToDisk,
+ QWebEnginePage::InspectElement,
+ QWebEnginePage::ExitFullScreen,
+ QWebEnginePage::RequestClose,
+ QWebEnginePage::Unselect,
+ QWebEnginePage::SavePage,
+ QWebEnginePage::ViewSource,
+ QWebEnginePage::ToggleBold,
+ QWebEnginePage::ToggleItalic,
+ QWebEnginePage::ToggleUnderline,
+ QWebEnginePage::ToggleStrikethrough,
+ QWebEnginePage::AlignLeft,
+ QWebEnginePage::AlignCenter,
+ QWebEnginePage::AlignRight,
+ QWebEnginePage::AlignJustified,
+ QWebEnginePage::Indent,
+ QWebEnginePage::Outdent,
+ QWebEnginePage::InsertOrderedList,
+ QWebEnginePage::InsertUnorderedList
};
const char * const actions_tbl[] = {
- "OpenLink",
- "DownloadLinkToDisk",
- "CopyLinkToClipboard",
- "OpenImageInNewWindow",
- "DownloadImageToDisk",
- "CopyImageToClipboard",
+ "NoWebAction",
"Back",
"Forward",
"Stop",
"Reload",
+ "ReloadAndBypassCache",
"Cut",
"Copy",
"Paste",
+ "Undo",
+ "Redo",
+ "SelectAll",
+ "PasteAndMatchStyle",
+ "OpenLinkInThisWindow",
+ "OpenLinkInNewWindow",
+ "OpenLinkInNewTab",
+ "OpenLinkInNewBackgroundTab",
+ "CopyLinkToClipboard",
+ "CopyImageToClipboard",
+ "CopyImageUrlToClipboard",
+ "CopyMediaUrlToClipboard",
+ "ToggleMediaControls",
+ "ToggleMediaLoop",
+ "ToggleMediaPlayPause",
+ "ToggleMediaMute",
+ "DownloadLinkToDisk",
+ "DownloadImageToDisk",
+ "DownloadMediaToDisk",
"InspectElement",
- "SelectAll"
+ "ExitFullScreen",
+ "RequestClose",
+ "Unselect",
+ "SavePage",
+ "ViewSource",
+ "ToggleBold",
+ "ToggleItalic",
+ "ToggleUnderline",
+ "ToggleStrikethrough",
+ "AlignLeft",
+ "AlignCenter",
+ "AlignRight",
+ "AlignJustified",
+ "Indent",
+ "Outdent",
+ "InsertOrderedList",
+ "InsertUnorderedList"
};
#define webattributes_num (sizeof(webattributes_tbl) / sizeof(webattributes_tbl[0]))
@@ -202,66 +295,17 @@ const char * const actions_tbl[] = {
[pre]
FindBackward - Searches backwards instead of forwards;
FindCaseSensitively - Changes the behaviour to a case sensitive find operation.
- FindWrapsAroundDocument - Restart from the beginning of the document if the end was reached and the text was not found.
- HighlightAllOccurrences - Highlights all existing occurrences.
[/pre]
- !fn: <array> $frames()
- Returns an array containing the names of the document frames.
!fn: appendWebViewActionToMenu(<menu:h_object>,<webview_action:string>,[<icon_identifier>])
- !fn: <id:integer> $firstChild(<element_id:integer>)
- Return the identifier of element's first child.
- !fn: <array> $findAll(<element_id:integer>,<query:string>)
- Searches for all the elements named <query> and stores them in an array of element's identifiers.
- !fn: <id:integer> $findFirst(<element_id:integer>,<query:string>)
- Searches for the first element named <query>; returns the identifier.
- !fn: <id:integer> $parentElement(<element_id:integer>,)
- Returns the parent of <element_id>.
- !fn: <id:integer> $nextSibling(<element_id>)
- Returns the element just after <element_id>.
- !fn: $appendInside(<element_id>,<html_code>)
- !fn: $appendOutside(<element_id>,<html_code>)
- !fn: <string> $elementTagName(<element_id>)
- Returns the tag name of the <element_id>.
- !fn: <id:integer> $getDocumentElement([frame_name:string])
- Return as unique identifier the document element of the frame [frame_name].
- If no value has been specified for [frame_name], the main frame of the page will be used.
- !fn: string $attributeNames(<element_id>)
- Returns a comma-separated list of the attribute names set on element <element_id>.
- !fn: string $attribute(<element_id>,<name:string>)
- Returns the value of the attribute <name> for element <element_id>.
- !fn: setStyleProperty(<element_id>,<name:string>,<value:string>)
- Sets the value of the inline style on element <element_id> with the given name to <value> .
- In order to ensure that the value will be applied, you may have to append "!important" to the value.
- !fn: <value:string> styleProperty(<element_id>,<name:string>,<style_resolve_strategy:string>)
- Returns the value of the style with the given name using the specified strategy. If a style with name does not exist, an empty string is returned.
- Possible value for <style_resolve_strategy> are:
- [pre]
- CascadedStyle - the property's value is determined using the rules defined in the document's stylesheet. [b]This is the default strategy[/b].
- InlineStyle - the property's value is determined by element definition, without respecting CSS rules.
- ComputedStyle - the property's value is determined by the style property resolved from the environment.
- [/pre]
!fn: pixmap $makePreview()
Returns a 212x142 thumbnail of the current webView constants.
The returned object is an instance of the pixmap class.
- !fn: string $toPlainText(<element_id>)
- Returns the string representation of element <element_id>.
- !fn: string $setPlainText(<element_id>)
- Set the string representation of the element <element_id>.
- !fn: $setElementAttribute(<element_id>,<name:string>,<value:string>)
- Sets the attribute <name> with value <value> to the element <element_id>.
!fn: $setWebSetting(<name:string>,<value:bool>)
Enables or disables the <name> setting depending on <value>.
Valid settings name: JavascriptEnabled, PluginsEnabled, JavascriptCanOpenWindows, JavascriptCanAccessClipboard, ZoomTextOnly, LocalContentCanAccessFileUrls.
- !fn: $removeFromDocument(<element_id>)
- Removes the element <element_id> from the document.
- !fn: $removeClass(<element_id>,<class_name:string>)
- Removes a class from the element <element_id>.
- !fn: string $classes(<element_id>)
- Returns a comma-separated list of classes set on the element <element_id>.
!fn: $setLinkDelegationPolicy(<policy:string>)
Sets the link delegation policy: what happens when the users click on a link. Valid values:
[br] DontDelegateLinks: No links are delegated. Instead, webView tries to handle them all.
- [br] DelegateExternalLinks: When activating links that point to documents not stored on the local filesystem or an equivalent then $linkClickedEvent() is executed.
[br] DelegateAllLinks: Whenever a link is activated the $linkClickedEvent() is executed.
!fn: $linkClickedEvent()
This function can be called when the user clicks on a link, depending no the current link delegation policy.
@@ -313,48 +357,12 @@ KVSO_BEGIN_REGISTERCLASS(KvsObject_webView, "webview", "widget")
// page related
KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, load)
KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, setHtml)
-KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, frames)
KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, makePreview)
KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, appendWebViewActionToMenu)
KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, setLinkDelegationPolicy)
-
-// navigationn through the dom's tree
-KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, firstChild)
-KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, lastChild)
-KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, appendInside)
-KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, appendOutside)
-KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, parentElement)
-KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, nextSibling)
-
-// find dom's elements
-KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, findAll)
-KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, findFirst)
KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, findText)
-
-// element info
-KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, elementTagName)
-KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, getDocumentElement)
-KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, elementAttributeNames)
-KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, setElementAttribute)
-KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, elementAttribute)
-KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, hitTestContent)
-KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, toPlainText)
-KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, setPlainText)
-KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, removeFromDocument)
-KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, removeClass)
-KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, addClass)
-
-// css
-KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, setStyleProperty)
-KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, styleProperty)
-KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, setWebSetting)
-
-KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, classes)
-
-KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, setEventFilter)
-
-KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, addToJavaScriptWindowObject)
KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, evaluateJavaScript)
+KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, setWebSetting)
// events
KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_webView, jsChangeEvent)
@@ -378,79 +386,25 @@ KVSO_END_CONSTRUCTOR(KvsObject_webView)
KVSO_BEGIN_DESTRUCTOR(KvsObject_webView)
-m_elementMapper.clear();
KVSO_END_CONSTRUCTOR(KvsObject_webView)
bool KvsObject_webView::init(KviKvsRunTimeContext * c, KviKvsVariantList *)
{
//SET_OBJECT(KviKvsWebview);
- setObject(new KviKvsWebView(parentScriptWidget(), getName().toUtf8().data(), this), true);
- elementMapId = 1;
+ KviKvsWebView *pView = new KviKvsWebView(parentScriptWidget(), getName().toUtf8().data(), this);
+ setObject(pView, true);
+ KviKvsWebViewPage *pPage = new KviKvsWebViewPage(pView);
+ pView->setPage(pPage);
m_pContext = c;
m_pNetworkManager = new QNetworkAccessManager(this);
- QWebPage * pPage = ((QWebView *)widget())->page();
- connect(((QWebView *)widget()), SIGNAL(loadStarted()), this, SLOT(slotLoadStarted()));
- connect(((QWebView *)widget()), SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished(bool)));
- connect(((QWebView *)widget()), SIGNAL(loadProgress(int)), this, SLOT(slotLoadProgress(int)));
+ connect(pView, SIGNAL(loadStarted()), this, SLOT(slotLoadStarted()));
+ connect(pView, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished(bool)));
+ connect(pView, SIGNAL(loadProgress(int)), this, SLOT(slotLoadProgress(int)));
connect(pPage, SIGNAL(linkClicked(const QUrl &)), this, SLOT(slotLinkClicked(const QUrl &)));
- connect(pPage, SIGNAL(downloadRequested(const QNetworkRequest &)), this, SLOT(slotDownloadRequest(const QNetworkRequest &)));
+ connect(QWebEngineProfile::defaultProfile(), SIGNAL(downloadRequested(QWebEngineDownloadItem*)),
+ this, SLOT(slotDownloadRequest(QWebEngineDownloadItem*)));
return true;
}
-int KvsObject_webView::insertElement(const QWebElement & ele)
-{
- int eleid = getElementId(ele);
- if(!eleid)
- {
- m_elementMapper[elementMapId] = ele;
- return elementMapId++;
- }
- else
- return eleid;
-}
-int KvsObject_webView::getElementId(const QWebElement & ele)
-{
- QHashIterator<int, QWebElement> it(m_elementMapper);
- while(it.hasNext())
- {
- it.next();
- if(it.value() == ele)
- return it.key();
- }
- return 0;
-}
-
-QWebElement KvsObject_webView::getElement(int iIdx)
-{
- return m_elementMapper.value(iIdx);
-}
-void KvsObject_webView::getFrames(QWebFrame * pCurFrame, QStringList & szFramesNames)
-{
- szFramesNames.append(pCurFrame->title());
- QList<QWebFrame *> lFrames = pCurFrame->childFrames();
- for(int i = 0; i < lFrames.count(); i++)
- {
- QWebFrame * pChildFrame = lFrames.at(i);
- if(pChildFrame->childFrames().count())
- getFrames(pChildFrame, szFramesNames);
- }
-}
-QWebFrame * KvsObject_webView::findFrame(QWebFrame * pCurFrame, QString & szFrameName)
-{
- if(pCurFrame->title() == szFrameName)
- return pCurFrame;
- QList<QWebFrame *> lFrames = pCurFrame->childFrames();
- for(int i = 0; i < lFrames.count(); i++)
- {
- QWebFrame * pChildFrame = lFrames.at(i);
- if(pChildFrame->childFrames().count())
- {
- pCurFrame = findFrame(pChildFrame, szFrameName);
- if(pCurFrame)
- return pCurFrame;
- }
- }
- return nullptr;
-}
KVSO_CLASS_FUNCTION(webView, setLinkDelegationPolicy)
{
@@ -459,16 +413,15 @@ KVSO_CLASS_FUNCTION(webView, setLinkDelegationPolicy)
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("policy", KVS_PT_STRING, 0, szPolicy)
KVSO_PARAMETERS_END(c)
- QWebPage::LinkDelegationPolicy policy = QWebPage::DontDelegateLinks;
+ KviKvsWebViewPage::LinkDelegationPolicy policy = KviKvsWebViewPage::DontDelegateLinks;
if(KviQString::equalCI(szPolicy, "DontDelegateLinks"))
- policy = QWebPage::DontDelegateLinks;
- else if(KviQString::equalCI(szPolicy, "DelegateExternalLinks"))
- policy = QWebPage::DelegateExternalLinks;
+ policy = KviKvsWebViewPage::DontDelegateLinks;
else if(KviQString::equalCI(szPolicy, "DelegateAllLinks"))
- policy = QWebPage::DelegateAllLinks;
+ policy = KviKvsWebViewPage::DelegateAllLinks;
else
c->warning(__tr2qs_ctx("Unknown delegation policy '%Q'- Switch do default dontDelegateLinks", "objects"), &szPolicy);
- ((QWebView *)widget())->page()->setLinkDelegationPolicy(policy);
+
+ ((KviKvsWebViewPage *)((QWebEngineView *)widget())->page())->setLinkDelegationPolicy(policy);
return true;
}
@@ -479,7 +432,7 @@ KVSO_CLASS_FUNCTION(webView, load)
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("url", KVS_PT_STRING, 0, szUrl)
KVSO_PARAMETERS_END(c)
- ((QWebView *)widget())->load(QUrl(szUrl));
+ ((QWebEngineView *)widget())->load(QUrl::fromUserInput(szUrl));
return true;
}
KVSO_CLASS_FUNCTION(webView, setHtml)
@@ -490,32 +443,15 @@ KVSO_CLASS_FUNCTION(webView, setHtml)
KVSO_PARAMETER("szHtml", KVS_PT_STRING, 0, szHtml)
KVSO_PARAMETER("urlbase", KVS_PT_STRING, KVS_PF_OPTIONAL, szUrlBase)
KVSO_PARAMETERS_END(c)
- ((QWebView *)widget())->setHtml(szHtml, QUrl(szUrlBase));
+ ((QWebEngineView *)widget())->setHtml(szHtml, QUrl(szUrlBase));
return true;
}
KVSO_CLASS_FUNCTION(webView, makePreview)
{
CHECK_INTERNAL_POINTER(widget())
- QSize size = ((QWebView *)widget())->page()->mainFrame()->contentsSize();
+ //QSizeF size = ((QWebEngineView *)widget())->page()->contentsSize();
QImage * pImage = new QImage(212, 142, QImage::Format_RGB32);
- QWebFrame * pFrame = ((QWebView *)widget())->page()->mainFrame();
- QPainter painter(pImage);
- painter.setRenderHint(QPainter::Antialiasing, true);
- painter.setRenderHint(QPainter::TextAntialiasing, true);
- painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
- double dWScale = size.width() > 0 ? (212.0 / (double)(size.width())) : 0;
- double dHScale = dWScale;
- if((size.height() * dWScale) < 142)
- {
- // solution 1 is to fill the missing bacgkround
- painter.fillRect(0, 0, 212, 142, QColor(255, 255, 255));
- // solution 2 is to stretch the contents, but this doesn't work well because
- // the frame reports a size that doesn't exactly match the document
- //dHScale = 142.0 / (double)(size.height());
- }
- painter.scale(dWScale, dHScale);
- pFrame->documentElement().render(&painter);
- painter.end();
+ ((QWebEngineView *)widget())->render(pImage);
KviKvsObjectClass * pClass = KviKvsKernel::instance()->objectController()->lookupClass("pixmap");
KviKvsVariantList params;
KviKvsObject * pObject = pClass->allocateInstance(nullptr, "internalpixmap", c->context(), &params);
@@ -524,250 +460,29 @@ KVSO_CLASS_FUNCTION(webView, makePreview)
return true;
}
-KVSO_CLASS_FUNCTION(webView, findAll)
-{
- CHECK_INTERNAL_POINTER(widget())
- QString szQuery;
- KviKvsArray * pArray;
- kvs_int_t iEleId;
- KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("element_identifier", KVS_PT_INTEGER, 0, iEleId)
- KVSO_PARAMETER("query", KVS_PT_STRING, 0, szQuery)
- KVSO_PARAMETERS_END(c)
- QWebElement element = getElement(iEleId);
- if(element.isNull())
- {
- c->warning(__tr2qs_ctx("Document element with ID %d doesn't exist", "objects"), iEleId);
- return true;
- }
- QWebElementCollection elementCollection = element.findAll(szQuery);
- if(!elementCollection.count())
- return true;
- //qDebug("collection %i",elementCollection.count());
- int idx = 0;
- pArray = new KviKvsArray();
- for(int i = 0; i < elementCollection.count(); i++)
- {
- QWebElement element = elementCollection.at(i);
- int id = insertElement(element);
- pArray->set(idx, new KviKvsVariant((kvs_int_t)id));
- idx++;
- }
- c->returnValue()->setArray(pArray);
- return true;
-}
-
KVSO_CLASS_FUNCTION(webView, evaluateJavaScript)
{
CHECK_INTERNAL_POINTER(widget())
QString szScript;
kvs_int_t iEleId;
KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("element_identifier", KVS_PT_INTEGER, 0, iEleId)
KVSO_PARAMETER("script_code", KVS_PT_STRING, 0, szScript)
KVSO_PARAMETERS_END(c)
- QWebElement element = getElement(iEleId);
- if(element.isNull())
- {
- c->warning(__tr2qs_ctx("Document element is null: you must call getDocumentElement first", "objects"));
- return true;
- }
- QVariant vRes = element.evaluateJavaScript(szScript);
- if(vRes.type() == QVariant::String)
- {
- QString szVal = vRes.toString();
- c->returnValue()->setString(szVal);
- }
- else
- c->warning(__tr2qs_ctx("Unsupported datatype", "objects"));
- return true;
-}
-
-KVSO_CLASS_FUNCTION(webView, findFirst)
-{
- QString szQuery;
- kvs_int_t iEleId;
- KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("element_identifier", KVS_PT_INTEGER, 0, iEleId)
- KVSO_PARAMETER("query", KVS_PT_STRING, 0, szQuery)
- KVSO_PARAMETERS_END(c)
- QWebElement element = getElement(iEleId);
- if(element.isNull())
- {
- c->warning(__tr2qs_ctx("Document element with ID %d doesn't exist", "objects"), iEleId);
- return true;
- }
- QWebElement tempElement = element.findFirst(szQuery);
- if(tempElement.isNull())
- {
- c->returnValue()->setInteger(-1);
- return true;
- }
- int id = insertElement(tempElement);
- c->returnValue()->setInteger((kvs_int_t)id);
- return true;
-}
-
-KVSO_CLASS_FUNCTION(webView, removeFromDocument)
-{
- kvs_int_t iEleId;
- KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("element_identifier", KVS_PT_INTEGER, 0, iEleId)
- KVSO_PARAMETERS_END(c)
- QWebElement element = getElement(iEleId);
- if(element.isNull())
- {
- c->warning(__tr2qs_ctx("Document element with ID %d doesn't exist", "objects"), iEleId);
- return true;
- }
- element.removeFromDocument();
- return true;
-}
-
-KVSO_CLASS_FUNCTION(webView, appendInside)
-{
- kvs_int_t iEleId;
- QString szCode;
- KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("element_identifier", KVS_PT_INTEGER, 0, iEleId)
- KVSO_PARAMETER("name", KVS_PT_NONEMPTYSTRING, 0, szCode)
- KVSO_PARAMETERS_END(c)
- QWebElement element = getElement(iEleId);
- if(element.isNull())
- {
- c->warning(__tr2qs_ctx("Document element with ID %d doesn't exist", "objects"), iEleId);
- return true;
- }
- element.appendInside(szCode);
- return true;
-}
-
-KVSO_CLASS_FUNCTION(webView, appendOutside)
-{
- kvs_int_t iEleId;
- QString szCode;
- KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("element_identifier", KVS_PT_INTEGER, 0, iEleId)
- KVSO_PARAMETER("name", KVS_PT_NONEMPTYSTRING, 0, szCode)
- KVSO_PARAMETERS_END(c)
- QWebElement element = getElement(iEleId);
- if(element.isNull())
- {
- c->warning(__tr2qs_ctx("Document element with ID %d doesn't exist", "objects"), iEleId);
- return true;
- }
- element.appendOutside(szCode);
- return true;
-}
-KVSO_CLASS_FUNCTION(webView, nextSibling)
-{
- CHECK_INTERNAL_POINTER(widget())
- kvs_int_t iEleId;
- KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("element_identifier", KVS_PT_INTEGER, 0, iEleId)
- KVSO_PARAMETERS_END(c)
- QWebElement element = getElement(iEleId);
- if(element.isNull())
- {
- c->warning(__tr2qs_ctx("Document element with ID %d doesn't exist", "objects"), iEleId);
- return true;
- }
- QWebElement tempElement = element.nextSibling();
- if(tempElement.isNull())
- {
- c->returnValue()->setInteger(-1);
- return true;
- }
- int id = insertElement(tempElement);
- c->returnValue()->setInteger((kvs_int_t)id);
- return true;
-}
-
-KVSO_CLASS_FUNCTION(webView, frames)
-{
- CHECK_INTERNAL_POINTER(widget())
- QWebFrame * pFrame = ((QWebView *)widget())->page()->mainFrame();
- QStringList szFramesNames;
- getFrames(pFrame, szFramesNames);
- KviKvsArray * pArray = new KviKvsArray();
- c->returnValue()->setArray(pArray);
- return true;
-}
-
-KVSO_CLASS_FUNCTION(webView, elementTagName)
-{
- CHECK_INTERNAL_POINTER(widget())
- kvs_int_t iEleId;
- KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("element_identifier", KVS_PT_INTEGER, 0, iEleId)
- KVSO_PARAMETERS_END(c)
- QWebElement element = getElement(iEleId);
- if(element.isNull())
- {
- // qDebug("isnull ad index %i",iEleId);
- c->warning(__tr2qs_ctx("Document element with ID %d doesn't exist", "objects"), iEleId);
- return true;
- }
- c->returnValue()->setString(element.tagName());
- return true;
-}
-
-KVSO_CLASS_FUNCTION(webView, setElementAttribute)
-{
- CHECK_INTERNAL_POINTER(widget())
- QString szName, szValue;
- kvs_int_t iEleId;
- KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("element_identifier", KVS_PT_INTEGER, 0, iEleId)
- KVSO_PARAMETER("name", KVS_PT_NONEMPTYSTRING, 0, szName)
- KVSO_PARAMETER("value", KVS_PT_STRING, 0, szValue)
- KVSO_PARAMETERS_END(c)
- QWebElement element = getElement(iEleId);
- if(element.isNull())
- {
- c->warning(__tr2qs_ctx("Document element with ID %d doesn't exist", "objects"), iEleId);
- return true;
- }
- element.setAttribute(szName, szValue);
+ ((QWebEngineView *)widget())->page()->runJavaScript(szScript, [](const QVariant &vRes) {
+ /*
+ * FIXME NEEDS A CALLBACK
+ if(vRes.type() == QVariant::String)
+ {
+ QString szVal = vRes.toString();
+ c->returnValue()->setString(szVal);
+ }
+ else
+ c->warning(__tr2qs_ctx("Unsupported datatype", "objects"));
+ */
+ });
return true;
}
-KVSO_CLASS_FUNCTION(webView, removeClass)
-{
- CHECK_INTERNAL_POINTER(widget())
- QString szClassName;
- kvs_int_t iEleId;
- KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("element_identifier", KVS_PT_INTEGER, 0, iEleId)
- KVSO_PARAMETER("class_name", KVS_PT_NONEMPTYSTRING, 0, szClassName)
- KVSO_PARAMETERS_END(c)
- QWebElement element = getElement(iEleId);
- if(element.isNull())
- {
- c->warning(__tr2qs_ctx("Document element with ID %d doesn't exist", "objects"), iEleId);
- return true;
- }
- element.removeClass(szClassName);
- return true;
-}
-KVSO_CLASS_FUNCTION(webView, addClass)
-{
- CHECK_INTERNAL_POINTER(widget())
- QString szClassName;
- kvs_int_t iEleId;
- KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("element_identifier", KVS_PT_INTEGER, 0, iEleId)
- KVSO_PARAMETER("class_name", KVS_PT_NONEMPTYSTRING, 0, szClassName)
- KVSO_PARAMETERS_END(c)
- QWebElement element = getElement(iEleId);
- if(element.isNull())
- {
- c->warning(__tr2qs_ctx("Document element with ID %d doesn't exist", "objects"), iEleId);
- return true;
- }
- element.addClass(szClassName);
- return true;
-}
KVSO_CLASS_FUNCTION(webView, setWebSetting)
{
CHECK_INTERNAL_POINTER(widget())
@@ -788,7 +503,7 @@ KVSO_CLASS_FUNCTION(webView, setWebSetting)
}
}
if(found)
- ((QWebView *)widget())->settings()->setAttribute(webattributes_cod[j], bEnabled);
+ ((QWebEngineView *)widget())->settings()->setAttribute(webattributes_cod[j], bEnabled);
else
c->warning(__tr2qs_ctx("Unknown web setting '%Q'", "objects"), &szName);
return true;
@@ -820,307 +535,7 @@ KVSO_CLASS_FUNCTION(webView, findText)
else
c->warning(__tr2qs_ctx("Unknown findflag '%Q'", "objects"), &it);
}
- ((QWebView *)widget())->findText(szName, (QWebPage::FindFlags)findflag);
- return true;
-}
-KVSO_CLASS_FUNCTION(webView, elementAttribute)
-{
- CHECK_INTERNAL_POINTER(widget())
- QString szName;
- kvs_int_t iEleId;
- KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("element_identifier", KVS_PT_INTEGER, 0, iEleId)
- KVSO_PARAMETER("name", KVS_PT_NONEMPTYSTRING, 0, szName)
- KVSO_PARAMETERS_END(c)
- QWebElement element = getElement(iEleId);
- if(element.isNull())
- {
- c->warning(__tr2qs_ctx("Document element with ID %d doesn't exist", "objects"), iEleId);
- return true;
- }
-
- // workaround for this issue: https://bugreports.qt.nokia.com//browse/QTWEBKIT-88
- if(KviQString::equalCI(element.tagName(), "input"))
- {
- QVariant value = element.evaluateJavaScript("this." + szName);
- c->returnValue()->setString(value.toString());
- return true;
- }
- c->returnValue()->setString(element.attribute(szName));
- return true;
-}
-
-KVSO_CLASS_FUNCTION(webView, elementAttributeNames)
-{
- CHECK_INTERNAL_POINTER(widget())
- kvs_int_t iEleId;
- KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("identifier", KVS_PT_INTEGER, 0, iEleId)
- KVSO_PARAMETERS_END(c)
- QString szAttributeNames;
- QWebElement element = getElement(iEleId);
- if(element.isNull())
- {
- c->warning(__tr2qs_ctx("Document element with ID %d doesn't exist", "objects"), iEleId);
- return true;
- }
- szAttributeNames = element.attributeNames().join(",");
- c->returnValue()->setString(szAttributeNames);
- return true;
-}
-KVSO_CLASS_FUNCTION(webView, classes)
-{
- CHECK_INTERNAL_POINTER(widget())
- kvs_int_t iEleId;
- KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("identifier", KVS_PT_INTEGER, 0, iEleId)
- KVSO_PARAMETERS_END(c)
- QWebElement element = getElement(iEleId);
- if(element.isNull())
- {
- c->warning(__tr2qs_ctx("Document element with ID %d doesn't exist", "objects"), iEleId);
- return true;
- }
- QString szClasses;
- szClasses = element.classes().join(",");
- c->returnValue()->setString(szClasses);
- return true;
-}
-
-KVSO_CLASS_FUNCTION(webView, toPlainText)
-{
- CHECK_INTERNAL_POINTER(widget())
- kvs_int_t iEleId;
- KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("identifier", KVS_PT_INTEGER, 0, iEleId)
- KVSO_PARAMETERS_END(c)
- QWebElement element = getElement(iEleId);
- if(element.isNull())
- {
- c->warning(__tr2qs_ctx("Document element with ID %d doesn't exist", "objects"), iEleId);
- return true;
- }
- c->returnValue()->setString(element.toPlainText());
- return true;
-}
-KVSO_CLASS_FUNCTION(webView, setPlainText)
-{
- CHECK_INTERNAL_POINTER(widget())
- QString szText;
- kvs_int_t iEleId;
- KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("identifier", KVS_PT_INTEGER, 0, iEleId)
- KVSO_PARAMETER("plaintext", KVS_PT_STRING, 0, szText)
- KVSO_PARAMETERS_END(c)
- QWebElement element = getElement(iEleId);
- if(element.isNull())
- {
- c->warning(__tr2qs_ctx("Document element with ID %d doesn't exist", "objects"), iEleId);
- return true;
- }
- element.setPlainText(szText);
- return true;
-}
-
-KVSO_CLASS_FUNCTION(webView, firstChild)
-{
- CHECK_INTERNAL_POINTER(widget())
- kvs_int_t iEleId;
- KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("identifier", KVS_PT_INTEGER, 0, iEleId)
- KVSO_PARAMETERS_END(c)
- QWebElement element = getElement(iEleId);
- if(element.isNull())
- {
- c->warning(__tr2qs_ctx("Document element with ID %d doesn't exist", "objects"), iEleId);
- return true;
- }
-
- QWebElement tempElement = element.firstChild();
- if(tempElement.isNull())
- {
- c->returnValue()->setInteger(-1);
- return true;
- }
- int id = insertElement(tempElement);
- c->returnValue()->setInteger((kvs_int_t)id);
- return true;
-}
-KVSO_CLASS_FUNCTION(webView, lastChild)
-{
- CHECK_INTERNAL_POINTER(widget())
- kvs_int_t iEleId;
- KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("identifier", KVS_PT_INTEGER, 0, iEleId)
- KVSO_PARAMETERS_END(c)
- QWebElement element = getElement(iEleId);
- if(element.isNull())
- {
- c->warning(__tr2qs_ctx("Document element with ID %d doesn't exist", "objects"), iEleId);
- return true;
- }
-
- QWebElement tempElement = element.lastChild();
- if(tempElement.isNull())
- {
- c->returnValue()->setInteger(-1);
- return true;
- }
- int id = insertElement(tempElement);
- c->returnValue()->setInteger((kvs_int_t)id);
- return true;
-}
-KVSO_CLASS_FUNCTION(webView, parentElement)
-{
- CHECK_INTERNAL_POINTER(widget())
- kvs_int_t iEleId;
- KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("identifier", KVS_PT_INTEGER, 0, iEleId)
- KVSO_PARAMETERS_END(c)
- QWebElement element = getElement(iEleId);
- if(element.isNull())
- {
- c->warning(__tr2qs_ctx("Document element with ID %d doesn't exist", "objects"), iEleId);
- return true;
- }
-
- QWebElement tempElement = element.parent();
- if(tempElement.isNull())
- {
- c->returnValue()->setInteger(-1);
- return true;
- }
- int id = insertElement(tempElement);
- c->returnValue()->setInteger((kvs_int_t)id);
- return true;
-}
-
-KVSO_CLASS_FUNCTION(webView, styleProperty)
-{
- CHECK_INTERNAL_POINTER(widget())
- QString szName, szStyleResolveStrategy;
- kvs_int_t iEleId;
- KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("identifier", KVS_PT_INTEGER, 0, iEleId)
- KVSO_PARAMETER("name", KVS_PT_NONEMPTYSTRING, 0, szName)
- KVSO_PARAMETER("style_resolve_strategy", KVS_PT_STRING, KVS_PF_OPTIONAL, szStyleResolveStrategy)
- KVSO_PARAMETERS_END(c)
- QWebElement element = getElement(iEleId);
- if(element.isNull())
- {
- c->warning(__tr2qs_ctx("Document element with ID %d doesn't exist", "objects"), iEleId);
- return true;
- }
- QWebElement::StyleResolveStrategy styleStrategy = QWebElement::CascadedStyle;
- if(!szStyleResolveStrategy.isEmpty())
- {
- if(KviQString::equalCI(szStyleResolveStrategy, "InlineStyle"))
- styleStrategy = QWebElement::InlineStyle;
- else if(KviQString::equalCI(szStyleResolveStrategy, "CascadedStyle"))
- styleStrategy = QWebElement::CascadedStyle;
- else if(KviQString::equalCI(szStyleResolveStrategy, "ComputedStyle"))
- styleStrategy = QWebElement::ComputedStyle;
- else
- {
- c->warning(__tr2qs_ctx("Unknown styleResolveStrategy: '%Q' - Switching to default CascadedStyle strategy", "objects"), &szStyleResolveStrategy);
- }
- }
- c->returnValue()->setString(element.styleProperty(szName, styleStrategy));
- return true;
-}
-KVSO_CLASS_FUNCTION(webView, setStyleProperty)
-{
- CHECK_INTERNAL_POINTER(widget())
- QString szProperty, szValue;
- kvs_int_t iEleId;
- KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("identifier", KVS_PT_INTEGER, 0, iEleId)
- KVSO_PARAMETER("property", KVS_PT_STRING, 0, szProperty)
- KVSO_PARAMETER("value", KVS_PT_STRING, 0, szValue)
- KVSO_PARAMETERS_END(c)
- QWebElement element = getElement(iEleId);
- if(element.isNull())
- {
- c->warning(__tr2qs_ctx("Document element with ID %d doesn't exist", "objects"), iEleId);
- return true;
- }
- element.setStyleProperty(szProperty, szValue);
- return true;
-}
-
-KVSO_CLASS_FUNCTION(webView, getDocumentElement)
-{
- CHECK_INTERNAL_POINTER(widget())
- QString szFrameName;
- KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("frame_name", KVS_PT_STRING, KVS_PF_OPTIONAL, szFrameName)
- KVSO_PARAMETERS_END(c)
- QWebFrame * pFrame;
- pFrame = ((QWebView *)widget())->page()->mainFrame();
- if(!szFrameName.isEmpty())
- {
- pFrame = findFrame(pFrame, szFrameName);
- if(!pFrame)
- {
- c->warning(__tr2qs_ctx("Unknown frame '%Q'", "objects"), &szFrameName);
- return true;
- }
- }
- int id = insertElement(pFrame->documentElement());
- c->returnValue()->setInteger((kvs_int_t)id);
- return true;
-}
-KVSO_CLASS_FUNCTION(webView, addToJavaScriptWindowObject)
-{
- CHECK_INTERNAL_POINTER(widget())
- QString szFrameName, szObjectName;
- KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("object_name", KVS_PT_NONEMPTYSTRING, 0, szObjectName)
- KVSO_PARAMETER("frame_name", KVS_PT_STRING, KVS_PF_OPTIONAL, szFrameName)
- KVSO_PARAMETERS_END(c)
- QWebFrame * pFrame;
- pFrame = ((QWebView *)widget())->page()->mainFrame();
- if(!szFrameName.isEmpty())
- {
- pFrame = findFrame(pFrame, szFrameName);
- if(!pFrame)
- {
- c->warning(__tr2qs_ctx("Unknown frame '%Q'", "objects"), &szFrameName);
- return true;
- }
- }
- pFrame->addToJavaScriptWindowObject(szObjectName, this);
- return true;
-}
-KVSO_CLASS_FUNCTION(webView, setEventFilter)
-{
- QWebFrame * pFrame;
- pFrame = ((QWebView *)widget())->page()->mainFrame();
- pFrame->addToJavaScriptWindowObject("kvs", this);
- return true;
-}
-
-KVSO_CLASS_FUNCTION(webView, hitTestContent)
-{
- CHECK_INTERNAL_POINTER(widget())
- kvs_int_t iYPos, iXPos;
- KVSO_PARAMETERS_BEGIN(c)
- KVSO_PARAMETER("x_pos", KVS_PT_INT, 0, iXPos)
- KVSO_PARAMETER("y_pos", KVS_PT_INT, 0, iYPos)
- KVSO_PARAMETERS_END(c)
- QWebFrame * pFrame;
- pFrame = ((QWebView *)widget())->page()->mainFrame();
- QWebHitTestResult res = pFrame->hitTestContent(QPoint(iXPos, iYPos));
- if(res.isNull())
- return true;
- KviKvsHash * pHash = new KviKvsHash();
- pHash->set("imageurl", new KviKvsVariant(res.imageUrl().toString()));
- pHash->set("linktitle", new KviKvsVariant(res.linkTitleString()));
- pHash->set("linktext", new KviKvsVariant(res.linkText()));
- pHash->set("linkelement", new KviKvsVariant((kvs_int_t)insertElement(res.linkElement())));
- pHash->set("enclosingelement", new KviKvsVariant((kvs_int_t)insertElement(res.enclosingBlockElement())));
- pHash->set("element", new KviKvsVariant((kvs_int_t)insertElement(res.element())));
- c->returnValue()->setHash(pHash);
+ ((QWebEngineView *)widget())->findText(szName, (QWebEnginePage::FindFlags)findflag);
return true;
}
@@ -1156,7 +571,7 @@ KVSO_CLASS_FUNCTION(webView, appendWebViewActionToMenu)
{
if(KviQString::equalCI(szActionName, actions_tbl[i]))
{
- pAction = ((QWebView *)widget())->pageAction(actions_cod[i]);
+ pAction = ((QWebEngineView *)widget())->pageAction(actions_cod[i]);
break;
}
}
@@ -1279,8 +694,6 @@ void KvsObject_webView::slotOnMouseOut(QString szParam)
// slots
void KvsObject_webView::slotLoadFinished(bool bOk)
{
- if(bOk)
- m_currentElement = ((QWebView *)widget())->page()->mainFrame()->documentElement();
KviKvsVariantList params(new KviKvsVariant(bOk));
callFunction(this, "loadFinishedEvent", &params);
}
@@ -1304,31 +717,22 @@ void KvsObject_webView::slotLinkClicked(const QUrl & url)
callFunction(this, "linkClickedEvent", &params);
}
-void KvsObject_webView::slotDownloadRequest(const QNetworkRequest & r)
+void KvsObject_webView::slotDownloadRequest(QWebEngineDownloadItem *pDownload)
{
- QNetworkReply * pReply = m_pNetworkManager->get(r);
QString szFilePath = "";
KviKvsVariant * filepathret = new KviKvsVariant(szFilePath);
- KviKvsVariantList params(new KviKvsVariant(r.url().toString()));
+ KviKvsVariantList params(new KviKvsVariant(pDownload->url().toString()));
callFunction(this, "downloadRequestEvent", filepathret, &params);
filepathret->asString(szFilePath);
if(!szFilePath.isEmpty())
{
- QFile * pFile = new QFile(szFilePath);
- if(!pFile->open(QIODevice::WriteOnly))
- {
- m_pContext->warning(__tr2qs_ctx("Invalid file path '%Q'", "objects"), &szFilePath);
- pReply->abort();
- pReply->deleteLater();
- return;
- }
- (void)new KviKvsDownloadHandler(this, pFile, pReply, g_iDownloadId);
+ (void)new KviKvsDownloadHandler(this, szFilePath, pDownload, g_iDownloadId);
g_iDownloadId++;
}
}
KviKvsWebView::KviKvsWebView(QWidget * par, const char * name, KvsObject_webView * parent)
- : QWebView(par)
+ : QWebEngineView(par)
{
m_pParentScript = parent;
setObjectName(name);
@@ -1341,11 +745,11 @@ void KviKvsWebView::mouseMoveEvent(QMouseEvent * ev)
lParams.append(new KviKvsVariant((kvs_int_t)ev->x()));
lParams.append(new KviKvsVariant((kvs_int_t)ev->y()));
if(!m_pParentScript->callFunction(m_pParentScript, "mouseMoveEvent", &vRetValue, &lParams))
- QWebView::mouseMoveEvent(ev); // ignore results of a broken event handler
+ QWebEngineView::mouseMoveEvent(ev); // ignore results of a broken event handler
else
{
if(!vRetValue.asBoolean())
- QWebView::mouseMoveEvent(ev);
+ QWebEngineView::mouseMoveEvent(ev);
}
}
void KviKvsWebView::contextMenuEvent(QContextMenuEvent * ev)
@@ -1355,11 +759,11 @@ void KviKvsWebView::contextMenuEvent(QContextMenuEvent * ev)
lParams.append(new KviKvsVariant((kvs_int_t)ev->x()));
lParams.append(new KviKvsVariant((kvs_int_t)ev->y()));
if(!m_pParentScript->callFunction(m_pParentScript, "customContextMenuRequestedEvent", &vRetValue, &lParams))
- QWebView::contextMenuEvent(ev); // ignore results of a broken event handler
+ QWebEngineView::contextMenuEvent(ev); // ignore results of a broken event handler
else
{
if(!vRetValue.asBoolean())
- QWebView::contextMenuEvent(ev);
+ QWebEngineView::contextMenuEvent(ev);
}
}
bool KviKvsWebView::event(QEvent * e)
@@ -1379,7 +783,7 @@ bool KviKvsWebView::event(QEvent * e)
return false;
}
}
- return QWebView::event(e);
+ return QWebEngineView::event(e);
}
KviKvsWebView::~KviKvsWebView()
= default;
diff --git a/src/modules/objects/KvsObject_webView.h b/src/modules/objects/KvsObject_webView.h
index 92c47804a..b396a38bb 100644
--- a/src/modules/objects/KvsObject_webView.h
+++ b/src/modules/objects/KvsObject_webView.h
@@ -30,14 +30,15 @@
#include "object_macros.h"
#include <QFile>
#include <QNetworkAccessManager>
-#include <QWebView>
-#include <QWebFrame>
-#include <QWebElement>
+#include <QWebEngineView>
+#include <QWebEnginePage>
#include <QMouseEvent>
#include <QContextMenuEvent>
+class QWebEngineDownloadItem;
class KvsObject_webView;
-class KviKvsWebView : public QWebView
+
+class KviKvsWebView : public QWebEngineView
{
Q_OBJECT
public:
@@ -59,6 +60,47 @@ protected:
*/
};
+class KviKvsWebViewPage : public QWebEnginePage
+{
+ Q_OBJECT
+public:
+ enum LinkDelegationPolicy
+ {
+ DontDelegateLinks,
+ DelegateAllLinks
+ };
+
+ KviKvsWebViewPage(QObject* parent = 0) : QWebEnginePage(parent){}
+
+ bool acceptNavigationRequest(const QUrl & url, QWebEnginePage::NavigationType type, bool)
+ {
+ if (type == QWebEnginePage::NavigationTypeLinkClicked)
+ {
+ emit linkClicked(url);
+ switch(m_ePolicy)
+ {
+ case DelegateAllLinks:
+ return false;
+ case DontDelegateLinks:
+ default:
+ return true;
+ }
+ }
+ return true;
+ }
+
+ void setLinkDelegationPolicy(LinkDelegationPolicy policy)
+ {
+ m_ePolicy = policy;
+ }
+
+protected:
+ LinkDelegationPolicy m_ePolicy = DontDelegateLinks;
+signals:
+ void linkClicked(const QUrl&);
+
+};
+
class KvsObject_webView : public KviKvsObject
{
Q_OBJECT
@@ -66,61 +108,19 @@ public:
KVSO_DECLARE_OBJECT(KvsObject_webView)
protected:
KviKvsRunTimeContext * m_pContext = nullptr;
- int elementMapId = 1;
- int insertElement(const QWebElement & ele);
- QWebElement getElement(int iIdx);
- int getElementId(const QWebElement &);
- QHash<int, QWebElement> m_elementMapper;
- KviPointerList<KviKvsObject> * lWebelement = nullptr;
- QHash<QString, QWebElement *> m_dictCache;
KviPointerList<QNetworkReply> * m_pReplyList = nullptr;
QNetworkAccessManager * m_pNetworkManager = nullptr;
- QWebElementCollection m_webElementCollection;
- QWebElement m_currentElement;
public:
QWidget * widget() { return (QWidget *)object(); }
protected:
- void getFrames(QWebFrame * pCurFrame, QStringList & szFramesNames);
- QWebFrame * findFrame(QWebFrame * pCurFrame, QString & szFrameName);
bool init(KviKvsRunTimeContext * pContext, KviKvsVariantList * pParams) override;
- bool removeFromDocument(KviKvsObjectFunctionCall * c);
bool makePreview(KviKvsObjectFunctionCall * c);
-
- bool removeClass(KviKvsObjectFunctionCall * c);
- bool addClass(KviKvsObjectFunctionCall * c);
-
- bool classes(KviKvsObjectFunctionCall * c);
-
- bool firstChild(KviKvsObjectFunctionCall * c);
- bool lastChild(KviKvsObjectFunctionCall * c);
- bool parentElement(KviKvsObjectFunctionCall * c);
- bool nextSibling(KviKvsObjectFunctionCall * c);
-
- bool toPlainText(KviKvsObjectFunctionCall * c);
- bool setPlainText(KviKvsObjectFunctionCall * c);
bool load(KviKvsObjectFunctionCall * c);
bool setHtml(KviKvsObjectFunctionCall * c);
- bool getDocumentElement(KviKvsObjectFunctionCall * c);
- bool elementTagName(KviKvsObjectFunctionCall * c);
- bool findAll(KviKvsObjectFunctionCall * c);
- bool appendInside(KviKvsObjectFunctionCall * c);
- bool appendOutside(KviKvsObjectFunctionCall * c);
-
- bool findFirst(KviKvsObjectFunctionCall * c);
bool findText(KviKvsObjectFunctionCall * c);
-
- bool hitTestContent(KviKvsObjectFunctionCall * c);
-
- bool elementAttributeNames(KviKvsObjectFunctionCall * c);
bool setLinkDelegationPolicy(KviKvsObjectFunctionCall * c);
- bool setElementAttribute(KviKvsObjectFunctionCall * c);
bool setWebSetting(KviKvsObjectFunctionCall * c);
- bool elementAttribute(KviKvsObjectFunctionCall * c);
- bool frames(KviKvsObjectFunctionCall * c);
-
- bool setStyleProperty(KviKvsObjectFunctionCall * c);
- bool styleProperty(KviKvsObjectFunctionCall * c);
bool appendWebViewActionToMenu(KviKvsObjectFunctionCall * c);
bool loadStartedEvent(KviKvsObjectFunctionCall * c);
@@ -134,7 +134,6 @@ protected:
bool evaluateJavaScript(KviKvsObjectFunctionCall * c);
//
- bool setEventFilter(KviKvsObjectFunctionCall * c);
bool jsChangeEvent(KviKvsObjectFunctionCall * c);
bool jsSubmitEvent(KviKvsObjectFunctionCall * c);
bool jsClickEvent(KviKvsObjectFunctionCall * c);
@@ -144,7 +143,7 @@ protected slots:
void slotLoadFinished(bool);
void slotLoadProgress(int);
void slotLoadStarted();
- void slotDownloadRequest(const QNetworkRequest &);
+ void slotDownloadRequest(QWebEngineDownloadItem *);
void slotLinkClicked(const QUrl &);
void slotOnChange(QString);
@@ -158,18 +157,17 @@ class KviKvsDownloadHandler : public QObject
{
Q_OBJECT
public:
- KviKvsDownloadHandler(KvsObject_webView * pParent, QFile * pFile, QNetworkReply * pNetReply, int iId);
+ KviKvsDownloadHandler(KvsObject_webView * pParent, QString &szFilePath, QWebEngineDownloadItem * pDownload, int iId);
~KviKvsDownloadHandler();
protected:
KvsObject_webView * m_pParentScript;
- QFile * m_pFile;
- QNetworkReply * m_pReply;
+ QWebEngineDownloadItem * m_pDownload;
int m_Id;
protected slots:
- void slotReadyRead();
- void slotReplyFinished();
+ void slotDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
+ void slotFinished();
};
#endif // COMPILE_WEBKIT_SUPPORT
diff --git a/src/modules/objects/KvsObject_widget.h b/src/modules/objects/KvsObject_widget.h
index a7fc36a17..ef5cd158f 100644
--- a/src/modules/objects/KvsObject_widget.h
+++ b/src/modules/objects/KvsObject_widget.h
@@ -33,7 +33,7 @@
#include <QGraphicsEffect>
#ifdef COMPILE_WEBKIT_SUPPORT
-#include <QtWebKitWidgets/QWebView>
+#include <QWebEngineView>
#endif
class KvsObject_widget : public KviKvsObject
@@ -49,7 +49,7 @@ protected:
bool init(KviKvsRunTimeContext * pContext, KviKvsVariantList * pParams) override;
#ifdef COMPILE_WEBKIT_SUPPORT
- QWebView * m_pWebview = nullptr;
+ QWebEngineView * m_pWebview = nullptr;
#endif
bool eventFilter(QObject * o, QEvent * e) override;
KviKvsRunTimeContext * m_pContext = nullptr;