Improve the behavior of scroll-into-view when the target is inside position:fixed
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Dec 2016 20:00:28 +0000 (20:00 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Dec 2016 20:00:28 +0000 (20:00 +0000)
commit132db2b8a9fbf11269ac13368fec880dd1cf881a
tree5deed8ceb66d58be4bd92e140c9624549fcadd70
parentf5ea5947c42a011b194db6ed83977e0cb3c71d82
Improve the behavior of scroll-into-view when the target is inside position:fixed
https://bugs.webkit.org/show_bug.cgi?id=165354

Reviewed by Zalan Bujtas.
Source/WebCore:

The existing RenderLayer::scrollRectToVisible() code paid no heed to whether the
target was inside position:fixed, resulting in unwanted scrolls.

Fix this by plumbing through from the call sites a "insideFixed" flag which we get
when we call localToAbsolute(), and use this flag to avoid scrolling at all if
unzoomed.

If zoomed and we're focussing something inside position:fixed, and if visual viewports
are enabled, we can compute the visual viewport required to reveal the target rect,
which gives us the ideal scroll position.

Fix a bug on non-iOS platforms when zoomed, which is to scale the viewRect since
frameView.visibleContentRect() gives an unscaled rect on those platforms.

Not all callers of scrollRectToVisible() are fixed, but those that are not will get
the current behavior.

Tests: fast/overflow/scroll-anchor-in-position-fixed.html
       fast/visual-viewport/zoomed-scroll-into-view-fixed.html
       fast/visual-viewport/zoomed-scroll-to-anchor-in-position-fixed.html

* dom/Element.cpp:
(WebCore::Element::scrollIntoView):
(WebCore::Element::scrollIntoViewIfNeeded):
(WebCore::Element::scrollIntoViewIfNotVisible):
(WebCore::Element::updateFocusAppearance):
* editing/FrameSelection.cpp:
(WebCore::FrameSelection::FrameSelection):
(WebCore::FrameSelection::absoluteCaretBounds):
(WebCore::FrameSelection::recomputeCaretRect):
(WebCore::FrameSelection::revealSelection):
* editing/FrameSelection.h:
* editing/VisiblePosition.cpp:
(WebCore::VisiblePosition::absoluteCaretBounds):
* editing/VisiblePosition.h:
* editing/htmlediting.cpp:
(WebCore::absoluteBoundsForLocalCaretRect):
* editing/htmlediting.h:
* page/FrameView.cpp:
(WebCore::FrameView::scrollElementToRect):
(WebCore::FrameView::scrollToAnchor):
* page/PrintContext.cpp:
(WebCore::PrintContext::outputLinkedDestinations):
* rendering/RenderElement.cpp:
(WebCore::RenderElement::getLeadingCorner):
(WebCore::RenderElement::getTrailingCorner):
(WebCore::RenderElement::absoluteAnchorRect):
(WebCore::RenderElement::anchorRect): Deleted.
* rendering/RenderElement.h:
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::scrollRectToVisible):
(WebCore::RenderLayer::getRectToExpose):
(WebCore::RenderLayer::autoscroll):
* rendering/RenderLayer.h:
* rendering/RenderObject.cpp:
(WebCore::RenderObject::scrollRectToVisible):
* rendering/RenderObject.h:

Source/WebKit/mac:

Plumb through 'insideFixed'. We don't get compute it, so behavior from
these call sites won't change.

* WebView/WebFrame.mm:
(-[WebFrame _scrollDOMRangeToVisible:]):
(-[WebFrame _scrollDOMRangeToVisible:withInset:]):

LayoutTests:

* fast/overflow/scroll-anchor-in-position-fixed-expected.txt: Added.
* fast/overflow/scroll-anchor-in-position-fixed.html: Added.
* fast/transforms/selection-bounds-in-transformed-view.html:
* fast/visual-viewport/zoomed-scroll-into-view-fixed-expected.txt: Added.
* fast/visual-viewport/zoomed-scroll-into-view-fixed.html: Added.
* fast/visual-viewport/zoomed-scroll-to-anchor-in-position-fixed-expected.txt: Added.
* fast/visual-viewport/zoomed-scroll-to-anchor-in-position-fixed.html: Added.
* platform/ios-simulator/TestExpectations:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@209411 268f45cc-cd09-0410-ab3c-d52691b4dbfc
27 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/overflow/scroll-anchor-in-position-fixed-expected.txt [new file with mode: 0644]
LayoutTests/fast/overflow/scroll-anchor-in-position-fixed.html [new file with mode: 0644]
LayoutTests/fast/transforms/selection-bounds-in-transformed-view.html
LayoutTests/fast/visual-viewport/zoomed-scroll-into-view-fixed-expected.txt [new file with mode: 0644]
LayoutTests/fast/visual-viewport/zoomed-scroll-into-view-fixed.html [new file with mode: 0644]
LayoutTests/fast/visual-viewport/zoomed-scroll-to-anchor-in-position-fixed-expected.txt [new file with mode: 0644]
LayoutTests/fast/visual-viewport/zoomed-scroll-to-anchor-in-position-fixed.html [new file with mode: 0644]
LayoutTests/platform/ios-simulator/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/dom/Element.cpp
Source/WebCore/editing/FrameSelection.cpp
Source/WebCore/editing/FrameSelection.h
Source/WebCore/editing/VisiblePosition.cpp
Source/WebCore/editing/VisiblePosition.h
Source/WebCore/editing/htmlediting.cpp
Source/WebCore/editing/htmlediting.h
Source/WebCore/page/FrameView.cpp
Source/WebCore/page/PrintContext.cpp
Source/WebCore/rendering/RenderElement.cpp
Source/WebCore/rendering/RenderElement.h
Source/WebCore/rendering/RenderLayer.cpp
Source/WebCore/rendering/RenderLayer.h
Source/WebCore/rendering/RenderObject.cpp
Source/WebCore/rendering/RenderObject.h
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebFrame.mm