diff --git a/interface/resources/qml/controls/TabletWebView.qml b/interface/resources/qml/controls/TabletWebView.qml index dd0c3c8135..04e784e2ba 100644 --- a/interface/resources/qml/controls/TabletWebView.qml +++ b/interface/resources/qml/controls/TabletWebView.qml @@ -23,11 +23,13 @@ Item { property bool keyboardRaised: false property bool punctuationMode: false property bool isDesktop: false - property bool removingPage: false - property bool loadingPage: false + property string initialPage: "" + property bool startingUp: true property alias webView: webview property alias profile: webview.profile property bool remove: false + property var urlList: [] + property var forwardList: [] property int currentPage: -1 // used as a model for repeater @@ -79,9 +81,12 @@ Item { id: displayUrl color: hifi.colors.baseGray font.pixelSize: 12 + verticalAlignment: Text.AlignLeft anchors { top: nav.bottom horizontalCenter: parent.horizontalCenter; + left: parent.left + leftMargin: 20 } } @@ -106,19 +111,19 @@ Item { } function goBack() { - if (webview.canGoBack && !isUrlLoaded(webview.url)) { - if (currentPage > 0) { - removingPage = true; - pagesModel.remove(currentPage); - } + if (webview.canGoBack) { + forwardList.push(webview.url); webview.goBack(); - } else if (currentPage > 0) { - removingPage = true; - pagesModel.remove(currentPage); + } else if (web.urlList.length > 0) { + var url = web.urlList.pop(); + loadUrl(url); + } else if (web.forwardList.length > 0) { + var url = web.forwardList.pop(); + loadUrl(url); + web.forwardList = []; } } - function closeWebEngine() { if (remove) { web.destroy(); @@ -151,32 +156,42 @@ Item { view.setEnabled(true); } + function loadUrl(url) { + webview.url = url + web.url = webview.url; + web.address = webview.url; + } + + function onInitialPage(url) { + return (url === webview.url); + } + + function urlAppend(url) { - if (removingPage) { - removingPage = false; - return; - } var lurl = decodeURIComponent(url) if (lurl[lurl.length - 1] !== "/") { lurl = lurl + "/" } - if (currentPage === -1 || (pagesModel.get(currentPage).webUrl !== lurl && !timer.running)) { - timer.start(); - pagesModel.append({webUrl: lurl}); - } + web.urlList.push(url); + setBackButtonStatus(); } - onCurrentPageChanged: { - if (currentPage >= 0 && currentPage < pagesModel.count) { - timer.start(); - webview.url = pagesModel.get(currentPage).webUrl; - web.url = webview.url; - web.address = webview.url; + function setBackButtonStatus() { + if (web.urlList.length > 0 || webview.canGoBack) { + back.enabledColor = hifi.colors.darkGray; + back.enabled = true; + } else { + back.enabledColor = hifi.colors.baseGray; + back.enabled = false; } } onUrlChanged: { - gotoPage(url) + loadUrl(url); + if (startingUp) { + web.initialPage = webview.url; + startingUp = false; + } } QtObject { @@ -184,18 +199,7 @@ Item { WebChannel.id: "eventBridgeWrapper" property var eventBridge; } - - Timer { - id: timer - interval: 200 - running: false - repeat: false - onTriggered: timer.stop(); - } - - - - + WebEngineView { id: webview objectName: "webEngineView" @@ -235,6 +239,7 @@ Item { worldId: WebEngineScript.MainWorld } + property string urlTag: "noDownload=false"; userScripts: [ createGlobalEventBridge, raiseAndLowerKeyboard, userScript ] property string newUrl: "" @@ -261,9 +266,7 @@ Item { keyboard.resetShiftMode(false); // Required to support clicking on "hifi://" links if (WebEngineView.LoadStartedStatus == loadRequest.status) { - urlAppend(loadRequest.url.toString()); - loadingPage = true; - var url = loadRequest.url.toString(); + var url = loadRequest.url.toString(); if (urlHandler.canHandleUrl(url)) { if (urlHandler.handleUrl(url)) { root.stop(); @@ -274,9 +277,19 @@ Item { if (WebEngineView.LoadFailedStatus == loadRequest.status) { console.log(" Tablet WebEngineView failed to laod url: " + loadRequest.url.toString()); } - } + if (WebEngineView.LoadSucceededStatus == loadRequest.status) { + web.address = webview.url; + if (startingUp) { + web.initialPage = webview.url; + startingUp = false; + } + } + } + onNewViewRequested: { + var currentUrl = webview.url; + urlAppend(currentUrl); request.openIn(webview); } }