Cleanup
This commit is contained in:
parent
810e507da9
commit
fdc51cb628
@ -170,7 +170,22 @@ def get_child_frames(startframe):
|
|||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
def _is_object_editable(elem):
|
def is_content_editable(elem):
|
||||||
|
"""Check if an element hsa a contenteditable attribute.
|
||||||
|
|
||||||
|
FIXME: Add tests.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
elem: The QWebElement to check.
|
||||||
|
|
||||||
|
Return:
|
||||||
|
True if the element has a contenteditable attribute, False otherwise.
|
||||||
|
"""
|
||||||
|
return (elem.hasAttribute('contenteditable') and
|
||||||
|
elem.attribute('contenteditable') not in ('false', 'inherit'))
|
||||||
|
|
||||||
|
|
||||||
|
def _is_editable_object(elem):
|
||||||
"""Check if an object-element is editable."""
|
"""Check if an object-element is editable."""
|
||||||
if not elem.hasAttribute('type'):
|
if not elem.hasAttribute('type'):
|
||||||
log.webview.debug("<object> without type clicked...")
|
log.webview.debug("<object> without type clicked...")
|
||||||
@ -187,19 +202,36 @@ def _is_object_editable(elem):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def is_content_editable(elem):
|
def _is_editable_input(elem):
|
||||||
"""Check if an element hsa a contenteditable attribute.
|
"""Check if an input-element is editable.
|
||||||
|
|
||||||
FIXME: Add tests.
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
elem: The QWebElement to check.
|
elem: The QWebElement to check.
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
True if the element has a contenteditable attribute, False otherwise.
|
True if the element is editable, False otherwise.
|
||||||
"""
|
"""
|
||||||
return (elem.hasAttribute('contenteditable') and
|
objtype = elem.attribute('type').lower()
|
||||||
elem.attribute('contenteditable') not in ('false', 'inherit'))
|
if objtype in ['text', 'email', 'url', 'tel', 'number', 'password',
|
||||||
|
'search', '']:
|
||||||
|
return is_writable(elem)
|
||||||
|
|
||||||
|
|
||||||
|
def _is_editable_div(elem):
|
||||||
|
"""Check if a div-element is editable.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
elem: The QWebElement to check.
|
||||||
|
|
||||||
|
Return:
|
||||||
|
True if the element is editable, False otherwise.
|
||||||
|
"""
|
||||||
|
# Beginnings of div-classes which are actually some kind of editor.
|
||||||
|
div_classes = ('CodeMirror', # Javascript editor over a textarea
|
||||||
|
'kix-') # Google Docs editor
|
||||||
|
for klass in elem.classes():
|
||||||
|
if any([klass.startswith(e) for e in div_classes]):
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def is_editable(elem):
|
def is_editable(elem):
|
||||||
@ -213,40 +245,28 @@ def is_editable(elem):
|
|||||||
Return:
|
Return:
|
||||||
True if we should switch to insert mode, False otherwise.
|
True if we should switch to insert mode, False otherwise.
|
||||||
"""
|
"""
|
||||||
# Beginnings of div-classes which are actually some kind of editor.
|
# pylint: disable=too-many-return-statements
|
||||||
|
roles = ('combobox', 'textbox')
|
||||||
log.misc.debug("Checking if element is editable: {}".format(
|
log.misc.debug("Checking if element is editable: {}".format(
|
||||||
elem.toOuterXml()))
|
elem.toOuterXml()))
|
||||||
div_classes = ('CodeMirror', # Javascript editor over a textarea
|
tag = elem.tagName().lower()
|
||||||
'kix-') # Google Docs editor
|
|
||||||
roles = ('combobox', 'textbox')
|
|
||||||
if is_content_editable(elem) and is_writable(elem):
|
if is_content_editable(elem) and is_writable(elem):
|
||||||
return True
|
return True
|
||||||
if (elem.hasAttribute('contenteditable') and
|
elif elem.hasAttribute('role') and elem.attribute('role') in roles:
|
||||||
elem.attribute('contenteditable') not in ('false', 'inherit')):
|
return True
|
||||||
return is_writable(elem)
|
elif tag == 'input':
|
||||||
tag = elem.tagName().lower()
|
return _is_editable_input(elem)
|
||||||
if tag == 'input':
|
|
||||||
objtype = elem.attribute('type').lower()
|
|
||||||
if objtype in ['text', 'email', 'url', 'tel', 'number', 'password',
|
|
||||||
'search', '']:
|
|
||||||
return is_writable(elem)
|
|
||||||
elif tag in ('textarea', 'select'):
|
elif tag in ('textarea', 'select'):
|
||||||
return is_writable(elem)
|
return is_writable(elem)
|
||||||
elif tag in ('embed', 'applet'):
|
elif tag in ('embed', 'applet'):
|
||||||
# Flash/Java/...
|
# Flash/Java/...
|
||||||
return config.get('input', 'insert-mode-on-plugins')
|
return config.get('input', 'insert-mode-on-plugins')
|
||||||
elif tag == 'object':
|
elif tag == 'object':
|
||||||
return _is_object_editable(elem)
|
return _is_editable_object(elem)
|
||||||
elif tag == 'div':
|
elif tag == 'div':
|
||||||
log.webview.debug("div with classes {} clicked!".format(
|
return _is_editable_div(elem)
|
||||||
elem.classes()))
|
else:
|
||||||
for klass in elem.classes():
|
return False
|
||||||
if any([klass.startswith(e) for e in div_classes]):
|
|
||||||
return True
|
|
||||||
elif tag == 'span':
|
|
||||||
log.webview.debug("span with classes {} clicked!".format(
|
|
||||||
elem.classes()))
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def focus_elem(frame):
|
def focus_elem(frame):
|
||||||
|
Loading…
Reference in New Issue
Block a user