Changeset 265059 in webkit
- Timestamp:
- Jul 29, 2020 2:50:47 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r265056 r265059 1 2020-07-29 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [macOS] Inspector bar in Mail compose shows incorrect text alignment style for ranged selections 4 https://bugs.webkit.org/show_bug.cgi?id=214930 5 <rdar://problem/66185224> 6 7 Reviewed by Tim Horton. 8 9 When a range of text is selected, AppKit consults `-attributedSubstringForProposedRange:completionHandler:` (or 10 just `-attributedSubstringFromRange:` in WebKitLegacy) to update the inspector bar with new style information. 11 Among this information is the paragraph style (an `NSParagraphStyle` corresponding to the attribute key 12 `NSParagraphStyleAttributeName`), which AppKit uses to select either the left, center or right text alignment 13 segmented control. 14 15 However, in both WebKitLegacy and modern WebKit, we don't include this information at all in HTMLConverter, 16 so AppKit just defaults to using `-[NSParagraphStyle defaultParagraphStyle]`, with a default text alignment of 17 `NSTextAlignmentNatural`. 18 19 To fix this, include a new paragraph style object in the case where the text alignment is not equal to natural 20 (in other words, either a direction has been explicitly specified, or the text alignment style is not equal to 21 "start"). This paragraph style matches the default paragraph style, except for the `alignment` property which 22 is set to the corresponding `NSTextAlignment` value. 23 24 Tests: AttributedSubstringForProposedRange.TextAlignmentParagraphStyles 25 FontAttributes.FontAttributesAfterChangingSelection 26 27 * editing/Editor.cpp: 28 (WebCore::Editor::fontAttributesAtSelectionStart const): 29 30 Also fixes an existing bug in `Editor::fontAttributesAtSelectionStart`, where `NSTextAlignmentNatural` is 31 currently always used for `text-align: start;`, even if the direction is specified as RTL. Instead, change this 32 so that we only fall back to "natural" if no direction is specified; otherwise, go with the explicit "left" or 33 "right" values. 34 35 * editing/cocoa/HTMLConverter.mm: 36 (WebCore::editingAttributedString): 37 1 38 2020-07-29 Jer Noble <jer.noble@apple.com> 2 39 -
trunk/Source/WebCore/editing/Editor.cpp
r265044 r265059 4035 4035 break; 4036 4036 case TextAlignMode::Start: 4037 attributes.horizontalAlignment = FontAttributes::HorizontalAlignment::Natural; 4037 if (style->hasExplicitlySetDirection()) 4038 attributes.horizontalAlignment = style->isLeftToRightDirection() ? FontAttributes::HorizontalAlignment::Left : FontAttributes::HorizontalAlignment::Right; 4039 else 4040 attributes.horizontalAlignment = FontAttributes::HorizontalAlignment::Natural; 4038 4041 break; 4039 4042 case TextAlignMode::End: -
trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm
r262683 r265059 2410 2410 [attrs setObject:[fontManager convertFont:WebDefaultFont() toSize:style.fontCascade().primaryFont().platformData().size()] forKey:NSFontAttributeName]; 2411 2411 2412 auto textAlignment = NSTextAlignmentNatural; 2413 switch (style.textAlign()) { 2414 case TextAlignMode::Right: 2415 case TextAlignMode::WebKitRight: 2416 textAlignment = NSTextAlignmentRight; 2417 break; 2418 case TextAlignMode::Left: 2419 case TextAlignMode::WebKitLeft: 2420 textAlignment = NSTextAlignmentLeft; 2421 break; 2422 case TextAlignMode::Center: 2423 case TextAlignMode::WebKitCenter: 2424 textAlignment = NSTextAlignmentCenter; 2425 break; 2426 case TextAlignMode::Justify: 2427 textAlignment = NSTextAlignmentJustified; 2428 break; 2429 case TextAlignMode::Start: 2430 if (style.hasExplicitlySetDirection()) 2431 textAlignment = style.isLeftToRightDirection() ? NSTextAlignmentLeft : NSTextAlignmentRight; 2432 break; 2433 case TextAlignMode::End: 2434 textAlignment = style.isLeftToRightDirection() ? NSTextAlignmentRight : NSTextAlignmentLeft; 2435 break; 2436 default: 2437 ASSERT_NOT_REACHED(); 2438 break; 2439 } 2440 2441 if (textAlignment != NSTextAlignmentNatural) { 2442 auto paragraphStyle = adoptNS(NSParagraphStyle.defaultParagraphStyle.mutableCopy); 2443 [paragraphStyle setAlignment:textAlignment]; 2444 [attrs setObject:paragraphStyle.get() forKey:NSParagraphStyleAttributeName]; 2445 } 2446 2412 2447 Color foregroundColor = style.visitedDependentColorWithColorFilter(CSSPropertyColor); 2413 2448 if (foregroundColor.isVisible()) -
trunk/Tools/ChangeLog
r265058 r265059 1 2020-07-29 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [macOS] Inspector bar in Mail compose shows incorrect text alignment style for ranged selections 4 https://bugs.webkit.org/show_bug.cgi?id=214930 5 <rdar://problem/66185224> 6 7 Reviewed by Tim Horton. 8 9 Add a new API test and adjust an existing test to verify the codechange. 10 11 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 12 * TestWebKitAPI/Tests/TestWebKitAPI/mac/AppKitSPI.h: 13 * TestWebKitAPI/Tests/WebKitCocoa/FontAttributes.mm: 14 (TestWebKitAPI::TEST): 15 * TestWebKitAPI/Tests/WebKitCocoa/rich-text-attributes.html: 16 * TestWebKitAPI/Tests/mac/AttributedSubstringForProposedRange.mm: Added. 17 (TEST): 18 1 19 2020-07-29 Jonathan Bedard <jbedard@apple.com> 2 20 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r264937 r265059 1167 1167 F4F5BB5221667BAA002D06B9 /* TestFontOptions.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4F5BB5121667BAA002D06B9 /* TestFontOptions.mm */; }; 1168 1168 F4FA282A24CD012700618A46 /* FormValidation.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4FA282924CD012700618A46 /* FormValidation.mm */; }; 1169 F4FA2A4F24D1F05700618A46 /* AttributedSubstringForProposedRange.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4FA2A4E24D1F05700618A46 /* AttributedSubstringForProposedRange.mm */; }; 1169 1170 F4FA91811E61849B007B8C1D /* WKWebViewMacEditingTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4FA917F1E61849B007B8C1D /* WKWebViewMacEditingTests.mm */; }; 1170 1171 F4FA91831E61857B007B8C1D /* double-click-does-not-select-trailing-space.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4FA91821E618566007B8C1D /* double-click-does-not-select-trailing-space.html */; }; … … 2880 2881 F4F5BB5121667BAA002D06B9 /* TestFontOptions.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = TestFontOptions.mm; sourceTree = "<group>"; }; 2881 2882 F4FA282924CD012700618A46 /* FormValidation.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FormValidation.mm; sourceTree = "<group>"; }; 2883 F4FA2A4E24D1F05700618A46 /* AttributedSubstringForProposedRange.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AttributedSubstringForProposedRange.mm; sourceTree = "<group>"; }; 2882 2884 F4FA917F1E61849B007B8C1D /* WKWebViewMacEditingTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewMacEditingTests.mm; sourceTree = "<group>"; }; 2883 2885 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; }; … … 4338 4340 55F9D2E42205031800A9AB38 /* AdditionalSupportedImageTypes.mm */, 4339 4341 B55F119F1516834F00915916 /* AttributedString.mm */, 4342 F4FA2A4E24D1F05700618A46 /* AttributedSubstringForProposedRange.mm */, 4340 4343 00CD9F6215BE312C002DA2CE /* BackForwardList.mm */, 4341 4344 1C7FEB1F207C0F2D00D23278 /* BackgroundColor.mm */, … … 4937 4940 834138C7203261CA00F26960 /* AsyncPolicyForNavigationResponse.mm in Sources */, 4938 4941 7CCE7EB41A411A7E00447C4C /* AttributedString.mm in Sources */, 4942 F4FA2A4F24D1F05700618A46 /* AttributedSubstringForProposedRange.mm in Sources */, 4939 4943 3760C4F1211249AF00233ACC /* AttrStyle.mm in Sources */, 4940 4944 CDED342F249DDE0E0002AE7A /* AudioRoutingArbitration.mm in Sources */, … … 5017 5021 7CCE7EEA1A411AE600447C4C /* DidNotHandleKeyDown.cpp in Sources */, 5018 5022 AD57AC211DA7465B00FF1BDE /* DidRemoveFrameFromHiearchyInPageCache.cpp in Sources */, 5023 FEC2A85424CE975F00ADBC35 /* DisallowVMEntry.cpp in Sources */, 5019 5024 73BD731823A846500020F450 /* DisplayName.mm in Sources */, 5020 5025 518EE51B20A78D0000E024F3 /* DoAfterNextPresentationUpdateAfterCrash.mm in Sources */, … … 5248 5253 83A2CFDE2481B3520018B2D3 /* ProcessSuspension.mm in Sources */, 5249 5254 518C1153205B0504001FF4AE /* ProcessSwapOnNavigation.mm in Sources */, 5255 FEC2A85624CEB65F00ADBC35 /* PropertySlot.cpp in Sources */, 5250 5256 7C83E0C11D0A652F00FEBCF3 /* ProvisionalURLNotChange.mm in Sources */, 5251 5257 5CFACF65226FD2DC0056C7D0 /* Proxy.mm in Sources */, 5252 5258 041A1E34216FFDBC00789E0A /* PublicSuffix.cpp in Sources */, 5253 FEC2A85424CE975F00ADBC35 /* DisallowVMEntry.cpp in Sources */,5254 5259 7C83E0C21D0A653500FEBCF3 /* QuickLook.mm in Sources */, 5255 5260 6B4E861C2220A5520022F389 /* RegistrableDomain.cpp in Sources */, … … 5436 5441 5E4B1D2E1D404C6100053621 /* WKScrollViewDelegate.mm in Sources */, 5437 5442 F43E3BBF20DADA1E00A4E7ED /* WKScrollViewTests.mm in Sources */, 5438 FEC2A85624CEB65F00ADBC35 /* PropertySlot.cpp in Sources */,5439 5443 4628C8E92367ABD100B073F0 /* WKSecurityOrigin.cpp in Sources */, 5440 5444 7CCE7F221A411AE600447C4C /* WKString.cpp in Sources */, -
trunk/Tools/TestWebKitAPI/Tests/TestWebKitAPI/mac/AppKitSPI.h
r261320 r265059 40 40 - (void)markedRangeWithCompletionHandler:(void(^)(NSRange markedRange))completionHandler; 41 41 - (void)hasMarkedTextWithCompletionHandler:(void(^)(BOOL hasMarkedText))completionHandler; 42 - (void)attributedSubstringForProposedRange:(NSRange)range completionHandler:(void(^)(NSAttributedString *, NSRange actualRange))completionHandler; 42 43 @end 43 44 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/FontAttributes.mm
r242339 r265059 338 338 EXPECT_EQ(0, [attributes[NSSuperscriptAttributeName] integerValue]); 339 339 } 340 { 341 [webView selectElementWithIdentifier:@"eleven"]; 342 NSDictionary *attributes = [webView fontAttributesAfterNextPresentationUpdate]; 343 checkColor(attributes[NSForegroundColorAttributeName], { }); 344 checkColor(attributes[NSBackgroundColorAttributeName], { }); 345 checkFont(attributes[NSFontAttributeName], { "Menlo-Regular", 20 }); 346 checkShadow(attributes[NSShadowAttributeName], { }); 347 checkParagraphStyles(attributes[NSParagraphStyleAttributeName], { NSTextAlignmentRight, { } }); 348 EXPECT_EQ(NSUnderlineStyleNone, [attributes[NSStrikethroughStyleAttributeName] integerValue]); 349 EXPECT_EQ(NSUnderlineStyleNone, [attributes[NSUnderlineStyleAttributeName] integerValue]); 350 EXPECT_EQ(0, [attributes[NSSuperscriptAttributeName] integerValue]); 351 } 340 352 } 341 353 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/rich-text-attributes.html
r236955 r265059 30 30 <span id="ten" style="font-family: Avenir-Book; font-size: 18px; font-style: oblique;">Ten</span> 31 31 </div> 32 <div id="eleven" dir="rtl" style="text-align: start; font-family: Menlo; font-size: 20px;">Eleven</div> 32 33 </div> 33 34 </body>
Note: See TracChangeset
for help on using the changeset viewer.