Back to index

lightning-sunbird  0.9+nobinonly
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes
nsHTMLCSSUtils Class Reference

#include <nsHTMLCSSUtils.h>

Collaboration diagram for nsHTMLCSSUtils:
Collaboration graph
[legend]

List of all members.

Classes

struct  CSSEquivTable

Public Types

enum  nsCSSEditableProperty {
  eCSSEditableProperty_NONE = 0, eCSSEditableProperty_background_color, eCSSEditableProperty_background_image, eCSSEditableProperty_border,
  eCSSEditableProperty_caption_side, eCSSEditableProperty_color, eCSSEditableProperty_float, eCSSEditableProperty_font_family,
  eCSSEditableProperty_font_size, eCSSEditableProperty_font_style, eCSSEditableProperty_font_weight, eCSSEditableProperty_height,
  eCSSEditableProperty_list_style_type, eCSSEditableProperty_margin_left, eCSSEditableProperty_margin_right, eCSSEditableProperty_text_align,
  eCSSEditableProperty_text_decoration, eCSSEditableProperty_vertical_align, eCSSEditableProperty_whitespace, eCSSEditableProperty_width
}

Public Member Functions

 nsHTMLCSSUtils ()
 ~nsHTMLCSSUtils ()
nsresult Init (nsHTMLEditor *aEditor)
PRBool IsCSSEditableProperty (nsIDOMNode *aNode, nsIAtom *aProperty, const nsAString *aAttribute)
 answers true if the given combination element_name/attribute_name has a CSS equivalence in this implementation
nsresult SetCSSProperty (nsIDOMElement *aElement, nsIAtom *aProperty, const nsAString &aValue, PRBool aSuppressTransaction)
 adds/remove a CSS declaration to the STYLE atrribute carried by a given element
nsresult SetCSSPropertyPixels (nsIDOMElement *aElement, nsIAtom *aProperty, PRInt32 aIntValue, PRBool aSuppressTxn)
nsresult RemoveCSSProperty (nsIDOMElement *aElement, nsIAtom *aProperty, const nsAString &aPropertyValue, PRBool aSuppressTransaction)
nsresult SetCSSProperty (nsIDOMElement *aElement, const nsAString &aProperty, const nsAString &aValue)
 directly adds/remove a CSS declaration to the STYLE atrribute carried by a given element without going through the txn manager
nsresult SetCSSPropertyPixels (nsIDOMElement *aElement, const nsAString &aProperty, PRInt32 aIntValue)
nsresult RemoveCSSProperty (nsIDOMElement *aElement, const nsAString &aProperty)
nsresult GetSpecifiedProperty (nsIDOMNode *aNode, nsIAtom *aProperty, nsAString &aValue)
 gets the specified/computed style value of a CSS property for a given node (or its element ancestor if it is not an element)
nsresult GetComputedProperty (nsIDOMNode *aNode, nsIAtom *aProperty, nsAString &aValue)
nsresult RemoveCSSInlineStyle (nsIDOMNode *aNode, nsIAtom *aProperty, const nsAString &aPropertyValue)
 Removes a CSS property from the specified declarations in STYLE attribute and removes the node if it is an useless span.
PRBool IsCSSInvertable (nsIAtom *aProperty, const nsAString *aAttribute)
 Answers true is the property can be removed by setting a "none" CSS value on a node.
nsresult GetDefaultBackgroundColor (nsAString &aColor)
 Get the default browser background color if we need it for GetCSSBackgroundColorState.
nsresult GetDefaultLengthUnit (nsAString &aLengthUnit)
 Get the default length unit used for CSS Indent/Outdent.
nsresult HasClassOrID (nsIDOMElement *aElement, PRBool &aReturn)
 asnwers true if the element aElement carries an ID or a class
nsresult GetCSSEquivalentToHTMLInlineStyleSet (nsIDOMNode *aNode, nsIAtom *aHTMLProperty, const nsAString *aAttribute, nsAString &aValueString, PRUint8 aStyleType)
 returns the list of values for the CSS equivalences to the passed HTML style for the passed node
nsresult IsCSSEquivalentToHTMLInlineStyleSet (nsIDOMNode *aNode, nsIAtom *aHTMLProperty, const nsAString *aAttribute, PRBool &aIsSet, nsAString &aValueString, PRUint8 aStyleType)
 Does the node aNode (or his parent if it is not an element node) carries the CSS equivalent styles to the HTML style for this node ?
nsresult SetCSSEquivalentToHTMLStyle (nsIDOMNode *aNode, nsIAtom *aHTMLProperty, const nsAString *aAttribute, const nsAString *aValue, PRInt32 *aCount, PRBool aSuppressTransaction)
 Adds to the node the CSS inline styles equivalent to the HTML style and return the number of CSS properties set by the call.
nsresult RemoveCSSEquivalentToHTMLStyle (nsIDOMNode *aNode, nsIAtom *aHTMLProperty, const nsAString *aAttribute, const nsAString *aValue, PRBool aSuppressTransaction)
 removes from the node the CSS inline styles equivalent to the HTML style
void ParseLength (const nsAString &aString, float *aValue, nsIAtom **aUnit)
 parses a "xxxx.xxxxxuuu" string where x is a digit and u an alpha char we need such a parser because nsIDOMCSSStyleDeclaration::GetPropertyCSSValue() is not implemented
nsresult SetCSSEnabled (PRBool aIsCSSPrefChecked)
 sets the mIsCSSPrefChecked private member ; used as callback from observer when the css pref state is changed
PRBool IsCSSPrefChecked ()
 retrieves the mIsCSSPrefChecked private member, true if the css pref is checked, false if it is not
PRBool ElementsSameStyle (nsIDOMNode *aFirstNode, nsIDOMNode *aSecondNode)
 ElementsSameStyle compares two elements and checks if they have the same specified CSS declarations in the STYLE attribute The answer is always false if at least one of them carries an ID or a class.
nsresult GetInlineStyles (nsIDOMElement *aElement, nsIDOMCSSStyleDeclaration **aCssDecl, PRUint32 *aLength)
 get the specified inline styles (style attribute) for an element
nsresult GetElementContainerOrSelf (nsIDOMNode *aNode, nsIDOMElement **aElement)
 returns aNode itself if it is an element node, or the first ancestors being an element node if aNode is not one itself
nsresult GetDefaultViewCSS (nsIDOMNode *aNode, nsIDOMViewCSS **aViewCSS)
 Gets the default DOMView for a given node.

Private Member Functions

void GetCSSPropertyAtom (nsCSSEditableProperty aProperty, nsIAtom **aAtom)
 retrieves the css property atom from an enum
void BuildCSSDeclarations (nsVoidArray &aPropertyArray, nsStringArray &cssValueArray, const CSSEquivTable *aEquivTable, const nsAString *aValue, PRBool aGetOrRemoveRequest)
 retrieves the CSS declarations equivalent to a HTML style value for a given equivalence table
void GenerateCSSDeclarationsFromHTMLStyle (nsIDOMNode *aNode, nsIAtom *aHTMLProperty, const nsAString *aAttribute, const nsAString *aValue, nsVoidArray &aPropertyArray, nsStringArray &aValueArray, PRBool aGetOrRemoveRequest)
 retrieves the CSS declarations equivalent to the given HTML property/attribute/value for a given node
nsresult CreateCSSPropertyTxn (nsIDOMElement *aElement, nsIAtom *aProperty, const nsAString &aValue, ChangeCSSInlineStyleTxn **aTxn, PRBool aRemoveProperty)
 creates a Transaction for setting or removing a css property
nsresult GetCSSInlinePropertyBase (nsIDOMNode *aNode, nsIAtom *aProperty, nsAString &aValue, nsIDOMViewCSS *aViewCSS, PRUint8 aStyleType)
 back-end for GetSpecifiedProperty and GetComputedProperty

Private Attributes

nsHTMLEditormHTMLEditor
PRBool mIsCSSPrefChecked

Detailed Description

Definition at line 61 of file nsHTMLCSSUtils.h.


Class Documentation

struct nsHTMLCSSUtils::CSSEquivTable

Definition at line 91 of file nsHTMLCSSUtils.h.

Class Members
const char * appendValue
PRBool caseSensitiveValue
nsCSSEditableProperty cssProperty
const char * defaultValue
PRBool gettable
const char * prependValue
nsProcessValueFunc processValueFunctor

Member Enumeration Documentation

Enumerator:
eCSSEditableProperty_NONE 
eCSSEditableProperty_background_color 
eCSSEditableProperty_background_image 
eCSSEditableProperty_border 
eCSSEditableProperty_caption_side 
eCSSEditableProperty_color 
eCSSEditableProperty_float 
eCSSEditableProperty_font_family 
eCSSEditableProperty_font_size 
eCSSEditableProperty_font_style 
eCSSEditableProperty_font_weight 
eCSSEditableProperty_height 
eCSSEditableProperty_list_style_type 
eCSSEditableProperty_margin_left 
eCSSEditableProperty_margin_right 
eCSSEditableProperty_text_align 
eCSSEditableProperty_text_decoration 
eCSSEditableProperty_vertical_align 
eCSSEditableProperty_whitespace 
eCSSEditableProperty_width 

Definition at line 67 of file nsHTMLCSSUtils.h.


Constructor & Destructor Documentation

Definition at line 300 of file nsHTMLCSSUtils.cpp.

Definition at line 305 of file nsHTMLCSSUtils.cpp.

{
}

Member Function Documentation

void nsHTMLCSSUtils::BuildCSSDeclarations ( nsVoidArray aPropertyArray,
nsStringArray &  cssValueArray,
const CSSEquivTable aEquivTable,
const nsAString *  aValue,
PRBool  aGetOrRemoveRequest 
) [private]

retrieves the CSS declarations equivalent to a HTML style value for a given equivalence table

Parameters:
aPropertyArray[OUT] the array of css properties
aValueArray[OUT] the array of values for the css properties above
aEquivTable[IN] the equivalence table
aValue[IN] the HTML style value
aGetOrRemoveRequest[IN] a boolean value being true if the call to the current method is made for GetCSSEquivalentToHTMLInlineStyleSet or RemoveCSSEquivalentToHTMLInlineStyleSet

Definition at line 859 of file nsHTMLCSSUtils.cpp.

{
  // clear arrays
  aPropertyArray.Clear();
  aValueArray.Clear();

  // if we have an input value, let's use it
  nsAutoString value, lowerCasedValue;
  if (aValue) {
    value.Assign(*aValue);
    lowerCasedValue.Assign(*aValue);
    ToLowerCase(lowerCasedValue);
  }

  PRInt8 index = 0;
  nsCSSEditableProperty cssProperty = aEquivTable[index].cssProperty;
  while (cssProperty) {
    if (!aGetOrRemoveRequest|| aEquivTable[index].gettable) {
      nsAutoString cssValue, cssPropertyString;
      nsIAtom * cssPropertyAtom;
      // find the equivalent css value for the index-th property in
      // the equivalence table
      (*aEquivTable[index].processValueFunctor) ((!aGetOrRemoveRequest || aEquivTable[index].caseSensitiveValue) ? &value : &lowerCasedValue,
                                                 cssValue,
                                                 aEquivTable[index].defaultValue,
                                                 aEquivTable[index].prependValue,
                                                 aEquivTable[index].appendValue);
      GetCSSPropertyAtom(cssProperty, &cssPropertyAtom);
      aPropertyArray.AppendElement(cssPropertyAtom);
      aValueArray.AppendString(cssValue);
    }
    index++;
    cssProperty = aEquivTable[index].cssProperty;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsHTMLCSSUtils::CreateCSSPropertyTxn ( nsIDOMElement aElement,
nsIAtom aProperty,
const nsAString &  aValue,
ChangeCSSInlineStyleTxn **  aTxn,
PRBool  aRemoveProperty 
) [private]

creates a Transaction for setting or removing a css property

Parameters:
aElement[IN] a DOM element
aProperty[IN] a CSS property
aValue[IN] the value to remove for this CSS property or the empty string if irrelevant
aTxn[OUT] the created transaction
aRemoveProperty[IN] true if we create a "remove" transaction, false for a "set"

Definition at line 516 of file nsHTMLCSSUtils.cpp.

{
  nsresult result = NS_ERROR_NULL_POINTER;
  if (aElement)
  {
    result = TransactionFactory::GetNewTransaction(ChangeCSSInlineStyleTxn::GetCID(), (EditTxn **)aTxn);
    if (NS_SUCCEEDED(result))  {
      result = (*aTxn)->Init(mHTMLEditor, aElement, aAttribute, aValue, aRemoveProperty);
    }
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsHTMLCSSUtils::ElementsSameStyle ( nsIDOMNode aFirstNode,
nsIDOMNode aSecondNode 
)

ElementsSameStyle compares two elements and checks if they have the same specified CSS declarations in the STYLE attribute The answer is always false if at least one of them carries an ID or a class.

Returns:
true if the two elements are considered to have same styles
Parameters:
aFirstNode[IN] a DOM node
aSecondNode[IN] a DOM node

Definition at line 1314 of file nsHTMLCSSUtils.cpp.

{
  nsresult res;
  nsCOMPtr<nsIDOMElement> firstElement  = do_QueryInterface(aFirstNode);
  nsCOMPtr<nsIDOMElement> secondElement = do_QueryInterface(aSecondNode);

  NS_ASSERTION((firstElement && secondElement), "Non element nodes passed to ElementsSameStyle.");

  nsAutoString firstID, secondID;
  PRBool isFirstIDSet, isSecondIDSet;
  res = mHTMLEditor->GetAttributeValue(firstElement,  NS_LITERAL_STRING("id"), firstID,  &isFirstIDSet);
  res = mHTMLEditor->GetAttributeValue(secondElement, NS_LITERAL_STRING("id"), secondID, &isSecondIDSet);
  if (isFirstIDSet || isSecondIDSet) {
    // at least one of the spans carries an ID ; suspect a CSS rule applies to it and
    // refuse to merge the nodes
    return PR_FALSE;
  }

  nsAutoString firstClass, secondClass;
  PRBool isFirstClassSet, isSecondClassSet;
  res = mHTMLEditor->GetAttributeValue(firstElement,  NS_LITERAL_STRING("class"), firstClass,  &isFirstClassSet);
  res = mHTMLEditor->GetAttributeValue(secondElement, NS_LITERAL_STRING("class"), secondClass, &isSecondClassSet);
  if (isFirstClassSet && isSecondClassSet) {
    // both spans carry a class, let's compare them
    if (!firstClass.Equals(secondClass)) {
      // WARNING : technically, the comparison just above is questionable :
      // from a pure HTML/CSS point of view class="a b" is NOT the same than
      // class="b a" because a CSS rule could test the exact value of the class
      // attribute to be "a b" for instance ; from a user's point of view, a
      // wysiwyg editor should probably NOT make any difference. CSS people
      // need to discuss this issue before any modification.
      return PR_FALSE;
    }
  }
  else if (isFirstClassSet || isSecondClassSet) {
    // one span only carries a class, early way out
    return PR_FALSE;
  }

  nsCOMPtr<nsIDOMCSSStyleDeclaration> firstCSSDecl, secondCSSDecl;
  PRUint32 firstLength, secondLength;
  res = GetInlineStyles(firstElement,  getter_AddRefs(firstCSSDecl),  &firstLength);
  if (NS_FAILED(res) || !firstCSSDecl) return PR_FALSE;
  res = GetInlineStyles(secondElement, getter_AddRefs(secondCSSDecl), &secondLength);
  if (NS_FAILED(res) || !secondCSSDecl) return PR_FALSE;

  if (firstLength != secondLength) {
    // early way out if we can
    return PR_FALSE;
  }
  else if (0 == firstLength) {
    // no inline style !
    return PR_TRUE;
  }

  PRUint32 i;
  nsAutoString propertyNameString;
  nsAutoString firstValue, secondValue;
  for (i=0; i<firstLength; i++) {
    firstCSSDecl->Item(i, propertyNameString);
    firstCSSDecl->GetPropertyValue(propertyNameString, firstValue);
    secondCSSDecl->GetPropertyValue(propertyNameString, secondValue);
    if (!firstValue.Equals(secondValue)) {
      return PR_FALSE;
    }
  }
  for (i=0; i<secondLength; i++) {
    secondCSSDecl->Item(i, propertyNameString);
    secondCSSDecl->GetPropertyValue(propertyNameString, secondValue);
    firstCSSDecl->GetPropertyValue(propertyNameString, firstValue);
    if (!firstValue.Equals(secondValue)) {
      return PR_FALSE;
    }
  }

  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsHTMLCSSUtils::GenerateCSSDeclarationsFromHTMLStyle ( nsIDOMNode aNode,
nsIAtom aHTMLProperty,
const nsAString *  aAttribute,
const nsAString *  aValue,
nsVoidArray aPropertyArray,
nsStringArray &  aValueArray,
PRBool  aGetOrRemoveRequest 
) [private]

retrieves the CSS declarations equivalent to the given HTML property/attribute/value for a given node

Parameters:
aNode[IN] the DOM node
aHTMLProperty[IN] an atom containing an HTML property
aAttribute[IN] a pointer to an attribute name or nsnull if irrelevant
aValue[IN] the attribute value
aPropertyArray[OUT] the array of css properties
aValueArray[OUT] the array of values for the css properties above
aGetOrRemoveRequest[IN] a boolean value being true if the call to the current method is made for GetCSSEquivalentToHTMLInlineStyleSet or RemoveCSSEquivalentToHTMLInlineStyleSet

Definition at line 902 of file nsHTMLCSSUtils.cpp.

{
  nsCOMPtr<nsIDOMNode> node = aNode;
  if (mHTMLEditor->IsTextNode(aNode)) {
    aNode->GetParentNode(getter_AddRefs(node));
  }
  if (!node) return;

  nsIAtom *tagName = nsEditor::GetTag(node);

  if (nsEditProperty::b == aHTMLProperty) {
    BuildCSSDeclarations(cssPropertyArray, cssValueArray, boldEquivTable, aValue, aGetOrRemoveRequest);
  }
  else if (nsEditProperty::i == aHTMLProperty) {
    BuildCSSDeclarations(cssPropertyArray, cssValueArray, italicEquivTable, aValue, aGetOrRemoveRequest);
  }
  else if (nsEditProperty::u == aHTMLProperty) {
    BuildCSSDeclarations(cssPropertyArray, cssValueArray, underlineEquivTable, aValue, aGetOrRemoveRequest);
  }
  else if (nsEditProperty::strike == aHTMLProperty) {
    BuildCSSDeclarations(cssPropertyArray, cssValueArray, strikeEquivTable, aValue, aGetOrRemoveRequest);
  }
  else if (nsEditProperty::tt == aHTMLProperty) {
    BuildCSSDeclarations(cssPropertyArray, cssValueArray, ttEquivTable, aValue, aGetOrRemoveRequest);
  }
  else if (aAttribute) {
    if (nsEditProperty::font == aHTMLProperty &&
        aAttribute->EqualsLiteral("color")) {
      BuildCSSDeclarations(cssPropertyArray, cssValueArray, fontColorEquivTable, aValue, aGetOrRemoveRequest);
    }
    else if (nsEditProperty::font == aHTMLProperty &&
             aAttribute->EqualsLiteral("face")) {
      BuildCSSDeclarations(cssPropertyArray, cssValueArray, fontFaceEquivTable, aValue, aGetOrRemoveRequest);
    }
    else if (aAttribute->EqualsLiteral("bgcolor")) {
      BuildCSSDeclarations(cssPropertyArray, cssValueArray, bgcolorEquivTable, aValue, aGetOrRemoveRequest);
    }
    else if (aAttribute->EqualsLiteral("background")) {
      BuildCSSDeclarations(cssPropertyArray, cssValueArray, backgroundImageEquivTable, aValue, aGetOrRemoveRequest);
    }
    else if (aAttribute->EqualsLiteral("text")) {
      BuildCSSDeclarations(cssPropertyArray, cssValueArray, textColorEquivTable, aValue, aGetOrRemoveRequest);
    }
    else if (aAttribute->EqualsLiteral("border")) {
      BuildCSSDeclarations(cssPropertyArray, cssValueArray, borderEquivTable, aValue, aGetOrRemoveRequest);
    }
    else if (aAttribute->EqualsLiteral("align")) {
      if (nsEditProperty::table  == tagName) {
        BuildCSSDeclarations(cssPropertyArray, cssValueArray, tableAlignEquivTable, aValue, aGetOrRemoveRequest);
      }
      else if (nsEditProperty::hr  == tagName) {
        BuildCSSDeclarations(cssPropertyArray, cssValueArray, hrAlignEquivTable, aValue, aGetOrRemoveRequest);
      }
      else if (nsEditProperty::legend  == tagName ||
               nsEditProperty::caption == tagName) {
        BuildCSSDeclarations(cssPropertyArray, cssValueArray, captionAlignEquivTable, aValue, aGetOrRemoveRequest);
      }
      else {
        BuildCSSDeclarations(cssPropertyArray, cssValueArray, textAlignEquivTable, aValue, aGetOrRemoveRequest);
      }
    }
    else if (aAttribute->EqualsLiteral("valign")) {
      BuildCSSDeclarations(cssPropertyArray, cssValueArray, verticalAlignEquivTable, aValue, aGetOrRemoveRequest);
    }
    else if (aAttribute->EqualsLiteral("nowrap")) {
      BuildCSSDeclarations(cssPropertyArray, cssValueArray, nowrapEquivTable, aValue, aGetOrRemoveRequest);
    }
    else if (aAttribute->EqualsLiteral("width")) {
      BuildCSSDeclarations(cssPropertyArray, cssValueArray, widthEquivTable, aValue, aGetOrRemoveRequest);
    }
    else if (aAttribute->EqualsLiteral("height") ||
             (nsEditProperty::hr == tagName && aAttribute->EqualsLiteral("size"))) {
      BuildCSSDeclarations(cssPropertyArray, cssValueArray, heightEquivTable, aValue, aGetOrRemoveRequest);
    }
    else if (aAttribute->EqualsLiteral("type") &&
             (nsEditProperty::ol == tagName
              || nsEditProperty::ul == tagName
              || nsEditProperty::li == tagName)) {
      BuildCSSDeclarations(cssPropertyArray, cssValueArray, listStyleTypeEquivTable, aValue, aGetOrRemoveRequest);
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsHTMLCSSUtils::GetComputedProperty ( nsIDOMNode aNode,
nsIAtom aProperty,
nsAString &  aValue 
)

Definition at line 541 of file nsHTMLCSSUtils.cpp.

{
  nsCOMPtr<nsIDOMViewCSS> viewCSS = nsnull;
  nsresult res = GetDefaultViewCSS(aNode, getter_AddRefs(viewCSS));
  if (NS_FAILED(res)) return res;

  return GetCSSInlinePropertyBase(aNode, aProperty, aValue, viewCSS, COMPUTED_STYLE_TYPE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsHTMLCSSUtils::GetCSSEquivalentToHTMLInlineStyleSet ( nsIDOMNode aNode,
nsIAtom aHTMLProperty,
const nsAString *  aAttribute,
nsAString &  aValueString,
PRUint8  aStyleType 
)

returns the list of values for the CSS equivalences to the passed HTML style for the passed node

Parameters:
aNode[IN] a DOM node
aHTMLProperty[IN] an atom containing an HTML property
aAttribute[IN] a pointer to an attribute name or nsnull if irrelevant
aValueString[OUT] the list of css values
aStyleType[IN] SPECIFIED_STYLE_TYPE to query the specified style values COMPUTED_STYLE_TYPE to query the computed style values

Definition at line 1089 of file nsHTMLCSSUtils.cpp.

{
  aValueString.Truncate();
  nsCOMPtr<nsIDOMElement> theElement;
  nsresult res = GetElementContainerOrSelf(aNode, getter_AddRefs(theElement));
  if (NS_FAILED(res)) return res;

  if (theElement && IsCSSEditableProperty(theElement, aHTMLProperty, aAttribute)) {
    // Yes, the requested HTML style has a CSS equivalence in this implementation
    // Retrieve the default ViewCSS if we are asked for computed styles
    nsCOMPtr<nsIDOMViewCSS> viewCSS = nsnull;
    if (COMPUTED_STYLE_TYPE == aStyleType) {
      res = GetDefaultViewCSS(theElement, getter_AddRefs(viewCSS));
      if (NS_FAILED(res)) return res;
    }
    nsVoidArray cssPropertyArray;
    nsStringArray cssValueArray;
    // get the CSS equivalence with last param PR_TRUE indicating we want only the
    // "gettable" properties
    GenerateCSSDeclarationsFromHTMLStyle(theElement, aHTMLProperty, aAttribute, nsnull,
                                         cssPropertyArray, cssValueArray, PR_TRUE);
    PRInt32 count = cssPropertyArray.Count();
    PRInt32 index;
    for (index = 0; index < count; index++) {
      nsAutoString valueString;
      // retrieve the specified/computed value of the property
      res = GetCSSInlinePropertyBase(theElement, (nsIAtom *)cssPropertyArray.ElementAt(index),
                                     valueString, viewCSS, aStyleType);
      if (NS_FAILED(res)) return res;
      // append the value to aValueString (possibly with a leading whitespace)
      if (index) aValueString.Append(PRUnichar(' '));
      aValueString.Append(valueString);
    }
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsHTMLCSSUtils::GetCSSInlinePropertyBase ( nsIDOMNode aNode,
nsIAtom aProperty,
nsAString &  aValue,
nsIDOMViewCSS aViewCSS,
PRUint8  aStyleType 
) [private]

back-end for GetSpecifiedProperty and GetComputedProperty

Parameters:
aNode[IN] a DOM node
aProperty[IN] a CSS property
aValue[OUT] the retrieved value for this property
aViewCSS[IN] the ViewCSS we need in case we query computed styles
aStyleType[IN] SPECIFIED_STYLE_TYPE to query the specified style values COMPUTED_STYLE_TYPE to query the computed style values

Definition at line 552 of file nsHTMLCSSUtils.cpp.

{
  aValue.Truncate();
  NS_ENSURE_TRUE(aProperty, NS_ERROR_NULL_POINTER);

  nsCOMPtr<nsIDOMElement>element;
  nsresult res = GetElementContainerOrSelf(aNode, getter_AddRefs(element));
  if (NS_FAILED(res)) return res;

  switch (aStyleType) {
    case COMPUTED_STYLE_TYPE:
      if (element && aViewCSS) {
        nsAutoString empty, value, propString;
        nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
        aProperty->ToString(propString);
        // Get the all the computed css styles attached to the element node
        res = aViewCSS->GetComputedStyle(element, empty, getter_AddRefs(cssDecl));
        if (NS_FAILED(res) || !cssDecl) return res;
        // from these declarations, get the one we want and that one only
        res = cssDecl->GetPropertyValue(propString, value);
        if (NS_FAILED(res)) return res;
        aValue.Assign(value);
      }
      break;
    case SPECIFIED_STYLE_TYPE:
      if (element) {
        nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
        PRUint32 length;
        res = GetInlineStyles(element, getter_AddRefs(cssDecl), &length);
        if (NS_FAILED(res) || !cssDecl) return res;
        nsAutoString value, propString;
        aProperty->ToString(propString);
        res = cssDecl->GetPropertyValue(propString, value);
        if (NS_FAILED(res)) return res;
        aValue.Assign(value);
      }
      break;
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsHTMLCSSUtils::GetCSSPropertyAtom ( nsCSSEditableProperty  aProperty,
nsIAtom **  aAtom 
) [private]

retrieves the css property atom from an enum

Parameters:
aProperty[IN] the enum value for the property
aAtom[OUT] the corresponding atom

Definition at line 790 of file nsHTMLCSSUtils.cpp.

{
  *aAtom = nsnull;
  if (0 < aProperty) {
    switch (aProperty) {
      case eCSSEditableProperty_background_color:
        *aAtom = nsEditProperty::cssBackgroundColor;
        break;
      case eCSSEditableProperty_background_image:
        *aAtom = nsEditProperty::cssBackgroundImage;
        break;
      case eCSSEditableProperty_border:
        *aAtom = nsEditProperty::cssBorder;
        break;
      case eCSSEditableProperty_caption_side:
        *aAtom = nsEditProperty::cssCaptionSide;
        break;
      case eCSSEditableProperty_color:
        *aAtom = nsEditProperty::cssColor;
        break;
      case eCSSEditableProperty_float:
        *aAtom = nsEditProperty::cssFloat;
        break;
      case eCSSEditableProperty_font_family:
        *aAtom = nsEditProperty::cssFontFamily;
        break;
      case eCSSEditableProperty_font_size:
        *aAtom = nsEditProperty::cssFontSize;
        break;
      case eCSSEditableProperty_font_style:
        *aAtom = nsEditProperty::cssFontStyle;
        break;
      case eCSSEditableProperty_font_weight:
        *aAtom = nsEditProperty::cssFontWeight;
        break;
      case eCSSEditableProperty_height:
        *aAtom = nsEditProperty::cssHeight;
        break;
      case eCSSEditableProperty_list_style_type:
        *aAtom = nsEditProperty::cssListStyleType;
        break;
      case eCSSEditableProperty_margin_left:
        *aAtom = nsEditProperty::cssMarginLeft;
        break;
      case eCSSEditableProperty_margin_right:
        *aAtom = nsEditProperty::cssMarginRight;
        break;
      case eCSSEditableProperty_text_align:
        *aAtom = nsEditProperty::cssTextAlign;
        break;
      case eCSSEditableProperty_text_decoration:
        *aAtom = nsEditProperty::cssTextDecoration;
        break;
      case eCSSEditableProperty_vertical_align:
        *aAtom = nsEditProperty::cssVerticalAlign;
        break;
      case eCSSEditableProperty_whitespace:
        *aAtom = nsEditProperty::cssWhitespace;
        break;
      case eCSSEditableProperty_width:
        *aAtom = nsEditProperty::cssWidth;
        break;
    }
  }
}

Here is the caller graph for this function:

Get the default browser background color if we need it for GetCSSBackgroundColorState.

Parameters:
aColor[OUT] the default color as it is defined in prefs

Definition at line 688 of file nsHTMLCSSUtils.cpp.

{
  nsresult result;
  nsCOMPtr<nsIPrefBranch> prefBranch =
    do_GetService(NS_PREFSERVICE_CONTRACTID, &result);
  if (NS_FAILED(result)) return result;
  aColor.AssignLiteral("#ffffff");
  nsXPIDLCString returnColor;
  if (prefBranch) {
    PRBool useCustomColors;
    result = prefBranch->GetBoolPref("editor.use_custom_colors", &useCustomColors);
    if (NS_FAILED(result)) return result;
    if (useCustomColors) {
      result = prefBranch->GetCharPref("editor.background_color",
                                       getter_Copies(returnColor));
      if (NS_FAILED(result)) return result;
    }
    else {
      PRBool useSystemColors;
      result = prefBranch->GetBoolPref("browser.display.use_system_colors", &useSystemColors);
      if (NS_FAILED(result)) return result;
      if (!useSystemColors) {
        result = prefBranch->GetCharPref("browser.display.background_color",
                                         getter_Copies(returnColor));
        if (NS_FAILED(result)) return result;
      }
    }
  }
  if (returnColor) {
    CopyASCIItoUTF16(returnColor, aColor);
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsHTMLCSSUtils::GetDefaultLengthUnit ( nsAString &  aLengthUnit)

Get the default length unit used for CSS Indent/Outdent.

Parameters:
aLengthUnit[OUT] the default length unit as it is defined in prefs

Definition at line 724 of file nsHTMLCSSUtils.cpp.

{
  nsresult result;
  nsCOMPtr<nsIPrefBranch> prefBranch =
    do_GetService(NS_PREFSERVICE_CONTRACTID, &result);
  if (NS_FAILED(result)) return result;
  aLengthUnit.AssignLiteral("px");
  if (NS_SUCCEEDED(result) && prefBranch) {
    nsXPIDLCString returnLengthUnit;
    result = prefBranch->GetCharPref("editor.css.default_length_unit",
                                     getter_Copies(returnLengthUnit));
    if (NS_FAILED(result)) return result;
    if (returnLengthUnit) {
      CopyASCIItoUTF16(returnLengthUnit, aLengthUnit);
    }
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Gets the default DOMView for a given node.

Parameters:
aNodethe node we want the default DOMView for
aViewCSS[OUT] the default DOMViewCSS

Definition at line 597 of file nsHTMLCSSUtils.cpp.

{
  nsCOMPtr<nsIDOMElement>element;
  nsresult res = GetElementContainerOrSelf(aNode, getter_AddRefs(element));
  if (NS_FAILED(res)) return res;

  // if we have an element node
  if (element) {
    // find the owner document
    nsCOMPtr<nsIDOMDocument> doc;
    nsCOMPtr<nsIDOMNode> node = do_QueryInterface(element);
    res = node->GetOwnerDocument(getter_AddRefs(doc));
    if (NS_FAILED(res)) return res;
    if (doc) {
      nsCOMPtr<nsIDOMDocumentView> documentView = do_QueryInterface(doc);
      nsCOMPtr<nsIDOMAbstractView> abstractView;
      // from the document, get the abtractView
      res = documentView->GetDefaultView(getter_AddRefs(abstractView));
      if (NS_FAILED(res)) return res;
      if (abstractView) {
        // from the abstractView, get the CSS view
        CallQueryInterface(abstractView, aViewCSS);
        return NS_OK;
      }
    }
  }
  *aViewCSS = nsnull;
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

returns aNode itself if it is an element node, or the first ancestors being an element node if aNode is not one itself

Parameters:
aNode[IN] a node
aElement[OUT] the deepest element node containing aNode (possibly aNode itself)

Definition at line 1408 of file nsHTMLCSSUtils.cpp.

{
  NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);

  nsCOMPtr<nsIDOMNode> node=aNode, parentNode;
  PRUint16 type;
  nsresult res;
  res = node->GetNodeType(&type);
  if (NS_FAILED(res)) return res;
  // loop until we find an element
  while (node && nsIDOMNode::ELEMENT_NODE != type) {
    parentNode = node;
    res = parentNode->GetParentNode(getter_AddRefs(node));
    if (NS_FAILED(res)) return res;
    if (node) {
      res = node->GetNodeType(&type);
      if (NS_FAILED(res)) return res;
    }
  }
  NS_ASSERTION(node, "we reached a null node ancestor !");
  NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
  nsCOMPtr<nsIDOMElement> element = do_QueryInterface(node);
  (*aElement) = element;
  NS_IF_ADDREF(*aElement);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

get the specified inline styles (style attribute) for an element

Parameters:
aElement[IN] the element node
aCssDecl[OUT] the CSS declaration corresponding to the style attr
aLength[OUT] the number of declarations in aCssDecl

Definition at line 1393 of file nsHTMLCSSUtils.cpp.

{
  if (!aElement || !aLength) return NS_ERROR_NULL_POINTER;
  *aLength = 0;
  nsCOMPtr<nsIDOMElementCSSInlineStyle> inlineStyles = do_QueryInterface(aElement);
  if (!inlineStyles) return NS_ERROR_NULL_POINTER;
  nsresult res = inlineStyles->GetStyle(aCssDecl);
  if (NS_FAILED(res) || !aCssDecl) return NS_ERROR_NULL_POINTER;
  (*aCssDecl)->GetLength(aLength);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsHTMLCSSUtils::GetSpecifiedProperty ( nsIDOMNode aNode,
nsIAtom aProperty,
nsAString &  aValue 
)

gets the specified/computed style value of a CSS property for a given node (or its element ancestor if it is not an element)

Parameters:
aNode[IN] a DOM node
aProperty[IN] an atom containing the CSS property to get
aPropertyValue[OUT] the retrieved value of the property

Definition at line 534 of file nsHTMLCSSUtils.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsHTMLCSSUtils::HasClassOrID ( nsIDOMElement aElement,
PRBool aReturn 
)

asnwers true if the element aElement carries an ID or a class

Parameters:
aElement[IN] a DOM element
aReturn[OUT] the boolean answer

Definition at line 1066 of file nsHTMLCSSUtils.cpp.

{
  nsAutoString classVal, idVal;
  PRBool isClassSet, isIdSet;
  aReturn = PR_FALSE;

  nsresult res = mHTMLEditor->GetAttributeValue(aElement,  NS_LITERAL_STRING("class"), classVal, &isClassSet);
  if (NS_FAILED(res)) return res;
  res = mHTMLEditor->GetAttributeValue(aElement,  NS_LITERAL_STRING("id"), idVal, &isIdSet);
  if (NS_FAILED(res)) return res;

  // we need to make sure that if the element has an id or a class attribute,
  // the attribute is not the empty string
  aReturn = ((isClassSet && !classVal.IsEmpty()) ||
             (isIdSet    && !idVal.IsEmpty()));
  return NS_OK;
}

Here is the caller graph for this function:

Definition at line 310 of file nsHTMLCSSUtils.cpp.

{
  nsresult result = NS_OK;
  mHTMLEditor = NS_STATIC_CAST(nsHTMLEditor*, aEditor);

  // let's retrieve the value of the "CSS editing" pref
  nsCOMPtr<nsIPrefBranch> prefBranch =
    do_GetService(NS_PREFSERVICE_CONTRACTID, &result);
  if (NS_SUCCEEDED(result) && prefBranch) {
    result = prefBranch->GetBoolPref("editor.use_css", &mIsCSSPrefChecked);
    if (NS_FAILED(result)) return result;
  }
  return result;
}

Here is the call graph for this function:

PRBool nsHTMLCSSUtils::IsCSSEditableProperty ( nsIDOMNode aNode,
nsIAtom aProperty,
const nsAString *  aAttribute 
)

answers true if the given combination element_name/attribute_name has a CSS equivalence in this implementation

Returns:
a boolean saying if the tag/attribute has a css equiv
Parameters:
aNode[IN] a DOM node
aProperty[IN] an atom containing a HTML tag name
aAttribute[IN] a string containing the name of a HTML attribute carried by the element above

Definition at line 328 of file nsHTMLCSSUtils.cpp.

{
  NS_ASSERTION(aNode, "Shouldn't you pass aNode? - Bug 214025");

  nsCOMPtr<nsIDOMNode> node = aNode;
  // we need an element node here
  if (mHTMLEditor->IsTextNode(aNode)) {
    aNode->GetParentNode(getter_AddRefs(node));
  }
  nsCOMPtr<nsIContent> content = do_QueryInterface(node);
  if (!content) return PR_FALSE;

  nsIAtom *tagName = content->Tag();
  // brade: should the above use nsEditor::GetTag(aNode)?
  // brade: shouldn't some of the above go below the next block?

  // html inline styles B I TT U STRIKE and COLOR/FACE on FONT
  if (nsEditProperty::b == aProperty
      || nsEditProperty::i == aProperty
      || nsEditProperty::tt == aProperty
      || nsEditProperty::u == aProperty
      || nsEditProperty::strike == aProperty
      || ((nsEditProperty::font == aProperty) && aAttribute &&
           (aAttribute->EqualsLiteral("color") ||
            aAttribute->EqualsLiteral("face")))) {
    return PR_TRUE;
  }

  // ALIGN attribute on elements supporting it
  if (aAttribute && (aAttribute->EqualsLiteral("align")) &&
      (nsEditProperty::div == tagName
       || nsEditProperty::p   == tagName
       || nsEditProperty::h1  == tagName
       || nsEditProperty::h2  == tagName
       || nsEditProperty::h3  == tagName
       || nsEditProperty::h4  == tagName
       || nsEditProperty::h5  == tagName
       || nsEditProperty::h6  == tagName
       || nsEditProperty::td  == tagName
       || nsEditProperty::th  == tagName
       || nsEditProperty::table  == tagName
       || nsEditProperty::hr  == tagName
       // brade: for the above, why not use nsHTMLEditUtils::SupportsAlignAttr
       // brade: but it also checks for tbody, tfoot, thead
       // Let's add the following elements here even if ALIGN has not
       // the same meaning for them
       || nsEditProperty::legend  == tagName
       || nsEditProperty::caption == tagName)) {
    return PR_TRUE;
  }

  if (aAttribute && (aAttribute->EqualsLiteral("valign")) &&
      (nsEditProperty::col == tagName
       || nsEditProperty::colgroup   == tagName
       || nsEditProperty::tbody  == tagName
       || nsEditProperty::td  == tagName
       || nsEditProperty::th  == tagName
       || nsEditProperty::tfoot  == tagName
       || nsEditProperty::thead  == tagName
       || nsEditProperty::tr  == tagName)) {
    return PR_TRUE;
  }

  // attributes TEXT, BACKGROUND and BGCOLOR on BODY
  if (aAttribute && (nsEditProperty::body == tagName) &&
      (aAttribute->EqualsLiteral("text")
       || aAttribute->EqualsLiteral("background")
       || aAttribute->EqualsLiteral("bgcolor"))) {
    return PR_TRUE;
  }

  // attribute BGCOLOR on other elements
  if (aAttribute && aAttribute->EqualsLiteral("bgcolor")) {
    return PR_TRUE;
  }

  // attributes HEIGHT, WIDTH and NOWRAP on TD and TH
  if (aAttribute && ((nsEditProperty::td == tagName)
                      || (nsEditProperty::th == tagName)) &&
      (aAttribute->EqualsLiteral("height")
       || aAttribute->EqualsLiteral("width")
       || aAttribute->EqualsLiteral("nowrap"))) {
    return PR_TRUE;
  }

  // attributes HEIGHT and WIDTH on TABLE
  if (aAttribute && (nsEditProperty::table == tagName) &&
      (aAttribute->EqualsLiteral("height")
       || aAttribute->EqualsLiteral("width"))) {
    return PR_TRUE;
  }

  // attributes SIZE and WIDTH on HR
  if (aAttribute && (nsEditProperty::hr == tagName) &&
      (aAttribute->EqualsLiteral("size")
       || aAttribute->EqualsLiteral("width"))) {
    return PR_TRUE;
  }

  // attribute TYPE on OL UL LI
  if (aAttribute && (nsEditProperty::ol == tagName
                     || nsEditProperty::ul == tagName
                     || nsEditProperty::li == tagName) &&
      aAttribute->EqualsLiteral("type")) {
    return PR_TRUE;
  }

  if (aAttribute && nsEditProperty::img == tagName &&
      (aAttribute->EqualsLiteral("border")
       || aAttribute->EqualsLiteral("width")
       || aAttribute->EqualsLiteral("height"))) {
    return PR_TRUE;
  }

  // other elements that we can align using CSS even if they
  // can't carry the html ALIGN attribute
  if (aAttribute && aAttribute->EqualsLiteral("align") &&
      (nsEditProperty::ul == tagName
       || nsEditProperty::ol == tagName
       || nsEditProperty::dl == tagName
       || nsEditProperty::li == tagName
       || nsEditProperty::dd == tagName
       || nsEditProperty::dt == tagName
       || nsEditProperty::address == tagName
       || nsEditProperty::pre == tagName
       || nsEditProperty::ul == tagName)) {
    return PR_TRUE;
  }

  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsHTMLCSSUtils::IsCSSEquivalentToHTMLInlineStyleSet ( nsIDOMNode aNode,
nsIAtom aHTMLProperty,
const nsAString *  aAttribute,
PRBool aIsSet,
nsAString &  aValueString,
PRUint8  aStyleType 
)

Does the node aNode (or his parent if it is not an element node) carries the CSS equivalent styles to the HTML style for this node ?

Parameters:
aNode[IN] a DOM node
aHTMLProperty[IN] an atom containing an HTML property
aAttribute[IN] a pointer to an attribute name or nsnull if irrelevant
aIsSet[OUT] a boolean being true if the css properties are set
aValueString[IN/OUT] the attribute value (in) the list of css values (out)
aStyleType[IN] SPECIFIED_STYLE_TYPE to query the specified style values COMPUTED_STYLE_TYPE to query the computed style values

Definition at line 1136 of file nsHTMLCSSUtils.cpp.

{
  NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);

  nsAutoString htmlValueString(valueString);
  aIsSet = PR_FALSE;
  nsCOMPtr<nsIDOMNode> node = aNode;
  NS_NAMED_LITERAL_STRING(boldStr, "bold");
  do {
    valueString.Assign(htmlValueString);
    // get the value of the CSS equivalent styles
    nsresult res = GetCSSEquivalentToHTMLInlineStyleSet(node, aHTMLProperty, aHTMLAttribute,
                                                        valueString, aStyleType);
    if (NS_FAILED(res)) return res;

    // early way out if we can
    if (valueString.IsEmpty()) return NS_OK;

    if (nsEditProperty::b == aHTMLProperty) {
      if (valueString.Equals(boldStr)) {
        aIsSet = PR_TRUE;
      }
      else if (valueString.EqualsLiteral("normal")) {
        aIsSet = PR_FALSE;
      }
      else if (valueString.EqualsLiteral("bolder")) {
        aIsSet = PR_TRUE;
        valueString.Assign(boldStr);
      }
      else {
        PRInt32 weight = 0;
        PRInt32 errorCode;
        nsAutoString value(valueString);
        weight = value.ToInteger(&errorCode, 10);
        if (400 < weight) {
          aIsSet = PR_TRUE;
          valueString.Assign(boldStr);
        }
        else {
          aIsSet = PR_FALSE;
          valueString.AssignLiteral("normal");
        }
      }
    }
    
    else if (nsEditProperty::i == aHTMLProperty) {
      if (valueString.EqualsLiteral("italic") ||
          valueString.EqualsLiteral("oblique")) {
        aIsSet= PR_TRUE;
      }
    }

    else if (nsEditProperty::u == aHTMLProperty) {
      nsAutoString val;
      val.AssignLiteral("underline");
      aIsSet = PRBool(ChangeCSSInlineStyleTxn::ValueIncludes(valueString, val, PR_FALSE));
    }

    else if (nsEditProperty::strike == aHTMLProperty) {
      nsAutoString val;
      val.AssignLiteral("line-through");
      aIsSet = PRBool(ChangeCSSInlineStyleTxn::ValueIncludes(valueString, val, PR_FALSE));
    }

    else if (aHTMLAttribute &&
             ( (nsEditProperty::font == aHTMLProperty && 
                aHTMLAttribute->EqualsLiteral("color")) ||
               aHTMLAttribute->EqualsLiteral("bgcolor"))) {
      if (htmlValueString.IsEmpty())
        aIsSet = PR_TRUE;
      else {
        nscolor rgba;
        nsAutoString subStr;
        htmlValueString.Right(subStr, htmlValueString.Length()-1);
        if (NS_ColorNameToRGB(htmlValueString, &rgba) ||
            NS_HexToRGB(subStr, &rgba)) {
          nsAutoString htmlColor, tmpStr;
          htmlColor.AppendLiteral("rgb(");

          NS_NAMED_LITERAL_STRING(comma, ", ");

          tmpStr.AppendInt(NS_GET_R(rgba), 10);
          htmlColor.Append(tmpStr + comma);

          tmpStr.Truncate();
          tmpStr.AppendInt(NS_GET_G(rgba), 10);
          htmlColor.Append(tmpStr + comma);

          tmpStr.Truncate();
          tmpStr.AppendInt(NS_GET_B(rgba), 10);
          htmlColor.Append(tmpStr);

          htmlColor.Append(PRUnichar(')'));
          aIsSet = htmlColor.Equals(valueString,
                                    nsCaseInsensitiveStringComparator());
        }
        else
          aIsSet = htmlValueString.Equals(valueString,
                                    nsCaseInsensitiveStringComparator());
      }
    }

    else if (nsEditProperty::tt == aHTMLProperty) {
      aIsSet = StringBeginsWith(valueString, NS_LITERAL_STRING("monospace"));
    }
    
    else if ((nsEditProperty::font == aHTMLProperty) && aHTMLAttribute
             && aHTMLAttribute->EqualsLiteral("face")) {
      if (!htmlValueString.IsEmpty()) {
        const PRUnichar commaSpace[] = { PRUnichar(','), PRUnichar(' '), 0 };
        const PRUnichar comma[] = { PRUnichar(','), 0 };
        htmlValueString.ReplaceSubstring(commaSpace, comma);
        nsAutoString valueStringNorm(valueString);
        valueStringNorm.ReplaceSubstring(commaSpace, comma);
        aIsSet = htmlValueString.Equals(valueStringNorm,
                                        nsCaseInsensitiveStringComparator());
      }
      else {
        // ignore this, it's TT or our default
        nsAutoString valueStringLower;
        ToLowerCase(valueString, valueStringLower);
        aIsSet = !valueStringLower.EqualsLiteral("monospace") &&
                 !valueStringLower.EqualsLiteral("serif");
      }
      return NS_OK;
    }
    else if (aHTMLAttribute
             && aHTMLAttribute->EqualsLiteral("align")) {
      aIsSet = PR_TRUE;
    }
    else {
      aIsSet = PR_FALSE;
      return NS_OK;
    }

    if (!htmlValueString.IsEmpty()) {
      if (htmlValueString.Equals(valueString,
                                 nsCaseInsensitiveStringComparator())) {
        aIsSet = PR_TRUE;
      }
    }

    if (nsEditProperty::u == aHTMLProperty || nsEditProperty::strike == aHTMLProperty) {
      // unfortunately, the value of the text-decoration property is not inherited.
      // that means that we have to look at ancestors of node to see if they are underlined
      nsCOMPtr<nsIDOMNode> tmp;
      res = node->GetParentNode(getter_AddRefs(tmp));
      if (NS_FAILED(res)) return res;
      nsCOMPtr<nsIDOMElement> element = do_QueryInterface(tmp);
      node = element;  // set to null if it's not a dom element
    }
  } while ((nsEditProperty::u == aHTMLProperty || nsEditProperty::strike == aHTMLProperty) &&
           !aIsSet && node);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsHTMLCSSUtils::IsCSSInvertable ( nsIAtom aProperty,
const nsAString *  aAttribute 
)

Answers true is the property can be removed by setting a "none" CSS value on a node.

Returns:
a boolean saying if the property can be remove by setting a "none" value
Parameters:
aProperty[IN] an atom containing a CSS property
aAttribute[IN] pointer to an attribute name or null if this information is irrelevant

Definition at line 681 of file nsHTMLCSSUtils.cpp.

{
  return PRBool(nsEditProperty::b == aProperty);
}

Here is the caller graph for this function:

retrieves the mIsCSSPrefChecked private member, true if the css pref is checked, false if it is not

Returns:
the boolean value of the css pref

Definition at line 1305 of file nsHTMLCSSUtils.cpp.

{
  return mIsCSSPrefChecked ;
}
void nsHTMLCSSUtils::ParseLength ( const nsAString &  aString,
float *  aValue,
nsIAtom **  aUnit 
)

parses a "xxxx.xxxxxuuu" string where x is a digit and u an alpha char we need such a parser because nsIDOMCSSStyleDeclaration::GetPropertyCSSValue() is not implemented

Parameters:
aString[IN] input string to parse
aValue[OUT] numeric part
aUnit[OUT] unit part

Definition at line 747 of file nsHTMLCSSUtils.cpp.

{
  nsAString::const_iterator iter;
  aString.BeginReading(iter);

  float a = 10.0f , b = 1.0f, value = 0;
  PRInt8 sign = 1;
  PRInt32 i = 0, j = aString.Length();
  PRUnichar c;
  nsAutoString unit;
  PRBool floatingPointFound = PR_FALSE;
  c = *iter;
  if (PRUnichar('-') == c) { sign = -1; iter++; i++; }
  else if (PRUnichar('+') == c) { iter++; i++; }
  while (i < j) {
    c = *iter;
    if ((PRUnichar('0') == c) ||
        (PRUnichar('1') == c) ||
        (PRUnichar('2') == c) ||
        (PRUnichar('3') == c) ||
        (PRUnichar('4') == c) ||
        (PRUnichar('5') == c) ||
        (PRUnichar('6') == c) ||
        (PRUnichar('7') == c) ||
        (PRUnichar('8') == c) ||
        (PRUnichar('9') == c)) {
      value = (value * a) + (b * (c - PRUnichar('0')));
      b = b / 10 * a;
    }
    else if (!floatingPointFound && (PRUnichar('.') == c)) {
      floatingPointFound = PR_TRUE;
      a = 1.0f; b = 0.1f;
    }
    else break;
    iter++;
    i++;
  }
  unit = Substring(aString, aString.Length() - (j-i), j-i);
  *aValue = value * sign;
  *aUnit = NS_NewAtom(unit); 
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsHTMLCSSUtils::RemoveCSSEquivalentToHTMLStyle ( nsIDOMNode aNode,
nsIAtom aHTMLProperty,
const nsAString *  aAttribute,
const nsAString *  aValue,
PRBool  aSuppressTransaction 
)

removes from the node the CSS inline styles equivalent to the HTML style

Parameters:
aNode[IN] a DOM node
aHTMLProperty[IN] an atom containing an HTML property
aAttribute[IN] a pointer to an attribute name or nsnull if irrelevant
aValue[IN] the attribute value
aSuppressTransaction[IN] a boolean indicating, when true, that no transaction should be recorded

Definition at line 1031 of file nsHTMLCSSUtils.cpp.

{
  nsCOMPtr<nsIDOMElement> theElement = do_QueryInterface(aNode);
  nsresult res = NS_OK;
  PRInt32 count = 0;
  if (theElement && IsCSSEditableProperty(aNode, aHTMLProperty, aAttribute)) {
    // we can apply the styles only if the node is an element and if we have
    // an equivalence for the requested HTML style in this implementation

    // Find the CSS equivalence to the HTML style
    nsVoidArray cssPropertyArray;
    nsStringArray cssValueArray;
    GenerateCSSDeclarationsFromHTMLStyle(aNode, aHTMLProperty, aAttribute, aValue,
                                         cssPropertyArray, cssValueArray, PR_TRUE);

    // remove the individual CSS inline styles
    count = cssPropertyArray.Count();
    PRInt32 index;
    for (index = 0; index < count; index++) {
      nsAutoString valueString;
      cssValueArray.StringAt(index, valueString);
      res = RemoveCSSProperty(theElement, (nsIAtom *)cssPropertyArray.ElementAt(index), valueString,
                              aSuppressTransaction);
      if (NS_FAILED(res)) return res;
    }
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsHTMLCSSUtils::RemoveCSSInlineStyle ( nsIDOMNode aNode,
nsIAtom aProperty,
const nsAString &  aPropertyValue 
)

Removes a CSS property from the specified declarations in STYLE attribute and removes the node if it is an useless span.

Parameters:
aNode[IN] the specific node we want to remove a style from
aProperty[IN] the CSS property atom to remove
aPropertyValue[IN] the value of the property we have to rremove if the property accepts more than one value

Definition at line 643 of file nsHTMLCSSUtils.cpp.

{
  nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(aNode);

  // remove the property from the style attribute
  nsresult res = RemoveCSSProperty(elem, aProperty, aPropertyValue, PR_FALSE);
  if (NS_FAILED(res)) return res;

  if (nsEditor::NodeIsType(aNode, nsEditProperty::span)) {
    nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
    PRUint32 attrCount = content->GetAttrCount();

    if (0 == attrCount) {
      // no more attributes on this span, let's remove the element
      res = mHTMLEditor->RemoveContainer(aNode);
      if (NS_FAILED(res)) return res;
    }
    else if (1 == attrCount) {
      // incredible hack in case the only remaining attribute is a _moz_dirty...
      PRInt32 nameSpaceID;
      nsCOMPtr<nsIAtom> attrName, prefix;
      res = content->GetAttrNameAt(0, &nameSpaceID, getter_AddRefs(attrName),
                                   getter_AddRefs(prefix));
      if (NS_FAILED(res)) return res;
      nsAutoString attrString, tmp;
      attrName->ToString(attrString);
      if (attrString.EqualsLiteral("_moz_dirty")) {
        res = mHTMLEditor->RemoveContainer(aNode);
        if (NS_FAILED(res)) return res;
      }
    }
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsHTMLCSSUtils::RemoveCSSProperty ( nsIDOMElement aElement,
nsIAtom aProperty,
const nsAString &  aPropertyValue,
PRBool  aSuppressTransaction 
)

Definition at line 498 of file nsHTMLCSSUtils.cpp.

{
  nsRefPtr<ChangeCSSInlineStyleTxn> txn;
  nsresult result = CreateCSSPropertyTxn(aElement, aProperty, aValue,
                                         getter_AddRefs(txn), PR_TRUE);
  if (NS_SUCCEEDED(result))  {
    if (aSuppressTransaction) {
      result = txn->DoTransaction();
    }
    else {
      result = mHTMLEditor->DoTransaction(txn);
    }
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsHTMLCSSUtils::RemoveCSSProperty ( nsIDOMElement aElement,
const nsAString &  aProperty 
)

Definition at line 1461 of file nsHTMLCSSUtils.cpp.

{
  nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
  PRUint32 length;
  nsresult res = GetInlineStyles(aElement, getter_AddRefs(cssDecl), &length);
  if (NS_FAILED(res) || !cssDecl) return res;

  nsAutoString returnString;
  return cssDecl->RemoveProperty(aProperty, returnString);
}

Here is the call graph for this function:

sets the mIsCSSPrefChecked private member ; used as callback from observer when the css pref state is changed

Parameters:
aIsCSSPrefChecked[IN] the new boolean state for the pref

Definition at line 1298 of file nsHTMLCSSUtils.cpp.

{
  mIsCSSPrefChecked = aIsCSSPrefChecked;
  return NS_OK;
}
nsresult nsHTMLCSSUtils::SetCSSEquivalentToHTMLStyle ( nsIDOMNode aNode,
nsIAtom aHTMLProperty,
const nsAString *  aAttribute,
const nsAString *  aValue,
PRInt32 aCount,
PRBool  aSuppressTransaction 
)

Adds to the node the CSS inline styles equivalent to the HTML style and return the number of CSS properties set by the call.

Parameters:
aNode[IN] a DOM node
aHTMLProperty[IN] an atom containing an HTML property
aAttribute[IN] a pointer to an attribute name or nsnull if irrelevant
aValue[IN] the attribute value
aCount[OUT] the number of CSS properties set by the call
aSuppressTransaction[IN] a boolean indicating, when true, that no transaction should be recorded

Definition at line 994 of file nsHTMLCSSUtils.cpp.

{
  nsCOMPtr<nsIDOMElement> theElement = do_QueryInterface(aNode);
  nsresult res = NS_OK;
  *aCount = 0;
  if (theElement && IsCSSEditableProperty(aNode, aHTMLProperty, aAttribute)) {
    // we can apply the styles only if the node is an element and if we have
    // an equivalence for the requested HTML style in this implementation

    // Find the CSS equivalence to the HTML style
    nsVoidArray cssPropertyArray;
    nsStringArray cssValueArray;
    GenerateCSSDeclarationsFromHTMLStyle(aNode, aHTMLProperty, aAttribute, aValue,
                                         cssPropertyArray, cssValueArray, PR_FALSE);

    // set the individual CSS inline styles
    *aCount = cssPropertyArray.Count();
    PRInt32 index;
    for (index = 0; index < *aCount; index++) {
      nsAutoString valueString;
      cssValueArray.StringAt(index, valueString);
      nsCOMPtr<nsIDOMElement> theElement = do_QueryInterface(aNode);
      res = SetCSSProperty(theElement, (nsIAtom *)cssPropertyArray.ElementAt(index),
                           valueString, aSuppressTransaction);
      if (NS_FAILED(res)) return res;
    }
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsHTMLCSSUtils::SetCSSProperty ( nsIDOMElement aElement,
nsIAtom aProperty,
const nsAString &  aValue,
PRBool  aSuppressTransaction 
)

adds/remove a CSS declaration to the STYLE atrribute carried by a given element

Parameters:
aElement[IN] a DOM element
aProperty[IN] an atom containing the CSS property to set
aValue[IN] a string containing the value of the CSS property
aSuppressTransaction[IN] a boolean indicating, when true, that no transaction should be recorded

Definition at line 465 of file nsHTMLCSSUtils.cpp.

{
  nsRefPtr<ChangeCSSInlineStyleTxn> txn;
  nsresult result = CreateCSSPropertyTxn(aElement, aProperty, aValue,
                                         getter_AddRefs(txn), PR_FALSE);
  if (NS_SUCCEEDED(result))  {
    if (aSuppressTransaction) {
      result = txn->DoTransaction();
    }
    else {
      result = mHTMLEditor->DoTransaction(txn);
    }
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsHTMLCSSUtils::SetCSSProperty ( nsIDOMElement aElement,
const nsAString &  aProperty,
const nsAString &  aValue 
)

directly adds/remove a CSS declaration to the STYLE atrribute carried by a given element without going through the txn manager

Parameters:
aElement[IN] a DOM element
aProperty[IN] a string containing the CSS property to set/remove
aValue[IN] a string containing the new value of the CSS property

Definition at line 1436 of file nsHTMLCSSUtils.cpp.

{
  nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
  PRUint32 length;
  nsresult res = GetInlineStyles(aElement, getter_AddRefs(cssDecl), &length);
  if (NS_FAILED(res) || !cssDecl) return res;

  return cssDecl->SetProperty(aProperty,
                              aValue,
                              EmptyString());
}

Here is the call graph for this function:

nsresult nsHTMLCSSUtils::SetCSSPropertyPixels ( nsIDOMElement aElement,
nsIAtom aProperty,
PRInt32  aIntValue,
PRBool  aSuppressTxn 
)

Definition at line 483 of file nsHTMLCSSUtils.cpp.

{
  nsAutoString s;
  s.AppendInt(aIntValue);
  return SetCSSProperty(aElement, aProperty, s + NS_LITERAL_STRING("px"),
                        aSuppressTransaction);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsHTMLCSSUtils::SetCSSPropertyPixels ( nsIDOMElement aElement,
const nsAString &  aProperty,
PRInt32  aIntValue 
)

Definition at line 1451 of file nsHTMLCSSUtils.cpp.

{
  nsAutoString s;
  s.AppendInt(aIntValue);
  return SetCSSProperty(aElement, aProperty, s + NS_LITERAL_STRING("px"));
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 400 of file nsHTMLCSSUtils.h.

Definition at line 401 of file nsHTMLCSSUtils.h.


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