[iOS WK2] WKWebView schedules nonstop layout after pressing cmb+b,i,u inside a contenteditable div
https://bugs.webkit.org/show_bug.cgi?id=175116
<rdar://problem/28279301>
Reviewed by Darin Adler and Ryosuke Niwa.
Source/WebCore:
WebCore support for WebPage::editorState refactoring. See WebKit ChangeLogs for more detail.
Tests: EditorStateTests.TypingAttributesBold
EditorStateTests.TypingAttributesItalic
EditorStateTests.TypingAttributesUnderline
EditorStateTests.TypingAttributesTextAlignmentAbsoluteAlignmentOptions
EditorStateTests.TypingAttributesTextAlignmentStartEnd
EditorStateTests.TypingAttributesTextAlignmentDirectionalText
EditorStateTests.TypingAttributesTextColor
EditorStateTests.TypingAttributesMixedStyles
EditorStateTests.TypingAttributesLinkColor
* css/StyleProperties.cpp:
(WebCore::StyleProperties::propertyAsColor const):
(WebCore::StyleProperties::propertyAsValueID const):
Introduces some helper functions in StyleProperties to convert CSS property values to Color or a CSSValueID.
* css/StyleProperties.h:
* editing/EditingStyle.cpp:
(WebCore::EditingStyle::hasStyle):
Pull out logic in selectionStartHasStyle that asks for a style TriState into EditingStyle::hasStyle. This is
because WebPage::editorState will now query for multiple styles at the selection start, but
selectionStartHasStyle currently recomputes styleAtSelectionStart every time it is called. To prevent extra work
from being done, we can just call selectionStartHasStyle once and use ask for EditingStyle::hasStyle on the
computed EditingStyle at selection start.
* editing/EditingStyle.h:
* editing/Editor.cpp:
(WebCore::Editor::selectionStartHasStyle const):
Source/WebKit:
Refactors WebPage::editorState to only use the StyleProperties derived from EditingStyle, instead of inserting
and removing a temporary node to figure out the style. Also adds hooks to notify the UI delegate of EditorState
changes.
* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(nsTextAlignment):
(dictionaryRepresentationForEditorState):
(-[WKWebView _didChangeEditorState]):
Alerts the private UI delegate of UI-side EditorState updates.
(-[WKWebView _web_editorStateDidChange]):
(-[WKWebView _executeEditCommand:argument:completion:]):
* UIProcess/API/Cocoa/WKWebViewInternal.h:
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/API/mac/WKView.mm:
(-[WKView _web_editorStateDidChange]):
* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::selectionDidChange):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::executeEditCommand):
Change executeEditCommand(name, callback) to executeEditCommand(name, argument, callback) and lift out of iOS
platform code and into WebPage.cpp.
* UIProcess/WebPageProxy.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView executeEditCommandWithCallback:]):
(-[WKContentView _selectionChanged]):
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::executeEditCommand): Deleted.
Move the iOS-specific implementation of executeEditCommand that invokes a callback when the web process responds
out of WebPageProxyIOS, and into cross-platform WebPageProxy code. Additionally, add a parameter for the edit
command's argument.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::editorState const):
Use EditingStyle::styleAtSelectionStart instead of Editor::styleForSelectionStart when computing an EditorState.
Tweak bold, italic and underline to use EditingStyle TriStates.
(WebKit::WebPage::executeEditCommandWithCallback):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::executeEditCommandWithCallback): Deleted.
Tools:
Introduces new testing infrastructure and API tests to test EditorState updates in the UI process. The new
EditorStateTests run on both iOS and Mac.
* TestWebKitAPI/EditingTestHarness.h: Added.
* TestWebKitAPI/EditingTestHarness.mm: Added.
EditingTestHarness is a helper object that API tests may use to apply editing commands and store EditorState
history. This test harness adds sugaring around various editing commands, and simplifies the process of checking
the state of the latest observed EditorState.
(-[EditingTestHarness initWithWebView:]):
(-[EditingTestHarness dealloc]):
(-[EditingTestHarness webView]):
(-[EditingTestHarness latestEditorState]):
(-[EditingTestHarness editorStateHistory]):
(-[EditingTestHarness insertText:andExpectEditorStateWith:]):
(-[EditingTestHarness insertHTML:andExpectEditorStateWith:]):
(-[EditingTestHarness selectAllAndExpectEditorStateWith:]):
(-[EditingTestHarness moveBackwardAndExpectEditorStateWith:]):
(-[EditingTestHarness moveWordBackwardAndExpectEditorStateWith:]):
(-[EditingTestHarness toggleBold]):
(-[EditingTestHarness toggleItalic]):
(-[EditingTestHarness toggleUnderline]):
(-[EditingTestHarness setForegroundColor:]):
(-[EditingTestHarness alignJustifiedAndExpectEditorStateWith:]):
(-[EditingTestHarness alignLeftAndExpectEditorStateWith:]):
(-[EditingTestHarness alignCenterAndExpectEditorStateWith:]):
(-[EditingTestHarness alignRightAndExpectEditorStateWith:]):
(-[EditingTestHarness insertParagraphAndExpectEditorStateWith:]):
(-[EditingTestHarness deleteBackwardAndExpectEditorStateWith:]):
(-[EditingTestHarness _execCommand:argument:expectEntries:]):
Dispatches an editing command to the web process, and blocks until a response is received. If an expected
entries dictionary is given, this will additionally verify that the latest EditorState contains all the expected
keys and values.
(-[EditingTestHarness latestEditorStateContains:]):
(-[EditingTestHarness _webView:editorStateDidChange:]):
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/EditorStateTests.mm: Added.
(TestWebKitAPI::setUpEditorStateTestHarness):
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKit2Cocoa/editor-state-test-harness.html: Added.
LayoutTests:
* platform/ios-wk2/editing/style/unbold-in-bold-expected.txt:
* platform/mac-wk2/editing/style/unbold-in-bold-expected.txt:
Rebaseline a WK2 LayoutTest expectations. This test currently expects an empty anonymous RenderBlock to be
inserted into the render tree, but this is only a result of us adding and removing a temporary <span> when
computing a RenderStyle in WebPage::editorState -- this patch removes these empty RenderBlocks, making these
expectations' RenderTrees consistent with WebKit1.
Canonical link: https://commits.webkit.org/192520@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221065 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-08-23 03:16:55 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Apple Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2020-04-20 15:32:36 +00:00
|
|
|
#import "config.h"
|
|
|
|
#import "EditingTestHarness.h"
|
[iOS WK2] WKWebView schedules nonstop layout after pressing cmb+b,i,u inside a contenteditable div
https://bugs.webkit.org/show_bug.cgi?id=175116
<rdar://problem/28279301>
Reviewed by Darin Adler and Ryosuke Niwa.
Source/WebCore:
WebCore support for WebPage::editorState refactoring. See WebKit ChangeLogs for more detail.
Tests: EditorStateTests.TypingAttributesBold
EditorStateTests.TypingAttributesItalic
EditorStateTests.TypingAttributesUnderline
EditorStateTests.TypingAttributesTextAlignmentAbsoluteAlignmentOptions
EditorStateTests.TypingAttributesTextAlignmentStartEnd
EditorStateTests.TypingAttributesTextAlignmentDirectionalText
EditorStateTests.TypingAttributesTextColor
EditorStateTests.TypingAttributesMixedStyles
EditorStateTests.TypingAttributesLinkColor
* css/StyleProperties.cpp:
(WebCore::StyleProperties::propertyAsColor const):
(WebCore::StyleProperties::propertyAsValueID const):
Introduces some helper functions in StyleProperties to convert CSS property values to Color or a CSSValueID.
* css/StyleProperties.h:
* editing/EditingStyle.cpp:
(WebCore::EditingStyle::hasStyle):
Pull out logic in selectionStartHasStyle that asks for a style TriState into EditingStyle::hasStyle. This is
because WebPage::editorState will now query for multiple styles at the selection start, but
selectionStartHasStyle currently recomputes styleAtSelectionStart every time it is called. To prevent extra work
from being done, we can just call selectionStartHasStyle once and use ask for EditingStyle::hasStyle on the
computed EditingStyle at selection start.
* editing/EditingStyle.h:
* editing/Editor.cpp:
(WebCore::Editor::selectionStartHasStyle const):
Source/WebKit:
Refactors WebPage::editorState to only use the StyleProperties derived from EditingStyle, instead of inserting
and removing a temporary node to figure out the style. Also adds hooks to notify the UI delegate of EditorState
changes.
* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(nsTextAlignment):
(dictionaryRepresentationForEditorState):
(-[WKWebView _didChangeEditorState]):
Alerts the private UI delegate of UI-side EditorState updates.
(-[WKWebView _web_editorStateDidChange]):
(-[WKWebView _executeEditCommand:argument:completion:]):
* UIProcess/API/Cocoa/WKWebViewInternal.h:
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/API/mac/WKView.mm:
(-[WKView _web_editorStateDidChange]):
* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::selectionDidChange):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::executeEditCommand):
Change executeEditCommand(name, callback) to executeEditCommand(name, argument, callback) and lift out of iOS
platform code and into WebPage.cpp.
* UIProcess/WebPageProxy.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView executeEditCommandWithCallback:]):
(-[WKContentView _selectionChanged]):
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::executeEditCommand): Deleted.
Move the iOS-specific implementation of executeEditCommand that invokes a callback when the web process responds
out of WebPageProxyIOS, and into cross-platform WebPageProxy code. Additionally, add a parameter for the edit
command's argument.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::editorState const):
Use EditingStyle::styleAtSelectionStart instead of Editor::styleForSelectionStart when computing an EditorState.
Tweak bold, italic and underline to use EditingStyle TriStates.
(WebKit::WebPage::executeEditCommandWithCallback):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::executeEditCommandWithCallback): Deleted.
Tools:
Introduces new testing infrastructure and API tests to test EditorState updates in the UI process. The new
EditorStateTests run on both iOS and Mac.
* TestWebKitAPI/EditingTestHarness.h: Added.
* TestWebKitAPI/EditingTestHarness.mm: Added.
EditingTestHarness is a helper object that API tests may use to apply editing commands and store EditorState
history. This test harness adds sugaring around various editing commands, and simplifies the process of checking
the state of the latest observed EditorState.
(-[EditingTestHarness initWithWebView:]):
(-[EditingTestHarness dealloc]):
(-[EditingTestHarness webView]):
(-[EditingTestHarness latestEditorState]):
(-[EditingTestHarness editorStateHistory]):
(-[EditingTestHarness insertText:andExpectEditorStateWith:]):
(-[EditingTestHarness insertHTML:andExpectEditorStateWith:]):
(-[EditingTestHarness selectAllAndExpectEditorStateWith:]):
(-[EditingTestHarness moveBackwardAndExpectEditorStateWith:]):
(-[EditingTestHarness moveWordBackwardAndExpectEditorStateWith:]):
(-[EditingTestHarness toggleBold]):
(-[EditingTestHarness toggleItalic]):
(-[EditingTestHarness toggleUnderline]):
(-[EditingTestHarness setForegroundColor:]):
(-[EditingTestHarness alignJustifiedAndExpectEditorStateWith:]):
(-[EditingTestHarness alignLeftAndExpectEditorStateWith:]):
(-[EditingTestHarness alignCenterAndExpectEditorStateWith:]):
(-[EditingTestHarness alignRightAndExpectEditorStateWith:]):
(-[EditingTestHarness insertParagraphAndExpectEditorStateWith:]):
(-[EditingTestHarness deleteBackwardAndExpectEditorStateWith:]):
(-[EditingTestHarness _execCommand:argument:expectEntries:]):
Dispatches an editing command to the web process, and blocks until a response is received. If an expected
entries dictionary is given, this will additionally verify that the latest EditorState contains all the expected
keys and values.
(-[EditingTestHarness latestEditorStateContains:]):
(-[EditingTestHarness _webView:editorStateDidChange:]):
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/EditorStateTests.mm: Added.
(TestWebKitAPI::setUpEditorStateTestHarness):
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKit2Cocoa/editor-state-test-harness.html: Added.
LayoutTests:
* platform/ios-wk2/editing/style/unbold-in-bold-expected.txt:
* platform/mac-wk2/editing/style/unbold-in-bold-expected.txt:
Rebaseline a WK2 LayoutTest expectations. This test currently expects an empty anonymous RenderBlock to be
inserted into the render tree, but this is only a result of us adding and removing a temporary <span> when
computing a RenderStyle in WebPage::editorState -- this patch removes these empty RenderBlocks, making these
expectations' RenderTrees consistent with WebKit1.
Canonical link: https://commits.webkit.org/192520@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221065 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-08-23 03:16:55 +00:00
|
|
|
|
|
|
|
#import "PlatformUtilities.h"
|
2019-12-13 06:06:08 +00:00
|
|
|
#import <WebKit/WKWebViewPrivateForTesting.h>
|
[iOS WK2] WKWebView schedules nonstop layout after pressing cmb+b,i,u inside a contenteditable div
https://bugs.webkit.org/show_bug.cgi?id=175116
<rdar://problem/28279301>
Reviewed by Darin Adler and Ryosuke Niwa.
Source/WebCore:
WebCore support for WebPage::editorState refactoring. See WebKit ChangeLogs for more detail.
Tests: EditorStateTests.TypingAttributesBold
EditorStateTests.TypingAttributesItalic
EditorStateTests.TypingAttributesUnderline
EditorStateTests.TypingAttributesTextAlignmentAbsoluteAlignmentOptions
EditorStateTests.TypingAttributesTextAlignmentStartEnd
EditorStateTests.TypingAttributesTextAlignmentDirectionalText
EditorStateTests.TypingAttributesTextColor
EditorStateTests.TypingAttributesMixedStyles
EditorStateTests.TypingAttributesLinkColor
* css/StyleProperties.cpp:
(WebCore::StyleProperties::propertyAsColor const):
(WebCore::StyleProperties::propertyAsValueID const):
Introduces some helper functions in StyleProperties to convert CSS property values to Color or a CSSValueID.
* css/StyleProperties.h:
* editing/EditingStyle.cpp:
(WebCore::EditingStyle::hasStyle):
Pull out logic in selectionStartHasStyle that asks for a style TriState into EditingStyle::hasStyle. This is
because WebPage::editorState will now query for multiple styles at the selection start, but
selectionStartHasStyle currently recomputes styleAtSelectionStart every time it is called. To prevent extra work
from being done, we can just call selectionStartHasStyle once and use ask for EditingStyle::hasStyle on the
computed EditingStyle at selection start.
* editing/EditingStyle.h:
* editing/Editor.cpp:
(WebCore::Editor::selectionStartHasStyle const):
Source/WebKit:
Refactors WebPage::editorState to only use the StyleProperties derived from EditingStyle, instead of inserting
and removing a temporary node to figure out the style. Also adds hooks to notify the UI delegate of EditorState
changes.
* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(nsTextAlignment):
(dictionaryRepresentationForEditorState):
(-[WKWebView _didChangeEditorState]):
Alerts the private UI delegate of UI-side EditorState updates.
(-[WKWebView _web_editorStateDidChange]):
(-[WKWebView _executeEditCommand:argument:completion:]):
* UIProcess/API/Cocoa/WKWebViewInternal.h:
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/API/mac/WKView.mm:
(-[WKView _web_editorStateDidChange]):
* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::selectionDidChange):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::executeEditCommand):
Change executeEditCommand(name, callback) to executeEditCommand(name, argument, callback) and lift out of iOS
platform code and into WebPage.cpp.
* UIProcess/WebPageProxy.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView executeEditCommandWithCallback:]):
(-[WKContentView _selectionChanged]):
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::executeEditCommand): Deleted.
Move the iOS-specific implementation of executeEditCommand that invokes a callback when the web process responds
out of WebPageProxyIOS, and into cross-platform WebPageProxy code. Additionally, add a parameter for the edit
command's argument.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::editorState const):
Use EditingStyle::styleAtSelectionStart instead of Editor::styleForSelectionStart when computing an EditorState.
Tweak bold, italic and underline to use EditingStyle TriStates.
(WebKit::WebPage::executeEditCommandWithCallback):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::executeEditCommandWithCallback): Deleted.
Tools:
Introduces new testing infrastructure and API tests to test EditorState updates in the UI process. The new
EditorStateTests run on both iOS and Mac.
* TestWebKitAPI/EditingTestHarness.h: Added.
* TestWebKitAPI/EditingTestHarness.mm: Added.
EditingTestHarness is a helper object that API tests may use to apply editing commands and store EditorState
history. This test harness adds sugaring around various editing commands, and simplifies the process of checking
the state of the latest observed EditorState.
(-[EditingTestHarness initWithWebView:]):
(-[EditingTestHarness dealloc]):
(-[EditingTestHarness webView]):
(-[EditingTestHarness latestEditorState]):
(-[EditingTestHarness editorStateHistory]):
(-[EditingTestHarness insertText:andExpectEditorStateWith:]):
(-[EditingTestHarness insertHTML:andExpectEditorStateWith:]):
(-[EditingTestHarness selectAllAndExpectEditorStateWith:]):
(-[EditingTestHarness moveBackwardAndExpectEditorStateWith:]):
(-[EditingTestHarness moveWordBackwardAndExpectEditorStateWith:]):
(-[EditingTestHarness toggleBold]):
(-[EditingTestHarness toggleItalic]):
(-[EditingTestHarness toggleUnderline]):
(-[EditingTestHarness setForegroundColor:]):
(-[EditingTestHarness alignJustifiedAndExpectEditorStateWith:]):
(-[EditingTestHarness alignLeftAndExpectEditorStateWith:]):
(-[EditingTestHarness alignCenterAndExpectEditorStateWith:]):
(-[EditingTestHarness alignRightAndExpectEditorStateWith:]):
(-[EditingTestHarness insertParagraphAndExpectEditorStateWith:]):
(-[EditingTestHarness deleteBackwardAndExpectEditorStateWith:]):
(-[EditingTestHarness _execCommand:argument:expectEntries:]):
Dispatches an editing command to the web process, and blocks until a response is received. If an expected
entries dictionary is given, this will additionally verify that the latest EditorState contains all the expected
keys and values.
(-[EditingTestHarness latestEditorStateContains:]):
(-[EditingTestHarness _webView:editorStateDidChange:]):
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/EditorStateTests.mm: Added.
(TestWebKitAPI::setUpEditorStateTestHarness):
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKit2Cocoa/editor-state-test-harness.html: Added.
LayoutTests:
* platform/ios-wk2/editing/style/unbold-in-bold-expected.txt:
* platform/mac-wk2/editing/style/unbold-in-bold-expected.txt:
Rebaseline a WK2 LayoutTest expectations. This test currently expects an empty anonymous RenderBlock to be
inserted into the render tree, but this is only a result of us adding and removing a temporary <span> when
computing a RenderStyle in WebPage::editorState -- this patch removes these empty RenderBlocks, making these
expectations' RenderTrees consistent with WebKit1.
Canonical link: https://commits.webkit.org/192520@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221065 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-08-23 03:16:55 +00:00
|
|
|
|
|
|
|
@implementation EditingTestHarness
|
|
|
|
|
|
|
|
- (instancetype)initWithWebView:(TestWKWebView *)webView
|
|
|
|
{
|
|
|
|
if (self = [super init]) {
|
|
|
|
_webView = webView;
|
|
|
|
[_webView setUIDelegate:self];
|
|
|
|
_editorStateHistory = adoptNS([[NSMutableArray alloc] init]);
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
if ([_webView UIDelegate] == self)
|
|
|
|
[_webView setUIDelegate:nil];
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (TestWKWebView *)webView
|
|
|
|
{
|
|
|
|
return _webView.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *)latestEditorState
|
|
|
|
{
|
|
|
|
return self.editorStateHistory.lastObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray<NSDictionary *> *)editorStateHistory
|
|
|
|
{
|
|
|
|
return _editorStateHistory.get();
|
|
|
|
}
|
|
|
|
|
[iOS WK2] Implement -[WKContentView hasText] for compatibility with the UITextInput protocol
https://bugs.webkit.org/show_bug.cgi?id=177662
<rdar://problem/33410373>
Reviewed by Tim Horton.
Source/WebCore:
Adds a new TextIterator helper function to determine whether a Range has any plain text.
Tests: EditorStateTests.ContentViewHasTextInContentEditableElement
EditorStateTests.ContentViewHasTextInTextarea
* editing/TextIterator.cpp:
(WebCore::hasAnyPlainText):
Add a new helper to determine whether a Range contains any plain text. While inspired by and very similar to the
plainText() helper function, this variant does not create a new string buffer when invoked, and is therefore
more efficient for the purposes of determining whether there is any plain text at all.
* editing/TextIterator.h:
Source/WebKit:
Implements -[WKContentView hasText] by propagating a flag through post-layout editor state.
* Shared/EditorState.cpp:
(WebKit::EditorState::PostLayoutData::encode const):
(WebKit::EditorState::PostLayoutData::decode):
* Shared/EditorState.h:
Add a new flag to EditorState indicating whether or not the current editable root containing the selection has
any plain text. Add IPC support for this new flag.
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView hasText]):
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::computeEditableRootHasContentAndPlainText):
Add a new helper to compute whether or not the editable root has any content, and any plain text. This
is used as the last cached value for -hasText on WKContentView that we will deliver to UIKit. Some important
things to note here:
- If post layout data already indicates that we have selected some plain text, or that there is a plain text
character near the selection, just set the flags to true and bail, since the editable root necessarily has
content that is plain text.
- If hasContent is false, don't even bother computing hasPlainText, because it must also be false.
- Otherwise, use hasAnyPlainText to compute the value of hasPlainText, which is a faster variant of plainText.
These optimizations help us avoid doing extra work at all when running Speedometer, apart from checking the
values of a few PostLayoutData flags. This also fixes the value of hasContent, which was previously always false
if we had a range selection rather than a caret selection even when the editable root has content, because the
logic to compute the value of hasContent only existed in the branch where we have a caret selection.
(WebKit::WebPage::platformEditorState const):
Tools:
Add EditorState API tests to check that the value of -[WKContentView hasText] is correct when editing both plain
and rich text areas.
* TestWebKitAPI/EditingTestHarness.h:
* TestWebKitAPI/EditingTestHarness.mm:
(-[EditingTestHarness insertParagraph]):
(-[EditingTestHarness insertText:]):
(-[EditingTestHarness insertHTML:]):
(-[EditingTestHarness selectAll]):
(-[EditingTestHarness deleteBackwards]):
* TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm:
Add versions of EditingTestHarness helpers that don't require us to expect any editor state after executing the
edit command.
(TestWebKitAPI::checkContentViewHasTextWithFailureDescription):
(TestWebKitAPI::TEST):
* TestWebKitAPI/cocoa/TestWKWebView.h:
* TestWebKitAPI/cocoa/TestWKWebView.mm:
(-[TestWKWebView textInputContentView]):
Canonical link: https://commits.webkit.org/193938@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222654 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-09-29 18:33:32 +00:00
|
|
|
- (void)insertParagraph
|
|
|
|
{
|
|
|
|
[self insertParagraphAndExpectEditorStateWith:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)insertText:(NSString *)text
|
|
|
|
{
|
|
|
|
[self insertText:text andExpectEditorStateWith:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)insertHTML:(NSString *)html
|
|
|
|
{
|
|
|
|
[self insertHTML:html andExpectEditorStateWith:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)selectAll
|
|
|
|
{
|
|
|
|
[self selectAllAndExpectEditorStateWith:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)deleteBackwards
|
|
|
|
{
|
|
|
|
[self deleteBackwardAndExpectEditorStateWith:nil];
|
|
|
|
}
|
|
|
|
|
2019-01-14 20:09:58 +00:00
|
|
|
- (void)moveBackward
|
|
|
|
{
|
|
|
|
[self moveBackwardAndExpectEditorStateWith:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)moveForward
|
|
|
|
{
|
|
|
|
[self moveForwardAndExpectEditorStateWith:nil];
|
|
|
|
}
|
|
|
|
|
[iOS WK2] WKWebView schedules nonstop layout after pressing cmb+b,i,u inside a contenteditable div
https://bugs.webkit.org/show_bug.cgi?id=175116
<rdar://problem/28279301>
Reviewed by Darin Adler and Ryosuke Niwa.
Source/WebCore:
WebCore support for WebPage::editorState refactoring. See WebKit ChangeLogs for more detail.
Tests: EditorStateTests.TypingAttributesBold
EditorStateTests.TypingAttributesItalic
EditorStateTests.TypingAttributesUnderline
EditorStateTests.TypingAttributesTextAlignmentAbsoluteAlignmentOptions
EditorStateTests.TypingAttributesTextAlignmentStartEnd
EditorStateTests.TypingAttributesTextAlignmentDirectionalText
EditorStateTests.TypingAttributesTextColor
EditorStateTests.TypingAttributesMixedStyles
EditorStateTests.TypingAttributesLinkColor
* css/StyleProperties.cpp:
(WebCore::StyleProperties::propertyAsColor const):
(WebCore::StyleProperties::propertyAsValueID const):
Introduces some helper functions in StyleProperties to convert CSS property values to Color or a CSSValueID.
* css/StyleProperties.h:
* editing/EditingStyle.cpp:
(WebCore::EditingStyle::hasStyle):
Pull out logic in selectionStartHasStyle that asks for a style TriState into EditingStyle::hasStyle. This is
because WebPage::editorState will now query for multiple styles at the selection start, but
selectionStartHasStyle currently recomputes styleAtSelectionStart every time it is called. To prevent extra work
from being done, we can just call selectionStartHasStyle once and use ask for EditingStyle::hasStyle on the
computed EditingStyle at selection start.
* editing/EditingStyle.h:
* editing/Editor.cpp:
(WebCore::Editor::selectionStartHasStyle const):
Source/WebKit:
Refactors WebPage::editorState to only use the StyleProperties derived from EditingStyle, instead of inserting
and removing a temporary node to figure out the style. Also adds hooks to notify the UI delegate of EditorState
changes.
* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(nsTextAlignment):
(dictionaryRepresentationForEditorState):
(-[WKWebView _didChangeEditorState]):
Alerts the private UI delegate of UI-side EditorState updates.
(-[WKWebView _web_editorStateDidChange]):
(-[WKWebView _executeEditCommand:argument:completion:]):
* UIProcess/API/Cocoa/WKWebViewInternal.h:
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/API/mac/WKView.mm:
(-[WKView _web_editorStateDidChange]):
* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::selectionDidChange):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::executeEditCommand):
Change executeEditCommand(name, callback) to executeEditCommand(name, argument, callback) and lift out of iOS
platform code and into WebPage.cpp.
* UIProcess/WebPageProxy.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView executeEditCommandWithCallback:]):
(-[WKContentView _selectionChanged]):
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::executeEditCommand): Deleted.
Move the iOS-specific implementation of executeEditCommand that invokes a callback when the web process responds
out of WebPageProxyIOS, and into cross-platform WebPageProxy code. Additionally, add a parameter for the edit
command's argument.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::editorState const):
Use EditingStyle::styleAtSelectionStart instead of Editor::styleForSelectionStart when computing an EditorState.
Tweak bold, italic and underline to use EditingStyle TriStates.
(WebKit::WebPage::executeEditCommandWithCallback):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::executeEditCommandWithCallback): Deleted.
Tools:
Introduces new testing infrastructure and API tests to test EditorState updates in the UI process. The new
EditorStateTests run on both iOS and Mac.
* TestWebKitAPI/EditingTestHarness.h: Added.
* TestWebKitAPI/EditingTestHarness.mm: Added.
EditingTestHarness is a helper object that API tests may use to apply editing commands and store EditorState
history. This test harness adds sugaring around various editing commands, and simplifies the process of checking
the state of the latest observed EditorState.
(-[EditingTestHarness initWithWebView:]):
(-[EditingTestHarness dealloc]):
(-[EditingTestHarness webView]):
(-[EditingTestHarness latestEditorState]):
(-[EditingTestHarness editorStateHistory]):
(-[EditingTestHarness insertText:andExpectEditorStateWith:]):
(-[EditingTestHarness insertHTML:andExpectEditorStateWith:]):
(-[EditingTestHarness selectAllAndExpectEditorStateWith:]):
(-[EditingTestHarness moveBackwardAndExpectEditorStateWith:]):
(-[EditingTestHarness moveWordBackwardAndExpectEditorStateWith:]):
(-[EditingTestHarness toggleBold]):
(-[EditingTestHarness toggleItalic]):
(-[EditingTestHarness toggleUnderline]):
(-[EditingTestHarness setForegroundColor:]):
(-[EditingTestHarness alignJustifiedAndExpectEditorStateWith:]):
(-[EditingTestHarness alignLeftAndExpectEditorStateWith:]):
(-[EditingTestHarness alignCenterAndExpectEditorStateWith:]):
(-[EditingTestHarness alignRightAndExpectEditorStateWith:]):
(-[EditingTestHarness insertParagraphAndExpectEditorStateWith:]):
(-[EditingTestHarness deleteBackwardAndExpectEditorStateWith:]):
(-[EditingTestHarness _execCommand:argument:expectEntries:]):
Dispatches an editing command to the web process, and blocks until a response is received. If an expected
entries dictionary is given, this will additionally verify that the latest EditorState contains all the expected
keys and values.
(-[EditingTestHarness latestEditorStateContains:]):
(-[EditingTestHarness _webView:editorStateDidChange:]):
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/EditorStateTests.mm: Added.
(TestWebKitAPI::setUpEditorStateTestHarness):
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKit2Cocoa/editor-state-test-harness.html: Added.
LayoutTests:
* platform/ios-wk2/editing/style/unbold-in-bold-expected.txt:
* platform/mac-wk2/editing/style/unbold-in-bold-expected.txt:
Rebaseline a WK2 LayoutTest expectations. This test currently expects an empty anonymous RenderBlock to be
inserted into the render tree, but this is only a result of us adding and removing a temporary <span> when
computing a RenderStyle in WebPage::editorState -- this patch removes these empty RenderBlocks, making these
expectations' RenderTrees consistent with WebKit1.
Canonical link: https://commits.webkit.org/192520@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221065 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-08-23 03:16:55 +00:00
|
|
|
- (void)insertText:(NSString *)text andExpectEditorStateWith:(NSDictionary<NSString *, id> *)entries
|
|
|
|
{
|
|
|
|
[self _execCommand:@"InsertText" argument:text expectEntries:entries];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)insertHTML:(NSString *)html andExpectEditorStateWith:(NSDictionary<NSString *, id> *)entries
|
|
|
|
{
|
|
|
|
[self _execCommand:@"InsertHTML" argument:html expectEntries:entries];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)selectAllAndExpectEditorStateWith:(NSDictionary<NSString *, id> *)entries
|
|
|
|
{
|
|
|
|
[self _execCommand:@"SelectAll" argument:nil expectEntries:entries];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)moveBackwardAndExpectEditorStateWith:(NSDictionary<NSString *, id> *)entries
|
|
|
|
{
|
|
|
|
[self _execCommand:@"MoveBackward" argument:nil expectEntries:entries];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)moveWordBackwardAndExpectEditorStateWith:(NSDictionary<NSString *, id> *)entries
|
|
|
|
{
|
|
|
|
[self _execCommand:@"MoveWordBackward" argument:nil expectEntries:entries];
|
|
|
|
}
|
|
|
|
|
2019-01-14 20:09:58 +00:00
|
|
|
- (void)moveForwardAndExpectEditorStateWith:(NSDictionary<NSString *, id> *)entries
|
|
|
|
{
|
|
|
|
[self _execCommand:@"MoveForward" argument:nil expectEntries:entries];
|
|
|
|
}
|
|
|
|
|
[iOS WK2] WKWebView schedules nonstop layout after pressing cmb+b,i,u inside a contenteditable div
https://bugs.webkit.org/show_bug.cgi?id=175116
<rdar://problem/28279301>
Reviewed by Darin Adler and Ryosuke Niwa.
Source/WebCore:
WebCore support for WebPage::editorState refactoring. See WebKit ChangeLogs for more detail.
Tests: EditorStateTests.TypingAttributesBold
EditorStateTests.TypingAttributesItalic
EditorStateTests.TypingAttributesUnderline
EditorStateTests.TypingAttributesTextAlignmentAbsoluteAlignmentOptions
EditorStateTests.TypingAttributesTextAlignmentStartEnd
EditorStateTests.TypingAttributesTextAlignmentDirectionalText
EditorStateTests.TypingAttributesTextColor
EditorStateTests.TypingAttributesMixedStyles
EditorStateTests.TypingAttributesLinkColor
* css/StyleProperties.cpp:
(WebCore::StyleProperties::propertyAsColor const):
(WebCore::StyleProperties::propertyAsValueID const):
Introduces some helper functions in StyleProperties to convert CSS property values to Color or a CSSValueID.
* css/StyleProperties.h:
* editing/EditingStyle.cpp:
(WebCore::EditingStyle::hasStyle):
Pull out logic in selectionStartHasStyle that asks for a style TriState into EditingStyle::hasStyle. This is
because WebPage::editorState will now query for multiple styles at the selection start, but
selectionStartHasStyle currently recomputes styleAtSelectionStart every time it is called. To prevent extra work
from being done, we can just call selectionStartHasStyle once and use ask for EditingStyle::hasStyle on the
computed EditingStyle at selection start.
* editing/EditingStyle.h:
* editing/Editor.cpp:
(WebCore::Editor::selectionStartHasStyle const):
Source/WebKit:
Refactors WebPage::editorState to only use the StyleProperties derived from EditingStyle, instead of inserting
and removing a temporary node to figure out the style. Also adds hooks to notify the UI delegate of EditorState
changes.
* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(nsTextAlignment):
(dictionaryRepresentationForEditorState):
(-[WKWebView _didChangeEditorState]):
Alerts the private UI delegate of UI-side EditorState updates.
(-[WKWebView _web_editorStateDidChange]):
(-[WKWebView _executeEditCommand:argument:completion:]):
* UIProcess/API/Cocoa/WKWebViewInternal.h:
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/API/mac/WKView.mm:
(-[WKView _web_editorStateDidChange]):
* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::selectionDidChange):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::executeEditCommand):
Change executeEditCommand(name, callback) to executeEditCommand(name, argument, callback) and lift out of iOS
platform code and into WebPage.cpp.
* UIProcess/WebPageProxy.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView executeEditCommandWithCallback:]):
(-[WKContentView _selectionChanged]):
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::executeEditCommand): Deleted.
Move the iOS-specific implementation of executeEditCommand that invokes a callback when the web process responds
out of WebPageProxyIOS, and into cross-platform WebPageProxy code. Additionally, add a parameter for the edit
command's argument.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::editorState const):
Use EditingStyle::styleAtSelectionStart instead of Editor::styleForSelectionStart when computing an EditorState.
Tweak bold, italic and underline to use EditingStyle TriStates.
(WebKit::WebPage::executeEditCommandWithCallback):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::executeEditCommandWithCallback): Deleted.
Tools:
Introduces new testing infrastructure and API tests to test EditorState updates in the UI process. The new
EditorStateTests run on both iOS and Mac.
* TestWebKitAPI/EditingTestHarness.h: Added.
* TestWebKitAPI/EditingTestHarness.mm: Added.
EditingTestHarness is a helper object that API tests may use to apply editing commands and store EditorState
history. This test harness adds sugaring around various editing commands, and simplifies the process of checking
the state of the latest observed EditorState.
(-[EditingTestHarness initWithWebView:]):
(-[EditingTestHarness dealloc]):
(-[EditingTestHarness webView]):
(-[EditingTestHarness latestEditorState]):
(-[EditingTestHarness editorStateHistory]):
(-[EditingTestHarness insertText:andExpectEditorStateWith:]):
(-[EditingTestHarness insertHTML:andExpectEditorStateWith:]):
(-[EditingTestHarness selectAllAndExpectEditorStateWith:]):
(-[EditingTestHarness moveBackwardAndExpectEditorStateWith:]):
(-[EditingTestHarness moveWordBackwardAndExpectEditorStateWith:]):
(-[EditingTestHarness toggleBold]):
(-[EditingTestHarness toggleItalic]):
(-[EditingTestHarness toggleUnderline]):
(-[EditingTestHarness setForegroundColor:]):
(-[EditingTestHarness alignJustifiedAndExpectEditorStateWith:]):
(-[EditingTestHarness alignLeftAndExpectEditorStateWith:]):
(-[EditingTestHarness alignCenterAndExpectEditorStateWith:]):
(-[EditingTestHarness alignRightAndExpectEditorStateWith:]):
(-[EditingTestHarness insertParagraphAndExpectEditorStateWith:]):
(-[EditingTestHarness deleteBackwardAndExpectEditorStateWith:]):
(-[EditingTestHarness _execCommand:argument:expectEntries:]):
Dispatches an editing command to the web process, and blocks until a response is received. If an expected
entries dictionary is given, this will additionally verify that the latest EditorState contains all the expected
keys and values.
(-[EditingTestHarness latestEditorStateContains:]):
(-[EditingTestHarness _webView:editorStateDidChange:]):
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/EditorStateTests.mm: Added.
(TestWebKitAPI::setUpEditorStateTestHarness):
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKit2Cocoa/editor-state-test-harness.html: Added.
LayoutTests:
* platform/ios-wk2/editing/style/unbold-in-bold-expected.txt:
* platform/mac-wk2/editing/style/unbold-in-bold-expected.txt:
Rebaseline a WK2 LayoutTest expectations. This test currently expects an empty anonymous RenderBlock to be
inserted into the render tree, but this is only a result of us adding and removing a temporary <span> when
computing a RenderStyle in WebPage::editorState -- this patch removes these empty RenderBlocks, making these
expectations' RenderTrees consistent with WebKit1.
Canonical link: https://commits.webkit.org/192520@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221065 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-08-23 03:16:55 +00:00
|
|
|
- (void)toggleBold
|
|
|
|
{
|
|
|
|
[self _execCommand:@"ToggleBold" argument:nil expectEntries:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)toggleItalic
|
|
|
|
{
|
|
|
|
[self _execCommand:@"ToggleItalic" argument:nil expectEntries:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)toggleUnderline
|
|
|
|
{
|
|
|
|
[self _execCommand:@"ToggleUnderline" argument:nil expectEntries:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setForegroundColor:(NSString *)colorAsString
|
|
|
|
{
|
|
|
|
[self _execCommand:@"ForeColor" argument:colorAsString expectEntries:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)alignJustifiedAndExpectEditorStateWith:(NSDictionary<NSString *, id> *)entries
|
|
|
|
{
|
|
|
|
[self _execCommand:@"AlignJustified" argument:nil expectEntries:entries];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)alignLeftAndExpectEditorStateWith:(NSDictionary<NSString *, id> *)entries
|
|
|
|
{
|
|
|
|
[self _execCommand:@"AlignLeft" argument:nil expectEntries:entries];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)alignCenterAndExpectEditorStateWith:(NSDictionary<NSString *, id> *)entries
|
|
|
|
{
|
|
|
|
[self _execCommand:@"AlignCenter" argument:nil expectEntries:entries];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)alignRightAndExpectEditorStateWith:(NSDictionary<NSString *, id> *)entries
|
|
|
|
{
|
|
|
|
[self _execCommand:@"AlignRight" argument:nil expectEntries:entries];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)insertParagraphAndExpectEditorStateWith:(NSDictionary<NSString *, id> *)entries
|
|
|
|
{
|
|
|
|
[self _execCommand:@"InsertParagraph" argument:nil expectEntries:entries];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)deleteBackwardAndExpectEditorStateWith:(NSDictionary<NSString *, id> *)entries
|
|
|
|
{
|
|
|
|
[self _execCommand:@"DeleteBackward" argument:nil expectEntries:entries];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)_execCommand:(NSString *)command argument:(NSString *)argument expectEntries:(NSDictionary<NSString *, id> *)entries
|
|
|
|
{
|
|
|
|
__block BOOL result = false;
|
|
|
|
__block bool done = false;
|
|
|
|
[_webView _executeEditCommand:command argument:argument completion:^(BOOL success) {
|
|
|
|
result = success;
|
|
|
|
done = true;
|
|
|
|
}];
|
|
|
|
TestWebKitAPI::Util::run(&done);
|
|
|
|
|
|
|
|
EXPECT_TRUE(result);
|
|
|
|
if (!result)
|
|
|
|
NSLog(@"Failed to execute editing command: ('%@', '%@')", command, argument ?: @"");
|
|
|
|
|
2019-11-01 18:27:00 +00:00
|
|
|
const NSTimeInterval loggingTimeout = 3;
|
|
|
|
auto startTime = retainPtr([NSDate date]);
|
|
|
|
BOOL hasLoggedWarning = NO;
|
|
|
|
BOOL containsEntries;
|
|
|
|
do {
|
|
|
|
[_webView waitForNextPresentationUpdate];
|
|
|
|
containsEntries = [self latestEditorStateContains:entries];
|
|
|
|
if (!hasLoggedWarning && [[NSDate date] timeIntervalSinceDate:startTime.get()] > loggingTimeout) {
|
|
|
|
NSLog(@"Expected %@ to contain %@", self.latestEditorState, entries);
|
|
|
|
hasLoggedWarning = YES;
|
|
|
|
}
|
|
|
|
} while (!containsEntries);
|
[iOS WK2] WKWebView schedules nonstop layout after pressing cmb+b,i,u inside a contenteditable div
https://bugs.webkit.org/show_bug.cgi?id=175116
<rdar://problem/28279301>
Reviewed by Darin Adler and Ryosuke Niwa.
Source/WebCore:
WebCore support for WebPage::editorState refactoring. See WebKit ChangeLogs for more detail.
Tests: EditorStateTests.TypingAttributesBold
EditorStateTests.TypingAttributesItalic
EditorStateTests.TypingAttributesUnderline
EditorStateTests.TypingAttributesTextAlignmentAbsoluteAlignmentOptions
EditorStateTests.TypingAttributesTextAlignmentStartEnd
EditorStateTests.TypingAttributesTextAlignmentDirectionalText
EditorStateTests.TypingAttributesTextColor
EditorStateTests.TypingAttributesMixedStyles
EditorStateTests.TypingAttributesLinkColor
* css/StyleProperties.cpp:
(WebCore::StyleProperties::propertyAsColor const):
(WebCore::StyleProperties::propertyAsValueID const):
Introduces some helper functions in StyleProperties to convert CSS property values to Color or a CSSValueID.
* css/StyleProperties.h:
* editing/EditingStyle.cpp:
(WebCore::EditingStyle::hasStyle):
Pull out logic in selectionStartHasStyle that asks for a style TriState into EditingStyle::hasStyle. This is
because WebPage::editorState will now query for multiple styles at the selection start, but
selectionStartHasStyle currently recomputes styleAtSelectionStart every time it is called. To prevent extra work
from being done, we can just call selectionStartHasStyle once and use ask for EditingStyle::hasStyle on the
computed EditingStyle at selection start.
* editing/EditingStyle.h:
* editing/Editor.cpp:
(WebCore::Editor::selectionStartHasStyle const):
Source/WebKit:
Refactors WebPage::editorState to only use the StyleProperties derived from EditingStyle, instead of inserting
and removing a temporary node to figure out the style. Also adds hooks to notify the UI delegate of EditorState
changes.
* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(nsTextAlignment):
(dictionaryRepresentationForEditorState):
(-[WKWebView _didChangeEditorState]):
Alerts the private UI delegate of UI-side EditorState updates.
(-[WKWebView _web_editorStateDidChange]):
(-[WKWebView _executeEditCommand:argument:completion:]):
* UIProcess/API/Cocoa/WKWebViewInternal.h:
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/API/mac/WKView.mm:
(-[WKView _web_editorStateDidChange]):
* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::selectionDidChange):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::executeEditCommand):
Change executeEditCommand(name, callback) to executeEditCommand(name, argument, callback) and lift out of iOS
platform code and into WebPage.cpp.
* UIProcess/WebPageProxy.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView executeEditCommandWithCallback:]):
(-[WKContentView _selectionChanged]):
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::executeEditCommand): Deleted.
Move the iOS-specific implementation of executeEditCommand that invokes a callback when the web process responds
out of WebPageProxyIOS, and into cross-platform WebPageProxy code. Additionally, add a parameter for the edit
command's argument.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::editorState const):
Use EditingStyle::styleAtSelectionStart instead of Editor::styleForSelectionStart when computing an EditorState.
Tweak bold, italic and underline to use EditingStyle TriStates.
(WebKit::WebPage::executeEditCommandWithCallback):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::executeEditCommandWithCallback): Deleted.
Tools:
Introduces new testing infrastructure and API tests to test EditorState updates in the UI process. The new
EditorStateTests run on both iOS and Mac.
* TestWebKitAPI/EditingTestHarness.h: Added.
* TestWebKitAPI/EditingTestHarness.mm: Added.
EditingTestHarness is a helper object that API tests may use to apply editing commands and store EditorState
history. This test harness adds sugaring around various editing commands, and simplifies the process of checking
the state of the latest observed EditorState.
(-[EditingTestHarness initWithWebView:]):
(-[EditingTestHarness dealloc]):
(-[EditingTestHarness webView]):
(-[EditingTestHarness latestEditorState]):
(-[EditingTestHarness editorStateHistory]):
(-[EditingTestHarness insertText:andExpectEditorStateWith:]):
(-[EditingTestHarness insertHTML:andExpectEditorStateWith:]):
(-[EditingTestHarness selectAllAndExpectEditorStateWith:]):
(-[EditingTestHarness moveBackwardAndExpectEditorStateWith:]):
(-[EditingTestHarness moveWordBackwardAndExpectEditorStateWith:]):
(-[EditingTestHarness toggleBold]):
(-[EditingTestHarness toggleItalic]):
(-[EditingTestHarness toggleUnderline]):
(-[EditingTestHarness setForegroundColor:]):
(-[EditingTestHarness alignJustifiedAndExpectEditorStateWith:]):
(-[EditingTestHarness alignLeftAndExpectEditorStateWith:]):
(-[EditingTestHarness alignCenterAndExpectEditorStateWith:]):
(-[EditingTestHarness alignRightAndExpectEditorStateWith:]):
(-[EditingTestHarness insertParagraphAndExpectEditorStateWith:]):
(-[EditingTestHarness deleteBackwardAndExpectEditorStateWith:]):
(-[EditingTestHarness _execCommand:argument:expectEntries:]):
Dispatches an editing command to the web process, and blocks until a response is received. If an expected
entries dictionary is given, this will additionally verify that the latest EditorState contains all the expected
keys and values.
(-[EditingTestHarness latestEditorStateContains:]):
(-[EditingTestHarness _webView:editorStateDidChange:]):
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/EditorStateTests.mm: Added.
(TestWebKitAPI::setUpEditorStateTestHarness):
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKit2Cocoa/editor-state-test-harness.html: Added.
LayoutTests:
* platform/ios-wk2/editing/style/unbold-in-bold-expected.txt:
* platform/mac-wk2/editing/style/unbold-in-bold-expected.txt:
Rebaseline a WK2 LayoutTest expectations. This test currently expects an empty anonymous RenderBlock to be
inserted into the render tree, but this is only a result of us adding and removing a temporary <span> when
computing a RenderStyle in WebPage::editorState -- this patch removes these empty RenderBlocks, making these
expectations' RenderTrees consistent with WebKit1.
Canonical link: https://commits.webkit.org/192520@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221065 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-08-23 03:16:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)latestEditorStateContains:(NSDictionary<NSString *, id> *)entries
|
|
|
|
{
|
|
|
|
NSDictionary *latestEditorState = self.latestEditorState;
|
|
|
|
for (NSString *key in entries) {
|
|
|
|
if (![latestEditorState[key] isEqual:entries[key]])
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
return latestEditorState.count || !entries.count;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - WKUIDelegatePrivate
|
|
|
|
|
|
|
|
- (void)_webView:(WKWebView *)webView editorStateDidChange:(NSDictionary *)editorState
|
|
|
|
{
|
|
|
|
if (![editorState[@"post-layout-data"] boolValue])
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (![self.latestEditorState isEqualToDictionary:editorState])
|
|
|
|
[_editorStateHistory addObject:editorState];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|