Bug 421159 - Scrolling by clicking the scroll bar is reset by scrolling with scroll wheel
Summary: Scrolling by clicking the scroll bar is reset by scrolling with scroll wheel
Status: RESOLVED FIXED
Alias: None
Product: okular
Classification: Applications
Component: general (show other bugs)
Version: 20.04.0
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Okular developers
URL:
Keywords:
: 425376 (view as bug list)
Depends on:
Blocks:
 
Reported: 2020-05-07 15:40 UTC by msessions21@gmail.com
Modified: 2020-11-06 17:37 UTC (History)
8 users (show)

See Also:
Latest Commit:
Version Fixed In: 1.11.3
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description msessions21@gmail.com 2020-05-07 15:40:11 UTC
SUMMARY
Scrolling by clicking the scroll bar is reset by scrolling with scroll wheel.

STEPS TO REPRODUCE
1. open a document in okular
2. click above or below scrollbar element
3. scroll with mouse wheel

OBSERVED RESULT
Position in document jumps to where it was before clicking the scroll bar upon scrolling with scroll wheel.

EXPECTED RESULT
Document should be scrolled relative to where it was after clicking the scroll bar.

SOFTWARE/OS VERSIONS

Operating System: Arch Linux 
KDE Plasma Version: 5.18.5
KDE Frameworks Version: 5.69.0
Qt Version: 5.14.2
Kernel Version: 5.4.38-1-lts
OS Type: 64-bit
Processors: 8 × Intel® Core™ i7-3770 CPU @ 3.40GHz
Memory: 31.3 GiB of RAM

ADDITIONAL INFORMATION
Scrolling works as expected in okular-19.12.3-3-x86_64
Comment 1 Albert Astals Cid 2020-05-09 21:36:07 UTC
I don't understand the problem, do you think you could record the screen a video/gif and maybe that would help me understand what you mean?
Comment 2 msessions21@gmail.com 2020-05-21 04:46:10 UTC
Here's a GIF recording of the bug

https://imgur.com/xou5cdA


SOFTWARE/OS VERSIONS

Operating System: Arch Linux 
KDE Plasma Version: 5.18.5
KDE Frameworks Version: 5.70.0
Qt Version: 5.14.2
Kernel Version: 5.4.41-1-lts
OS Type: 64-bit
Processors: 8 × Intel® Core™ i7-3770 CPU @ 3.40GHz
Memory: 31.3 GiB of RAM

okular 1.10.1
Comment 3 Albert Astals Cid 2020-05-21 21:26:49 UTC
I still can figure out what is wrong with the video, could you describe second by second what you are doing and what you're expecting it would happen?
Comment 4 msessions21@gmail.com 2020-05-21 22:21:44 UTC
Seconds 0-5, scrolling with scroll wheel works normally.
Seconds 5-12, clicking the scroll bar to scroll works as expected until trying to scroll with the scroll wheel. Meaning that scrolling with the scroll wheel after having clicked the scroll bar causes the reader (Okular) to jump back to the position in the document before I clicked on the scroll bar.

After that in the video is a repeat of Seconds 0-12, but I clicked the scroll bar to scroll down. and then up a bit, and ends by scrolling the scroll wheel which still causes the document position to jump to where it was before.
Comment 5 Christoph Feck 2020-05-22 20:53:30 UTC
New information was added with comment 4; changing status for inspection.
Comment 6 Albert Astals Cid 2020-05-24 17:42:21 UTC
Ok, now i understood:
 * Start in page 1
 * Left click on the scrollbar below the slider it self until some pages change and say you're now in page 10
 * use the wheel in the viewport (not the scrollbar), you're back to page 1
Comment 7 Albert Astals Cid 2020-05-24 17:43:53 UTC
Another regression caused by the QScroller patches.
Comment 8 Oliver Sander 2020-06-03 06:22:13 UTC
I tried to write a unit test for this, but I failed to find a way to send wheel events to the PageView object.  This seems to be a known problem:

   https://stackoverflow.com/questions/50996997/how-to-simulate-mouse-wheel-events-using-qtestlib-qt5

I see TabletEvents being sent in parttest.cpp by calls to

    qApp->notify( qApp, &enterProximityEvent );

but that doesn't seem to work for wheel events.

Is there a secret trick to it, or do we have to live without a test?
Comment 9 Laura David Hurka 2020-06-03 12:17:47 UTC
(In reply to Oliver Sander from comment #8)
> but I failed to find a way to send wheel events to the PageView object.

xdotool should work. But that would depend on the test environment. If only the GitLab CI can run this test, would that be enough? (Does GitLab run the autotests?)
Comment 10 Oliver Sander 2020-06-03 12:32:04 UTC
Thanks, I hadn't heard of of xdotool.  But I need something that works from within the QTest framework.  And yes, gitlab does run the autotests.
Comment 11 Albert Astals Cid 2020-06-03 21:57:42 UTC
This makes the pageview scroll

void PartTest::testWheelInPageView()
{
    QVariantList dummyArgs;
    Okular::Part part(nullptr, nullptr, dummyArgs);
    QVERIFY(openDocument(&part, QStringLiteral(KDESRCDIR "data/file2.pdf")));
    part.widget()->resize(600, 400);
    part.widget()->show();
    QVERIFY(QTest::qWaitForWindowExposed(part.widget()));
    QTest::qWait(3000);
    auto we = new QWheelEvent({}, {}, {}, {0, -150}, Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false);
    QCoreApplication::postEvent(part.m_pageView->viewport(), we);
    QTest::qWait(3000);
}



The QWheelEvent definition is a bit "bogus" in which it doesn't define pos nor globalPos, just abuses the knowledge that PageView::wheelEvent just uses the angleDelta().y()
Comment 12 Oliver Sander 2020-06-04 18:17:42 UTC
Thank you!  There is a now a test at

  https://invent.kde.org/graphics/okular/merge_requests/188
Comment 13 popov895 2020-06-08 14:41:29 UTC
This behavior also occurs when scrolling a document while the mouse cursor is over the scrollbar (both horizontal and vertical). Tested on pdf files, text files and images.
Comment 14 Bug Janitor Service 2020-10-12 11:31:58 UTC
A possibly relevant merge request was started @ https://invent.kde.org/graphics/okular/-/merge_requests/292
Comment 15 Laura David Hurka 2020-10-13 16:04:38 UTC
Git commit 17c266993deda05713171f824669cb4e09a6ee65 by David Hurka.
Committed on 12/10/2020 at 11:16.
Pushed by ngraham into branch 'release/20.08'.

Fix scrolling with scrollbar when the slider is not clicked

This fixes scrolling with the scrollbar,
so it is not reset when scrolling on the viewport afterwards.

PageView’s QSroller was not correctly updated by update_scroller,
because it was connected to QAbstractSlider::sliderMoved and sliderReleased,
which are only emitted while the “slider is down”,
i. e. not when the user scrolls the scrollbar other than dragging the slider.
Now update_scroller is connected to actionTriggered(),
which is emitted for all user interactions.

Note that scrolling using the scrollbar calls QAbstractScrollArea::scrollContentsBy(),
and so bypasses smooth scrolling of the QScroller. This could be considered a feature,
otherwise it is more a bug in Qt than in Okular, because we can not ignore scrollContentsBy().

Steps to reproduce:
1. Open a long document
2. Click on the vertical scrollbar below the slider
3. Okular scrolls one page down
4. Scroll in the viewport
5. Okular starts scrolling from the position from step 1.

Test plan:
* Scroll using scrollbar
  + Click on the vertical scrollbar below the slider
  + Middle-click on the vertical scrollbar below the slider
  + Click on the little arrow of the vertical scrollbar
  + Scroll using a scrolling device (e. g. `xdotool click 4`) on the vertical scrollbar
  + Drag the slider of the scrollbar
* “cross-product” verify QScroller state
  + Scroll using a scrolling device on the viewport
  + Scroll using Browse tool dragging
  + Scroll the viewport by clicking a point in the thumbnails view
  + Scroll the viewport using arrow keys and Page Up/Down keys

M  +7    -4    ui/pageview.cpp

https://invent.kde.org/graphics/okular/commit/17c266993deda05713171f824669cb4e09a6ee65
Comment 16 Laura David Hurka 2020-11-06 17:37:34 UTC
*** Bug 425376 has been marked as a duplicate of this bug. ***