55 */
66
77var Class = require ( '../utils/Class' ) ;
8+ var Rectangle = require ( '../geom/rectangle/Rectangle' ) ;
89var Vec2 = require ( '../math/Vector2' ) ;
910
1011/*
@@ -30,7 +31,7 @@ var Vec2 = require('../math/Vector2');
3031 * @class ScaleManager
3132 * @memberOf Phaser.Boot
3233 * @constructor
33- * @since 3.12 .0
34+ * @since 3.15 .0
3435 *
3536 * @param {Phaser.Game } game - A reference to the Phaser.Game instance.
3637 * @param {any } config
@@ -47,148 +48,221 @@ var ScaleManager = new Class({
4748 * @name Phaser.Boot.ScaleManager#game
4849 * @type {Phaser.Game }
4950 * @readOnly
50- * @since 3.12 .0
51+ * @since 3.15 .0
5152 */
5253 this . game = game ;
5354
5455 this . config = config ;
5556
56- /**
57- * Target width (in pixels) of the Display canvas.
58- * @property {number } width
59- * @readonly
60- */
6157 this . width = 0 ;
6258
63- /**
64- * Target height (in pixels) of the Display canvas.
65- * @property {number } height
66- * @readonly
67- */
6859 this . height = 0 ;
6960
70- this . zoom = 0 ;
61+ this . minWidth = null ;
7162
72- this . resolution = 1 ;
63+ this . maxWidth = null ;
7364
74- this . parent = null ;
65+ this . minHeight = null ;
7566
76- this . scaleMode = 0 ;
67+ this . maxHeight = null ;
7768
78- /**
79- * Minimum width the canvas should be scaled to (in pixels).
80- * Change with {@link #setMinMax}.
81- * @property {?number } minWidth
82- * @readonly
83- * @protected
84- */
85- this . minWidth = null ;
69+ this . offset = new Vec2 ( ) ;
8670
87- /**
88- * Minimum height the canvas should be scaled to (in pixels).
89- * Change with {@link #setMinMax}.
90- * @property {?number } minHeight
91- * @readonly
92- * @protected
93- */
94- this . minHeight = null ;
71+ this . forceLandscape = false ;
9572
96- /**
97- * Maximum width the canvas should be scaled to (in pixels).
98- * If null it will scale to whatever width the browser can handle.
99- * Change with {@link #setMinMax}.
100- * @property {?number } maxWidth
101- * @readonly
102- * @protected
103- */
104- this . maxWidth = null ;
73+ this . forcePortrait = false ;
10574
106- /**
107- * Maximum height the canvas should be scaled to (in pixels).
108- * If null it will scale to whatever height the browser can handle.
109- * Change with {@link #setMinMax}.
110- * @property {?number } maxHeight
111- * @readonly
112- * @protected
113- */
114- this . maxHeight = null ;
75+ this . incorrectOrientation = false ;
76+
77+ this . _pageAlignHorizontally = false ;
78+
79+ this . _pageAlignVertically = false ;
80+
81+ this . hasPhaserSetFullScreen = false ;
82+
83+ this . fullScreenTarget = null ;
84+
85+ this . _createdFullScreenTarget = null ;
86+
87+ this . screenOrientation = this . dom . getScreenOrientation ( ) ;
11588
116- /**
117- * The _current_ scale factor based on the game dimensions vs. the scaled dimensions.
118- * @property {Phaser.Point } scaleFactor
119- * @readonly
120- */
12189 this . scaleFactor = new Vec2 ( 1 , 1 ) ;
12290
123- /**
124- * The _current_ inversed scale factor. The displayed dimensions divided by the game dimensions.
125- * @property {Phaser.Point } scaleFactorInversed
126- * @readonly
127- * @protected
128- */
12991 this . scaleFactorInversed = new Vec2 ( 1 , 1 ) ;
13092
131- /**
132- * The aspect ratio of the scaled Display canvas.
133- * @property {number } aspectRatio
134- * @readonly
135- */
93+ this . margin = { left : 0 , top : 0 , right : 0 , bottom : 0 , x : 0 , y : 0 } ;
94+
95+ this . bounds = new Rectangle ( ) ;
96+
13697 this . aspectRatio = 0 ;
13798
138- /**
139- * The aspect ratio of the original game dimensions.
140- * @property {number } sourceAspectRatio
141- * @readonly
142- */
14399 this . sourceAspectRatio = 0 ;
144100
145- /**
146- * True if the the browser window (instead of the display canvas's DOM parent) should be used as the bounding parent.
147- *
148- * This is set automatically based on the `parent` argument passed to {@link Phaser.Game}.
149- *
150- * The {@link #parentNode} property is generally ignored while this is in effect.
151- *
152- * @property {boolean } parentIsWindow
153- */
101+ this . event = null ;
102+
103+ this . windowConstraints = {
104+ right : 'layout' ,
105+ bottom : ''
106+ } ;
107+
108+ this . compatibility = {
109+ supportsFullScreen : false ,
110+ orientationFallback : null ,
111+ noMargins : false ,
112+ scrollTo : null ,
113+ forceMinimumDocumentHeight : false ,
114+ canExpandParent : true ,
115+ clickTrampoline : ''
116+ } ;
117+
118+ this . _scaleMode = Phaser . ScaleManager . NO_SCALE ;
119+
120+ this . _fullScreenScaleMode = Phaser . ScaleManager . NO_SCALE ;
121+
154122 this . parentIsWindow = false ;
155123
156- /**
157- * The _original_ DOM element for the parent of the Display canvas.
158- * This may be different in fullscreen - see {@link #createFullScreenTarget}.
159- *
160- * This is set automatically based on the `parent` argument passed to {@link Phaser.Game}.
161- *
162- * This should only be changed after moving the Game canvas to a different DOM parent.
163- *
164- * @property {?DOMElement } parentNode
165- */
166124 this . parentNode = null ;
167125
168- /**
169- * The scale of the game in relation to its parent container.
170- * @property {Phaser.Point } parentScaleFactor
171- * @readonly
172- */
173126 this . parentScaleFactor = new Vec2 ( 1 , 1 ) ;
174127
175- this . _lastParentWidth = 0 ;
128+ this . trackParentInterval = 2000 ;
129+
130+ this . onResize = null ;
131+
132+ this . onResizeContext = null ;
133+
134+ this . _pendingScaleMode = null ;
135+
136+ this . _fullScreenRestore = null ;
137+
138+ this . _gameSize = new Rectangle ( ) ;
139+
140+ this . _userScaleFactor = new Vec2 ( 1 , 1 ) ;
141+
142+ this . _userScaleTrim = new Vec2 ( 0 , 0 ) ;
143+
144+ this . _lastUpdate = 0 ;
145+
146+ this . _updateThrottle = 0 ;
147+
148+ this . _updateThrottleReset = 100 ;
149+
150+ this . _parentBounds = new Rectangle ( ) ;
176151
177- this . _lastParentHeight = 0 ;
152+ this . _tempBounds = new Rectangle ( ) ;
178153
179- this . _innerHeight = 0 ;
154+ this . _lastReportedCanvasSize = new Rectangle ( ) ;
180155
181- this . init ( ) ;
156+ this . _lastReportedGameSize = new Rectangle ( ) ;
157+
158+ this . _booted = false ;
182159 } ,
183160
184- init : function ( )
161+ boot : function ( )
185162 {
186- this . _innerHeight = this . getInnerHeight ( ) ;
187-
163+ // this._innerHeight = this.getInnerHeight();
188164 // var gameWidth = this.config.width;
189165 // var gameHeight = this.config.height;
166+
167+ // Configure device-dependent compatibility
168+
169+ var game = this . game ;
170+ var device = game . device ;
171+ var os = game . device . os ;
172+ var compat = this . compatibility ;
173+
174+ compat . supportsFullScreen = device . fullscreen . available && ! os . cocoonJS ;
175+
176+ // We can't do anything about the status bars in iPads, web apps or desktops
177+ if ( ! os . iPad && ! os . webApp && ! os . desktop )
178+ {
179+ if ( os . android && ! device . browser . chrome )
180+ {
181+ compat . scrollTo = new Vec2 ( 0 , 1 ) ;
182+ }
183+ else
184+ {
185+ compat . scrollTo = new Vec2 ( 0 , 0 ) ;
186+ }
187+ }
188+
189+ if ( os . desktop )
190+ {
191+ compat . orientationFallback = 'screen' ;
192+ compat . clickTrampoline = 'when-not-mouse' ;
193+ }
194+ else
195+ {
196+ compat . orientationFallback = '' ;
197+ compat . clickTrampoline = '' ;
198+ }
199+
200+ // Configure event listeners
201+
202+ var _this = this ;
203+
204+ this . _orientationChange = function ( event )
205+ {
206+ return _this . orientationChange ( event ) ;
207+ } ;
208+
209+ this . _windowResize = function ( event )
210+ {
211+ return _this . windowResize ( event ) ;
212+ } ;
213+
214+ // This does not appear to be on the standards track
215+ window . addEventListener ( 'orientationchange' , this . _orientationChange , false ) ;
216+ window . addEventListener ( 'resize' , this . _windowResize , false ) ;
217+
218+ if ( this . compatibility . supportsFullScreen )
219+ {
220+ this . _fullScreenChange = function ( event )
221+ {
222+ return _this . fullScreenChange ( event ) ;
223+ } ;
224+
225+ this . _fullScreenError = function ( event )
226+ {
227+ return _this . fullScreenError ( event ) ;
228+ } ;
229+
230+ var vendors = [ 'webkit' , 'moz' , '' ] ;
231+
232+ vendors . forEach ( function ( prefix )
233+ {
234+ document . addEventListener ( prefix + 'fullscreenchange' , this . _fullScreenChange , false ) ;
235+ document . addEventListener ( prefix + 'fullscreenerror' , this . _fullScreenError , false ) ;
236+ } ) ;
237+
238+ // MS Specific
239+ document . addEventListener ( 'MSFullscreenChange' , this . _fullScreenChange , false ) ;
240+ document . addEventListener ( 'MSFullscreenError' , this . _fullScreenError , false ) ;
241+ }
242+
243+ this . game . events . on ( 'resume' , this . _gameResumed , this ) ;
244+
245+ // Initialize core bounds
246+
247+ // this.dom.getOffset(this.game.canvas, this.offset);
248+
249+ this . bounds . setTo ( this . offset . x , this . offset . y , this . width , this . height ) ;
250+
251+ this . setGameSize ( this . game . width , this . game . height ) ;
252+
253+ // Don't use updateOrientationState so events are not fired
254+ // this.screenOrientation = this.dom.getScreenOrientation(this.compatibility.orientationFallback);
255+
256+ this . _booted = true ;
257+
258+ if ( this . _pendingScaleMode !== null )
259+ {
260+ this . scaleMode = this . _pendingScaleMode ;
261+ this . _pendingScaleMode = null ;
262+ }
190263 } ,
191264
265+ /*
192266 centerDisplay: function ()
193267 {
194268 var height = this.height;
@@ -202,6 +276,7 @@ var ScaleManager = new Class({
202276 this.canvas.style.width = gameWidth + 'px';
203277 this.canvas.style.height = gameHeight + 'px';
204278 },
279+ */
205280
206281 /*
207282 iOS10 Resize hack. Thanks, Apple.
0 commit comments