OSDN Git Service

Version 0.6.48, fix X.UA for s60 Safari.
[pettanr/clientJs.git] / 0.6.x / js / dom / 13_XDomBoxModel.js
1 X.Dom.BoxModel = {\r
2         CONTENT_BOX      : 1,\r
3         PADDING_BOX      : 2,\r
4         BORDER_BOX       : 3,\r
5                 \r
6         defaultBoxModel  : 0,\r
7         boxSizingEnabled : false,\r
8         \r
9         // TODO: offsetLeft, offsetTop の基準位置\r
10         absoluteOffset   : 0,\r
11         \r
12         vScrollbarSize   : 0,\r
13         hScrollbarSize   : 0\r
14 };\r
15 \r
16 X.Dom.listenOnce( X.Dom.Event.DOM_INIT, function(){\r
17 \r
18         var node = Node._systemNode;\r
19         node.cssText( 'width:10px;padding:1px;border:2px solid #0;margin:4px;' );\r
20         \r
21         X.Dom.BoxModel.defaultBoxModel = node.width() === 10 ?\r
22                 X.Dom.BoxModel.BORDER_BOX :\r
23                 X.Dom.BoxModel.CONTENT_BOX;\r
24         \r
25         if( X.Dom.BoxModel.defaultBoxModel === X.Dom.BoxModel.CONTENT_BOX ){\r
26                 X.Dom.BoxModel.boxSizingEnabled = node.cssText( 'width:10px;padding:1px;border:2px solid #0;margin:4px;' +\r
27                         'box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing: border-box;-o-box-sizing:border-box;-ms-box-sizing:border-box;' )\r
28                                                                                         .width() === 10;\r
29         };\r
30         // padding\r
31         // border\r
32         // margin\r
33         // top\r
34 \r
35         node.cssText( 'width:90px;height:90px;overflow:auto;' )\r
36                 .html( '<div style="width:100px;height:100px;"></div>' )\r
37                 ._startUpdate();\r
38         \r
39         X.Dom.BoxModel.vScrollbarSize = 90 - node._rawNode.clientWidth;\r
40         X.Dom.BoxModel.hScrollbarSize = 90 - node._rawNode.clientHeight;\r
41 \r
42         X.Dom.BoxModel.absoluteOffset =\r
43                 node.cssText( 'position:absolute;top:0;left:0;margin:1px;border:2px solid #000;padding:4px;' )\r
44                         .firstChild().cssText( 'position:absolute;top:8px;left:8px;margin:16px;border:32px solid #666;padding:64px;' )\r
45                         .y();\r
46 \r
47         node.cssText( '' ).empty();\r
48 });\r
49 \r
50 /* --------------------------------------\r
51  * Width, Height\r
52  *  display:blobk かつ overflow:hidden かつ size(px,em)が設定されていたら、再描画しないでその値を返す\r
53  *  display:none なら 0\r
54  * \r
55  * getBoxObjectFor\r
56  * getBoundingClientRect\r
57  */\r
58 Node.prototype.width = function(){\r
59         if( !this.parent ){// todo : _state で tree に所属しているか?判定\r
60                 console.log( 'xnode.width() : no parent' );\r
61                 return 0;\r
62         };\r
63         Node.root._updateTimerID && Node.root._startUpdate();\r
64         if( !this._root ){\r
65                 console.log( 'xnode.width() : not belong tree.' );\r
66                 return 0;\r
67         };\r
68         if( this._state & X.Dom.State.DISPLAY_NONE ) return 0;\r
69         if( X.Dom.DOM_W3C ){\r
70                 // this.css( X.Dom.Style.Unit.px, 'width' );\r
71                 return this._rawNode.offsetWidth;\r
72         } else\r
73         if( X.Dom.DOM_IE4 ){\r
74                 return ( this._rawNode || this._ie4getRawNode() ).offsetWidth;\r
75         } else {\r
76                 \r
77         };\r
78 };\r
79 \r
80 Node.prototype.height = function(){\r
81         if( !this.parent ){\r
82                 console.log( 'xnode.height() : no parent' );\r
83                 return 0;\r
84         };\r
85         Node.root._updateTimerID && Node.root._startUpdate();\r
86         if( !this._root ){\r
87                 console.log( 'xnode.height() : not belong tree.' );\r
88                 return 0;\r
89         };\r
90         if( this._state & X.Dom.State.DISPLAY_NONE ) return 0;\r
91         if( X.Dom.DOM_W3C ){\r
92                 // this.css( X.Dom.Style.Unit.px, 'height' );\r
93                 return this._rawNode.offsetHeight;\r
94         } else\r
95         if( X.Dom.DOM_IE4 ){\r
96                 return ( this._rawNode || this._ie4getRawNode() ).offsetHeight;\r
97         } else {\r
98                 \r
99         };\r
100 };\r
101 \r
102 Node.prototype.scrollWidth = function(){\r
103         if( !this.parent ){// todo : _state で tree に所属しているか?判定\r
104                 console.log( 'xnode.width() : no parent' );\r
105                 return 0;\r
106         };\r
107         Node.root._updateTimerID && Node.root._startUpdate();\r
108         if( !this._root ){\r
109                 console.log( 'xnode.width() : not belong tree.' );\r
110                 return 0;\r
111         };\r
112         if( this._state & X.Dom.State.DISPLAY_NONE ) return 0;\r
113         if( X.Dom.DOM_W3C ){\r
114                 // this.css( X.Dom.Style.Unit.px, 'width' );\r
115                 return this._rawNode.scrollWidth;\r
116         } else\r
117         if( X.Dom.DOM_IE4 ){\r
118                 return ( this._rawNode || this._ie4getRawNode() ).scrollWidth;\r
119         } else {\r
120                 \r
121         };\r
122 };\r
123 \r
124 Node.prototype.scrollHeight = function(){\r
125         if( !this.parent ){\r
126                 console.log( 'xnode.height() : no parent' );\r
127                 return 0;\r
128         };\r
129         Node.root._updateTimerID && Node.root._startUpdate();\r
130         if( !this._root ){\r
131                 console.log( 'xnode.height() : not belong tree.' );\r
132                 return 0;\r
133         };\r
134         if( this._state & X.Dom.State.DISPLAY_NONE ) return 0;\r
135         if( X.Dom.DOM_W3C ){\r
136                 // this.css( X.Dom.Style.Unit.px, 'height' );\r
137                 return this._rawNode.scrollHeight;\r
138         } else\r
139         if( X.Dom.DOM_IE4 ){\r
140                 return ( this._rawNode || this._ie4getRawNode() ).scollHeight;\r
141         } else {\r
142                 \r
143         };\r
144 };\r
145 \r
146 Node.prototype.scrollLeft = function(){\r
147         if( !this.parent ){// todo : _state で tree に所属しているか?判定\r
148                 console.log( 'xnode.scrollLeft() : no parent' );\r
149                 return 0;\r
150         };\r
151         Node.root._updateTimerID && Node.root._startUpdate();\r
152         if( !this._root ){\r
153                 console.log( 'xnode.scrollLeft() : not belong tree.' );\r
154                 return 0;\r
155         };\r
156         if( this._state & X.Dom.State.DISPLAY_NONE ) return 0;\r
157         if( X.Dom.DOM_W3C ){\r
158                 // this.css( X.Dom.Style.Unit.px, 'width' );\r
159                 return this._rawNode.scrollLeft;\r
160         } else\r
161         if( X.Dom.DOM_IE4 ){\r
162                 return ( this._rawNode || this._ie4getRawNode() ).scrollLeft;\r
163         } else {\r
164                 \r
165         };\r
166 };\r
167 \r
168 Node.prototype.scrollTop = function(){\r
169         if( !this.parent ){// todo : _state で tree に所属しているか?判定\r
170                 console.log( 'xnode.scrollTop() : no parent' );\r
171                 return 0;\r
172         };\r
173         Node.root._updateTimerID && Node.root._startUpdate();\r
174         if( !this._root ){\r
175                 console.log( 'xnode.scrollTop() : not belong tree.' );\r
176                 return 0;\r
177         };\r
178         if( this._state & X.Dom.State.DISPLAY_NONE ) return 0;\r
179         if( X.Dom.DOM_W3C ){\r
180                 // this.css( X.Dom.Style.Unit.px, 'width' );\r
181                 return this._rawNode.scrollTop;\r
182         } else\r
183         if( X.Dom.DOM_IE4 ){\r
184                 return ( this._rawNode || this._ie4getRawNode() ).scrollTop;\r
185         } else {\r
186                 \r
187         };\r
188 };\r
189 \r
190 /* --------------------------------------\r
191  *  x, y\r
192  *  position:absolute かつ x か y が設定されていたら、再描画しないで css オブジェクトから計算した値を返す。 float は?\r
193  *  position:absolute の指定で自動で top,left を補う必要あり? -> X.Dom.Style\r
194  *  親要素 border 外側からの値。 IE, Firefox, Safari, Chrome の offsetLeft/Topでは、border 内側なので補正する。\r
195  * transformX, Y は加える? アニメーション中は?\r
196  */\r
197 // X.Dom.Style.transform,\r
198 Node.prototype.x = function(){\r
199         if( !this.parent ){\r
200                 console.log( 'xnode.x() : no parent' );\r
201                 return 0;\r
202         };\r
203         Node.root._updateTimerID && Node.root._startUpdate();\r
204         if( !this._root ){\r
205                 console.log( 'xnode.x() : not belong tree.' );\r
206                 return 0;\r
207         };\r
208         if( this._state & X.Dom.State.DISPLAY_NONE ) return 0;\r
209         if( X.Dom.DOM_W3C ){\r
210                 // this.css( X.Dom.Style.Unit.px, 'left' );\r
211                 // this.css( X.Dom.Style.Unit.px, 'translateX' );\r
212                 return this._rawNode.offsetLeft;\r
213         } else\r
214         if( X.Dom.DOM_IE4 ){\r
215                 return ( this._rawNode || this._ie4getRawNode() ).offsetLeft;\r
216         } else {\r
217                 \r
218         };\r
219 };\r
220 \r
221 Node.prototype.y = function(){\r
222         if( !this.parent ){\r
223                 console.log( 'xnode.y() : no parent' );\r
224                 return 0;\r
225         };\r
226         Node.root._updateTimerID && Node.root._startUpdate();\r
227         if( !this._root ){\r
228                 console.log( 'xnode.y() : not belong tree.' );\r
229                 return 0;\r
230         };\r
231         if( this._state & X.Dom.State.DISPLAY_NONE ) return 0;\r
232         if( X.Dom.DOM_W3C ){\r
233                 // this.css( X.Dom.Style.Unit.px, 'top' );\r
234                 // this.css( X.Dom.Style.Unit.px, 'transisitonY' );\r
235                 return this._rawNode.offsetTop;\r
236         } else\r
237         if( X.Dom.DOM_IE4 ){\r
238                 return ( this._rawNode || this._ie4getRawNode() ).offsetTop;            \r
239         } else {\r
240                 \r
241         };\r
242 };\r
243 \r