<attachment>'s label baseline should match that of the surrounding text
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Feb 2015 21:56:43 +0000 (21:56 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Feb 2015 21:56:43 +0000 (21:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142099
rdar://problem/19982495

Reviewed by Dan Bernstein.

* rendering/RenderAttachment.cpp:
(WebCore::RenderAttachment::baselinePosition):
* rendering/RenderAttachment.h:
Override baselinePosition and retrieve it from RenderTheme.

* rendering/RenderTheme.h:
(WebCore::RenderTheme::attachmentBaseline):
* rendering/RenderThemeMac.h:
* rendering/RenderThemeMac.mm:
(WebCore::AttachmentLayout::AttachmentLayout):
(WebCore::RenderThemeMac::attachmentBaseline):
Plumb the label baseline from AttachmentLayout to RenderAttachment.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180780 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderAttachment.cpp
Source/WebCore/rendering/RenderAttachment.h
Source/WebCore/rendering/RenderTheme.h
Source/WebCore/rendering/RenderThemeMac.h
Source/WebCore/rendering/RenderThemeMac.mm

index 2a4f72a..bf02f1b 100644 (file)
@@ -1,3 +1,24 @@
+2015-02-27  Timothy Horton  <timothy_horton@apple.com>
+
+        <attachment>'s label baseline should match that of the surrounding text
+        https://bugs.webkit.org/show_bug.cgi?id=142099
+        rdar://problem/19982495
+
+        Reviewed by Dan Bernstein.
+
+        * rendering/RenderAttachment.cpp:
+        (WebCore::RenderAttachment::baselinePosition):
+        * rendering/RenderAttachment.h:
+        Override baselinePosition and retrieve it from RenderTheme.
+
+        * rendering/RenderTheme.h:
+        (WebCore::RenderTheme::attachmentBaseline):
+        * rendering/RenderThemeMac.h:
+        * rendering/RenderThemeMac.mm:
+        (WebCore::AttachmentLayout::AttachmentLayout):
+        (WebCore::RenderThemeMac::attachmentBaseline):
+        Plumb the label baseline from AttachmentLayout to RenderAttachment.
+
 2015-02-27  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r180752.
index 3228078..cf99a44 100644 (file)
@@ -80,6 +80,11 @@ void RenderAttachment::representedFileChanged()
     repaint();
 }
 
+int RenderAttachment::baselinePosition(FontBaseline, bool, LineDirectionMode, LinePositionMode) const
+{
+    return document().page()->theme().attachmentBaseline(*this);
+}
+
 } // namespace WebCore
 
 #endif
index 67a1407..b68a09a 100644 (file)
@@ -56,6 +56,8 @@ private:
 
     bool isSelected() const;
     bool isFocused() const;
+
+    virtual int baselinePosition(FontBaseline, bool, LineDirectionMode, LinePositionMode) const;
 };
 
 } // namespace WebCore
index 0c0d3b0..92246f5 100644 (file)
@@ -252,6 +252,7 @@ public:
 
 #if ENABLE(ATTACHMENT_ELEMENT)
     virtual LayoutSize attachmentIntrinsicSize(const RenderAttachment&) const { return LayoutSize(); }
+    virtual int attachmentBaseline(const RenderAttachment&) const { return -1; }
 #endif
 
 protected:
index e70e0a5..0900f4a 100644 (file)
@@ -170,6 +170,7 @@ protected:
 
 #if ENABLE(ATTACHMENT_ELEMENT)
     virtual LayoutSize attachmentIntrinsicSize(const RenderAttachment&) const override;
+    virtual int attachmentBaseline(const RenderAttachment&) const override;
     virtual bool paintAttachment(const RenderObject&, const PaintInfo&, const IntRect&) override;
 #endif
 
index 039b120..ba62d7c 100644 (file)
@@ -25,6 +25,7 @@
 #import "CSSValueKeywords.h"
 #import "CSSValueList.h"
 #import "ColorMac.h"
+#import "CoreGraphicsSPI.h"
 #import "Document.h"
 #import "Element.h"
 #import "ExceptionCodePlaceholder.h"
@@ -2096,6 +2097,8 @@ struct AttachmentLayout {
     FloatRect iconBackgroundRect;
     FloatRect attachmentRect;
 
+    int baseline;
+
     RetainPtr<CTFontRef> labelFont;
     FontCascade labelFontCascade;
     std::unique_ptr<TextRun> labelTextRun;
@@ -2117,6 +2120,8 @@ AttachmentLayout::AttachmentLayout(const RenderAttachment& attachment)
     float textHeight = labelFontCascade.fontMetrics().height();
     float xOffset = (attachmentIconBackgroundSize / 2) - (textWidth / 2);
 
+    baseline = CGRound(attachmentIconBackgroundSize + attachmentIconToLabelMargin + labelFontCascade.fontMetrics().ascent());
+
     textRect = FloatRect(xOffset, attachmentIconBackgroundSize + attachmentIconToLabelMargin, textWidth, textHeight);
     textBackgroundRect = textRect;
     textBackgroundRect.inflateX(attachmentLabelBackgroundPadding);
@@ -2140,6 +2145,12 @@ LayoutSize RenderThemeMac::attachmentIntrinsicSize(const RenderAttachment& attac
     return LayoutSize(layout.attachmentRect.size());
 }
 
+int RenderThemeMac::attachmentBaseline(const RenderAttachment& attachment) const
+{
+    AttachmentLayout layout(attachment);
+    return layout.baseline;
+}
+
 static void paintAttachmentIconBackground(const RenderAttachment&, GraphicsContext& context, AttachmentLayout& layout)
 {
     // FIXME: Finder has a discontinuous behavior here when you have a background color other than white,