Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes
nsStyleLinkElement Class Reference

#include <nsStyleLinkElement.h>

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

List of all members.

Public Member Functions

 nsStyleLinkElement ()
virtual ~nsStyleLinkElement ()
NS_IMETHOD QueryInterface (REFNSIID aIID, void **aInstancePtr)=0
NS_DECL_NSIDOMLINKSTYLE NS_IMETHOD SetStyleSheet (nsIStyleSheet *aStyleSheet)
 Used to make the association between a style sheet and the element that linked it to the document.
NS_IMETHOD GetStyleSheet (nsIStyleSheet *&aStyleSheet)
 Used to obtain the style sheet linked in by this element.
NS_IMETHOD InitStyleLinkElement (nsIParser *aParser, PRBool aDontLoadStyle)
 Initialize the stylesheet linking element.
NS_IMETHOD UpdateStyleSheet (nsIDocument *aOldDocument=nsnull, nsICSSLoaderObserver *aObserver=nsnull)
 Tells this element to update the stylesheet.
NS_IMETHOD SetEnableUpdates (PRBool aEnableUpdates)
 Tells this element wether to update the stylesheet when the element's properties change.
NS_IMETHOD GetCharset (nsAString &aCharset)
 Gets the charset that the element claims the style sheet is in.
virtual void SetLineNumber (PRUint32 aLineNumber)

Static Public Member Functions

static void ParseLinkTypes (const nsAString &aTypes, nsStringArray &aResult)

Public Attributes

readonly attribute nsIDOMStyleSheet sheet

Protected Member Functions

virtual void GetStyleSheetURL (PRBool *aIsInline, nsIURI **aURI)=0
virtual void GetStyleSheetInfo (nsAString &aTitle, nsAString &aType, nsAString &aMedia, PRBool *aIsAlternate)=0

Protected Attributes

nsCOMPtr< nsIStyleSheetmStyleSheet
nsCOMPtr< nsIParsermParser
PRPackedBool mDontLoadStyle
PRPackedBool mUpdatesEnabled
PRUint32 mLineNumber

Detailed Description

Definition at line 51 of file nsStyleLinkElement.h.


Constructor & Destructor Documentation

Definition at line 64 of file nsStyleLinkElement.cpp.

{
  nsCOMPtr<nsICSSStyleSheet> cssSheet = do_QueryInterface(mStyleSheet);
  if (cssSheet) {
    cssSheet->SetOwningNode(nsnull);
  }
}

Here is the call graph for this function:


Member Function Documentation

NS_IMETHODIMP nsStyleLinkElement::GetCharset ( nsAString &  aCharset) [virtual]

Gets the charset that the element claims the style sheet is in.

Parameters:
aCharsetthe charset

Implements nsIStyleSheetLinkingElement.

Reimplemented in nsXMLStylesheetPI.

Definition at line 137 of file nsStyleLinkElement.cpp.

{
  // descendants have to implement this themselves
  return NS_ERROR_NOT_IMPLEMENTED;
}

Used to obtain the style sheet linked in by this element.

Parameters:
aStyleSheetout parameter that returns the style sheet associated with this element.

Implements nsIStyleSheetLinkingElement.

Definition at line 95 of file nsStyleLinkElement.cpp.

{
  aStyleSheet = mStyleSheet;
  NS_IF_ADDREF(aStyleSheet);

  return NS_OK;
}
virtual void nsStyleLinkElement::GetStyleSheetInfo ( nsAString &  aTitle,
nsAString &  aType,
nsAString &  aMedia,
PRBool aIsAlternate 
) [protected, pure virtual]

Implemented in nsHTMLLinkElement, nsHTMLStyleElement, nsSVGStyleElement, and nsXMLStylesheetPI.

Here is the caller graph for this function:

virtual void nsStyleLinkElement::GetStyleSheetURL ( PRBool aIsInline,
nsIURI **  aURI 
) [protected, pure virtual]

Implemented in nsHTMLLinkElement, nsHTMLStyleElement, nsSVGStyleElement, and nsXMLStylesheetPI.

Here is the caller graph for this function:

NS_IMETHODIMP nsStyleLinkElement::InitStyleLinkElement ( nsIParser aParser,
PRBool  aDontLoadStyle 
) [virtual]

Initialize the stylesheet linking element.

This method passes in a parser that the element blocks if the stylesheet is a stylesheet that should be loaded with the parser blocked. If aDontLoadStyle is true the element will ignore the first modification to the element that would cause a stylesheet to be loaded. Subsequent modifications to the element will not be ignored.

Implements nsIStyleSheetLinkingElement.

Definition at line 104 of file nsStyleLinkElement.cpp.

{
  mParser = aParser;
  mDontLoadStyle = aDontLoadStyle;

  return NS_OK;
}
void nsStyleLinkElement::ParseLinkTypes ( const nsAString &  aTypes,
nsStringArray &  aResult 
) [static]

Definition at line 149 of file nsStyleLinkElement.cpp.

{
  nsAString::const_iterator start, done;
  aTypes.BeginReading(start);
  aTypes.EndReading(done);
  if (start == done)
    return;

  nsAString::const_iterator current(start);
  PRBool inString = !nsCRT::IsAsciiSpace(*current);
  nsAutoString subString;

  while (current != done) {
    if (nsCRT::IsAsciiSpace(*current)) {
      if (inString) {
        ToLowerCase(Substring(start, current), subString);
        aResult.AppendString(subString);
        inString = PR_FALSE;
      }
    }
    else {
      if (!inString) {
        start = current;
        inString = PR_TRUE;
      }
    }
    ++current;
  }
  if (inString) {
    ToLowerCase(Substring(start, current), subString);
    aResult.AppendString(subString);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHOD nsStyleLinkElement::QueryInterface ( REFNSIID  aIID,
void **  aInstancePtr 
) [pure virtual]

Here is the caller graph for this function:

Tells this element wether to update the stylesheet when the element's properties change.

Parameters:
aEnableUpdatesupdate on changes or not.

Implements nsIStyleSheetLinkingElement.

Definition at line 129 of file nsStyleLinkElement.cpp.

{
  mUpdatesEnabled = aEnableUpdates;

  return NS_OK;
}

Here is the caller graph for this function:

void nsStyleLinkElement::SetLineNumber ( PRUint32  aLineNumber) [virtual]

Implements nsIStyleSheetLinkingElement.

Definition at line 144 of file nsStyleLinkElement.cpp.

{
  mLineNumber = aLineNumber;
}

Used to make the association between a style sheet and the element that linked it to the document.

Parameters:
aStyleSheetthe style sheet associated with this element.

Implements nsIStyleSheetLinkingElement.

Definition at line 73 of file nsStyleLinkElement.cpp.

{
  nsCOMPtr<nsICSSStyleSheet> cssSheet = do_QueryInterface(mStyleSheet);
  if (cssSheet) {
    cssSheet->SetOwningNode(nsnull);
  }

  mStyleSheet = aStyleSheet;
  cssSheet = do_QueryInterface(mStyleSheet);
  if (cssSheet) {
    nsCOMPtr<nsIDOMNode> node;
    CallQueryInterface(this,
                       NS_STATIC_CAST(nsIDOMNode**, getter_AddRefs(node)));
    if (node) {
      cssSheet->SetOwningNode(node);
    }
  }
    
  return NS_OK;
}

Here is the call graph for this function:

Tells this element to update the stylesheet.

Parameters:
aOldDocumentthe document that this element was part of (nsnull if we're not moving the element from one document to another).
aObserverobserver to notify once the stylesheet is loaded. It might be notified before the function returns.

Implements nsIStyleSheetLinkingElement.

Definition at line 191 of file nsStyleLinkElement.cpp.

{
  if (mStyleSheet && aOldDocument) {
    // We're removing the link element from the document, unload the
    // stylesheet.  We want to do this even if updates are disabled, since
    // otherwise a sheet with a stale linking element pointer will be hanging
    // around -- not good!
    aOldDocument->BeginUpdate(UPDATE_STYLE);
    aOldDocument->RemoveStyleSheet(mStyleSheet);
    aOldDocument->EndUpdate(UPDATE_STYLE);
    mStyleSheet = nsnull;
  }

  if (mDontLoadStyle || !mUpdatesEnabled) {
    return NS_OK;
  }

  // Keep a strong ref to the parser so it's still around when we pass it
  // to the CSS loader. Release strong ref in mParser so we don't hang on
  // to the parser once we start the load or if we fail to load the
  // stylesheet.
  nsCOMPtr<nsIParser> parser = mParser;
  mParser = nsnull;

  nsCOMPtr<nsIContent> thisContent;
  QueryInterface(NS_GET_IID(nsIContent), getter_AddRefs(thisContent));

  NS_ENSURE_TRUE(thisContent, NS_ERROR_FAILURE);

  nsCOMPtr<nsIDocument> doc = thisContent->GetDocument();

  if (!doc) {
    return NS_OK;
  }

  nsCOMPtr<nsIURI> uri;
  PRBool isInline;
  GetStyleSheetURL(&isInline, getter_AddRefs(uri));

  if (mStyleSheet && !isInline && uri) {
    nsCOMPtr<nsIURI> oldURI;

    mStyleSheet->GetSheetURI(getter_AddRefs(oldURI));
    if (oldURI) {
      PRBool equal;
      nsresult rv = oldURI->Equals(uri, &equal);
      if (NS_SUCCEEDED(rv) && equal) {
        return NS_OK; // We already loaded this stylesheet
      }
    }
  }

  if (mStyleSheet) {
    doc->BeginUpdate(UPDATE_STYLE);
    doc->RemoveStyleSheet(mStyleSheet);
    doc->EndUpdate(UPDATE_STYLE);
    mStyleSheet = nsnull;
  }

  if (!uri && !isInline) {
    return NS_OK; // If href is empty and this is not inline style then just bail
  }

  nsAutoString title, type, media;
  PRBool isAlternate;

  GetStyleSheetInfo(title, type, media, &isAlternate);

  if (!type.LowerCaseEqualsLiteral("text/css")) {
    return NS_OK;
  }

  PRBool blockParser = kBlockByDefault;
  if (isAlternate) {
    blockParser = PR_FALSE;
  }

  /* NOTE: no longer honoring the important keyword to indicate blocking
           as it is proprietary and unnecessary since all non-alternate 
           will block the parser now  -mja
    if (-1 != linkTypes.IndexOf("important")) {
      blockParser = PR_TRUE;
    }
  */

  if (!isAlternate && !title.IsEmpty()) {  // possibly preferred sheet
    nsAutoString prefStyle;
    doc->GetHeaderData(nsHTMLAtoms::headerDefaultStyle, prefStyle);

    if (prefStyle.IsEmpty()) {
      doc->SetHeaderData(nsHTMLAtoms::headerDefaultStyle, title);
    }
  }

  PRBool doneLoading;
  nsresult rv = NS_OK;
  if (isInline) {
    PRUint32 count = thisContent->GetChildCount();

    nsAutoString content;

    PRUint32 i;
    for (i = 0; i < count; ++i) {
      nsIContent *node = thisContent->GetChildAt(i);
      nsCOMPtr<nsIDOMText> tc = do_QueryInterface(node);
      // Ignore nodes that are not DOMText.
      if (!tc) {
        nsCOMPtr<nsIDOMComment> comment = do_QueryInterface(node);
        if (comment)
          // Skip a comment
          continue;
        break;
      }

      nsAutoString tcString;
      tc->GetData(tcString);
      content.Append(tcString);
    }

    // Use of the stream will be done before parsing returns.  So it will go
    // out of scope before |content| does.
    nsCOMPtr<nsIUnicharInputStream> uin;
    rv = NS_NewStringUnicharInputStream(getter_AddRefs(uin), &content,
                                        PR_FALSE);
    if (NS_FAILED(rv)) {
      return rv;
    }

    // Now that we have a url and a unicode input stream, parse the
    // style sheet.
    rv = doc->CSSLoader()->
      LoadInlineStyle(thisContent, uin, mLineNumber, title, media,
                      ((blockParser) ? parser.get() : nsnull),
                      doneLoading, aObserver);
  }
  else {
    rv = doc->CSSLoader()->
      LoadStyleLink(thisContent, uri, title, media,
                    ((blockParser) ? parser.get() : nsnull),
                    doneLoading, aObserver);
  }

  if (NS_SUCCEEDED(rv) && blockParser && !doneLoading) {
    rv = NS_ERROR_HTMLPARSER_BLOCK;
  }

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 86 of file nsStyleLinkElement.h.

Definition at line 88 of file nsStyleLinkElement.h.

Definition at line 85 of file nsStyleLinkElement.h.

Definition at line 84 of file nsStyleLinkElement.h.

Definition at line 87 of file nsStyleLinkElement.h.

Definition at line 45 of file nsIDOMLinkStyle.idl.


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