@@ -172,17 +172,37 @@ mpl.figure.prototype._init_canvas = function () {
172
172
var entry = entries [ i ] ;
173
173
var width , height ;
174
174
if ( entry . contentBoxSize ) {
175
- width = entry . contentBoxSize . inlineSize ;
176
- height = entry . contentBoxSize . blockSize ;
175
+ if ( entry . contentBoxSize instanceof Array ) {
176
+ // Chrome 84 implements new version of spec.
177
+ width = entry . contentBoxSize [ 0 ] . inlineSize ;
178
+ height = entry . contentBoxSize [ 0 ] . blockSize ;
179
+ } else {
180
+ // Firefox implements old version of spec.
181
+ width = entry . contentBoxSize . inlineSize ;
182
+ height = entry . contentBoxSize . blockSize ;
183
+ }
177
184
} else {
185
+ // Chrome <84 implements even older version of spec.
178
186
width = entry . contentRect . width ;
179
187
height = entry . contentRect . height ;
180
188
}
181
189
182
190
// Keep the size of the canvas and rubber band canvas in sync with
183
191
// the canvas container.
184
- canvas . setAttribute ( 'width' , width * mpl . ratio ) ;
185
- canvas . setAttribute ( 'height' , height * mpl . ratio ) ;
192
+ if ( entry . devicePixelContentBoxSize ) {
193
+ // Chrome 84 implements new version of spec.
194
+ canvas . setAttribute (
195
+ 'width' ,
196
+ entry . devicePixelContentBoxSize [ 0 ] . inlineSize
197
+ ) ;
198
+ canvas . setAttribute (
199
+ 'height' ,
200
+ entry . devicePixelContentBoxSize [ 0 ] . blockSize
201
+ ) ;
202
+ } else {
203
+ canvas . setAttribute ( 'width' , width * mpl . ratio ) ;
204
+ canvas . setAttribute ( 'height' , height * mpl . ratio ) ;
205
+ }
186
206
canvas . setAttribute (
187
207
'style' ,
188
208
'width: ' + width + 'px; height: ' + height + 'px;'
@@ -254,6 +274,7 @@ mpl.figure.prototype._init_canvas = function () {
254
274
255
275
// Disable right mouse context menu.
256
276
this . rubberband_canvas . addEventListener ( 'contextmenu' , function ( _e ) {
277
+ event . preventDefault ( ) ;
257
278
return false ;
258
279
} ) ;
259
280
0 commit comments