diff --git a/TODO b/TODO index b1c9de953..4f6a8db2b 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,6 @@ keyparser foo ============= -- Get to insert mode when clicking flash plugins - Handle keybind to get out of insert mode (e.g. esc) - Pass keypresses to statusbar correctly - Switch to normal mode if new page loaded diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 808b61b18..6193b4002 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -166,6 +166,11 @@ DATA = OrderedDict([ ('cmd_timeout', SettingValue(types.Int(minval=0), "500"), "Timeout for ambiguous keybindings."), + + ('insert_mode_on_plugins', + SettingValue(types.Bool(), "true"), + "Whether to switch to insert mode when clicking flash and other " + "plugins."), )), ('tabbar', sect.KeyValue( diff --git a/qutebrowser/widgets/browsertab.py b/qutebrowser/widgets/browsertab.py index e75291b02..43a6619cd 100644 --- a/qutebrowser/widgets/browsertab.py +++ b/qutebrowser/widgets/browsertab.py @@ -110,6 +110,30 @@ class BrowserTab(QWebView): logging.debug("Everything destroyed, calling callback") self._shutdown_callback() + def _is_editable(self, hitresult): + """Checks if the hitresult needs keyboard focus. + + Args: + hitresult: A QWebHitTestResult + """ + # FIXME is this algorithm accurate? + if hitresult.isContentEditable(): + return True + if not config.get('general', 'insert_mode_on_plugins'): + return False + elem = hitresult.element() + tag = elem.tagName().lower() + if tag in ['embed', 'applet']: + return True + elif tag == 'object': + if not elem.hasAttribute("type"): + logging.warn(" without type clicked...") + return False + objtype = elem.attribute("type") + if not objtype.startswith("image/"): + logging.debug(" clicked.".format(objtype)) + return True + def openurl(self, url): """Open an URL in the browser. @@ -268,10 +292,11 @@ class BrowserTab(QWebView): frame = self.page_.frameAt(pos) pos -= frame.geometry().topLeft() hitresult = frame.hitTestContent(pos) - if hitresult.isContentEditable(): + if self._is_editable(hitresult): logging.debug("Clicked editable element!") modemanager.enter("insert") else: + logging.debug("Clicked non-editable element!") try: modemanager.leave("insert") except ValueError: