mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-25 06:36:11 +03:00
Merge pull request #1937 from ronnymikalsen/1763-a11y-browser-zoom
fix(a11y): draw the level based on pixel density ratio
This commit is contained in:
commit
0a78916ff7
@ -986,7 +986,7 @@ function OpenSeadragon( options ){
|
||||
* @member {Number} pixelDensityRatio
|
||||
* @memberof OpenSeadragon
|
||||
*/
|
||||
$.pixelDensityRatio = (function () {
|
||||
$.getCurrentPixelDensityRatio = function() {
|
||||
if ( $.supportsCanvas ) {
|
||||
var context = document.createElement('canvas').getContext('2d');
|
||||
var devicePixelRatio = window.devicePixelRatio || 1;
|
||||
@ -999,7 +999,13 @@ function OpenSeadragon( options ){
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}());
|
||||
};
|
||||
|
||||
/**
|
||||
* @member {Number} pixelDensityRatio
|
||||
* @memberof OpenSeadragon
|
||||
*/
|
||||
$.pixelDensityRatio = $.getCurrentPixelDensityRatio();
|
||||
|
||||
}( OpenSeadragon ));
|
||||
|
||||
|
@ -313,8 +313,8 @@ $.TileSource.prototype = {
|
||||
*/
|
||||
getPixelRatio: function( level ) {
|
||||
var imageSizeScaled = this.dimensions.times( this.getLevelScale( level ) ),
|
||||
rx = 1.0 / imageSizeScaled.x,
|
||||
ry = 1.0 / imageSizeScaled.y;
|
||||
rx = 1.0 / imageSizeScaled.x * $.pixelDensityRatio,
|
||||
ry = 1.0 / imageSizeScaled.y * $.pixelDensityRatio;
|
||||
|
||||
return new $.Point(rx, ry);
|
||||
},
|
||||
|
@ -220,6 +220,7 @@ $.Viewer = function( options ) {
|
||||
this._updateRequestId = null;
|
||||
this._loadQueue = [];
|
||||
this.currentOverlays = [];
|
||||
this._updatePixelDensityRatioBind = null;
|
||||
|
||||
this._lastScrollTime = $.now(); // variable used to help normalize the scroll event speed of different devices
|
||||
|
||||
@ -426,6 +427,8 @@ $.Viewer = function( options ) {
|
||||
}
|
||||
}
|
||||
|
||||
this._addUpdatePixelDensityRatioEvent();
|
||||
|
||||
//Instantiate a navigator if configured
|
||||
if ( this.showNavigator){
|
||||
this.navigator = new $.Navigator({
|
||||
@ -748,6 +751,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
|
||||
return;
|
||||
}
|
||||
|
||||
this._removeUpdatePixelDensityRatioEvent();
|
||||
|
||||
this.close();
|
||||
|
||||
this.clearOverlays();
|
||||
@ -2268,6 +2273,38 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
|
||||
} else {
|
||||
$.console.warn('Attempting to display a reference strip while "sequenceMode" is off.');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds _updatePixelDensityRatio to the window resize event.
|
||||
* @private
|
||||
*/
|
||||
_addUpdatePixelDensityRatioEvent: function() {
|
||||
this._updatePixelDensityRatioBind = this._updatePixelDensityRatio.bind(this);
|
||||
$.addEvent( window, 'resize', this._updatePixelDensityRatioBind );
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes _updatePixelDensityRatio from the window resize event.
|
||||
* @private
|
||||
*/
|
||||
_removeUpdatePixelDensityRatioEvent: function() {
|
||||
$.removeEvent( window, 'resize', this._updatePixelDensityRatioBind );
|
||||
},
|
||||
|
||||
/**
|
||||
* Update pixel density ratio, clears all tiles and triggers updates for
|
||||
* all items if the ratio has changed.
|
||||
* @private
|
||||
*/
|
||||
_updatePixelDensityRatio: function() {
|
||||
var previusPixelDensityRatio = $.pixelDensityRatio;
|
||||
var currentPixelDensityRatio = $.getCurrentPixelDensityRatio();
|
||||
if (previusPixelDensityRatio !== currentPixelDensityRatio) {
|
||||
$.pixelDensityRatio = currentPixelDensityRatio;
|
||||
this.world.resetItems();
|
||||
this.forceRedraw();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user