diff options
| author | Felix "xq" Queißner <git@masterq32.de> | 2021-11-20 15:02:03 +0100 |
|---|---|---|
| committer | Felix "xq" Queißner <git@masterq32.de> | 2021-11-20 15:02:03 +0100 |
| commit | 9dd660d66e23f02716d4b2bad84ac86764de71a6 (patch) | |
| tree | f958489dc64d8afb34702ebe89bf24a71067d1c4 /src/browsertab.cpp | |
| parent | 9744a24ffbf4d5ea6ad8b418d740c90336ee33b8 (diff) | |
| download | kristall-9dd660d66e23f02716d4b2bad84ac86764de71a6.tar.gz | |
Improves caching api related to urls, implements fragment handling, fixes #237
Diffstat (limited to 'src/browsertab.cpp')
| -rw-r--r-- | src/browsertab.cpp | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/browsertab.cpp b/src/browsertab.cpp index f790e8e..1b90720 100644 --- a/src/browsertab.cpp +++ b/src/browsertab.cpp @@ -586,6 +586,15 @@ void BrowserTab::on_requestComplete(const QByteArray &ref_data, const MimeType & renderPage(data, mime); + if(this->navigate_to_fragment) + { + // Implement navigation semantics: + QString fragment = this->current_location.fragment(); + if(not fragment.isEmpty()) { + this->scrollToAnchor(fragment); + } + } + this->updatePageTitle(); this->updateUrlBarStyle(); @@ -1585,6 +1594,18 @@ bool BrowserTab::startRequest(const QUrl &url, ProtocolHandler::RequestOptions o QString urlstr = url.toString(QUrl::FullyEncoded); + { + QUrl old_url_cleaned = this->current_location; + QUrl new_url_cleaned = url; + + old_url_cleaned.setFragment(""); + new_url_cleaned.setFragment(""); + + // Only jump to (potential) fragment when we either change the base url + // or reload the current page with a new fragment. + this->navigate_to_fragment = ((old_url_cleaned != new_url_cleaned) or (this->current_location.fragment() != url.fragment())); + } + this->is_internal_location = (url.scheme() == "about" || url.scheme() == "file"); this->current_location = url; this->setUrlBarText(urlstr); @@ -1596,8 +1617,7 @@ bool BrowserTab::startRequest(const QUrl &url, ProtocolHandler::RequestOptions o return this->current_handler->startRequest(url.adjusted(QUrl::RemoveFragment), options); }; - if ((flags & RequestFlags::DontReadFromCache) || - this->current_identity.isValid()) + if ((flags & RequestFlags::DontReadFromCache) || this->current_identity.isValid()) { return req(); } @@ -1610,10 +1630,10 @@ bool BrowserTab::startRequest(const QUrl &url, ProtocolHandler::RequestOptions o this->was_read_from_cache = true; this->on_requestComplete(pg->body, pg->mime); - // Move scrollbar to cached position - if ((flags & RequestFlags::NavigatedBackOrForward) && - pg->scroll_pos != -1) + // Move scrollbar to cached position, but only if url or the fragment has changed + if ((flags & RequestFlags::NavigatedBackOrForward) && pg->scroll_pos != -1) { this->ui->text_browser->verticalScrollBar()->setValue(pg->scroll_pos); + } return true; } |
