Commit bba63307 authored by Rinigus Saar's avatar Rinigus Saar Committed by Jonah Brüchert

Improve find on page support

parent bf80bd6b
/***************************************************************************
* *
* Copyright 2020 Rinigus <rinigus.git@gmail.com> *
* *
* 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 *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
* *
***************************************************************************/
import QtQuick 2.3
import QtQuick.Layouts 1.0
import QtQuick.Controls 2.0 as Controls
import org.kde.kirigami 2.5 as Kirigami
import org.kde.mobile.angelfish 1.0
Item {
id: findInPage
anchors {
top: parent.bottom
left: parent.left
right: parent.right
}
height: Kirigami.Units.gridUnit * 3
property bool active: false
property int buttonSize: Kirigami.Units.gridUnit * 2
Rectangle { anchors.fill: parent; color: Kirigami.Theme.backgroundColor; }
RowLayout {
id: layout
anchors.fill: parent
anchors.leftMargin: Kirigami.Units.gridUnit / 2
anchors.rightMargin: Kirigami.Units.gridUnit / 2
spacing: Kirigami.Units.smallSpacing
Kirigami.Theme.inherit: true
Controls.TextField {
id: input
Kirigami.Theme.inherit: true
Layout.fillWidth: true
leftPadding: index.anchors.rightMargin
rightPadding: index.width + 2 * index.anchors.rightMargin
clip: true
inputMethodHints: rootPage.privateMode ? Qt.ImhNoPredictiveText : Qt.ImhNone
placeholderText: i18n("Search...")
onAccepted: currentWebView.findInPageForward(displayText)
onDisplayTextChanged: currentWebView.findInPageForward(displayText)
Keys.onEscapePressed: findInPage.active = false
Controls.Label {
id: index
anchors.right: parent.right
anchors.rightMargin: Kirigami.Units.gridUnit / 2
anchors.verticalCenter: parent.verticalCenter
text: "%1 / %2".arg(currentWebView.findInPageResultIndex).arg(currentWebView.findInPageResultCount)
verticalAlignment: Text.AlignVCenter
Kirigami.Theme.inherit: true
color: Kirigami.Theme.disabledTextColor
visible: input.displayText
}
}
Controls.ToolButton {
Kirigami.Theme.inherit: true
Layout.preferredWidth: buttonSize
Layout.preferredHeight: buttonSize
icon.name: "go-up"
onClicked: currentWebView.findInPageBack(input.displayText)
}
Controls.ToolButton {
Kirigami.Theme.inherit: true
Layout.preferredWidth: buttonSize
Layout.preferredHeight: buttonSize
icon.name: "go-down"
onClicked: currentWebView.findInPageForward(input.displayText)
}
Controls.ToolButton {
Kirigami.Theme.inherit: true
Layout.preferredWidth: buttonSize
Layout.preferredHeight: buttonSize
icon.name: "window-close"
onClicked: findInPage.active = false
}
}
states: [
State {
name: "shown"
when: findInPage.active
AnchorChanges {
target: findInPage
anchors.bottom: findInPage.parent.bottom
anchors.top: undefined
}
},
State {
name: "hidden"
AnchorChanges {
target: findInPage
anchors.bottom: undefined
anchors.top: findInPage.parent.bottom
}
}
]
onActiveChanged: {
if (!active)
input.text = '';
else
input.forceActiveFocus();
}
function activate() {
active = true;
}
}
InputSheet {
id: findSheet
title: i18n("Find in page")
placeholderText: i18n("Find...")
description: i18n("Highlight text on the current website")
onAccepted: currentWebView.findText(findSheet.text)
}
......@@ -232,11 +232,13 @@ Item {
AnchorChanges {
target: navigation
anchors.bottom: undefined
anchors.top: parent.bottom
anchors.top: navigation.parent.bottom
}
}
]
transitions: Transition {
AnchorAnimation { duration: Kirigami.Units.longDuration; }
AnchorAnimation {
duration: navigation.visible ? Kirigami.Units.longDuration : 0
}
}
}
......@@ -23,7 +23,7 @@ import QtQuick 2.3
import QtQuick.Controls 2.4 as Controls
import QtQuick.Window 2.1
import QtQuick.Layouts 1.3
import QtWebEngine 1.7
import QtWebEngine 1.10
import org.kde.kirigami 2.4 as Kirigami
import org.kde.mobile.angelfish 1.0
......@@ -58,6 +58,9 @@ WebEngineView {
// last request (successful or failed)
property url requestedUrl: url
property int findInPageResultIndex
property int findInPageResultCount
UserAgentGenerator {
id: userAgent
onUserAgentChanged: webEngineView.reload()
......@@ -260,6 +263,11 @@ WebEngineView {
sheetLoader.item.open()
}
onFindTextFinished: {
findInPageResultIndex = result.activeMatch;
findInPageResultCount = result.numberOfMatches;
}
onVisibleChanged: {
// set user agent to the current displayed tab
// this ensures that we follow mobile preference
......@@ -275,6 +283,14 @@ WebEngineView {
}
}
function findInPageBack(text) {
findText(text, WebEngineView.FindBackward);
}
function findInPageForward(text) {
findText(text);
}
function stopLoading() {
loadingActive = false;
stop();
......
......@@ -194,7 +194,7 @@ Kirigami.ApplicationWindow {
height: Math.round(Kirigami.Units.gridUnit / 6)
z: navigation.z + 1
anchors {
bottom: navigation.top
bottom: findInPage.active ? findInPage.top : navigation.top
bottomMargin: -Math.round(height / 2)
left: tabs.left
right: tabs.right
......@@ -224,12 +224,7 @@ Kirigami.ApplicationWindow {
Kirigami.Action {
icon.name: "edit-find"
shortcut: "Ctrl+F"
onTriggered: {
if (!sheetLoader.item || !sheetLoader.item.sheetOpen) {
sheetLoader.setSource("FindInPageSheet.qml")
sheetLoader.item.open()
}
}
onTriggered: findInPage.activate()
text: i18n("Find in page")
},
Kirigami.Action {
......@@ -306,11 +301,27 @@ Kirigami.ApplicationWindow {
}
]
// Find bar
FindInPageBar {
id: findInPage
Kirigami.Theme.colorSet: rootPage.privateMode ? Kirigami.Theme.Complementary : Kirigami.Theme.Window
layer.enabled: active
layer.effect: DropShadow {
verticalOffset: - 1
color: Kirigami.Theme.disabledTextColor
samples: 10
spread: 0.1
cached: true // element is static
}
}
// Bottom navigation bar
Navigation {
id: navigation
navigationShown: visible && rootPage.navigationAutoShow && webBrowser.visibility !== Window.FullScreen
visible: webBrowser.visibility !== Window.FullScreen
navigationShown: visible && rootPage.navigationAutoShow
visible: webBrowser.visibility !== Window.FullScreen && !findInPage.active
Kirigami.Theme.colorSet: rootPage.privateMode ? Kirigami.Theme.Complementary : Kirigami.Theme.Window
......@@ -323,12 +334,6 @@ Kirigami.ApplicationWindow {
cached: true // element is static
}
anchors {
bottom: parent.bottom
left: parent.left
right: parent.right
}
onActivateUrlEntry: urlEntry.open()
}
......@@ -336,16 +341,16 @@ Kirigami.ApplicationWindow {
id: urlEntry
}
// Thin line above navigation
// Thin line above navigation or find
Rectangle {
height: webBrowser.borderWidth
color: webBrowser.borderColor
anchors {
left: parent.left
bottom: navigation.top
bottom: findInPage.active ? findInPage.top : navigation.top
right: parent.right
}
visible: navigation.navigationShown
visible: navigation.navigationShown || findInPage.active
}
// dealing with hiding and showing navigation bar
......
......@@ -21,7 +21,7 @@
<file alias="NewTabQuestion.qml">contents/ui/NewTabQuestion.qml</file>
<file alias="DownloadQuestion.qml">contents/ui/DownloadQuestion.qml</file>
<file alias="PermissionQuestion.qml">contents/ui/PermissionQuestion.qml</file>
<file alias="FindInPageSheet.qml">contents/ui/FindInPageSheet.qml</file>
<file alias="FindInPageBar.qml">contents/ui/FindInPageBar.qml</file>
<file alias="JavaScriptDialogSheet.qml">contents/ui/JavaScriptDialogSheet.qml</file>
</qresource>
</RCC>
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