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