3  * $Revision: 1.2 $ $Date: 2003/02/07 16:04:21 $
 
   7 /* ***** BEGIN LICENSE BLOCK *****
 
   8  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
  10  * The contents of this file are subject to the Mozilla Public License Version
 
  11  * 1.1 (the "License"); you may not use this file except in compliance with
 
  12  * the License. You may obtain a copy of the License at
 
  13  * http://www.mozilla.org/MPL/
 
  15  * Software distributed under the License is distributed on an "AS IS" basis,
 
  16  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
  17  * for the specific language governing rights and limitations under the
 
  20  * The Original Code is Netscape code.
 
  22  * The Initial Developer of the Original Code is
 
  23  * Netscape Corporation.
 
  24  * Portions created by the Initial Developer are Copyright (C) 2001
 
  25  * the Initial Developer. All Rights Reserved.
 
  27  * Contributor(s): Bob Clary <bclary@netscape.com>
 
  29  * ***** END LICENSE BLOCK ***** */
 
  33 function cssStyleGetClip()
 
  35   var clip = this.getEffectiveValue('clip');
 
  41   if (clip == '' || clip == 'auto')
 
  43     clip = 'rect(0px, ' + this.getWidth() + 'px, ' + this.getHeight() + 'px, 0px)';
 
  47     clip = clip.replace(/px /g, 'px, ');
 
  55 function cssStyleSetClip(sClipString)
 
  57   this.styleObj.clip = sClipString;
 
  60 // xbStyle.getClipTop()
 
  62 function cssStyleGetClipTop()
 
  64   var clip = this.getClip();
 
  65   var rect = new xbClipRect(clip);
 
  69 // xbStyle.setClipTop()
 
  71 function cssStyleSetClipTop(top)
 
  73   var clip = this.getClip();
 
  74   var rect         = new xbClipRect(clip);
 
  76   this.styleObj.clip = rect.toString();
 
  79 // xbStyle.getClipRight()
 
  81 function cssStyleGetClipRight()
 
  83   var clip = this.getClip();
 
  84   var rect = new xbClipRect(clip);
 
  88 // xbStyle.setClipRight()
 
  90 function cssStyleSetClipRight(right)
 
  92   var clip = this.getClip();
 
  93   var rect          = new xbClipRect(clip);
 
  95   this.styleObj.clip  = rect.toString();
 
  98 // xbStyle.getClipBottom()
 
 100 function cssStyleGetClipBottom()
 
 102   var clip = this.getClip();
 
 103   var rect = new xbClipRect(clip);
 
 107 // xbStyle.setClipBottom()
 
 109 function cssStyleSetClipBottom(bottom)
 
 111   var clip = this.getClip();
 
 112   var rect           = new xbClipRect(clip);
 
 113   rect.bottom        = bottom;
 
 114   this.styleObj.clip   = rect.toString();
 
 117 // xbStyle.getClipLeft()
 
 119 function cssStyleGetClipLeft()
 
 121   var clip = this.getClip();
 
 122   var rect = new xbClipRect(clip);
 
 126 // xbStyle.setClipLeft()
 
 128 function cssStyleSetClipLeft(left)
 
 130   var clip = this.getClip();
 
 131   var rect = new xbClipRect(clip);
 
 133   this.styleObj.clip = rect.toString();
 
 136 // xbStyle.getClipWidth()
 
 138 function cssStyleGetClipWidth()
 
 140   var clip = this.getClip();
 
 141   var rect = new xbClipRect(clip);
 
 142   return rect.getWidth();
 
 145 // xbStyle.setClipWidth()
 
 147 function cssStyleSetClipWidth(width)
 
 149   var clip = this.getClip();
 
 150   var rect = new xbClipRect(clip);
 
 151   rect.setWidth(width);
 
 152   this.styleObj.clip = rect.toString();
 
 155 // xbStyle.getClipHeight()
 
 157 function cssStyleGetClipHeight()
 
 159   var clip = this.getClip();
 
 160   var rect = new xbClipRect(clip);
 
 161   return rect.getHeight();
 
 164 // xbStyle.setClipHeight()
 
 166 function cssStyleSetClipHeight(height)
 
 168   var clip = this.getClip();
 
 169   var rect = new xbClipRect(clip);
 
 170   rect.setHeight(height);
 
 171   this.styleObj.clip = rect.toString();
 
 174 // the CSS attributes left,top are for absolutely positioned elements
 
 175 // measured relative to the containing element.  for relatively positioned
 
 176 // elements, left,top are measured from the element's normal inline position.
 
 177 // getLeft(), setLeft() operate on this type of coordinate.
 
 179 // to allow dynamic positioning the getOffsetXXX and setOffsetXXX methods are
 
 180 // defined to return and set the position of either an absolutely or relatively
 
 181 // positioned element relative to the containing element.
 
 187 function cssStyleGetLeft()
 
 189   var left = this.getEffectiveValue('left');
 
 190   if (typeof(left) == 'number')
 
 193   if (left != '' && left.indexOf('px') == -1)
 
 195     xbDEBUG.dump('xbStyle.getLeft: Element ID=' + this.object.id + ' does not use pixels as units. left=' + left + ' Click Ok to continue, Cancel to Abort');
 
 199   if (top == 'auto' && this.object && typeof(this.object.offsetTop) == 'number')
 
 201     left = this.object.offsetTop + 'px';
 
 207   return xbToInt(left);
 
 212 function cssStyleSetLeft(left)
 
 214   if (typeof(this.styleObj.left) == 'number')
 
 215     this.styleObj.left = left;
 
 217     this.styleObj.left = left + 'px';
 
 222 function cssStyleGetTop()
 
 224   var top = this.getEffectiveValue('top');
 
 225   if (typeof(top) == 'number')
 
 228   if (top != '' && top.indexOf('px') == -1)
 
 230     xbDEBUG.dump('xbStyle.getTop: Element ID=' + this.object.id + ' does not use pixels as units. top=' + top + ' Click Ok to continue, Cancel to Abort');
 
 234   if (top == 'auto' && this.object && typeof(this.object.offsetTop) == 'number')
 
 236     top = this.object.offsetTop + 'px';
 
 247 function cssStyleSetTop(top)
 
 249   if (typeof(this.styleObj.top) == 'number')
 
 250     this.styleObj.top = top;
 
 252     this.styleObj.top = top + 'px';
 
 255 // xbStyle.getPageX()
 
 257 function cssStyleGetPageX()
 
 260   var elm = this.object;
 
 264   //xxxHack: Due to limitations in Gecko's (0.9.6) ability to determine the 
 
 265   // effective position attribute , attempt to use offsetXXX
 
 267   if (typeof(elm.offsetLeft) == 'number')
 
 272       elm = elm.offsetParent;
 
 281         elmstyle = new xbStyle(elm);
 
 282         position = elmstyle.getEffectiveValue('position');
 
 283         if (position != '' && position != 'static')
 
 284           x += elmstyle.getLeft();
 
 286       elm = elm.parentNode;
 
 293 // xbStyle.setPageX()
 
 295 function cssStyleSetPageX(x)
 
 298   var elm = this.object.parentNode;
 
 302   //xxxHack: Due to limitations in Gecko's (0.9.6) ability to determine the 
 
 303   // effective position attribute , attempt to use offsetXXX
 
 305   if (elm && typeof(elm.offsetLeft) == 'number')
 
 309       xParent += elm.offsetLeft;
 
 310       elm = elm.offsetParent;
 
 319         elmstyle = new xbStyle(elm);
 
 320         position = elmstyle.getEffectiveValue('position');
 
 321         if (position != '' && position != 'static')
 
 322           xParent += elmstyle.getLeft();
 
 324       elm = elm.parentNode;
 
 333 // xbStyle.getPageY()
 
 335 function cssStyleGetPageY()
 
 338   var elm = this.object;
 
 342   //xxxHack: Due to limitations in Gecko's (0.9.6) ability to determine the 
 
 343   // effective position attribute , attempt to use offsetXXX
 
 345   if (typeof(elm.offsetTop) == 'number')
 
 350       elm = elm.offsetParent;
 
 359         elmstyle = new xbStyle(elm);
 
 360         position = elmstyle.getEffectiveValue('position');
 
 361         if (position != '' && position != 'static')
 
 362           y += elmstyle.getTop();
 
 364       elm = elm.parentNode;
 
 371 // xbStyle.setPageY()
 
 373 function cssStyleSetPageY(y)
 
 376   var elm = this.object.parentNode;
 
 380   //xxxHack: Due to limitations in Gecko's (0.9.6) ability to determine the 
 
 381   // effective position attribute , attempt to use offsetXXX
 
 383   if (elm && typeof(elm.offsetTop) == 'number')
 
 387       yParent += elm.offsetTop;
 
 388       elm = elm.offsetParent;
 
 397         elmstyle = new xbStyle(elm);
 
 398         position = elmstyle.getEffectiveValue('position');
 
 399         if (position != '' && position != 'static')
 
 400           yParent += elmstyle.getTop();
 
 402       elm = elm.parentNode;
 
 411 // xbStyle.getHeight()
 
 413 function cssStyleGetHeight()
 
 415   var display = this.getEffectiveValue('display');
 
 416   var height = this.getEffectiveValue('height');
 
 418   if (typeof(height) == 'number')
 
 424   if (height == '' || height == 'auto' || height.indexOf('%') != -1)
 
 426     if (typeof(this.object.offsetHeight) == 'number')
 
 428       height = this.object.offsetHeight + 'px';
 
 430     else if (typeof(this.object.scrollHeight) == 'number')
 
 432       height = this.object.scrollHeight + 'px';
 
 436   if (height.indexOf('px') == -1)
 
 438     xbDEBUG.dump('xbStyle.getHeight: Element ID=' + this.object.id + ' does not use pixels as units. height=' + height + ' Click Ok to continue, Cancel to Abort');
 
 442   height = xbToInt(height);
 
 447 // xbStyle.setHeight()
 
 449 function cssStyleSetHeight(height)
 
 451   if (typeof(this.styleObj.height) == 'number')
 
 452     this.styleObj.height = height;
 
 454     this.styleObj.height = height + 'px';
 
 457 // xbStyle.getWidth()
 
 459 function cssStyleGetWidth()
 
 461   var display = this.getEffectiveValue('display');
 
 462   var width = this.getEffectiveValue('width');
 
 464   if (typeof(width) == 'number')
 
 466      // note Opera 6 has a bug in width and offsetWidth where 
 
 467      // it returns the page width. Use clientWidth instead.
 
 468      if (navigator.userAgent.indexOf('Opera') != -1)
 
 469        return this.object.clientWidth;
 
 474   if (width == '' || width == 'auto' || width.indexOf('%') != -1)
 
 476     if (typeof(this.object.offsetWidth) == 'number')
 
 478       width = this.object.offsetWidth + 'px';
 
 480     else if (typeof(this.object.scrollHeight) == 'number')
 
 482       width = this.object.scrollWidth + 'px';
 
 486   if (width.indexOf('px') == -1)
 
 488     xbDEBUG.dump('xbStyle.getWidth: Element ID=' + this.object.id + ' does not use pixels as units. width=' + width + ' Click Ok to continue, Cancel to Abort');
 
 492   width = xbToInt(width);
 
 497 // xbStyle.setWidth()
 
 499 function cssStyleSetWidth(width)
 
 501   if (typeof(this.styleObj.width) == 'number')
 
 502     this.styleObj.width = width;
 
 504     this.styleObj.width = width + 'px';
 
 507 // xbStyle.getVisibility()
 
 509 function cssStyleGetVisibility()
 
 511   return this.getEffectiveValue('visibility');
 
 514 // xbStyle.setVisibility()
 
 516 function cssStyleSetVisibility(visibility)
 
 518   this.styleObj.visibility = visibility;
 
 521 // xbStyle.getzIndex()
 
 523 function cssStyleGetzIndex()
 
 525   return xbToInt(this.getEffectiveValue('zIndex'));
 
 528 // xbStyle.setzIndex()
 
 530 function cssStyleSetzIndex(zIndex)
 
 532   this.styleObj.zIndex = zIndex;
 
 535 // xbStyle.getBackgroundColor()
 
 537 function cssStyleGetBackgroundColor()
 
 539   return this.getEffectiveValue('backgroundColor');
 
 542 // xbStyle.setBackgroundColor()
 
 544 function cssStyleSetBackgroundColor(color)
 
 546   this.styleObj.backgroundColor = color;
 
 549 // xbStyle.getColor()
 
 551 function cssStyleGetColor()
 
 553   return this.getEffectiveValue('color');
 
 556 // xbStyle.setColor()
 
 558 function cssStyleSetColor(color)
 
 560   this.styleObj.color = color;
 
 563 // xbStyle.moveAbove()
 
 565 function xbStyleMoveAbove(cont)
 
 567   this.setzIndex(cont.getzIndex()+1);
 
 570 // xbStyle.moveBelow()
 
 572 function xbStyleMoveBelow(cont)
 
 574   var zindex = cont.getzIndex() - 1;
 
 576   this.setzIndex(zindex);
 
 581 function xbStyleMoveBy(deltaX, deltaY)
 
 583   this.moveTo(this.getLeft() + deltaX, this.getTop() + deltaY);
 
 588 function xbStyleMoveTo(x, y)
 
 594 // xbStyle.moveToAbsolute()
 
 596 function xbStyleMoveToAbsolute(x, y)
 
 602 // xbStyle.resizeBy()
 
 604 function xbStyleResizeBy(deltaX, deltaY)
 
 606   this.setWidth( this.getWidth() + deltaX );
 
 607   this.setHeight( this.getHeight() + deltaY );
 
 610 // xbStyle.resizeTo()
 
 612 function xbStyleResizeTo(x, y)
 
 618 // xbStyle.setInnerHTML()
 
 620 function xbSetInnerHTML(str)
 
 622   if (typeof(this.object.innerHTML) != 'undefined')
 
 623     this.object.innerHTML = str;
 
 627 // Extensions to xbStyle that are not supported by Netscape Navigator 4
 
 628 // but that provide cross browser implementations of properties for 
 
 629 // Mozilla, Gecko, Netscape 6.x and Opera
 
 631 // xbStyle.getBorderTopWidth()
 
 633 function cssStyleGetBorderTopWidth()
 
 635   return xbToInt(this.getEffectiveValue('borderTopWidth'));
 
 638 // xbStyle.getBorderRightWidth()
 
 640 function cssStyleGetBorderRightWidth()
 
 642   return xbToInt(this.getEffectiveValue('borderRightWidth'));
 
 645 // xbStyle.getBorderBottomWidth()
 
 647 function cssStyleGetBorderBottomWidth()
 
 649   return xbToInt(this.getEffectiveValue('borderBottomWidth'));
 
 652 // xbStyle.getBorderLeftWidth()
 
 654 function cssStyleGetBorderLeftWidth()
 
 656   return xbToInt(this.getEffectiveValue('borderLeftWidth'));
 
 659 // xbStyle.getMarginTop()
 
 661 function cssStyleGetMarginTop()
 
 663   return xbToInt(this.getEffectiveValue('marginTop'));
 
 666 // xbStyle.getMarginRight()
 
 668 function cssStyleGetMarginRight()
 
 670   return xbToInt(this.getEffectiveValue('marginRight'));
 
 673 // xbStyle.getMarginBottom()
 
 675 function cssStyleGetMarginBottom()
 
 677   return xbToInt(this.getEffectiveValue('marginBottom'));
 
 680 // xbStyle.getMarginLeft()
 
 682 function cssStyleGetMarginLeft()
 
 684   return xbToInt(this.getEffectiveValue('marginLeft'));
 
 687 // xbStyle.getPaddingTop()
 
 689 function cssStyleGetPaddingTop()
 
 691   return xbToInt(this.getEffectiveValue('paddingTop'));
 
 694 // xbStyle.getPaddingRight()
 
 696 function cssStyleGetPaddingRight()
 
 698   return xbToInt(this.getEffectiveValue('paddingRight'));
 
 701 // xbStyle.getPaddingBottom()
 
 703 function cssStyleGetPaddingBottom()
 
 705   return xbToInt(this.getEffectiveValue('paddingBottom'));
 
 708 // xbStyle.getPaddingLeft()
 
 710 function cssStyleGetPaddingLeft()
 
 712   return xbToInt(this.getEffectiveValue('paddingLeft'));
 
 715 // xbStyle.getClientWidth()
 
 717 function cssStyleGetClientWidth()
 
 719   return this.getWidth() + this.getPaddingLeft() + this.getPaddingRight();
 
 721   if (typeof(this.object.clientWidth) == 'number')
 
 722     return this.object.clientWidth;
 
 728 // xbStyle.getClientHeight()
 
 730 function cssStyleGetClientHeight()
 
 732   return this.getHeight() + this.getPaddingTop() + this.getPaddingBottom();
 
 734   if (typeof(this.object.clientHeight) == 'number')
 
 735     return this.object.clientHeight;
 
 741 xbStyle.prototype.getClip            = cssStyleGetClip;
 
 742 xbStyle.prototype.setClip            = cssStyleSetClip;  
 
 743 xbStyle.prototype.getClipTop         = cssStyleGetClipTop;
 
 744 xbStyle.prototype.setClipTop         = cssStyleSetClipTop;  
 
 745 xbStyle.prototype.getClipRight       = cssStyleGetClipRight;
 
 746 xbStyle.prototype.setClipRight       = cssStyleSetClipRight;  
 
 747 xbStyle.prototype.getClipBottom      = cssStyleGetClipBottom;
 
 748 xbStyle.prototype.setClipBottom      = cssStyleSetClipBottom;  
 
 749 xbStyle.prototype.getClipLeft        = cssStyleGetClipLeft;
 
 750 xbStyle.prototype.setClipLeft        = cssStyleSetClipLeft;  
 
 751 xbStyle.prototype.getClipWidth       = cssStyleGetClipWidth;
 
 752 xbStyle.prototype.setClipWidth       = cssStyleSetClipWidth;  
 
 753 xbStyle.prototype.getClipHeight      = cssStyleGetClipHeight;
 
 754 xbStyle.prototype.setClipHeight      = cssStyleSetClipHeight;  
 
 755 xbStyle.prototype.getLeft            = cssStyleGetLeft;
 
 756 xbStyle.prototype.setLeft            = cssStyleSetLeft;
 
 757 xbStyle.prototype.getTop             = cssStyleGetTop;
 
 758 xbStyle.prototype.setTop             = cssStyleSetTop;
 
 759 xbStyle.prototype.getPageX           = cssStyleGetPageX;
 
 760 xbStyle.prototype.setPageX           = cssStyleSetPageX;
 
 761 xbStyle.prototype.getPageY           = cssStyleGetPageY;
 
 762 xbStyle.prototype.setPageY           = cssStyleSetPageY;
 
 763 xbStyle.prototype.getVisibility      = cssStyleGetVisibility;
 
 764 xbStyle.prototype.setVisibility      = cssStyleSetVisibility;
 
 765 xbStyle.prototype.getzIndex          = cssStyleGetzIndex;
 
 766 xbStyle.prototype.setzIndex          = cssStyleSetzIndex;            
 
 767 xbStyle.prototype.getHeight          = cssStyleGetHeight;
 
 768 xbStyle.prototype.setHeight          = cssStyleSetHeight;
 
 769 xbStyle.prototype.getWidth           = cssStyleGetWidth;
 
 770 xbStyle.prototype.setWidth           = cssStyleSetWidth;
 
 771 xbStyle.prototype.getBackgroundColor = cssStyleGetBackgroundColor;
 
 772 xbStyle.prototype.setBackgroundColor = cssStyleSetBackgroundColor;
 
 773 xbStyle.prototype.getColor           = cssStyleGetColor;
 
 774 xbStyle.prototype.setColor           = cssStyleSetColor;
 
 775 xbStyle.prototype.setInnerHTML       = xbSetInnerHTML;
 
 776 xbStyle.prototype.getBorderTopWidth    = cssStyleGetBorderTopWidth;
 
 777 xbStyle.prototype.getBorderRightWidth  = cssStyleGetBorderRightWidth;
 
 778 xbStyle.prototype.getBorderBottomWidth = cssStyleGetBorderBottomWidth;
 
 779 xbStyle.prototype.getBorderLeftWidth   = cssStyleGetBorderLeftWidth;
 
 780 xbStyle.prototype.getMarginLeft        = cssStyleGetMarginLeft;
 
 781 xbStyle.prototype.getMarginTop         = cssStyleGetMarginTop;
 
 782 xbStyle.prototype.getMarginRight       = cssStyleGetMarginRight;
 
 783 xbStyle.prototype.getMarginBottom      = cssStyleGetMarginBottom;
 
 784 xbStyle.prototype.getMarginLeft        = cssStyleGetMarginLeft;
 
 785 xbStyle.prototype.getPaddingTop        = cssStyleGetPaddingTop;
 
 786 xbStyle.prototype.getPaddingRight      = cssStyleGetPaddingRight;
 
 787 xbStyle.prototype.getPaddingBottom     = cssStyleGetPaddingBottom;
 
 788 xbStyle.prototype.getPaddingLeft       = cssStyleGetPaddingLeft;
 
 789 xbStyle.prototype.getClientWidth       = cssStyleGetClientWidth;
 
 790 xbStyle.prototype.getClientHeight      = cssStyleGetClientHeight;