WebBrowser/WebBrowserPage.py

branch
maintenance
changeset 6693
3629d88ae235
parent 6692
c104c120e043
child 6695
0a51887c13cd
--- a/WebBrowser/WebBrowserPage.py	Thu Jan 10 14:23:49 2019 +0100
+++ b/WebBrowser/WebBrowserPage.py	Sat Feb 02 11:12:54 2019 +0100
@@ -28,6 +28,7 @@
 from .JavaScript.ExternalJsObject import ExternalJsObject
 
 from .Tools.WebHitTestResult import WebHitTestResult
+from .Tools import Scripts
 
 import Preferences
 from Globals import qVersionTuple
@@ -41,8 +42,8 @@
         browsing event
     @signal safeBrowsingBad(threatType, threatMessages) emitted to indicate a
         malicious web site as determined by safe browsing
-    @signal printRequested() emitted to indicate a print request of the shown
-        web page
+    @signal printPageRequested() emitted to indicate a print request of the
+        shown web page
     @signal navigationRequestAccepted(url, navigation type, main frame) emitted
         to signal an accepted navigation request
     """
@@ -56,7 +57,7 @@
     safeBrowsingAbort = pyqtSignal()
     safeBrowsingBad = pyqtSignal(str, str)
     
-    printRequested = pyqtSignal()
+    printPageRequested = pyqtSignal()
     navigationRequestAccepted = pyqtSignal(QUrl, QWebEnginePage.NavigationType,
                                            bool)
     
@@ -83,6 +84,12 @@
         
         self.urlChanged.connect(self.__urlChanged)
         
+        try:
+            self.contentsSizeChanged.connect(self.__contentsSizeChanged)
+        except AttributeError:
+            # defined for Qt >= 5.7
+            pass
+        
         self.__printer = None
         self.__badSite = False
         
@@ -155,7 +162,7 @@
                     QUrl(query.queryItemValue("url")))
                 return False
             elif url.path() == "PrintPage":
-                self.printRequested.emit()
+                self.printPageRequested.emit()
                 return False
         
         # Safe Browsing
@@ -466,6 +473,17 @@
         loop.exec_()
         return resultDict["res"]
     
+    def __contentsSizeChanged(self, size):
+        """
+        Private slot to work around QWebEnginePage not scrolling to anchors
+        when opened in a background tab.
+        
+        @param size changed contents size (unused)
+        @type QSize
+        """
+        fragment = self.url().fragment()
+        self.runJavaScript(Scripts.scrollToAnchor(fragment))
+    
     ##############################################
     ## Methods below deal with JavaScript messages
     ##############################################

eric ide

mercurial