@@ -35,6 +35,42 @@ cc.DENSITYDPI_HIGH = "high-dpi";
35
35
cc . DENSITYDPI_MEDIUM = "medium-dpi" ;
36
36
cc . DENSITYDPI_LOW = "low-dpi" ;
37
37
38
+ cc . __BrowserGetter = {
39
+ init : function ( ) {
40
+ this . html = document . getElementsByTagName ( "html" ) [ 0 ] ;
41
+ } ,
42
+ avaWidth : function ( frame ) {
43
+ if ( ! frame || frame === this . html )
44
+ return window . innerWidth ;
45
+ else
46
+ return frame . clientWidth ;
47
+ } ,
48
+ avaHeight : function ( frame ) {
49
+ if ( ! frame || frame === this . html )
50
+ return window . innerHeight ;
51
+ else
52
+ return frame . clientHeight ;
53
+ } ,
54
+ meta : {
55
+ "width" : "device-width" ,
56
+ "user-scalable" : "no"
57
+ }
58
+ } ;
59
+
60
+ switch ( cc . sys . browserType ) {
61
+ case cc . sys . BROWSER_TYPE_CHROME :
62
+ cc . __BrowserGetter . avaWidth = function ( frame ) {
63
+ return frame . clientWidth ;
64
+ } ;
65
+ cc . __BrowserGetter . avaHeight = function ( frame ) {
66
+ return frame . clientHeight ;
67
+ } ;
68
+ cc . __BrowserGetter . __defineGetter__ ( "target-densitydpi" , function ( ) {
69
+ return cc . view . _targetDensityDPI ;
70
+ } ) ;
71
+ break ;
72
+ }
73
+
38
74
/**
39
75
* cc.view is the singleton object which represents the game window.<br/>
40
76
* It's main task include: <br/>
@@ -205,8 +241,8 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{
205
241
206
242
_initFrameSize : function ( ) {
207
243
var locFrameSize = this . _frameSize ;
208
- locFrameSize . width = this . _frame . clientWidth ;
209
- locFrameSize . height = this . _frame . clientHeight ;
244
+ locFrameSize . width = cc . __BrowserGetter . avaWidth ( this . _frame ) ;
245
+ locFrameSize . height = cc . __BrowserGetter . avaHeight ( this . _frame ) ;
210
246
} ,
211
247
212
248
// hack
@@ -234,14 +270,7 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{
234
270
vp . name = "viewport" ;
235
271
vp . content = "" ;
236
272
237
- // For avoiding Android Firefox issue, to remove once firefox fixes its issue.
238
- if ( cc . sys . isMobile && cc . sys . browserType == cc . sys . BROWSER_TYPE_FIREFOX ) {
239
- viewportMetas = { "width" : "device-width" , "initial-scale" : "1.0" } ;
240
- } else {
241
- viewportMetas = { "width" : "device-width" , "user-scalable" : "no" , "maximum-scale" : "1.0" , "initial-scale" : "1.0" } ;
242
- }
243
- if ( cc . sys . isMobile )
244
- viewportMetas [ "target-densitydpi" ] = this . _targetDensityDPI ;
273
+ viewportMetas = cc . __BrowserGetter . meta ;
245
274
246
275
content = currentVP ? currentVP . content : "" ;
247
276
for ( var key in viewportMetas ) {
@@ -250,7 +279,7 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{
250
279
content += "," + key + "=" + viewportMetas [ key ] ;
251
280
}
252
281
}
253
- if ( content != "" )
282
+ if ( / ^ , / . test ( content ) )
254
283
content = content . substr ( 1 ) ;
255
284
256
285
vp . content = content ;
@@ -494,46 +523,56 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{
494
523
*/
495
524
setDesignResolutionSize : function ( width , height , resolutionPolicy ) {
496
525
// Defensive code
497
- if ( isNaN ( width ) || width == 0 || isNaN ( height ) || height == 0 ) {
526
+ if ( ! ( width > 0 || height > 0 ) ) {
498
527
cc . log ( cc . _LogInfos . EGLView_setDesignResolutionSize ) ;
499
528
return ;
500
529
}
501
- var _t = this ;
502
- _t . setResolutionPolicy ( resolutionPolicy ) ;
503
- var policy = _t . _resolutionPolicy ;
504
- if ( policy )
505
- policy . preApply ( _t ) ;
506
- else {
530
+
531
+ this . setResolutionPolicy ( resolutionPolicy ) ;
532
+ var policy = this . _resolutionPolicy ;
533
+ if ( ! policy ) {
507
534
cc . log ( cc . _LogInfos . EGLView_setDesignResolutionSize_2 ) ;
508
535
return ;
509
536
}
537
+ policy . preApply ( this ) ;
510
538
511
539
// Reinit frame size
512
- if ( cc . sys . isMobile )
513
- _t . _setViewPortMeta ( ) ;
514
- _t . _initFrameSize ( ) ;
515
- _t . _designResolutionSize = cc . size ( width , height ) ;
516
- _t . _originalDesignResolutionSize = cc . size ( width , height ) ;
540
+ if ( cc . sys . isMobile )
541
+ this . _setViewPortMeta ( ) ;
542
+
543
+ this . _initFrameSize ( ) ;
544
+
545
+ this . _originalDesignResolutionSize . width = this . _designResolutionSize . width = width ;
546
+ this . _originalDesignResolutionSize . height = this . _designResolutionSize . height = height ;
547
+
548
+ var result = policy . apply ( this , this . _designResolutionSize ) ;
517
549
518
- var result = policy . apply ( _t , _t . _designResolutionSize ) ;
519
- if ( result . scale && result . scale . length == 2 ) {
520
- _t . _scaleX = result . scale [ 0 ] ;
521
- _t . _scaleY = result . scale [ 1 ] ;
550
+ if ( result . scale && result . scale . length == 2 ) {
551
+ this . _scaleX = result . scale [ 0 ] ;
552
+ this . _scaleY = result . scale [ 1 ] ;
522
553
}
523
- if ( result . viewport ) {
524
- var vp = _t . _viewPortRect = result . viewport , visible = _t . _visibleRect ;
525
- visible . width = cc . _canvas . width / _t . _scaleX ;
526
- visible . height = cc . _canvas . height / _t . _scaleY ;
527
- visible . x = - vp . x / 2 / _t . _scaleX ;
528
- visible . y = - vp . y / 2 / _t . _scaleY ;
554
+
555
+ if ( result . viewport ) {
556
+ var vp = this . _viewPortRect ,
557
+ vb = this . _visibleRect ,
558
+ rv = result . viewport ;
559
+
560
+ vp . x = rv . x ;
561
+ vp . y = rv . y ;
562
+ vp . width = rv . width ;
563
+ vp . height = rv . height ;
564
+
565
+ vb . x = - vp . x / this . _scaleX ;
566
+ vb . y = - vp . y / this . _scaleY ;
567
+ vb . width = cc . _canvas . width / this . _scaleX ;
568
+ vb . height = cc . _canvas . height / this . _scaleY ;
529
569
}
530
570
531
571
// reset director's member variables to fit visible rect
532
572
var director = cc . director ;
533
- director . _winSizeInPoints . width = _t . _designResolutionSize . width ;
534
- director . _winSizeInPoints . height = _t . _designResolutionSize . height ;
535
-
536
- policy . postApply ( _t ) ;
573
+ director . _winSizeInPoints . width = this . _designResolutionSize . width ;
574
+ director . _winSizeInPoints . height = this . _designResolutionSize . height ;
575
+ policy . postApply ( this ) ;
537
576
cc . winSize . width = director . _winSizeInPoints . width ;
538
577
cc . winSize . height = director . _winSizeInPoints . height ;
539
578
@@ -543,12 +582,12 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{
543
582
director . setGLDefaultValues ( ) ;
544
583
}
545
584
546
- _t . _originalScaleX = _t . _scaleX ;
547
- _t . _originalScaleY = _t . _scaleY ;
585
+ this . _originalScaleX = this . _scaleX ;
586
+ this . _originalScaleY = this . _scaleY ;
548
587
// For editbox
549
588
if ( cc . DOM )
550
589
cc . DOM . _resetEGLViewDiv ( ) ;
551
- cc . visibleRect && cc . visibleRect . init ( _t . _visibleRect ) ;
590
+ cc . visibleRect && cc . visibleRect . init ( this . _visibleRect ) ;
552
591
} ,
553
592
554
593
/**
0 commit comments