Bug 53767

Summary: SVG <use> element is not repositioned when moved to x=0 y=0 through script
Product: WebKit Reporter: Alexis Deveria <adeveria>
Component: SVGAssignee: Rob Buis <rwlbuis>
Status: RESOLVED FIXED    
Severity: Normal CC: emumonger, jeffschiller, marc.bernard, rwlbuis, zimmermann
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: OS X 10.5   
Attachments:
Description Flags
Example of the problem, the green rect should cover the red one after one second.
none
Patch
none
Patch zimmermann: review+

Alexis Deveria
Reported 2011-02-04 07:33:29 PST
SVG <use> elements will appear with x="0" y="0" statically and can moved using any other values in JS, but exactly x=0 and y=0 results in no visual difference. Same problem when removing both x and y attributes.
Attachments
Example of the problem, the green rect should cover the red one after one second. (797 bytes, image/svg+xml)
2011-02-04 07:35 PST, Alexis Deveria
no flags
Patch (7.42 KB, patch)
2011-07-22 18:09 PDT, Rob Buis
no flags
Patch (9.71 KB, patch)
2011-07-23 09:45 PDT, Rob Buis
zimmermann: review+
Alexis Deveria
Comment 1 2011-02-04 07:35:07 PST
Created attachment 81217 [details] Example of the problem, the green rect should cover the red one after one second.
Rob Buis
Comment 2 2011-07-22 18:09:17 PDT
Dirk Schulze
Comment 3 2011-07-22 22:29:40 PDT
Comment on attachment 101798 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=101798&action=review > Source/WebCore/rendering/svg/SVGShadowTreeElements.cpp:53 > + m_yOffset = y; > + if (renderer()) > + static_cast<RenderSVGTransformableContainer*>(renderer())->setNeedsTransformUpdate(); Si it is not only 0,0 affected but every other position as well? Because according your patch I don't see a reason why just 0,0 should be affected.
Nikolas Zimmermann
Comment 4 2011-07-22 23:37:59 PDT
Comment on attachment 101798 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=101798&action=review >> Source/WebCore/rendering/svg/SVGShadowTreeElements.cpp:53 >> + static_cast<RenderSVGTransformableContainer*>(renderer())->setNeedsTransformUpdate(); > > Si it is not only 0,0 affected but every other position as well? Because according your patch I don't see a reason why just 0,0 should be affected. The more interessting question is why would you need a "transform update" if transform did not change? Note that RenderSVGShadowTreeRootContainer inherits from RenderSVGTransformableContainer, and bool RenderSVGTransformableContainer::calculateLocalTransform() contains special code to apply the container offset to the local transform. This should work even _without_ touching setNeedsTransformUpdate. If it doesn't there's another bug that you're hiding by this workaround. r- for this reason.
Nikolas Zimmermann
Comment 5 2011-07-22 23:41:51 PDT
Good point Dirk - why is only x/y=0 affected. Here's the answer: bool RenderSVGTransformableContainer::calculateLocalTransform() { SVGStyledTransformableElement* element = static_cast<SVGStyledTransformableElement*>(node()); ...... FloatSize translation = static_cast<SVGShadowTreeContainerElement*>(element)->containerTranslation(); if (!translation.width() && !translation.height()) return needsUpdate; if translation width/height (corresponds to x/y) is 0 we'll ignore updating the transform. We need to store the previous translation, and compare it with the current translation, if they are equal just "return needsUpdate" otherwhise go on.... That explains why only x=0&&y=0 failed here, and avoids the setNeedsTransformUpdate hack from your current patch...
Rob Buis
Comment 6 2011-07-23 05:32:28 PDT
Hi guys, (In reply to comment #5) > Good point Dirk - why is only x/y=0 affected. > Here's the answer: > > bool RenderSVGTransformableContainer::calculateLocalTransform() > { > SVGStyledTransformableElement* element = static_cast<SVGStyledTransformableElement*>(node()); > ...... > > FloatSize translation = static_cast<SVGShadowTreeContainerElement*>(element)->containerTranslation(); > if (!translation.width() && !translation.height()) > return needsUpdate; > > if translation width/height (corresponds to x/y) is 0 we'll ignore updating the transform. > We need to store the previous translation, and compare it with the current translation, if they are equal just "return needsUpdate" otherwhise go on.... > > That explains why only x=0&&y=0 failed here, and avoids the setNeedsTransformUpdate hack from your current patch... Was just about to hint at the same code (just woken up) :) Will have a look at it again. Cheers, Rob.
Rob Buis
Comment 7 2011-07-23 09:45:15 PDT
Nikolas Zimmermann
Comment 8 2011-07-24 02:44:50 PDT
Comment on attachment 101814 [details] Patch Excellent patch, r=me!
Rob Buis
Comment 9 2011-07-24 13:11:36 PDT
Landed in r91644.
Note You need to log in before you can comment on or make changes to this bug.