Warning, /plasma-mobile/raven/src/contents/ui/mailpartview/HtmlPart.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2016 Michael Bohlender <michael.bohlender@kdemail.net>
0002 // SPDX-License-Identifier: GPL-2.0-or-later
0003 
0004 
0005 import QtQuick 2.7
0006 import QtQuick.Controls 2.15 as QQC2
0007 import QtWebEngine 1.4
0008 import QtQuick.Window 2.0
0009 
0010 import org.kde.raven 1.0
0011 import org.kde.kirigami 2.19 as Kirigami
0012 
0013 Item {
0014     id: root
0015     objectName: "htmlPart"
0016     property string content
0017     //We have to give it a minimum size so the html content starts to expand
0018     property int minimumSize: 10
0019     property int contentHeight: minimumSize
0020     property int contentWidth: minimumSize
0021     property string searchString
0022     property bool autoLoadImages: false
0023 
0024     onSearchStringChanged: {
0025         htmlView.findText(searchString)
0026     }
0027     onContentChanged: {
0028         htmlView.loadHtml(content, "file:///");
0029     }
0030 
0031     QQC2.ScrollView {
0032         anchors.fill: parent
0033         Flickable {
0034             id: flickable
0035 
0036             clip: true
0037             boundsBehavior: Flickable.StopAtBounds
0038 
0039             WebEngineView {
0040                 id: htmlView
0041                 objectName: "htmlView"
0042                 anchors.fill: parent
0043 
0044                 Component.onCompleted: loadHtml(content, "file:///")
0045                 onLoadingChanged: {
0046                     if (loadRequest.status == WebEngineView.LoadFailedStatus) {
0047                         console.warn("Failed to load html content.")
0048                         console.warn("Error is ", loadRequest.errorString)
0049                     }
0050                     root.contentWidth = Math.max(contentsSize.width, flickable.minimumSize)
0051 
0052                     if (loadRequest.status == WebEngineView.LoadSucceededStatus) {
0053                         runJavaScript("[document.body.scrollHeight, document.body.scrollWidth, document.documentElement.scrollHeight]", function(result) {
0054                             root.contentHeight = Math.min(Math.max(result[0], result[2]), 4000);
0055                             root.contentWidth = Math.min(Math.max(result[1], flickable.width), 2000)
0056                         });
0057                     }
0058                 }
0059                 onLinkHovered: {
0060                     console.debug("Link hovered ", hoveredUrl)
0061                 }
0062                 onNavigationRequested: {
0063                     console.debug("Nav request ", request.navigationType, request.url)
0064                     if (request.navigationType == WebEngineNavigationRequest.LinkClickedNavigation) {
0065                         Qt.openUrlExternally(request.url)
0066                         request.action = WebEngineNavigationRequest.IgnoreRequest
0067                     }
0068                 }
0069                 onNewViewRequested: {
0070                     console.debug("New view request ", request, request.requestedUrl)
0071                     //We ignore requests for new views and open a browser instead
0072                     Qt.openUrlExternally(request.requestedUrl)
0073                 }
0074                 settings {
0075                     webGLEnabled: false
0076                     touchIconsEnabled: false
0077                     spatialNavigationEnabled: false
0078                     screenCaptureEnabled: false
0079                     pluginsEnabled: false
0080                     localStorageEnabled: false
0081                     localContentCanAccessRemoteUrls: false
0082                     localContentCanAccessFileUrls: false
0083                     linksIncludedInFocusChain: false
0084                     javascriptEnabled: true
0085                     javascriptCanOpenWindows: false
0086                     javascriptCanAccessClipboard: false
0087                     hyperlinkAuditingEnabled: false
0088                     fullScreenSupportEnabled: false
0089                     errorPageEnabled: false
0090                     //defaultTextEncoding: ???
0091                     autoLoadImages: root.autoLoadImages
0092                     autoLoadIconsForPage: false
0093                     accelerated2dCanvasEnabled: false
0094                     //The webview should not steal focus
0095                     focusOnNavigationEnabled: false
0096                 }
0097                 profile {
0098                     offTheRecord: true
0099                     httpCacheType: WebEngineProfile.NoCache
0100                     persistentCookiesPolicy: WebEngineProfile.NoPersistentCookies
0101                 }
0102                 onContextMenuRequested: function(request) {
0103                     request.accepted = true
0104                 }
0105             }
0106         }
0107     }
0108 }