@@ -35,6 +35,60 @@ 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
+ availWidth : function ( frame ) {
43
+ if ( ! frame || frame === this . html )
44
+ return window . innerWidth ;
45
+ else
46
+ return frame . clientWidth ;
47
+ } ,
48
+ availHeight : 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_SAFARI :
62
+ cc . __BrowserGetter . meta [ "minimal-ui" ] = "true" ;
63
+ break ;
64
+ case cc . sys . BROWSER_TYPE_CHROME :
65
+ cc . __BrowserGetter . __defineGetter__ ( "target-densitydpi" , function ( ) {
66
+ return cc . view . _targetDensityDPI ;
67
+ } ) ;
68
+ case cc . sys . BROWSER_TYPE_UC :
69
+ cc . __BrowserGetter . availWidth = function ( frame ) {
70
+ return frame . clientWidth ;
71
+ } ;
72
+ cc . __BrowserGetter . availHeight = function ( frame ) {
73
+ return frame . clientHeight ;
74
+ } ;
75
+ break ;
76
+ case cc . sys . BROWSER_TYPE_MIUI :
77
+ cc . __BrowserGetter . init = function ( view ) {
78
+ if ( view . __resizeWithBrowserSize ) return ;
79
+ var resize = function ( ) {
80
+ view . setDesignResolutionSize (
81
+ view . _designResolutionSize . width ,
82
+ view . _designResolutionSize . height ,
83
+ view . _resolutionPolicy
84
+ ) ;
85
+ window . removeEventListener ( "resize" , resize , false ) ;
86
+ } ;
87
+ window . addEventListener ( "resize" , resize , false ) ;
88
+ } ;
89
+ break ;
90
+ }
91
+
38
92
/**
39
93
* cc.view is the singleton object which represents the game window.<br/>
40
94
* It's main task include: <br/>
@@ -102,6 +156,9 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{
102
156
*/
103
157
ctor : function ( ) {
104
158
var _t = this , d = document , _strategyer = cc . ContainerStrategy , _strategy = cc . ContentStrategy ;
159
+
160
+ cc . __BrowserGetter . init ( this ) ;
161
+
105
162
_t . _frame = ( cc . container . parentNode === d . body ) ? d . documentElement : cc . container . parentNode ;
106
163
_t . _frameSize = cc . size ( 0 , 0 ) ;
107
164
_t . _initFrameSize ( ) ;
@@ -205,8 +262,8 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{
205
262
206
263
_initFrameSize : function ( ) {
207
264
var locFrameSize = this . _frameSize ;
208
- locFrameSize . width = this . _frame . clientWidth ;
209
- locFrameSize . height = this . _frame . clientHeight ;
265
+ locFrameSize . width = cc . __BrowserGetter . availWidth ( this . _frame ) ;
266
+ locFrameSize . height = cc . __BrowserGetter . availHeight ( this . _frame ) ;
210
267
} ,
211
268
212
269
// hack
@@ -234,14 +291,7 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{
234
291
vp . name = "viewport" ;
235
292
vp . content = "" ;
236
293
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 ;
294
+ viewportMetas = cc . __BrowserGetter . meta ;
245
295
246
296
content = currentVP ? currentVP . content : "" ;
247
297
for ( var key in viewportMetas ) {
@@ -250,7 +300,7 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{
250
300
content += "," + key + "=" + viewportMetas [ key ] ;
251
301
}
252
302
}
253
- if ( content != "" )
303
+ if ( / ^ , / . test ( content ) )
254
304
content = content . substr ( 1 ) ;
255
305
256
306
vp . content = content ;
@@ -494,46 +544,56 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{
494
544
*/
495
545
setDesignResolutionSize : function ( width , height , resolutionPolicy ) {
496
546
// Defensive code
497
- if ( isNaN ( width ) || width == 0 || isNaN ( height ) || height == 0 ) {
547
+ if ( ! ( width > 0 || height > 0 ) ) {
498
548
cc . log ( cc . _LogInfos . EGLView_setDesignResolutionSize ) ;
499
549
return ;
500
550
}
501
- var _t = this ;
502
- _t . setResolutionPolicy ( resolutionPolicy ) ;
503
- var policy = _t . _resolutionPolicy ;
504
- if ( policy )
505
- policy . preApply ( _t ) ;
506
- else {
551
+
552
+ this . setResolutionPolicy ( resolutionPolicy ) ;
553
+ var policy = this . _resolutionPolicy ;
554
+ if ( ! policy ) {
507
555
cc . log ( cc . _LogInfos . EGLView_setDesignResolutionSize_2 ) ;
508
556
return ;
509
557
}
558
+ policy . preApply ( this ) ;
510
559
511
560
// 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 ) ;
561
+ if ( cc . sys . isMobile )
562
+ this . _setViewPortMeta ( ) ;
563
+
564
+ this . _initFrameSize ( ) ;
565
+
566
+ this . _originalDesignResolutionSize . width = this . _designResolutionSize . width = width ;
567
+ this . _originalDesignResolutionSize . height = this . _designResolutionSize . height = height ;
568
+
569
+ var result = policy . apply ( this , this . _designResolutionSize ) ;
517
570
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 ] ;
571
+ if ( result . scale && result . scale . length == 2 ) {
572
+ this . _scaleX = result . scale [ 0 ] ;
573
+ this . _scaleY = result . scale [ 1 ] ;
522
574
}
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 ;
575
+
576
+ if ( result . viewport ) {
577
+ var vp = this . _viewPortRect ,
578
+ vb = this . _visibleRect ,
579
+ rv = result . viewport ;
580
+
581
+ vp . x = rv . x ;
582
+ vp . y = rv . y ;
583
+ vp . width = rv . width ;
584
+ vp . height = rv . height ;
585
+
586
+ vb . x = - vp . x / this . _scaleX ;
587
+ vb . y = - vp . y / this . _scaleY ;
588
+ vb . width = cc . _canvas . width / this . _scaleX ;
589
+ vb . height = cc . _canvas . height / this . _scaleY ;
529
590
}
530
591
531
592
// reset director's member variables to fit visible rect
532
593
var director = cc . director ;
533
- director . _winSizeInPoints . width = _t . _designResolutionSize . width ;
534
- director . _winSizeInPoints . height = _t . _designResolutionSize . height ;
535
-
536
- policy . postApply ( _t ) ;
594
+ director . _winSizeInPoints . width = this . _designResolutionSize . width ;
595
+ director . _winSizeInPoints . height = this . _designResolutionSize . height ;
596
+ policy . postApply ( this ) ;
537
597
cc . winSize . width = director . _winSizeInPoints . width ;
538
598
cc . winSize . height = director . _winSizeInPoints . height ;
539
599
@@ -543,12 +603,12 @@ cc.EGLView = cc.Class.extend(/** @lends cc.view# */{
543
603
director . setGLDefaultValues ( ) ;
544
604
}
545
605
546
- _t . _originalScaleX = _t . _scaleX ;
547
- _t . _originalScaleY = _t . _scaleY ;
606
+ this . _originalScaleX = this . _scaleX ;
607
+ this . _originalScaleY = this . _scaleY ;
548
608
// For editbox
549
609
if ( cc . DOM )
550
610
cc . DOM . _resetEGLViewDiv ( ) ;
551
- cc . visibleRect && cc . visibleRect . init ( _t . _visibleRect ) ;
611
+ cc . visibleRect && cc . visibleRect . init ( this . _visibleRect ) ;
552
612
} ,
553
613
554
614
/**
0 commit comments