Continued porting the web browser. QtWebEngine

Sun, 20 Mar 2016 14:09:05 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 20 Mar 2016 14:09:05 +0100
branch
QtWebEngine
changeset 4884
6983af705a7f
parent 4881
c269212cceac
child 4885
362360f9a979

Continued porting the web browser.

- added full screen support

Preferences/ConfigurationPages/WebBrowserPage.py file | annotate | diff | comparison | revisions
Preferences/ConfigurationPages/WebBrowserPage.ui file | annotate | diff | comparison | revisions
Preferences/__init__.py file | annotate | diff | comparison | revisions
WebBrowser/WebBrowserPage.py file | annotate | diff | comparison | revisions
WebBrowser/WebBrowserView.py file | annotate | diff | comparison | revisions
WebBrowser/WebBrowserWindow.py file | annotate | diff | comparison | revisions
--- a/Preferences/ConfigurationPages/WebBrowserPage.py	Sat Mar 19 20:07:34 2016 +0100
+++ b/Preferences/ConfigurationPages/WebBrowserPage.py	Sun Mar 20 14:09:05 2016 +0100
@@ -63,6 +63,8 @@
             Preferences.getWebBrowser("ErrorPageEnabled"))
         self.scrollingCheckBox.setChecked(
             Preferences.getWebBrowser("ScrollAnimatorEnabled"))
+        self.fullscreenCheckBox.setChecked(
+            Preferences.getWebBrowser("FullScreenSupportEnabled"))
         
         self.javaScriptGroup.setChecked(
             Preferences.getWebBrowser("JavaScriptEnabled"))
@@ -170,6 +172,9 @@
         Preferences.setWebBrowser(
             "ScrollAnimatorEnabled",
             self.scrollingCheckBox.isChecked())
+        Preferences.setWebBrowser(
+            "FullScreenSupportEnabled",
+            self.fullscreenCheckBox.isChecked())
         
         Preferences.setWebBrowser(
             "JavaScriptEnabled",
--- a/Preferences/ConfigurationPages/WebBrowserPage.ui	Sat Mar 19 20:07:34 2016 +0100
+++ b/Preferences/ConfigurationPages/WebBrowserPage.ui	Sun Mar 20 14:09:05 2016 +0100
@@ -97,7 +97,25 @@
         </property>
        </widget>
       </item>
+      <item row="3" column="0">
+       <widget class="QCheckBox" name="fullscreenCheckBox">
+        <property name="toolTip">
+         <string>Select to enable fullscreen support</string>
+        </property>
+        <property name="text">
+         <string>Enable Fullscreen Support</string>
+        </property>
+       </widget>
+      </item>
      </layout>
+     <zorder>singleHelpWindowCheckBox</zorder>
+     <zorder>webSuggestionsCheckBox</zorder>
+     <zorder>saveGeometryCheckBox</zorder>
+     <zorder>showTabPreviews</zorder>
+     <zorder>errorPageCheckBox</zorder>
+     <zorder>scrollingCheckBox</zorder>
+     <zorder>startupGroupBox</zorder>
+     <zorder>fullscreenCheckBox</zorder>
     </widget>
    </item>
    <item>
@@ -652,6 +670,7 @@
   <tabstop>showTabPreviews</tabstop>
   <tabstop>errorPageCheckBox</tabstop>
   <tabstop>scrollingCheckBox</tabstop>
+  <tabstop>fullscreenCheckBox</tabstop>
   <tabstop>startupCombo</tabstop>
   <tabstop>homePageEdit</tabstop>
   <tabstop>setCurrentPageButton</tabstop>
--- a/Preferences/__init__.py	Sat Mar 19 20:07:34 2016 +0100
+++ b/Preferences/__init__.py	Sun Mar 20 14:09:05 2016 +0100
@@ -1083,18 +1083,6 @@
             return
         
         webEngineSettings = QWebEngineSettings.globalSettings()
-##        fontFamily = webEngineSettings.fontFamily(
-##            QWebEngineSettings.StandardFont)
-##        fontSize = webEngineSettings.fontSize(
-##            QWebEngineSettings.DefaultFontSize)
-##        cls.webBrowserDefaults["StandardFont"] = \
-##            QFont(fontFamily, fontSize).toString()
-##        fontFamily = webEngineSettings.fontFamily(
-##            QWebEngineSettings.FixedFont)
-##        fontSize = webEngineSettings.fontSize(
-##            QWebEngineSettings.DefaultFixedFontSize)
-##        cls.webBrowserDefaults["FixedFont"] = \
-##            QFont(fontFamily, fontSize).toString()
         cls.webBrowserDefaults.update({
             "StandardFontFamily": webEngineSettings.fontFamily(
                 QWebEngineSettings.StandardFont),
@@ -1150,6 +1138,8 @@
                 QWebEngineSettings.ScrollAnimatorEnabled),
             "ErrorPageEnabled": webEngineSettings.testAttribute(
                 QWebEngineSettings.ErrorPageEnabled),
+            "FullScreenSupportEnabled": webEngineSettings.testAttribute(
+                QWebEngineSettings.FullScreenSupportEnabled),
         })
         
         cls.webEngineSettingsIntitialized = True
@@ -2814,7 +2804,6 @@
 ##                 "SiteSpecificQuirksEnabled",
 ##                 "ClickToFlashEnabled",
 ##                 ]:
-    # TODO: add "FullScreenSupportEnabled
     elif key in ["SingleWebBrowserWindow", "SaveGeometry", "JavaScriptEnabled",
                  "JavaScriptCanOpenWindows", "JavaScriptCanAccessClipboard",
                  "AutoLoadImages", "LocalStorageEnabled",
@@ -2829,7 +2818,7 @@
                  "ShowPreview", "WebInspectorEnabled", "DiskCacheEnabled",
                  "DoNotTrack", "SendReferer", "FilterTrackingCookies",
                  "AdBlockEnabled", "AdBlockUseLimitedEasyList",
-                 "PluginsEnabled",
+                 "PluginsEnabled", "FullScreenSupportEnabled",
                  ]:
         return toBool(prefClass.settings.value(
             "WebBrowser/" + key, prefClass.webBrowserDefaults[key]))
--- a/WebBrowser/WebBrowserPage.py	Sat Mar 19 20:07:34 2016 +0100
+++ b/WebBrowser/WebBrowserPage.py	Sun Mar 20 14:09:05 2016 +0100
@@ -91,6 +91,8 @@
         
         self.proxyAuthenticationRequired.connect(
             WebBrowserWindow.networkManager().proxyAuthentication)
+        
+        self.fullScreenRequested.connect(self.__fullScreenRequested)
     
     def acceptNavigationRequest(self, url, type_, isMainFrame):
         """
@@ -619,6 +621,19 @@
         return WebBrowserWindow.networkManager().certificateError(
             error, self.view())
     
+    def __fullScreenRequested(self, request):
+        """
+        Private slot handling a full screen request.
+        """
+        self.view().requestFullScreen(request.toggleOn())
+        
+        accepted = request.toggleOn() == self.view().isFullScreen()
+        
+        if accepted:
+            request.accept()
+        else:
+            request.reject()
+    
     ##############################################
     ## Methods below deal with JavaScript messages
     ##############################################
--- a/WebBrowser/WebBrowserView.py	Sat Mar 19 20:07:34 2016 +0100
+++ b/WebBrowser/WebBrowserView.py	Sun Mar 20 14:09:05 2016 +0100
@@ -1281,6 +1281,12 @@
             evt.accept()
             return
         
+        if evt.key() == Qt.Key_Escape:
+            if self.isFullScreen():
+                self.triggerPageAction(QWebEnginePage.ExitFullScreen)
+                evt.accept()
+                return
+        
         # TODO: Access Keys
 ##        if self.__enableAccessKeys:
 ##            self.__accessKeysPressed = (
@@ -1925,6 +1931,31 @@
         return len(self.__rss) > 0
     
     ###########################################################################
+    ## Full Screen handling below
+    ###########################################################################
+    
+    def isFullScreen(self):
+        """
+        Public method to check, if full screen mode is active.
+        
+        @return flag indicating full screen mode
+        @rtype bool
+        """
+        return self.__mw.isFullScreen()
+    
+    def requestFullScreen(self, enable):
+        """
+        Public method to request full screen mode.
+        
+        @param enable flag indicating full screen mode on or off
+        @type bool
+        """
+        if enable:
+            self.__mw.enterHtmlFullScreen()
+        else:
+            self.__mw.showNormal()
+    
+    ###########################################################################
     ## Clicked Frame slots
     ###########################################################################
     
--- a/WebBrowser/WebBrowserWindow.py	Sat Mar 19 20:07:34 2016 +0100
+++ b/WebBrowser/WebBrowserWindow.py	Sun Mar 20 14:09:05 2016 +0100
@@ -18,7 +18,7 @@
 import sys
 
 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QByteArray, QSize, QTimer, \
-    QUrl, QThread, QTextCodec, QProcess
+    QUrl, QThread, QTextCodec, QProcess, QEvent
 from PyQt5.QtGui import QDesktopServices, QKeySequence, QFont, QFontMetrics, \
     QIcon
 from PyQt5.QtWidgets import QWidget, QVBoxLayout, QSizePolicy, QDockWidget, \
@@ -153,6 +153,9 @@
             self.webProfile(private)
             self.networkManager()
             
+            self.__htmlFullScreen = False
+            self.__windowStates = 0
+            
             from .SearchWidget import SearchWidget
             from .QtHelp.HelpTocWidget import HelpTocWidget
             from .QtHelp.HelpIndexWidget import HelpIndexWidget
@@ -520,6 +523,9 @@
         settings.setAttribute(
             QWebEngineSettings.ErrorPageEnabled,
             Preferences.getWebBrowser("ErrorPageEnabled"))
+        settings.setAttribute(
+            QWebEngineSettings.FullScreenSupportEnabled,
+            Preferences.getWebBrowser("FullScreenSupportEnabled"))
     
     def __initActions(self):
         """
@@ -793,8 +799,7 @@
             UI.PixmapCache.getIcon("back.png"),
             self.tr('&Backward'),
             QKeySequence(self.tr("Alt+Left", "Go|Backward")),
-            QKeySequence(self.tr("Backspace", "Go|Backward")),
-            self, 'webbrowser_go_backward')
+            0, self, 'webbrowser_go_backward')
         self.backAct.setStatusTip(self.tr('Move one screen backward'))
         self.backAct.setWhatsThis(self.tr(
             """<b>Backward</b>"""
@@ -810,8 +815,7 @@
             UI.PixmapCache.getIcon("forward.png"),
             self.tr('&Forward'),
             QKeySequence(self.tr("Alt+Right", "Go|Forward")),
-            QKeySequence(self.tr("Shift+Backspace", "Go|Forward")),
-            self, 'webbrowser_go_foreward')
+            0, self, 'webbrowser_go_foreward')
         self.forwardAct.setStatusTip(self.tr(
             'Move one screen forward'))
         self.forwardAct.setWhatsThis(self.tr(
@@ -2577,7 +2581,7 @@
         Preferences.setWebBrowser("WebBrowserState", state)
 
         if Preferences.getWebBrowser("SaveGeometry"):
-            if not self.__isFullScreen():
+            if not self.isFullScreen():
                 Preferences.setGeometry("WebBrowserGeometry",
                                         self.saveGeometry())
         else:
@@ -2662,28 +2666,33 @@
         """
         Private slot called to toggle fullscreen mode.
         """
-        if self.__isFullScreen():
+        if self.__htmlFullScreen:
+            self.currentBrowser().triggerPageAction(
+                QWebEnginePage.ExitFullScreen)
+            return
+        
+        if self.isFullScreen():
             # switch back to normal
-            self.setWindowState(self.windowState() & ~Qt.WindowFullScreen)
+            self.showNormal()
             self.menuBar().show()
             self.fullScreenAct.setIcon(
                 UI.PixmapCache.getIcon("windowFullscreen.png"))
             self.fullScreenAct.setIconText(self.tr('Full Screen'))
         else:
             # switch to full screen
-            self.setWindowState(self.windowState() | Qt.WindowFullScreen)
+            self.showFullScreen()
             self.menuBar().hide()
             self.fullScreenAct.setIcon(
                 UI.PixmapCache.getIcon("windowRestore.png"))
             self.fullScreenAct.setIconText(self.tr('Restore Window'))
     
-    def __isFullScreen(self):
-        """
-        Private method to determine, if the window is in full screen mode.
-        
-        @return flag indicating full screen mode (boolean)
-        """
-        return self.windowState() & Qt.WindowFullScreen
+    def enterHtmlFullScreen(self):
+        """
+        Public method to switch to full screen initiated by the
+        HTML page.
+        """
+        self.showFullScreen()
+        self.__htmlFullScreen = True
     
     def __copy(self):
         """
@@ -3961,6 +3970,28 @@
         
         super(WebBrowserWindow, self).keyPressEvent(evt)
     
+    def event(self, evt):
+        """
+        Public method handling events.
+        
+        @param evt reference to the event
+        @type QEvent
+        @return flag indicating a handled event
+        @rtype bool
+        """
+        if evt.type() == QEvent.WindowStateChange:
+            if not bool(evt.oldState() & Qt.WindowFullScreen) and \
+               bool(self.windowState() & Qt.WindowFullScreen):
+                # enter full screen mode
+                self.__windowStates = evt.oldState()
+            elif bool(evt.oldState() & Qt.WindowFullScreen) and \
+                 not bool(self.windowState() & Qt.WindowFullScreen):
+                # leave full screen mode
+                self.setWindowState(self.__windowStates)
+                self.__htmlFullScreen = False
+        
+        return super(WebBrowserWindow, self).event(evt)
+    
     ###########################################################################
     ## Interface to VirusTotal below                                         ##
     ###########################################################################

eric ide

mercurial