[Cocoa] [WK2] Add support for text alignment and text lists in font attributes
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Oct 2018 01:52:49 +0000 (01:52 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Oct 2018 01:52:49 +0000 (01:52 +0000)
commitc29b32fd852345ec83daa89c46b86f93071b4c8b
tree3bfe55f4c9881f8b1193a1259fa0778798f11ec0
parent9d215ab82d14a98d9d68e91b6629b4bcd3af8275
[Cocoa] [WK2] Add support for text alignment and text lists in font attributes
https://bugs.webkit.org/show_bug.cgi?id=190342
<rdar://problem/44767118>

Reviewed by Tim Horton.

Source/WebCore:

Adds support for computing and encoding information about text alignment and enclosing list elements in the font
attributes dictionary, exposed to the UI delegate on Cocoa platforms. This is exposed through NSParagraphStyle,
which contains properties for both `NSTextAlignment` and an array of enclosing `NSTextList` objects.

Test:   FontAttributes.NestedTextListsWithHorizontalAlignment
        FontAttributes.FontAttributesAfterChangingSelection

* editing/Editor.cpp:
(WebCore::editableTextListsAtPositionInDescendingOrder):

Add a helper function to ascend the DOM, starting at the given position, in search of enclosing list elements.
For each enclosing list element we find within the scope of the editable root, we create a `TextList`
representing the list element.

(WebCore::Editor::fontAttributesAtSelectionStart const):

Compute and set enclosing text lists and text alignment. For text alignment, we convert the initial text-align
value, `start`, to NSTextAlignmentNatural (the default text alignment type on Cocoa platforms); other values
then map to Left, Right, Center, and Justified as expected (taking direction into account).

* editing/FontAttributes.h:
(WebCore::TextList::encode const):
(WebCore::TextList::decode):

Introduce TextList, a platform-agnostic representation of an unordered or ordered list. On Cocoa, this can be
used to construct a corresponding NSTextList.

* editing/cocoa/FontAttributesCocoa.mm:
(WebCore::cocoaTextListMarkerName):

Attempt to map a WebCore list style type to a `NSTextListMarker*` constant. While most of the Cocoa marker
formats have a corresponding web-exposed list style type, many web-exposed types have no Cocoa equivalent; as
such, fall back to default marker formats: "{disc}" for unordered lists and "{decimal}" for ordered lists.

(WebCore::TextList::createTextList const):
(WebCore::FontAttributes::createDictionary const):

Include an NSParagraphStyle in the dictionary of font attributes that includes information about text alignment
and enclosing text lists (per Cocoa convention, in order from outermost list to innermost list).

Source/WebCore/PAL:

* pal/ios/UIKitSoftLink.h:
* pal/ios/UIKitSoftLink.mm:

Add NSParagraphStyle and NSTextList to the UIKit soft link header.

* pal/spi/cocoa/NSAttributedStringSPI.h:
* pal/spi/ios/UIKitSPI.h:

Add some SPI declarations for NSMutableParagraphStyle and NSTextList when building with a non-internal iOS SDK,
and import <UIKit/NSParagraphStyle_Private.h> and <UIKit/NSTextList.h> when building with an internal iOS SDK.
Additionally, define some internal UIFoundation string constants that denote NSTextList marker formats. These
constants are API on macOS, but are neither exposed as API nor SPI on iOS.

Source/WebKit:

Add encoding and decoding for text alignment and text lists in FontAttributes.

* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<FontAttributes>::encode):
(IPC::ArgumentCoder<FontAttributes>::decode):

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/FontAttributes.mm:

Add a new API test to check that the font attributes dictionary contains the correct NSParagraphStyles when
moving the selection around text inside nested list elements.

(TestWebKitAPI::checkParagraphStyles):

Add a new helper to check an NSParagraphStyle against expected results.

(TestWebKitAPI::webViewForTestingFontAttributes):

Allow each test to pass in the name of the test page to load.

(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKitCocoa/nested-lists.html: Added.

Add a new test page that contains text enclosed in multiple levels of unordered and ordered lists.

* TestWebKitAPI/Tests/WebKitCocoa/rich-text-attributes.html:

Remove `text-align: left` from one of these elements, to test for NSTextAlignmentNatural.

LayoutTests:

* editing/mac/attributed-string/attributed-string-for-typing-expected.txt:
* editing/mac/attributed-string/attributed-string-for-typing-with-color-filter-expected.txt:
* platform/mac-sierra/editing/mac/attributed-string/attributed-string-for-typing-expected.txt:
* platform/mac-sierra/editing/mac/attributed-string/attributed-string-for-typing-with-color-filter-expected.txt:

Rebaseline these two layout tests, now that typing attributes include an NSParagraphStyle.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236955 268f45cc-cd09-0410-ab3c-d52691b4dbfc
21 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/mac/attributed-string/attributed-string-for-typing-expected.txt
LayoutTests/editing/mac/attributed-string/attributed-string-for-typing-with-color-filter-expected.txt
LayoutTests/platform/mac-sierra/editing/mac/attributed-string/attributed-string-for-typing-expected.txt
LayoutTests/platform/mac-sierra/editing/mac/attributed-string/attributed-string-for-typing-with-color-filter-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/PAL/ChangeLog
Source/WebCore/PAL/pal/ios/UIKitSoftLink.h
Source/WebCore/PAL/pal/ios/UIKitSoftLink.mm
Source/WebCore/PAL/pal/spi/cocoa/NSAttributedStringSPI.h
Source/WebCore/PAL/pal/spi/ios/UIKitSPI.h
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/FontAttributes.h
Source/WebCore/editing/cocoa/FontAttributesCocoa.mm
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebCoreArgumentCoders.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitCocoa/FontAttributes.mm
Tools/TestWebKitAPI/Tests/WebKitCocoa/nested-lists.html [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKitCocoa/rich-text-attributes.html