Merge pull request #10395 from ctrlaltdavid/21319

Fix browser "back" button in tablet snapshot and goto "i" pages
This commit is contained in:
anshuman64 2017-05-08 14:51:18 -07:00 committed by GitHub
commit f10535d991
2 changed files with 31 additions and 83 deletions

View file

@ -17,26 +17,26 @@ Rectangle {
property alias pixelSize: label.font.pixelSize; property alias pixelSize: label.font.pixelSize;
property bool selected: false property bool selected: false
property bool hovered: false property bool hovered: false
property bool enabled: false
property int spacing: 2 property int spacing: 2
property var action: function () {} property var action: function () {}
property string enabledColor: hifi.colors.blueHighlight property string enabledColor: hifi.colors.blueHighlight
property string disabledColor: hifi.colors.blueHighlight property string disabledColor: hifi.colors.blueHighlight
property string highlightColor: hifi.colors.blueHighlight;
width: label.width + 64 width: label.width + 64
height: 32 height: 32
color: hifi.colors.white color: hifi.colors.white
enabled: false
HifiConstants { id: hifi } HifiConstants { id: hifi }
RalewaySemiBold { RalewaySemiBold {
id: label; id: label;
color: enabledColor color: enabled ? enabledColor : disabledColor
font.pixelSize: 15; font.pixelSize: 15;
anchors { anchors {
horizontalCenter: parent.horizontalCenter; horizontalCenter: parent.horizontalCenter;
verticalCenter: parent.verticalCenter; verticalCenter: parent.verticalCenter;
} }
} }
Rectangle { Rectangle {
id: indicator id: indicator

View file

@ -8,6 +8,7 @@ import "../styles" as HifiStyles
import "../styles-uit" import "../styles-uit"
import "../" import "../"
import "." import "."
Item { Item {
id: web id: web
HifiConstants { id: hifi } HifiConstants { id: hifi }
@ -22,17 +23,14 @@ Item {
property bool keyboardRaised: false property bool keyboardRaised: false
property bool punctuationMode: false property bool punctuationMode: false
property bool isDesktop: false property bool isDesktop: false
property string initialPage: ""
property bool startingUp: true
property alias webView: webview property alias webView: webview
property alias profile: webview.profile property alias profile: webview.profile
property bool remove: false property bool remove: false
property var urlList: []
property var forwardList: []
// Manage own browse history because WebEngineView history is wiped when a new URL is loaded via
property int currentPage: -1 // used as a model for repeater // onNewViewRequested, e.g., as happens when a social media share button is clicked.
property alias pagesModel: pagesModel property var history: []
property int historyIndex: -1
Rectangle { Rectangle {
id: buttons id: buttons
@ -51,21 +49,22 @@ Item {
TabletWebButton { TabletWebButton {
id: back id: back
enabledColor: hifi.colors.baseGray enabledColor: hifi.colors.darkGray
enabled: false disabledColor: hifi.colors.lightGrayText
enabled: historyIndex > 0
text: "BACK" text: "BACK"
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
onClicked: goBack() onClicked: goBack()
hoverEnabled: true
} }
} }
TabletWebButton { TabletWebButton {
id: close id: close
enabledColor: hifi.colors.darkGray enabledColor: hifi.colors.darkGray
disabledColor: hifi.colors.lightGrayText
enabled: true
text: "CLOSE" text: "CLOSE"
MouseArea { MouseArea {
@ -75,7 +74,6 @@ Item {
} }
} }
RalewaySemiBold { RalewaySemiBold {
id: displayUrl id: displayUrl
color: hifi.colors.baseGray color: hifi.colors.baseGray
@ -90,7 +88,6 @@ Item {
} }
} }
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
preventStealing: true preventStealing: true
@ -98,29 +95,10 @@ Item {
} }
} }
ListModel {
id: pagesModel
onCountChanged: {
currentPage = count - 1;
if (currentPage > 0) {
back.enabledColor = hifi.colors.darkGray;
} else {
back.enabledColor = hifi.colors.baseGray;
}
}
}
function goBack() { function goBack() {
if (webview.canGoBack) { if (historyIndex > 0) {
forwardList.push(webview.url); historyIndex--;
webview.goBack(); loadUrl(history[historyIndex]);
} 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 = [];
} }
} }
@ -137,19 +115,12 @@ Item {
} }
function goForward() { function goForward() {
if (currentPage < pagesModel.count - 1) { if (historyIndex < history.length - 1) {
currentPage++; historyIndex++;
loadUrl(history[historyIndex]);
} }
} }
function gotoPage(url) {
urlAppend(url)
}
function isUrlLoaded(url) {
return (pagesModel.get(currentPage).webUrl === url);
}
function reloadPage() { function reloadPage() {
view.reloadAndBypassCache() view.reloadAndBypassCache()
view.setActiveFocusOnPress(true); view.setActiveFocusOnPress(true);
@ -161,36 +132,8 @@ Item {
web.url = webview.url; web.url = webview.url;
} }
function onInitialPage(url) {
return (url === webview.url);
}
function urlAppend(url) {
var lurl = decodeURIComponent(url)
if (lurl[lurl.length - 1] !== "/") {
lurl = lurl + "/"
}
web.urlList.push(url);
setBackButtonStatus();
}
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: { onUrlChanged: {
loadUrl(url); loadUrl(url);
if (startingUp) {
web.initialPage = webview.url;
startingUp = false;
}
} }
QtObject { QtObject {
@ -258,6 +201,17 @@ Item {
grantFeaturePermission(securityOrigin, feature, true); grantFeaturePermission(securityOrigin, feature, true);
} }
onUrlChanged: {
// Record history, skipping null and duplicate items.
var urlString = url + "";
urlString = urlString.replace(/\//g, "%2F"); // Consistent representation of "/"s to avoid false differences.
if (urlString.length > 0 && (historyIndex === -1 || urlString !== history[historyIndex])) {
historyIndex++;
history = history.slice(0, historyIndex);
history.push(urlString);
}
}
onLoadingChanged: { onLoadingChanged: {
keyboardRaised = false; keyboardRaised = false;
punctuationMode = false; punctuationMode = false;
@ -277,17 +231,11 @@ Item {
} }
if (WebEngineView.LoadSucceededStatus == loadRequest.status) { if (WebEngineView.LoadSucceededStatus == loadRequest.status) {
if (startingUp) {
web.initialPage = webview.url;
startingUp = false;
}
webview.forceActiveFocus(); webview.forceActiveFocus();
} }
} }
onNewViewRequested: { onNewViewRequested: {
var currentUrl = webview.url;
urlAppend(currentUrl);
request.openIn(webview); request.openIn(webview);
} }
} }