Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed address bar cleared/losing focus on Navigation #2157

Merged
merged 17 commits into from
Feb 27, 2024

Conversation

mallexxx
Copy link
Collaborator

@mallexxx mallexxx commented Feb 5, 2024

Task/Issue URL: https://app.asana.com/0/1177771139624306/1206506638670996/f

Description:

  • Fixed user input overwritten in the Address Bar on Web View navigation (preserving input until url changes when the address bar is not the first responder)
  • Fixed Address Bar losing focus on non-user-initiated navigations
  • Fixed minor nasty issues like:
  • empty address bar on Browser Launch + State Restoration
  • focused address bar on State Restoration
  • delayed Address Bar update, focus state change on tab switching
  • Slightly updated the Address Bar text update logics + spoofing prevention
  • Updating the address bar text on Navigation Did Commit event instead of Loading getting 100% - should be more accurate (CC @not-a-rootkit- ✓ Address bar behavior changed after url confirmation in 1.66.0)
  • Fixed the leaking Cancellable - created on each navigation in the loading progress subscription

Steps to test this PR:

  1. Launch browser with an empty tab open: start typing quickly before the browser window appears; Validate when the new tab is displayed, all the entered text is there and not being selected or reset
  2. Launch browser with a restored tab: validate url is displayed right away; Quickly activate the address bar and start typing, validate the input is not reset during redirections
  3. [+test] Switch between loaded tabs and home tab/settings/bookmarks, validate the Address Bar gets activated on the New Tab; Validate privacy entry button/icon is correct
  4. Enter something, switch to another tab, enter something, return back, validate the input is preserved, return to tab 2, validate its input is preserved
  5. Enter something, open some bookmark, history item, html file by dragging it to the icon – validate the address bar is deactivated and reset
  6. Validate some spoofing scenario from https://app.asana.com/0/1199230911884351/1205844442726343/f
  7. Open new tab - validate address bar is activated; Navigate somewhere, validate address bar is deactivated; go back to the home page - validate address bar is activated; navigate forward: deactivated; make sure privacy entry point icon doesn‘t blink
  8. Navigate somewhere, then somewhere else; activate the Address Bar, go back, validate the address bar is deactivated
  9. Open new tab; Open another new tab - address bar should remain active; close the 2nd tab - address bar should remain active
  10. Navigate to settings, bookmarks, onboarding - validate address bar is not active
  11. Session restore to a website; to new tab; to settings; to bookmarks etc - validate address bar is activated/deactivated accordingly
  12. Open 2 tabs, navigate both somewhere, activate the address bar, switch to another tab - validate the address bar is deactivated
  13. Open SERP, enter something in the address bar, click the Search button in SERP (submitting the same query) - validate the address bar text is reset

Internal references:

Pull Request Review Checklist
Software Engineering Expectations
Technical Design Template
Pull Request Documentation

Copy link
Contributor

@tomasstrba tomasstrba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mallexxx , I started with testing and found this issue where activating another new tab doesn't hide suggestions
https://github.com/duckduckgo/macos-browser/assets/57389842/c2b1134a-57ba-480a-b176-b0084a09b026

@mallexxx
Copy link
Collaborator Author

mallexxx commented Feb 7, 2024

good catch, @tomasstrba! fixed

@tomasstrba
Copy link
Contributor

@mallexxx, switching between homepage and the regular tab makes this weird visual glitch in the address bar. You'll better see it if you download the video and go frame by frame

glitch.mov

It is caused by this frame:
Screenshot 2024-02-11 at 7 20 50 PM

@tomasstrba tomasstrba assigned mallexxx and unassigned tomasstrba Feb 11, 2024
Copy link
Contributor

github-actions bot commented Feb 19, 2024

Warnings
⚠️ PR has more than 500 lines of code changing. Consider splitting into smaller PRs if possible.

Generated by 🚫 dangerJS against a968834

@mallexxx mallexxx assigned tomasstrba and unassigned mallexxx Feb 19, 2024
LD_RUNPATH_SEARCH_PATHS = $(inherited) @executable_path/../Frameworks @loader_path/../Frameworks
PROVISIONING_PROFILE_SPECIFIER[config=CI][sdk=macosx*] =
SWIFT_EMIT_LOC_STRINGS = NO
TEST_TARGET_NAME = DuckDuckGo Privacy Browser
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really related change but this made UI test at least launchable

@@ -240,7 +240,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate, FileDownloadManagerDel

startupSync()

stateRestorationManager.applicationDidFinishLaunching()
if [.normal, .uiTests].contains(NSApp.runType) {
stateRestorationManager.applicationDidFinishLaunching()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disable state restoration for integration tests

@@ -61,7 +61,6 @@ final class MainView: NSView {
bookmarksBarHeightConstraint = bookmarksBarContainerView.heightAnchor.constraint(equalToConstant: 34)

navigationBarTopConstraint = navigationBarContainerView.topAnchor.constraint(equalTo: topAnchor, constant: 38)
addressBarHeightConstraint = navigationBarContainerView.heightAnchor.constraint(equalToConstant: 42)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved tnis into the Navigation Bar Controller in sake of encapsulation and fluid address bar animation

@@ -314,10 +314,7 @@ fileprivate extension MainMenu {
fileprivate extension NavigationBarViewController {

var controlsForUserPrevention: [NSControl?] {
return [goBackButton,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was enabling back/forward/refresh buttons after onboarding; they are disabled by default as there‘s no nav history yet

@@ -319,6 +327,8 @@ final class AddressBarViewController: NSViewController {
activeBackgroundView.layer?.borderColor = NSColor.controlAccentColor.withAlphaComponent(0.8).cgColor
activeOuterBorderView.layer?.backgroundColor = accentColor.withAlphaComponent(0.2).cgColor
activeBackgroundView.layer?.borderColor = accentColor.withAlphaComponent(0.8).cgColor

addressBarTextField.placeholderString = tabViewModel?.tab.content == .newtab ? UserText.addressBarPlaceholder : ""
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prevent placeholder blinking when going forward from newtab to a url

@@ -680,17 +680,16 @@ protocol NewWindowPolicyDecisionMaker {
}
return
}
var title = webView.title?.trimmingWhitespace()
if title?.isEmpty ?? true {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we‘ve got this in TabViewModel

if title != self.title {
self.title = title
}

if let wkBackForwardListItem = webView.backForwardList.currentItem,
content.urlForWebView == wkBackForwardListItem.url {
content.urlForWebView == wkBackForwardListItem.url,
!webView.isLoading,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prevent updating wrong history item while loading

guard let self,
case .url(let url, credential: let credential, .webViewUpdated) = self.content,
url == navigation.url else { return }
self.content = .url(url, credential: credential, source: .historyEntry)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change content type from .webViewUpdated to .historyEntry so the address bar is deactivated on back/forward/refresh

@@ -1285,6 +1308,7 @@ extension Tab/*: NavigationResponder*/ { // to be moved to Tab+Navigation.swift
func didStart(_ navigation: Navigation) {
webViewDidStartNavigationPublisher.send()
delegate?.tabDidStartNavigation(self)
permissions.tabDidStartNavigation()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix encapsulation

@@ -20,6 +20,19 @@ import AppKit

final class BrowserTabView: ColorView {

// Returns correct subview for the rendering of snapshots
func findContentSubview(containsHostingView: Bool) -> NSView? {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was raising file too long linter issue, moved to the custom view

Comment on lines +472 to +480
getView = { [weak self] in self?.transientTabContentViewController?.view }
case .url, .subscription:
getView = { [weak self] in self?.webView }
case .settings:
getView = { [weak self] in self?.preferencesViewController?.view }
case .bookmarks:
getView = { [weak self] in self?.bookmarksViewController?.view }
case .dataBrokerProtection:
getView = { [weak self] in self?.dataBrokerProtectionHomeViewController?.view }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if view is not yet in hierarchy - add it afterwards

Comment on lines +138 to 142
updateAddressBarStrings()
if case .didCommit = event {
updateCanBeBookmarked()
updateFavicon()
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

address bar should update instantly for some kind of contents except for web view updated; but the favicon and button shouldn‘t blink

Comment on lines +191 to +192
self?.updateTitle()
self?.updateFavicon()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only update on actual error state change to avoid blinking

Copy link
Contributor

@tomasstrba tomasstrba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Address bar activation/deactivation functionality works great now! 👍 I don't see any animation glitch. There are just few details I observed:

  1. There is a separator below the navigation bar on the new tab page, which shouldn't be there
Screenshot 2024-02-23 at 10 06 46 AM
  1. I am not sure if this PR influenced it, but switching tabs is slower. Try switching between new tab page and random regular tabs.

  2. Also, there is a significant lag until the webview is presented when SERP is triggered from the address bar.

DuckDuckGo/NavigationBar/View/AddressBarTextField.swift Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

@mallexxx
Copy link
Collaborator Author

Thanks, @tomasstrba, I‘ve fixed the divider issue;
Frankly I don‘t see any glitches on tab switching or SERP loading, I‘ve checked: web view is being added on NavigationDidStart, tab switching seems working fast..
I did see some slowdown on switching to the New Tab page some time ago and it seemed like the heavy loaded SwiftUI issue - I hope that should be fixed when we switch to a native home page

Copy link
Contributor

@tomasstrba tomasstrba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍 Good job! 👏

@mallexxx mallexxx merged commit 99f8049 into main Feb 27, 2024
17 checks passed
@mallexxx mallexxx deleted the alex/fix-address-bar-cleared-on-nav branch February 27, 2024 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants