Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Friends
nsCSSStyleSheet Class Reference

#include <nsCSSStyleSheet.h>

Inheritance diagram for nsCSSStyleSheet:
Inheritance graph
[legend]
Collaboration diagram for nsCSSStyleSheet:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsCSSStyleSheet ()
NS_DECL_ISUPPORTS NS_IMETHOD GetSheetURI (nsIURI **aSheetURI) const
NS_IMETHOD GetBaseURI (nsIURI **aBaseURI) const
NS_IMETHOD GetTitle (nsString &aTitle) const
NS_IMETHOD GetType (nsString &aType) const
 NS_IMETHOD_ (PRBool) UseForMedium(nsPresContext *aPresContext) const
 NS_IMETHOD_ (PRBool) HasRules() const
NS_IMETHOD GetApplicable (PRBool &aApplicable) const
 Whether the sheet is applicable.
NS_IMETHOD SetEnabled (PRBool aEnabled)
 Set the stylesheet to be enabled.
NS_IMETHOD GetComplete (PRBool &aComplete) const
 Whether the sheet is complete.
NS_IMETHOD SetComplete ()
NS_IMETHOD GetParentSheet (nsIStyleSheet *&aParent) const
NS_IMETHOD GetOwningDocument (nsIDocument *&aDocument) const
NS_IMETHOD SetOwningDocument (nsIDocument *aDocument)
NS_IMETHOD ContainsStyleSheet (nsIURI *aURL, PRBool &aContains, nsIStyleSheet **aTheChild=nsnull)
NS_IMETHOD AppendStyleSheet (nsICSSStyleSheet *aSheet)
NS_IMETHOD InsertStyleSheetAt (nsICSSStyleSheet *aSheet, PRInt32 aIndex)
NS_IMETHOD PrependStyleRule (nsICSSRule *aRule)
NS_IMETHOD AppendStyleRule (nsICSSRule *aRule)
NS_IMETHOD ReplaceStyleRule (nsICSSRule *aOld, nsICSSRule *aNew)
NS_IMETHOD StyleRuleCount (PRInt32 &aCount) const
NS_IMETHOD GetStyleRuleAt (PRInt32 aIndex, nsICSSRule *&aRule) const
NS_IMETHOD DeleteRuleFromGroup (nsICSSGroupRule *aGroup, PRUint32 aIndex)
NS_IMETHOD InsertRuleIntoGroup (const nsAString &aRule, nsICSSGroupRule *aGroup, PRUint32 aIndex, PRUint32 *_retval)
NS_IMETHOD ReplaceRuleInGroup (nsICSSGroupRule *aGroup, nsICSSRule *aOld, nsICSSRule *aNew)
NS_IMETHOD StyleSheetCount (PRInt32 &aCount) const
NS_IMETHOD GetStyleSheetAt (PRInt32 aIndex, nsICSSStyleSheet *&aSheet) const
NS_IMETHOD SetURIs (nsIURI *aSheetURI, nsIURI *aBaseURI)
 SetURIs must be called on all sheets before parsing into them.
NS_IMETHOD SetTitle (const nsAString &aTitle)
NS_IMETHOD SetMedia (nsMediaList *aMedia)
NS_IMETHOD SetOwningNode (nsIDOMNode *aOwningNode)
NS_IMETHOD SetOwnerRule (nsICSSImportRule *aOwnerRule)
NS_IMETHOD GetOwnerRule (nsICSSImportRule **aOwnerRule)
virtual NS_HIDDEN_ (nsXMLNameSpaceMap *) GetNameSpaceMap() const
NS_IMETHOD Clone (nsICSSStyleSheet *aCloneParent, nsICSSImportRule *aCloneOwnerRule, nsIDocument *aCloneDocument, nsIDOMNode *aCloneOwningNode, nsICSSStyleSheet **aClone) const
NS_IMETHOD IsModified (PRBool *aSheetModified) const
NS_IMETHOD SetModified (PRBool aModified)
NS_IMETHOD AddRuleProcessor (nsCSSRuleProcessor *aProcessor)
NS_IMETHOD DropRuleProcessor (nsCSSRuleProcessor *aProcessor)
NS_IMETHOD SetURIs18 (nsIURI *aSheetURI, nsIURI *aOriginalSheetURI, nsIURI *aBaseURI)
NS_IMETHOD StyleSheetLoaded (nsICSSStyleSheet *aSheet, PRBool aNotify)
nsresult EnsureUniqueInner ()
unsigned long insertRule (in DOMString rule, in unsigned long index) raises (DOMException)
void deleteRule (in unsigned long index) raises (DOMException)

Public Attributes

readonly attribute nsIDOMCSSRule ownerRule
readonly attribute
nsIDOMCSSRuleList 
cssRules
readonly attribute DOMString type
attribute boolean disabled
readonly attribute nsIDOMNode ownerNode
readonly attribute nsIDOMStyleSheet parentStyleSheet
readonly attribute DOMString href
readonly attribute DOMString title
readonly attribute nsIDOMMediaList media

Protected Member Functions

virtual ~nsCSSStyleSheet ()
void ClearRuleCascades ()
nsresult WillDirty ()
void DidDirty ()

Protected Attributes

nsString mTitle
nsCOMPtr< nsMediaListmMedia
nsCSSStyleSheetmFirstChild
nsCSSStyleSheetmNext
nsICSSStyleSheetmParent
nsICSSImportRulemOwnerRule
CSSImportsCollectionImplmImportsCollection
CSSRuleListImplmRuleCollection
nsIDocumentmDocument
nsIDOMNodemOwningNode
PRPackedBool mDisabled
PRPackedBool mDirty
nsCSSStyleSheetInnermInner
nsAutoVoidArray * mRuleProcessors

Private Member Functions

 nsCSSStyleSheet (const nsCSSStyleSheet &aCopy, nsICSSStyleSheet *aParentToUse, nsICSSImportRule *aOwnerRuleToUse, nsIDocument *aDocumentToUse, nsIDOMNode *aOwningNodeToUse)
 nsCSSStyleSheet (const nsCSSStyleSheet &aCopy)
nsCSSStyleSheetoperator= (const nsCSSStyleSheet &aCopy)

Friends

class nsMediaList
PRBool CascadeSheetRulesInto (nsICSSStyleSheet *aSheet, void *aData)

Detailed Description

Definition at line 91 of file nsCSSStyleSheet.h.


Constructor & Destructor Documentation

nsCSSStyleSheet::nsCSSStyleSheet ( const nsCSSStyleSheet aCopy,
nsICSSStyleSheet aParentToUse,
nsICSSImportRule aOwnerRuleToUse,
nsIDocument aDocumentToUse,
nsIDOMNode aOwningNodeToUse 
) [private]

Definition at line 1302 of file nsCSSStyleSheet.cpp.

  : nsICSSStyleSheet_MOZILLA_1_8_BRANCH(),
    mRefCnt(0),
    mTitle(aCopy.mTitle), 
    mMedia(nsnull),
    mFirstChild(nsnull), 
    mNext(nsnull),
    mParent(aParentToUse),
    mOwnerRule(aOwnerRuleToUse),
    mImportsCollection(nsnull), // re-created lazily
    mRuleCollection(nsnull), // re-created lazily
    mDocument(aDocumentToUse),
    mOwningNode(aOwningNodeToUse),
    mDisabled(aCopy.mDisabled),
    mDirty(PR_FALSE),
    mInner(aCopy.mInner),
    mRuleProcessors(nsnull)
{

  mInner->AddSheet(this);

  if (aCopy.mRuleCollection && 
      aCopy.mRuleCollection->mRulesAccessed) {  // CSSOM's been there, force full copy now
    NS_ASSERTION(mInner->mComplete, "Why have rules been accessed on an incomplete sheet?");
    EnsureUniqueInner();
  }

  if (aCopy.mMedia) {
    aCopy.mMedia->Clone(getter_AddRefs(mMedia));
  }

  if (aCopy.mFirstChild) {
    nsCSSStyleSheet*  otherChild = aCopy.mFirstChild;
    nsCSSStyleSheet** ourSlot = &mFirstChild;
    do {
      // XXX This is wrong; we should be keeping @import rules and
      // sheets in sync!
      nsCSSStyleSheet* child = new nsCSSStyleSheet(*otherChild,
                                                       this,
                                                       nsnull,
                                                       aDocumentToUse,
                                                       nsnull);
      if (child) {
        NS_ADDREF(child);
        (*ourSlot) = child;
        ourSlot = &(child->mNext);
      }
      otherChild = otherChild->mNext;
    }
    while (otherChild && ourSlot);
  }
}

Here is the call graph for this function:

nsCSSStyleSheet::~nsCSSStyleSheet ( ) [protected, virtual]

Definition at line 1359 of file nsCSSStyleSheet.cpp.

{
  if (mFirstChild) {
    nsCSSStyleSheet* child = mFirstChild;
    do {
      child->mParent = nsnull;
      child->mDocument = nsnull;
      child = child->mNext;
    } while (child);
    NS_RELEASE(mFirstChild);
  }
  NS_IF_RELEASE(mNext);
  if (nsnull != mRuleCollection) {
    mRuleCollection->DropReference();
    NS_RELEASE(mRuleCollection);
  }
  if (nsnull != mImportsCollection) {
    mImportsCollection->DropReference();
    NS_RELEASE(mImportsCollection);
  }
  if (mMedia) {
    mMedia->SetStyleSheet(nsnull);
    mMedia = nsnull;
  }
  mInner->RemoveSheet(this);
  // XXX The document reference is not reference counted and should
  // not be released. The document will let us know when it is going
  // away.
  if (mRuleProcessors) {
    NS_ASSERTION(mRuleProcessors->Count() == 0, "destucting sheet with rule processor reference");
    delete mRuleProcessors; // weak refs, should be empty here anyway
  }
}

Here is the call graph for this function:


Member Function Documentation

Implements nsICSSStyleSheet.

Definition at line 1412 of file nsCSSStyleSheet.cpp.

{
  if (! mRuleProcessors) {
    mRuleProcessors = new nsAutoVoidArray();
    if (!mRuleProcessors)
      return NS_ERROR_OUT_OF_MEMORY;
  }
  NS_ASSERTION(-1 == mRuleProcessors->IndexOf(aProcessor),
               "processor already registered");
  mRuleProcessors->AppendElement(aProcessor); // weak ref
  return NS_OK;
}

Implements nsICSSStyleSheet.

Definition at line 1728 of file nsCSSStyleSheet.cpp.

{
  NS_PRECONDITION(nsnull != aRule, "null arg");

  if (NS_SUCCEEDED(WillDirty())) {
    if (! mInner->mOrderedRules) {
      NS_NewISupportsArray(&(mInner->mOrderedRules));
    }
    if (mInner->mOrderedRules) {
      mInner->mOrderedRules->AppendElement(aRule);
      aRule->SetStyleSheet(this);
      DidDirty();

      PRInt32 type = nsICSSRule::UNKNOWN_RULE;
      aRule->GetType(type);
      if (nsICSSRule::NAMESPACE_RULE == type) {
        if (!mInner->mNameSpaceMap) {
          mInner->mNameSpaceMap = nsXMLNameSpaceMap::Create();
          NS_ENSURE_TRUE(mInner->mNameSpaceMap, NS_ERROR_OUT_OF_MEMORY);
        }

        nsCOMPtr<nsICSSNameSpaceRule> nameSpaceRule(do_QueryInterface(aRule));

        nsCOMPtr<nsIAtom> prefix;
        nsAutoString  urlSpec;
        nameSpaceRule->GetPrefix(*getter_AddRefs(prefix));
        nameSpaceRule->GetURLSpec(urlSpec);

        mInner->mNameSpaceMap->AddPrefix(prefix, urlSpec);
      }
    }
  }
  return NS_OK;
}

Here is the call graph for this function:

Implements nsICSSStyleSheet.

Definition at line 1641 of file nsCSSStyleSheet.cpp.

{
  NS_PRECONDITION(nsnull != aSheet, "null arg");

  if (NS_SUCCEEDED(WillDirty())) {
    NS_ADDREF(aSheet);
    nsCSSStyleSheet* sheet = (nsCSSStyleSheet*)aSheet;

    if (! mFirstChild) {
      mFirstChild = sheet;
    }
    else {
      nsCSSStyleSheet* child = mFirstChild;
      while (child->mNext) {
        child = child->mNext;
      }
      child->mNext = sheet;
    }
  
    // This is not reference counted. Our parent tells us when
    // it's going away.
    sheet->mParent = this;
    sheet->mDocument = mDocument;
    DidDirty();
  }
  return NS_OK;
}

Here is the call graph for this function:

Definition at line 2001 of file nsCSSStyleSheet.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsCSSStyleSheet::Clone ( nsICSSStyleSheet aCloneParent,
nsICSSImportRule aCloneOwnerRule,
nsIDocument aCloneDocument,
nsIDOMNode aCloneOwningNode,
nsICSSStyleSheet **  aClone 
) const [virtual]

Implements nsICSSStyleSheet.

Definition at line 1889 of file nsCSSStyleSheet.cpp.

{
  NS_PRECONDITION(aClone, "Null out param!");
  nsCSSStyleSheet* clone = new nsCSSStyleSheet(*this,
                                                   aCloneParent,
                                                   aCloneOwnerRule,
                                                   aCloneDocument,
                                                   aCloneOwningNode);
  if (clone) {
    *aClone = NS_STATIC_CAST(nsICSSStyleSheet*, clone);
    NS_ADDREF(*aClone);
  }
  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsCSSStyleSheet::ContainsStyleSheet ( nsIURI aURL,
PRBool aContains,
nsIStyleSheet **  aTheChild = nsnull 
) [virtual]

Implements nsICSSStyleSheet.

Definition at line 1600 of file nsCSSStyleSheet.cpp.

{
  NS_PRECONDITION(nsnull != aURL, "null arg");

  if (!mInner || !mInner->mSheetURI) {
    // We're not yet far enough along in our load to know what our URL is (we
    // may still get redirected and such).  Assert (caller should really not be
    // calling this on us at this stage) and return.
    NS_ERROR("ContainsStyleSheet called on a sheet that's still loading");
    aContains = PR_FALSE;
    return NS_OK;
  }
  
  // first check ourself out
  nsresult rv = mInner->mSheetURI->Equals(aURL, &aContains);
  if (NS_FAILED(rv)) aContains = PR_FALSE;

  if (aContains) {
    // if we found it and the out-param is there, set it and addref
    if (aTheChild) {
      rv = QueryInterface( NS_GET_IID(nsIStyleSheet), (void **)aTheChild);
    }
  } else {
    nsCSSStyleSheet*  child = mFirstChild;
    // now check the chil'ins out (recursively)
    while ((PR_FALSE == aContains) && (nsnull != child)) {
      child->ContainsStyleSheet(aURL, aContains, aTheChild);
      if (aContains) {
        break;
      } else {
        child = child->mNext;
      }
    }
  }

  // NOTE: if there are errors in the above we are handling them locally 
  //       and not promoting them to the caller
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIDOMCSSStyleSheet::deleteRule ( in unsigned long  index) raises (DOMException) [inherited]

Implements nsICSSStyleSheet.

Definition at line 2428 of file nsCSSStyleSheet.cpp.

{
  NS_ENSURE_ARG_POINTER(aGroup);
  NS_ASSERTION(mInner && mInner->mComplete,
               "No deleting from an incomplete sheet!");
  nsresult result;
  nsCOMPtr<nsICSSRule> rule;
  result = aGroup->GetStyleRuleAt(aIndex, *getter_AddRefs(rule));
  NS_ENSURE_SUCCESS(result, result);
  
  // check that the rule actually belongs to this sheet!
  nsCOMPtr<nsIStyleSheet> ruleSheet;
  rule->GetStyleSheet(*getter_AddRefs(ruleSheet));
  if (this != ruleSheet) {
    return NS_ERROR_INVALID_ARG;
  }

  mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, PR_TRUE);
  
  result = WillDirty();
  NS_ENSURE_SUCCESS(result, result);

  result = aGroup->DeleteStyleRuleAt(aIndex);
  NS_ENSURE_SUCCESS(result, result);
  
  rule->SetStyleSheet(nsnull);
  
  DidDirty();

  if (mDocument) {
    mDocument->StyleRuleRemoved(this, rule);
  }

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 2024 of file nsCSSStyleSheet.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Implements nsICSSStyleSheet.

Definition at line 1426 of file nsCSSStyleSheet.cpp.

{
  if (!mRuleProcessors)
    return NS_ERROR_FAILURE;
  return mRuleProcessors->RemoveElement(aProcessor)
           ? NS_OK
           : NS_ERROR_FAILURE;
}

Definition at line 1870 of file nsCSSStyleSheet.cpp.

{
  if (! mInner) {
    return NS_ERROR_NOT_INITIALIZED;
  }
  if (1 < mInner->mSheets.Count()) {
    nsCSSStyleSheetInner* clone = mInner->CloneFor(this);
    if (clone) {
      mInner->RemoveSheet(this);
      mInner = clone;
    }
    else {
      return NS_ERROR_OUT_OF_MEMORY;
    }
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsCSSStyleSheet::GetApplicable ( PRBool aApplicable) const [virtual]

Whether the sheet is applicable.

A sheet that is not applicable should never be inserted into a style set. A sheet may not be applicable for a variety of reasons including being disabled and being incomplete.

Implements nsIStyleSheet.

Definition at line 1515 of file nsCSSStyleSheet.cpp.

{
  aApplicable = !mDisabled && mInner && mInner->mComplete;
  return NS_OK;
}

Here is the caller graph for this function:

NS_IMETHODIMP nsCSSStyleSheet::GetBaseURI ( nsIURI **  aBaseURI) const [virtual]

Implements nsIStyleSheet.

Definition at line 1469 of file nsCSSStyleSheet.cpp.

{
  NS_IF_ADDREF(*aBaseURI = (mInner ? mInner->mBaseURI.get() : nsnull));
  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsCSSStyleSheet::GetComplete ( PRBool aComplete) const [virtual]

Whether the sheet is complete.

Implements nsIStyleSheet.

Definition at line 1528 of file nsCSSStyleSheet.cpp.

{
  aComplete = mInner && mInner->mComplete;
  return NS_OK;
}

Implements nsICSSStyleSheet.

Definition at line 1592 of file nsCSSStyleSheet.cpp.

{
  *aOwnerRule = mOwnerRule;
  NS_IF_ADDREF(*aOwnerRule);
  return NS_OK;
}

Implements nsIStyleSheet.

Definition at line 1559 of file nsCSSStyleSheet.cpp.

{
  aDocument = mDocument;
  NS_IF_ADDREF(aDocument);
  return NS_OK;
}

Implements nsIStyleSheet.

Definition at line 1551 of file nsCSSStyleSheet.cpp.

{
  aParent = mParent;
  NS_IF_ADDREF(aParent);
  return NS_OK;
}
NS_IMETHODIMP nsCSSStyleSheet::GetSheetURI ( nsIURI **  aSheetURI) const [virtual]

Implements nsIStyleSheet.

Definition at line 1462 of file nsCSSStyleSheet.cpp.

{
  NS_IF_ADDREF(*aSheetURI = (mInner ? mInner->mSheetURI.get() : nsnull));
  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsCSSStyleSheet::GetStyleRuleAt ( PRInt32  aIndex,
nsICSSRule *&  aRule 
) const [virtual]

Implements nsICSSStyleSheet.

Definition at line 1803 of file nsCSSStyleSheet.cpp.

{
  // Important: If this function is ever made scriptable, we must add
  // a security check here. See GetCSSRules below for an example.
  nsresult result = NS_ERROR_ILLEGAL_VALUE;

  if (mInner && mInner->mOrderedRules) {
    aRule = (nsICSSRule*)(mInner->mOrderedRules->ElementAt(aIndex));
    if (nsnull != aRule) {
      result = NS_OK;
    }
  }
  else {
    aRule = nsnull;
  }
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsCSSStyleSheet::GetStyleSheetAt ( PRInt32  aIndex,
nsICSSStyleSheet *&  aSheet 
) const [virtual]

Implements nsICSSStyleSheet.

Definition at line 1848 of file nsCSSStyleSheet.cpp.

{
  // XXX Ughh...an O(n^2) method for doing iteration. Again, we hope
  // that this isn't done too often. If it is, we need to change the
  // underlying storage mechanism
  aSheet = nsnull;

  if (mFirstChild) {
    const nsCSSStyleSheet* child = mFirstChild;
    while ((child) && (0 != aIndex)) {
      --aIndex;
      child = child->mNext;
    }
    
    aSheet = (nsICSSStyleSheet*)child;
    NS_IF_ADDREF(aSheet);
  }

  return NS_OK;
}
NS_IMETHODIMP nsCSSStyleSheet::GetTitle ( nsString aTitle) const [virtual]

Implements nsIStyleSheet.

Definition at line 2116 of file nsCSSStyleSheet.cpp.

{
  aTitle = mTitle;
  return NS_OK;
}
NS_IMETHODIMP nsCSSStyleSheet::GetType ( nsString aType) const [virtual]

Implements nsIStyleSheet.

Definition at line 1483 of file nsCSSStyleSheet.cpp.

{
  aType.AssignLiteral("text/css");
  return NS_OK;
}
unsigned long nsIDOMCSSStyleSheet::insertRule ( in DOMString  rule,
in unsigned long  index 
) raises (DOMException) [inherited]
NS_IMETHODIMP nsCSSStyleSheet::InsertRuleIntoGroup ( const nsAString &  aRule,
nsICSSGroupRule aGroup,
PRUint32  aIndex,
PRUint32 _retval 
) [virtual]

Implements nsICSSStyleSheet.

Definition at line 2465 of file nsCSSStyleSheet.cpp.

{
  nsresult result;
  NS_ASSERTION(mInner && mInner->mComplete,
               "No inserting into an incomplete sheet!");
  // check that the group actually belongs to this sheet!
  nsCOMPtr<nsIStyleSheet> groupSheet;
  aGroup->GetStyleSheet(*getter_AddRefs(groupSheet));
  if (this != groupSheet) {
    return NS_ERROR_INVALID_ARG;
  }

  if (aRule.IsEmpty()) {
    // Nothing to do here
    return NS_OK;
  }
  
  // Hold strong ref to the CSSLoader in case the document update
  // kills the document
  nsCOMPtr<nsICSSLoader> loader;
  if (mDocument) {
    loader = mDocument->CSSLoader();
    NS_ASSERTION(loader, "Document with no CSS loader!");
  }

  nsCOMPtr<nsICSSParser> css;
  if (loader) {
    result = loader->GetParserFor(this, getter_AddRefs(css));
  }
  else {
    result = NS_NewCSSParser(getter_AddRefs(css));
    if (css) {
      css->SetStyleSheet(this);
    }
  }
  NS_ENSURE_SUCCESS(result, result);

  // parse and grab the rule
  mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, PR_TRUE);

  result = WillDirty();
  NS_ENSURE_SUCCESS(result, result);

  nsCOMPtr<nsISupportsArray> rules;
  result = css->ParseRule(aRule, mInner->mSheetURI, mInner->mBaseURI,
                          getter_AddRefs(rules));
  NS_ENSURE_SUCCESS(result, result);

  PRUint32 rulecount = 0;
  rules->Count(&rulecount);
  if (rulecount == 0) {
    // Since we know aRule was not an empty string, just throw
    return NS_ERROR_DOM_SYNTAX_ERR;
  }

  PRUint32 counter;
  nsCOMPtr<nsICSSRule> rule;
  for (counter = 0; counter < rulecount; counter++) {
    // Only rulesets are allowed in a group as of CSS2
    PRInt32 type = nsICSSRule::UNKNOWN_RULE;
    rule = dont_AddRef((nsICSSRule*)rules->ElementAt(counter));
    rule->GetType(type);
    if (type != nsICSSRule::STYLE_RULE) {
      return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
    }
  }
  
  result = aGroup->InsertStyleRulesAt(aIndex, rules);
  NS_ENSURE_SUCCESS(result, result);
  DidDirty();
  for (counter = 0; counter < rulecount; counter++) {
    rule = dont_AddRef((nsICSSRule*)rules->ElementAt(counter));
  
    if (mDocument) {
      mDocument->StyleRuleAdded(this, rule);
    }
  }

  if (loader) {
    loader->RecycleParser(css);
  }

  *_retval = aIndex;
  return NS_OK;
}

Here is the call graph for this function:

Implements nsICSSStyleSheet.

Definition at line 1670 of file nsCSSStyleSheet.cpp.

{
  NS_PRECONDITION(nsnull != aSheet, "null arg");

  nsresult result = WillDirty();

  if (NS_SUCCEEDED(result)) {
    NS_ADDREF(aSheet);
    nsCSSStyleSheet* sheet = (nsCSSStyleSheet*)aSheet;
    nsCSSStyleSheet* child = mFirstChild;

    if (aIndex && child) {
      while ((0 < --aIndex) && child->mNext) {
        child = child->mNext;
      }
      sheet->mNext = child->mNext;
      child->mNext = sheet;
    }
    else {
      sheet->mNext = mFirstChild;
      mFirstChild = sheet; 
    }

    // This is not reference counted. Our parent tells us when
    // it's going away.
    sheet->mParent = this;
    sheet->mDocument = mDocument;
    DidDirty();
  }
  return result;
}

Here is the call graph for this function:

NS_IMETHODIMP nsCSSStyleSheet::IsModified ( PRBool aSheetModified) const [virtual]

Implements nsICSSStyleSheet.

Definition at line 2031 of file nsCSSStyleSheet.cpp.

{
  *aSheetModified = mDirty;
  return NS_OK;
}
virtual nsCSSStyleSheet::NS_HIDDEN_ ( nsXMLNameSpaceMap ) const [virtual]

Implements nsICSSStyleSheet.

nsCSSStyleSheet::NS_IMETHOD_ ( PRBool  ) const [virtual]

Implements nsIStyleSheet.

nsCSSStyleSheet::NS_IMETHOD_ ( PRBool  ) const [virtual]

Implements nsIStyleSheet.

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

Implements nsICSSStyleSheet.

Definition at line 1703 of file nsCSSStyleSheet.cpp.

{
  NS_PRECONDITION(nsnull != aRule, "null arg");

  if (NS_SUCCEEDED(WillDirty())) {
    if (! mInner->mOrderedRules) {
      NS_NewISupportsArray(&(mInner->mOrderedRules));
    }
    if (mInner->mOrderedRules) {
      mInner->mOrderedRules->InsertElementAt(aRule, 0);
      aRule->SetStyleSheet(this);
      DidDirty();

      PRInt32 type = nsICSSRule::UNKNOWN_RULE;
      aRule->GetType(type);
      if (nsICSSRule::NAMESPACE_RULE == type) {
        // no api to prepend a namespace (ugh), release old ones and re-create them all
        mInner->RebuildNameSpaces();
      }
    }
  }
  return NS_OK;
}

Here is the call graph for this function:

Implements nsICSSStyleSheet.

Definition at line 2555 of file nsCSSStyleSheet.cpp.

{
  nsresult result;
  NS_PRECONDITION(mInner && mInner->mComplete,
                  "No replacing in an incomplete sheet!");
#ifdef DEBUG
  {
    nsCOMPtr<nsIStyleSheet> groupSheet;
    aGroup->GetStyleSheet(*getter_AddRefs(groupSheet));
    NS_ASSERTION(this == groupSheet, "group doesn't belong to this sheet");
  }
#endif
  result = WillDirty();
  NS_ENSURE_SUCCESS(result, result);

  result = aGroup->ReplaceStyleRule(aOld, aNew);
  DidDirty();
  return result;
}

Here is the call graph for this function:

Implements nsICSSStyleSheet.

Definition at line 1764 of file nsCSSStyleSheet.cpp.

{
  NS_PRECONDITION(mInner->mOrderedRules, "can't have old rule");
  NS_PRECONDITION(mInner && mInner->mComplete,
                  "No replacing in an incomplete sheet!");

  if (NS_SUCCEEDED(WillDirty())) {
    PRInt32 index = mInner->mOrderedRules->IndexOf(aOld);
    NS_ENSURE_TRUE(index != -1, NS_ERROR_UNEXPECTED);
    mInner->mOrderedRules->ReplaceElementAt(aNew, index);

    aNew->SetStyleSheet(this);
    aOld->SetStyleSheet(nsnull);
    DidDirty();
#ifdef DEBUG
    PRInt32 type = nsICSSRule::UNKNOWN_RULE;
    aNew->GetType(type);
    NS_ASSERTION(nsICSSRule::NAMESPACE_RULE != type, "not yet implemented");
    aOld->GetType(type);
    NS_ASSERTION(nsICSSRule::NAMESPACE_RULE != type, "not yet implemented");
#endif
  }
  return NS_OK;
}

Here is the call graph for this function:

Implements nsIStyleSheet.

Definition at line 1535 of file nsCSSStyleSheet.cpp.

{
  if (!mInner)
    return NS_ERROR_UNEXPECTED;
  NS_ASSERTION(!mDirty, "Can't set a dirty sheet complete!");
  mInner->mComplete = PR_TRUE;
  if (mDocument && !mDisabled) {
    // Let the document know
    mDocument->BeginUpdate(UPDATE_STYLE);
    mDocument->SetStyleSheetApplicableState(this, PR_TRUE);
    mDocument->EndUpdate(UPDATE_STYLE);
  }
  return NS_OK;
}

Here is the call graph for this function:

Set the stylesheet to be enabled.

This may or may not make it applicable.

Implements nsIStyleSheet.

Definition at line 1522 of file nsCSSStyleSheet.cpp.

{
  return nsCSSStyleSheet::SetDisabled(!aEnabled);
}

Implements nsICSSStyleSheet.

Definition at line 1500 of file nsCSSStyleSheet.cpp.

{
  mMedia = aMedia;
  return NS_OK;
}

Implements nsICSSStyleSheet.

Definition at line 2038 of file nsCSSStyleSheet.cpp.

{
  mDirty = aModified;
  return NS_OK;
}

Implements nsICSSStyleSheet.

Definition at line 1585 of file nsCSSStyleSheet.cpp.

{ // not ref counted
  mOwnerRule = aOwnerRule;
  return NS_OK;
}

Implements nsIStyleSheet.

Definition at line 1567 of file nsCSSStyleSheet.cpp.

{ // not ref counted
  mDocument = aDocument;
  // Now set the same document on all our child sheets....
  for (nsCSSStyleSheet* child = mFirstChild; child; child = child->mNext) {
    child->SetOwningDocument(aDocument);
  }
  return NS_OK;
}

Implements nsICSSStyleSheet.

Definition at line 1578 of file nsCSSStyleSheet.cpp.

{ // not ref counted
  mOwningNode = aOwningNode;
  return NS_OK;
}
NS_IMETHODIMP nsCSSStyleSheet::SetTitle ( const nsAString &  aTitle) [virtual]

Implements nsICSSStyleSheet.

Definition at line 1476 of file nsCSSStyleSheet.cpp.

{
  mTitle = aTitle;
  return NS_OK;
}
NS_IMETHODIMP nsCSSStyleSheet::SetURIs ( nsIURI aSheetURI,
nsIURI aBaseURI 
) [virtual]

SetURIs must be called on all sheets before parsing into them.

SetURIs may only be called while the sheet is 1) incomplete and 2) has no rules in it

Implements nsICSSStyleSheet.

Definition at line 1437 of file nsCSSStyleSheet.cpp.

{
  return SetURIs18(aSheetURI, nsnull, aBaseURI);
}

Here is the call graph for this function:

NS_IMETHODIMP nsCSSStyleSheet::SetURIs18 ( nsIURI aSheetURI,
nsIURI aOriginalSheetURI,
nsIURI aBaseURI 
) [virtual]

Implements nsICSSStyleSheet_MOZILLA_1_8_BRANCH.

Definition at line 1443 of file nsCSSStyleSheet.cpp.

{
  NS_PRECONDITION(aSheetURI && aBaseURI, "null ptr");

  if (! mInner) {
    return NS_ERROR_OUT_OF_MEMORY;
  }

  NS_ASSERTION(!mInner->mOrderedRules && !mInner->mComplete,
               "Can't call SetURL on sheets that are complete or have rules");

  mInner->mSheetURI = aSheetURI;
  mInner->mOriginalSheetURI = aOriginalSheetURI;
  mInner->mBaseURI = aBaseURI;
  return NS_OK;
}

Here is the caller graph for this function:

NS_IMETHODIMP nsCSSStyleSheet::StyleRuleCount ( PRInt32 aCount) const [virtual]

Implements nsICSSStyleSheet.

Definition at line 1790 of file nsCSSStyleSheet.cpp.

{
  aCount = 0;
  if (mInner && mInner->mOrderedRules) {
    PRUint32 cnt;
    nsresult rv = ((nsCSSStyleSheet*)this)->mInner->mOrderedRules->Count(&cnt);      // XXX bogus cast -- this method should not be const
    aCount = (PRInt32)cnt;
    return rv;
  }
  return NS_OK;
}

Implements nsICSSStyleSheet.

Definition at line 1831 of file nsCSSStyleSheet.cpp.

{
  // XXX Far from an ideal way to do this, but the hope is that
  // it won't be done too often. If it is, we might want to 
  // consider storing the children in an array.
  aCount = 0;

  const nsCSSStyleSheet* child = mFirstChild;
  while (child) {
    aCount++;
    child = child->mNext;
  }

  return NS_OK;
}

Implements nsICSSLoaderObserver.

Definition at line 2578 of file nsCSSStyleSheet.cpp.

{
#ifdef DEBUG
  nsCOMPtr<nsIStyleSheet> styleSheet(do_QueryInterface(aSheet));
  NS_ASSERTION(styleSheet, "Sheet not implementing nsIStyleSheet!\n");
  nsCOMPtr<nsIStyleSheet> parentSheet;
  aSheet->GetParentSheet(*getter_AddRefs(parentSheet));
  nsCOMPtr<nsIStyleSheet> thisSheet;
  QueryInterface(NS_GET_IID(nsIStyleSheet), getter_AddRefs(thisSheet));
  NS_ASSERTION(thisSheet == parentSheet, "We are being notified of a sheet load for a sheet that is not our child!\n");
#endif
  
  if (mDocument && aNotify) {
    nsCOMPtr<nsICSSImportRule> ownerRule;
    aSheet->GetOwnerRule(getter_AddRefs(ownerRule));
    
    mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, PR_TRUE);

    // XXXldb @import rules shouldn't even implement nsIStyleRule (but
    // they do)!
    nsCOMPtr<nsIStyleRule> styleRule(do_QueryInterface(ownerRule));
    
    mDocument->StyleRuleAdded(this, styleRule);
  }

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 2013 of file nsCSSStyleSheet.cpp.

{
  if (mInner && !mInner->mComplete) {
    // Do nothing
    return NS_OK;
  }
  
  return EnsureUniqueInner();
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

PRBool CascadeSheetRulesInto ( nsICSSStyleSheet aSheet,
void aData 
) [friend]

Definition at line 3838 of file nsCSSStyleSheet.cpp.

{
  nsCSSStyleSheet*  sheet = NS_STATIC_CAST(nsCSSStyleSheet*, aSheet);
  CascadeEnumData* data = NS_STATIC_CAST(CascadeEnumData*, aData);
  PRBool bSheetApplicable = PR_TRUE;
  sheet->GetApplicable(bSheetApplicable);

  if (bSheetApplicable && sheet->UseForMedium(data->mPresContext)) {
    nsCSSStyleSheet* child = sheet->mFirstChild;
    while (child) {
      CascadeSheetRulesInto(child, data);
      child = child->mNext;
    }

    if (sheet->mInner && sheet->mInner->mOrderedRules) {
      sheet->mInner->mOrderedRules->EnumerateForwards(InsertRuleByWeight, data);
    }
  }
  return PR_TRUE;
}
friend class nsMediaList [friend]

Definition at line 203 of file nsCSSStyleSheet.h.


Member Data Documentation

Definition at line 56 of file nsIDOMCSSStyleSheet.idl.

Definition at line 56 of file nsIDOMStyleSheet.idl.

readonly attribute DOMString nsIDOMStyleSheet::href [inherited]

Definition at line 59 of file nsIDOMStyleSheet.idl.

Definition at line 197 of file nsCSSStyleSheet.h.

Definition at line 196 of file nsCSSStyleSheet.h.

Definition at line 194 of file nsCSSStyleSheet.h.

Definition at line 61 of file nsIDOMStyleSheet.idl.

Definition at line 187 of file nsCSSStyleSheet.h.

Definition at line 192 of file nsCSSStyleSheet.h.

Definition at line 199 of file nsCSSStyleSheet.h.

Definition at line 186 of file nsCSSStyleSheet.h.

Definition at line 188 of file nsCSSStyleSheet.h.

Definition at line 190 of file nsCSSStyleSheet.h.

Definition at line 195 of file nsCSSStyleSheet.h.

Definition at line 189 of file nsCSSStyleSheet.h.

Definition at line 193 of file nsCSSStyleSheet.h.

nsAutoVoidArray* nsCSSStyleSheet::mRuleProcessors [protected]

Definition at line 201 of file nsCSSStyleSheet.h.

Definition at line 185 of file nsCSSStyleSheet.h.

Definition at line 57 of file nsIDOMStyleSheet.idl.

Definition at line 55 of file nsIDOMCSSStyleSheet.idl.

Definition at line 58 of file nsIDOMStyleSheet.idl.

readonly attribute DOMString nsIDOMStyleSheet::title [inherited]

Definition at line 60 of file nsIDOMStyleSheet.idl.

readonly attribute DOMString nsIDOMStyleSheet::type [inherited]

Definition at line 55 of file nsIDOMStyleSheet.idl.


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