From 6434dac680fbf1adc74eea94f37e46203730355e Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 20 Apr 2014 23:02:27 +0200 Subject: [PATCH] Check element visibility before drawing --- qutebrowser/browser/hints.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/qutebrowser/browser/hints.py b/qutebrowser/browser/hints.py index 229c959e5..8cc4d7e15 100644 --- a/qutebrowser/browser/hints.py +++ b/qutebrowser/browser/hints.py @@ -66,20 +66,12 @@ class HintManager: frame: The QWebFrame to use for finding elements and drawing. """ self._frame = frame - self._elems = None + self._elems = [] self._labels = [] def _draw_label(self, elem): """Draw a hint label over an element.""" rect = elem.geometry() - if (not rect.isValid()) and rect.x() == 0: - # Most likely an invisible link - return - framegeom = self._frame.geometry() - framegeom.translate(self._frame.scrollPosition()) - if not framegeom.contains(rect): - # out of screen - return css = HintManager.HINT_CSS.format(left=rect.x(), top=rect.y(), config=config.instance) doc = self._frame.documentElement() @@ -94,8 +86,18 @@ class HintManager: mode: The mode to be used. """ selector = HintManager.SELECTORS[mode] - self._elems = self._frame.findAllElements(selector) - for e in self._elems: + elems = self._frame.findAllElements(selector) + for e in elems: + rect = e.geometry() + if (not rect.isValid()) and rect.x() == 0: + # Most likely an invisible link + continue + framegeom = self._frame.geometry() + framegeom.translate(self._frame.scrollPosition()) + if not framegeom.contains(rect): + # out of screen + continue + self._elems.append(e) self._draw_label(e) def stop(self):