Skip to content

Commit

Permalink
WebKit-specific: don't attempt to select a word on a scrollbar
Browse files Browse the repository at this point in the history
Without the added scollbar check, when "Select word by single click"
option is on, clicking on a scollbar clears current selection and
scrolls the page two times faster than when this option is off.
  • Loading branch information
vedgy committed Aug 29, 2022
1 parent 85983aa commit 6375c05
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 10 additions & 9 deletions articlewebview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void ArticleWebView::mousePressEvent( QMouseEvent * event )

QWebView::mousePressEvent( event );

if ( selectionBySingleClick && ( event->buttons() & Qt::LeftButton ) )
if( selectionBySingleClick && ( event->buttons() & Qt::LeftButton ) && !isOnScrollBar( *event ) )
{
findText(""); // clear the selection first, if any
QMouseEvent ev( QEvent::MouseButtonDblClick, event->pos(), Qt::LeftButton, Qt::LeftButton, event->modifiers() );
Expand All @@ -109,16 +109,9 @@ void ArticleWebView::mouseDoubleClickEvent( QMouseEvent * event )
{
QWebView::mouseDoubleClickEvent( event );

int scrollBarWidth = page()->mainFrame()->scrollBarGeometry( Qt::Vertical ).width();
int scrollBarHeight = page()->mainFrame()->scrollBarGeometry( Qt::Horizontal ).height();

// emit the signal only if we are not double-clicking on scrollbars
if ( ( event->x() < width() - scrollBarWidth ) &&
( event->y() < height() - scrollBarHeight ) )
{
if( !isOnScrollBar( *event ) )
emit doubleClicked( event->pos() );
}

}

// TODO (Qt WebEngine): port if this code is useful in the Qt WebEngine version.
Expand Down Expand Up @@ -174,6 +167,14 @@ void ArticleWebView::wheelEvent( QWheelEvent *ev )

}

bool ArticleWebView::isOnScrollBar( QMouseEvent const & event ) const
{
int const scrollBarWidth = page()->mainFrame()->scrollBarGeometry( Qt::Vertical ).width();
int const scrollBarHeight = page()->mainFrame()->scrollBarGeometry( Qt::Horizontal ).height();

return event.x() >= width() - scrollBarWidth || event.y() >= height() - scrollBarHeight;
}

#else // USE_QTWEBKIT

#include <QChildEvent>
Expand Down
2 changes: 2 additions & 0 deletions articlewebview.hh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ protected:

private:

bool isOnScrollBar( QMouseEvent const & event ) const;

Config::Class * cfg;
ArticleInspector * inspector;

Expand Down

0 comments on commit 6375c05

Please sign in to comment.