[WK2][iOS] editorState() should not cause a synchronous layout
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Apr 2015 18:31:51 +0000 (18:31 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Apr 2015 18:31:51 +0000 (18:31 +0000)
commitedb172577bde6a75496be5838019f01abbf07de3
tree168b07c8fb6f020406343bd18e4edaa9f34ab5a8
parent8dbee4e4740aa415970e39514cdd8f4a39994d07
[WK2][iOS] editorState() should not cause a synchronous layout
https://bugs.webkit.org/show_bug.cgi?id=142536
<rdar://problem/20041506>

Reviewed by Enrica Casucci.

Source/WebCore:

Add didChangeSelectionAndUpdateLayout() callback to EditorClient
that is called at the end of FrameSelection::updateAndRevealSelection().

* editing/FrameSelection.cpp:
(WebCore::FrameSelection::updateAndRevealSelection):
* loader/EmptyClients.h:
* page/EditorClient.h:

Source/WebKit/mac:

Provide implementation for EditorClient::didChangeSelectionAndUpdateLayout().

* WebCoreSupport/WebEditorClient.h:

Source/WebKit/win:

Provide implementation for EditorClient::didChangeSelectionAndUpdateLayout().

* WebCoreSupport/WebEditorClient.h:

Source/WebKit2:

platformEditorState() on iOS does a synchronous layout to compute some
of the EditorState members (e.g. caretRectAtStart / caretRectAtEnd).
This is bad for performance as this is called every time the selection
is changed (which happens for e.g. when you set the value of a focused
HTMLInputElement).

This patch updates the behavior on iOS to only send a partial EditorState
on selection change so that the UIProcess gets most of the information
(the ones that do not require style recalc or layout) ASAP. A full Editor
state is then sent after the asynchronous layout is done.

With this change, I see a 38% improvement on Speedometer (26.4 +/- 0.37
-> 36.5 +/- 0.54) on iPhone 6 Plus.

* Shared/EditorState.cpp:
(WebKit::EditorState::encode):
(WebKit::EditorState::decode):
(WebKit::EditorState::PostLayoutData::encode):
(WebKit::EditorState::PostLayoutData::decode):
* Shared/EditorState.h:
(WebKit::EditorState::EditorState): Deleted.
* UIProcess/ios/WKContentView.mm:
(-[WKContentView _didCommitLayerTree:]):
* UIProcess/ios/WKContentViewInteraction.mm:
(WebKit::WKSelectionDrawingInfo::WKSelectionDrawingInfo):
(-[WKContentView webSelectionRects]):
(-[WKContentView _addShortcut:]):
(-[WKContentView selectedText]):
(-[WKContentView isReplaceAllowed]):
(-[WKContentView _promptForReplace:]):
(-[WKContentView _transliterateChinese:]):
(-[WKContentView textStylingAtPosition:inDirection:]):
(-[WKContentView canPerformAction:withSender:]):
(-[WKContentView _showDictionary:]):
(-[WKContentView _characterBeforeCaretSelection]):
(-[WKContentView _characterInRelationToCaretSelection:]):
(-[WKContentView _selectionAtDocumentStart]):
(-[WKContentView selectedTextRange]):
(-[WKContentView hasContent]):
* WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::didChangeSelectionAndUpdateLayout):
* WebProcess/WebCoreSupport/WebEditorClient.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::editorState):
(WebKit::WebPage::didChangeSelection):
(WebKit::WebPage::sendPostLayoutEditorStateIfNeeded):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/efl/WebPageEfl.cpp:
(WebKit::WebPage::platformEditorState):
* WebProcess/WebPage/gtk/WebPageGtk.cpp:
(WebKit::WebPage::platformEditorState):
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::platformEditorState):
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::platformEditorState):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@182603 268f45cc-cd09-0410-ab3c-d52691b4dbfc
21 files changed:
Source/WebCore/ChangeLog
Source/WebCore/editing/FrameSelection.cpp
Source/WebCore/loader/EmptyClients.h
Source/WebCore/page/EditorClient.h
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebCoreSupport/WebEditorClient.h
Source/WebKit/win/ChangeLog
Source/WebKit/win/WebCoreSupport/WebEditorClient.h
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/EditorState.cpp
Source/WebKit2/Shared/EditorState.h
Source/WebKit2/UIProcess/ios/WKContentView.mm
Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm
Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.h
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/efl/WebPageEfl.cpp
Source/WebKit2/WebProcess/WebPage/gtk/WebPageGtk.cpp
Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm
Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm