OpenLayers OpenLayers

Changeset 7649

Show
Ignore:
Timestamp:
07/31/08 17:21:10 (4 months ago)
Author:
ahocevar
Message:

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)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Handler/Box.js

    r7375 r7649  
    3030     */ 
    3131    boxDivClassName: 'olHandlerBoxZoomBox', 
     32     
     33    /** 
     34     * Property: boxCharacteristics 
     35     * {Object} Caches some box characteristics from css. This is used 
     36     *     by the getBoxCharacteristics method. 
     37     */ 
     38    boxCharacteristics: null, 
    3239 
    3340    /** 
     
    93100        this.zoomBox.style.left = xy.x < startX ? xy.x+"px" : startX+"px"; 
    94101        this.zoomBox.style.top = xy.y < startY ? xy.y+"px" : startY+"px"; 
     102 
     103        // depending on the box model, modify width and height to take borders 
     104        // of the box into account 
     105        var box = this.getBoxCharacteristics(deltaX, deltaY); 
     106        if (box.newBoxModel) { 
     107            if (xy.x > startX) { 
     108                this.zoomBox.style.width = 
     109                    Math.max(1, deltaX - box.xOffset) + "px"; 
     110            } 
     111            if (xy.y > startY) { 
     112                this.zoomBox.style.height = 
     113                    Math.max(1, deltaY - box.yOffset) + "px"; 
     114            } 
     115        } 
    95116    }, 
    96117 
     
    126147        this.map.viewPortDiv.removeChild(this.zoomBox); 
    127148        this.zoomBox = null; 
     149        this.boxCharacteristics = null; 
    128150    }, 
    129151 
     
    151173        } 
    152174    }, 
     175     
     176    getBoxCharacteristics: function(dx, dy) { 
     177        if (!this.boxCharacteristics) { 
     178            var xOffset = parseInt(OpenLayers.Element.getStyle(this.zoomBox, 
     179                "border-left-width")) + parseInt(OpenLayers.Element.getStyle( 
     180                this.zoomBox, "border-right-width")) + 1; 
     181            var yOffset = parseInt(OpenLayers.Element.getStyle(this.zoomBox, 
     182                "border-top-width")) + parseInt(OpenLayers.Element.getStyle( 
     183                this.zoomBox, "border-bottom-width")) + 1; 
     184            // all browsers use the new box model, except IE in quirks mode 
     185            var newBoxModel = OpenLayers.Util.getBrowserName() == "msie" ? 
     186                document.compatMode != "BackCompat" : true; 
     187            this.boxCharacteristics = { 
     188                xOffset: xOffset, 
     189                yOffset: yOffset, 
     190                newBoxModel: newBoxModel 
     191            } 
     192        } 
     193        return this.boxCharacteristics; 
     194    }, 
    153195 
    154196    CLASS_NAME: "OpenLayers.Handler.Box"