OSDN Git Service

0e77c479bb7cff9c4b2596a9b0350d98a30f61f7
[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 Node.prototype.width = function(){\r
56         if( !this.parent ){// todo : _state で tree に所属しているか?判定\r
57                 console.log( 'xnode.width() : no parent' );\r
58                 return 0;\r
59         };\r
60         Node.root._updateTimerID && Node.root._startUpdate();\r
61         if( !this._root ){\r
62                 console.log( 'xnode.width() : not belong tree.' );\r
63                 return 0;\r
64         };\r
65         if( this._state & X.Dom.State.DISPLAY_NONE ) return 0;\r
66         if( X.Dom.DOM_W3C ){\r
67                 // this.css( X.Dom.Style.Unit.px, 'width' );\r
68                 return this._rawNode.offsetWidth;\r
69         } else\r
70         if( X.Dom.DOM_IE4 ){\r
71                 return ( this._rawNode || this._ie4getRawNode() ).offsetWidth;\r
72         } else {\r
73                 \r
74         };\r
75 };\r
76 \r
77 Node.prototype.height = function(){\r
78         if( !this.parent ){\r
79                 console.log( 'xnode.height() : no parent' );\r
80                 return 0;\r
81         };\r
82         Node.root._updateTimerID && Node.root._startUpdate();\r
83         if( !this._root ){\r
84                 console.log( 'xnode.height() : not belong tree.' );\r
85                 return 0;\r
86         };\r
87         if( this._state & X.Dom.State.DISPLAY_NONE ) return 0;\r
88         if( X.Dom.DOM_W3C ){\r
89                 // this.css( X.Dom.Style.Unit.px, 'height' );\r
90                 return this._rawNode.offsetHeight;\r
91         } else\r
92         if( X.Dom.DOM_IE4 ){\r
93                 return ( this._rawNode || this._ie4getRawNode() ).offsetHeight;\r
94         } else {\r
95                 \r
96         };\r
97 };\r
98 \r
99 Node.prototype.scrollWidth = function(){\r
100         if( !this.parent ){// todo : _state で tree に所属しているか?判定\r
101                 console.log( 'xnode.width() : no parent' );\r
102                 return 0;\r
103         };\r
104         Node.root._updateTimerID && Node.root._startUpdate();\r
105         if( !this._root ){\r
106                 console.log( 'xnode.width() : not belong tree.' );\r
107                 return 0;\r
108         };\r
109         if( this._state & X.Dom.State.DISPLAY_NONE ) return 0;\r
110         if( X.Dom.DOM_W3C ){\r
111                 // this.css( X.Dom.Style.Unit.px, 'width' );\r
112                 return this._rawNode.scrollWidth;\r
113         } else\r
114         if( X.Dom.DOM_IE4 ){\r
115                 return ( this._rawNode || this._ie4getRawNode() ).scrollWidth;\r
116         } else {\r
117                 \r
118         };\r
119 };\r
120 \r
121 Node.prototype.scrollHeight = function(){\r
122         if( !this.parent ){\r
123                 console.log( 'xnode.height() : no parent' );\r
124                 return 0;\r
125         };\r
126         Node.root._updateTimerID && Node.root._startUpdate();\r
127         if( !this._root ){\r
128                 console.log( 'xnode.height() : not belong tree.' );\r
129                 return 0;\r
130         };\r
131         if( this._state & X.Dom.State.DISPLAY_NONE ) return 0;\r
132         if( X.Dom.DOM_W3C ){\r
133                 // this.css( X.Dom.Style.Unit.px, 'height' );\r
134                 return this._rawNode.scrollHeight;\r
135         } else\r
136         if( X.Dom.DOM_IE4 ){\r
137                 return ( this._rawNode || this._ie4getRawNode() ).scollHeight;\r
138         } else {\r
139                 \r
140         };\r
141 };\r
142 \r
143 Node.prototype.scrollLeft = function(){\r
144         if( !this.parent ){// todo : _state で tree に所属しているか?判定\r
145                 console.log( 'xnode.scrollLeft() : no parent' );\r
146                 return 0;\r
147         };\r
148         Node.root._updateTimerID && Node.root._startUpdate();\r
149         if( !this._root ){\r
150                 console.log( 'xnode.scrollLeft() : not belong tree.' );\r
151                 return 0;\r
152         };\r
153         if( this._state & X.Dom.State.DISPLAY_NONE ) return 0;\r
154         if( X.Dom.DOM_W3C ){\r
155                 // this.css( X.Dom.Style.Unit.px, 'width' );\r
156                 return this._rawNode.scrollLeft;\r
157         } else\r
158         if( X.Dom.DOM_IE4 ){\r
159                 return ( this._rawNode || this._ie4getRawNode() ).scrollLeft;\r
160         } else {\r
161                 \r
162         };\r
163 };\r
164 \r
165 Node.prototype.scrollTop = function(){\r
166         if( !this.parent ){// todo : _state で tree に所属しているか?判定\r
167                 console.log( 'xnode.scrollTop() : no parent' );\r
168                 return 0;\r
169         };\r
170         Node.root._updateTimerID && Node.root._startUpdate();\r
171         if( !this._root ){\r
172                 console.log( 'xnode.scrollTop() : not belong tree.' );\r
173                 return 0;\r
174         };\r
175         if( this._state & X.Dom.State.DISPLAY_NONE ) return 0;\r
176         if( X.Dom.DOM_W3C ){\r
177                 // this.css( X.Dom.Style.Unit.px, 'width' );\r
178                 return this._rawNode.scrollTop;\r
179         } else\r
180         if( X.Dom.DOM_IE4 ){\r
181                 return ( this._rawNode || this._ie4getRawNode() ).scrollTop;\r
182         } else {\r
183                 \r
184         };\r
185 };\r
186 \r
187 /* --------------------------------------\r
188  *  x, y\r
189  *  position:absolute かつ x か y が設定されていたら、再描画しないで css オブジェクトから計算した値を返す。 float は?\r
190  *  position:absolute の指定で自動で top,left を補う必要あり? -> X.Dom.Style\r
191  *  親要素 border 外側からの値。 IE, Firefox, Safari, Chrome の offsetLeft/Topでは、border 内側なので補正する。\r
192  * transformX, Y は加える? アニメーション中は?\r
193  */\r
194 // X.Dom.Style.transform,\r
195 Node.prototype.x = function(){\r
196         if( !this.parent ){\r
197                 console.log( 'xnode.x() : no parent' );\r
198                 return 0;\r
199         };\r
200         Node.root._updateTimerID && Node.root._startUpdate();\r
201         if( !this._root ){\r
202                 console.log( 'xnode.x() : not belong tree.' );\r
203                 return 0;\r
204         };\r
205         if( this._state & X.Dom.State.DISPLAY_NONE ) return 0;\r
206         if( X.Dom.DOM_W3C ){\r
207                 // this.css( X.Dom.Style.Unit.px, 'left' );\r
208                 // this.css( X.Dom.Style.Unit.px, 'translateX' );\r
209                 return this._rawNode.offsetLeft;\r
210         } else\r
211         if( X.Dom.DOM_IE4 ){\r
212                 return ( this._rawNode || this._ie4getRawNode() ).offsetLeft;\r
213         } else {\r
214                 \r
215         };\r
216 };\r
217 \r
218 Node.prototype.y = function(){\r
219         if( !this.parent ){\r
220                 console.log( 'xnode.y() : no parent' );\r
221                 return 0;\r
222         };\r
223         Node.root._updateTimerID && Node.root._startUpdate();\r
224         if( !this._root ){\r
225                 console.log( 'xnode.y() : not belong tree.' );\r
226                 return 0;\r
227         };\r
228         if( this._state & X.Dom.State.DISPLAY_NONE ) return 0;\r
229         if( X.Dom.DOM_W3C ){\r
230                 // this.css( X.Dom.Style.Unit.px, 'top' );\r
231                 // this.css( X.Dom.Style.Unit.px, 'transisitonY' );\r
232                 return this._rawNode.offsetTop;\r
233         } else\r
234         if( X.Dom.DOM_IE4 ){\r
235                 return ( this._rawNode || this._ie4getRawNode() ).offsetTop;            \r
236         } else {\r
237                 \r
238         };\r
239 };\r
240 \r