Warning, /pim/mimetreeparser/src/quick/qml/private/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.pim.mimetreeparser 1.0
0011 
0012 Item {
0013     id: root
0014     objectName: "htmlPart"
0015     property string content
0016     //We have to give it a minimum size so the html content starts to expand
0017     property int minimumSize: 10
0018     property int contentHeight: minimumSize
0019     property int contentWidth: minimumSize
0020     property string searchString
0021     property bool autoLoadImages: false
0022 
0023     onSearchStringChanged: {
0024         htmlView.findText(searchString)
0025     }
0026     onContentChanged: {
0027         htmlView.loadHtml(content, "file:///");
0028     }
0029 
0030     QQC2.ScrollView {
0031         anchors.fill: parent
0032         Flickable {
0033             id: flickable
0034 
0035             clip: true
0036             boundsBehavior: Flickable.StopAtBounds
0037 
0038             WebEngineView {
0039                 id: htmlView
0040                 objectName: "htmlView"
0041                 anchors.fill: parent
0042 
0043                 Component.onCompleted: loadHtml(content, "file:///")
0044                 onLoadingChanged: loadingInfo => {
0045                     if (loadingInfo.status == WebEngineView.LoadFailedStatus) {
0046                         console.warn("Failed to load html content.")
0047                         console.warn("Error is ", loadingInfo.errorString)
0048                     }
0049                     root.contentWidth = Math.max(contentsSize.width, flickable.minimumSize)
0050 
0051                     if (loadingInfo.status == WebEngineView.LoadSucceededStatus) {
0052                         runJavaScript("[document.body.scrollHeight, document.body.scrollWidth, document.documentElement.scrollHeight]", function(result) {
0053                             root.contentHeight = Math.min(Math.max(result[0], result[2]), 4000);
0054                             root.contentWidth = Math.min(Math.max(result[1], flickable.width), 2000)
0055                         });
0056                     }
0057                 }
0058                 onLinkHovered: hoveredUrl => {
0059                     // Qt 6.6.1 needs to toString otherwise we get a compile error
0060                     // https://bugreports.qt.io/browse/QTBUG-119165
0061                     console.debug("Link hovered ", hoveredUrl.toString())
0062                 }
0063                 onNavigationRequested: request => {
0064                     console.debug("Nav request ", request.navigationType, request.url)
0065                     if (request.navigationType == WebEngineNavigationRequest.LinkClickedNavigation) {
0066                         Qt.openUrlExternally(request.url)
0067                         request.action = WebEngineNavigationRequest.IgnoreRequest
0068                     }
0069                 }
0070                 settings {
0071                     webGLEnabled: false
0072                     touchIconsEnabled: false
0073                     spatialNavigationEnabled: false
0074                     screenCaptureEnabled: false
0075                     pluginsEnabled: false
0076                     localStorageEnabled: false
0077                     localContentCanAccessRemoteUrls: false
0078                     localContentCanAccessFileUrls: false
0079                     linksIncludedInFocusChain: false
0080                     javascriptEnabled: true
0081                     javascriptCanOpenWindows: false
0082                     javascriptCanAccessClipboard: false
0083                     hyperlinkAuditingEnabled: false
0084                     fullScreenSupportEnabled: false
0085                     errorPageEnabled: false
0086                     //defaultTextEncoding: ???
0087                     autoLoadImages: root.autoLoadImages
0088                     autoLoadIconsForPage: false
0089                     accelerated2dCanvasEnabled: false
0090                     //The webview should not steal focus
0091                     focusOnNavigationEnabled: false
0092                 }
0093                 profile {
0094                     offTheRecord: true
0095                     httpCacheType: WebEngineProfile.NoCache
0096                     persistentCookiesPolicy: WebEngineProfile.NoPersistentCookies
0097                 }
0098                 onContextMenuRequested: request => {
0099                     request.accepted = true
0100                 }
0101             }
0102         }
0103     }
0104 }