Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions
nsFormControlHelper Class Reference

nsFormControlHelper is the base class for frames of form controls. More...

#include <nsFormControlHelper.h>

List of all members.

Public Types

enum  nsHTMLTextWrap { eHTMLTextWrap_Off = 1, eHTMLTextWrap_Hard = 2, eHTMLTextWrap_Soft = 3 }
enum  nsArrowDirection { eArrowDirection_Left, eArrowDirection_Right, eArrowDirection_Up, eArrowDirection_Down }
 Enumeration of possible mouse states used to detect mouse clicks. More...

Public Member Functions

nsresult SetCurrentCheckState (PRBool aState)
 Get the state of the checked attribute.
nsresult GetDefaultCheckState (PRBool *aState)
 Get the state of the defaultchecked attribute.

Static Public Member Functions

static nsresult GetFrameFontFM (nsIFrame *aFrame, nsIFontMetrics **aFontMet)
static void PlatformToDOMLineBreaks (nsString &aString)
static PRBool GetDisabled (nsIContent *aContent)
 Get whether a form control is disabled.
static nsresult GetName (nsIContent *aContent, nsAString *aResult)
 Get the name of the form control.
static PRInt32 GetType (nsIContent *aContent)
 Get the type of the form control (if it's not obvious from the frame type)
static nsresult GetValueAttr (nsIContent *aContent, nsAString *aResult)
 Get the value of the form control (if it's just living in an attr)
static nsresult Reset (nsIFrame *aFrame, nsPresContext *aPresContext)
 Cause the form control to reset its value.
static PRBool GetBool (const nsAString &aValue)
 Utility to convert a string to a PRBool.
static void GetBoolString (const PRBool aValue, nsAString &aResult)
 Utility to convert a PRBool to a string.
static void GetRepChars (char &char1, char &char2)
static nsresult GetWrapProperty (nsIContent *aContent, nsString &aOutValue)
 returns the value of the "wrap" property in aOutValue returns NS_CONTENT_ATTR_NOT_THERE if the property does not exist for this
static nsresult GetWrapPropertyEnum (nsIContent *aContent, nsHTMLTextWrap &aWrapProp)
static void SetupPoints (PRUint32 aNumberOfPoints, nscoord *aPoints, nsPoint *aPolygon, nscoord aScaleFactor, nscoord aX, nscoord aY, nscoord aCenterX, nscoord aCenterY)
 Scale, translate and convert an arrow of poitns from nscoord's to nsPoints's.
static void PaintLine (nsIRenderingContext &aRenderingContext, nscoord aSX, nscoord aSY, nscoord aEX, nscoord aEY, PRBool aHorz, nscoord aWidth, nscoord aOnePixel)
 Paint a fat line.
static void PaintFixedSizeCheckMark (nsIRenderingContext &aRenderingContext, float aPixelsToTwips)
 Paint a fixed size checkmark.
static void PaintCheckMark (nsIRenderingContext &aRenderingContext, float aPixelsToTwips, const nsRect &aRect)
 Paint a checkmark.
static void PaintFixedSizeCheckMarkBorder (nsIRenderingContext &aRenderingContext, float aPixelsToTwips, const nsStyleColor &aBackgroundColor)
 Paint a fixed size checkmark border.
static void PaintRectangularButton (nsPresContext *aPresContext, nsIRenderingContext &aRenderingContext, const nsRect &aDirtyRect, const nsRect &aRect, PRBool aShift, PRBool aShowFocus, PRBool aDisabled, PRBool aDrawOutline, nsStyleContext *aOutlineStyle, nsStyleContext *aFocusStyle, nsStyleContext *aStyleContext, nsString &aLabel, nsIFrame *aForFrame)
 Paint a rectangular button.
static void StyleChangeReflow (nsPresContext *aPresContext, nsIFrame *aFrame)

Protected Member Functions

 nsFormControlHelper ()
virtual ~nsFormControlHelper ()

Detailed Description

nsFormControlHelper is the base class for frames of form controls.

It provides a uniform way of creating widgets, resizing, and painting.

See also:
nsLeafFrame and its base classes for more info

Definition at line 77 of file nsFormControlHelper.h.


Member Enumeration Documentation

Enumeration of possible mouse states used to detect mouse clicks.

Enumerator:
eArrowDirection_Left 
eArrowDirection_Right 
eArrowDirection_Up 
eArrowDirection_Down 

Definition at line 214 of file nsFormControlHelper.h.

Enumerator:
eHTMLTextWrap_Off 
eHTMLTextWrap_Hard 
eHTMLTextWrap_Soft 

Definition at line 155 of file nsFormControlHelper.h.

               {
    eHTMLTextWrap_Off     = 1,    // the default
    eHTMLTextWrap_Hard    = 2,    // "hard" or "physical"
    eHTMLTextWrap_Soft    = 3     // "soft" or "virtual"
  } nsHTMLTextWrap;

Constructor & Destructor Documentation

Definition at line 88 of file nsFormControlHelper.cpp.

Definition at line 93 of file nsFormControlHelper.cpp.


Member Function Documentation

PRBool nsFormControlHelper::GetBool ( const nsAString &  aValue) [static]

Utility to convert a string to a PRBool.

Parameters:
aValuestring to convert to a PRBool
Returns:
PR_TRUE if aValue = "1", PR_FALSE otherwise

Definition at line 107 of file nsFormControlHelper.cpp.

{
  return aValue.Equals(NS_STRING_TRUE);
}
void nsFormControlHelper::GetBoolString ( const PRBool  aValue,
nsAString &  aResult 
) [static]

Utility to convert a PRBool to a string.

Parameters:
aValueBoolean value to convert to string.
aResultstring to hold the boolean value. It is set to "1" if aValue equals PR_TRUE, "0" if aValue equals PR_FALSE.

Definition at line 112 of file nsFormControlHelper.cpp.

{
  if (aValue)
    aResult.Assign(NS_STRING_TRUE); 
  else
    aResult.Assign(NS_STRING_FALSE);
}

Here is the caller graph for this function:

Get the state of the defaultchecked attribute.

Parameters:
aStateset to PR_TRUE if the defaultchecked attribute is set, PR_FALSE if the defaultchecked attribute has been removed
Returns:
NS_OK or NS_CONTENT_ATTR_HAS_VALUE
static PRBool nsFormControlHelper::GetDisabled ( nsIContent aContent) [inline, static]

Get whether a form control is disabled.

Parameters:
aContentthe content of the form control in question
Returns:
whether the form control is disabled

Definition at line 94 of file nsFormControlHelper.h.

                                                  {
    return aContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::disabled);
  };

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsFormControlHelper::GetFrameFontFM ( nsIFrame aFrame,
nsIFontMetrics **  aFontMet 
) [static]

Definition at line 122 of file nsFormControlHelper.cpp.

{
  nsStyleContext* sc = aFrame->GetStyleContext();
  return aFrame->GetPresContext()->DeviceContext()->
    GetMetricsFor(sc->GetStyleFont()->mFont,
                  sc->GetStyleVisibility()->mLangGroup,
                  *aFontMet);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsFormControlHelper::GetName ( nsIContent aContent,
nsAString *  aResult 
) [static]

Get the name of the form control.

Parameters:
aContentthe content to get the name of
aResultthe returned name of the form control [OUT]
Returns:
NS_CONTENT_ATTR_HAS_VALUE if things go well
NS_CONTENT_ATTR_NO_VALUE if the name attr is present but is empty
NS_CONTENT_ATTR_NOT_THERE if the name attribute is undefined
NS_ERROR_FAILURE if aContent is null or is not HTML content

Definition at line 335 of file nsFormControlHelper.cpp.

{
  NS_PRECONDITION(aResult, "Null pointer bad!");
  if (!aContent->IsContentOfType(nsIContent::eHTML))
    return NS_ERROR_FAILURE;

  return aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::name, *aResult);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void nsFormControlHelper::GetRepChars ( char &  char1,
char &  char2 
) [inline, static]

Definition at line 149 of file nsFormControlHelper.h.

                                                    {
    char1 = 'W';
    char2 = 'w';
  }

Get the type of the form control (if it's not obvious from the frame type)

Parameters:
aContentthe content to get the name of
aTypethe returned type of the form control [OUT]
Returns:
NS_CONTENT_ATTR_HAS_VALUE if things go well
NS_CONTENT_ATTR_NO_VALUE if the type attr is present but is empty
NS_CONTENT_ATTR_NOT_THERE if the type attribute is undefined
NS_ERROR_FAILURE if aContent is null or is not HTML content

Definition at line 345 of file nsFormControlHelper.cpp.

{
  nsCOMPtr<nsIFormControl> formControl(do_QueryInterface(aContent));
  if (formControl) {
    return formControl->GetType();
  }

  NS_ERROR("Form control not implementing nsIFormControl, assuming TEXT type");
  return NS_FORM_INPUT_TEXT;
}

Here is the call graph for this function:

nsresult nsFormControlHelper::GetValueAttr ( nsIContent aContent,
nsAString *  aResult 
) [static]

Get the value of the form control (if it's just living in an attr)

Parameters:
aContentthe content to get the name of
aResultthe returned value of the form control [OUT]
Returns:
NS_CONTENT_ATTR_HAS_VALUE if things go well
NS_CONTENT_ATTR_NO_VALUE if the value attr is present but is empty
NS_CONTENT_ATTR_NOT_THERE if the value attribute is undefined
NS_ERROR_FAILURE if aContent is null or is not HTML content

Definition at line 357 of file nsFormControlHelper.cpp.

{
  NS_PRECONDITION(aResult, "Null pointer bad!");
  if (!aContent->IsContentOfType(nsIContent::eHTML))
    return NS_ERROR_FAILURE;

  return aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::value, *aResult);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsFormControlHelper::GetWrapProperty ( nsIContent aContent,
nsString aOutValue 
) [static]

returns the value of the "wrap" property in aOutValue returns NS_CONTENT_ATTR_NOT_THERE if the property does not exist for this

Definition at line 133 of file nsFormControlHelper.cpp.

{
  if (aContent->IsContentOfType(nsIContent::eHTML)) {
    return aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::wrap, aOutValue);
  }

  aOutValue.Truncate();

  return NS_CONTENT_ATTR_NOT_THERE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsFormControlHelper::GetWrapPropertyEnum ( nsIContent aContent,
nsHTMLTextWrap aWrapProp 
) [static]

Definition at line 146 of file nsFormControlHelper.cpp.

{
  // soft is the default; "physical" defaults to soft as well because all other
  // browsers treat it that way and there is no real reason to maintain physical
  // and virtual as separate entities if no one else does.  Only hard and off
  // do anything different.
  aWrapProp = eHTMLTextWrap_Soft; // the default
  
  nsAutoString wrap;
  nsresult rv = GetWrapProperty(aContent, wrap);

  if (rv != NS_CONTENT_ATTR_NOT_THERE) {

    if (wrap.EqualsIgnoreCase(kTextControl_Wrap_Hard)) {
      aWrapProp = eHTMLTextWrap_Hard;
    } else if (wrap.EqualsIgnoreCase(kTextControl_Wrap_Off)) {
      aWrapProp = eHTMLTextWrap_Off;
    }
  }
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsFormControlHelper::PaintCheckMark ( nsIRenderingContext aRenderingContext,
float  aPixelsToTwips,
const nsRect aRect 
) [static]

Paint a checkmark.

Parameters:
aRenderingContextthe rendering context
aPixelsToTwipsscale factor for convering pixels to twips.
aWidthwidth in twips
aHeightheight in twips

Definition at line 287 of file nsFormControlHelper.cpp.

{
 // Width and height of the fixed size checkmark in TWIPS.
  const PRInt32 fixedSizeCheckmarkWidth = 165;
  const PRInt32 fixedSizeCheckmarkHeight = 165;

  if ((fixedSizeCheckmarkWidth == aRect.width)  &&
      (fixedSizeCheckmarkHeight == aRect.height)) {
      // Standard size, so draw a fixed size check mark instead of a scaled check mark.
      PaintFixedSizeCheckMark(aRenderingContext, aPixelsToTwips);
    return;
  }

  const PRUint32 checkpoints = 7;
  const PRUint32 checksize   = 9; //This is value is determined by added 2 units to the end
                                //of the 7X& pixel rectangle below to provide some white space
                                //around the checkmark when it is rendered.

    // Points come from the coordinates on a 7X7 pixels 
    // box with 0,0 at the lower left. 
  nscoord checkedPolygonDef[] = {0,2, 2,4, 6,0 , 6,2, 2,6, 0,4, 0,2 };
    // Location of the center point of the checkmark
  const PRUint32 centerx = 3;
  const PRUint32 centery = 3;
  
  nsPoint checkedPolygon[checkpoints];
  PRUint32 defIndex = 0;
  PRUint32 polyIndex = 0;

     // Scale the checkmark based on the smallest dimension
  PRUint32 size = aRect.width / checksize;
  if (aRect.height < aRect.width) {
   size = aRect.height / checksize;
  }
  
    // Center and offset each point in the polygon definition.
  for (defIndex = 0; defIndex < (checkpoints * 2); defIndex++) {
    checkedPolygon[polyIndex].x = nscoord((((checkedPolygonDef[defIndex]) - centerx) * (size)) + (aRect.width / 2) + aRect.x);
    defIndex++;
    checkedPolygon[polyIndex].y = nscoord((((checkedPolygonDef[defIndex]) - centery) * (size)) + (aRect.height / 2) + aRect.y);
    polyIndex++;
  }
  
  aRenderingContext.FillPolygon(checkedPolygon, checkpoints);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsFormControlHelper::PaintFixedSizeCheckMark ( nsIRenderingContext aRenderingContext,
float  aPixelsToTwips 
) [static]

Paint a fixed size checkmark.

Parameters:
aRenderingContextthe rendering context
aPixelsToTwipsscale factor for convering pixels to twips.

Definition at line 230 of file nsFormControlHelper.cpp.

{

    // Offsets to x,y location, These offsets are used to place the checkmark in the middle
    // of it's 12X12 pixel box.
  const PRUint32 ox = 3;
  const PRUint32 oy = 3;

  nscoord onePixel = NSIntPixelsToTwips(1, aPixelsToTwips);

    // Draw checkmark using a series of rectangles. This builds an replica of the
    // way the checkmark looks under Windows. Using a polygon does not correctly 
    // represent a checkmark under Windows. This is due to round-off error in the
    // Twips to Pixel conversions.
  PaintLine(aRenderingContext, 0 + ox, 2 + oy, 0 + ox, 4 + oy, PR_FALSE, 1, onePixel);
  PaintLine(aRenderingContext, 1 + ox, 3 + oy, 1 + ox, 5 + oy, PR_FALSE, 1, onePixel);
  PaintLine(aRenderingContext, 2 + ox, 4 + oy, 2 + ox, 6 + oy, PR_FALSE, 1, onePixel);
  PaintLine(aRenderingContext, 3 + ox, 3 + oy, 3 + ox, 5 + oy, PR_FALSE, 1, onePixel);
  PaintLine(aRenderingContext, 4 + ox, 2 + oy, 4 + ox, 4 + oy, PR_FALSE, 1, onePixel);
  PaintLine(aRenderingContext, 5 + ox, 1 + oy, 5 + ox, 3 + oy, PR_FALSE, 1, onePixel);
  PaintLine(aRenderingContext, 6 + ox, 0 + oy, 6 + ox, 2 + oy, PR_FALSE, 1, onePixel);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsFormControlHelper::PaintFixedSizeCheckMarkBorder ( nsIRenderingContext aRenderingContext,
float  aPixelsToTwips,
const nsStyleColor aBackgroundColor 
) [static]

Paint a fixed size checkmark border.

Parameters:
aRenderingContextthe rendering context
aPixelsToTwipsscale factor for convering pixels to twips.
aBackgroundColorcolor for background of the checkbox

Definition at line 255 of file nsFormControlHelper.cpp.

{
    // Offsets to x,y location
  PRUint32 ox = 0;
  PRUint32 oy = 0;

  nscoord onePixel = NSIntPixelsToTwips(1, aPixelsToTwips);
  nscoord twelvePixels = NSIntPixelsToTwips(12, aPixelsToTwips);

    // Draw Background
  aRenderingContext.SetColor(aBackgroundColor.mColor);
  nsRect rect(0, 0, twelvePixels, twelvePixels);
  aRenderingContext.FillRect(rect);

    // Draw Border
  aRenderingContext.SetColor(NS_RGB(128, 128, 128));
  PaintLine(aRenderingContext, 0 + ox, 0 + oy, 11 + ox, 0 + oy, PR_TRUE, 1, onePixel);
  PaintLine(aRenderingContext, 0 + ox, 0 + oy, 0 + ox, 11 + oy, PR_FALSE, 1, onePixel);

  aRenderingContext.SetColor(NS_RGB(192, 192, 192));
  PaintLine(aRenderingContext, 1 + ox, 11 + oy, 11 + ox, 11 + oy, PR_TRUE, 1, onePixel);
  PaintLine(aRenderingContext, 11 + ox, 1 + oy, 11 + ox, 11 + oy, PR_FALSE, 1, onePixel);

  aRenderingContext.SetColor(NS_RGB(0, 0, 0));
  PaintLine(aRenderingContext, 1 + ox, 1 + oy, 10 + ox, 1 + oy, PR_TRUE, 1, onePixel);
  PaintLine(aRenderingContext, 1 + ox, 1 + oy, 1 + ox, 10 + oy, PR_FALSE, 1, onePixel);

}

Here is the call graph for this function:

void nsFormControlHelper::PaintLine ( nsIRenderingContext aRenderingContext,
nscoord  aSX,
nscoord  aSY,
nscoord  aEX,
nscoord  aEY,
PRBool  aHorz,
nscoord  aWidth,
nscoord  aOnePixel 
) [static]

Paint a fat line.

The line is drawn as a polygon with a specified width.

Parameters:
aRenderingContextthe rendering context
aSXstarting x in pixels
aSYstarting y in pixels
aEXending x in pixels
aEYending y in pixels
aHorzPR_TRUE if aWidth is added to x coordinates to form polygon. If PR_FALSE then aWidth as added to the y coordinates.
aOnePixelnumber of twips in a single pixel.

Definition at line 175 of file nsFormControlHelper.cpp.

{
  
  nsPoint p[5];
  if (aHorz) {
    aEX++;
    p[0].x = nscoord(float(aSX)*aOnePixel);
    p[0].y = nscoord(float(aSY)*aOnePixel);
    p[1].x = nscoord(float(aEX)*aOnePixel);
    p[1].y = nscoord(float(aEY)*aOnePixel);
    p[2].x = nscoord(float(aEX)*aOnePixel);
    p[2].y = nscoord(float(aEY+1)*aOnePixel);
    p[3].x = nscoord(float(aSX)*aOnePixel);
    p[3].y = nscoord(float(aSY+1)*aOnePixel);
    p[4].x = nscoord(float(aSX)*aOnePixel);
    p[4].y = nscoord(float(aSY)*aOnePixel);
  } else {
    aEY++;
    p[0].x = nscoord(float(aSX)*aOnePixel);
    p[0].y = nscoord(float(aSY)*aOnePixel);
    p[1].x = nscoord(float(aEX)*aOnePixel);
    p[1].y = nscoord(float(aEY)*aOnePixel);
    p[2].x = nscoord(float(aEX+1)*aOnePixel);
    p[2].y = nscoord(float(aEY)*aOnePixel);
    p[3].x = nscoord(float(aSX+1)*aOnePixel);
    p[3].y = nscoord(float(aSY)*aOnePixel);
    p[4].x = nscoord(float(aSX)*aOnePixel);
    p[4].y = nscoord(float(aSY)*aOnePixel);
  }
  aRenderingContext.FillPolygon(p, 5);

}

Here is the call graph for this function:

Here is the caller graph for this function:

static void nsFormControlHelper::PaintRectangularButton ( nsPresContext aPresContext,
nsIRenderingContext aRenderingContext,
const nsRect aDirtyRect,
const nsRect aRect,
PRBool  aShift,
PRBool  aShowFocus,
PRBool  aDisabled,
PRBool  aDrawOutline,
nsStyleContext aOutlineStyle,
nsStyleContext aFocusStyle,
nsStyleContext aStyleContext,
nsString aLabel,
nsIFrame aForFrame 
) [static]

Paint a rectangular button.

Includes background, string, and focus indicator

Parameters:
aPresContextthe presentation context
aRenderingContextthe rendering context
aDirtyRectrectangle requiring update
aRectx,y, width, and height of the button in TWIPS
aShiftif PR_TRUE offset button as if it were pressed
aShowFocusif PR_TRUE draw focus rectangle over button
aStyleContextstyle context used for drawing button background
aLabellabel for button
aForFramethe frame that the scrollbar will be rendered in to

Definition at line 98 of file nsFormControlHelper.cpp.

{
  // Windows linebreaks: Map CRLF to LF:
  aString.ReplaceSubstring(NS_LITERAL_STRING("\r\n").get(), NS_LITERAL_STRING("\n").get());

  // Mac linebreaks: Map any remaining CR to LF:
  aString.ReplaceSubstring(NS_LITERAL_STRING("\r").get(), NS_LITERAL_STRING("\n").get());
}

Here is the caller graph for this function:

nsresult nsFormControlHelper::Reset ( nsIFrame aFrame,
nsPresContext aPresContext 
) [static]

Cause the form control to reset its value.

Parameters:
aFramethe frame who owns the form control
aPresContextthe pres context

Definition at line 369 of file nsFormControlHelper.cpp.

{
  nsCOMPtr<nsIFormControl> control = do_QueryInterface(aFrame->GetContent());
  if (control) {
    control->Reset();
    return NS_OK;
  }

  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Get the state of the checked attribute.

Parameters:
aStateset to PR_TRUE if the checked attribute is set, PR_FALSE if the checked attribute has been removed
Returns:
NS_OK or NS_CONTENT_ATTR_HAS_VALUE Set the state of the checked attribute.
Parameters:
aStateset to PR_TRUE to set the attribute, PR_FALSE to unset the attribute
Returns:
NS_OK or NS_CONTENT_ATTR_HAS_VALUE
void nsFormControlHelper::SetupPoints ( PRUint32  aNumberOfPoints,
nscoord aPoints,
nsPoint aPolygon,
nscoord  aScaleFactor,
nscoord  aX,
nscoord  aY,
nscoord  aCenterX,
nscoord  aCenterY 
) [static]

Scale, translate and convert an arrow of poitns from nscoord's to nsPoints's.

Parameters:
aNumberOfPointsnumber of (x,y) pairs
aPointsarrow of points to convert
aScaleFactorscale factor to apply to each points translation.
aXx coordinate to add to each point after scaling
aYy coordinate to add to each point after scaling
aCenterXx coordinate of the center point in the original array of points.
aCenterYy coordiante of the center point in the original array of points.

Definition at line 212 of file nsFormControlHelper.cpp.

{
  const nscoord offsetX = aCenterX * aScaleFactor;
  const nscoord offsetY = aCenterY * aScaleFactor;

  PRUint32 i = 0;
  PRUint32 count = 0;
  for (i = 0; i < aNumberOfPoints; i++) {
    aPolygon[i].x = (aPoints[count] * aScaleFactor) + aX - offsetX;
    count++;
    aPolygon[i].y = (aPoints[count] * aScaleFactor) + aY - offsetY;
    count++;
  }
}
void nsFormControlHelper::StyleChangeReflow ( nsPresContext aPresContext,
nsIFrame aFrame 
) [static]

Definition at line 381 of file nsFormControlHelper.cpp.

Here is the call graph for this function:


The documentation for this class was generated from the following files: