Take css borders into account when drawing the box. This has to be done for every browser, except IE in quirks mode. r=crschmidt (closes 1593)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@7649 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2008-07-31 21:21:10 +00:00
parent d3151ccb40
commit 5191dac459

View File

@@ -29,6 +29,13 @@ OpenLayers.Handler.Box = OpenLayers.Class(OpenLayers.Handler, {
* olHandlerBoxZoomBox
*/
boxDivClassName: 'olHandlerBoxZoomBox',
/**
* Property: boxCharacteristics
* {Object} Caches some box characteristics from css. This is used
* by the getBoxCharacteristics method.
*/
boxCharacteristics: null,
/**
* Constructor: OpenLayers.Handler.Box
@@ -92,6 +99,20 @@ OpenLayers.Handler.Box = OpenLayers.Class(OpenLayers.Handler, {
this.zoomBox.style.height = Math.max(1, deltaY) + "px";
this.zoomBox.style.left = xy.x < startX ? xy.x+"px" : startX+"px";
this.zoomBox.style.top = xy.y < startY ? xy.y+"px" : startY+"px";
// depending on the box model, modify width and height to take borders
// of the box into account
var box = this.getBoxCharacteristics(deltaX, deltaY);
if (box.newBoxModel) {
if (xy.x > startX) {
this.zoomBox.style.width =
Math.max(1, deltaX - box.xOffset) + "px";
}
if (xy.y > startY) {
this.zoomBox.style.height =
Math.max(1, deltaY - box.yOffset) + "px";
}
}
},
/**
@@ -125,6 +146,7 @@ OpenLayers.Handler.Box = OpenLayers.Class(OpenLayers.Handler, {
removeBox: function() {
this.map.viewPortDiv.removeChild(this.zoomBox);
this.zoomBox = null;
this.boxCharacteristics = null;
},
/**
@@ -150,6 +172,26 @@ OpenLayers.Handler.Box = OpenLayers.Class(OpenLayers.Handler, {
return false;
}
},
getBoxCharacteristics: function(dx, dy) {
if (!this.boxCharacteristics) {
var xOffset = parseInt(OpenLayers.Element.getStyle(this.zoomBox,
"border-left-width")) + parseInt(OpenLayers.Element.getStyle(
this.zoomBox, "border-right-width")) + 1;
var yOffset = parseInt(OpenLayers.Element.getStyle(this.zoomBox,
"border-top-width")) + parseInt(OpenLayers.Element.getStyle(
this.zoomBox, "border-bottom-width")) + 1;
// all browsers use the new box model, except IE in quirks mode
var newBoxModel = OpenLayers.Util.getBrowserName() == "msie" ?
document.compatMode != "BackCompat" : true;
this.boxCharacteristics = {
xOffset: xOffset,
yOffset: yOffset,
newBoxModel: newBoxModel
}
}
return this.boxCharacteristics;
},
CLASS_NAME: "OpenLayers.Handler.Box"
});