Skip to content
Browse files
Get rid of webkitelem.focus_elem
  • Loading branch information
The-Compiler committed Sep 7, 2016
1 parent c267776 commit 78d64f47916f51c51893e15e3147620424a84f62
@@ -306,14 +306,3 @@ def get_child_frames(startframe):
new_frames += frame.childFrames()
frames = new_frames
return results

def focus_elem(frame):
"""Get the focused element in a web frame.
frame: The QWebFrame to search in.
# FIXME:qtwebengine get rid of this
elem = frame.findFirstElement('*:focus')
return WebKitElement(elem, tab=None)
@@ -550,8 +550,7 @@ def find_at_pos(self, pos, callback):
hitresult = frame.hitTestContent(pos)
if hitresult.isNull():
# For some reason, the whole hit result can be null sometimes (e.g.
# on doodle menu links). If this is the case, we schedule a check
# later (in mouseReleaseEvent) which uses webkitelem.focus_elem.
# on doodle menu links).
log.webview.debug("Hit test result is null!")
@@ -561,8 +560,7 @@ def find_at_pos(self, pos, callback):
except webkitelem.IsNullError:
# For some reason, the hit result element can be a null element
# sometimes (e.g. when clicking the timetable fields on
# ). If this is the case, we schedule a check
# later (in mouseReleaseEvent) which uses webelem.focus_elem.
# ).
log.webview.debug("Hit test result element is null!")
@@ -73,11 +73,7 @@ def __init__(self, key, modifiers=0, text=''):

class FakeWebFrame:

"""A stub for QWebFrame.
focus_elem: The 'focused' element.
"""A stub for QWebFrame."""

def __init__(self, geometry=None, *, scroll=None, plaintext=None,
html=None, parent=None, zoom=1.0):
@@ -96,20 +92,10 @@ def __init__(self, geometry=None, *, scroll=None, plaintext=None,
self.geometry = mock.Mock(return_value=geometry)
self.scrollPosition = mock.Mock(return_value=scroll)
self.parentFrame = mock.Mock(return_value=parent)
self.focus_elem = None
self.toPlainText = mock.Mock(return_value=plaintext)
self.toHtml = mock.Mock(return_value=html)
self.zoomFactor = mock.Mock(return_value=zoom)

def findFirstElement(self, selector):
if selector == '*:focus':
if self.focus_elem is not None:
return self.focus_elem
raise Exception("Trying to get focus element but it's unset!")
raise Exception("Unknown selector {!r}!".format(selector))

class FakeChildrenFrame:

@@ -681,19 +681,6 @@ def test_invalid_invisible(self, invalid_objects):
assert not invalid_objects.elems[1].is_visible(invalid_objects.frame)

def test_focus_element(stubs):
"""Test getting focus element with a fake frame/element.
Testing this with a real webpage is almost impossible because the window
and the element would have focus, which is hard to achieve consistently in
a test.
frame = stubs.FakeWebFrame(QRect(0, 0, 100, 100))
elem = get_webelem()
frame.focus_elem = elem._elem
assert webkitelem.focus_elem(frame)._elem is elem._elem

class TestRectOnView:


0 comments on commit 78d64f4

Please sign in to comment.