From 6b358fe95507360c8a9891f10f87e6e721d0eb02 Mon Sep 17 00:00:00 2001 From: Thomas Fischer Date: Sat, 8 Sep 2018 00:59:41 -0700 Subject: [PATCH] (QtWebEngine) Unhide scrollbar on search result --- qutebrowser/browser/shared.py | 4 ++-- qutebrowser/browser/webengine/webenginetab.py | 21 +++++++++++-------- qutebrowser/config/configdata.yml | 11 +++++++--- qutebrowser/config/configfiles.py | 1 + 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/qutebrowser/browser/shared.py b/qutebrowser/browser/shared.py index 2398ca2e4..7dfcda4bd 100644 --- a/qutebrowser/browser/shared.py +++ b/qutebrowser/browser/shared.py @@ -274,7 +274,7 @@ def get_tab(win_id, target): return tabbed_browser.tabopen(url=None, background=bg_tab) -def get_user_stylesheet(): +def get_user_stylesheet(searching=False): """Get the combined user-stylesheet.""" css = '' stylesheets = config.val.content.user_stylesheets @@ -283,7 +283,7 @@ def get_user_stylesheet(): with open(filename, 'r', encoding='utf-8') as f: css += f.read() - if not config.val.scrolling.bar: + if not (config.val.scrolling.bar == 'always' or config.val.scrolling.bar == 'when_searching' and searching): css += '\nhtml > ::-webkit-scrollbar { width: 0px; height: 0px; }' return css diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py index cfb809097..d6a89f072 100644 --- a/qutebrowser/browser/webengine/webenginetab.py +++ b/qutebrowser/browser/webengine/webenginetab.py @@ -163,10 +163,11 @@ class WebEngineSearch(browsertab.AbstractSearch): back yet. """ - def __init__(self, parent=None): + def __init__(self, tab, parent=None): super().__init__(parent) self._flags = QWebEnginePage.FindFlags(0) self._pending_searches = 0 + self._tab = tab def _find(self, text, flags, callback, caller): """Call findText on the widget.""" @@ -194,6 +195,7 @@ class WebEngineSearch(browsertab.AbstractSearch): .strip()) if callback is not None: callback(found) + self._tab.scripts.update_stylesheet(searching=found) self._widget.findText(text, flags, wrapped_callback) def search(self, text, *, ignore_case='never', reverse=False, @@ -216,6 +218,7 @@ class WebEngineSearch(browsertab.AbstractSearch): def clear(self): self.search_displayed = False self._widget.findText('') + self._tab.scripts.update_stylesheet(searching=False) def prev_result(self, *, result_cb=None): # The int() here makes sure we get a copy of the flags. @@ -813,11 +816,11 @@ class _WebEngineScripts(QObject): def _on_config_changed(self, option): if option in ['scrolling.bar', 'content.user_stylesheets']: self._init_stylesheet() - self._update_stylesheet() + self.update_stylesheet() - def _update_stylesheet(self): + def update_stylesheet(self, searching=False): """Update the custom stylesheet in existing tabs.""" - css = shared.get_user_stylesheet() + css = shared.get_user_stylesheet(searching=searching) code = javascript.assemble('stylesheet', 'set_css', css) self._tab.run_js_async(code) @@ -991,13 +994,13 @@ class WebEngineTab(browsertab.AbstractTab): self.caret = WebEngineCaret(mode_manager=mode_manager, tab=self, parent=self) self.zoom = WebEngineZoom(tab=self, parent=self) - self.search = WebEngineSearch(parent=self) + self.search = WebEngineSearch(tab=self, parent=self) self.printing = WebEnginePrinting(tab=self) self.elements = WebEngineElements(tab=self) self.action = WebEngineAction(tab=self) self.audio = WebEngineAudio(parent=self) self._permissions = _WebEnginePermissions(tab=self, parent=self) - self._scripts = _WebEngineScripts(tab=self, parent=self) + self.scripts = _WebEngineScripts(tab=self, parent=self) # We're assigning settings in _set_widget self.settings = webenginesettings.WebEngineSettings(settings=None) self._set_widget(widget) @@ -1006,13 +1009,13 @@ class WebEngineTab(browsertab.AbstractTab): self._child_event_filter = None self._saved_zoom = None self._reload_url = None - self._scripts.init() + self.scripts.init() def _set_widget(self, widget): # pylint: disable=protected-access super()._set_widget(widget) self._permissions._widget = widget - self._scripts._widget = widget + self.scripts._widget = widget def _install_event_filter(self): fp = self._widget.focusProxy() @@ -1405,7 +1408,7 @@ class WebEngineTab(browsertab.AbstractTab): # pylint: disable=protected-access self.audio._connect_signals() self._permissions.connect_signals() - self._scripts.connect_signals() + self.scripts.connect_signals() def event_target(self): return self._widget.render_widget() diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index 7d39bded8..1dc008a1b 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -1191,9 +1191,14 @@ prompt.radius: ## scrolling scrolling.bar: - type: Bool - default: false - desc: Show a scrollbar. + type: + name: String + valid_values: + - always: Always show the scrollbar. + - never: Never show the scrollbar. + - when_searching: Show the scrollbar when searching for text in the webpage. + default: when_searching + desc: When to show the scrollbar. scrolling.smooth: type: Bool diff --git a/qutebrowser/config/configfiles.py b/qutebrowser/config/configfiles.py index a2c88d311..46d9946da 100644 --- a/qutebrowser/config/configfiles.py +++ b/qutebrowser/config/configfiles.py @@ -277,6 +277,7 @@ class YamlConfig(QObject): self._mark_changed() self._migrate_bool(settings, 'tabs.favicons.show', 'always', 'never') + self._migrate_bool(settings, 'scrolling.bar', 'when_searching', 'never') self._migrate_bool(settings, 'qt.force_software_rendering', 'software-opengl', 'none')