[Attachment Support] Attachment elements don't appear in drag images on macOS
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Aug 2018 17:20:37 +0000 (17:20 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Aug 2018 17:20:37 +0000 (17:20 +0000)
commit093f2205b465bd3e05bbc8c42656e434c3cc75f2
tree03400c18a5124df888e5537addacd8f4b001ab6a
parent66c49108e40700855a28b3cc2c63f19be6189ff1
[Attachment Support] Attachment elements don't appear in drag images on macOS
https://bugs.webkit.org/show_bug.cgi?id=188823
<rdar://problem/43616378>

Reviewed by Tim Horton.

Source/WebCore:

Currently, attachment elements don't show up in the drag image snapshot on macOS. This is because only the
"Selection" phase is painted when generating a drag image on macOS, and many replaced renderers (with some
exceptions, such as RenderImage) only paint visible content during the "Foreground" phase. To fix this, we
override RenderAttachment::paintReplaced to paint the attachment in the case where the Selection phase is being
painted.

Tests:  WKAttachmentTestsMac.DragAttachmentAsFilePromise
        WKAttachmentTests.MoveAttachmentElementAsIconByDragging

* rendering/RenderAttachment.cpp:
(WebCore::RenderAttachment::paintReplaced):
* rendering/RenderAttachment.h:
* rendering/RenderThemeMac.mm:
(WebCore::titleTextColorForAttachment):
(WebCore::AttachmentLayout::layOutTitle):

Plumb an AttachmentLayoutStyle (i.e. NonSelected or Selected) to AttachmentLayout, and use this bit when
determining the title text color, as well whether to paint backgrounds for the icon and title.

(WebCore::AttachmentLayout::AttachmentLayout):
(WebCore::RenderThemeMac::attachmentIntrinsicSize const):
(WebCore::RenderThemeMac::attachmentBaseline const):
(WebCore::paintAttachmentIconBackground):
(WebCore::paintAttachmentTitleBackground):

Bail from painting backgrounds if a selected style is used for the attachment.

(WebCore::RenderThemeMac::paintAttachment):

Rather than check the RenderAttachment's selection state when determining whether to paint with a non-selected
or selected style, only use selected style if the RenderAttachment has a selection _and_ the painting phase is
not "Selection". While this sounds extremely counter-intuitive, the "Selection" painting phase refers to
painting the selected foreground content _without_ including any part of the selection highlight.

Tools:

Adjusts a couple of existing tests to additionally verify that the drag image generated when dragging an
attachment element in macOS is not completely transparent.

* TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
(isCompletelyTransparent):
(TestWebKitAPI::TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@235229 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderAttachment.cpp
Source/WebCore/rendering/RenderAttachment.h
Source/WebCore/rendering/RenderThemeMac.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm