Focus event dispatched in iframe causes parent document to scroll incorrectly
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 Jun 2016 21:22:54 +0000 (21:22 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 Jun 2016 21:22:54 +0000 (21:22 +0000)
commit83ad9778b6e6099f35e76f63dd8acc234160e787
treea161c3338886b8af2bd9c057bffac28704083905
parent3c09fcbcfdfe82bfda2fe903379b7489403affca
Focus event dispatched in iframe causes parent document to scroll incorrectly
https://bugs.webkit.org/show_bug.cgi?id=158629
rdar://problem/26521616

Reviewed by Tim Horton.
Source/WebCore:

When focussing elements in iframes, the page could scroll to an incorrect location.
This happened because code in Element::focus() tried to disable scrolling on focus,
but did so only for the current frame, so ancestor frames got programmatically scrolled.
On iOS we handle the scrolling in the UI process, so never want the web process to
do programmatic scrolling.

Fix by changing the focus and cache restore code to use SelectionRevealMode::DoNotReveal,
rather than manually prohibiting frame scrolling. Pass SelectionRevealMode through various callers,
and use RevealUpToMainFrame for iOS, allowing the UI process to do the zoomToRect: for the main frame.

Tests: fast/forms/ios/focus-input-in-iframe.html
       fast/forms/ios/programmatic-focus-input-in-iframe.html

* dom/Document.h:
* dom/Element.cpp:
(WebCore::Element::scrollIntoView):
(WebCore::Element::scrollIntoViewIfNeeded):
(WebCore::Element::scrollIntoViewIfNotVisible):
(WebCore::Element::focus):
(WebCore::Element::updateFocusAppearance):
* dom/Element.h:
* editing/Editor.cpp:
(WebCore::Editor::insertTextWithoutSendingTextEvent):
(WebCore::Editor::revealSelectionAfterEditingOperation):
(WebCore::Editor::findStringAndScrollToVisible):
* editing/FrameSelection.cpp:
(WebCore::FrameSelection::updateAndRevealSelection):
(WebCore::FrameSelection::revealSelection):
(WebCore::FrameSelection::FrameSelection): Deleted.
* editing/FrameSelection.h:
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::updateFocusAppearance):
* html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::updateFocusAppearance):
* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::contextMenuItemSelected):
* page/FrameView.cpp:
(WebCore::FrameView::scrollToAnchor):
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::scrollRectToVisible):
(WebCore::RenderLayer::autoscroll):
* rendering/RenderLayer.h:
* rendering/RenderObject.cpp:
(WebCore::RenderObject::scrollRectToVisible):
* rendering/RenderObject.h:

Source/WebKit/mac:

Pass SelectionRevealMode::Reveal in existing code.

* WebView/WebFrame.mm:
(-[WebFrame _scrollDOMRangeToVisible:]):
(-[WebFrame _scrollDOMRangeToVisible:withInset:]):
(-[WebFrame revealSelectionAtExtent:]):
* WebView/WebHTMLView.mm:
(-[WebHTMLView jumpToSelection:]):
(-[WebHTMLView centerSelectionInVisibleArea:]):

Source/WebKit2:

Pass SelectionRevealMode::Reveal in existing code.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::centerSelectionInVisibleArea):

LayoutTests:

* fast/forms/ios/focus-input-in-iframe-expected.txt: Added.
* fast/forms/ios/focus-input-in-iframe.html: Added.
* fast/forms/ios/programmatic-focus-input-in-iframe-expected.txt: Added.
* fast/forms/ios/programmatic-focus-input-in-iframe.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202243 268f45cc-cd09-0410-ab3c-d52691b4dbfc
25 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/forms/ios/focus-input-in-iframe-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/ios/focus-input-in-iframe.html [new file with mode: 0644]
LayoutTests/fast/forms/ios/programmatic-focus-input-in-iframe-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/ios/programmatic-focus-input-in-iframe.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.h
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/Element.h
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/FrameSelection.cpp
Source/WebCore/editing/FrameSelection.h
Source/WebCore/html/HTMLInputElement.cpp
Source/WebCore/html/HTMLTextAreaElement.cpp
Source/WebCore/page/ContextMenuController.cpp
Source/WebCore/page/FrameView.cpp
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
Source/WebKit/mac/WebView/WebHTMLView.mm
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebPage/WebPage.cpp