Title: [237403] trunk
Revision
237403
Author
[email protected]
Date
2018-10-24 15:51:03 -0700 (Wed, 24 Oct 2018)

Log Message

Attachment filenames with RTL characters should format similar to Finder
https://bugs.webkit.org/show_bug.cgi?id=190736
<rdar://problem/44735946>

Reviewed by Dan Bernstein.

Source/WebCore:

Test: fast/attachment/attachment-title-with-rtl.html

* html/HTMLAttachmentElement.cpp:
(WebCore::HTMLAttachmentElement::attachmentTitleForDisplay const):
* html/HTMLAttachmentElement.h:
Add attachmentTitleForDisplay(), which wraps the non-extension part of
attachmentTitle in BiDi isolates, matching Finder's behavior.

* rendering/RenderThemeIOS.mm:
(WebCore::RenderAttachmentInfo::buildWrappedLines):
(WebCore::RenderAttachmentInfo::RenderAttachmentInfo):
* rendering/RenderThemeMac.mm:
(WebCore::AttachmentLayout::layOutTitle):
Adopt attachmentTitleForDisplay, and ask CoreText to use a subrange of
the original string for the last line, instead of splitting the string
ourselves. This ensures that BiDi control characters are respected
even in the last line of the string.

LayoutTests:

* fast/attachment/attachment-title-with-rtl-expected.html: Added.
* fast/attachment/attachment-title-with-rtl.html: Added.
Add a test that directionality marks in the attachment's title are
isolated from the file extension.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (237402 => 237403)


--- trunk/LayoutTests/ChangeLog	2018-10-24 22:28:42 UTC (rev 237402)
+++ trunk/LayoutTests/ChangeLog	2018-10-24 22:51:03 UTC (rev 237403)
@@ -1,3 +1,16 @@
+2018-10-24  Tim Horton  <[email protected]>
+
+        Attachment filenames with RTL characters should format similar to Finder
+        https://bugs.webkit.org/show_bug.cgi?id=190736
+        <rdar://problem/44735946>
+
+        Reviewed by Dan Bernstein.
+
+        * fast/attachment/attachment-title-with-rtl-expected.html: Added.
+        * fast/attachment/attachment-title-with-rtl.html: Added.
+        Add a test that directionality marks in the attachment's title are
+        isolated from the file extension.
+
 2018-10-24  Megan Gardner  <[email protected]>
 
         Turn on Conic Gradients

Added: trunk/LayoutTests/fast/attachment/attachment-title-with-rtl-expected.html (0 => 237403)


--- trunk/LayoutTests/fast/attachment/attachment-title-with-rtl-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/attachment/attachment-title-with-rtl-expected.html	2018-10-24 22:51:03 UTC (rev 237403)
@@ -0,0 +1,8 @@
+<!DOCTYPE html><!-- webkit-test-runner [ enableAttachmentElement=true ] -->
+<html>
+<body>
+<attachment title="isolate.ext"></attachment>
+<attachment title="isolate-isolate.ext"></attachment>
+<attachment title="long-title-wraps-abc.ext"></attachment>
+</body>
+</html>

Added: trunk/LayoutTests/fast/attachment/attachment-title-with-rtl.html (0 => 237403)


--- trunk/LayoutTests/fast/attachment/attachment-title-with-rtl.html	                        (rev 0)
+++ trunk/LayoutTests/fast/attachment/attachment-title-with-rtl.html	2018-10-24 22:51:03 UTC (rev 237403)
@@ -0,0 +1,8 @@
+<!DOCTYPE html><!-- webkit-test-runner [ enableAttachmentElement=true ] -->
+<html>
+<body>
+<attachment title="&#x202E;etalosi.ext"></attachment>
+<attachment title="isolate-&#x202E;etalosi.ext"></attachment>
+<attachment title="long-title-wraps-&#x202E;cba.ext"></attachment>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (237402 => 237403)


--- trunk/Source/WebCore/ChangeLog	2018-10-24 22:28:42 UTC (rev 237402)
+++ trunk/Source/WebCore/ChangeLog	2018-10-24 22:51:03 UTC (rev 237403)
@@ -1,3 +1,29 @@
+2018-10-24  Tim Horton  <[email protected]>
+
+        Attachment filenames with RTL characters should format similar to Finder
+        https://bugs.webkit.org/show_bug.cgi?id=190736
+        <rdar://problem/44735946>
+
+        Reviewed by Dan Bernstein.
+
+        Test: fast/attachment/attachment-title-with-rtl.html
+
+        * html/HTMLAttachmentElement.cpp:
+        (WebCore::HTMLAttachmentElement::attachmentTitleForDisplay const):
+        * html/HTMLAttachmentElement.h:
+        Add attachmentTitleForDisplay(), which wraps the non-extension part of
+        attachmentTitle in BiDi isolates, matching Finder's behavior.
+
+        * rendering/RenderThemeIOS.mm:
+        (WebCore::RenderAttachmentInfo::buildWrappedLines):
+        (WebCore::RenderAttachmentInfo::RenderAttachmentInfo):
+        * rendering/RenderThemeMac.mm:
+        (WebCore::AttachmentLayout::layOutTitle):
+        Adopt attachmentTitleForDisplay, and ask CoreText to use a subrange of
+        the original string for the last line, instead of splitting the string
+        ourselves. This ensures that BiDi control characters are respected
+        even in the last line of the string.
+
 2018-10-24  Megan Gardner  <[email protected]>
 
         Turn on Conic Gradients

Modified: trunk/Source/WebCore/html/HTMLAttachmentElement.cpp (237402 => 237403)


--- trunk/Source/WebCore/html/HTMLAttachmentElement.cpp	2018-10-24 22:28:42 UTC (rev 237402)
+++ trunk/Source/WebCore/html/HTMLAttachmentElement.cpp	2018-10-24 22:51:03 UTC (rev 237403)
@@ -160,6 +160,27 @@
     return m_file ? m_file->name() : String();
 }
 
+String HTMLAttachmentElement::attachmentTitleForDisplay() const
+{
+    auto title = attachmentTitle();
+
+    auto indexOfLastDot = title.reverseFind('.');
+    if (indexOfLastDot == notFound)
+        return title;
+
+    String name = title.left(indexOfLastDot);
+    String extension = title.substring(indexOfLastDot);
+
+    StringBuilder builder;
+    builder.append(leftToRightMark);
+    builder.append(firstStrongIsolate);
+    builder.append(name);
+    builder.append(popDirectionalIsolate);
+    builder.append(extension);
+
+    return builder.toString();
+}
+
 String HTMLAttachmentElement::attachmentType() const
 {
     return attributeWithoutSynchronization(typeAttr);

Modified: trunk/Source/WebCore/html/HTMLAttachmentElement.h (237402 => 237403)


--- trunk/Source/WebCore/html/HTMLAttachmentElement.h	2018-10-24 22:28:42 UTC (rev 237402)
+++ trunk/Source/WebCore/html/HTMLAttachmentElement.h	2018-10-24 22:51:03 UTC (rev 237403)
@@ -61,6 +61,7 @@
     bool hasEnclosingImage() const;
 
     WEBCORE_EXPORT String attachmentTitle() const;
+    String attachmentTitleForDisplay() const;
     String attachmentType() const;
     String attachmentPath() const;
 

Modified: trunk/Source/WebCore/rendering/RenderThemeIOS.mm (237402 => 237403)


--- trunk/Source/WebCore/rendering/RenderThemeIOS.mm	2018-10-24 22:28:42 UTC (rev 237402)
+++ trunk/Source/WebCore/rendering/RenderThemeIOS.mm	2018-10-24 22:51:03 UTC (rev 237403)
@@ -1609,12 +1609,13 @@
     // Combine it into one last line, and center-truncate it.
     CTLineRef firstRemainingLine = (CTLineRef)CFArrayGetValueAtIndex(ctLines, lineIndex);
     CFIndex remainingRangeStart = CTLineGetStringRange(firstRemainingLine).location;
-    NSRange remainingRange = NSMakeRange(remainingRangeStart, [attributedText length] - remainingRangeStart);
-    NSAttributedString *remainingString = [attributedText attributedSubstringFromRange:remainingRange];
-    RetainPtr<CTLineRef> remainingLine = adoptCF(CTLineCreateWithAttributedString((CFAttributedStringRef)remainingString));
+    CFRange remainingRange = CFRangeMake(remainingRangeStart, [attributedText length] - remainingRangeStart);
+    RetainPtr<CGPathRef> remainingPath = adoptCF(CGPathCreateWithRect(CGRectMake(0, 0, CGFLOAT_MAX, CGFLOAT_MAX), nullptr));
+    RetainPtr<CTFrameRef> remainingFrame = adoptCF(CTFramesetterCreateFrame(framesetter.get(), remainingRange, remainingPath.get(), nullptr));
     RetainPtr<NSAttributedString> ellipsisString = adoptNS([[NSAttributedString alloc] initWithString:@"\u2026" attributes:textAttributes]);
     RetainPtr<CTLineRef> ellipsisLine = adoptCF(CTLineCreateWithAttributedString((CFAttributedStringRef)ellipsisString.get()));
-    RetainPtr<CTLineRef> truncatedLine = adoptCF(CTLineCreateTruncatedLine(remainingLine.get(), attachmentWrappingTextMaximumWidth, kCTLineTruncationMiddle, ellipsisLine.get()));
+    CTLineRef remainingLine = (CTLineRef)CFArrayGetValueAtIndex(CTFrameGetLines(remainingFrame.get()), 0);
+    RetainPtr<CTLineRef> truncatedLine = adoptCF(CTLineCreateTruncatedLine(remainingLine, attachmentWrappingTextMaximumWidth, kCTLineTruncationMiddle, ellipsisLine.get()));
 
     if (!truncatedLine)
         truncatedLine = remainingLine;
@@ -1703,7 +1704,7 @@
 
     hasProgress = getAttachmentProgress(attachment, progress);
 
-    String title = attachment.attachmentElement().attachmentTitle();
+    String title = attachment.attachmentElement().attachmentTitleForDisplay();
     String action = ""
     String subtitle = attachment.attachmentElement().attributeWithoutSynchronization(subtitleAttr);
 

Modified: trunk/Source/WebCore/rendering/RenderThemeMac.mm (237402 => 237403)


--- trunk/Source/WebCore/rendering/RenderThemeMac.mm	2018-10-24 22:28:42 UTC (rev 237402)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.mm	2018-10-24 22:51:03 UTC (rev 237403)
@@ -2637,7 +2637,7 @@
     RetainPtr<CTFontRef> font = adoptCF(CTFontCreateUIFontForLanguage(kCTFontUIFontSystem, attachmentTitleFontSize, language));
     baseline = CGRound(attachmentIconBackgroundSize + attachmentIconToTitleMargin + CTFontGetAscent(font.get()));
 
-    String title = attachment.attachmentElement().attachmentTitle();
+    String title = attachment.attachmentElement().attachmentTitleForDisplay();
     if (title.isEmpty())
         return;
 
@@ -2677,12 +2677,13 @@
     // Combine it into one last line, and center-truncate it.
     CTLineRef firstRemainingLine = (CTLineRef)CFArrayGetValueAtIndex(ctLines, lineIndex);
     CFIndex remainingRangeStart = CTLineGetStringRange(firstRemainingLine).location;
-    NSRange remainingRange = NSMakeRange(remainingRangeStart, [attributedTitle length] - remainingRangeStart);
-    NSAttributedString *remainingString = [attributedTitle attributedSubstringFromRange:remainingRange];
-    RetainPtr<CTLineRef> remainingLine = adoptCF(CTLineCreateWithAttributedString((CFAttributedStringRef)remainingString));
+    CFRange remainingRange = CFRangeMake(remainingRangeStart, [attributedTitle length] - remainingRangeStart);
+    RetainPtr<CGPathRef> remainingPath = adoptCF(CGPathCreateWithRect(CGRectMake(0, 0, CGFLOAT_MAX, CGFLOAT_MAX), nullptr));
+    RetainPtr<CTFrameRef> remainingFrame = adoptCF(CTFramesetterCreateFrame(titleFramesetter.get(), remainingRange, remainingPath.get(), nullptr));
     RetainPtr<NSAttributedString> ellipsisString = adoptNS([[NSAttributedString alloc] initWithString:@"\u2026" attributes:textAttributes]);
     RetainPtr<CTLineRef> ellipsisLine = adoptCF(CTLineCreateWithAttributedString((CFAttributedStringRef)ellipsisString.get()));
-    RetainPtr<CTLineRef> truncatedLine = adoptCF(CTLineCreateTruncatedLine(remainingLine.get(), attachmentTitleMaximumWidth, kCTLineTruncationMiddle, ellipsisLine.get()));
+    CTLineRef remainingLine = (CTLineRef)CFArrayGetValueAtIndex(CTFrameGetLines(remainingFrame.get()), 0);
+    RetainPtr<CTLineRef> truncatedLine = adoptCF(CTLineCreateTruncatedLine(remainingLine, attachmentTitleMaximumWidth, kCTLineTruncationMiddle, ellipsisLine.get()));
 
     if (!truncatedLine)
         truncatedLine = remainingLine;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to