Continued porting the web browser. QtWebEngine

Sat, 19 Mar 2016 20:07:34 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 19 Mar 2016 20:07:34 +0100
branch
QtWebEngine
changeset 4881
c269212cceac
parent 4880
561f2bd9cfb9
child 4884
6983af705a7f

Continued porting the web browser.

- did some Qt 5.6 related changes

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/AdBlock/AdBlockRule.py file | annotate | diff | comparison | revisions
WebBrowser/SearchWidget.py file | annotate | diff | comparison | revisions
WebBrowser/SearchWidget.ui file | annotate | diff | comparison | revisions
WebBrowser/WebBrowserView.py file | annotate | diff | comparison | revisions
--- a/Preferences/ConfigurationPages/WebBrowserPage.py	Sat Mar 19 18:18:09 2016 +0100
+++ b/Preferences/ConfigurationPages/WebBrowserPage.py	Sat Mar 19 20:07:34 2016 +0100
@@ -73,8 +73,8 @@
 ##            Preferences.getWebBrowser("JavaScriptCanCloseWindows"))
         self.jsClipboardCheckBox.setChecked(
             Preferences.getWebBrowser("JavaScriptCanAccessClipboard"))
-##        self.pluginsGroup.setChecked(
-##            Preferences.getWebBrowser("PluginsEnabled"))
+        self.pluginsCheckBox.setChecked(
+            Preferences.getWebBrowser("PluginsEnabled"))
         # TODO: Click2Flash
 ##        self.clickToFlashCheckBox.setChecked(
 ##            Preferences.getWebBrowser("ClickToFlashEnabled"))
@@ -147,7 +147,6 @@
         # Hide entries not yet supported
         self.accessKeysCheckBox.hide()
         self.jsCloseWindowsCheckBox.hide()
-        self.pluginsGroup.hide()
     
     def save(self):
         """
@@ -185,10 +184,9 @@
         Preferences.setWebBrowser(
             "JavaScriptCanAccessClipboard",
             self.jsClipboardCheckBox.isChecked())
-        # TODO: Qt 5.6
-##        Preferences.setWebBrowser(
-##            "PluginsEnabled",
-##            self.pluginsGroup.isChecked())
+        Preferences.setWebBrowser(
+            "PluginsEnabled",
+            self.pluginsCheckBox.isChecked())
         # TODO: Click2Flash
 ##        Preferences.setWebBrowser(
 ##            "ClickToFlashEnabled",
--- a/Preferences/ConfigurationPages/WebBrowserPage.ui	Sat Mar 19 18:18:09 2016 +0100
+++ b/Preferences/ConfigurationPages/WebBrowserPage.ui	Sat Mar 19 20:07:34 2016 +0100
@@ -275,40 +275,13 @@
        </widget>
       </item>
       <item>
-       <widget class="QGroupBox" name="pluginsGroup">
+       <widget class="QCheckBox" name="pluginsCheckBox">
         <property name="toolTip">
          <string>Select to enable plugins in web pages</string>
         </property>
-        <property name="title">
+        <property name="text">
          <string>Enable Plug-ins</string>
         </property>
-        <property name="checkable">
-         <bool>true</bool>
-        </property>
-        <property name="checked">
-         <bool>false</bool>
-        </property>
-        <layout class="QGridLayout" name="gridLayout_7">
-         <item row="0" column="0">
-          <widget class="QCheckBox" name="clickToFlashCheckBox">
-           <property name="enabled">
-            <bool>false</bool>
-           </property>
-           <property name="sizePolicy">
-            <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
-             <horstretch>8</horstretch>
-             <verstretch>0</verstretch>
-            </sizepolicy>
-           </property>
-           <property name="toolTip">
-            <string>Select to activate the Flash blocker</string>
-           </property>
-           <property name="text">
-            <string>Use ClickToFlash on Flash plugins</string>
-           </property>
-          </widget>
-         </item>
-        </layout>
        </widget>
       </item>
       <item>
@@ -688,8 +661,7 @@
   <tabstop>jsOpenWindowsCheckBox</tabstop>
   <tabstop>jsCloseWindowsCheckBox</tabstop>
   <tabstop>jsClipboardCheckBox</tabstop>
-  <tabstop>pluginsGroup</tabstop>
-  <tabstop>clickToFlashCheckBox</tabstop>
+  <tabstop>pluginsCheckBox</tabstop>
   <tabstop>doNotTrackCheckBox</tabstop>
   <tabstop>sendRefererCheckBox</tabstop>
   <tabstop>refererWhitelistButton</tabstop>
--- a/Preferences/__init__.py	Sat Mar 19 18:18:09 2016 +0100
+++ b/Preferences/__init__.py	Sat Mar 19 20:07:34 2016 +0100
@@ -1128,8 +1128,8 @@
 ##                QWebEngineSettings.JavascriptCanCloseWindows),
             "JavaScriptCanAccessClipboard": webEngineSettings.testAttribute(
                 QWebEngineSettings.JavascriptCanAccessClipboard),
-##            "PluginsEnabled":
-##            websettings.testAttribute(QWebSettings.PluginsEnabled),
+            "PluginsEnabled": webEngineSettings.testAttribute(
+                QWebEngineSettings.PluginsEnabled),
 ##            "OfflineStorageDatabaseEnabled":
 ##            websettings.testAttribute(
 ##                QWebSettings.OfflineStorageDatabaseEnabled),
@@ -2807,13 +2807,14 @@
 ##    elif key in ["PrintBackgrounds",
 ##                 "JavaEnabled",
 ##                 "JavaScriptCanCloseWindows",
-##                 "PluginsEnabled", "DnsPrefetchEnabled",
+##                 "DnsPrefetchEnabled",
 ##                 "OfflineStorageDatabaseEnabled",
 ##                 "OfflineWebApplicationCacheEnabled", "LocalStorageEnabled",
 ##                 "AccessKeysEnabled",
 ##                 "SiteSpecificQuirksEnabled",
 ##                 "ClickToFlashEnabled",
 ##                 ]:
+    # TODO: add "FullScreenSupportEnabled
     elif key in ["SingleWebBrowserWindow", "SaveGeometry", "JavaScriptEnabled",
                  "JavaScriptCanOpenWindows", "JavaScriptCanAccessClipboard",
                  "AutoLoadImages", "LocalStorageEnabled",
@@ -2828,6 +2829,7 @@
                  "ShowPreview", "WebInspectorEnabled", "DiskCacheEnabled",
                  "DoNotTrack", "SendReferer", "FilterTrackingCookies",
                  "AdBlockEnabled", "AdBlockUseLimitedEasyList",
+                 "PluginsEnabled",
                  ]:
         return toBool(prefClass.settings.value(
             "WebBrowser/" + key, prefClass.webBrowserDefaults[key]))
--- a/WebBrowser/AdBlock/AdBlockRule.py	Sat Mar 19 18:18:09 2016 +0100
+++ b/WebBrowser/AdBlock/AdBlockRule.py	Sat Mar 19 20:07:34 2016 +0100
@@ -12,7 +12,6 @@
 import re
 
 from PyQt5.QtCore import Qt, QRegExp
-from PyQt5.QtNetwork import QNetworkRequest
 from PyQt5.QtWebEngineCore import QWebEngineUrlRequestInfo
 
 
@@ -85,6 +84,7 @@
         self.__stylesheetException = False
         self.__objectSubrequest = False
         self.__objectSubrequestException = False
+        self.__stringMatchRule = False
         
         self.setFilter(filter)
     
@@ -251,6 +251,7 @@
         # no regexp required
         self.__useRegExp = False
         self.__matchString = parsedLine
+        self.__stringMatchRule = True
     
     def __parseDomains(self, domains, separator):
         """
@@ -288,23 +289,7 @@
         if self.__cssRule or not self.__enabled or self.__internalDisabled:
             return False
         
-        matched = False
-        
-        if self.__useRegExp:
-            matched = self.__regExp.indexIn(encodedUrl) != -1
-        elif self.__useDomainMatch:
-            matched = domain.endswith(self.__matchString)
-        elif self.__useEndsMatch:
-            if self.__caseSensitivity == Qt.CaseInsensitive:
-                matched = encodedUrl.lower().endswith(
-                    self.__matchString.lower())
-            else:
-                matched = encodedUrl.endswith(self.__matchString)
-        else:
-            if self.__caseSensitivity == Qt.CaseInsensitive:
-                matched = self.__matchString.lower() in encodedUrl.lower()
-            else:
-                matched = self.__matchString in encodedUrl
+        matched = self.__stringMatch(domain, encodedUrl)
         
         if matched:
             # check domain restrictions
@@ -359,7 +344,41 @@
         
         encodedUrl = bytes(url.toEncoded()).decode()
         domain = url.host()
-        return self.networkMatch(QNetworkRequest(url), domain, encodedUrl)
+        return self.__stringMatch(domain, encodedUrl)
+    
+    def __stringMatch(self, domain, encodedUrl):
+        """
+        Private method to match a domain string.
+        
+        @param domain domain to match
+        @type str
+        @param encodedUrl URL in encoded form
+        @type str
+        @return flag indicating a match
+        @rtype bool
+        """
+        if self.__cssRule or not self.__enabled or self.__internalDisabled:
+            return False
+        
+        matched = False
+        
+        if self.__useRegExp:
+            matched = self.__regExp.indexIn(encodedUrl) != -1
+        elif self.__useDomainMatch:
+            matched = domain.endswith(self.__matchString)
+        elif self.__useEndsMatch:
+            if self.__caseSensitivity == Qt.CaseInsensitive:
+                matched = encodedUrl.lower().endswith(
+                    self.__matchString.lower())
+            else:
+                matched = encodedUrl.endswith(self.__matchString)
+        else:
+            if self.__caseSensitivity == Qt.CaseInsensitive:
+                matched = self.__matchString.lower() in encodedUrl.lower()
+            else:
+                matched = self.__matchString in encodedUrl
+        
+        return matched
     
     def matchDomain(self, domain):
         """
--- a/WebBrowser/SearchWidget.py	Sat Mar 19 18:18:09 2016 +0100
+++ b/WebBrowser/SearchWidget.py	Sat Mar 19 20:07:34 2016 +0100
@@ -34,10 +34,6 @@
         
         self.__mainWindow = mainWindow
         
-        # TODO: Check what Qt 5.6 can offer (maybe using JavaScript)
-        self.wrapCheckBox.setVisible(False)
-        self.highlightAllCheckBox.setVisible(False)
-##        self.wrapCheckBox.setChecked(True)
         self.closeButton.setIcon(UI.PixmapCache.getIcon("close.png"))
         self.findPrevButton.setIcon(UI.PixmapCache.getIcon("1leftarrow.png"))
         self.findNextButton.setIcon(UI.PixmapCache.getIcon("1rightarrow.png"))
@@ -73,7 +69,6 @@
         @param txt current text of the search combos line edit (string)
             (unused)
         """
-        self.on_highlightAllCheckBox_toggled(True)
         self.__findNextPrev()
     
     def __findNextPrev(self):
@@ -86,13 +81,10 @@
         if not self.findtextCombo.currentText():
             return
         
-        # TODO: adjust this to the browser API
         self.__mainWindow.currentBrowser().findNextPrev(
             self.findtextCombo.currentText(),
             self.caseCheckBox.isChecked(),
             self.__findBackwards,
-            self.wrapCheckBox.isChecked(),
-            False,
             self.__findNextPrevCallback)
     
     def __findNextPrevCallback(self, found):
@@ -105,24 +97,6 @@
         if not found:
             self.infoLabel.setText(self.tr("Expression was not found."))
             self.__setFindtextComboBackground(True)
-##    
-##    @pyqtSlot(bool)
-##    def on_highlightAllCheckBox_toggled(self, checked):
-##        """
-##        Private slot to toggle the highlight of all occurrences.
-##        
-##        @param checked flag indicating the check box toggle state (boolean)
-##        """
-##        cbr = self.__mainWindow.currentBrowser()
-##        if cbr is None:
-##            return
-##        cbr.findNextPrev(
-##            "", False, False, False, True)
-##        if self.highlightAllCheckBox.isChecked():
-##            cbr.findNextPrev(
-##                self.findtextCombo.currentText(),
-##                self.caseCheckBox.isChecked(),
-##                False, False, True)
     
     @pyqtSlot()
     def on_findNextButton_clicked(self):
--- a/WebBrowser/SearchWidget.ui	Sat Mar 19 18:18:09 2016 +0100
+++ b/WebBrowser/SearchWidget.ui	Sat Mar 19 20:07:34 2016 +0100
@@ -6,15 +6,24 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>718</width>
-    <height>25</height>
+    <width>747</width>
+    <height>26</height>
    </rect>
   </property>
   <property name="windowTitle">
    <string>Find</string>
   </property>
   <layout class="QHBoxLayout" name="horizontalLayout">
-   <property name="margin">
+   <property name="leftMargin">
+    <number>0</number>
+   </property>
+   <property name="topMargin">
+    <number>0</number>
+   </property>
+   <property name="rightMargin">
+    <number>0</number>
+   </property>
+   <property name="bottomMargin">
     <number>0</number>
    </property>
    <item>
@@ -75,20 +84,6 @@
     </widget>
    </item>
    <item>
-    <widget class="QCheckBox" name="wrapCheckBox">
-     <property name="text">
-      <string>Wrap around</string>
-     </property>
-    </widget>
-   </item>
-   <item>
-    <widget class="QCheckBox" name="highlightAllCheckBox">
-     <property name="text">
-      <string>Highlight all</string>
-     </property>
-    </widget>
-   </item>
-   <item>
     <widget class="Line" name="infoLine">
      <property name="orientation">
       <enum>Qt::Vertical</enum>
@@ -113,8 +108,6 @@
  <tabstops>
   <tabstop>findtextCombo</tabstop>
   <tabstop>caseCheckBox</tabstop>
-  <tabstop>wrapCheckBox</tabstop>
-  <tabstop>highlightAllCheckBox</tabstop>
   <tabstop>findNextButton</tabstop>
   <tabstop>findPrevButton</tabstop>
   <tabstop>closeButton</tabstop>
--- a/WebBrowser/WebBrowserView.py	Sat Mar 19 18:18:09 2016 +0100
+++ b/WebBrowser/WebBrowserView.py	Sat Mar 19 20:07:34 2016 +0100
@@ -487,17 +487,13 @@
         """
         return self.selectedText() != ""
     
-    # TODO: adjust this to what Qt 5.6 is offering
-    def findNextPrev(self, txt, case, backwards, wrap, highlightAll, callback):
+    def findNextPrev(self, txt, case, backwards, callback):
         """
         Public slot to find the next occurrence of a text.
         
         @param txt text to search for (string)
         @param case flag indicating a case sensitive search (boolean)
         @param backwards flag indicating a backwards search (boolean)
-        @param wrap flag indicating to wrap around (boolean)
-        @param highlightAll flag indicating to highlight all occurrences
-            (boolean)
         @param callback reference to a function with a bool parameter
         @type function(bool) or None
         """
@@ -506,13 +502,6 @@
             findFlags |= QWebEnginePage.FindCaseSensitively
         if backwards:
             findFlags |= QWebEnginePage.FindBackward
-##        if wrap:
-##            findFlags |= QWebPage.FindWrapsAroundDocument
-##        try:
-##            if highlightAll:
-##                findFlags |= QWebPage.HighlightAllOccurrences
-##        except AttributeError:
-##            pass
         
         if callback is None:
             self.findText(txt, findFlags)

eric ide

mercurial