Title: [199247] trunk
Revision
199247
Author
[email protected]
Date
2016-04-08 14:01:50 -0700 (Fri, 08 Apr 2016)

Log Message

Focus ring drawn at incorrect location on image map with CSS transform.
https://bugs.webkit.org/show_bug.cgi?id=143527
<rdar://problem/21908735>

Reviewed by Simon Fraser.

Source/WebCore:

Implement pathForFocusRing for HTMLAreaElement. It follows the logic of RenderObject::addFocusRingRects().

Tests: fast/images/image-map-outline-in-positioned-container.html
       fast/images/image-map-outline-with-paint-root-offset.html
       fast/images/image-map-outline-with-scale-transform.html
       fast/images/image-map-outline.html

* html/HTMLAreaElement.cpp:
(WebCore::HTMLAreaElement::pathForFocusRing):
* html/HTMLAreaElement.h:
* rendering/RenderElement.cpp:
(WebCore::RenderElement::paintFocusRing): Move addFocusRingRects() out of focus ring painting.
(WebCore::RenderElement::paintOutline):
* rendering/RenderElement.h:
* rendering/RenderImage.cpp:
(WebCore::RenderImage::paint):
(WebCore::RenderImage::paintAreaElementFocusRing):
* rendering/RenderImage.h:
* rendering/RenderInline.cpp:
(WebCore::RenderInline::paintOutline):

LayoutTests:

Implement pathForFocusRing for HTMLAreaElement.

* fast/images/image-map-outline-in-positioned-container-expected.html: Added.
* fast/images/image-map-outline-in-positioned-container.html: Added.
* fast/images/image-map-outline-with-paint-root-offset-expected.html: Added.
* fast/images/image-map-outline-with-paint-root-offset.html: Added.
* fast/images/image-map-outline-with-scale-transform-expected.html: Added.
* fast/images/image-map-outline-with-scale-transform.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (199246 => 199247)


--- trunk/LayoutTests/ChangeLog	2016-04-08 20:59:51 UTC (rev 199246)
+++ trunk/LayoutTests/ChangeLog	2016-04-08 21:01:50 UTC (rev 199247)
@@ -1,3 +1,20 @@
+2016-04-08  Zalan Bujtas  <[email protected]>
+
+        Focus ring drawn at incorrect location on image map with CSS transform.
+        https://bugs.webkit.org/show_bug.cgi?id=143527
+        <rdar://problem/21908735>
+
+        Reviewed by Simon Fraser.
+
+        Implement pathForFocusRing for HTMLAreaElement.
+
+        * fast/images/image-map-outline-in-positioned-container-expected.html: Added.
+        * fast/images/image-map-outline-in-positioned-container.html: Added.
+        * fast/images/image-map-outline-with-paint-root-offset-expected.html: Added.
+        * fast/images/image-map-outline-with-paint-root-offset.html: Added.
+        * fast/images/image-map-outline-with-scale-transform-expected.html: Added.
+        * fast/images/image-map-outline-with-scale-transform.html: Added.
+
 2016-04-08  Filip Pizlo  <[email protected]>
 
         Add IC support for arguments.length

Added: trunk/LayoutTests/fast/images/image-map-outline-in-positioned-container-expected.html (0 => 199247)


--- trunk/LayoutTests/fast/images/image-map-outline-in-positioned-container-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/images/image-map-outline-in-positioned-container-expected.html	2016-04-08 21:01:50 UTC (rev 199247)
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This tests that we paint area outline properly when the image is inside positioned containers.</title>
+<style>
+img {
+    position: absolute;
+    top: 30px;
+    left: 30px;
+}
+
+div {
+    position: absolute;
+    top: 35px;
+    left: 35px;
+    width: 20px;
+    height: 20px;
+	outline: auto;
+}
+</style>
+</head>
+<body>
+<img src="" width=50 height=50>
+<div></div>
+</body>
+</html>

Added: trunk/LayoutTests/fast/images/image-map-outline-in-positioned-container.html (0 => 199247)


--- trunk/LayoutTests/fast/images/image-map-outline-in-positioned-container.html	                        (rev 0)
+++ trunk/LayoutTests/fast/images/image-map-outline-in-positioned-container.html	2016-04-08 21:01:50 UTC (rev 199247)
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This tests that we paint area outline properly when the image is inside positioned containers.</title>
+<style>
+.container {
+  position: absolute;
+  left: 20px;
+  top: 20px;
+}
+
+.inner {
+  position: absolute;
+  left: 10px;
+  top: 10px;
+}
+</style>
+<script>
+window._onload_ = function() {
+    document.getElementById("area").focus();
+}
+</script>
+</head>
+<body>
+<div class=container>
+  <div class=inner>
+    <img src="" width=50 height=50 usemap=""
+    <map name="map"><area id=area shape="rectangle" coords="5, 5, 25, 25" href=""
+  </div>
+</div>
+</body>
+</html>

Added: trunk/LayoutTests/fast/images/image-map-outline-with-paint-root-offset-expected.html (0 => 199247)


--- trunk/LayoutTests/fast/images/image-map-outline-with-paint-root-offset-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/images/image-map-outline-with-paint-root-offset-expected.html	2016-04-08 21:01:50 UTC (rev 199247)
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This tests that we paint area outline properly when the paintroot is shifted.</title>
+<style>
+img {
+    position: absolute;
+    top: 5px;
+    left: 5px;
+}
+div {
+    position: absolute;
+    top: 10px;
+    left: 10px;
+    width: 20px;
+    height: 20px;
+	outline: auto;
+}
+</style>
+</head>
+<body>
+<img src="" width=50 height=50>
+<div></div>
+</body>
+</html>

Added: trunk/LayoutTests/fast/images/image-map-outline-with-paint-root-offset.html (0 => 199247)


--- trunk/LayoutTests/fast/images/image-map-outline-with-paint-root-offset.html	                        (rev 0)
+++ trunk/LayoutTests/fast/images/image-map-outline-with-paint-root-offset.html	2016-04-08 21:01:50 UTC (rev 199247)
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This tests that we paint area outline properly when the paintroot is shifted.</title>
+<style>
+.paintroot {
+  transform: translateZ(0);
+  position: absolute;
+  left: 5px;
+  top: 5px;
+}
+</style>
+<script>
+window._onload_ = function() {
+    document.getElementById("area").focus();
+}
+</script>
+</head>
+<body>
+<div class=paintroot>
+  <img src="" width=50 height=50 usemap=""
+  <map name="map"><area id=area shape="rectangle" coords="5, 5, 25, 25" href=""
+</div>
+</body>
+</html>

Added: trunk/LayoutTests/fast/images/image-map-outline-with-scale-transform-expected.html (0 => 199247)


--- trunk/LayoutTests/fast/images/image-map-outline-with-scale-transform-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/images/image-map-outline-with-scale-transform-expected.html	2016-04-08 21:01:50 UTC (rev 199247)
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This tests that we paint area outline properly when the image's container is scaled.</title>
+<style>
+img {
+    position: absolute;
+    top: 23px;
+    left: 25px;
+}
+
+div {
+    position: absolute;
+    top: 33px;
+    left: 35px;
+    width: 40px;
+    height: 40px;
+	outline: auto;
+}
+</style>
+</head>
+<body>
+<img src="" width=100 height=100>
+<div></div>
+</body>
+</html>

Added: trunk/LayoutTests/fast/images/image-map-outline-with-scale-transform.html (0 => 199247)


--- trunk/LayoutTests/fast/images/image-map-outline-with-scale-transform.html	                        (rev 0)
+++ trunk/LayoutTests/fast/images/image-map-outline-with-scale-transform.html	2016-04-08 21:01:50 UTC (rev 199247)
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This tests that we paint area outline properly when the image's container is scaled.</title>
+<style>
+.container {
+  transform: scale(2);
+  position: absolute;
+  left: 50px;
+  top: 50px;
+}
+</style>
+<script>
+window._onload_ = function() {
+    document.getElementById("area").focus();
+}
+</script>
+</head>
+<body>
+<div class=container>
+  <img src="" width=50 height=50 usemap=""
+  <map name="map"><area id=area shape="rectangle" coords="5, 5, 25, 25" href=""
+</div>
+</body>
+</html>

Modified: trunk/LayoutTests/platform/ios-simulator/TestExpectations (199246 => 199247)


--- trunk/LayoutTests/platform/ios-simulator/TestExpectations	2016-04-08 20:59:51 UTC (rev 199246)
+++ trunk/LayoutTests/platform/ios-simulator/TestExpectations	2016-04-08 21:01:50 UTC (rev 199247)
@@ -3022,3 +3022,9 @@
 # iOS list box controls are not drawn in the standard way.
 fast/forms/listbox-padding-clip.html [ ImageOnlyFailure ]
 fast/forms/listbox-padding-clip-overlay.html [ ImageOnlyFailure ]
+
+# No focusring on iOS.
+fast/images/image-map-outline-in-positioned-container.html [ Pass ImageOnlyFailure ]
+fast/images/image-map-outline-with-paint-root-offset.html [ Pass ImageOnlyFailure ]
+fast/images/image-map-outline-with-scale-transform.html [ Pass ImageOnlyFailure ]
+ 
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (199246 => 199247)


--- trunk/Source/WebCore/ChangeLog	2016-04-08 20:59:51 UTC (rev 199246)
+++ trunk/Source/WebCore/ChangeLog	2016-04-08 21:01:50 UTC (rev 199247)
@@ -1,3 +1,32 @@
+2016-04-08  Zalan Bujtas  <[email protected]>
+
+        Focus ring drawn at incorrect location on image map with CSS transform.
+        https://bugs.webkit.org/show_bug.cgi?id=143527
+        <rdar://problem/21908735>
+
+        Reviewed by Simon Fraser.
+
+        Implement pathForFocusRing for HTMLAreaElement. It follows the logic of RenderObject::addFocusRingRects().
+
+        Tests: fast/images/image-map-outline-in-positioned-container.html
+               fast/images/image-map-outline-with-paint-root-offset.html
+               fast/images/image-map-outline-with-scale-transform.html
+               fast/images/image-map-outline.html
+
+        * html/HTMLAreaElement.cpp:
+        (WebCore::HTMLAreaElement::pathForFocusRing):
+        * html/HTMLAreaElement.h:
+        * rendering/RenderElement.cpp:
+        (WebCore::RenderElement::paintFocusRing): Move addFocusRingRects() out of focus ring painting.
+        (WebCore::RenderElement::paintOutline):
+        * rendering/RenderElement.h:
+        * rendering/RenderImage.cpp:
+        (WebCore::RenderImage::paint):
+        (WebCore::RenderImage::paintAreaElementFocusRing):
+        * rendering/RenderImage.h:
+        * rendering/RenderInline.cpp:
+        (WebCore::RenderInline::paintOutline):
+
 2016-04-08  Brent Fulgham  <[email protected]>
 
         [WK1] Wheel event callback removing the window causes crash in WebCore

Modified: trunk/Source/WebCore/html/HTMLAreaElement.cpp (199246 => 199247)


--- trunk/Source/WebCore/html/HTMLAreaElement.cpp	2016-04-08 20:59:51 UTC (rev 199246)
+++ trunk/Source/WebCore/html/HTMLAreaElement.cpp	2016-04-08 21:01:50 UTC (rev 199247)
@@ -116,6 +116,11 @@
     return p;
 }
 
+Path HTMLAreaElement::computePathForFocusRing(const LayoutSize& elementSize) const
+{
+    return getRegion(m_shape == Default ? elementSize : m_lastSize);
+}
+
 // FIXME: Use RenderElement* instead of RenderObject* once we upstream iOS's DOMUIKitExtensions.{h, mm}.
 LayoutRect HTMLAreaElement::computeRect(RenderObject* obj) const
 {

Modified: trunk/Source/WebCore/html/HTMLAreaElement.h (199246 => 199247)


--- trunk/Source/WebCore/html/HTMLAreaElement.h	2016-04-08 20:59:51 UTC (rev 199246)
+++ trunk/Source/WebCore/html/HTMLAreaElement.h	2016-04-08 21:01:50 UTC (rev 199247)
@@ -44,6 +44,7 @@
     // FIXME: Use RenderElement* instead of RenderObject* once we upstream iOS's DOMUIKitExtensions.{h, mm}.
     LayoutRect computeRect(RenderObject*) const;
     Path computePath(RenderObject*) const;
+    Path computePathForFocusRing(const LayoutSize& elementSize) const;
 
     // The parent map's image.
     HTMLImageElement* imageElement() const;

Modified: trunk/Source/WebCore/rendering/RenderElement.cpp (199246 => 199247)


--- trunk/Source/WebCore/rendering/RenderElement.cpp	2016-04-08 20:59:51 UTC (rev 199246)
+++ trunk/Source/WebCore/rendering/RenderElement.cpp	2016-04-08 21:01:50 UTC (rev 199247)
@@ -2040,12 +2040,9 @@
     }
 }
 
-void RenderElement::paintFocusRing(PaintInfo& paintInfo, const LayoutPoint& paintOffset, const RenderStyle& style)
+void RenderElement::paintFocusRing(PaintInfo& paintInfo, const RenderStyle& style, const Vector<LayoutRect>& focusRingRects)
 {
     ASSERT(style.outlineStyleIsAuto());
-
-    Vector<LayoutRect> focusRingRects;
-    addFocusRingRects(focusRingRects, paintOffset, paintInfo.paintContainer);
     float outlineOffset = style.outlineOffset();
     Vector<FloatRect> pixelSnappedFocusRingRects;
     float deviceScaleFactor = document().deviceScaleFactor();
@@ -2086,8 +2083,11 @@
     float outlineOffset = floorToDevicePixel(styleToUse.outlineOffset(), document().deviceScaleFactor());
 
     // Only paint the focus ring by hand if the theme isn't able to draw it.
-    if (styleToUse.outlineStyleIsAuto() && !theme().supportsFocusRing(styleToUse))
-        paintFocusRing(paintInfo, paintRect.location(), styleToUse);
+    if (styleToUse.outlineStyleIsAuto() && !theme().supportsFocusRing(styleToUse)) {
+        Vector<LayoutRect> focusRingRects;
+        addFocusRingRects(focusRingRects, paintRect.location(), paintInfo.paintContainer);
+        paintFocusRing(paintInfo, styleToUse, focusRingRects);
+    }
 
     if (hasOutlineAnnotation() && !styleToUse.outlineStyleIsAuto() && !theme().supportsFocusRing(styleToUse))
         addPDFURLRect(paintInfo, paintRect.location());

Modified: trunk/Source/WebCore/rendering/RenderElement.h (199246 => 199247)


--- trunk/Source/WebCore/rendering/RenderElement.h	2016-04-08 20:59:51 UTC (rev 199246)
+++ trunk/Source/WebCore/rendering/RenderElement.h	2016-04-08 21:01:50 UTC (rev 199247)
@@ -267,7 +267,7 @@
     unsigned renderBlockFlowLineLayoutPath() const { return m_renderBlockFlowLineLayoutPath; }
     bool renderBlockFlowHasMarkupTruncation() const { return m_renderBlockFlowHasMarkupTruncation; }
 
-    void paintFocusRing(PaintInfo&, const LayoutPoint&, const RenderStyle&);
+    void paintFocusRing(PaintInfo&, const RenderStyle&, const Vector<LayoutRect>& focusRingRects);
     void paintOutline(PaintInfo&, const LayoutRect&);
     void updateOutlineAutoAncestor(bool hasOutlineAuto) const;
 

Modified: trunk/Source/WebCore/rendering/RenderImage.cpp (199246 => 199247)


--- trunk/Source/WebCore/rendering/RenderImage.cpp	2016-04-08 20:59:51 UTC (rev 199246)
+++ trunk/Source/WebCore/rendering/RenderImage.cpp	2016-04-08 21:01:50 UTC (rev 199247)
@@ -30,6 +30,7 @@
 
 #include "BitmapImage.h"
 #include "CachedImage.h"
+#include "FocusController.h"
 #include "FontCache.h"
 #include "FontCascade.h"
 #include "Frame.h"
@@ -484,13 +485,14 @@
     RenderReplaced::paint(paintInfo, paintOffset);
     
     if (paintInfo.phase == PaintPhaseOutline)
-        paintAreaElementFocusRing(paintInfo);
+        paintAreaElementFocusRing(paintInfo, paintOffset);
 }
     
-void RenderImage::paintAreaElementFocusRing(PaintInfo& paintInfo)
+void RenderImage::paintAreaElementFocusRing(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
 {
 #if PLATFORM(IOS)
     UNUSED_PARAM(paintInfo);
+    UNUSED_PARAM(paintOffset);
 #else
     if (document().printing() || !frame().selection().isFocusedAndActive())
         return;
@@ -498,6 +500,9 @@
     if (paintInfo.context().paintingDisabled() && !paintInfo.context().updatingControlTints())
         return;
 
+    if (!document().page())
+        return;
+
     Element* focusedElement = document().focusedElement();
     if (!is<HTMLAreaElement>(focusedElement))
         return;
@@ -506,24 +511,37 @@
     if (areaElement.imageElement() != element())
         return;
 
+    auto* areaElementStyle = areaElement.computedStyle();
+    if (!areaElementStyle)
+        return;
+
+    float outlineWidth = areaElementStyle->outlineWidth();
+    if (!outlineWidth)
+        return;
+
     // Even if the theme handles focus ring drawing for entire elements, it won't do it for
     // an area within an image, so we don't call RenderTheme::supportsFocusRing here.
-
-    Path path = areaElement.computePath(this);
+    auto path = areaElement.computePathForFocusRing(size());
     if (path.isEmpty())
         return;
 
-    // FIXME: Do we need additional code to clip the path to the image's bounding box?
+    AffineTransform zoomTransform;
+    zoomTransform.scale(style().effectiveZoom());
+    path.transform(zoomTransform);
 
-    RenderStyle* areaElementStyle = areaElement.computedStyle();
-    float outlineWidth = areaElementStyle->outlineWidth();
-    if (!outlineWidth)
-        return;
+    auto adjustedOffset = paintOffset;
+    adjustedOffset.moveBy(location());
+    path.translate(toFloatSize(adjustedOffset));
 
-    paintInfo.context().drawFocusRing(path, outlineWidth,
-        areaElementStyle->outlineOffset(),
-        areaElementStyle->visitedDependentColor(CSSPropertyOutlineColor));
+#if PLATFORM(MAC)
+    bool needsRepaint;
+    paintInfo.context().drawFocusRing(path, document().page()->focusController().timeSinceFocusWasSet(), needsRepaint);
+    if (needsRepaint)
+        document().page()->focusController().setFocusedElementNeedsRepaint();
+#else
+    paintInfo.context().drawFocusRing(path, outlineWidth, areaElementStyle->outlineOffset(), areaElementStyle->visitedDependentColor(CSSPropertyOutlineColor));
 #endif
+#endif
 }
 
 void RenderImage::areaElementFocusChanged(HTMLAreaElement* element)

Modified: trunk/Source/WebCore/rendering/RenderImage.h (199246 => 199247)


--- trunk/Source/WebCore/rendering/RenderImage.h	2016-04-08 20:59:51 UTC (rev 199246)
+++ trunk/Source/WebCore/rendering/RenderImage.h	2016-04-08 21:01:50 UTC (rev 199247)
@@ -117,7 +117,7 @@
     // Update the size of the image to be rendered. Object-fit may cause this to be different from the CSS box's content rect.
     void updateInnerContentRect();
 
-    void paintAreaElementFocusRing(PaintInfo&);
+    void paintAreaElementFocusRing(PaintInfo&, const LayoutPoint& paintOffset);
     
     void layoutShadowControls(const LayoutSize& oldSize);
 

Modified: trunk/Source/WebCore/rendering/RenderInline.cpp (199246 => 199247)


--- trunk/Source/WebCore/rendering/RenderInline.cpp	2016-04-08 20:59:51 UTC (rev 199246)
+++ trunk/Source/WebCore/rendering/RenderInline.cpp	2016-04-08 21:01:50 UTC (rev 199247)
@@ -1603,8 +1603,11 @@
 
     RenderStyle& styleToUse = style();
     // Only paint the focus ring by hand if the theme isn't able to draw it.
-    if (styleToUse.outlineStyleIsAuto() && !theme().supportsFocusRing(styleToUse))
-        paintFocusRing(paintInfo, paintOffset, styleToUse);
+    if (styleToUse.outlineStyleIsAuto() && !theme().supportsFocusRing(styleToUse)) {
+        Vector<LayoutRect> focusRingRects;
+        addFocusRingRects(focusRingRects, paintOffset, paintInfo.paintContainer);
+        paintFocusRing(paintInfo, styleToUse, focusRingRects);
+    }
 
     if (hasOutlineAnnotation() && !styleToUse.outlineStyleIsAuto() && !theme().supportsFocusRing(styleToUse))
         addPDFURLRect(paintInfo, paintOffset);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to