Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hold the Scroll to the Text Fragment until a user scroll happens. #4371

Conversation

megangardner
Copy link
Contributor

@megangardner megangardner commented Sep 15, 2022

4dc689b

Hold the Scroll to the Text Fragment until a user scroll happens.
https://bugs.webkit.org/show_bug.cgi?id=245207
rdar://99668200

Reviewed by Tim Horton.

For each layout that comes in until the user scrolls we need to reset
the scroll to keep the fragment in the middle of the page.
Otherwise, more content can come in the scroll the fragment off the
page, which can be very confusing to the user.

* Source/WebCore/page/FrameView.cpp:
(WebCore::FrameView::reset):
(WebCore::FrameView::scrollToFragment):
(WebCore::FrameView::maintainScrollPositionAtRange):
(WebCore::FrameView::textFragmentIndicatorTimerFired):
(WebCore::FrameView::cancelScheduledTextFragmentIndicatorTimer):
(WebCore::FrameView::scrollToRange):
(WebCore::FrameView::performPostLayoutTasks):
* Source/WebCore/page/FrameView.h:

Canonical link: https://commits.webkit.org/254507@main

7efddec

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios   πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  πŸ§ͺ win
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim   πŸ›  mac-debug βœ… πŸ›  gtk βœ… πŸ›  wincairo
βœ… πŸ§ͺ webkitperl   πŸ§ͺ ios-wk2   πŸ›  mac-AS-debug βœ… πŸ§ͺ gtk-wk2
βœ… πŸ§ͺ api-ios   πŸ§ͺ api-mac βœ… πŸ§ͺ api-gtk
βœ… πŸ›  tv   πŸ§ͺ mac-wk1
βœ… πŸ›  tv-sim   πŸ§ͺ mac-wk2
βœ… πŸ›  πŸ§ͺ merge βœ… πŸ›  watch   πŸ§ͺ mac-AS-debug-wk2
βœ… πŸ›  watch-sim   πŸ§ͺ mac-wk2-stress

@megangardner megangardner self-assigned this Sep 15, 2022
@megangardner megangardner added DOM For bugs specific to XML/HTML DOM elements (including parsing). WebKit Nightly Build labels Sep 15, 2022
@megangardner megangardner force-pushed the eng/Hold-the-Scroll-to-the-Text-Fragment-until-a-user-scroll-happens- branch from 8325577 to 62c50f1 Compare September 15, 2022 00:37
@@ -2321,6 +2322,19 @@ void FrameView::maintainScrollPositionAtAnchor(ContainerNode* anchorNode)
scrollToAnchor();
}

void FrameView::maintainScrollPositionAtRange(SimpleRange* range)
{
UNUSED_PARAM(range);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get rid of this, since you clearly use it.

m_pendingTextFragmentIndicatorRange.reset();
m_pendingTextFragmentIndicatorText = String();
m_delayedTextFragmentIndicatorTimer.stop();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

@@ -3531,6 +3547,30 @@ void FrameView::scrollToAnchor()
cancelScheduledScrolls();
}

void FrameView::scrollToRange()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a super vague name. Can we call it "scrollToTextFragment"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(or scrollToTextFragmentRange, or something)

@@ -472,6 +472,7 @@ class FrameView final : public ScrollView {

bool scrollToFragment(const URL&);
void maintainScrollPositionAtAnchor(ContainerNode*);
void maintainScrollPositionAtRange(SimpleRange*);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto here, not just "range" but more importantly "text fragment"

@@ -911,6 +913,7 @@ class FrameView final : public ScrollView {
RefPtr<Node> m_nodeToDraw;
std::optional<SimpleRange> m_pendingTextFragmentIndicatorRange;
String m_pendingTextFragmentIndicatorText;
bool m_doNotResetFragmentTimer { false };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this isn't just about the timer. It's "should incoming scrolling cancel maintaining scroll-to-text-fragment position". Try to make a better name. It's hard to compress down.

@megangardner megangardner force-pushed the eng/Hold-the-Scroll-to-the-Text-Fragment-until-a-user-scroll-happens- branch from 62c50f1 to a33c32b Compare September 15, 2022 04:46
@@ -2321,6 +2322,18 @@ void FrameView::maintainScrollPositionAtAnchor(ContainerNode* anchorNode)
scrollToAnchor();
}

void FrameView::maintainScrollPositionAtScrollToTextFragmentRange(SimpleRange* range)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't this take a reference?

{
LOG(Scrolling, "FrameView::maintainScrollPositionAtScrollToTextFragmentRange at %p", range);

m_pendingTextFragmentIndicatorRange = *range;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since clearly it must be nonnull

@@ -2509,6 +2521,8 @@ void FrameView::textFragmentIndicatorTimerFired()

void FrameView::cancelScheduledTextFragmentIndicatorTimer()
{
if (m_skipScrollResetofScrollToTextFragementRange)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your camel casing fell apart in the middle

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also your spelling of fragment

ASSERT(frame().document());
Ref document = *frame().document();

SetForScope doNotResetFragmentTimer(m_skipScrollResetofScrollToTextFragementRange, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The local name should be fixed up too

@megangardner megangardner force-pushed the eng/Hold-the-Scroll-to-the-Text-Fragment-until-a-user-scroll-happens- branch from a33c32b to 7efddec Compare September 15, 2022 06:20
@megangardner megangardner added the merge-queue Applied to send a pull request to merge-queue label Sep 15, 2022
https://bugs.webkit.org/show_bug.cgi?id=245207
rdar://99668200

Reviewed by Tim Horton.

For each layout that comes in until the user scrolls we need to reset
the scroll to keep the fragment in the middle of the page.
Otherwise, more content can come in the scroll the fragment off the
page, which can be very confusing to the user.

* Source/WebCore/page/FrameView.cpp:
(WebCore::FrameView::reset):
(WebCore::FrameView::scrollToFragment):
(WebCore::FrameView::maintainScrollPositionAtRange):
(WebCore::FrameView::textFragmentIndicatorTimerFired):
(WebCore::FrameView::cancelScheduledTextFragmentIndicatorTimer):
(WebCore::FrameView::scrollToRange):
(WebCore::FrameView::performPostLayoutTasks):
* Source/WebCore/page/FrameView.h:

Canonical link: https://commits.webkit.org/254507@main
@webkit-early-warning-system webkit-early-warning-system force-pushed the eng/Hold-the-Scroll-to-the-Text-Fragment-until-a-user-scroll-happens- branch from 7efddec to 4dc689b Compare September 15, 2022 08:05
@webkit-commit-queue
Copy link
Collaborator

Committed 254507@main (4dc689b): https://commits.webkit.org/254507@main

Reviewed commits have been landed. Closing PR #4371 and removing active labels.

@webkit-early-warning-system webkit-early-warning-system merged commit 4dc689b into WebKit:main Sep 15, 2022
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Sep 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DOM For bugs specific to XML/HTML DOM elements (including parsing).
Projects
None yet
4 participants