Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

adapt ChromeStateTracker / ScrollTracker for QtWebEngine #333

Draft
wants to merge 6 commits into
base: xenial
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/app/ChromeStateTracker.qml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ import QtQuick 2.4
ScrollTracker {
id: chromeStateTracker

active: webview && !webview.fullscreen
active: webview && !webview.fullscreen && !webview.loading

onScrolledUp: {
if (!header.moving && chromeStateChangeTimer.settled) {
if (chromeStateChangeTimer.settled) {
delayedAutoHideTimer.up = true
delayedAutoHideTimer.restart()
}
}
onScrolledDown: {
if (!header.moving && chromeStateChangeTimer.settled) {
if (chromeStateChangeTimer.settled) {
delayedAutoHideTimer.up = false
delayedAutoHideTimer.restart()
}
Expand Down Expand Up @@ -69,14 +69,16 @@ ScrollTracker {
// See https://bugs.launchpad.net/morph-browser/+bug/1354700.
Timer {
id: chromeStateChangeTimer
interval: 50
running: !chromeStateTracker.header.moving
interval: 150
onTriggered: settled = true
property bool settled: true
}

Connections {
target: chromeStateTracker.header
onMovingChanged: chromeStateChangeTimer.settled = false
onStateChanged: {
chromeStateChangeTimer.settled = false;
chromeStateChangeTimer.restart();
}
}
}
39 changes: 19 additions & 20 deletions src/app/ScrollTracker.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Item {
property var webview
property var header

readonly property bool nearTop: webview ? webview.contentY < (internal.headerHeight / internal.contentRatio) : false
readonly property bool nearBottom: webview ? (webview.contentY + internal.viewportHeight + internal.headerHeight / internal.contentRatio) > internal.contentHeight : false
readonly property bool nearTop: webview ? (webview.scrollPosition.y / webview.scaleFactor) < units.gu(4) : false
readonly property bool nearBottom: webview ? ((webview.contentsSize.height - webview.scrollPosition.y) / webview.scaleFactor - webview.height) < units.gu(4) : false

property bool active: true

Expand All @@ -37,29 +37,28 @@ Item {

QtObject {
id: internal
property real previousScrollPositionY: 0.0
}

readonly property real headerHeight: scrollTracker.header ? scrollTracker.header.height : 0
readonly property real headerVisibleHeight: scrollTracker.header ? scrollTracker.header.visibleHeight : 0
Connections {
target: scrollTracker.active ? scrollTracker.webview : null
onScrollPositionChanged: {

readonly property real contentHeight: scrollTracker.webview ? scrollTracker.webview.contentHeight + headerVisibleHeight : 0.0
readonly property real viewportHeight: scrollTracker.webview ? scrollTracker.webview.viewportHeight + headerVisibleHeight : 0.0
readonly property real maxContentY: scrollTracker.webview ? scrollTracker.webview.contentHeight - scrollTracker.webview.viewportHeight : 0.0
if (header.moving) {
return;
}

readonly property real contentRatio: scrollTracker.webview ? scrollTracker.webview.viewportHeight / scrollTracker.webview.contentHeight : 1.0
if (scrollTracker.webview.scrollPosition.y === internal.previousScrollPositionY) {
return;
}

readonly property real currentScrollFraction: (maxContentY == 0.0) ? 0.0 : (scrollTracker.webview.contentY / maxContentY)
property real previousScrollFraction: 0.0
}
var oldScrollPosition = internal.previousScrollPositionY;
internal.previousScrollPositionY = scrollTracker.webview.scrollPosition.y;

Connections {
target: scrollTracker.active ? scrollTracker.webview : null
onContentYChanged: {
var old = internal.previousScrollFraction
internal.previousScrollFraction = internal.currentScrollFraction
if (internal.currentScrollFraction < old) {
scrollTracker.scrolledUp()
} else if (internal.currentScrollFraction > old) {
scrollTracker.scrolledDown()
if (internal.previousScrollPositionY < oldScrollPosition) {
scrollTracker.scrolledUp()
} else if (internal.previousScrollPositionY > oldScrollPosition) {
scrollTracker.scrolledDown()
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/app/webbrowser/Browser.qml
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,6 @@ Common.BrowserView {
visible: bottomEdgeHandle.dragging || tabslist.animating || (state == "shown")
onVisibleChanged: {
if (visible) {

currentWebview.hideContextMenu();
chrome.state = "hidden";
}
Expand Down