Go to insert mode when plugin clicked

This commit is contained in:
Florian Bruhin 2014-04-24 07:41:20 +02:00
parent 5b84848ad9
commit a82ab6d707
3 changed files with 31 additions and 2 deletions

1
TODO
View File

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

View File

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

View File

@ -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("<object> without type clicked...")
return False
objtype = elem.attribute("type")
if not objtype.startswith("image/"):
logging.debug("<object type=\"{}\"> 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: