[WK2] EditorState updates should be rolled into the layer update lifecycle when possible
https://bugs.webkit.org/show_bug.cgi?id=175370
<rdar://problem/33799806>

Reviewed by Ryosuke Niwa.

Source/WebCore:

Remove didChangeSelectionAndUpdateLayout -- EditorState updates that are scheduled due to missing post-layout
data will now be scheduled for the next presentation update. Additionally, add editor client hooks to notify the
WebKit layer when we've updated the current composition. See WebKit ChangeLog for more details. This patch
adjusts and rebaselines existing layout tests.

* editing/Editor.cpp:
(WebCore::SetCompositionScope::SetCompositionScope):
(WebCore::SetCompositionScope::~SetCompositionScope):

Introduce a helper RAII class to ensure that we ignore selection changes during the scope of
Editor::setComposition and call out to the client with WebEditorClient::didUpdateComposition afterwards. This
also maintains a UserTypingGestureIndicator over its lifetime, so we don't additionally need to create a
UserTypingGestureIndicator in Editor::setComposition.

(WebCore::Editor::setComposition):
* editing/FrameSelection.cpp:
(WebCore::FrameSelection::setSelection):
(WebCore::FrameSelection::updateAndRevealSelection):
(WebCore::FrameSelection::setSelectedRange):
* editing/FrameSelection.h:
(WebCore::FrameSelection::defaultSetSelectionOptions):

Plumb state about whether or not the selection change was triggered by the user to FrameSelection::setSelection,
and if so, notify the editing client. A separate SetSelectionOptions flag is used here instead of
RevealSelection to avoid calling out to the client in places where we want to reveal the selection regardless of
whether or not the selection is user triggered.

* loader/EmptyClients.cpp:
* page/EditorClient.h:

Source/WebKit:

See per-method comments for more detail. WebPage::didChangeSelection now schedules EditorState updates to be sent
during the next layer tree transaction rather than sending them synchronously. To ensure that iOS and Mac continue
to behave correctly w.r.t. EditorState updates, we immediately dispatch EditorStates in the following cases:
- After the composition changes, is confirmed, or is canceled.
- After an edit command is executed.
- After ending user-triggered selection changes.

* Shared/mac/RemoteLayerTreeTransaction.h:
(WebKit::RemoteLayerTreeTransaction::hasEditorState const):
(WebKit::RemoteLayerTreeTransaction::editorState const):
(WebKit::RemoteLayerTreeTransaction::setEditorState):

Attaches an optional EditorState to the RemoteLayerTreeTransaction. This EditorState is computed and sent over
when setting up the transaction in WebPage, if something previously scheduled an EditorState update.

* Shared/mac/RemoteLayerTreeTransaction.mm:
(WebKit::RemoteLayerTreeTransaction::encode const):
(WebKit::RemoteLayerTreeTransaction::decode):

Add coder support for sending over a layer tree transaction's EditorState.

* UIProcess/API/Cocoa/WKViewPrivate.h:
* UIProcess/API/mac/WKView.mm:
(-[WKView _doAfterNextPresentationUpdate:]):

Add _doAfterNextPresentationUpdate to WKView (used in TestWebKitAPI -- refer to
WebKitAgnosticTest::waitForNextPresentationUpdate).

* UIProcess/DrawingAreaProxy.h:
(WebKit::DrawingAreaProxy::dispatchPresentationCallbacksAfterFlushingLayers):
* UIProcess/DrawingAreaProxy.messages.in:

Add a new IPC messages, DispatchPresentationCallbacksAfterFlushingLayers, to invoke in-flight presentation
callbacks in the UI process following a layer flush in the web process.

* UIProcess/WebPageProxy.h:
* UIProcess/mac/RemoteLayerTreeDrawingAreaProxy.mm:
(WebKit::RemoteLayerTreeDrawingAreaProxy::commitLayerTree):
* UIProcess/mac/TiledCoreAnimationDrawingAreaProxy.h:
* UIProcess/mac/TiledCoreAnimationDrawingAreaProxy.mm:
(WebKit::TiledCoreAnimationDrawingAreaProxy::~TiledCoreAnimationDrawingAreaProxy):
(WebKit::TiledCoreAnimationDrawingAreaProxy::dispatchAfterEnsuringDrawing):
(WebKit::TiledCoreAnimationDrawingAreaProxy::dispatchPresentationCallbacksAfterFlushingLayers):

Run all pending _doAfterNextPresentationUpdate callbacks.

* WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::didApplyStyle):
(WebKit::WebEditorClient::respondToChangedContents):
(WebKit::WebEditorClient::didEndUserTriggeredSelectionChanges):
(WebKit::WebEditorClient::didUpdateComposition):

Forward editor client calls to the WebPage.

(WebKit::WebEditorClient::didChangeSelectionAndUpdateLayout): Deleted.
* WebProcess/WebCoreSupport/WebEditorClient.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::editorState const):
(WebKit::WebPage::updateEditorStateAfterLayoutIfEditabilityChanged):
(WebKit::WebPage::willCommitLayerTree):
(WebKit::WebPage::didApplyStyle):

Allow style application to immediately trigger EditorState updates, if we're not currently ignoring selection
changes in the Editor.

(WebKit::WebPage::didChangeContents):

Allow applying top-level edit commands to immediately trigger EditorState updates, if we're not currently
ignoring selection changes in the Editor.

(WebKit::WebPage::didChangeSelection):
(WebKit::WebPage::didUpdateComposition):
(WebKit::WebPage::didEndUserTriggeredSelectionChanges):
(WebKit::WebPage::discardedComposition):
(WebKit::WebPage::canceledComposition):

When handling composition updates, always send an EditorState to the UI process. Unlike other cases, IME
requires immediate EditorState data, so we need to be explicit here in sending updates right away.

(WebKit::WebPage::sendEditorStateUpdate):
(WebKit::WebPage::sendPartialEditorStateAndSchedulePostLayoutUpdate):
(WebKit::WebPage::flushPendingEditorStateUpdate):

Helper methods to schedule an EditorState update to be sent upon the next layer tree update, or flush any
pending EditorState update that has been scheduled. The private, more aggressive variant of this is
sendEditorStateUpdate, which ignores whether or not there was already an EditorState update scheduled, and sends
one anyways (this still fulfills any EditorState update that was previously scheduled).

These helper methods are treated as no-ops when invoked while ignoring selection changes. This is to prevent
temporary selection state and editor commands during operations such as text indicator snapshotting from pushing
bogus information about transient editor states to the UI process.

(WebKit::WebPage::sendPostLayoutEditorStateIfNeeded): Deleted.
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::platformEditorState const):
(WebKit::WebPage::executeEditCommandWithCallback):
(WebKit::selectionIsInsideFixedPositionContainer):
(WebKit::WebPage::updateVisibleContentRects):

Fix a hack that was computing an EditorState to figure out whether the current selection starts or ends in a
fixed position container. Factors out relevant logic into a separate helper, and also schedules an EditorState
update instead of immediately computing it.

* WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.h:
* WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm:
(WebKit::TiledCoreAnimationDrawingArea::addTransactionCallbackID):

Add support for registering and dispatching presentation callbacks that hook into the layer flush lifecycle,
using the tiled CA drawing area. These are used by Mac LayoutTests and API tests that need to wait until the
next flush before checking for state that depends on EditorState updates in the UI process.

(WebKit::TiledCoreAnimationDrawingArea::flushLayers):

Tell the WebPage to flush any pending EditorState updates.

* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::platformEditorState const):

Source/WebKitLegacy/mac:

Adjust WebEditorClient for interface changes.

* WebCoreSupport/WebEditorClient.h:

Source/WebKitLegacy/win:

Adjust WebEditorClient for interface changes.

* WebCoreSupport/WebEditorClient.h:

Tools:

Tweaks API tests that involve editing to wait for a presentation update before checking against UI process-side
information sent via EditorState updates. This allows any EditorState update scheduled by the test to propagate
to the UI process.

* TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewCandidateTests.mm:
(-[CandidateTestWebView typeString:inputMessage:]):
(+[CandidateTestWebView setUpWithFrame:testPage:]):
* TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewTextInput.mm:
* TestWebKitAPI/Tests/mac/AcceptsFirstMouse.mm:
(TestWebKitAPI::AcceptsFirstMouse::runTest):
* TestWebKitAPI/Tests/mac/WKWebViewMacEditingTests.mm:
* TestWebKitAPI/cocoa/TestWKWebView.h:
* TestWebKitAPI/cocoa/TestWKWebView.mm:
(-[TestWKWebView waitForNextPresentationUpdate]):

Add a new helper method to spin until the next presentation update.

* TestWebKitAPI/mac/WebKitAgnosticTest.h:
* TestWebKitAPI/mac/WebKitAgnosticTest.mm:
(TestWebKitAPI::WebKitAgnosticTest::waitForNextPresentationUpdate):

LayoutTests:

Rebaseline and adjust LayoutTests.

* editing/caret/ios/absolute-caret-position-after-scroll-expected.txt:
* editing/caret/ios/absolute-caret-position-after-scroll.html:
* editing/caret/ios/fixed-caret-position-after-scroll-expected.txt:
* editing/caret/ios/fixed-caret-position-after-scroll.html:
* editing/secure-input/password-input-changed-type.html:
* editing/secure-input/password-input-focusing.html:
* editing/secure-input/removed-password-input.html:
* editing/secure-input/reset-state-on-navigation.html:
* editing/selection/character-granularity-rect.html:

Delay checking for secure input state and caret rects until after the next presentation update.

* editing/selection/ios/absolute-selection-after-scroll-expected.txt:
* editing/selection/ios/absolute-selection-after-scroll.html:
* editing/selection/ios/fixed-selection-after-scroll-expected.txt:
* editing/selection/ios/fixed-selection-after-scroll.html:

Refactor and simplify these tests. These tests are not run on the OpenSource bots, since they depend on long
press and tap gestures.

* platform/ios-wk2/editing/inserting/insert-div-024-expected.txt:
* platform/ios-wk2/editing/inserting/insert-div-026-expected.txt:
* platform/ios-wk2/editing/style/5084241-expected.txt:

Rebaselines these tests, removing an anonymous RenderBlock inserted as a result of inserting and removing a
dummy span in order to compute a RenderStyle in WebPage::editorState. This is because editorState is no longer
invoked immediately on page load; https://bugs.webkit.org/show_bug.cgi?id=175116 tracks preventing this render
tree thrashing altogether.

* platform/mac-wk2/TestExpectations:
* platform/mac-wk2/editing/style/unbold-in-bold-expected.txt:
* resources/ui-helper.js:

Introduce new UIHelper functions.

(window.UIHelper.ensurePresentationUpdate.return.new.Promise):
(window.UIHelper.ensurePresentationUpdate):

Returns a Promise, resolved after the next presentation update.

(window.UIHelper.activateAndWaitForInputSessionAt.return.new.Promise.):
(window.UIHelper.activateAndWaitForInputSessionAt.return.new.Promise):
(window.UIHelper.activateAndWaitForInputSessionAt):

Returns a Promise, resolved after tapping at the given location and waiting for the keyboard to appear on iOS.

(window.UIHelper.getUICaretRect.return.new.Promise.):
(window.UIHelper.getUICaretRect.return.new.Promise):
(window.UIHelper.getUICaretRect):
(window.UIHelper.getUISelectionRects.return.new.Promise.):
(window.UIHelper.getUISelectionRects.return.new.Promise):
(window.UIHelper.getUISelectionRects):

Helpers to fetch selection and caret rect information in the UI process.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@221064 268f45cc-cd09-0410-ab3c-d52691b4dbfc
57 files changed
tree: ee31dea3ee9397a53124ef02767114276e3f1743
  1. Examples/
  2. JSTests/
  3. LayoutTests/
  4. ManualTests/
  5. PerformanceTests/
  6. Source/
  7. Tools/
  8. WebKit.xcworkspace/
  9. WebKitLibraries/
  10. Websites/
  11. .dir-locals.el
  12. .gitattributes
  13. .gitignore
  14. ChangeLog
  15. ChangeLog-2012-05-22
  16. CMakeLists.txt
  17. Makefile
  18. Makefile.shared
  19. ReadMe.md
ReadMe.md

WebKit

WebKit is a cross-platform web browser engine. On iOS and macOS, it powers Safari, Mail, iBooks, and many other applications.

Feature Status

Visit WebKit Feature Status page to see which Web API has been implemented, in development, or under consideration.

Trying the Latest

Downloading Safari Technology Preview to test the latest version of WebKit.

Reporting Bugs

  1. Search WebKit Bugzilla to see if there is an existing report for the bug you've encountered.
  2. Create a Bugzilla account to to report bugs (and to comment on them) if you haven't done so already.
  3. File a bug in accordance with our guidelines.

Once your bug is filed, you will receive email when it is updated at each stage in the bug life cycle. After the bug is considered fixed, you may be asked to download the latest nightly and confirm that the fix works for you.

Getting the Code

On Windows, follow the instructions on our website.

Cloning the Git SVN Repository

Run the following command to clone WebKit's Git SVN repository:

git clone git://git.webkit.org/WebKit.git WebKit

If you want to be able to commit changes to the repository, or just want to check out branches that aren’t contained in WebKit.git, you will need track WebKit's Subversion repository. You can run the following command to configure this and other options of the new Git clone for WebKit development.

Tools/Scripts/webkit-patch setup-git-clone

For information about this, and other aspects of using Git with WebKit, read the wiki page.

Checking out the Subversion Repository

Run the following command to check out WebKit's subversion repository:

svn checkout https://svn.webkit.org/repository/webkit/trunk WebKit

Building WebKit

Building Mac Port

Install Xcode and its command line tools if you haven't done so already:

  1. Install Xcode Get Xcode from https://developer.apple.com/downloads. To build WebKit for OS X, Xcode 5.1.1 or later is required. To build WebKit for iOS Simulator, Xcode 7 or later is required.
  2. Install the Xcode Command Line Tools In Terminal, run the command: xcode-select --install

Run the following command to build a debug build with debugging symbols and assertions:

Tools/Scripts/build-webkit --debug

For performance testing, and other purposes, use --release instead.

Using Xcode

You can open WebKit.xcworkspace to build and debug WebKit within WebKit.

If you don't use a custom build location in Xcode preferences, you have to update the workspace settings to use WebKitBuild directory. In menu bar, choose File > Workspace Settings, then click the Advanced button, select “Custom”, “Relative to Workspace”, and enter WebKitBuild for both Products and Intermediates.

Building iOS Port

The first time after you install a new Xcode, you will need to run the following command to enable Xcode to build command line tools for iOS Simulator:

 sudo Tools/Scripts/configure-xcode-for-ios-development

Without this step, you will see the error message: “target specifies product type ‘com.apple.product-type.tool’, but there’s no such product type for the ‘iphonesimulator’ platform.” when building target JSCLLIntOffsetsExtractor of project JavaScriptCore.

Run the following command to build a debug build with debugging symbols and assertions for iOS:

Tools/Scripts/build-webkit --debug --ios-simulator.

Building GTK+ Port

Install the dependencies by running the following command:

Tools/gtk/install-dependencies

Then run the following command to build additional dependencies:

Tools/Scripts/update-webkitgtk-libs

Run the following command to build WebKit with debugging symbols for GTK+ port:

Tools/Scripts/build-webkit --debug --gtk

Note that the procedure for building a release tarball is different. For more information, see the wiki page.

Building Windows Port

For building WebKit on Windows, see the wiki page.

Running WebKit

With Safari and Other macOS Applications

Run the following command to launch Safari with your local build of WebKit:

Tools/Scripts/run-safari --debug

The run-safari script sets the DYLD_FRAMEWORK_PATH environment variable to point to your build products, and then launches /Applications/Safari.app. DYLD_FRAMEWORK_PATH tells the system loader to prefer your build products over the frameworks installed in /System/Library/Frameworks.

To run other applications with your local build of WebKit, run the following command:

Tools/Scripts/run-webkit-app <application-path>

iOS Simulator

Run the following command to launch iOS simulator with your local build of WebKit:

run-safari --debug --ios-simulator

In both cases, if you have built release builds instead, use --release instead of --debug.

Contribute

Congratulations! You’re up and running. Now you can begin coding in WebKit and contribute your fixes and new features to the project. For details on submitting your code to the project, read Contributing Code.