diff --git a/qutebrowser/browser/curcommand.py b/qutebrowser/browser/curcommand.py index 405e87165..dfcb325e9 100644 --- a/qutebrowser/browser/curcommand.py +++ b/qutebrowser/browser/curcommand.py @@ -164,6 +164,17 @@ class CurCommandDispatcher(QObject): for _ in range(count): self._tabs.currentWidget().forward() + @cmdutils.register(instance='mainwindow.tabs.cur') + def hint(self, mode="all"): + """Start hinting. + + Command handler for :hint. + + Args: + mode: The hinting mode to use. + """ + self._tabs.currentWidget()._hintmanager.start(mode) + @pyqtSlot(str, int) def search(self, text, flags): """Search for text in the current page. diff --git a/qutebrowser/browser/hints.py b/qutebrowser/browser/hints.py new file mode 100644 index 000000000..8786bdd28 --- /dev/null +++ b/qutebrowser/browser/hints.py @@ -0,0 +1,60 @@ +# Copyright 2014 Florian Bruhin (The Compiler) +# +# This file is part of qutebrowser. +# +# qutebrowser is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# qutebrowser is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with qutebrowser. If not, see . + +"""A HintManager to draw hints over links.""" + + +class HintManager: + + """Manage drawing hints over links or other elements. + + Class attributes: + SELECTORS: CSS selectors for the different highlighting modes. + + Attributes: + _frame: The QWebFrame to use. + """ + + SELECTORS = { + "all": ("a, textarea, select, input:not([type=hidden]), button, " + "frame, iframe, [onclick], [onmousedown], [role=link], " + "[role=option], [role=button], img"), + "links": "a", + "images": "img", + # FIXME remove input:not([type=hidden]) and add mor explicit inputs. + "editable": ("input:not([type=hidden]), input[type=text], " + "input[type=password], input[type=search], textarea"), + "url": "[src], [href]", + } + + def __init__(self, frame): + """Constructor. + + Args: + frame: The QWebFrame to use for finding elements and drawing. + """ + self._frame = frame + + def start(self, mode="all"): + """Start hinting. + + Args: + mode: The mode to be used. + """ + elems = self._frame.findAllElements(HintManager.SELECTORS[mode]) + for e in elems: + e.setAttribute("style", "background-color:red") diff --git a/qutebrowser/widgets/browsertab.py b/qutebrowser/widgets/browsertab.py index fc725701f..5abb4312a 100644 --- a/qutebrowser/widgets/browsertab.py +++ b/qutebrowser/widgets/browsertab.py @@ -28,6 +28,7 @@ import qutebrowser.utils.url as urlutils import qutebrowser.config.config as config import qutebrowser.utils.message as message from qutebrowser.browser.webpage import BrowserPage +from qutebrowser.browser.hints import HintManager from qutebrowser.utils.signals import SignalCache from qutebrowser.utils.usertypes import NeighborList @@ -41,6 +42,7 @@ class BrowserTab(QWebView): Attributes: page_: The QWebPage behind the view signal_cache: The signal cache associated with the view. + _hintmanager: The HintManager instance for this view. _zoom: A NeighborList with the zoom levels. _scroll_pos: The old scroll position. _shutdown_callback: Callback to be called after shutdown. @@ -74,6 +76,7 @@ class BrowserTab(QWebView): self._init_neighborlist() self.page_ = BrowserPage(self) self.setPage(self.page_) + self._hintmanager = HintManager(self.page_.mainFrame()) self.signal_cache = SignalCache(uncached=['linkHovered']) self.page_.setLinkDelegationPolicy(QWebPage.DelegateAllLinks) self.page_.linkHovered.connect(self.linkHovered)