<attachment> elements jump around a lot around when subtitle text changes slightly
https://bugs.webkit.org/show_bug.cgi?id=158818
<rdar://problem/24450270>
Reviewed by Simon Fraser.
Test: fast/attachment/attachment-subtitle-resize.html
* rendering/RenderAttachment.cpp:
(WebCore::RenderAttachment::layout):
* rendering/RenderAttachment.h:
* rendering/RenderThemeMac.mm:
(WebCore::AttachmentLayout::AttachmentLayout):
(WebCore::RenderThemeMac::paintAttachment):
In order to avoid changes to the centered subtitle text causing the whole
attachment to bounce around a lot, make it so that attachment width can only
increase, never decrease, and round the subtitle's width up to the nearest
increment of 10px when determining its affect on the whole element's width.
Also, center the attachment in its element, instead of left-aligning it,
so that the extra width we may have is evenly distributed between the two sides.
* fast/attachment/attachment-subtitle-resize-expected.txt: Added.
* fast/attachment/attachment-subtitle-resize.html: Added.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@202117 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/fast/attachment/attachment-subtitle-resize.html b/LayoutTests/fast/attachment/attachment-subtitle-resize.html
new file mode 100644
index 0000000..019da4b
--- /dev/null
+++ b/LayoutTests/fast/attachment/attachment-subtitle-resize.html
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+<script src="../../resources/js-test-pre.js"></script>
+<script>
+ if (window.internals)
+ window.internals.settings.setAttachmentElementEnabled(true)
+</script>
+<body>
+<attachment id="wideAttachment" subtitle="VERY LONG SUBTITLE THAT WILL MAKE THE ATTACHMENT VERY WIDE"></attachment>
+<attachment id="skinnyAttachment" subtitle="skinny but wider than icon"></attachment>
+<attachment id="resizedAttachment" subtitle="skinny but wider than icon"></attachment>
+<script>
+description("This tests that attachments which resize will only grow in width, never shrink.");
+
+var wideAttachmentEl = document.getElementById("wideAttachment");
+var skinnyAttachmentEl = document.getElementById("skinnyAttachment");
+var resizedAttachmentEl = document.getElementById("resizedAttachment");
+
+var wideAttachmentWidth = wideAttachmentEl.offsetWidth;
+var skinnyAttachmentWidth = skinnyAttachmentEl.offsetWidth;
+
+function assert(value, description)
+{
+ if (value)
+ testPassed(description);
+ else
+ testFailed(description);
+}
+
+assert(wideAttachmentWidth > skinnyAttachmentWidth, "wideAttachmentWidth > skinnyAttachmentWidth");
+
+assert(resizedAttachmentEl.offsetWidth == skinnyAttachmentWidth, "Attachment starts out skinny.");
+
+resizedAttachmentEl.setAttribute("subtitle", "VERY LONG SUBTITLE THAT WILL MAKE THE ATTACHMENT VERY WIDE");
+assert(resizedAttachmentEl.offsetWidth == wideAttachmentWidth, "Attachment resized from skinny to wide becomes wide.");
+
+resizedAttachmentEl.setAttribute("subtitle", "skinny but wider than icon");
+assert(resizedAttachmentEl.offsetWidth == wideAttachmentWidth, "Attachment resized from wide to skinny remains wide.");
+
+</script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>