Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
nsHTMLHRElement.cpp File Reference
#include "nsIDOMHTMLHRElement.h"
#include "nsIDOMNSHTMLHRElement.h"
#include "nsIDOMEventReceiver.h"
#include "nsGenericHTMLElement.h"
#include "nsHTMLAtoms.h"
#include "nsStyleConsts.h"
#include "nsPresContext.h"
#include "nsMappedAttributes.h"
#include "nsRuleData.h"

Go to the source code of this file.

Classes

class  nsHTMLHRElement

Functions

static void MapAttributesIntoRule (const nsMappedAttributes *aAttributes, nsRuleData *aData)

Variables

static
NS_HTML_CONTENT_INTERFACE_MAP_END
const nsAttrValue::EnumTable 
kAlignTable []

Function Documentation

static void MapAttributesIntoRule ( const nsMappedAttributes aAttributes,
nsRuleData aData 
) [static]

Definition at line 144 of file nsHTMLHRElement.cpp.

{
  PRBool noshade = PR_FALSE;

  const nsAttrValue* colorValue = aAttributes->GetAttr(nsHTMLAtoms::color);
  nscolor color;
  PRBool colorIsSet = colorValue && colorValue->GetColorValue(color);

  if (aData->mSID == eStyleStruct_Position ||
      aData->mSID == eStyleStruct_Border) {
    if (colorIsSet) {
      noshade = PR_TRUE;
    } else {
      noshade = !!aAttributes->GetAttr(nsHTMLAtoms::noshade);
    }
  }

  if (aData->mSID == eStyleStruct_Margin) {
    // align: enum
    const nsAttrValue* value = aAttributes->GetAttr(nsHTMLAtoms::align);
    if (value && value->Type() == nsAttrValue::eEnum) {
      // Map align attribute into auto side margins
      nsCSSRect& margin = aData->mMarginData->mMargin;
      switch (value->GetEnumValue()) {
      case NS_STYLE_TEXT_ALIGN_LEFT:
        if (margin.mLeft.GetUnit() == eCSSUnit_Null)
          margin.mLeft.SetFloatValue(0.0f, eCSSUnit_Pixel);
        if (margin.mRight.GetUnit() == eCSSUnit_Null)
          margin.mRight.SetAutoValue();
        break;
      case NS_STYLE_TEXT_ALIGN_RIGHT:
        if (margin.mLeft.GetUnit() == eCSSUnit_Null)
          margin.mLeft.SetAutoValue();
        if (margin.mRight.GetUnit() == eCSSUnit_Null)
          margin.mRight.SetFloatValue(0.0f, eCSSUnit_Pixel);
        break;
      case NS_STYLE_TEXT_ALIGN_CENTER:
        if (margin.mLeft.GetUnit() == eCSSUnit_Null)
          margin.mLeft.SetAutoValue();
        if (margin.mRight.GetUnit() == eCSSUnit_Null)
          margin.mRight.SetAutoValue();
        break;
      }
    }
  }
  else if (aData->mSID == eStyleStruct_Position) {
    // width: integer, percent
    if (aData->mPositionData->mWidth.GetUnit() == eCSSUnit_Null) {
      const nsAttrValue* value = aAttributes->GetAttr(nsHTMLAtoms::width);
      if (value && value->Type() == nsAttrValue::eInteger) {
        aData->mPositionData->mWidth.SetFloatValue((float)value->GetIntegerValue(), eCSSUnit_Pixel);
      } else if (value && value->Type() == nsAttrValue::ePercent) {
        aData->mPositionData->mWidth.SetPercentValue(value->GetPercentValue());
      }
    }

    if (aData->mPositionData->mHeight.GetUnit() == eCSSUnit_Null) {
      // size: integer
      if (noshade) {
        // noshade case: size is set using the border
        aData->mPositionData->mHeight.SetAutoValue();
      } else {
        // normal case
        // the height includes the top and bottom borders that are initially 1px.
        // for size=1, html.css has a special case rule that makes this work by
        // removing all but the top border.
        const nsAttrValue* value = aAttributes->GetAttr(nsHTMLAtoms::size);
        if (value && value->Type() == nsAttrValue::eInteger) {
          aData->mPositionData->mHeight.SetFloatValue((float)value->GetIntegerValue(), eCSSUnit_Pixel);
        } // else use default value from html.css
      }
    }
  }
  else if (aData->mSID == eStyleStruct_Border && noshade) { // if not noshade, border styles are dealt with by html.css
    // size: integer
    // if a size is set, use half of it per side, otherwise, use 1px per side
    float sizePerSide;
    PRBool allSides = PR_TRUE;
    const nsAttrValue* value = aAttributes->GetAttr(nsHTMLAtoms::size);
    if (value && value->Type() == nsAttrValue::eInteger) {
      sizePerSide = (float)value->GetIntegerValue() / 2.0f;
      if (sizePerSide < 1.0f) {
        // XXX When the pixel bug is fixed, all the special casing for
        // subpixel borders should be removed.
        // In the meantime, this makes http://www.microsoft.com/ look right.
        sizePerSide = 1.0f;
        allSides = PR_FALSE;
      }
    } else {
      sizePerSide = 1.0f; // default to a 2px high line
    }
    nsCSSRect& borderWidth = aData->mMarginData->mBorderWidth;
    if (borderWidth.mTop.GetUnit() == eCSSUnit_Null) {
      borderWidth.mTop.SetFloatValue(sizePerSide, eCSSUnit_Pixel);
    }
    if (allSides) {
      if (borderWidth.mRight.GetUnit() == eCSSUnit_Null) {
        borderWidth.mRight.SetFloatValue(sizePerSide, eCSSUnit_Pixel);
      }
      if (borderWidth.mBottom.GetUnit() == eCSSUnit_Null) {
        borderWidth.mBottom.SetFloatValue(sizePerSide, eCSSUnit_Pixel);
      }
      if (borderWidth.mLeft.GetUnit() == eCSSUnit_Null) {
        borderWidth.mLeft.SetFloatValue(sizePerSide, eCSSUnit_Pixel);
      }
    }

    // if a color is set, set the border-style to 'solid' so that the
    // 'color' property takes effect, otherwise, use '-moz-bg-solid'.
    // (we got the color attribute earlier)
    PRInt32 style = colorIsSet ? NS_STYLE_BORDER_STYLE_SOLID :
                                 NS_STYLE_BORDER_STYLE_BG_SOLID;

    nsCSSRect& borderStyle = aData->mMarginData->mBorderStyle;
    if (borderStyle.mTop.GetUnit() == eCSSUnit_Null) {
      borderStyle.mTop.SetIntValue(style, eCSSUnit_Enumerated);
    }
    if (allSides) {
      if (borderStyle.mRight.GetUnit() == eCSSUnit_Null) {
        borderStyle.mRight.SetIntValue(style, eCSSUnit_Enumerated);
      }
      if (borderStyle.mBottom.GetUnit() == eCSSUnit_Null) {
        borderStyle.mBottom.SetIntValue(style, eCSSUnit_Enumerated);
      }
      if (borderStyle.mLeft.GetUnit() == eCSSUnit_Null) {
        borderStyle.mLeft.SetIntValue(style, eCSSUnit_Enumerated);
      }

      // If it would be noticeable, set the border radius to
      // 100% on all corners
      nsCSSRect& borderRadius = aData->mMarginData->mBorderRadius;
      if (borderRadius.mTop.GetUnit() == eCSSUnit_Null) {
        borderRadius.mTop.SetPercentValue(1.0f);
      }
      if (borderRadius.mRight.GetUnit() == eCSSUnit_Null) {
        borderRadius.mRight.SetPercentValue(1.0f);
      }
      if (borderRadius.mBottom.GetUnit() == eCSSUnit_Null) {
        borderRadius.mBottom.SetPercentValue(1.0f);
      }
      if (borderRadius.mLeft.GetUnit() == eCSSUnit_Null) {
        borderRadius.mLeft.SetPercentValue(1.0f);
      }
    }
  }
  else if (aData->mSID == eStyleStruct_Color) {
    // color: a color
    // (we got the color attribute earlier)
    if (colorIsSet &&
        aData->mColorData->mColor.GetUnit() == eCSSUnit_Null) {
      aData->mColorData->mColor.SetColorValue(color);
    }
  }

  nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Initial value:
 {
  { "left", NS_STYLE_TEXT_ALIGN_LEFT },
  { "right", NS_STYLE_TEXT_ALIGN_RIGHT },
  { "center", NS_STYLE_TEXT_ALIGN_CENTER },
  { 0 }
}

Definition at line 115 of file nsHTMLHRElement.cpp.