Diff
Modified: trunk/LayoutTests/ChangeLog (180719 => 180720)
--- trunk/LayoutTests/ChangeLog 2015-02-27 02:07:02 UTC (rev 180719)
+++ trunk/LayoutTests/ChangeLog 2015-02-27 02:07:22 UTC (rev 180720)
@@ -1,3 +1,16 @@
+2015-02-26 Timothy Horton <[email protected]>
+
+ Implement <attachment> element appearance on Mac
+ https://bugs.webkit.org/show_bug.cgi?id=142023
+
+ Reviewed by Dean Jackson.
+
+ * fast/attachment/attachment-rendering-expected.txt:
+ * platform/mac/fast/attachment/attachment-disabled-rendering-expected.png: Added.
+ * platform/mac/fast/attachment/attachment-rendering-expected.png: Added.
+ * platform/mac/fast/attachment/attachment-rendering-expected.txt: Added.
+ Add Mac overrides for <attachment> tests (and pixel results).
+
2015-02-26 Doug Russell <[email protected]>
AX: Expose caret browsing preference to accessibility API
Modified: trunk/LayoutTests/fast/attachment/attachment-disabled-rendering-expected.txt (180719 => 180720)
--- trunk/LayoutTests/fast/attachment/attachment-disabled-rendering-expected.txt 2015-02-27 02:07:02 UTC (rev 180719)
+++ trunk/LayoutTests/fast/attachment/attachment-disabled-rendering-expected.txt 2015-02-27 02:07:22 UTC (rev 180720)
@@ -2,10 +2,10 @@
RenderView at (0,0) size 800x600
layer at (0,0) size 800x600
RenderBlock {HTML} at (0,0) size 800x600
- RenderBody {BODY} at (8,8) size 784x576
+ RenderBody {BODY} at (8,8) size 784x584
RenderBlock {P} at (0,0) size 784x18
RenderText {#text} at (0,0) size 766x18
text run at (0,0) width 766: "This tests that attachments don't have a custom renderer when they are disabled. This test must be run in the test runner."
RenderBlock (anonymous) at (0,34) size 784x0
- RenderInline {ATTACHMENT} at (0,0) size 0x0
+ RenderBlock {ATTACHMENT} at (0,0) size 0x0
RenderText {#text} at (0,0) size 0x0
Modified: trunk/LayoutTests/fast/attachment/attachment-rendering-expected.txt (180719 => 180720)
--- trunk/LayoutTests/fast/attachment/attachment-rendering-expected.txt 2015-02-27 02:07:02 UTC (rev 180719)
+++ trunk/LayoutTests/fast/attachment/attachment-rendering-expected.txt 2015-02-27 02:07:22 UTC (rev 180720)
@@ -6,6 +6,6 @@
RenderBlock {P} at (0,0) size 784x18
RenderText {#text} at (0,0) size 326x18
text run at (0,0) width 326: "This tests that attachments have a custom renderer."
- RenderBlock (anonymous) at (0,34) size 784x200
- RenderAttachment {ATTACHMENT} at (0,0) size 200x200
+ RenderBlock (anonymous) at (0,34) size 784x0
+ RenderAttachment {ATTACHMENT} at (0,0) size 0x0
RenderText {#text} at (0,0) size 0x0
Added: trunk/LayoutTests/platform/mac/fast/attachment/attachment-disabled-rendering-expected.png
(Binary files differ)
Property changes on: trunk/LayoutTests/platform/mac/fast/attachment/attachment-disabled-rendering-expected.png
___________________________________________________________________
Added: svn:mime-type
Added: trunk/LayoutTests/platform/mac/fast/attachment/attachment-rendering-expected.png
(Binary files differ)
Property changes on: trunk/LayoutTests/platform/mac/fast/attachment/attachment-rendering-expected.png
___________________________________________________________________
Added: svn:mime-type
Added: trunk/LayoutTests/platform/mac/fast/attachment/attachment-rendering-expected.txt (0 => 180720)
--- trunk/LayoutTests/platform/mac/fast/attachment/attachment-rendering-expected.txt (rev 0)
+++ trunk/LayoutTests/platform/mac/fast/attachment/attachment-rendering-expected.txt 2015-02-27 02:07:22 UTC (rev 180720)
@@ -0,0 +1,11 @@
+layer at (0,0) size 800x600
+ RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+ RenderBlock {HTML} at (0,0) size 800x600
+ RenderBody {BODY} at (8,8) size 784x584
+ RenderBlock {P} at (0,0) size 784x18
+ RenderText {#text} at (0,0) size 326x18
+ text run at (0,0) width 326: "This tests that attachments have a custom renderer."
+ RenderBlock (anonymous) at (0,34) size 784x77
+ RenderAttachment {ATTACHMENT} at (0,0) size 60x77
+ RenderText {#text} at (0,0) size 0x0
Modified: trunk/Source/WebCore/ChangeLog (180719 => 180720)
--- trunk/Source/WebCore/ChangeLog 2015-02-27 02:07:02 UTC (rev 180719)
+++ trunk/Source/WebCore/ChangeLog 2015-02-27 02:07:22 UTC (rev 180720)
@@ -1,3 +1,81 @@
+2015-02-26 Timothy Horton <[email protected]>
+
+ Implement <attachment> element appearance on Mac
+ https://bugs.webkit.org/show_bug.cgi?id=142023
+
+ Reviewed by Dean Jackson.
+
+ * css/CSSParser.cpp:
+ (WebCore::isValidKeywordPropertyAndValue):
+ * css/CSSPrimitiveValueMappings.h:
+ (WebCore::CSSPrimitiveValue::CSSPrimitiveValue):
+ * css/CSSValueKeywords.in:
+ * css/html.css:
+ (attachment):
+ * platform/ThemeTypes.h:
+ Add a new -webkit-appearance value, attachment.
+
+ * WebCore.xcodeproj/project.pbxproj:
+ * html/HTMLAttachmentElement.cpp:
+ (WebCore::HTMLAttachmentElement::setFile):
+ Let the renderer know when the file changes (so it can relayout and repaint).
+
+ (WebCore::HTMLAttachmentElement::filePath):
+ (WebCore::HTMLAttachmentElement::fileName):
+ * html/HTMLAttachmentElement.h:
+ Handy acccessors for the full path and the name of the file.
+
+ * platform/spi/mac/IconServicesSPI.h: Added.
+ * platform/spi/mac/LaunchServicesSPI.h: Added.
+ Add some IconServices and LaunchServices SPI headers.
+
+ * rendering/RenderAttachment.cpp:
+ (WebCore::RenderAttachment::RenderAttachment):
+ Don't have a default intrinsic size; we'll adjust in layout().
+
+ (WebCore::RenderAttachment::isSelected):
+ (WebCore::RenderAttachment::isFocused):
+ (WebCore::RenderAttachment::isSelectedOrFocused):
+ Factor out from paintReplaced().
+
+ (WebCore::RenderAttachment::layout):
+ Use RenderTheme to compute the intrinsic size of this attachment.
+
+ (WebCore::RenderAttachment::paintReplaced):
+ Use RenderTheme to paint the attachment.
+
+ (WebCore::RenderAttachment::representedFileChanged):
+ When the represented file changes, we need to recompute the intrinsic size and repaint.
+
+ * rendering/RenderTheme.cpp:
+ (WebCore::RenderTheme::adjustStyle):
+ (WebCore::RenderTheme::paint):
+ (WebCore::RenderTheme::adjustAttachmentStyle):
+ (WebCore::RenderTheme::paintAttachment):
+ Plumb through the attachment appearance.
+
+ * rendering/RenderAttachment.h:
+ * rendering/RenderTheme.h:
+ (WebCore::RenderTheme::paintAttachment):
+ (WebCore::RenderTheme::attachmentIntrinsicSize):
+ * rendering/RenderThemeMac.h:
+ * rendering/RenderThemeMac.mm:
+ (WebCore::attachmentIconBackgroundColor):
+ (WebCore::attachmentIconBorderColor):
+ (WebCore::AttachmentLayout):
+ AttachmentLayout lays out the innards of the RenderThemeMac attachment
+ presentation: an icon with an optional bordered background, with a label
+ underneath it with an optional background.
+
+ (WebCore::RenderThemeMac::attachmentIntrinsicSize):
+ (WebCore::paintAttachmentIconBackground):
+ (WebCore::paintAttachmentIcon):
+ (WebCore::RenderThemeMac::paintAttachmentLabelBackground):
+ (WebCore::RenderThemeMac::paintAttachmentLabel):
+ (WebCore::RenderThemeMac::paintAttachment):
+ Paint the attachment element. Paint the optional backgrounds (and swap
+ out the text color) if the element is selected/focused.
+
2015-02-26 Doug Russell <[email protected]>
AX: Expose caret browsing preference to accessibility API
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (180719 => 180720)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2015-02-27 02:07:02 UTC (rev 180719)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2015-02-27 02:07:22 UTC (rev 180720)
@@ -1127,6 +1127,8 @@
2D6E468417D660F500ECF8BB /* PDFDocumentImageMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D6E468217D660F500ECF8BB /* PDFDocumentImageMac.mm */; };
2D70BA1318074DDF0001908A /* PlatformCALayerMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D70BA1218074DDF0001908A /* PlatformCALayerMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
2D70BA1518074F860001908A /* PlatformCALayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D70BA1418074F850001908A /* PlatformCALayer.cpp */; };
+ 2D74E99C1A9D3F3200DFB3D4 /* IconServicesSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D74E99B1A9D3F3200DFB3D4 /* IconServicesSPI.h */; };
+ 2D74E99E1A9D402900DFB3D4 /* LaunchServicesSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D74E99D1A9D402900DFB3D4 /* LaunchServicesSPI.h */; };
2D76BB821945632400CFD29A /* RunLoopObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D76BB801945632400CFD29A /* RunLoopObserver.h */; settings = {ATTRIBUTES = (Private, ); }; };
2D76BB8419456F8100CFD29A /* RunLoopObserver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D76BB8319456F8100CFD29A /* RunLoopObserver.cpp */; };
2D8287F616E4A0380086BD00 /* HitTestLocation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D8287F416E4A0380086BD00 /* HitTestLocation.cpp */; };
@@ -8179,6 +8181,8 @@
2D6E468217D660F500ECF8BB /* PDFDocumentImageMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PDFDocumentImageMac.mm; sourceTree = "<group>"; };
2D70BA1218074DDF0001908A /* PlatformCALayerMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PlatformCALayerMac.h; path = ca/mac/PlatformCALayerMac.h; sourceTree = "<group>"; };
2D70BA1418074F850001908A /* PlatformCALayer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PlatformCALayer.cpp; path = ca/PlatformCALayer.cpp; sourceTree = "<group>"; };
+ 2D74E99B1A9D3F3200DFB3D4 /* IconServicesSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IconServicesSPI.h; sourceTree = "<group>"; };
+ 2D74E99D1A9D402900DFB3D4 /* LaunchServicesSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LaunchServicesSPI.h; sourceTree = "<group>"; };
2D76BB801945632400CFD29A /* RunLoopObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RunLoopObserver.h; sourceTree = "<group>"; };
2D76BB8319456F8100CFD29A /* RunLoopObserver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RunLoopObserver.cpp; sourceTree = "<group>"; };
2D8287F416E4A0380086BD00 /* HitTestLocation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HitTestLocation.cpp; sourceTree = "<group>"; };
@@ -17668,6 +17672,8 @@
isa = PBXGroup;
children = (
2D59F1BE1A0044C6001F3D29 /* DataDetectorsSPI.h */,
+ 2D74E99B1A9D3F3200DFB3D4 /* IconServicesSPI.h */,
+ 2D74E99D1A9D402900DFB3D4 /* LaunchServicesSPI.h */,
2D413F601A187A3F0041A521 /* LookupSPI.h */,
1C6466271A12C3F90094603C /* NSFontSPI.h */,
9321D58F1A3906FA008052BE /* NSImmediateActionGestureRecognizerSPI.h */,
@@ -24268,6 +24274,7 @@
2E37DFDB12DBAFB800A6B233 /* DOMURL.h in Headers */,
CD9DE18217AAD6A400EA386D /* DOMURLMediaSource.h in Headers */,
15C770A6100D41CD005BA267 /* DOMValidityState.h in Headers */,
+ 2D74E99C1A9D3F3200DFB3D4 /* IconServicesSPI.h in Headers */,
BC1A37C0097C715F0019F3D8 /* DOMViews.h in Headers */,
31C0FF490E4CEFDD007D6FE5 /* DOMWebKitAnimationEvent.h in Headers */,
31C0FF4B0E4CEFDD007D6FE5 /* DOMWebKitAnimationEventInternal.h in Headers */,
@@ -26464,6 +26471,7 @@
B2227A880D00BF220071B782 /* SVGPatternElement.h in Headers */,
B2227A8C0D00BF220071B782 /* SVGPointList.h in Headers */,
B2227A8F0D00BF220071B782 /* SVGPolyElement.h in Headers */,
+ 2D74E99E1A9D402900DFB3D4 /* LaunchServicesSPI.h in Headers */,
2D58D8551A15F65F00A5F726 /* DataDetection.h in Headers */,
B2227A910D00BF220071B782 /* SVGPolygonElement.h in Headers */,
B2227A940D00BF220071B782 /* SVGPolylineElement.h in Headers */,
Modified: trunk/Source/WebCore/css/CSSPrimitiveValueMappings.h (180719 => 180720)
--- trunk/Source/WebCore/css/CSSPrimitiveValueMappings.h 2015-02-27 02:07:02 UTC (rev 180719)
+++ trunk/Source/WebCore/css/CSSPrimitiveValueMappings.h 2015-02-27 02:07:22 UTC (rev 180720)
@@ -602,6 +602,11 @@
case CapsLockIndicatorPart:
m_value.valueID = CSSValueCapsLockIndicator;
break;
+#if ENABLE(ATTACHMENT_ELEMENT)
+ case AttachmentPart:
+ m_value.valueID = CSSValueAttachment;
+ break;
+#endif
#if ENABLE(SERVICE_CONTROLS)
case ImageControlsButtonPart:
m_value.valueID = CSSValueImageControlsButton;
Modified: trunk/Source/WebCore/css/CSSValueKeywords.in (180719 => 180720)
--- trunk/Source/WebCore/css/CSSValueKeywords.in 2015-02-27 02:07:02 UTC (rev 180719)
+++ trunk/Source/WebCore/css/CSSValueKeywords.in 2015-02-27 02:07:22 UTC (rev 180720)
@@ -745,6 +745,9 @@
image-controls-button
#endif
textarea
+#if defined(ENABLE_ATTACHMENT_ELEMENT) && ENABLE_ATTACHMENT_ELEMENT
+attachment
+#endif
caps-lock-indicator
//
Modified: trunk/Source/WebCore/css/html.css (180719 => 180720)
--- trunk/Source/WebCore/css/html.css 2015-02-27 02:07:02 UTC (rev 180719)
+++ trunk/Source/WebCore/css/html.css 2015-02-27 02:07:22 UTC (rev 180720)
@@ -1193,6 +1193,10 @@
#endif
#if defined(ENABLE_ATTACHMENT_ELEMENT) && ENABLE_ATTACHMENT_ELEMENT
+attachment {
+ -webkit-appearance: attachment;
+}
+
attachment:focus {
outline: none;
}
Modified: trunk/Source/WebCore/html/HTMLAttachmentElement.cpp (180719 => 180720)
--- trunk/Source/WebCore/html/HTMLAttachmentElement.cpp 2015-02-27 02:07:02 UTC (rev 180719)
+++ trunk/Source/WebCore/html/HTMLAttachmentElement.cpp 2015-02-27 02:07:22 UTC (rev 180720)
@@ -64,6 +64,12 @@
void HTMLAttachmentElement::setFile(File* file)
{
m_file = file;
+
+ auto* renderer = this->renderer();
+ if (!is<RenderAttachment>(renderer))
+ return;
+
+ downcast<RenderAttachment>(*renderer).representedFileChanged();
}
void HTMLAttachmentElement::setFocus(bool shouldBeFocused)
Modified: trunk/Source/WebCore/platform/ThemeTypes.h (180719 => 180720)
--- trunk/Source/WebCore/platform/ThemeTypes.h 2015-02-27 02:07:02 UTC (rev 180719)
+++ trunk/Source/WebCore/platform/ThemeTypes.h 2015-02-27 02:07:22 UTC (rev 180720)
@@ -45,7 +45,11 @@
#if ENABLE(SERVICE_CONTROLS)
ImageControlsButtonPart,
#endif
- TextAreaPart, CapsLockIndicatorPart
+ TextAreaPart,
+#if ENABLE(ATTACHMENT_ELEMENT)
+ AttachmentPart,
+#endif
+ CapsLockIndicatorPart
};
enum SelectionPart {
Added: trunk/Source/WebCore/platform/spi/mac/IconServicesSPI.h (0 => 180720)
--- trunk/Source/WebCore/platform/spi/mac/IconServicesSPI.h (rev 0)
+++ trunk/Source/WebCore/platform/spi/mac/IconServicesSPI.h 2015-02-27 02:07:22 UTC (rev 180720)
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "LaunchServicesSPI.h"
+#import "SoftLinking.h"
+#import <objc/runtime.h>
+
+SOFT_LINK_PRIVATE_FRAMEWORK(IconServices)
+
+typedef UInt32 ISScale;
+
+SOFT_LINK(IconServices, _ISCreateCGImageFromBindingWithSizeScaleAndOptions, CGImageRef, (LSBindingRef binding, CGSize size, ISScale scale, CFDictionaryRef options), (binding, size, scale, options))
Added: trunk/Source/WebCore/platform/spi/mac/LaunchServicesSPI.h (0 => 180720)
--- trunk/Source/WebCore/platform/spi/mac/LaunchServicesSPI.h (rev 0)
+++ trunk/Source/WebCore/platform/spi/mac/LaunchServicesSPI.h 2015-02-27 02:07:22 UTC (rev 180720)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if USE(APPLE_INTERNAL_SDK)
+
+#include <LaunchServices/LaunchServicesPriv.h>
+
+#else
+
+WTF_EXTERN_C_BEGIN
+typedef struct _LSBinding* LSBindingRef;
+LSBindingRef _LSBindingCreateWithURL(CFAllocatorRef, CFURLRef);
+WTF_EXTERN_C_END
+
+#endif
Modified: trunk/Source/WebCore/rendering/RenderAttachment.cpp (180719 => 180720)
--- trunk/Source/WebCore/rendering/RenderAttachment.cpp 2015-02-27 02:07:02 UTC (rev 180719)
+++ trunk/Source/WebCore/rendering/RenderAttachment.cpp 2015-02-27 02:07:22 UTC (rev 180720)
@@ -29,16 +29,20 @@
#if ENABLE(ATTACHMENT_ELEMENT)
#include "FloatRect.h"
+#include "FloatRoundedRect.h"
#include "FrameSelection.h"
#include "HTMLAttachmentElement.h"
+#include "Page.h"
#include "PaintInfo.h"
+#include "RenderTheme.h"
+#include "URL.h"
namespace WebCore {
using namespace HTMLNames;
RenderAttachment::RenderAttachment(HTMLAttachmentElement& element, Ref<RenderStyle>&& style)
- : RenderReplaced(element, WTF::move(style), LayoutSize(200, 200))
+ : RenderReplaced(element, WTF::move(style), LayoutSize())
{
}
@@ -47,24 +51,35 @@
return downcast<HTMLAttachmentElement>(nodeForNonAnonymous());
}
-void RenderAttachment::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
+bool RenderAttachment::isSelected() const
{
- // FIXME: Implement
-
RefPtr<Range> selectionRange = frame().selection().selection().firstRange();
- bool selected = selectionRange && selectionRange->intersectsNode(&nodeForNonAnonymous(), ASSERT_NO_EXCEPTION);
- bool focused = frame().selection().isFocusedAndActive() && document().focusedElement() == &attachmentElement();
+ return selectionRange && selectionRange->intersectsNode(&nodeForNonAnonymous(), ASSERT_NO_EXCEPTION);
+}
- paintInfo.context->save();
- paintInfo.context->fillRect(FloatRect(paintOffset.x(), paintOffset.y(), 200, 200), selected || focused ? Color::cyan : Color::lightGray, ColorSpaceSRGB);
- paintInfo.context->restore();
+bool RenderAttachment::isFocused() const
+{
+ return frame().selection().isFocusedAndActive() && document().focusedElement() == &attachmentElement();
}
+void RenderAttachment::layout()
+{
+ setIntrinsicSize(document().page()->theme().attachmentIntrinsicSize(*this));
+
+ RenderReplaced::layout();
+}
+
void RenderAttachment::focusChanged()
{
repaint();
}
+void RenderAttachment::representedFileChanged()
+{
+ setNeedsLayout();
+ repaint();
+}
+
} // namespace WebCore
#endif
Modified: trunk/Source/WebCore/rendering/RenderAttachment.h (180719 => 180720)
--- trunk/Source/WebCore/rendering/RenderAttachment.h 2015-02-27 02:07:02 UTC (rev 180719)
+++ trunk/Source/WebCore/rendering/RenderAttachment.h 2015-02-27 02:07:22 UTC (rev 180720)
@@ -41,14 +41,21 @@
HTMLAttachmentElement& attachmentElement() const;
void focusChanged();
+ void representedFileChanged();
+ bool isSelectedOrFocused() const { return isSelected() || isFocused(); }
+
private:
void element() const = delete;
virtual bool isAttachment() const override { return true; }
virtual const char* renderName() const override { return "RenderAttachment"; }
- virtual void paintReplaced(PaintInfo&, const LayoutPoint&) override;
virtual bool shouldDrawSelectionTint() const override { return false; }
+
+ virtual void layout() override;
+
+ bool isSelected() const;
+ bool isFocused() const;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/rendering/RenderTheme.cpp (180719 => 180720)
--- trunk/Source/WebCore/rendering/RenderTheme.cpp 2015-02-27 02:07:02 UTC (rev 180719)
+++ trunk/Source/WebCore/rendering/RenderTheme.cpp 2015-02-27 02:07:22 UTC (rev 180720)
@@ -252,6 +252,10 @@
#endif
case CapsLockIndicatorPart:
return adjustCapsLockIndicatorStyle(styleResolver, style, e);
+#if ENABLE(ATTACHMENT_ELEMENT)
+ case AttachmentPart:
+ return adjustAttachmentStyle(styleResolver, style, e);
+#endif
default:
break;
}
@@ -390,6 +394,10 @@
#endif
case CapsLockIndicatorPart:
return paintCapsLockIndicator(o, paintInfo, integralSnappedRect);
+#if ENABLE(ATTACHMENT_ELEMENT)
+ case AttachmentPart:
+ return paintAttachment(o, paintInfo, integralSnappedRect);
+#endif
default:
break;
}
@@ -975,6 +983,17 @@
return false;
}
+#if ENABLE(ATTACHMENT_ELEMENT)
+void RenderTheme::adjustAttachmentStyle(StyleResolver&, RenderStyle&, Element*) const
+{
+}
+
+bool RenderTheme::paintAttachment(const RenderObject&, const PaintInfo&, const IntRect&)
+{
+ return false;
+}
+#endif
+
#if ENABLE(DATALIST_ELEMENT)
LayoutUnit RenderTheme::sliderTickSnappingThreshold() const
{
Modified: trunk/Source/WebCore/rendering/RenderTheme.h (180719 => 180720)
--- trunk/Source/WebCore/rendering/RenderTheme.h 2015-02-27 02:07:02 UTC (rev 180719)
+++ trunk/Source/WebCore/rendering/RenderTheme.h 2015-02-27 02:07:22 UTC (rev 180720)
@@ -43,6 +43,7 @@
class HTMLInputElement;
class Icon;
class PopupMenu;
+class RenderAttachment;
class RenderMenuList;
#if ENABLE(METER_ELEMENT)
class RenderMeter;
@@ -249,6 +250,10 @@
virtual bool defaultButtonHasAnimation() const { return false; }
+#if ENABLE(ATTACHMENT_ELEMENT)
+ virtual LayoutSize attachmentIntrinsicSize(const RenderAttachment&) const { return LayoutSize(); }
+#endif
+
protected:
virtual FontDescription& cachedSystemFontDescription(CSSValueID systemFontID) const;
virtual void updateCachedSystemFontDescription(CSSValueID systemFontID, FontDescription&) const = 0;
@@ -315,6 +320,11 @@
virtual void adjustCapsLockIndicatorStyle(StyleResolver&, RenderStyle&, Element*) const;
virtual bool paintCapsLockIndicator(const RenderObject&, const PaintInfo&, const IntRect&);
+#if ENABLE(ATTACHMENT_ELEMENT)
+ virtual void adjustAttachmentStyle(StyleResolver&, RenderStyle&, Element*) const;
+ virtual bool paintAttachment(const RenderObject&, const PaintInfo&, const IntRect&);
+#endif
+
virtual void adjustProgressBarStyle(StyleResolver&, RenderStyle&, Element*) const;
virtual bool paintProgressBar(const RenderObject&, const PaintInfo&, const IntRect&) { return true; }
Modified: trunk/Source/WebCore/rendering/RenderThemeMac.h (180719 => 180720)
--- trunk/Source/WebCore/rendering/RenderThemeMac.h 2015-02-27 02:07:02 UTC (rev 180719)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.h 2015-02-27 02:07:22 UTC (rev 180720)
@@ -38,6 +38,7 @@
class RenderProgress;
class RenderStyle;
+struct AttachmentLayout;
class RenderThemeMac final : public RenderTheme {
public:
@@ -167,6 +168,11 @@
virtual bool paintSnapshottedPluginOverlay(const RenderObject&, const PaintInfo&, const IntRect&) override;
+#if ENABLE(ATTACHMENT_ELEMENT)
+ virtual LayoutSize attachmentIntrinsicSize(const RenderAttachment&) const override;
+ virtual bool paintAttachment(const RenderObject&, const PaintInfo&, const IntRect&) override;
+#endif
+
private:
virtual String fileListNameForWidth(const FileList*, const FontCascade&, int width, bool multipleFilesAllowed) const override;
@@ -226,6 +232,11 @@
NSServicesRolloverButtonCell *servicesRolloverButtonCell() const;
#endif
+#if ENABLE(ATTACHMENT_ELEMENT)
+ void paintAttachmentLabelBackground(const RenderAttachment&, GraphicsContext&, AttachmentLayout&) const;
+ void paintAttachmentLabel(const RenderAttachment&, GraphicsContext&, AttachmentLayout&, bool useSelectedStyle) const;
+#endif
+
mutable RetainPtr<NSPopUpButtonCell> m_popupButton;
mutable RetainPtr<NSSearchFieldCell> m_search;
mutable RetainPtr<NSMenu> m_searchMenuTemplate;
Modified: trunk/Source/WebCore/rendering/RenderThemeMac.mm (180719 => 180720)
--- trunk/Source/WebCore/rendering/RenderThemeMac.mm 2015-02-27 02:07:02 UTC (rev 180719)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.mm 2015-02-27 02:07:22 UTC (rev 180720)
@@ -34,19 +34,23 @@
#import "Frame.h"
#import "FrameView.h"
#import "GraphicsContextCG.h"
+#import "HTMLAttachmentElement.h"
#import "HTMLAudioElement.h"
#import "HTMLInputElement.h"
#import "HTMLMediaElement.h"
#import "HTMLNames.h"
#import "HTMLPlugInImageElement.h"
+#import "IconServicesSPI.h"
#import "Image.h"
#import "ImageBuffer.h"
+#import "LaunchServicesSPI.h"
#import "LocalCurrentGraphicsContext.h"
#import "LocalizedStrings.h"
#import "MediaControlElements.h"
#import "NSSharingServicePickerSPI.h"
#import "Page.h"
#import "PaintInfo.h"
+#import "RenderAttachment.h"
#import "RenderLayer.h"
#import "RenderMedia.h"
#import "RenderMediaControlElements.h"
@@ -2066,6 +2070,170 @@
}
#endif
+#if ENABLE(ATTACHMENT_ELEMENT)
+const CGFloat attachmentIconSize = 48;
+const CGFloat attachmentIconBackgroundPadding = 6;
+const CGFloat attachmentIconBackgroundSize = attachmentIconSize + attachmentIconBackgroundPadding;
+const CGFloat attachmentIconSelectionBorderThickness = 1;
+const CGFloat attachmentIconBackgroundRadius = 3;
+const CGFloat attachmentIconToLabelMargin = 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 attachmentMargin = 3;
+
+struct AttachmentLayout {
+ AttachmentLayout(const RenderAttachment&);
+
+ FloatRect textRect;
+ FloatRect textBackgroundRect;
+ FloatRect iconRect;
+ FloatRect iconBackgroundRect;
+ FloatRect attachmentRect;
+
+ RetainPtr<CTFontRef> labelFont;
+ FontCascade labelFontCascade;
+ std::unique_ptr<TextRun> labelTextRun;
+};
+
+AttachmentLayout::AttachmentLayout(const RenderAttachment& attachment)
+{
+ // FIXME: We should have a limit on the width of the label.
+ // FIXME: We should support line-breaking (up to two lines) and always middle-truncate the second line.
+ File* file = attachment.attachmentElement().file();
+
+ labelFont = adoptCF(CTFontCreateUIFontForLanguage(kCTFontSystemFontType, attachmentLabelFontSize, nullptr));
+ labelFontCascade = FontCascade(FontPlatformData(labelFont.get(), attachmentLabelFontSize));
+
+ String filename = file ? file->name() : String();
+ labelTextRun = std::make_unique<TextRun>(filename);
+ labelTextRun->setDirection(filename.defaultWritingDirection() == U_LEFT_TO_RIGHT ? LTR : RTL);
+ float textWidth = labelFontCascade.width(*labelTextRun);
+ float textHeight = labelFontCascade.fontMetrics().height();
+ float xOffset = (attachmentIconBackgroundSize / 2) - (textWidth / 2);
+
+ textRect = FloatRect(xOffset, attachmentIconBackgroundSize + attachmentIconToLabelMargin, textWidth, textHeight);
+ textBackgroundRect = textRect;
+ textBackgroundRect.inflateX(attachmentLabelBackgroundPadding);
+ textBackgroundRect = encloseRectToDevicePixels(textBackgroundRect, attachment.document().deviceScaleFactor());
+
+ iconBackgroundRect = FloatRect(0, 0, attachmentIconBackgroundSize, attachmentIconBackgroundSize);
+
+ iconRect = iconBackgroundRect;
+ iconRect.setSize(FloatSize(attachmentIconSize, attachmentIconSize));
+ iconRect.move(attachmentIconBackgroundPadding / 2, attachmentIconBackgroundPadding / 2);
+
+ attachmentRect = iconBackgroundRect;
+ attachmentRect.unite(textBackgroundRect);
+ attachmentRect.inflate(attachmentMargin);
+ attachmentRect = encloseRectToDevicePixels(attachmentRect, attachment.document().deviceScaleFactor());
+}
+
+LayoutSize RenderThemeMac::attachmentIntrinsicSize(const RenderAttachment& attachment) const
+{
+ AttachmentLayout layout(attachment);
+ return LayoutSize(layout.attachmentRect.size());
+}
+
+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,
+ // where it switches into 'bordered mode' and the border pops in on top of the background.
+ bool paintBorder = true;
+
+ FloatRect backgroundRect = layout.iconBackgroundRect;
+ if (paintBorder)
+ backgroundRect.inflate(-attachmentIconSelectionBorderThickness);
+
+ FloatSize iconBackgroundRadiusSize(attachmentIconBackgroundRadius, attachmentIconBackgroundRadius);
+
+ Path backgroundPath;
+ backgroundPath.addRoundedRect(backgroundRect, iconBackgroundRadiusSize);
+ context.setFillColor(attachmentIconBackgroundColor(), ColorSpaceDeviceRGB);
+ context.fillPath(backgroundPath);
+
+ if (paintBorder) {
+ FloatRect borderRect = layout.iconBackgroundRect;
+ borderRect.inflate(-attachmentIconSelectionBorderThickness / 2);
+
+ Path borderPath;
+ borderPath.addRoundedRect(borderRect, iconBackgroundRadiusSize);
+ context.setStrokeColor(attachmentIconBorderColor(), ColorSpaceDeviceRGB);
+ context.setStrokeThickness(attachmentIconSelectionBorderThickness);
+ context.strokePath(borderPath);
+ }
+}
+
+static void paintAttachmentIcon(const RenderAttachment& attachment, GraphicsContext& context, AttachmentLayout& layout)
+{
+ File* file = attachment.attachmentElement().file();
+ RetainPtr<LSBindingRef> lsBinding = adoptCF(_LSBindingCreateWithURL(kCFAllocatorDefault, (CFURLRef)[NSURL fileURLWithPath:file ? file->path() : String()]));
+ if (!lsBinding)
+ return;
+
+ // FIXME: This should take transforms and page scale into account, not just deviceScaleFactor.
+ FloatSize iconSizeInPoints(attachmentIconSize, attachmentIconSize);
+ iconSizeInPoints.scale(attachment.document().deviceScaleFactor());
+
+ RetainPtr<CGImageRef> icon = adoptCF(_ISCreateCGImageFromBindingWithSizeScaleAndOptions(lsBinding.get(), iconSizeInPoints, 1, nil));
+ if (!icon)
+ return;
+
+ context.drawNativeImage(icon.get(), iconSizeInPoints, ColorSpaceDeviceRGB, layout.iconRect, FloatRect(FloatPoint(), iconSizeInPoints));
+}
+
+void RenderThemeMac::paintAttachmentLabelBackground(const RenderAttachment&, GraphicsContext& context, AttachmentLayout& layout) const
+{
+ Path backgroundPath;
+ backgroundPath.addRoundedRect(layout.textBackgroundRect, FloatSize(attachmentLabelBackgroundRadius, attachmentLabelBackgroundRadius));
+ context.setFillColor(convertNSColorToColor([NSColor alternateSelectedControlColor]), ColorSpaceDeviceRGB);
+ context.fillPath(backgroundPath);
+}
+
+void RenderThemeMac::paintAttachmentLabel(const RenderAttachment&, GraphicsContext& context, AttachmentLayout& layout, bool useSelectedStyle) const
+{
+ FloatPoint textLocation = layout.textRect.minXMaxYCorner();
+ textLocation.move(0, -layout.labelFontCascade.fontMetrics().descent());
+
+ context.setFillColor(useSelectedStyle ? convertNSColorToColor([NSColor alternateSelectedControlTextColor]) : Color::black, ColorSpaceDeviceRGB);
+ context.drawBidiText(layout.labelFontCascade, *layout.labelTextRun, textLocation);
+}
+
+bool RenderThemeMac::paintAttachment(const RenderObject& renderer, const PaintInfo& paintInfo, const IntRect& paintRect)
+{
+ if (!is<RenderAttachment>(renderer))
+ return false;
+
+ const RenderAttachment& attachment = downcast<RenderAttachment>(renderer);
+
+ AttachmentLayout layout(attachment);
+
+ GraphicsContext& context = *paintInfo.context;
+
+ GraphicsContextStateSaver saver(context);
+
+ context.translate(toFloatSize(paintRect.location()));
+ context.translate(FloatSize((layout.attachmentRect.width() - attachmentIconBackgroundSize) / 2, 0));
+
+ bool useSelectedStyle = attachment.isSelectedOrFocused();
+
+ if (useSelectedStyle)
+ paintAttachmentIconBackground(attachment, context, layout);
+ paintAttachmentIcon(attachment, context, layout);
+ if (useSelectedStyle)
+ paintAttachmentLabelBackground(attachment, context, layout);
+ paintAttachmentLabel(attachment, context, layout, useSelectedStyle);
+
+ return true;
+}
+
+#endif // ENABLE(ATTACHMENT_ELEMENT)
+
} // namespace WebCore
#endif // !PLATFORM(IOS)