Skip to content
Permalink
Browse files
AX: Expose bold and italic font styling as text attributes for macOS
https://bugs.webkit.org/show_bug.cgi?id=249688
rdar://problem/103577386

Reviewed by Chris Fleizach.

Currently WebKit only exposes bold and italic properties of font styling for iOS.
This patch adds bold and italic font styling information to accessibility for macOS
by checking the bold and italic symbolic font traits in AXAttributedStringSetFont and
adding their result as AXFontBold and AXFontItalic font attributes.

* LayoutTests/accessibility/mac/attributed-string/attributed-string-text-styling-expected.txt: Added.
* LayoutTests/accessibility/mac/attributed-string/attributed-string-text-styling.html: Added.
* Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.mm:
(AXAttributedStringSetFont):

Canonical link: https://commits.webkit.org/258212@main
  • Loading branch information
tommymchugh authored and fleizach committed Dec 21, 2022
1 parent bf10c63 commit 9a11844523ca34c274cd4b361f9805010fc759ae
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
@@ -0,0 +1,19 @@
This test ensures that attributed string for text marker range includes text styling information.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


PASS textPlain.attributedStringForTextMarkerRange(textPlainRange) is textPlainAttributes
PASS textBold.attributedStringForTextMarkerRange(textBoldRange) is textBoldAttributes
PASS textItalic.attributedStringForTextMarkerRange(textItalicRange) is textItalicAttributes
PASS textBoldItalic.attributedStringForTextMarkerRange(textBoldItalicRange) is textBoldItalicAttributes
PASS successfullyParsed is true

TEST COMPLETE
The

Fox

Jumped

Over
@@ -0,0 +1,38 @@
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../../resources/accessibility-helper.js"></script>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<p id="text-plain">The</p>
<p id="text-bold" style="font-weight: bold">Fox</p>
<p id="text-italic" style="font-style: italic">Jumped</p>
<p id="text-bold-italic" style="font-style: italic; font-weight: bold;">Over</p>

<script>
description("This test ensures that attributed string for text marker range includes text styling information.");
if (window.accessibilityController) {
var textPlain = accessibilityController.accessibleElementById("text-plain");
var textPlainRange = textPlain.textMarkerRangeForElement(textPlain);
var textPlainAttributes = "AXFont - {\n AXFontFamily = Times;\n AXFontName = \"Times-Roman\";\n AXFontSize = 16;\n AXVisibleName = \"Times Roman\";\n}, The";
shouldBe("textPlain.attributedStringForTextMarkerRange(textPlainRange)", "textPlainAttributes");

var textBold = accessibilityController.accessibleElementById("text-bold");
var textBoldRange = textBold.textMarkerRangeForElement(textBold);
var textBoldAttributes = "AXFont - {\n AXFontBold = 1;\n AXFontFamily = Times;\n AXFontName = \"Times-Bold\";\n AXFontSize = 16;\n AXVisibleName = \"Times Bold\";\n}, Fox";
shouldBe("textBold.attributedStringForTextMarkerRange(textBoldRange)", "textBoldAttributes");

var textItalic = accessibilityController.accessibleElementById("text-italic");
var textItalicRange = textItalic.textMarkerRangeForElement(textItalic);
var textItalicAttributes = "AXFont - {\n AXFontFamily = Times;\n AXFontItalic = 1;\n AXFontName = \"Times-Italic\";\n AXFontSize = 16;\n AXVisibleName = \"Times Italic\";\n}, Jumped";
shouldBe("textItalic.attributedStringForTextMarkerRange(textItalicRange)", "textItalicAttributes");

var textBoldItalic = accessibilityController.accessibleElementById("text-bold-italic");
var textBoldItalicRange = textBoldItalic.textMarkerRangeForElement(textBoldItalic);
var textBoldItalicAttributes = "AXFont - {\n AXFontBold = 1;\n AXFontFamily = Times;\n AXFontItalic = 1;\n AXFontName = \"Times-BoldItalic\";\n AXFontSize = 16;\n AXVisibleName = \"Times Bold Italic\";\n}, Over";
shouldBe("textBoldItalic.attributedStringForTextMarkerRange(textBoldItalicRange)", "textBoldItalicAttributes");
}
</script>
</body>
</html>
@@ -19,6 +19,7 @@ Attributed string with range: ello
}worl{
AXBackgroundColor = " [ (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)] ( 0 0 0 0 )";
AXFont = {
AXFontBold = 1;
AXFontFamily = Times;
AXFontName = "Times-Bold";
AXFontSize = 16;
@@ -653,6 +653,11 @@ void AXAttributedStringSetFont(NSMutableAttributedString *attributedString, CTFo
auto displayName = adoptCF(CTFontCopyDisplayName(font));
if (displayName)
[fontAttributes setValue:bridge_cast(displayName.get()) forKey:NSAccessibilityVisibleNameKey];
auto traits = CTFontGetSymbolicTraits(font);
if (traits & kCTFontTraitBold)
[fontAttributes setValue:@YES forKey:@"AXFontBold"];
if (traits & kCTFontTraitItalic)
[fontAttributes setValue:@YES forKey:@"AXFontItalic"];

[attributedString addAttribute:NSAccessibilityFontTextAttribute value:fontAttributes.get() range:range];
#endif

0 comments on commit 9a11844

Please sign in to comment.