JosephShenton / closure-library

Automatically exported from code.google.com/p/closure-library
1 stars 0 forks source link

goog.positioning.positionAtAnchor doesn't work as expected when offsetParent has borders #494

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago

What steps will reproduce the problem?
1. open attached file (position-at-anchor.html)
2. click "Position movable"

What is the expected output? What do you see instead?

The movable element should be positioned at the top left corner of the anchor 
element.

Instead it's positioned so that the distance to the top left corner of the 
anchor element is the same as the top and left borders applied to the 
offsetParent element.

What version of the product are you using? On what operating system?

r2143, Chrome/OS X

Please provide any additional information below.

One way to fix this is by changing the function 
goog.positioning.getOffsetParentPageOffset, as you can see when you click "Fix 
goog.positioning.getOffsetParentPageOffset".

The lines added to the fixed version are (in position-at-anchor.html):

                  var borders = goog.style.getBorderBox(parent);
                  movableParentTopLeft.x += borders.left;
                  movableParentTopLeft.y += borders.top;

Now it returns the page offset of the *movable element* when it's positioned so 
that its top and left values are both set to 0. Or another interpretation is 
that it returns the page offset of the *content area* of the *offset parent 
element*.

But this probably changes the intended behavior of the function, which is to 
retrieve the page offset coordinates of the *offset parent element*, and now 
the patched version won't do exactly that. This might break other apps already 
using this function.

Probably a better way to fix this is by patching only 
goog.positioning.positionAtAnchor or then creating a new function, like 
"getPageOffsetAtOrigin", meaning the page offset when the movable element is 
positioned at the coordinates (0, 0) (origin) as explained before. Or also 
"getOffsetParentContentPageOffset", indicating it will return the page offset 
of the content area (without the borders) of the page offset element.

Original issue reported on code.google.com by alo.and on 10 Sep 2012 at 3:19

Attachments: