Commit 30c6d456 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

[WebBrowser Plasmoid] Port to QtWebEngine

QtWebkit is old, unmaintained, possibly insecure, and also has quite a few bugs nowadays.
This also adds a couple of smaller features while at it:

* Reload button turns into a Stop button while loading
* Cursor changes shape over links
* Address bar selects all text when clicked to ease typing a completely new address
* Browser forward/back button on the mouse work

as well as a slew of features brought in by QtWebEngine, such as:

* Text selection support
* Context menu with "Copy link" and others

BUG: 371023
BUG: 361939
FIXED-IN: 5.13.0

Differential Revision: https://phabricator.kde.org/D10039
parent d7bf4598
plasma_install_package(activitypager org.kde.plasma.activitypager)
plasma_install_package(kickerdash org.kde.plasma.kickerdash)
plasma_install_package(konsoleprofiles/package org.kde.plasma.konsoleprofiles)
plasma_install_package(webbrowser org.kde.plasma.webbrowser)
add_subdirectory(binary-clock)
add_subdirectory(calculator)
......@@ -27,3 +26,4 @@ endif(NOT WIN32)
add_subdirectory(timer)
add_subdirectory(userswitcher)
add_subdirectory(weather)
add_subdirectory(webbrowser)
find_package(Qt5WebEngine ${REQUIRED_QT_VERSION} CONFIG)
set_package_properties(Qt5WebEngine PROPERTIES
PURPOSE "Needed by the web browser applet"
URL "https://doc.qt.io/qt-5/qtwebengine-index.html"
TYPE OPTIONAL
)
if (Qt5WebEngine_FOUND)
plasma_install_package(package org.kde.plasma.webbrowser)
endif()
/***************************************************************************
* Copyright 2014, 2016 by Mikhail Ivchenko <ematirov@gmail.com> *
* Copyright 2018 by Kai Uwe Broulik <kde@privat.broulik.de> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
......@@ -18,7 +19,7 @@
***************************************************************************/
import QtQuick 2.0
import QtWebKit 3.0
import QtWebEngine 1.1
import QtQuick.Layouts 1.1
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras
......@@ -45,23 +46,72 @@ ColumnLayout {
}
webview.url = url;
}
onActiveFocusChanged: {
if (activeFocus) {
selectAll();
}
}
text: webview.url
}
PlasmaComponents.Button{
iconSource: "view-refresh"
onClicked: webview.reload()
iconSource: webview.loading ? "process-stop" : "view-refresh"
onClicked: webview.loading ? webview.stop() : webview.reload()
}
}
PlasmaExtras.ScrollArea {
Item {
Layout.fillWidth: true
Layout.fillHeight: true
WebView {
// TODO use contentsSize but that crashes, now mostly for some sane initial size
Layout.preferredWidth: units.gridUnit * 25
Layout.preferredHeight: units.gridUnit * 12
// Binding it to e.g. width will be super slow on resizing
Timer {
id: updateZoomTimer
interval: 100
onTriggered: {
// Try to fit contents for a smaller screen
webview.zoomFactor = Math.min(1, webview.width / 1000);
}
}
WebEngineView {
id: webview
anchors.fill: parent
onUrlChanged: plasmoid.configuration.url = url;
Component.onCompleted: url = plasmoid.configuration.url;
onLinkHovered: {
if (hoveredUrl.toString() !== "") {
mouseArea.cursorShape = Qt.PointingHandCursor;
} else {
mouseArea.cursorShape = Qt.ArrowCursor;
}
}
onWidthChanged: updateZoomTimer.start()
onLoadingChanged: {
if (loadRequest.status === WebEngineLoadRequest.LoadSucceededStatus) {
updateZoomTimer.start();
}
}
}
}
//There will be RowLayout with buttons for bookmarks and zooming.
MouseArea {
id: mouseArea
anchors.fill: parent
acceptedButtons: Qt.BackButton | Qt.ForwardButton
onPressed: {
if (mouse.button === Qt.BackButton) {
webview.goBack();
} else if (mouse.button === Qt.ForwardButton) {
webview.goForward();
}
}
}
}
}
Supports Markdown
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