Title: [200596] trunk/Source/WebCore
Revision
200596
Author
timothy_hor...@apple.com
Date
2016-05-09 16:48:17 -0700 (Mon, 09 May 2016)

Log Message

Draw border and correct icon for placeholder attachments
https://bugs.webkit.org/show_bug.cgi?id=157495
rdar://problem/19982510

Reviewed by Anders Carlsson.

* Resources/AttachmentPlaceholder.png: Added.
* Resources/attachmentplacehol...@2x.png: Added.
* WebCore.xcodeproj/project.pbxproj:
* rendering/RenderThemeMac.mm:
(WebCore::attachmentPlaceholderBorderColor):
(WebCore::paintAttachmentIconPlaceholder):
(WebCore::paintAttachmentProgress):
(WebCore::paintAttachmentPlaceholderBorder):
(WebCore::RenderThemeMac::paintAttachment):
If progress is set, but set to 0, draw a dashed border around the attachment
and use the placeholder "download" artwork.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (200595 => 200596)


--- trunk/Source/WebCore/ChangeLog	2016-05-09 22:50:34 UTC (rev 200595)
+++ trunk/Source/WebCore/ChangeLog	2016-05-09 23:48:17 UTC (rev 200596)
@@ -1,3 +1,23 @@
+2016-05-09  Tim Horton  <timothy_hor...@apple.com>
+
+        Draw border and correct icon for placeholder attachments
+        https://bugs.webkit.org/show_bug.cgi?id=157495
+        rdar://problem/19982510
+
+        Reviewed by Anders Carlsson.
+
+        * Resources/AttachmentPlaceholder.png: Added.
+        * Resources/attachmentplacehol...@2x.png: Added.
+        * WebCore.xcodeproj/project.pbxproj:
+        * rendering/RenderThemeMac.mm:
+        (WebCore::attachmentPlaceholderBorderColor):
+        (WebCore::paintAttachmentIconPlaceholder):
+        (WebCore::paintAttachmentProgress):
+        (WebCore::paintAttachmentPlaceholderBorder):
+        (WebCore::RenderThemeMac::paintAttachment):
+        If progress is set, but set to 0, draw a dashed border around the attachment
+        and use the placeholder "download" artwork.
+
 2016-05-09  Ada Chan  <adac...@apple.com>
 
         Introduce WebVideoFullscreenInterfaceMac::isPlayingVideoInEnhancedFullscreen() and use it in WebVideoFullscreenManagerProxy::isPlayingVideoInEnhancedFullscreen()

Added: trunk/Source/WebCore/Resources/AttachmentPlaceholder.png


(Binary files differ)
Property changes on: trunk/Source/WebCore/Resources/AttachmentPlaceholder.png ___________________________________________________________________

Added: svn:mime-type

Added: trunk/Source/WebCore/Resources/attachmentplacehol...@2x.png


(Binary files differ)
Property changes on: trunk/Source/WebCore/Resources/attachmentplacehol...@2x.png ___________________________________________________________________

Added: svn:mime-type

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (200595 => 200596)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-05-09 22:50:34 UTC (rev 200595)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-05-09 23:48:17 UTC (rev 200596)
@@ -1165,6 +1165,8 @@
 		2D5002FB1B56D7990020AAF7 /* PathUtilities.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D5002F91B56D7990020AAF7 /* PathUtilities.cpp */; };
 		2D5002FC1B56D7990020AAF7 /* PathUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D5002FA1B56D7990020AAF7 /* PathUtilities.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		2D5036681BCDDDC400E20BB3 /* GestureEvents.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D5036671BCDDDC400E20BB3 /* GestureEvents.cpp */; };
+		2D50A4B71CE10E0000198049 /* AttachmentPlaceholder.png in Resources */ = {isa = PBXBuildFile; fileRef = 2D50A4B51CE10E0000198049 /* AttachmentPlaceholder.png */; };
+		2D50A4B81CE10E0000198049 /* attachmentplacehol...@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 2D50A4B61CE10E0000198049 /* attachmentplacehol...@2x.png */; };
 		2D5646B01B8F8493003C4994 /* DictionaryPopupInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D5646AF1B8F8493003C4994 /* DictionaryPopupInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		2D59F1BF1A0044C6001F3D29 /* DataDetectorsSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D59F1BE1A0044C6001F3D29 /* DataDetectorsSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		2D5A592F152525230036EE51 /* ImageOrientation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8748D7412CC3F89001FBA41 /* ImageOrientation.cpp */; };
@@ -8654,6 +8656,8 @@
 		2D5002F91B56D7990020AAF7 /* PathUtilities.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PathUtilities.cpp; sourceTree = "<group>"; };
 		2D5002FA1B56D7990020AAF7 /* PathUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PathUtilities.h; sourceTree = "<group>"; };
 		2D5036671BCDDDC400E20BB3 /* GestureEvents.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GestureEvents.cpp; sourceTree = "<group>"; };
+		2D50A4B51CE10E0000198049 /* AttachmentPlaceholder.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = AttachmentPlaceholder.png; sourceTree = "<group>"; };
+		2D50A4B61CE10E0000198049 /* attachmentplacehol...@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "attachmentplacehol...@2x.png"; sourceTree = "<group>"; };
 		2D5646AF1B8F8493003C4994 /* DictionaryPopupInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DictionaryPopupInfo.h; sourceTree = "<group>"; };
 		2D59F1BE1A0044C6001F3D29 /* DataDetectorsSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DataDetectorsSPI.h; sourceTree = "<group>"; };
 		2D5BC42516F882BE007048D0 /* SecurityPolicyViolationEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SecurityPolicyViolationEvent.h; sourceTree = "<group>"; };
@@ -17948,6 +17952,8 @@
 		65998A650E5F5FD3004E097A /* images */ = {
 			isa = PBXGroup;
 			children = (
+				2D50A4B51CE10E0000198049 /* AttachmentPlaceholder.png */,
+				2D50A4B61CE10E0000198049 /* attachmentplacehol...@2x.png */,
 				D02B64B014089E56006EFA21 /* DictationPhraseWithAlternativesDot.png */,
 				D02B64B114089E56006EFA21 /* dictationphrasewithalternatives...@2x.png */,
 				BE8C753010681324001E93F5 /* SpellingDot.png */,
@@ -28872,6 +28878,7 @@
 				BCAD180A131C7A0D00990406 /* Localizable.strings in Resources */,
 				311C08BD18EB7CAF00B65615 /* mediaControlsApple.css in Resources */,
 				311C08BE18EB7CAF00B65615 /* mediaControlsApple.js in Resources */,
+				2D50A4B71CE10E0000198049 /* AttachmentPlaceholder.png in Resources */,
 				311C08BF18EB7CAF00B65615 /* mediaControlsiOS.css in Resources */,
 				311C08C018EB7CAF00B65615 /* mediaControlsiOS.js in Resources */,
 				7A1D7FCB18F85F0F00C385AD /* mediaControlsLocalizedStrings.js in Resources */,
@@ -28883,6 +28890,7 @@
 				A11E8C081B1E29020003A7C7 /* northSouthResizeCursor.png in Resources */,
 				A11E8C091B1E29070003A7C7 /* northWestSouthEastResizeCursor.png in Resources */,
 				BE8C753110681324001E93F5 /* SpellingDot.png in Resources */,
+				2D50A4B81CE10E0000198049 /* attachmentplacehol...@2x.png in Resources */,
 				01E6C2E41194B2820050821C /* spelling...@2x.png in Resources */,
 				1C2417BA1992C04100EF9938 /* spelling...@3x.png in Resources */,
 				93153BDC141959BC00FCF5BE /* textAreaResizeCorner.png in Resources */,

Modified: trunk/Source/WebCore/rendering/RenderThemeMac.mm (200595 => 200596)


--- trunk/Source/WebCore/rendering/RenderThemeMac.mm	2016-05-09 22:50:34 UTC (rev 200595)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.mm	2016-05-09 23:48:17 UTC (rev 200596)
@@ -36,6 +36,7 @@
 #import "Frame.h"
 #import "FrameSelection.h"
 #import "FrameView.h"
+#import "GeometryUtilities.h"
 #import "GraphicsContextCG.h"
 #import "HTMLAttachmentElement.h"
 #import "HTMLAudioElement.h"
@@ -2182,6 +2183,11 @@
 static Color attachmentProgressBarFillColor() { return Color(Color::white); }
 static Color attachmentProgressBarBorderColor() { return Color(0, 0, 0, 128); }
 
+const CGFloat attachmentPlaceholderBorderRadius = 5;
+static Color attachmentPlaceholderBorderColor() { return Color(0, 0, 0, 56); }
+const CGFloat attachmentPlaceholderBorderWidth = 2;
+const CGFloat attachmentPlaceholderBorderDashLength = 6;
+
 const CGFloat attachmentMargin = 3;
 
 struct AttachmentLayout {
@@ -2445,6 +2451,24 @@
     icon->paint(context, layout.iconRect);
 }
 
+static void paintAttachmentIconPlaceholder(const RenderAttachment& attachment, GraphicsContext& context, AttachmentLayout& layout)
+{
+    RefPtr<Image> placeholderImage;
+    float imageScale = 1;
+    if (attachment.document().deviceScaleFactor() >= 2) {
+        placeholderImage = Image::loadPlatformResource("AttachmentPlaceholder@2x");
+        imageScale = 2;
+    } else
+        placeholderImage = Image::loadPlatformResource("AttachmentPlaceholder");
+
+    // Center the placeholder image where the icon would usually be.
+    FloatRect placeholderRect(0, 0, placeholderImage->width() / imageScale, placeholderImage->height() / imageScale);
+    placeholderRect.setX(layout.iconRect.x() + (layout.iconRect.width() - placeholderRect.width()) / 2);
+    placeholderRect.setY(layout.iconRect.y() + (layout.iconRect.height() - placeholderRect.height()) / 2);
+
+    context.drawImage(*placeholderImage, placeholderRect);
+}
+
 static void paintAttachmentTitleBackground(const RenderAttachment& attachment, GraphicsContext& context, AttachmentLayout& layout)
 {
     if (layout.lines.isEmpty())
@@ -2491,16 +2515,8 @@
     CTLineDraw(layout.subtitleLine.get(), context.platformContext());
 }
 
-static void paintAttachmentProgress(const RenderAttachment& attachment, GraphicsContext& context, AttachmentLayout& layout)
+static void paintAttachmentProgress(const RenderAttachment& attachment, GraphicsContext& context, AttachmentLayout& layout, float progress)
 {
-    String progressString = attachment.attachmentElement().fastGetAttribute(progressAttr);
-    if (progressString.isEmpty())
-        return;
-    bool validProgress;
-    float progress = progressString.toFloat(&validProgress);
-    if (!validProgress)
-        return;
-
     GraphicsContextStateSaver saver(context);
 
     FloatRect progressBounds((attachmentIconBackgroundSize - attachmentProgressBarWidth) / 2, layout.iconBackgroundRect.maxY() + attachmentProgressBarOffset - attachmentProgressBarHeight, attachmentProgressBarWidth, attachmentProgressBarHeight);
@@ -2532,6 +2548,17 @@
     context.strokePath(borderPath);
 }
 
+static void paintAttachmentPlaceholderBorder(const RenderAttachment&, GraphicsContext& context, AttachmentLayout& layout)
+{
+    Path borderPath;
+    borderPath.addRoundedRect(layout.attachmentRect, FloatSize(attachmentPlaceholderBorderRadius, attachmentPlaceholderBorderRadius));
+    context.setStrokeColor(attachmentPlaceholderBorderColor());
+    context.setStrokeThickness(attachmentPlaceholderBorderWidth);
+    context.setStrokeStyle(DashedStroke);
+    context.setLineDash({attachmentPlaceholderBorderDashLength}, 0);
+    context.strokePath(borderPath);
+}
+
 bool RenderThemeMac::paintAttachment(const RenderObject& renderer, const PaintInfo& paintInfo, const IntRect& paintRect)
 {
     if (!is<RenderAttachment>(renderer))
@@ -2541,6 +2568,12 @@
 
     AttachmentLayout layout(attachment);
 
+    String progressString = attachment.attachmentElement().fastGetAttribute(progressAttr);
+    bool validProgress = false;
+    float progress = 0;
+    if (!progressString.isEmpty())
+        progress = progressString.toFloat(&validProgress);
+
     GraphicsContext& context = paintInfo.context();
     LocalCurrentGraphicsContext localContext(context);
     GraphicsContextStateSaver saver(context);
@@ -2549,16 +2582,26 @@
     context.translate(FloatSize((layout.attachmentRect.width() - attachmentIconBackgroundSize) / 2, 0));
 
     bool useSelectedStyle = attachment.selectionState() != RenderObject::SelectionNone;
+    bool usePlaceholder = validProgress && !progress;
 
     if (useSelectedStyle)
         paintAttachmentIconBackground(attachment, context, layout);
-    paintAttachmentIcon(attachment, context, layout);
+    if (usePlaceholder)
+        paintAttachmentIconPlaceholder(attachment, context, layout);
+    else
+        paintAttachmentIcon(attachment, context, layout);
+
     if (useSelectedStyle)
         paintAttachmentTitleBackground(attachment, context, layout);
     paintAttachmentTitle(attachment, context, layout);
     paintAttachmentSubtitle(attachment, context, layout);
-    paintAttachmentProgress(attachment, context, layout);
 
+    if (validProgress && progress)
+        paintAttachmentProgress(attachment, context, layout, progress);
+
+    if (usePlaceholder)
+        paintAttachmentPlaceholderBorder(attachment, context, layout);
+
     return true;
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to