Skip to content
Permalink
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.
Args:
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!")
callback(None)
return
@@ -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
# http://www.sbb.ch/ ). If this is the case, we schedule a check
# later (in mouseReleaseEvent) which uses webelem.focus_elem.
# http://www.sbb.ch/ ).
log.webview.debug("Hit test result element is null!")
callback(None)
return
@@ -73,11 +73,7 @@ def __init__(self, key, modifiers=0, text=''):

class FakeWebFrame:

"""A stub for QWebFrame.
Attributes:
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
else:
raise Exception("Trying to get focus element but it's unset!")
else:
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:

@pytest.fixture(autouse=True)

0 comments on commit 78d64f4

Please sign in to comment.