From 831ccbba28b7bae2abfe964428d126f44ae43f1b Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Thu, 8 Jun 2023 16:54:48 -0700 Subject: [PATCH] Add a settings option to control spatial navigation. https://redmine.stoutner.com/issues/1002 --- src/helpers/UserAgentHelper.cpp | 10 ++++----- src/settings/Settings.kcfg | 4 ++++ src/uis/SettingsGeneral.ui | 13 ++++++++++++ src/widgets/TabWidget.cpp | 36 ++++++++++++++++++++++++--------- 4 files changed, 49 insertions(+), 14 deletions(-) diff --git a/src/helpers/UserAgentHelper.cpp b/src/helpers/UserAgentHelper.cpp index 3013de8..0f01bbb 100644 --- a/src/helpers/UserAgentHelper.cpp +++ b/src/helpers/UserAgentHelper.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2022 Soren Stoutner . + * Copyright 2022-2023 Soren Stoutner . * * This file is part of Privacy Browser PC . * @@ -39,10 +39,10 @@ const QString UserAgentHelper::SAFARI_MACOS_DATABASE = QLatin1String("Safari mac // Define the public user agent constants. const QString UserAgentHelper::PRIVACY_BROWSER_USER_AGENT = QLatin1String("PrivacyBrowser/1.0"); const QString UserAgentHelper::FIREFOX_LINUX_USER_AGENT = QLatin1String("Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0"); -const QString UserAgentHelper::CHROMIUM_LINUX_USER_AGENT = QLatin1String("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"); -const QString UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT = QLatin1String("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/112.0"); -const QString UserAgentHelper::CHROME_WINDOWS_USER_AGENT = QLatin1String("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"); -const QString UserAgentHelper::EDGE_WINDOWS_USER_AGENT = QLatin1String("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36 Edg/112.0.1722.68"); +const QString UserAgentHelper::CHROMIUM_LINUX_USER_AGENT = QLatin1String("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36"); +const QString UserAgentHelper::FIREFOX_WINDOWS_USER_AGENT = QLatin1String("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0"); +const QString UserAgentHelper::CHROME_WINDOWS_USER_AGENT = QLatin1String("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"); +const QString UserAgentHelper::EDGE_WINDOWS_USER_AGENT = QLatin1String("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.37"); const QString UserAgentHelper::SAFARI_MACOS_USER_AGENT = QLatin1String("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Safari/605.1.15"); // Construct the class. diff --git a/src/settings/Settings.kcfg b/src/settings/Settings.kcfg index a395e2e..4216013 100644 --- a/src/settings/Settings.kcfg +++ b/src/settings/Settings.kcfg @@ -68,6 +68,10 @@ true + + true + + true diff --git a/src/uis/SettingsGeneral.ui b/src/uis/SettingsGeneral.ui index d2911fa..4c08bda 100644 --- a/src/uis/SettingsGeneral.ui +++ b/src/uis/SettingsGeneral.ui @@ -205,6 +205,19 @@ + + + + + Spatial navigation + + + + Spatial navigation allows the moving between links and input fields using the keyboard arrow keys. The default is enabled. + + + + diff --git a/src/widgets/TabWidget.cpp b/src/widgets/TabWidget.cpp index 05f10d2..0a7b3ca 100644 --- a/src/widgets/TabWidget.cpp +++ b/src/widgets/TabWidget.cpp @@ -121,8 +121,11 @@ TabWidget::TabWidget(QWidget *windowPointer) : QWidget(windowPointer) TabWidget::~TabWidget() { + // Get the number of tabs. + int numberOfTabs = qTabWidgetPointer->count(); + // Manually delete each WebEngine page. - for (int i = 0; i < qTabWidgetPointer->count(); ++i) + for (int i = 0; i < numberOfTabs; ++i) { // Get the privacy WebEngine view. PrivacyWebEngineView *privacyWebEngineViewPointer = qobject_cast(qTabWidgetPointer->widget(i)); @@ -296,14 +299,17 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const // Create a no tabs loading variable. bool noTabsLoading = true; + // Get the number of tabs. + int numberOfTabs = qTabWidgetPointer->count(); + // Check to see if any other tabs are loading. - for (int i = 0; i < qTabWidgetPointer->count(); i++) + for (int i = 0; i < numberOfTabs; i++) { // Get the privacy WebEngine view for the tab. - PrivacyWebEngineView *webEngineViewPointer = qobject_cast(qTabWidgetPointer->widget(i)); + PrivacyWebEngineView *privacyWebEngineViewPointer = qobject_cast(qTabWidgetPointer->widget(i)); - // Check to see if it is currently loading. - if (webEngineViewPointer->isLoading) + // Check to see if it is currently loading. If at least one tab is loading, this flag will end up being marked `false` when the for loop has finished. + if (privacyWebEngineViewPointer->isLoading) noTabsLoading = false; } @@ -391,8 +397,8 @@ PrivacyWebEngineView* TabWidget::addTab(const bool removeUrlLineEditFocus, const // Don't allow JavaScript to open windows. webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, false); - // Allow keyboard navigation. - webEngineSettingsPointer->setAttribute(QWebEngineSettings::SpatialNavigationEnabled, true); + // Allow keyboard navigation between links and input fields. + webEngineSettingsPointer->setAttribute(QWebEngineSettings::SpatialNavigationEnabled, Settings::spatialNavigation()); // Enable full screen support. webEngineSettingsPointer->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, true); @@ -460,6 +466,18 @@ void TabWidget::applyApplicationSettings() else qTabWidgetPointer->setTabPosition(QTabWidget::South); + // Get the number of tabs. + int numberOfTabs = qTabWidgetPointer->count(); + + // Apply the spatial navigation settings to each WebEngine. + for (int i = 0; i < numberOfTabs; ++i) { + // Get the WebEngine view pointer. + PrivacyWebEngineView *privacyWebEngineViewPointer = qobject_cast(qTabWidgetPointer->widget(i)); + + // Apply the spatial navigation settings to each page. + privacyWebEngineViewPointer->page()->settings()->setAttribute(QWebEngineSettings::SpatialNavigationEnabled, Settings::spatialNavigation()); + } + // Set the search engine URL. searchEngineUrl = SearchEngineHelper::getSearchUrl(Settings::searchEngine()); @@ -521,10 +539,10 @@ void TabWidget::applySpellCheckLanguages() const for (int i = 0; i < numberOfTabs; ++i) { // Get the WebEngine view pointer. - PrivacyWebEngineView *webEngineViewPointer = qobject_cast(qTabWidgetPointer->currentWidget()); + PrivacyWebEngineView *privacyWebEngineViewPointer = qobject_cast(qTabWidgetPointer->widget(i)); // Get the WebEngine page pointer. - QWebEnginePage *webEnginePagePointer = webEngineViewPointer->page(); + QWebEnginePage *webEnginePagePointer = privacyWebEngineViewPointer->page(); // Get the WebEngine profile pointer. QWebEngineProfile *webEngineProfilePointer = webEnginePagePointer->profile(); -- 2.43.0