- Revision
- 265059
- Author
- wenson_hs...@apple.com
- Date
- 2020-07-29 14:50:47 -0700 (Wed, 29 Jul 2020)
Log Message
[macOS] Inspector bar in Mail compose shows incorrect text alignment style for ranged selections
https://bugs.webkit.org/show_bug.cgi?id=214930
<rdar://problem/66185224>
Reviewed by Tim Horton.
Source/WebCore:
When a range of text is selected, AppKit consults `-attributedSubstringForProposedRange:completionHandler:` (or
just `-attributedSubstringFromRange:` in WebKitLegacy) to update the inspector bar with new style information.
Among this information is the paragraph style (an `NSParagraphStyle` corresponding to the attribute key
`NSParagraphStyleAttributeName`), which AppKit uses to select either the left, center or right text alignment
segmented control.
However, in both WebKitLegacy and modern WebKit, we don't include this information at all in HTMLConverter,
so AppKit just defaults to using `-[NSParagraphStyle defaultParagraphStyle]`, with a default text alignment of
`NSTextAlignmentNatural`.
To fix this, include a new paragraph style object in the case where the text alignment is not equal to natural
(in other words, either a direction has been explicitly specified, or the text alignment style is not equal to
"start"). This paragraph style matches the default paragraph style, except for the `alignment` property which
is set to the corresponding `NSTextAlignment` value.
Tests: AttributedSubstringForProposedRange.TextAlignmentParagraphStyles
FontAttributes.FontAttributesAfterChangingSelection
* editing/Editor.cpp:
(WebCore::Editor::fontAttributesAtSelectionStart const):
Also fixes an existing bug in `Editor::fontAttributesAtSelectionStart`, where `NSTextAlignmentNatural` is
currently always used for `text-align: start;`, even if the direction is specified as RTL. Instead, change this
so that we only fall back to "natural" if no direction is specified; otherwise, go with the explicit "left" or
"right" values.
* editing/cocoa/HTMLConverter.mm:
(WebCore::editingAttributedString):
Tools:
Add a new API test and adjust an existing test to verify the codechange.
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/TestWebKitAPI/mac/AppKitSPI.h:
* TestWebKitAPI/Tests/WebKitCocoa/FontAttributes.mm:
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKitCocoa/rich-text-attributes.html:
* TestWebKitAPI/Tests/mac/AttributedSubstringForProposedRange.mm: Added.
(TEST):
Modified Paths
Added Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (265058 => 265059)
--- trunk/Source/WebCore/ChangeLog 2020-07-29 21:50:02 UTC (rev 265058)
+++ trunk/Source/WebCore/ChangeLog 2020-07-29 21:50:47 UTC (rev 265059)
@@ -1,3 +1,40 @@
+2020-07-29 Wenson Hsieh <wenson_hs...@apple.com>
+
+ [macOS] Inspector bar in Mail compose shows incorrect text alignment style for ranged selections
+ https://bugs.webkit.org/show_bug.cgi?id=214930
+ <rdar://problem/66185224>
+
+ Reviewed by Tim Horton.
+
+ When a range of text is selected, AppKit consults `-attributedSubstringForProposedRange:completionHandler:` (or
+ just `-attributedSubstringFromRange:` in WebKitLegacy) to update the inspector bar with new style information.
+ Among this information is the paragraph style (an `NSParagraphStyle` corresponding to the attribute key
+ `NSParagraphStyleAttributeName`), which AppKit uses to select either the left, center or right text alignment
+ segmented control.
+
+ However, in both WebKitLegacy and modern WebKit, we don't include this information at all in HTMLConverter,
+ so AppKit just defaults to using `-[NSParagraphStyle defaultParagraphStyle]`, with a default text alignment of
+ `NSTextAlignmentNatural`.
+
+ To fix this, include a new paragraph style object in the case where the text alignment is not equal to natural
+ (in other words, either a direction has been explicitly specified, or the text alignment style is not equal to
+ "start"). This paragraph style matches the default paragraph style, except for the `alignment` property which
+ is set to the corresponding `NSTextAlignment` value.
+
+ Tests: AttributedSubstringForProposedRange.TextAlignmentParagraphStyles
+ FontAttributes.FontAttributesAfterChangingSelection
+
+ * editing/Editor.cpp:
+ (WebCore::Editor::fontAttributesAtSelectionStart const):
+
+ Also fixes an existing bug in `Editor::fontAttributesAtSelectionStart`, where `NSTextAlignmentNatural` is
+ currently always used for `text-align: start;`, even if the direction is specified as RTL. Instead, change this
+ so that we only fall back to "natural" if no direction is specified; otherwise, go with the explicit "left" or
+ "right" values.
+
+ * editing/cocoa/HTMLConverter.mm:
+ (WebCore::editingAttributedString):
+
2020-07-29 Jer Noble <jer.no...@apple.com>
REGRESSION(r264476): Calling systemHasAC() regresses launch time performance
Modified: trunk/Source/WebCore/editing/Editor.cpp (265058 => 265059)
--- trunk/Source/WebCore/editing/Editor.cpp 2020-07-29 21:50:02 UTC (rev 265058)
+++ trunk/Source/WebCore/editing/Editor.cpp 2020-07-29 21:50:47 UTC (rev 265059)
@@ -4034,7 +4034,10 @@
attributes.horizontalAlignment = FontAttributes::HorizontalAlignment::Justify;
break;
case TextAlignMode::Start:
- attributes.horizontalAlignment = FontAttributes::HorizontalAlignment::Natural;
+ if (style->hasExplicitlySetDirection())
+ attributes.horizontalAlignment = style->isLeftToRightDirection() ? FontAttributes::HorizontalAlignment::Left : FontAttributes::HorizontalAlignment::Right;
+ else
+ attributes.horizontalAlignment = FontAttributes::HorizontalAlignment::Natural;
break;
case TextAlignMode::End:
attributes.horizontalAlignment = style->isLeftToRightDirection() ? FontAttributes::HorizontalAlignment::Right : FontAttributes::HorizontalAlignment::Left;
Modified: trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm (265058 => 265059)
--- trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm 2020-07-29 21:50:02 UTC (rev 265058)
+++ trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm 2020-07-29 21:50:47 UTC (rev 265059)
@@ -2409,6 +2409,41 @@
else
[attrs setObject:[fontManager convertFont:WebDefaultFont() toSize:style.fontCascade().primaryFont().platformData().size()] forKey:NSFontAttributeName];
+ auto textAlignment = NSTextAlignmentNatural;
+ switch (style.textAlign()) {
+ case TextAlignMode::Right:
+ case TextAlignMode::WebKitRight:
+ textAlignment = NSTextAlignmentRight;
+ break;
+ case TextAlignMode::Left:
+ case TextAlignMode::WebKitLeft:
+ textAlignment = NSTextAlignmentLeft;
+ break;
+ case TextAlignMode::Center:
+ case TextAlignMode::WebKitCenter:
+ textAlignment = NSTextAlignmentCenter;
+ break;
+ case TextAlignMode::Justify:
+ textAlignment = NSTextAlignmentJustified;
+ break;
+ case TextAlignMode::Start:
+ if (style.hasExplicitlySetDirection())
+ textAlignment = style.isLeftToRightDirection() ? NSTextAlignmentLeft : NSTextAlignmentRight;
+ break;
+ case TextAlignMode::End:
+ textAlignment = style.isLeftToRightDirection() ? NSTextAlignmentRight : NSTextAlignmentLeft;
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ break;
+ }
+
+ if (textAlignment != NSTextAlignmentNatural) {
+ auto paragraphStyle = adoptNS(NSParagraphStyle.defaultParagraphStyle.mutableCopy);
+ [paragraphStyle setAlignment:textAlignment];
+ [attrs setObject:paragraphStyle.get() forKey:NSParagraphStyleAttributeName];
+ }
+
Color foregroundColor = style.visitedDependentColorWithColorFilter(CSSPropertyColor);
if (foregroundColor.isVisible())
[attrs setObject:nsColor(foregroundColor) forKey:NSForegroundColorAttributeName];
Modified: trunk/Tools/ChangeLog (265058 => 265059)
--- trunk/Tools/ChangeLog 2020-07-29 21:50:02 UTC (rev 265058)
+++ trunk/Tools/ChangeLog 2020-07-29 21:50:47 UTC (rev 265059)
@@ -1,3 +1,21 @@
+2020-07-29 Wenson Hsieh <wenson_hs...@apple.com>
+
+ [macOS] Inspector bar in Mail compose shows incorrect text alignment style for ranged selections
+ https://bugs.webkit.org/show_bug.cgi?id=214930
+ <rdar://problem/66185224>
+
+ Reviewed by Tim Horton.
+
+ Add a new API test and adjust an existing test to verify the codechange.
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/TestWebKitAPI/mac/AppKitSPI.h:
+ * TestWebKitAPI/Tests/WebKitCocoa/FontAttributes.mm:
+ (TestWebKitAPI::TEST):
+ * TestWebKitAPI/Tests/WebKitCocoa/rich-text-attributes.html:
+ * TestWebKitAPI/Tests/mac/AttributedSubstringForProposedRange.mm: Added.
+ (TEST):
+
2020-07-29 Jonathan Bedard <jbed...@apple.com>
[webkitcorepy] Add an auto-installer (Unreviewed follow-up fix)
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (265058 => 265059)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2020-07-29 21:50:02 UTC (rev 265058)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2020-07-29 21:50:47 UTC (rev 265059)
@@ -1166,6 +1166,7 @@
F4F405BD1D4C0D1C007A9707 /* skinny-autoplaying-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4F405BB1D4C0CF8007A9707 /* skinny-autoplaying-video-with-audio.html */; };
F4F5BB5221667BAA002D06B9 /* TestFontOptions.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4F5BB5121667BAA002D06B9 /* TestFontOptions.mm */; };
F4FA282A24CD012700618A46 /* FormValidation.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4FA282924CD012700618A46 /* FormValidation.mm */; };
+ F4FA2A4F24D1F05700618A46 /* AttributedSubstringForProposedRange.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4FA2A4E24D1F05700618A46 /* AttributedSubstringForProposedRange.mm */; };
F4FA91811E61849B007B8C1D /* WKWebViewMacEditingTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4FA917F1E61849B007B8C1D /* WKWebViewMacEditingTests.mm */; };
F4FA91831E61857B007B8C1D /* double-click-does-not-select-trailing-space.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4FA91821E618566007B8C1D /* double-click-does-not-select-trailing-space.html */; };
F4FC077720F013B600CA043C /* significant-text-milestone.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4FC077620F0108100CA043C /* significant-text-milestone.html */; };
@@ -2879,6 +2880,7 @@
F4F5BB5021667BAA002D06B9 /* TestFontOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TestFontOptions.h; sourceTree = "<group>"; };
F4F5BB5121667BAA002D06B9 /* TestFontOptions.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = TestFontOptions.mm; sourceTree = "<group>"; };
F4FA282924CD012700618A46 /* FormValidation.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FormValidation.mm; sourceTree = "<group>"; };
+ F4FA2A4E24D1F05700618A46 /* AttributedSubstringForProposedRange.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AttributedSubstringForProposedRange.mm; sourceTree = "<group>"; };
F4FA917F1E61849B007B8C1D /* WKWebViewMacEditingTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewMacEditingTests.mm; sourceTree = "<group>"; };
F4FA91821E618566007B8C1D /* double-click-does-not-select-trailing-space.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = "double-click-does-not-select-trailing-space.html"; path = "Tests/WebKitCocoa/double-click-does-not-select-trailing-space.html"; sourceTree = SOURCE_ROOT; };
F4FC077620F0108100CA043C /* significant-text-milestone.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "significant-text-milestone.html"; sourceTree = "<group>"; };
@@ -4337,6 +4339,7 @@
379028B514FABD92007E6B43 /* AcceptsFirstMouse.mm */,
55F9D2E42205031800A9AB38 /* AdditionalSupportedImageTypes.mm */,
B55F119F1516834F00915916 /* AttributedString.mm */,
+ F4FA2A4E24D1F05700618A46 /* AttributedSubstringForProposedRange.mm */,
00CD9F6215BE312C002DA2CE /* BackForwardList.mm */,
1C7FEB1F207C0F2D00D23278 /* BackgroundColor.mm */,
26DF5A5D15A29BAA003689C2 /* CancelLoadFromResourceLoadDelegate.mm */,
@@ -4936,6 +4939,7 @@
51B40D9E23AC962400E05241 /* AsyncFunction.mm in Sources */,
834138C7203261CA00F26960 /* AsyncPolicyForNavigationResponse.mm in Sources */,
7CCE7EB41A411A7E00447C4C /* AttributedString.mm in Sources */,
+ F4FA2A4F24D1F05700618A46 /* AttributedSubstringForProposedRange.mm in Sources */,
3760C4F1211249AF00233ACC /* AttrStyle.mm in Sources */,
CDED342F249DDE0E0002AE7A /* AudioRoutingArbitration.mm in Sources */,
CDC8E48D1BC5CB4500594FEC /* AudioSessionCategoryIOS.mm in Sources */,
@@ -5016,6 +5020,7 @@
7CCE7EE91A411AE600447C4C /* DidAssociateFormControls.cpp in Sources */,
7CCE7EEA1A411AE600447C4C /* DidNotHandleKeyDown.cpp in Sources */,
AD57AC211DA7465B00FF1BDE /* DidRemoveFrameFromHiearchyInPageCache.cpp in Sources */,
+ FEC2A85424CE975F00ADBC35 /* DisallowVMEntry.cpp in Sources */,
73BD731823A846500020F450 /* DisplayName.mm in Sources */,
518EE51B20A78D0000E024F3 /* DoAfterNextPresentationUpdateAfterCrash.mm in Sources */,
2D7FD19322419087007887F1 /* DocumentEditingContext.mm in Sources */,
@@ -5247,10 +5252,10 @@
CDA4438E21F7A47700379489 /* ProcessSuspendMediaBuffering.mm in Sources */,
83A2CFDE2481B3520018B2D3 /* ProcessSuspension.mm in Sources */,
518C1153205B0504001FF4AE /* ProcessSwapOnNavigation.mm in Sources */,
+ FEC2A85624CEB65F00ADBC35 /* PropertySlot.cpp in Sources */,
7C83E0C11D0A652F00FEBCF3 /* ProvisionalURLNotChange.mm in Sources */,
5CFACF65226FD2DC0056C7D0 /* Proxy.mm in Sources */,
041A1E34216FFDBC00789E0A /* PublicSuffix.cpp in Sources */,
- FEC2A85424CE975F00ADBC35 /* DisallowVMEntry.cpp in Sources */,
7C83E0C21D0A653500FEBCF3 /* QuickLook.mm in Sources */,
6B4E861C2220A5520022F389 /* RegistrableDomain.cpp in Sources */,
7CCE7F0D1A411AE600447C4C /* ReloadPageAfterCrash.cpp in Sources */,
@@ -5435,7 +5440,6 @@
7C83E0B51D0A649300FEBCF3 /* WKRetainPtr.cpp in Sources */,
5E4B1D2E1D404C6100053621 /* WKScrollViewDelegate.mm in Sources */,
F43E3BBF20DADA1E00A4E7ED /* WKScrollViewTests.mm in Sources */,
- FEC2A85624CEB65F00ADBC35 /* PropertySlot.cpp in Sources */,
4628C8E92367ABD100B073F0 /* WKSecurityOrigin.cpp in Sources */,
7CCE7F221A411AE600447C4C /* WKString.cpp in Sources */,
7CCE7F1E1A411AE600447C4C /* WKStringJSString.cpp in Sources */,
Modified: trunk/Tools/TestWebKitAPI/Tests/TestWebKitAPI/mac/AppKitSPI.h (265058 => 265059)
--- trunk/Tools/TestWebKitAPI/Tests/TestWebKitAPI/mac/AppKitSPI.h 2020-07-29 21:50:02 UTC (rev 265058)
+++ trunk/Tools/TestWebKitAPI/Tests/TestWebKitAPI/mac/AppKitSPI.h 2020-07-29 21:50:47 UTC (rev 265059)
@@ -39,6 +39,7 @@
- (void)selectedRangeWithCompletionHandler:(void(^)(NSRange selectedRange))completionHandler;
- (void)markedRangeWithCompletionHandler:(void(^)(NSRange markedRange))completionHandler;
- (void)hasMarkedTextWithCompletionHandler:(void(^)(BOOL hasMarkedText))completionHandler;
+- (void)attributedSubstringForProposedRange:(NSRange)range completionHandler:(void(^)(NSAttributedString *, NSRange actualRange))completionHandler;
@end
@protocol NSInspectorBarClient <NSObject>
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/FontAttributes.mm (265058 => 265059)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/FontAttributes.mm 2020-07-29 21:50:02 UTC (rev 265058)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/FontAttributes.mm 2020-07-29 21:50:47 UTC (rev 265059)
@@ -337,6 +337,18 @@
EXPECT_EQ(NSUnderlineStyleNone, [attributes[NSUnderlineStyleAttributeName] integerValue]);
EXPECT_EQ(0, [attributes[NSSuperscriptAttributeName] integerValue]);
}
+ {
+ [webView selectElementWithIdentifier:@"eleven"];
+ NSDictionary *attributes = [webView fontAttributesAfterNextPresentationUpdate];
+ checkColor(attributes[NSForegroundColorAttributeName], { });
+ checkColor(attributes[NSBackgroundColorAttributeName], { });
+ checkFont(attributes[NSFontAttributeName], { "Menlo-Regular", 20 });
+ checkShadow(attributes[NSShadowAttributeName], { });
+ checkParagraphStyles(attributes[NSParagraphStyleAttributeName], { NSTextAlignmentRight, { } });
+ EXPECT_EQ(NSUnderlineStyleNone, [attributes[NSStrikethroughStyleAttributeName] integerValue]);
+ EXPECT_EQ(NSUnderlineStyleNone, [attributes[NSUnderlineStyleAttributeName] integerValue]);
+ EXPECT_EQ(0, [attributes[NSSuperscriptAttributeName] integerValue]);
+ }
}
TEST(FontAttributes, NestedTextListsWithHorizontalAlignment)
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/rich-text-attributes.html (265058 => 265059)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/rich-text-attributes.html 2020-07-29 21:50:02 UTC (rev 265058)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/rich-text-attributes.html 2020-07-29 21:50:47 UTC (rev 265059)
@@ -29,6 +29,7 @@
<div style="text-align: right;">
<span id="ten" style="font-family: Avenir-Book; font-size: 18px; font-style: oblique;">Ten</span>
</div>
+ <div id="eleven" dir="rtl" style="text-align: start; font-family: Menlo; font-size: 20px;">Eleven</div>
</div>
</body>
</html>
Added: trunk/Tools/TestWebKitAPI/Tests/mac/AttributedSubstringForProposedRange.mm (0 => 265059)
--- trunk/Tools/TestWebKitAPI/Tests/mac/AttributedSubstringForProposedRange.mm (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/AttributedSubstringForProposedRange.mm 2020-07-29 21:50:47 UTC (rev 265059)
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+#import "config.h"
+
+#if PLATFORM(MAC)
+
+#import "AppKitSPI.h"
+#import "PlatformUtilities.h"
+#import "TestWKWebView.h"
+#import <wtf/RetainPtr.h>
+
+TEST(AttributedSubstringForProposedRange, TextAlignmentParagraphStyles)
+{
+ NSString *markup = @"<!DOCTYPE html>"
+ "<meta charset='utf8'>"
+ "<body contenteditable>"
+ "<div>Default</div>"
+ "<div style='text-align: right;'>Right</div>"
+ "<div style='text-align: center;'>Center</div>"
+ "<div style='text-align: left;'>Left</div>"
+ "<div style='text-align: justify;'>Justify</div>"
+ "<div style='text-align: start;' dir='rtl'>Start + RTL</div>"
+ "<div style='text-align: end;' dir='rtl'>End + RTL</div>"
+ "<div style='text-align: end;' dir='ltr'>End + LTR</div>"
+ "<div style='text-align: start;' dir='ltr'>Start + LTR</div>"
+ "</body>"
+ "<script>getSelection().setPosition(document.body)</script>";
+
+ auto webView = adoptNS([[TestWKWebView<NSTextInputClient_Async> alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+ [webView synchronouslyLoadHTMLString:markup];
+
+ __block bool finished = false;
+ [webView attributedSubstringForProposedRange:NSMakeRange(0, NSUIntegerMax) completionHandler:^(NSAttributedString *string, NSRange actualRange) {
+ EXPECT_EQ(0U, actualRange.location);
+ EXPECT_EQ(77U, actualRange.length);
+
+ auto textAlignmentForSubstring = [&](NSString *substring) -> NSTextAlignment {
+ NSRange range = [string.string rangeOfString:substring];
+ EXPECT_GT(range.length, 0U);
+
+ __block RetainPtr<NSParagraphStyle> result;
+ [string enumerateAttribute:NSParagraphStyleAttributeName inRange:range options:0 usingBlock:^(NSParagraphStyle *style, NSRange, BOOL *) {
+ result = style;
+ }];
+ return result ? [result alignment] : NSTextAlignmentNatural;
+ };
+
+ EXPECT_EQ(NSTextAlignmentNatural, textAlignmentForSubstring(@"Default"));
+ EXPECT_EQ(NSTextAlignmentRight, textAlignmentForSubstring(@"Right"));
+ EXPECT_EQ(NSTextAlignmentCenter, textAlignmentForSubstring(@"Center"));
+ EXPECT_EQ(NSTextAlignmentLeft, textAlignmentForSubstring(@"Left"));
+ EXPECT_EQ(NSTextAlignmentJustified, textAlignmentForSubstring(@"Justify"));
+ EXPECT_EQ(NSTextAlignmentRight, textAlignmentForSubstring(@"Start + RTL"));
+ EXPECT_EQ(NSTextAlignmentLeft, textAlignmentForSubstring(@"End + RTL"));
+ EXPECT_EQ(NSTextAlignmentRight, textAlignmentForSubstring(@"End + LTR"));
+ EXPECT_EQ(NSTextAlignmentLeft, textAlignmentForSubstring(@"Start + LTR"));
+
+ finished = true;
+ }];
+ TestWebKitAPI::Util::run(&finished);
+}
+
+#endif // PLATFORM(MAC)