3 * $Revision: 1.2 $ $Date: 2003/02/07 16:04:22 $
\r
6 /* ***** BEGIN LICENSE BLOCK *****
\r
7 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
\r
9 * The contents of this file are subject to the Mozilla Public License Version
\r
10 * 1.1 (the "License"); you may not use this file except in compliance with
\r
11 * the License. You may obtain a copy of the License at
\r
12 * http://www.mozilla.org/MPL/
\r
14 * Software distributed under the License is distributed on an "AS IS" basis,
\r
15 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
\r
16 * for the specific language governing rights and limitations under the
\r
19 * The Original Code is Netscape code.
\r
21 * The Initial Developer of the Original Code is
\r
22 * Netscape Corporation.
\r
23 * Portions created by the Initial Developer are Copyright (C) 2001
\r
24 * the Initial Developer. All Rights Reserved.
\r
26 * Contributor(s): Bob Clary <bclary@netscape.com>
\r
28 * ***** END LICENSE BLOCK ***** */
\r
30 function xbStyleNotSupported() {}
\r
32 function xbStyleNotSupportStringValue(propname) { xbDEBUG.dump(propname + ' is not supported in this browser'); return '';};
\r
34 /////////////////////////////////////////////////////////////
\r
37 function xbClipRect(a1, a2, a3, a4)
\r
44 if (typeof(a1) == 'string')
\r
50 if (a1.indexOf('rect(') == 0)
\r
52 // I would have preferred [0-9]+[a-zA-Z]+ for a regexp
\r
53 // but NN4 returns null for that.
\r
54 ca = a1.substring(5, a1.length-1).match(/-?[0-9a-zA-Z]+/g);
\r
55 for (i = 0; i < 4; ++i)
\r
57 val = xbToInt(ca[i]);
\r
58 if (val != 0 && ca[i].indexOf('px') == -1)
\r
60 xbDEBUG.dump('xbClipRect: A clipping region ' + a1 + ' was detected that did not use pixels as units. Click Ok to continue, Cancel to Abort');
\r
67 this.bottom = ca[2];
\r
71 else if (typeof(a1) == 'number' && typeof(a2) == 'number' && typeof(a3) == 'number' && typeof(a4) == 'number')
\r
80 xbClipRect.prototype.top = 0;
\r
81 xbClipRect.prototype.right = 0;
\r
82 xbClipRect.prototype.bottom = 0;
\r
83 xbClipRect.prototype.left = 0;
\r
86 function xbClipRectGetWidth()
\r
88 return this.right - this.left;
\r
90 xbClipRect.prototype.getWidth = xbClipRectGetWidth;
\r
92 function xbClipRectSetWidth(width)
\r
94 this.right = this.left + width;
\r
96 xbClipRect.prototype.setWidth = xbClipRectSetWidth;
\r
98 function xbClipRectGetHeight()
\r
100 return this.bottom - this.top;
\r
102 xbClipRect.prototype.getHeight = xbClipRectGetHeight;
\r
104 function xbClipRectSetHeight(height)
\r
106 this.bottom = this.top + height;
\r
108 xbClipRect.prototype.setHeight = xbClipRectSetHeight;
\r
110 function xbClipRectToString()
\r
112 return 'rect(' + this.top + 'px ' + this.right + 'px ' + this.bottom + 'px ' + this.left + 'px )' ;
\r
114 xbClipRect.prototype.toString = xbClipRectToString;
\r
116 /////////////////////////////////////////////////////////////
\r
119 // Note Opera violates the standard by cascading the effective values
\r
120 // into the HTMLElement.style object. We can use IE's HTMLElement.currentStyle
\r
121 // to get the effective values. In Gecko we will use the W3 DOM Style Standard getComputedStyle
\r
123 function xbStyle(obj, win, position)
\r
125 if (typeof(obj) == 'object' && typeof(obj.style) != 'undefined')
\r
126 this.styleObj = obj.style;
\r
127 else if (document.layers) // NN4
\r
129 if (typeof(position) == 'undefined')
\r
132 this.styleObj = obj;
\r
133 this.styleObj.position = position;
\r
136 this.window = win ? win : window;
\r
139 xbStyle.prototype.styleObj = null;
\r
140 xbStyle.prototype.object = null;
\r
142 /////////////////////////////////////////////////////////////
\r
143 // xbStyle.getEffectiveValue()
\r
144 // note that xbStyle's constructor uses the currentStyle object
\r
145 // for IE5+ and that Opera's style object contains computed values
\r
146 // already. Netscape Navigator's layer object also contains the
\r
147 // computed values as well. Note that IE4 will not return the
\r
148 // computed values.
\r
150 function xbStyleGetEffectiveValue(propname)
\r
154 if (this.window.document.defaultView && this.window.document.defaultView.getComputedStyle)
\r
157 // Note that propname is the name of the property in the CSS Style
\r
158 // Object. However the W3 method getPropertyValue takes the actual
\r
159 // property name from the CSS Style rule, i.e., propname is
\r
160 // 'backgroundColor' but getPropertyValue expects 'background-color'.
\r
163 var cappropname = propname;
\r
165 while ( (capIndex = cappropname.search(/[A-Z]/)) != -1)
\r
167 if (capIndex != -1)
\r
169 cappropname = cappropname.substring(0, capIndex) + '-' + cappropname.substring(capIndex, capIndex+1).toLowerCase() + cappropname.substr(capIndex+1);
\r
173 value = this.window.document.defaultView.getComputedStyle(this.object, '').getPropertyValue(cappropname);
\r
175 // xxxHack for Gecko:
\r
176 if (!value && this.styleObj[propname])
\r
178 value = this.styleObj[propname];
\r
181 else if (typeof(this.styleObj[propname]) == 'undefined')
\r
183 value = xbStyleNotSupportStringValue(propname);
\r
185 else if (typeof(this.object.currentStyle) != 'undefined')
\r
188 value = this.object.currentStyle[propname];
\r
191 value = this.styleObj[propname];
\r
194 if (propname == 'clip' && !value)
\r
196 // clip is not stored in IE5/6 handle separately
\r
197 value = 'rect(' + this.object.currentStyle.clipTop + ', ' + this.object.currentStyle.clipRight + ', ' + this.object.currentStyle.clipBottom + ', ' + this.object.currentStyle.clipLeft + ')';
\r
202 // IE4+, Opera, NN4
\r
203 value = this.styleObj[propname];
\r
209 /////////////////////////////////////////////////////////////////////////////
\r
210 // xbStyle.moveAbove()
\r
212 function xbStyleMoveAbove(cont)
\r
214 this.setzIndex(cont.getzIndex()+1);
\r
217 /////////////////////////////////////////////////////////////////////////////
\r
218 // xbStyle.moveBelow()
\r
220 function xbStyleMoveBelow(cont)
\r
222 var zindex = cont.getzIndex() - 1;
\r
224 this.setzIndex(zindex);
\r
227 /////////////////////////////////////////////////////////////////////////////
\r
228 // xbStyle.moveBy()
\r
230 function xbStyleMoveBy(deltaX, deltaY)
\r
232 this.moveTo(this.getLeft() + deltaX, this.getTop() + deltaY);
\r
235 /////////////////////////////////////////////////////////////////////////////
\r
236 // xbStyle.moveTo()
\r
238 function xbStyleMoveTo(x, y)
\r
244 /////////////////////////////////////////////////////////////////////////////
\r
245 // xbStyle.moveToAbsolute()
\r
247 function xbStyleMoveToAbsolute(x, y)
\r
253 /////////////////////////////////////////////////////////////////////////////
\r
254 // xbStyle.resizeBy()
\r
256 function xbStyleResizeBy(deltaX, deltaY)
\r
258 this.setWidth( this.getWidth() + deltaX );
\r
259 this.setHeight( this.getHeight() + deltaY );
\r
262 /////////////////////////////////////////////////////////////////////////////
\r
263 // xbStyle.resizeTo()
\r
265 function xbStyleResizeTo(x, y)
\r
271 ////////////////////////////////////////////////////////////////////////
\r
273 xbStyle.prototype.getEffectiveValue = xbStyleGetEffectiveValue;
\r
274 xbStyle.prototype.moveAbove = xbStyleMoveAbove;
\r
275 xbStyle.prototype.moveBelow = xbStyleMoveBelow;
\r
276 xbStyle.prototype.moveBy = xbStyleMoveBy;
\r
277 xbStyle.prototype.moveTo = xbStyleMoveTo;
\r
278 xbStyle.prototype.moveToAbsolute = xbStyleMoveToAbsolute;
\r
279 xbStyle.prototype.resizeBy = xbStyleResizeBy;
\r
280 xbStyle.prototype.resizeTo = xbStyleResizeTo;
\r
282 if (document.all || document.getElementsByName)
\r
284 xblibrary.loadScript('xbStyle-css.js');
\r
286 else if (document.layers)
\r
288 xblibrary.loadScript('xbStyle-nn4.js');
\r
292 xblibrary.loadScript('xbStyle-not-supported.js');
\r