Add proof-of-concept hinting

This commit is contained in:
Florian Bruhin 2014-04-19 17:50:11 +02:00
parent 1f66766e0a
commit e6569f946c
3 changed files with 74 additions and 0 deletions

View File

@ -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.

View File

@ -0,0 +1,60 @@
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# 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 <http://www.gnu.org/licenses/>.
"""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")

View File

@ -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)