diff options
| author | Mike Skec <skec@protonmail.ch> | 2021-01-07 08:53:02 +1100 |
|---|---|---|
| committer | Felix Queißner <felix@ib-queissner.de> | 2021-01-07 09:44:02 +0100 |
| commit | 9ed3c1693fbd777f64d390e5b2d795fa285ffb85 (patch) | |
| tree | 25f677579979e046b70b6b8f6e457b10ab37169b /src | |
| parent | 50729c19ebf75ab91ee285fe7af86abbdaec411c (diff) | |
| download | kristall-9ed3c1693fbd777f64d390e5b2d795fa285ffb85.tar.gz | |
Remembered scroll adjustment
Now only scrolls back if the user navigated back/forward. This is a little more intuitive and makes it less confusing when user clicks a link to a cached page
Diffstat (limited to 'src')
| -rw-r--r-- | src/browsertab.cpp | 18 | ||||
| -rw-r--r-- | src/browsertab.hpp | 17 |
2 files changed, 26 insertions, 9 deletions
diff --git a/src/browsertab.cpp b/src/browsertab.cpp index 0cedb35..008ec80 100644 --- a/src/browsertab.cpp +++ b/src/browsertab.cpp @@ -128,7 +128,7 @@ BrowserTab::~BrowserTab() delete ui; } -void BrowserTab::navigateTo(const QUrl &url, PushToHistory mode, bool no_cache_read) +void BrowserTab::navigateTo(const QUrl &url, PushToHistory mode, RequestFlags flags) { if (kristall::protocols.isSchemeSupported(url.scheme()) != ProtocolSetup::Enabled) { @@ -152,7 +152,7 @@ void BrowserTab::navigateTo(const QUrl &url, PushToHistory mode, bool no_cache_r this->successfully_loaded = false; this->timer.start(); - if(not this->startRequest(url, ProtocolHandler::Default, no_cache_read)) { + if(not this->startRequest(url, ProtocolHandler::Default, flags)) { QMessageBox::critical(this, "Kristall", QString("Failed to execute request to %1").arg(url.toString())); return; } @@ -171,7 +171,7 @@ void BrowserTab::navigateBack(const QModelIndex &history_index) if (url.isValid()) { current_history_index = history_index; - navigateTo(url, DontPush); + navigateTo(url, DontPush, RequestFlags::NavigatedBackOrForward); } } @@ -194,7 +194,7 @@ void BrowserTab::scrollToAnchor(QString const &anchor) void BrowserTab::reloadPage() { if (current_location.isValid()) - this->navigateTo(this->current_location, DontPush, true); + this->navigateTo(this->current_location, DontPush, RequestFlags::DontReadFromCache); } void BrowserTab::focusUrlBar() @@ -1297,7 +1297,7 @@ void BrowserTab::addProtocolHandler(std::unique_ptr<ProtocolHandler> &&handler) this->protocol_handlers.emplace_back(std::move(handler)); } -bool BrowserTab::startRequest(const QUrl &url, ProtocolHandler::RequestOptions options, bool no_cache_read) +bool BrowserTab::startRequest(const QUrl &url, ProtocolHandler::RequestOptions options, RequestFlags flags) { this->updateMouseCursor(true); @@ -1403,8 +1403,11 @@ bool BrowserTab::startRequest(const QUrl &url, ProtocolHandler::RequestOptions o return this->current_handler->startRequest(url.adjusted(QUrl::RemoveFragment), options); }; - if (no_cache_read || this->current_identity.isValid()) + if ((flags & RequestFlags::DontReadFromCache) || + this->current_identity.isValid()) + { return req(); + } // Check if we have the page in our cache. if (auto pg = kristall::cache.find(url); pg != nullptr) @@ -1414,7 +1417,8 @@ bool BrowserTab::startRequest(const QUrl &url, ProtocolHandler::RequestOptions o this->on_requestComplete(pg->body, pg->mime); // Move scrollbar to cached position - if (pg->scroll_pos != -1) + if ((flags & RequestFlags::NavigatedBackOrForward) && + pg->scroll_pos != -1) this->ui->text_browser->verticalScrollBar()->setValue(pg->scroll_pos); return true; diff --git a/src/browsertab.hpp b/src/browsertab.hpp index 595e846..d706f72 100644 --- a/src/browsertab.hpp +++ b/src/browsertab.hpp @@ -40,6 +40,19 @@ struct DocumentStats } }; +enum RequestFlags : int +{ + None = 0, + + // Forces request to be made to server + // instead of reading from cache. + DontReadFromCache = 1, + + // If the user navigated back/forward + // (i.e if using back/forward buttons in toolbar) + NavigatedBackOrForward = 2, +}; + class BrowserTab : public QWidget { Q_OBJECT @@ -53,7 +66,7 @@ public: explicit BrowserTab(MainWindow * mainWindow); ~BrowserTab(); - void navigateTo(QUrl const & url, PushToHistory mode, bool no_cache_read = false); + void navigateTo(QUrl const & url, PushToHistory mode, RequestFlags flags = RequestFlags::None); void navigateBack(const QModelIndex &history_index); @@ -165,7 +178,7 @@ private: this->addProtocolHandler(std::make_unique<T>()); } - bool startRequest(QUrl const & url, ProtocolHandler::RequestOptions options, bool no_cache_read = false); + bool startRequest(QUrl const & url, ProtocolHandler::RequestOptions options, RequestFlags flags = RequestFlags::None); void updateMouseCursor(bool waiting); |
