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

Implement hiding toolbars on full screen #3652

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions DuckDuckGo/Common/Localizables/UserText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ struct UserText {
static let themeSystem = NSLocalizedString("preferences.appearance.theme.system", value: "System", comment: "In the preferences for themes, the option to select for use the change the mode based on the system preferences.")
static let addressBar = NSLocalizedString("preferences.appearance.address-bar", value: "Address Bar", comment: "Theme preferences")
static let showFullWebsiteAddress = NSLocalizedString("preferences.appearance.show-full-url", value: "Full website address", comment: "Option to show full URL in the address bar")
static let hideToolbarsOnFullScreen = NSLocalizedString("preferences.appearance.hide-toolbars-on-full-screen", value: "Remove Tabs and Bookmarks Bar toolbars on Full Screen", comment: "Option to hide tabs and bookmarks bar toolbars on full screen")
static let showAutocompleteSuggestions = NSLocalizedString("preferences.appearance.show-autocomplete-suggestions", value: "Autocomplete suggestions", comment: "Option to show autocomplete suggestions in the address bar")
static let customizeBackground = NSLocalizedString("preferences.appearance.customize-background", value: "Customize Background", comment: "Button to open home page background customization options")
static let zoomPickerTitle = NSLocalizedString("preferences.appearance.zoom-picker", value: "Default page zoom", comment: "Default page zoom picker title")
Expand Down
2 changes: 2 additions & 0 deletions DuckDuckGo/Common/Utilities/UserDefaultsWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ public struct UserDefaultsWrapper<T> {
case centerAlignedBookmarksBar = "bookmarks.bar.center.aligned"
case lastBookmarksBarUsagePixelSendDate = "bookmarks.bar.last-usage-pixel-send-date"

case hideToolbarsOnFullScreen = "hide.toolbars.on.fullscren"

case pinnedViews = "pinning.pinned-views"
case manuallyToggledPinnedViews = "pinning.manually-toggled-pinned-views"

Expand Down
14 changes: 13 additions & 1 deletion DuckDuckGo/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -52814,6 +52814,18 @@
}
}
},
"preferences.appearance.hide-toolbars-on-full-screen" : {
"comment" : "Option to hide tabs and bookmarks bar toolbars on full screen",
"extractionState" : "extracted_with_value",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "Remove Tabs and Bookmarks Bar toolbars on Full Screen"
}
}
}
},
"preferences.appearance.show-autocomplete-suggestions" : {
"comment" : "Option to show autocomplete suggestions in the address bar",
"extractionState" : "extracted_with_value",
Expand Down Expand Up @@ -64606,4 +64618,4 @@
}
},
"version" : "1.0"
}
}
15 changes: 12 additions & 3 deletions DuckDuckGo/MainWindow/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ final class MainView: NSView {

private(set) var navigationBarTopConstraint: NSLayoutConstraint!
private(set) var bookmarksBarHeightConstraint: NSLayoutConstraint!
private(set) var webContainerTopConstraint: NSLayoutConstraint!
private(set) var webContainerTopConstraintToNavigation: NSLayoutConstraint!
private(set) var tabBarHeightConstraint: NSLayoutConstraint!

@Published var isMouseAboveWebView: Bool = false

Expand Down Expand Up @@ -59,14 +62,19 @@ final class MainView: NSView {

private func addConstraints() {
bookmarksBarHeightConstraint = bookmarksBarContainerView.heightAnchor.constraint(equalToConstant: 34)

tabBarHeightConstraint = tabBarContainerView.heightAnchor.constraint(equalToConstant: 38)
navigationBarTopConstraint = navigationBarContainerView.topAnchor.constraint(equalTo: topAnchor, constant: 38)
webContainerTopConstraint = webContainerView.topAnchor.constraint(equalTo: bookmarksBarContainerView.bottomAnchor)
webContainerTopConstraintToNavigation = webContainerView.topAnchor.constraint(equalTo: navigationBarContainerView.bottomAnchor)

webContainerTopConstraint.priority = .defaultHigh
webContainerTopConstraintToNavigation.priority = .defaultLow

NSLayoutConstraint.activate([
tabBarContainerView.topAnchor.constraint(equalTo: topAnchor),
tabBarContainerView.leadingAnchor.constraint(equalTo: leadingAnchor),
tabBarContainerView.trailingAnchor.constraint(equalTo: trailingAnchor),
tabBarContainerView.heightAnchor.constraint(equalToConstant: 38),
tabBarHeightConstraint,

divider.topAnchor.constraint(equalTo: navigationBarContainerView.bottomAnchor),
divider.leadingAnchor.constraint(equalTo: leadingAnchor),
Expand All @@ -82,7 +90,8 @@ final class MainView: NSView {
navigationBarContainerView.leadingAnchor.constraint(equalTo: leadingAnchor),
navigationBarContainerView.trailingAnchor.constraint(equalTo: trailingAnchor),

webContainerView.topAnchor.constraint(equalTo: bookmarksBarContainerView.bottomAnchor),
webContainerTopConstraint,
webContainerTopConstraintToNavigation,
webContainerView.bottomAnchor.constraint(equalTo: bottomAnchor),
webContainerView.leadingAnchor.constraint(equalTo: leadingAnchor),
webContainerView.trailingAnchor.constraint(equalTo: trailingAnchor),
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/MainWindow/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import os.log
import BrokenSitePrompt

final class MainViewController: NSViewController {
private lazy var mainView = MainView(frame: NSRect(x: 0, y: 0, width: 600, height: 660))
private(set) lazy var mainView = MainView(frame: NSRect(x: 0, y: 0, width: 600, height: 660))

let tabBarViewController: TabBarViewController
let navigationBarViewController: NavigationBarViewController
Expand Down
42 changes: 38 additions & 4 deletions DuckDuckGo/MainWindow/MainWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ final class MainWindowController: NSWindowController {
private var fireViewModel: FireViewModel
private static var knownFullScreenMouseDetectionWindows = Set<NSValue>()
let fireWindowSession: FireWindowSession?
private let appearancePreferences: AppearancePreferencesUserDefaultsPersistor

var mainViewController: MainViewController {
// swiftlint:disable force_cast
Expand All @@ -51,6 +52,7 @@ final class MainWindowController: NSWindowController {
assert(!mainViewController.isBurner || fireWindowSession != nil)
self.fireWindowSession = fireWindowSession
fireWindowSession?.addWindow(window)
appearancePreferences = AppearancePreferencesUserDefaultsPersistor()

super.init(window: window)

Expand Down Expand Up @@ -227,6 +229,42 @@ extension MainWindowController: NSWindowDelegate {
func windowWillEnterFullScreen(_ notification: Notification) {
mainViewController.tabBarViewController.draggingSpace.isHidden = true
mainViewController.windowWillEnterFullScreen()

if appearancePreferences.hideToolbarsOnFullScreen {
onEnterFullScreenWhenFullScreenModeIsEnabled()
}
}

func windowWillExitFullScreen(_ notification: Notification) {
mainViewController.tabBarViewController.draggingSpace.isHidden = false

if appearancePreferences.hideToolbarsOnFullScreen {
onExitFullScreenWhenFullScreenModeIsEnabled()
}
}

private func onEnterFullScreenWhenFullScreenModeIsEnabled() {
guard let toolbar = window?.toolbar else { return }
toolbar.isVisible = false

mainViewController.mainView.navigationBarTopConstraint.animator().constant = 0
mainViewController.mainView.tabBarHeightConstraint.animator().constant = 0
mainViewController.mainView.webContainerTopConstraintToNavigation.animator().priority = .defaultHigh
mainViewController.mainView.webContainerTopConstraint.animator().priority = .defaultLow
moveTabBarView(toTitlebarView: false)
}

private func onExitFullScreenWhenFullScreenModeIsEnabled() {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) { [weak self] in
guard let toolbar = self?.window?.toolbar else { return }
toolbar.isVisible = true

self?.mainViewController.mainView.tabBarHeightConstraint.animator().constant = 38
self?.mainViewController.mainView.navigationBarTopConstraint.animator().constant = 38
self?.mainViewController.mainView.webContainerTopConstraintToNavigation.animator().priority = .defaultLow
self?.mainViewController.mainView.webContainerTopConstraint.animator().priority = .defaultHigh
self?.moveTabBarView(toTitlebarView: true)
}
}

func windowWillMiniaturize(_ notification: Notification) {
Expand Down Expand Up @@ -276,10 +314,6 @@ extension MainWindowController: NSWindowDelegate {
}
}

func windowWillExitFullScreen(_ notification: Notification) {
mainViewController.tabBarViewController.draggingSpace.isHidden = false
}

func windowWillClose(_ notification: Notification) {
mainViewController.windowWillClose()

Expand Down
11 changes: 11 additions & 0 deletions DuckDuckGo/Preferences/Model/AppearancePreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ protocol AppearancePreferencesPersistor {
var homeButtonPosition: HomeButtonPosition { get set }
var homePageCustomBackground: String? { get set }
var centerAlignedBookmarksBar: Bool { get set }
var hideToolbarsOnFullScreen: Bool { get set }
}

struct AppearancePreferencesUserDefaultsPersistor: AppearancePreferencesPersistor {
Expand Down Expand Up @@ -101,6 +102,9 @@ struct AppearancePreferencesUserDefaultsPersistor: AppearancePreferencesPersisto

@UserDefaultsWrapper(key: .centerAlignedBookmarksBar, defaultValue: true)
var centerAlignedBookmarksBar: Bool

@UserDefaultsWrapper(key: .hideToolbarsOnFullScreen, defaultValue: false)
var hideToolbarsOnFullScreen: Bool
}

protocol HomePageNavigator {
Expand Down Expand Up @@ -208,6 +212,12 @@ final class AppearancePreferences: ObservableObject {
}
}

@Published var hideToolbarsOnFullScreen: Bool {
didSet {
persistor.hideToolbarsOnFullScreen = hideToolbarsOnFullScreen
}
}

@Published var favoritesDisplayMode: FavoritesDisplayMode {
didSet {
persistor.favoritesDisplayMode = favoritesDisplayMode.description
Expand Down Expand Up @@ -355,6 +365,7 @@ final class AppearancePreferences: ObservableObject {
homeButtonPosition = persistor.homeButtonPosition
homePageCustomBackground = persistor.homePageCustomBackground.flatMap(CustomBackground.init)
centerAlignedBookmarksBarBool = persistor.centerAlignedBookmarksBar
hideToolbarsOnFullScreen = persistor.hideToolbarsOnFullScreen
}

private var persistor: AppearancePreferencesPersistor
Expand Down
2 changes: 2 additions & 0 deletions DuckDuckGo/Preferences/View/PreferencesAppearanceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ extension Preferences {
// SECTION 2: Address Bar
PreferencePaneSection(UserText.addressBar) {
ToggleMenuItem(UserText.showFullWebsiteAddress, isOn: $model.showFullURL)

ToggleMenuItem(UserText.hideToolbarsOnFullScreen, isOn: $model.hideToolbarsOnFullScreen)
}

// SECTION 3: New Tab Page
Expand Down
10 changes: 8 additions & 2 deletions UnitTests/Preferences/AppearancePreferencesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct AppearancePreferencesPersistorMock: AppearancePreferencesPersistor {
var homePageCustomBackground: String?
var centerAlignedBookmarksBar: Bool
var didDismissHomePagePromotion: Bool
var hideToolbarsOnFullScreen: Bool

init(
showFullURL: Bool = false,
Expand All @@ -55,7 +56,8 @@ struct AppearancePreferencesPersistorMock: AppearancePreferencesPersistor {
homeButtonPosition: HomeButtonPosition = .right,
homePageCustomBackground: String? = nil,
centerAlignedBookmarksBar: Bool = true,
didDismissHomePagePromotion: Bool = true
didDismissHomePagePromotion: Bool = true,
hideToolbarsOnFullScreen: Bool = false
) {
self.showFullURL = showFullURL
self.currentThemeName = currentThemeName
Expand All @@ -73,6 +75,7 @@ struct AppearancePreferencesPersistorMock: AppearancePreferencesPersistor {
self.homePageCustomBackground = homePageCustomBackground
self.centerAlignedBookmarksBar = centerAlignedBookmarksBar
self.didDismissHomePagePromotion = didDismissHomePagePromotion
self.hideToolbarsOnFullScreen = hideToolbarsOnFullScreen
}
}

Expand Down Expand Up @@ -103,6 +106,7 @@ final class AppearancePreferencesTests: XCTestCase {
XCTAssertEqual(model.homeButtonPosition, .left)
XCTAssertEqual(model.homePageCustomBackground, .gradient(.gradient01))
XCTAssertTrue(model.centerAlignedBookmarksBarBool)
XCTAssertFalse(model.hideToolbarsOnFullScreen)

model = AppearancePreferences(
persistor: AppearancePreferencesPersistorMock(
Expand All @@ -115,7 +119,8 @@ final class AppearancePreferencesTests: XCTestCase {
isSearchBarVisible: false,
homeButtonPosition: .left,
homePageCustomBackground: CustomBackground.gradient(.gradient05).description,
centerAlignedBookmarksBar: false
centerAlignedBookmarksBar: false,
hideToolbarsOnFullScreen: true
)
)
XCTAssertEqual(model.showFullURL, true)
Expand All @@ -128,6 +133,7 @@ final class AppearancePreferencesTests: XCTestCase {
XCTAssertEqual(model.homeButtonPosition, .left)
XCTAssertEqual(model.homePageCustomBackground, .gradient(.gradient05))
XCTAssertFalse(model.centerAlignedBookmarksBarBool)
XCTAssertTrue(model.hideToolbarsOnFullScreen)
}

func testWhenInitializedWithGarbageThenThemeIsSetToSystemDefault() throws {
Expand Down
2 changes: 2 additions & 0 deletions UnitTests/Sync/Mocks/MockAppearancePreferencesPersistor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ class MockAppearancePreferencesPersistor: AppearancePreferencesPersistor {
var centerAlignedBookmarksBar: Bool = false

var didDismissHomePagePromotion = true

var hideToolbarsOnFullScreen: Bool = false
}
Loading