Skip to content

Commit

Permalink
Adjust for IE7's inconsistent application of logical vs. device pixel…
Browse files Browse the repository at this point in the history
… ratio when zoomed. Issue lojjic#79
  • Loading branch information
lojjic committed May 12, 2012
1 parent 7f94811 commit 322d587
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
11 changes: 8 additions & 3 deletions sources/BoundsInfo.js
Expand Up @@ -25,14 +25,19 @@ PIE.BoundsInfo.prototype = {
getLiveBounds: function() {
var el = this.targetElement,
rect = el.getBoundingClientRect(),
isIE9 = PIE.ieDocMode === 9;
isIE9 = PIE.ieDocMode === 9,
width = rect.right - rect.left,
// IE7 is inconsistent in using logical vs. device pixels in measurements so we must
// calculate the ratio and use it in certain places as a position adjustment
logicalZoomRatio = ( PIE.ieVersion === 7 && width ) ? el.offsetWidth / width : 1;
return {
x: rect.left,
y: rect.top,
// In some cases scrolling the page will cause IE9 to report incorrect dimensions
// in the rect returned by getBoundingClientRect, so we must query offsetWidth/Height instead
w: isIE9 ? el.offsetWidth : rect.right - rect.left,
h: isIE9 ? el.offsetHeight : rect.bottom - rect.top
w: isIE9 ? el.offsetWidth : width * logicalZoomRatio,
h: isIE9 ? el.offsetHeight : ( rect.bottom - rect.top ) * logicalZoomRatio,
logicalZoomRatio: logicalZoomRatio
};
},

Expand Down
15 changes: 8 additions & 7 deletions sources/RootRenderer.js
Expand Up @@ -40,11 +40,12 @@ PIE.RootRenderer = PIE.RendererBase.newRenderer( {
boxPos,
s = this.getBoxEl().style, cs,
x = 0, y = 0,
elBounds = this.boundsInfo.getBounds();
elBounds = this.boundsInfo.getBounds(),
logicalZoomRatio = elBounds.logicalZoomRatio;

if( tgtPos === 'fixed' && PIE.ieVersion > 6 ) {
x = elBounds.x;
y = elBounds.y;
x = elBounds.x * logicalZoomRatio;
y = elBounds.y * logicalZoomRatio;
boxPos = tgtPos;
} else {
// Get the element's offsets from its nearest positioned ancestor. Uses
Expand All @@ -55,12 +56,12 @@ PIE.RootRenderer = PIE.RendererBase.newRenderer( {
if( par ) {
parRect = par.getBoundingClientRect();
cs = par.currentStyle;
x = elBounds.x - parRect.left - ( parseFloat(cs.borderLeftWidth) || 0 );
y = elBounds.y - parRect.top - ( parseFloat(cs.borderTopWidth) || 0 );
x = ( elBounds.x - parRect.left ) * logicalZoomRatio - ( parseFloat(cs.borderLeftWidth) || 0 );
y = ( elBounds.y - parRect.top ) * logicalZoomRatio - ( parseFloat(cs.borderTopWidth) || 0 );
} else {
docEl = doc.documentElement;
x = elBounds.x + docEl.scrollLeft - docEl.clientLeft;
y = elBounds.y + docEl.scrollTop - docEl.clientTop;
x = ( elBounds.x + docEl.scrollLeft - docEl.clientLeft ) * logicalZoomRatio;
y = ( elBounds.y + docEl.scrollTop - docEl.clientTop ) * logicalZoomRatio;
}
boxPos = 'absolute';
}
Expand Down

0 comments on commit 322d587

Please sign in to comment.