@@ -172,17 +172,37 @@ mpl.figure.prototype._init_canvas = function () {
172172 var entry = entries [ i ] ;
173173 var width , height ;
174174 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+ }
177184 } else {
185+ // Chrome <84 implements even older version of spec.
178186 width = entry . contentRect . width ;
179187 height = entry . contentRect . height ;
180188 }
181189
182190 // Keep the size of the canvas and rubber band canvas in sync with
183191 // 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+ }
186206 canvas . setAttribute (
187207 'style' ,
188208 'width: ' + width + 'px; height: ' + height + 'px;'
@@ -254,6 +274,7 @@ mpl.figure.prototype._init_canvas = function () {
254274
255275 // Disable right mouse context menu.
256276 this . rubberband_canvas . addEventListener ( 'contextmenu' , function ( _e ) {
277+ event . preventDefault ( ) ;
257278 return false ;
258279 } ) ;
259280
0 commit comments