Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Private Member Functions
nsCSSSelector Struct Reference

#include <nsICSSStyleRule.h>

Collaboration diagram for nsCSSSelector:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsCSSSelector (void)
 ~nsCSSSelector (void)
nsCSSSelectorClone () const
 Do a deep clone.
void Reset (void)
void SetNameSpace (PRInt32 aNameSpace)
void SetTag (const nsString &aTag)
void AddID (const nsString &aID)
void AddClass (const nsString &aClass)
void AddPseudoClass (const nsString &aPseudoClass, const PRUnichar *aString=nsnull)
void AddPseudoClass (nsIAtom *aPseudoClass, const PRUnichar *aString=nsnull)
void AddAttribute (PRInt32 aNameSpace, const nsString &aAttr)
void AddAttribute (PRInt32 aNameSpace, const nsString &aAttr, PRUint8 aFunc, const nsString &aValue, PRBool aCaseSensitive)
void SetOperator (PRUnichar aOperator)
PRInt32 CalcWeight (void) const
void ToString (nsAString &aString, nsICSSStyleSheet *aSheet, PRBool aAppend=PR_FALSE) const

Public Attributes

PRInt32 mNameSpace
nsCOMPtr< nsIAtommTag
nsAtomListmIDList
nsAtomListmClassList
nsAtomStringListmPseudoClassList
nsAttrSelectormAttrList
PRUnichar mOperator
nsCSSSelectormNegations
nsCSSSelectormNext

Private Member Functions

nsCSSSelectorClone (PRBool aDeepNext, PRBool aDeepNegations) const
void AppendNegationToString (nsAString &aString)
void ToStringInternal (nsAString &aString, nsICSSStyleSheet *aSheet, PRBool aIsPseudoElem, PRIntn aNegatedIndex) const
 nsCSSSelector (const nsCSSSelector &aCopy)
nsCSSSelectoroperator= (const nsCSSSelector &aCopy)

Detailed Description

Definition at line 126 of file nsICSSStyleRule.h.


Constructor & Destructor Documentation

Definition at line 310 of file nsCSSStyleRule.cpp.

{
  MOZ_COUNT_DTOR(nsCSSSelector);
  Reset();
  // No need to worry about multiple levels of recursion since an
  // mNegations can't have an mNext.
  NS_IF_DEEP_DELETE(nsCSSSelector, mNext);
}

Here is the call graph for this function:


Member Function Documentation

void nsCSSSelector::AddAttribute ( PRInt32  aNameSpace,
const nsString aAttr 
)

Definition at line 392 of file nsCSSStyleRule.cpp.

{
  if (!aAttr.IsEmpty()) {
    nsAttrSelector** list = &mAttrList;
    while (nsnull != *list) {
      list = &((*list)->mNext);
    }
    *list = new nsAttrSelector(aNameSpace, aAttr);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsCSSSelector::AddAttribute ( PRInt32  aNameSpace,
const nsString aAttr,
PRUint8  aFunc,
const nsString aValue,
PRBool  aCaseSensitive 
)

Definition at line 403 of file nsCSSStyleRule.cpp.

{
  if (!aAttr.IsEmpty()) {
    nsAttrSelector** list = &mAttrList;
    while (nsnull != *list) {
      list = &((*list)->mNext);
    }
    *list = new nsAttrSelector(aNameSpace, aAttr, aFunc, aValue, aCaseSensitive);
  }
}

Here is the call graph for this function:

Definition at line 357 of file nsCSSStyleRule.cpp.

{
  if (!aClass.IsEmpty()) {
    nsAtomList** list = &mClassList;
    while (nsnull != *list) {
      list = &((*list)->mNext);
    }
    *list = new nsAtomList(aClass);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 346 of file nsCSSStyleRule.cpp.

{
  if (!aID.IsEmpty()) {
    nsAtomList** list = &mIDList;
    while (nsnull != *list) {
      list = &((*list)->mNext);
    }
    *list = new nsAtomList(aID);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsCSSSelector::AddPseudoClass ( const nsString aPseudoClass,
const PRUnichar aString = nsnull 
)

Definition at line 368 of file nsCSSStyleRule.cpp.

{
  if (!aPseudoClass.IsEmpty()) {
    nsAtomStringList** list = &mPseudoClassList;
    while (nsnull != *list) {
      list = &((*list)->mNext);
    }
    *list = new nsAtomStringList(aPseudoClass, aString);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsCSSSelector::AddPseudoClass ( nsIAtom aPseudoClass,
const PRUnichar aString = nsnull 
)

Definition at line 380 of file nsCSSStyleRule.cpp.

{
  if (nsnull != aPseudoClass) {
    nsAtomStringList** list = &mPseudoClassList;
    while (nsnull != *list) {
      list = &((*list)->mNext);
    }
    *list = new nsAtomStringList(aPseudoClass, aString);
  }
}

Here is the call graph for this function:

void nsCSSSelector::AppendNegationToString ( nsAString &  aString) [private]

Definition at line 466 of file nsCSSStyleRule.cpp.

{
  aString.AppendLiteral(":not(");
}

Definition at line 420 of file nsCSSStyleRule.cpp.

{
  PRInt32 weight = 0;

  if (nsnull != mTag) {
    weight += 0x000001;
  }
  nsAtomList* list = mIDList;
  while (nsnull != list) {
    weight += 0x010000;
    list = list->mNext;
  }
  list = mClassList;
  while (nsnull != list) {
    weight += 0x000100;
    list = list->mNext;
  }
  nsAtomStringList *plist = mPseudoClassList;
  while (nsnull != plist) {
    weight += 0x000100;
    plist = plist->mNext;
  }
  nsAttrSelector* attr = mAttrList;
  while (nsnull != attr) {
    weight += 0x000100;
    attr = attr->mNext;
  }
  if (nsnull != mNegations) {
    weight += mNegations->CalcWeight();
  }
  return weight;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsCSSSelector* nsCSSSelector::Clone ( void  ) const [inline]

Do a deep clone.

Should be used only on the first in the linked list.

Definition at line 132 of file nsICSSStyleRule.h.

{ return Clone(PR_TRUE, PR_TRUE); }

Here is the call graph for this function:

Here is the caller graph for this function:

nsCSSSelector * nsCSSSelector::Clone ( PRBool  aDeepNext,
PRBool  aDeepNegations 
) const [private]

Definition at line 283 of file nsCSSStyleRule.cpp.

{
  nsCSSSelector *result = new nsCSSSelector();
  if (!result)
    return nsnull;

  result->mNameSpace = mNameSpace;
  result->mTag = mTag;
  
  NS_IF_CLONE(mIDList);
  NS_IF_CLONE(mClassList);
  NS_IF_CLONE(mPseudoClassList);
  NS_IF_CLONE(mAttrList);

  // No need to worry about multiple levels of recursion since an
  // mNegations can't have an mNext.
  if (aDeepNegations) {
    NS_IF_DEEP_CLONE(nsCSSSelector, mNegations, (PR_TRUE, PR_FALSE));
  }

  if (aDeepNext) {
    NS_IF_DEEP_CLONE(nsCSSSelector, mNext, (PR_FALSE, PR_TRUE));
  }

  return result;
}

Here is the call graph for this function:

nsCSSSelector& nsCSSSelector::operator= ( const nsCSSSelector aCopy) [private]

Definition at line 319 of file nsCSSStyleRule.cpp.

{
  mNameSpace = kNameSpaceID_Unknown;
  mTag = nsnull;
  NS_IF_DELETE(mIDList);
  NS_IF_DELETE(mClassList);
  NS_IF_DELETE(mPseudoClassList);
  NS_IF_DELETE(mAttrList);
  // No need to worry about multiple levels of recursion since an
  // mNegations can't have an mNext.
  NS_IF_DEEP_DELETE(nsCSSSelector, mNegations);
  mOperator = PRUnichar(0);
}

Here is the caller graph for this function:

Definition at line 333 of file nsCSSStyleRule.cpp.

{
  mNameSpace = aNameSpace;
}

Here is the caller graph for this function:

Definition at line 415 of file nsCSSStyleRule.cpp.

{
  mOperator = aOperator;
}

Here is the caller graph for this function:

Definition at line 338 of file nsCSSStyleRule.cpp.

{
  if (aTag.IsEmpty())
    mTag = nsnull;
  else
    mTag = do_GetAtom(aTag);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsCSSSelector::ToString ( nsAString &  aString,
nsICSSStyleSheet aSheet,
PRBool  aAppend = PR_FALSE 
) const

Definition at line 476 of file nsCSSStyleRule.cpp.

{
  if (!aAppend)
   aString.Truncate();
   
  ToStringInternal(aString, aSheet, IsPseudoElement(mTag), 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsCSSSelector::ToStringInternal ( nsAString &  aString,
nsICSSStyleSheet aSheet,
PRBool  aIsPseudoElem,
PRIntn  aNegatedIndex 
) const [private]

Definition at line 485 of file nsCSSStyleRule.cpp.

{
  nsAutoString temp;
  PRBool aIsNegated = PRBool(0 < aNegatedIndex);
  PRBool isPseudoElement = IsPseudoElement(mTag);
  
  // selectors are linked from right-to-left, so the next selector in the linked list
  // actually precedes this one in the resulting string
  if (mNext) {
    mNext->ToStringInternal(aString, aSheet, IsPseudoElement(mTag), 0);
    if (!aIsNegated && !isPseudoElement) {
      // don't add a leading whitespace if we have a pseudo-element
      // or a negated simple selector
      aString.Append(PRUnichar(' '));
    }
  }
  if (1 < aNegatedIndex) {
    // the first mNegations does not contain a negated type element selector
    // or a negated universal selector
    NS_IF_NEGATED_START(aIsNegated, aString)
  }

  // For non-pseudo-element selectors or for lone pseudo-elements, deal with
  // namespace prefixes.
  if (!isPseudoElement || !mNext) {
    // append the namespace prefix if needed
    if (mNameSpace == kNameSpaceID_None) {
      // The only way to do this in CSS is to have an explicit namespace
      // of "none" specified in the sheet by having a '|' with nothing
      // before it.
      aString.Append(PRUnichar('|'));
    } else {
      if (aSheet) {
        nsXMLNameSpaceMap *sheetNS = aSheet->GetNameSpaceMap();
    
        // sheetNS is non-null if and only if we had an @namespace rule.  If it's
        // null, that means that the only namespaces we could have are the
        // wildcard namespace (which can be implicit in this case) and the "none"
        // namespace, which we handled above.  So no need to output anything when
        // sheetNS is null.
        if (sheetNS) {
          nsIAtom *prefixAtom = nsnull;
          // prefixAtom is non-null if and only if we have a prefix other than
          // '*'
          if (mNameSpace != kNameSpaceID_Unknown) {
            prefixAtom = sheetNS->FindPrefix(mNameSpace);
          }
          if (prefixAtom) {
            nsAutoString prefix;
            prefixAtom->ToString(prefix);
            aString.Append(prefix);
            aString.Append(PRUnichar('|'));
          } else if (mNameSpace == kNameSpaceID_Unknown) {
            // explicit *| or only non-default namespace rules and we're not
            // using any of those namespaces
            aString.AppendLiteral("*|");
          }
          // else we are in the default namespace and don't need to output
          // anything
        }
      }
    }
  }
      
  // smells like a universal selector
  if (!mTag && !mIDList && !mClassList) {
    if (1 != aNegatedIndex) {
      aString.Append(PRUnichar('*'));
    }
    if (1 < aNegatedIndex) {
      NS_IF_NEGATED_END(aIsNegated, aString)
    }
  } else {
    // Append the tag name, if there is one
    if (mTag) {
      if (isPseudoElement) {
        if (!mNext) {
          // Lone pseudo-element selector -- toss in a wildcard type selector
          aString.Append(PRUnichar('*'));
        }
        if (!nsCSSPseudoElements::IsCSS2PseudoElement(mTag)) {
          aString.Append(PRUnichar(':'));
        }
      }
      nsAutoString prefix;
      mTag->ToString(prefix);
      aString.Append(prefix);
      NS_IF_NEGATED_END(aIsNegated, aString)
    }
    // Append the id, if there is one
    if (mIDList) {
      nsAtomList* list = mIDList;
      while (list != nsnull) {
        list->mAtom->ToString(temp);
        NS_IF_NEGATED_START(aIsNegated, aString)
        aString.Append(PRUnichar('#'));
        aString.Append(temp);
        NS_IF_NEGATED_END(aIsNegated, aString)
        list = list->mNext;
      }
    }
    // Append each class in the linked list
    if (mClassList) {
      nsAtomList* list = mClassList;
      while (list != nsnull) {
        list->mAtom->ToString(temp);
        NS_IF_NEGATED_START(aIsNegated, aString)
        aString.Append(PRUnichar('.'));
        aString.Append(temp);
        NS_IF_NEGATED_END(aIsNegated, aString)
        list = list->mNext;
      }
    }
  }

  // Append each attribute selector in the linked list
  if (mAttrList) {
    nsAttrSelector* list = mAttrList;
    while (list != nsnull) {
      NS_IF_NEGATED_START(aIsNegated, aString)
      aString.Append(PRUnichar('['));
      // Append the namespace prefix
      if (list->mNameSpace > 0) {
        if (aSheet) {
          nsXMLNameSpaceMap *sheetNS = aSheet->GetNameSpaceMap();
          // will return null if namespace was the default
          nsIAtom *prefixAtom = sheetNS->FindPrefix(list->mNameSpace);
          if (prefixAtom) { 
            nsAutoString prefix;
            prefixAtom->ToString(prefix);
            aString.Append(prefix);
            aString.Append(PRUnichar('|'));
          }
        }
      }
      // Append the attribute name
      list->mAttr->ToString(temp);
      aString.Append(temp);

      if (list->mFunction != NS_ATTR_FUNC_SET) {
        // Append the function
        if (list->mFunction == NS_ATTR_FUNC_INCLUDES)
          aString.Append(PRUnichar('~'));
        else if (list->mFunction == NS_ATTR_FUNC_DASHMATCH)
          aString.Append(PRUnichar('|'));
        else if (list->mFunction == NS_ATTR_FUNC_BEGINSMATCH)
          aString.Append(PRUnichar('^'));
        else if (list->mFunction == NS_ATTR_FUNC_ENDSMATCH)
          aString.Append(PRUnichar('$'));
        else if (list->mFunction == NS_ATTR_FUNC_CONTAINSMATCH)
          aString.Append(PRUnichar('*'));

        aString.Append(PRUnichar('='));
      
        // Append the value
        nsAutoString escaped;
        nsStyleUtil::EscapeCSSString(list->mValue, escaped);
      
        aString.Append(PRUnichar('\"'));
        aString.Append(escaped);
        aString.Append(PRUnichar('\"'));
      }

      aString.Append(PRUnichar(']'));
      
      NS_IF_NEGATED_END(aIsNegated, aString)
      list = list->mNext;
    }
  }

  // Append each pseudo-class in the linked list
  if (mPseudoClassList) {
    nsAtomStringList* list = mPseudoClassList;
    while (list != nsnull) {
      list->mAtom->ToString(temp);
      NS_IF_NEGATED_START(aIsNegated, aString)
      aString.Append(temp);
      if (nsnull != list->mString) {
        aString.Append(PRUnichar('('));
        aString.Append(list->mString);
        aString.Append(PRUnichar(')'));
      }
      NS_IF_NEGATED_END(aIsNegated, aString)
      list = list->mNext;
    }
  }

  if (mNegations) {
    // chain all the negated selectors
    mNegations->ToStringInternal(aString, aSheet, PR_FALSE, aNegatedIndex + 1);
  }

  // Append the operator only if the selector is not negated and is not
  // a pseudo-element
  if (!aIsNegated && mOperator && !aIsPseudoElem) {
    aString.Append(PRUnichar(' '));
    aString.Append(mOperator);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 166 of file nsICSSStyleRule.h.

Definition at line 163 of file nsICSSStyleRule.h.

Definition at line 162 of file nsICSSStyleRule.h.

Definition at line 160 of file nsICSSStyleRule.h.

Definition at line 168 of file nsICSSStyleRule.h.

Definition at line 170 of file nsICSSStyleRule.h.

Definition at line 167 of file nsICSSStyleRule.h.

Definition at line 164 of file nsICSSStyleRule.h.

Definition at line 161 of file nsICSSStyleRule.h.


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