Title: [181056] trunk
Revision
181056
Author
[email protected]
Date
2015-03-04 17:39:27 -0800 (Wed, 04 Mar 2015)

Log Message

<attachment> should show the file size as detail text below the icon
https://bugs.webkit.org/show_bug.cgi?id=142261
<rdar://problem/20009570>

Reviewed by Dean Jackson.

Test: fast/attachment/attachment-subtitle.html

* html/HTMLAttachmentElement.cpp:
(WebCore::HTMLAttachmentElement::setFile):
(WebCore::HTMLAttachmentElement::parseAttribute):
* html/HTMLAttachmentElement.h:
Let RenderAttachment know when the subtitle attribute changes.

* html/HTMLAttributeNames.in:
Add a subtitle attribute.

* rendering/RenderAttachment.cpp:
(WebCore::RenderAttachment::invalidate):
(WebCore::RenderAttachment::representedFileChanged): Deleted.
* rendering/RenderAttachment.h:
Rename representedFileChanged to invalidate; it will cause layout and
repaint of the attachment. Mostly for use from HTMLAttachmentElement,
when properties that affect the display and/or intrinsic size change.

* rendering/RenderThemeMac.mm:
(WebCore::attachmentTitleInactiveBackgroundColor):
(WebCore::attachmentTitleInactiveTextColor):
(WebCore::attachmentSubtitleTextColor):
(WebCore::titleTextColorForAttachment):
(WebCore::AttachmentLayout::addTitleLine):
(WebCore::AttachmentLayout::layOutTitle):
(WebCore::AttachmentLayout::layOutSubtitle):
(WebCore::AttachmentLayout::AttachmentLayout):
(WebCore::addAttachmentTitleBackgroundRightCorner):
(WebCore::addAttachmentTitleBackgroundLeftCorner):
(WebCore::paintAttachmentTitleBackground):
(WebCore::paintAttachmentTitle):
(WebCore::paintAttachmentSubtitle):
(WebCore::RenderThemeMac::paintAttachment):
(WebCore::attachmentLabelInactiveBackgroundColor): Deleted.
(WebCore::attachmentLabelInactiveTextColor): Deleted.
(WebCore::labelTextColorForAttachment): Deleted.
(WebCore::AttachmentLayout::addLine): Deleted.
(WebCore::AttachmentLayout::layOutLabel): Deleted.
(WebCore::addAttachmentLabelBackgroundRightCorner): Deleted.
(WebCore::addAttachmentLabelBackgroundLeftCorner): Deleted.
(WebCore::paintAttachmentLabelBackground): Deleted.
(WebCore::paintAttachmentLabel): Deleted.
Rename everything "label" to "title" (except LabelLine, which is not
specifically about the title). We're going to use "title" for the
main text below the icon, and "subtitle" for the secondary text below that.

Avoid keeping the CTFonts on the AttachmentLayout; there's no need for it.

Add layOutSubtitle and paintAttachmentSubtitle, which orient and paint
the subtitle (below the title, in blue, smaller than the label).

* fast/attachment/attachment-subtitle.html: Added.
* platform/mac/fast/attachment/attachment-subtitle-expected.png: Added.
* platform/mac/fast/attachment/attachment-subtitle-expected.txt: Added.
Add a test of the rendering of attachment subtitles, and results for Mac.

* platform/mac-mavericks/fast/attachment/attachment-subtitle-expected.txt: Added.
Add Mavericks baselines.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (181055 => 181056)


--- trunk/LayoutTests/ChangeLog	2015-03-05 01:19:57 UTC (rev 181055)
+++ trunk/LayoutTests/ChangeLog	2015-03-05 01:39:27 UTC (rev 181056)
@@ -1,3 +1,19 @@
+2015-03-04  Timothy Horton  <[email protected]>
+
+        <attachment> should show the file size as detail text below the icon
+        https://bugs.webkit.org/show_bug.cgi?id=142261
+        <rdar://problem/20009570>
+
+        Reviewed by Dean Jackson.
+
+        * fast/attachment/attachment-subtitle.html: Added.
+        * platform/mac/fast/attachment/attachment-subtitle-expected.png: Added.
+        * platform/mac/fast/attachment/attachment-subtitle-expected.txt: Added.
+        Add a test of the rendering of attachment subtitles, and results for Mac.
+
+        * platform/mac-mavericks/fast/attachment/attachment-subtitle-expected.txt: Added.
+        Add Mavericks baselines.
+
 2015-03-04  Alex Christensen  <[email protected]>
 
         Unreviewed gardening.

Added: trunk/LayoutTests/fast/attachment/attachment-subtitle.html (0 => 181056)


--- trunk/LayoutTests/fast/attachment/attachment-subtitle.html	                        (rev 0)
+++ trunk/LayoutTests/fast/attachment/attachment-subtitle.html	2015-03-05 01:39:27 UTC (rev 181056)
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<body>
+<attachment id="attachment" subtitle="1024 bytes"></attachment>
+<script>
+var file;
+if (window.internals)
+    file = window.internals.createFile("resources/test-file.txt");
+
+document.getElementById("attachment").file = file;
+</script>
+</body>
+</html>

Added: trunk/LayoutTests/platform/mac/fast/attachment/attachment-subtitle-expected.png


(Binary files differ)
Property changes on: trunk/LayoutTests/platform/mac/fast/attachment/attachment-subtitle-expected.png ___________________________________________________________________

Added: svn:mime-type

Added: trunk/LayoutTests/platform/mac/fast/attachment/attachment-subtitle-expected.txt (0 => 181056)


--- trunk/LayoutTests/platform/mac/fast/attachment/attachment-subtitle-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/fast/attachment/attachment-subtitle-expected.txt	2015-03-05 01:39:27 UTC (rev 181056)
@@ -0,0 +1,8 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x105
+  RenderBlock {HTML} at (0,0) size 800x105
+    RenderBody {BODY} at (8,8) size 784x89
+      RenderAttachment {ATTACHMENT} at (0,0) size 74x89
+      RenderText {#text} at (0,0) size 0x0
+      RenderText {#text} at (0,0) size 0x0

Added: trunk/LayoutTests/platform/mac-mavericks/fast/attachment/attachment-subtitle-expected.txt (0 => 181056)


--- trunk/LayoutTests/platform/mac-mavericks/fast/attachment/attachment-subtitle-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac-mavericks/fast/attachment/attachment-subtitle-expected.txt	2015-03-05 01:39:27 UTC (rev 181056)
@@ -0,0 +1,8 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x105
+  RenderBlock {HTML} at (0,0) size 800x105
+    RenderBody {BODY} at (8,8) size 784x89
+      RenderAttachment {ATTACHMENT} at (0,0) size 78x89
+      RenderText {#text} at (0,0) size 0x0
+      RenderText {#text} at (0,0) size 0x0

Modified: trunk/Source/WebCore/ChangeLog (181055 => 181056)


--- trunk/Source/WebCore/ChangeLog	2015-03-05 01:19:57 UTC (rev 181055)
+++ trunk/Source/WebCore/ChangeLog	2015-03-05 01:39:27 UTC (rev 181056)
@@ -1,3 +1,63 @@
+2015-03-04  Timothy Horton  <[email protected]>
+
+        <attachment> should show the file size as detail text below the icon
+        https://bugs.webkit.org/show_bug.cgi?id=142261
+        <rdar://problem/20009570>
+
+        Reviewed by Dean Jackson.
+
+        Test: fast/attachment/attachment-subtitle.html
+
+        * html/HTMLAttachmentElement.cpp:
+        (WebCore::HTMLAttachmentElement::setFile):
+        (WebCore::HTMLAttachmentElement::parseAttribute):
+        * html/HTMLAttachmentElement.h:
+        Let RenderAttachment know when the subtitle attribute changes.
+
+        * html/HTMLAttributeNames.in:
+        Add a subtitle attribute.
+
+        * rendering/RenderAttachment.cpp:
+        (WebCore::RenderAttachment::invalidate):
+        (WebCore::RenderAttachment::representedFileChanged): Deleted.
+        * rendering/RenderAttachment.h:
+        Rename representedFileChanged to invalidate; it will cause layout and
+        repaint of the attachment. Mostly for use from HTMLAttachmentElement,
+        when properties that affect the display and/or intrinsic size change.
+
+        * rendering/RenderThemeMac.mm:
+        (WebCore::attachmentTitleInactiveBackgroundColor):
+        (WebCore::attachmentTitleInactiveTextColor):
+        (WebCore::attachmentSubtitleTextColor):
+        (WebCore::titleTextColorForAttachment):
+        (WebCore::AttachmentLayout::addTitleLine):
+        (WebCore::AttachmentLayout::layOutTitle):
+        (WebCore::AttachmentLayout::layOutSubtitle):
+        (WebCore::AttachmentLayout::AttachmentLayout):
+        (WebCore::addAttachmentTitleBackgroundRightCorner):
+        (WebCore::addAttachmentTitleBackgroundLeftCorner):
+        (WebCore::paintAttachmentTitleBackground):
+        (WebCore::paintAttachmentTitle):
+        (WebCore::paintAttachmentSubtitle):
+        (WebCore::RenderThemeMac::paintAttachment):
+        (WebCore::attachmentLabelInactiveBackgroundColor): Deleted.
+        (WebCore::attachmentLabelInactiveTextColor): Deleted.
+        (WebCore::labelTextColorForAttachment): Deleted.
+        (WebCore::AttachmentLayout::addLine): Deleted.
+        (WebCore::AttachmentLayout::layOutLabel): Deleted.
+        (WebCore::addAttachmentLabelBackgroundRightCorner): Deleted.
+        (WebCore::addAttachmentLabelBackgroundLeftCorner): Deleted.
+        (WebCore::paintAttachmentLabelBackground): Deleted.
+        (WebCore::paintAttachmentLabel): Deleted.
+        Rename everything "label" to "title" (except LabelLine, which is not
+        specifically about the title). We're going to use "title" for the
+        main text below the icon, and "subtitle" for the secondary text below that.
+
+        Avoid keeping the CTFonts on the AttachmentLayout; there's no need for it.
+
+        Add layOutSubtitle and paintAttachmentSubtitle, which orient and paint
+        the subtitle (below the title, in blue, smaller than the label).
+
 2015-03-04  David Kilzer  <[email protected]>
 
         [Windows] Build fix: Make sure to include <CoreMedia/CoreMedia.h> before redefining CMSampleBuffer

Modified: trunk/Source/WebCore/html/HTMLAttachmentElement.cpp (181055 => 181056)


--- trunk/Source/WebCore/html/HTMLAttachmentElement.cpp	2015-03-05 01:19:57 UTC (rev 181055)
+++ trunk/Source/WebCore/html/HTMLAttachmentElement.cpp	2015-03-05 01:39:27 UTC (rev 181056)
@@ -69,9 +69,19 @@
     if (!is<RenderAttachment>(renderer))
         return;
 
-    downcast<RenderAttachment>(*renderer).representedFileChanged();
+    downcast<RenderAttachment>(*renderer).invalidate();
 }
 
+void HTMLAttachmentElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
+{
+    if (name == subtitleAttr && is<RenderAttachment>(renderer())) {
+        downcast<RenderAttachment>(*renderer()).invalidate();
+        return;
+    }
+
+    HTMLElement::parseAttribute(name, value);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(ATTACHMENT_ELEMENT)

Modified: trunk/Source/WebCore/html/HTMLAttachmentElement.h (181055 => 181056)


--- trunk/Source/WebCore/html/HTMLAttachmentElement.h	2015-03-05 01:19:57 UTC (rev 181055)
+++ trunk/Source/WebCore/html/HTMLAttachmentElement.h	2015-03-05 01:39:27 UTC (rev 181056)
@@ -47,6 +47,7 @@
     virtual RenderPtr<RenderElement> createElementRenderer(Ref<RenderStyle>&&) override;
 
     virtual bool canContainRangeEndPoint() const override { return false; }
+    virtual void parseAttribute(const QualifiedName&, const AtomicString&) override;
     
     RefPtr<File> m_file;
 };

Modified: trunk/Source/WebCore/html/HTMLAttributeNames.in (181055 => 181056)


--- trunk/Source/WebCore/html/HTMLAttributeNames.in	2015-03-05 01:19:57 UTC (rev 181055)
+++ trunk/Source/WebCore/html/HTMLAttributeNames.in	2015-03-05 01:39:27 UTC (rev 181056)
@@ -329,6 +329,7 @@
 start
 step
 style
+subtitle
 summary
 tabindex
 tableborder

Modified: trunk/Source/WebCore/rendering/RenderAttachment.cpp (181055 => 181056)


--- trunk/Source/WebCore/rendering/RenderAttachment.cpp	2015-03-05 01:19:57 UTC (rev 181055)
+++ trunk/Source/WebCore/rendering/RenderAttachment.cpp	2015-03-05 01:39:27 UTC (rev 181056)
@@ -64,7 +64,7 @@
     RenderReplaced::layout();
 }
 
-void RenderAttachment::representedFileChanged()
+void RenderAttachment::invalidate()
 {
     setNeedsLayout();
     repaint();

Modified: trunk/Source/WebCore/rendering/RenderAttachment.h (181055 => 181056)


--- trunk/Source/WebCore/rendering/RenderAttachment.h	2015-03-05 01:19:57 UTC (rev 181055)
+++ trunk/Source/WebCore/rendering/RenderAttachment.h	2015-03-05 01:39:27 UTC (rev 181056)
@@ -40,7 +40,7 @@
 
     HTMLAttachmentElement& attachmentElement() const;
 
-    void representedFileChanged();
+    void invalidate();
 
     bool isSelected() const;
 

Modified: trunk/Source/WebCore/rendering/RenderThemeMac.mm (181055 => 181056)


--- trunk/Source/WebCore/rendering/RenderThemeMac.mm	2015-03-05 01:19:57 UTC (rev 181055)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.mm	2015-03-05 01:39:27 UTC (rev 181056)
@@ -2078,20 +2078,23 @@
 const CGFloat attachmentIconBackgroundSize = attachmentIconSize + attachmentIconBackgroundPadding;
 const CGFloat attachmentIconSelectionBorderThickness = 1;
 const CGFloat attachmentIconBackgroundRadius = 3;
-const CGFloat attachmentIconToLabelMargin = 2;
+const CGFloat attachmentIconToTitleMargin = 2;
 
 static Color attachmentIconBackgroundColor() { return Color(0, 0, 0, 30); }
 static Color attachmentIconBorderColor() { return Color(255, 255, 255, 125); }
 
-const CGFloat attachmentLabelFontSize = 12;
-const CGFloat attachmentLabelBackgroundRadius = 3;
-const CGFloat attachmentLabelBackgroundPadding = 3;
-const CGFloat attachmentLabelMaximumWidth = 100 - (attachmentLabelBackgroundPadding * 2);
-const CFIndex attachmentLabelMaximumLineCount = 2;
+const CGFloat attachmentTitleFontSize = 12;
+const CGFloat attachmentTitleBackgroundRadius = 3;
+const CGFloat attachmentTitleBackgroundPadding = 3;
+const CGFloat attachmentTitleMaximumWidth = 100 - (attachmentTitleBackgroundPadding * 2);
+const CFIndex attachmentTitleMaximumLineCount = 2;
 
-static Color attachmentLabelInactiveBackgroundColor() { return Color(204, 204, 204, 255); }
-static Color attachmentLabelInactiveTextColor() { return Color(100, 100, 100, 255); }
+static Color attachmentTitleInactiveBackgroundColor() { return Color(204, 204, 204, 255); }
+static Color attachmentTitleInactiveTextColor() { return Color(100, 100, 100, 255); }
 
+const CGFloat attachmentSubtitleFontSize = 10;
+static Color attachmentSubtitleTextColor() { return Color(82, 145, 214, 255); }
+
 const CGFloat attachmentMargin = 3;
 
 struct AttachmentLayout {
@@ -2111,25 +2114,28 @@
 
     int baseline;
 
-    RetainPtr<CTFontRef> labelFont;
+    RetainPtr<CTLineRef> subtitleLine;
+    FloatRect subtitleTextRect;
 
 private:
-    void layOutLabel(const RenderAttachment&);
-    void addLine(CTLineRef, CGFloat& yOffset, Vector<CGPoint> origins, CFIndex lineIndex, const RenderAttachment&);
+    void layOutTitle(const RenderAttachment&);
+    void layOutSubtitle(const RenderAttachment&);
+
+    void addTitleLine(CTLineRef, CGFloat& yOffset, Vector<CGPoint> origins, CFIndex lineIndex, const RenderAttachment&);
 };
 
-static NSColor *labelTextColorForAttachment(const RenderAttachment& attachment)
+static NSColor *titleTextColorForAttachment(const RenderAttachment& attachment)
 {
     if (attachment.isSelected()) {
         if (attachment.frame().selection().isFocusedAndActive())
             return [NSColor alternateSelectedControlTextColor];    
-        return (NSColor *)cachedCGColor(attachmentLabelInactiveTextColor(), ColorSpaceDeviceRGB);
+        return (NSColor *)cachedCGColor(attachmentTitleInactiveTextColor(), ColorSpaceDeviceRGB);
     }
 
     return [NSColor blackColor];
 }
 
-void AttachmentLayout::addLine(CTLineRef line, CGFloat& yOffset, Vector<CGPoint> origins, CFIndex lineIndex, const RenderAttachment& attachment)
+void AttachmentLayout::addTitleLine(CTLineRef line, CGFloat& yOffset, Vector<CGPoint> origins, CFIndex lineIndex, const RenderAttachment& attachment)
 {
     CGRect lineBounds = CTLineGetBoundsWithOptions(line, 0);
     CGFloat trailingWhitespaceWidth = CTLineGetTrailingWhitespaceWidth(line);
@@ -2146,14 +2152,14 @@
     labelLine.origin = FloatPoint(xOffset, yOffset + lineHeight - origins.last().y);
     labelLine.line = line;
     labelLine.backgroundRect = FloatRect(xOffset, yOffset, lineWidthIgnoringTrailingWhitespace, lineHeight);
-    labelLine.backgroundRect.inflateX(attachmentLabelBackgroundPadding);
+    labelLine.backgroundRect.inflateX(attachmentTitleBackgroundPadding);
     labelLine.backgroundRect = encloseRectToDevicePixels(labelLine.backgroundRect, attachment.document().deviceScaleFactor());
 
     // If the text rects are close in size, the curved enclosing background won't
     // look right, so make them the same exact size.
     if (!lines.isEmpty()) {
         float previousBackgroundRectWidth = lines.last().backgroundRect.width();
-        if (fabs(labelLine.backgroundRect.width() - previousBackgroundRectWidth) < attachmentLabelBackgroundRadius * 4) {
+        if (fabs(labelLine.backgroundRect.width() - previousBackgroundRectWidth) < attachmentTitleBackgroundRadius * 4) {
             float newBackgroundRectWidth = std::max(previousBackgroundRectWidth, labelLine.backgroundRect.width());
             labelLine.backgroundRect.inflateX((newBackgroundRectWidth - labelLine.backgroundRect.width()) / 2);
             lines.last().backgroundRect.inflateX((newBackgroundRectWidth - previousBackgroundRectWidth) / 2);
@@ -2163,45 +2169,51 @@
     lines.append(labelLine);
 }
 
-void AttachmentLayout::layOutLabel(const RenderAttachment& attachment)
+void AttachmentLayout::layOutTitle(const RenderAttachment& attachment)
 {
+    RetainPtr<CTFontRef> font = adoptCF(CTFontCreateUIFontForLanguage(kCTFontSystemFontType, attachmentTitleFontSize, nullptr));
+    baseline = CGRound(attachmentIconBackgroundSize + attachmentIconToTitleMargin + CTFontGetAscent(font.get()));
+
     File* file = attachment.attachmentElement().file();
+    if (!file)
+        return;
+    String filename = file->name();
+    if (filename.isEmpty())
+        return;
 
-    labelFont = adoptCF(CTFontCreateUIFontForLanguage(kCTFontSystemFontType, attachmentLabelFontSize, nullptr));
-    String filename = file ? file->name() : String();
     NSDictionary *textAttributes = @{
-        (id)kCTFontAttributeName: (id)labelFont.get(),
-        (id)kCTForegroundColorAttributeName: labelTextColorForAttachment(attachment)
+        (id)kCTFontAttributeName: (id)font.get(),
+        (id)kCTForegroundColorAttributeName: titleTextColorForAttachment(attachment)
     };
     RetainPtr<NSAttributedString> attributedFilename = adoptNS([[NSAttributedString alloc] initWithString:filename attributes:textAttributes]);
-    RetainPtr<CTFramesetterRef> labelFramesetter = adoptCF(CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attributedFilename.get()));
+    RetainPtr<CTFramesetterRef> titleFramesetter = adoptCF(CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attributedFilename.get()));
 
     CFRange fitRange;
-    CGSize labelTextSize = CTFramesetterSuggestFrameSizeWithConstraints(labelFramesetter.get(), CFRangeMake(0, 0), nullptr, CGSizeMake(attachmentLabelMaximumWidth, CGFLOAT_MAX), &fitRange);
+    CGSize titleTextSize = CTFramesetterSuggestFrameSizeWithConstraints(titleFramesetter.get(), CFRangeMake(0, 0), nullptr, CGSizeMake(attachmentTitleMaximumWidth, CGFLOAT_MAX), &fitRange);
 
-    RetainPtr<CGPathRef> labelPath = adoptCF(CGPathCreateWithRect(CGRectMake(0, 0, labelTextSize.width, labelTextSize.height), nullptr));
-    RetainPtr<CTFrameRef> labelFrame = adoptCF(CTFramesetterCreateFrame(labelFramesetter.get(), fitRange, labelPath.get(), nullptr));
+    RetainPtr<CGPathRef> titlePath = adoptCF(CGPathCreateWithRect(CGRectMake(0, 0, titleTextSize.width, titleTextSize.height), nullptr));
+    RetainPtr<CTFrameRef> titleFrame = adoptCF(CTFramesetterCreateFrame(titleFramesetter.get(), fitRange, titlePath.get(), nullptr));
 
-    CFArrayRef ctLines = CTFrameGetLines(labelFrame.get());
+    CFArrayRef ctLines = CTFrameGetLines(titleFrame.get());
     CFIndex lineCount = CFArrayGetCount(ctLines);
     if (!lineCount)
         return;
 
     Vector<CGPoint> origins(lineCount);
-    CTFrameGetLineOrigins(labelFrame.get(), CFRangeMake(0, 0), origins.data());
+    CTFrameGetLineOrigins(titleFrame.get(), CFRangeMake(0, 0), origins.data());
 
-    // Lay out and record the first (attachmentLabelMaximumLineCount - 1) lines.
+    // Lay out and record the first (attachmentTitleMaximumLineCount - 1) lines.
     CFIndex lineIndex = 0;
-    CGFloat yOffset = attachmentIconBackgroundSize + attachmentIconToLabelMargin;
-    for (; lineIndex < std::min(attachmentLabelMaximumLineCount - 1, lineCount); ++lineIndex) {
+    CGFloat yOffset = attachmentIconBackgroundSize + attachmentIconToTitleMargin;
+    for (; lineIndex < std::min(attachmentTitleMaximumLineCount - 1, lineCount); ++lineIndex) {
         CTLineRef line = (CTLineRef)CFArrayGetValueAtIndex(ctLines, lineIndex);
-        addLine(line, yOffset, origins, lineIndex, attachment);
+        addTitleLine(line, yOffset, origins, lineIndex, attachment);
     }
 
     if (lineIndex == lineCount)
         return;
 
-    // We had text that didn't fit in the first (attachmentLabelMaximumLineCount - 1) lines.
+    // We had text that didn't fit in the first (attachmentTitleMaximumLineCount - 1) lines.
     // Combine it into one last line, and center-truncate it.
     CTLineRef firstRemainingLine = (CTLineRef)CFArrayGetValueAtIndex(ctLines, lineIndex);
     CFIndex remainingRangeStart = CTLineGetStringRange(firstRemainingLine).location;
@@ -2210,20 +2222,49 @@
     RetainPtr<CTLineRef> remainingLine = adoptCF(CTLineCreateWithAttributedString((CFAttributedStringRef)remainingString));
     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(), attachmentLabelMaximumWidth, kCTLineTruncationMiddle, ellipsisLine.get()));
+    RetainPtr<CTLineRef> truncatedLine = adoptCF(CTLineCreateTruncatedLine(remainingLine.get(), attachmentTitleMaximumWidth, kCTLineTruncationMiddle, ellipsisLine.get()));
 
     if (!truncatedLine)
         truncatedLine = remainingLine;
 
-    addLine(truncatedLine.get(), yOffset, origins, lineIndex, attachment);
+    addTitleLine(truncatedLine.get(), yOffset, origins, lineIndex, attachment);
 }
 
+void AttachmentLayout::layOutSubtitle(const RenderAttachment& attachment)
+{
+    String subtitleText = attachment.attachmentElement().fastGetAttribute(subtitleAttr);
+
+    if (subtitleText.isEmpty())
+        return;
+
+    RetainPtr<CTFontRef> font = adoptCF(CTFontCreateUIFontForLanguage(kCTFontSystemFontType, attachmentSubtitleFontSize, nullptr));
+    NSDictionary *textAttributes = @{
+        (id)kCTFontAttributeName: (id)font.get(),
+        (id)kCTForegroundColorAttributeName: (NSColor *)cachedCGColor(attachmentSubtitleTextColor(), ColorSpaceDeviceRGB)
+    };
+    RetainPtr<NSAttributedString> attributedSubtitleText = adoptNS([[NSAttributedString alloc] initWithString:subtitleText attributes:textAttributes]);
+    subtitleLine = adoptCF(CTLineCreateWithAttributedString((CFAttributedStringRef)attributedSubtitleText.get()));
+
+    CGRect lineBounds = CTLineGetBoundsWithOptions(subtitleLine.get(), 0);
+
+    // Center the line relative to the icon.
+    CGFloat xOffset = (attachmentIconBackgroundSize / 2) - (lineBounds.size.width / 2);
+    CGFloat yOffset = 0;
+
+    if (!lines.isEmpty())
+        yOffset = lines.last().backgroundRect.maxY();
+    else
+        yOffset = attachmentIconBackgroundSize + attachmentIconToTitleMargin;
+
+    LabelLine labelLine;
+    subtitleTextRect = FloatRect(xOffset, yOffset, lineBounds.size.width, lineBounds.size.height);
+}
+
 AttachmentLayout::AttachmentLayout(const RenderAttachment& attachment)
 {
-    layOutLabel(attachment);
+    layOutTitle(attachment);
+    layOutSubtitle(attachment);
 
-    baseline = CGRound(attachmentIconBackgroundSize + attachmentIconToLabelMargin + CTFontGetAscent(labelFont.get()));
-
     iconBackgroundRect = FloatRect(0, 0, attachmentIconBackgroundSize, attachmentIconBackgroundSize);
 
     iconRect = iconBackgroundRect;
@@ -2233,6 +2274,7 @@
     attachmentRect = iconBackgroundRect;
     for (const auto& line : lines)
         attachmentRect.unite(line.backgroundRect);
+    attachmentRect.unite(subtitleTextRect);
     attachmentRect.inflate(attachmentMargin);
     attachmentRect = encloseRectToDevicePixels(attachmentRect, attachment.document().deviceScaleFactor());
 }
@@ -2296,10 +2338,10 @@
     context.drawNativeImage(icon.get(), iconSizeInPoints, ColorSpaceDeviceRGB, layout.iconRect, FloatRect(FloatPoint(), iconSizeInPoints));
 }
 
-static void addAttachmentLabelBackgroundRightCorner(Path& path, const FloatRect* fromRect, const FloatRect* toRect)
+static void addAttachmentTitleBackgroundRightCorner(Path& path, const FloatRect* fromRect, const FloatRect* toRect)
 {
-    FloatSize horizontalRadius(attachmentLabelBackgroundRadius, 0);
-    FloatSize verticalRadius(0, attachmentLabelBackgroundRadius);
+    FloatSize horizontalRadius(attachmentTitleBackgroundRadius, 0);
+    FloatSize verticalRadius(0, attachmentTitleBackgroundRadius);
 
     if (!fromRect) {
         // For the first (top) rect:
@@ -2310,7 +2352,7 @@
         path.addLineTo(toRect->maxXMinYCorner() - horizontalRadius);
 
         // Arc the top corner.
-        path.addArcTo(toRect->maxXMinYCorner(), toRect->maxXMinYCorner() + verticalRadius, attachmentLabelBackgroundRadius);
+        path.addArcTo(toRect->maxXMinYCorner(), toRect->maxXMinYCorner() + verticalRadius, attachmentTitleBackgroundRadius);
 
         // Down the right.
         path.addLineTo(toRect->maxXMaxYCorner() - verticalRadius);
@@ -2318,7 +2360,7 @@
         // For the last rect:
 
         // Arc the bottom corner.
-        path.addArcTo(fromRect->maxXMaxYCorner(), fromRect->maxXMaxYCorner() - horizontalRadius, attachmentLabelBackgroundRadius);
+        path.addArcTo(fromRect->maxXMaxYCorner(), fromRect->maxXMaxYCorner() - horizontalRadius, attachmentTitleBackgroundRadius);
     } else {
         // For middle rects:
 
@@ -2331,22 +2373,22 @@
 
         if (widthDifference < 0) {
             // Arc the outer corner.
-            path.addArcTo(FloatPoint(fromRect->maxX(), toRect->y()), FloatPoint(fromRect->maxX(), toRect->y()) - horizontalRadius, attachmentLabelBackgroundRadius);
+            path.addArcTo(FloatPoint(fromRect->maxX(), toRect->y()), FloatPoint(fromRect->maxX(), toRect->y()) - horizontalRadius, attachmentTitleBackgroundRadius);
 
             // Across the bottom, towards the left.
             path.addLineTo(toRect->maxXMinYCorner() + horizontalRadius);
 
             // Arc the inner corner.
-            path.addArcTo(toRect->maxXMinYCorner(), toRect->maxXMinYCorner() + verticalRadius, attachmentLabelBackgroundRadius);
+            path.addArcTo(toRect->maxXMinYCorner(), toRect->maxXMinYCorner() + verticalRadius, attachmentTitleBackgroundRadius);
         } else {
             // Arc the inner corner.
-            path.addArcTo(FloatPoint(fromRect->maxX(), toRect->y()), FloatPoint(fromRect->maxX(), toRect->y()) + horizontalRadius, attachmentLabelBackgroundRadius);
+            path.addArcTo(FloatPoint(fromRect->maxX(), toRect->y()), FloatPoint(fromRect->maxX(), toRect->y()) + horizontalRadius, attachmentTitleBackgroundRadius);
 
             // Across the bottom, towards the right.
             path.addLineTo(toRect->maxXMinYCorner() - horizontalRadius);
 
             // Arc the outer corner.
-            path.addArcTo(toRect->maxXMinYCorner(), toRect->maxXMinYCorner() + verticalRadius, attachmentLabelBackgroundRadius);
+            path.addArcTo(toRect->maxXMinYCorner(), toRect->maxXMinYCorner() + verticalRadius, attachmentTitleBackgroundRadius);
         }
 
         // Down the right.
@@ -2354,10 +2396,10 @@
     }
 }
 
-static void addAttachmentLabelBackgroundLeftCorner(Path& path, const FloatRect* fromRect, const FloatRect* toRect)
+static void addAttachmentTitleBackgroundLeftCorner(Path& path, const FloatRect* fromRect, const FloatRect* toRect)
 {
-    FloatSize horizontalRadius(attachmentLabelBackgroundRadius, 0);
-    FloatSize verticalRadius(0, attachmentLabelBackgroundRadius);
+    FloatSize horizontalRadius(attachmentTitleBackgroundRadius, 0);
+    FloatSize verticalRadius(0, attachmentTitleBackgroundRadius);
 
     if (!fromRect) {
         // For the first (bottom) rect:
@@ -2366,7 +2408,7 @@
         path.addLineTo(toRect->minXMaxYCorner() + horizontalRadius);
 
         // Arc the bottom corner.
-        path.addArcTo(toRect->minXMaxYCorner(), toRect->minXMaxYCorner() - verticalRadius, attachmentLabelBackgroundRadius);
+        path.addArcTo(toRect->minXMaxYCorner(), toRect->minXMaxYCorner() - verticalRadius, attachmentTitleBackgroundRadius);
 
         // Up the left.
         path.addLineTo(toRect->minXMinYCorner() + verticalRadius);
@@ -2374,7 +2416,7 @@
         // For the last (top) rect:
 
         // Arc the top corner.
-        path.addArcTo(fromRect->minXMinYCorner(), fromRect->minXMinYCorner() + horizontalRadius, attachmentLabelBackgroundRadius);
+        path.addArcTo(fromRect->minXMinYCorner(), fromRect->minXMinYCorner() + horizontalRadius, attachmentTitleBackgroundRadius);
     } else {
         // For middle rects:
         float widthDifference = toRect->width() - fromRect->width();
@@ -2386,22 +2428,22 @@
 
         if (widthDifference < 0) {
             // Arc the inner corner.
-            path.addArcTo(FloatPoint(fromRect->x(), toRect->maxY()), FloatPoint(fromRect->x(), toRect->maxY()) + horizontalRadius, attachmentLabelBackgroundRadius);
+            path.addArcTo(FloatPoint(fromRect->x(), toRect->maxY()), FloatPoint(fromRect->x(), toRect->maxY()) + horizontalRadius, attachmentTitleBackgroundRadius);
 
             // Across the bottom, towards the right.
             path.addLineTo(toRect->minXMaxYCorner() - horizontalRadius);
 
             // Arc the outer corner.
-            path.addArcTo(toRect->minXMaxYCorner(), toRect->minXMaxYCorner() - verticalRadius, attachmentLabelBackgroundRadius);
+            path.addArcTo(toRect->minXMaxYCorner(), toRect->minXMaxYCorner() - verticalRadius, attachmentTitleBackgroundRadius);
         } else {
             // Arc the outer corner.
-            path.addArcTo(FloatPoint(fromRect->x(), toRect->maxY()), FloatPoint(fromRect->x(), toRect->maxY()) - horizontalRadius, attachmentLabelBackgroundRadius);
+            path.addArcTo(FloatPoint(fromRect->x(), toRect->maxY()), FloatPoint(fromRect->x(), toRect->maxY()) - horizontalRadius, attachmentTitleBackgroundRadius);
 
             // Across the bottom, towards the left.
             path.addLineTo(toRect->minXMaxYCorner() + horizontalRadius);
 
             // Arc the inner corner.
-            path.addArcTo(toRect->minXMaxYCorner(), toRect->minXMaxYCorner() - verticalRadius, attachmentLabelBackgroundRadius);
+            path.addArcTo(toRect->minXMaxYCorner(), toRect->minXMaxYCorner() - verticalRadius, attachmentTitleBackgroundRadius);
         }
         
         // Up the right.
@@ -2409,7 +2451,7 @@
     }
 }
 
-static void paintAttachmentLabelBackground(const RenderAttachment& attachment, GraphicsContext& context, AttachmentLayout& layout)
+static void paintAttachmentTitleBackground(const RenderAttachment& attachment, GraphicsContext& context, AttachmentLayout& layout)
 {
     if (layout.lines.isEmpty())
         return;
@@ -2417,11 +2459,11 @@
     Path backgroundPath;
 
     for (size_t i = 0; i <= layout.lines.size(); ++i)
-        addAttachmentLabelBackgroundRightCorner(backgroundPath, i ? &layout.lines[i - 1].backgroundRect : nullptr, i < layout.lines.size() ? &layout.lines[i].backgroundRect : nullptr);
+        addAttachmentTitleBackgroundRightCorner(backgroundPath, i ? &layout.lines[i - 1].backgroundRect : nullptr, i < layout.lines.size() ? &layout.lines[i].backgroundRect : nullptr);
 
     for (size_t i = 0; i <= layout.lines.size(); ++i) {
         size_t reverseIndex = layout.lines.size() - i;
-        addAttachmentLabelBackgroundLeftCorner(backgroundPath, reverseIndex < layout.lines.size() ? &layout.lines[reverseIndex].backgroundRect : nullptr, reverseIndex ? &layout.lines[reverseIndex - 1].backgroundRect : nullptr);
+        addAttachmentTitleBackgroundLeftCorner(backgroundPath, reverseIndex < layout.lines.size() ? &layout.lines[reverseIndex].backgroundRect : nullptr, reverseIndex ? &layout.lines[reverseIndex - 1].backgroundRect : nullptr);
     }
 
     backgroundPath.closeSubpath();
@@ -2430,13 +2472,13 @@
     if (attachment.frame().selection().isFocusedAndActive())
         backgroundColor = convertNSColorToColor([NSColor alternateSelectedControlColor]);
     else
-        backgroundColor = attachmentLabelInactiveBackgroundColor();
+        backgroundColor = attachmentTitleInactiveBackgroundColor();
 
     context.setFillColor(backgroundColor, ColorSpaceDeviceRGB);
     context.fillPath(backgroundPath);
 }
 
-static void paintAttachmentLabel(const RenderAttachment&, GraphicsContext& context, AttachmentLayout& layout) 
+static void paintAttachmentTitle(const RenderAttachment&, GraphicsContext& context, AttachmentLayout& layout)
 {
     for (const auto& line : layout.lines) {
         GraphicsContextStateSaver saver(context);
@@ -2449,6 +2491,17 @@
     }
 }
 
+static void paintAttachmentSubtitle(const RenderAttachment&, GraphicsContext& context, AttachmentLayout& layout)
+{
+    GraphicsContextStateSaver saver(context);
+
+    context.translate(toFloatSize(layout.subtitleTextRect.minXMaxYCorner()));
+    context.scale(FloatSize(1, -1));
+
+    CGContextSetTextMatrix(context.platformContext(), CGAffineTransformIdentity);
+    CTLineDraw(layout.subtitleLine.get(), context.platformContext());
+}
+
 bool RenderThemeMac::paintAttachment(const RenderObject& renderer, const PaintInfo& paintInfo, const IntRect& paintRect)
 {
     if (!is<RenderAttachment>(renderer))
@@ -2471,8 +2524,9 @@
         paintAttachmentIconBackground(attachment, context, layout);
     paintAttachmentIcon(attachment, context, layout);
     if (useSelectedStyle)
-        paintAttachmentLabelBackground(attachment, context, layout);
-    paintAttachmentLabel(attachment, context, layout);
+        paintAttachmentTitleBackground(attachment, context, layout);
+    paintAttachmentTitle(attachment, context, layout);
+    paintAttachmentSubtitle(attachment, context, layout);
 
     return true;
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to