Пример #1
0
 def on_load_finished(self, ok):
     """Handle auto-insert-mode after loading finished."""
     if ok and not self._has_ssl_errors:
         self._set_load_status(LoadStatus.success)
     elif ok:
         self._set_load_status(LoadStatus.warn)
     else:
         self._set_load_status(LoadStatus.error)
     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 = webelem.WebElementWrapper(frame.findFirstElement(':focus'))
     except webelem.IsNullError:
         log.webview.debug("Focused element is null!")
         return
     log.modes.debug("focus element: {}".format(repr(elem)))
     if elem.is_editable():
         modeman.maybe_enter(self._win_id, usertypes.KeyMode.insert,
                             'load finished')
Пример #2
0
 def on_load_finished(self, ok):
     """Handle auto-insert-mode after loading finished."""
     if ok and not self._has_ssl_errors:
         self._set_load_status(LoadStatus.success)
     elif ok:
         self._set_load_status(LoadStatus.warn)
     else:
         self._set_load_status(LoadStatus.error)
     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 = webelem.WebElementWrapper(frame.findFirstElement(':focus'))
     except webelem.IsNullError:
         log.webview.debug("Focused element is null!")
         return
     log.modes.debug("focus element: {}".format(repr(elem)))
     if elem.is_editable():
         modeman.maybe_enter(self._win_id, usertypes.KeyMode.insert,
                             'load finished')
Пример #3
0
    def on_load_finished(self):
        """Handle auto-insert-mode after loading finished.

        We don't take loadFinished's ok argument here as it always seems to be
        true when the QWebPage has an ErrorPageExtension implemented.
        See https://github.com/The-Compiler/qutebrowser/issues/84
        """
        ok = not self.page().error_occured
        if ok and not self._has_ssl_errors:
            self._set_load_status(LoadStatus.success)
        elif ok:
            self._set_load_status(LoadStatus.warn)
        else:
            self._set_load_status(LoadStatus.error)
        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 = webelem.WebElementWrapper(frame.findFirstElement(':focus'))
        except webelem.IsNullError:
            log.webview.debug("Focused element is null!")
            return
        log.modes.debug("focus element: {}".format(repr(elem)))
        if elem.is_editable():
            modeman.maybe_enter(self._win_id, usertypes.KeyMode.insert,
                                'load finished')
Пример #4
0
    def on_load_finished(self):
        """Handle auto-insert-mode after loading finished.

        We don't take loadFinished's ok argument here as it always seems to be
        true when the QWebPage has an ErrorPageExtension implemented.
        See https://github.com/The-Compiler/qutebrowser/issues/84
        """
        ok = not self.page().error_occured
        if ok and not self._has_ssl_errors:
            self._set_load_status(LoadStatus.success)
        elif ok:
            self._set_load_status(LoadStatus.warn)
        else:
            self._set_load_status(LoadStatus.error)
        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 = webelem.WebElementWrapper(frame.findFirstElement(':focus'))
        except webelem.IsNullError:
            log.webview.debug("Focused element is null!")
            return
        log.modes.debug("focus element: {}".format(repr(elem)))
        if elem.is_editable():
            modeman.maybe_enter(self._win_id, usertypes.KeyMode.insert,
                                'load finished')
Пример #5
0
    def _mousepress_insertmode(self, e):
        """Switch to insert mode when an editable element was clicked.

        Args:
            e: The QMouseEvent.
        """
        pos = e.pos()
        frame = self.page().frameAt(pos)
        if frame is None:
            # This happens when we click inside the webview, but not actually
            # on the QWebPage - for example when clicking the scrollbar
            # sometimes.
            log.mouse.debug("Clicked at {} but frame is None!".format(pos))
            return
        # You'd think we have to subtract frame.geometry().topLeft() from the
        # position, but it seems QWebFrame::hitTestContent wants a position
        # relative to the QWebView, not to the frame. This makes no sense to
        # me, but it works this way.
        hitresult = frame.hitTestContent(pos)
        if hitresult.isNull():
            # For some reason, the whole hitresult can be null sometimes (e.g.
            # on doodle menu links). If this is the case, we schedule a check
            # later (in mouseReleaseEvent) which uses webelem.focus_elem.
            log.mouse.debug("Hitresult is null!")
            self._check_insertmode = True
            return
        try:
            elem = webelem.WebElementWrapper(hitresult.element())
        except webelem.IsNullError:
            # For some reason, the hitresult 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.
            log.mouse.debug("Hitresult element is null!")
            self._check_insertmode = True
            return
        if ((hitresult.isContentEditable() and elem.is_writable())
                or elem.is_editable()):
            log.mouse.debug("Clicked editable element!")
            modeman.maybe_enter(self._win_id, usertypes.KeyMode.insert,
                                'click')
        else:
            log.mouse.debug("Clicked non-editable element!")
            if config.get('input', 'auto-leave-insert-mode'):
                modeman.maybe_leave(self._win_id, usertypes.KeyMode.insert,
                                    'click')
Пример #6
0
    def _mousepress_insertmode(self, e):
        """Switch to insert mode when an editable element was clicked.

        Args:
            e: The QMouseEvent.
        """
        pos = e.pos()
        frame = self.page().frameAt(pos)
        if frame is None:
            # This happens when we click inside the webview, but not actually
            # on the QWebPage - for example when clicking the scrollbar
            # sometimes.
            log.mouse.debug("Clicked at {} but frame is None!".format(pos))
            return
        # You'd think we have to subtract frame.geometry().topLeft() from the
        # position, but it seems QWebFrame::hitTestContent wants a position
        # relative to the QWebView, not to the frame. This makes no sense to
        # me, but it works this way.
        hitresult = frame.hitTestContent(pos)
        if hitresult.isNull():
            # For some reason, the whole hitresult can be null sometimes (e.g.
            # on doodle menu links). If this is the case, we schedule a check
            # later (in mouseReleaseEvent) which uses webelem.focus_elem.
            log.mouse.debug("Hitresult is null!")
            self._check_insertmode = True
            return
        try:
            elem = webelem.WebElementWrapper(hitresult.element())
        except webelem.IsNullError:
            # For some reason, the hitresult 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.
            log.mouse.debug("Hitresult element is null!")
            self._check_insertmode = True
            return
        if ((hitresult.isContentEditable() and elem.is_writable()) or
                elem.is_editable()):
            log.mouse.debug("Clicked editable element!")
            modeman.maybe_enter(self._win_id, usertypes.KeyMode.insert,
                                'click')
        else:
            log.mouse.debug("Clicked non-editable element!")
            if config.get('input', 'auto-leave-insert-mode'):
                modeman.maybe_leave(self._win_id, usertypes.KeyMode.insert,
                                    'click')
Пример #7
0
 def mouserelease_insertmode(self):
     """If we have an insertmode check scheduled, handle it."""
     if not self._check_insertmode:
         return
     self._check_insertmode = False
     try:
         elem = webelem.focus_elem(self.page().currentFrame())
     except webelem.IsNullError:
         log.mouse.warning("Element vanished!")
         return
     if elem.is_editable():
         log.mouse.debug("Clicked editable element (delayed)!")
         modeman.maybe_enter(usertypes.KeyMode.insert, 'click-delayed')
     else:
         log.mouse.debug("Clicked non-editable element (delayed)!")
         if config.get('input', 'auto-leave-insert-mode'):
             modeman.maybe_leave(usertypes.KeyMode.insert, 'click-delayed')
Пример #8
0
 def mouserelease_insertmode(self):
     """If we have an insertmode check scheduled, handle it."""
     if not self._check_insertmode:
         return
     self._check_insertmode = False
     try:
         elem = webelem.focus_elem(self.page().currentFrame())
     except webelem.IsNullError:
         log.mouse.warning("Element vanished!")
         return
     if elem.is_editable():
         log.mouse.debug("Clicked editable element (delayed)!")
         modeman.maybe_enter(self._win_id, usertypes.KeyMode.insert,
                             'click-delayed')
     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')
Пример #9
0
 def focusInEvent(self, e):
     """Extend focusInEvent to enter command mode."""
     modeman.maybe_enter(self._win_id, usertypes.KeyMode.command,
                         'cmd focus')
     super().focusInEvent(e)