Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
 def _handle_auto_insert_mode(self, ok):
     """Handle auto-insert-mode after loading finished."""
     if not config.get('input', 'auto-insert-mode'):
         return
     mode_manager = objreg.get('mode-manager', scope='window',
                               window=self.win_id)
     cur_mode = mode_manager.mode
     if cur_mode == usertypes.KeyMode.insert or not ok:
         return
     frame = self.page().currentFrame()
     try:
         elem = webkitelem.focus_elem(frame)
     except webkitelem.IsNullError:
         log.webview.debug("Focused element is null!")
         return
     log.modes.debug("focus element: {}".format(repr(elem)))
     if elem.is_editable():
         modeman.enter(self.win_id, usertypes.KeyMode.insert,
                       'load finished', only_if_normal=True)
Ejemplo n.º 3
0
 def mouserelease_insertmode(self):
     """If we have an insertmode check scheduled, handle it."""
     # FIXME:qtwebengine Use tab.find_focus_element here
     if not self._check_insertmode:
         return
     self._check_insertmode = False
     try:
         elem = webkitelem.focus_elem(self.page().currentFrame())
     except (webkitelem.IsNullError, RuntimeError):
         log.mouse.debug("Element/page vanished!")
         return
     if elem.is_editable():
         log.mouse.debug("Clicked editable element (delayed)!")
         modeman.enter(self.win_id, usertypes.KeyMode.insert,
                       'click-delayed', only_if_normal=True)
     else:
         log.mouse.debug("Clicked non-editable element (delayed)!")
         if config.get('input', 'auto-leave-insert-mode'):
             modeman.maybe_leave(self.win_id, usertypes.KeyMode.insert,
                                 'click-delayed')
Ejemplo n.º 4
0
 def _handle_auto_insert_mode(self, ok):
     """Handle auto-insert-mode after loading finished."""
     if not config.get('input', 'auto-insert-mode'):
         return
     mode_manager = objreg.get('mode-manager',
                               scope='window',
                               window=self.win_id)
     cur_mode = mode_manager.mode
     if cur_mode == usertypes.KeyMode.insert or not ok:
         return
     frame = self.page().currentFrame()
     try:
         elem = webkitelem.focus_elem(frame)
     except webkitelem.IsNullError:
         log.webview.debug("Focused element is null!")
         return
     log.modes.debug("focus element: {}".format(repr(elem)))
     if elem.is_editable():
         modeman.enter(self.win_id,
                       usertypes.KeyMode.insert,
                       'load finished',
                       only_if_normal=True)