]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/commitdiff
Add a settings option to control spatial navigation. https://redmine.stoutner.com...
authorSoren Stoutner <soren@stoutner.com>
Thu, 8 Jun 2023 23:54:48 +0000 (16:54 -0700)
committerSoren Stoutner <soren@stoutner.com>
Thu, 8 Jun 2023 23:54:48 +0000 (16:54 -0700)
src/helpers/UserAgentHelper.cpp
src/settings/Settings.kcfg
src/uis/SettingsGeneral.ui
src/widgets/TabWidget.cpp

index 3013de8274bea711e513641096d574dd36488942..0f01bbba78113d1aa9db4f04f783bf0c7a4f2b5b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2022 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2022-2023 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser PC <https://www.stoutner.com/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.
index a395e2eaca9c5bc2c39f01f4f8af043f8d28973c..42160135f957f5e767387e0c4ca77c97943a0445 100644 (file)
             <default>true</default>
         </entry>
 
+        <entry name="spatialNavigation" type="Bool">
+            <default>true</default>
+        </entry>
+
         <entry name="fullScreenHideMenuBar" type="Bool">
             <default>true</default>
         </entry>
index d2911fa04108ed598f024528902a0f0808024b9c..4c08bda737f9dddb09a0def326de10552a05bb9b 100644 (file)
                 </widget>
             </item>
 
+            <!-- Spatial navigation. -->
+            <item>
+                <widget class="QCheckBox" name="kcfg_spatialNavigation">
+                    <property name="text">
+                        <string>Spatial navigation</string>
+                    </property>
+
+                    <property name="toolTip">
+                        <string>Spatial navigation allows the moving between links and input fields using the keyboard arrow keys.  The default is enabled.</string>
+                    </property>
+                </widget>
+            </item>
+
             <!-- Full screen browsing. -->
             <item>
                 <widget class="QGroupBox">
index 05f10d23b970520b50a919e59cd3146c1b5cd3e2..0a7b3ca1d458ae6d0b97d735545f1fd5bfdcc28c 100644 (file)
@@ -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<PrivacyWebEngineView *>(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<PrivacyWebEngineView*>(qTabWidgetPointer->widget(i));
+            PrivacyWebEngineView *privacyWebEngineViewPointer = qobject_cast<PrivacyWebEngineView*>(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<PrivacyWebEngineView *>(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<PrivacyWebEngineView *>(qTabWidgetPointer->currentWidget());
+        PrivacyWebEngineView *privacyWebEngineViewPointer = qobject_cast<PrivacyWebEngineView *>(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();