You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Attachment Support] Implement delegate hooks for attachment element insertion and removal
https://bugs.webkit.org/show_bug.cgi?id=179016
<rdar://problem/35250890>
Reviewed by Tim Horton.
Source/WebCore:
Implements a mechanism for notifying WebKit2 clients when attachment elements are inserted into or removed from
the document. See per-change comments below for more details.
API tests: WKAttachmentTests.AttachmentElementInsertion
WKAttachmentTests.AttachmentUpdatesWhenInsertingAndDeletingNewline
WKAttachmentTests.AttachmentUpdatesWhenUndoingAndRedoing
WKAttachmentTests.AttachmentUpdatesWhenChangingFontStyles
WKAttachmentTests.AttachmentUpdatesWhenInsertingLists
WKAttachmentTests.AttachmentUpdatesWhenInsertingRichMarkup
* editing/Editor.cpp:
(WebCore::Editor::respondToChangedSelection):
(WebCore::Editor::editorUIUpdateTimerFired):
Additionally notify the client of any attachment updates.
(WebCore::Editor::scheduleEditorUIUpdate):
Add a new helper that starts the editor UI update timer with 0 delay, and use it everywhere we schedule an
editor UI update.
(WebCore::Editor::didInsertAttachmentElement):
(WebCore::Editor::didRemoveAttachmentElement):
Maintain two sets of attachment element identifiers -- the first one tracking insertions, and the second one
tracking removals. When an attachment element is inserted, we first check to see if that attachment element has
just been removed; if so, we don't add it to the inserted identifiers set, but instead remove it from the set of
removed identifiers. We perform a similar check in the opposite case. This prevents us from notifying the client
of extraneous insertions and removals during certain editing commands which may reparent and move attachment
elements around. In both cases, we schedule an editor UI update afterwards, where we will notify the client of
attachment updates.
(WebCore::Editor::notifyClientOfAttachmentUpdates):
(WebCore::Editor::insertAttachmentFromFile):
* editing/Editor.h:
* html/HTMLAttachmentElement.cpp:
(WebCore::HTMLAttachmentElement::HTMLAttachmentElement):
Remove the version of HTMLAttachmentElement's constructor that takes a unique identifier.
(WebCore::HTMLAttachmentElement::insertedIntoAncestor):
(WebCore::HTMLAttachmentElement::removedFromAncestor):
Implement these hooks to observe insertion into and removal from the DOM. If the element was attached to or
removed from an ancestor that was connected to the document, call out to the document's frame's editor. This
"document-connected" rule prevents us from calling out to the client in cases where (for instance) we append an
attachment element to a newly created DocumentFragment in preparation for executing a ReplaceSelectionCommand.
(WebCore::HTMLAttachmentElement::uniqueIdentifier const):
(WebCore::HTMLAttachmentElement::setUniqueIdentifier):
Refactor unique identifier to refer to the new attachment identifier attribute instead of a member variable.
* html/HTMLAttachmentElement.h:
* html/HTMLAttributeNames.in:
Add a new attribute representing an attachment element's identifier. This enables us to keep track of particular
attachments as they are destroyed and recreated as different objects, as a result of some editing commands.
* page/EditorClient.h:
(WebCore::EditorClient::didInsertAttachment):
(WebCore::EditorClient::didRemoveAttachment):
Add boilerplate editor client hooks for attachment insertion and removal.
Source/WebKit:
Adds boilerplate plumbing to WebEditorClient, WebPage, and the usual machinery in the UI process to notify
WebKit2 clients when attachment elements have been inserted or removed from the document. See the WebCore
ChangeLog for more details about the implementation, or the Tools ChangeLog for more information about new API
tests.
* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _didInsertAttachment:]):
(-[WKWebView _didRemoveAttachment:]):
* UIProcess/API/Cocoa/WKWebViewInternal.h:
* UIProcess/Cocoa/PageClientImplCocoa.h:
* UIProcess/Cocoa/PageClientImplCocoa.mm:
(WebKit::PageClientImplCocoa::didInsertAttachment):
(WebKit::PageClientImplCocoa::didRemoveAttachment):
* UIProcess/PageClient.h:
(WebKit::PageClient::didInsertAttachment):
(WebKit::PageClient::didRemoveAttachment):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::didInsertAttachment):
(WebKit::WebPageProxy::didRemoveAttachment):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::didInsertAttachment):
(WebKit::WebEditorClient::didRemoveAttachment):
* WebProcess/WebCoreSupport/WebEditorClient.h:
Tools:
Introduces new API tests to check that various editing operations will or won't result in the new attachment
insertion and removal delegate hooks being fired. Additionally refactors an existing test to verify that
attachments insertion and removal is observable by the UI delegate.
* TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
(-[AttachmentUpdateObserver init]):
(-[AttachmentUpdateObserver inserted]):
(-[AttachmentUpdateObserver removed]):
(-[AttachmentUpdateObserver _webView:didInsertAttachment:]):
(-[AttachmentUpdateObserver _webView:didRemoveAttachment:]):
(TestWebKitAPI::ObserveAttachmentUpdatesForScope::ObserveAttachmentUpdatesForScope):
(TestWebKitAPI::ObserveAttachmentUpdatesForScope::~ObserveAttachmentUpdatesForScope):
(TestWebKitAPI::ObserveAttachmentUpdatesForScope::expectAttachmentUpdates):
Implement a testing mechanism to temporarily bind a UI delegate to a given WKWebView and listen for inserted or
removed attachments over the course of a particular scope. The API tests use this mechanism to check that the UI
delegate hooks added in this patch are invoked with the right attachments when performing edit commands.
(-[TestWKWebView _synchronouslyExecuteEditCommand:argument:]):
(-[TestWKWebView expectUpdatesAfterCommand:withArgument:expectedRemovals:expectedInsertions:]):
(TestWebKitAPI::TEST):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@224512 268f45cc-cd09-0410-ab3c-d52691b4dbfc
0 commit comments