Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Private Attributes
nsXMLPrettyPrinter Class Reference

#include <nsXMLPrettyPrinter.h>

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

List of all members.

Public Member Functions

 nsXMLPrettyPrinter ()
virtual ~nsXMLPrettyPrinter ()
virtual NS_DECL_ISUPPORTS void BeginUpdate (nsIDocument *aDocument, nsUpdateType aUpdateType)
 Notify that a content model update is beginning.
virtual void EndUpdate (nsIDocument *aDocument, nsUpdateType aUpdateType)
 Notify that a content model update is finished.
virtual void AttributeChanged (nsIDocument *aDocument, nsIContent *aContent, PRInt32 aNameSpaceID, nsIAtom *aAttribute, PRInt32 aModType)
 Notification that the content model has changed.
virtual void ContentAppended (nsIDocument *aDocument, nsIContent *aContainer, PRInt32 aNewIndexInContainer)
 Notifcation that the content model has had data appended to the given content object.
virtual void ContentInserted (nsIDocument *aDocument, nsIContent *aContainer, nsIContent *aChild, PRInt32 aIndexInContainer)
 Notification that content has been inserted.
virtual void ContentRemoved (nsIDocument *aDocument, nsIContent *aContainer, nsIContent *aChild, PRInt32 aIndexInContainer)
 Content has just been removed.
virtual void DocumentWillBeDestroyed (nsIDocument *aDocument)
 The document is in the process of being destroyed.
nsresult PrettyPrint (nsIDocument *aDocument)
 This will prettyprint the document if the document is loaded in a displayed window.
virtual void BeginLoad (nsIDocument *aDocument)=0
 Notify the observer that a document load is beginning.
virtual void EndLoad (nsIDocument *aDocument)=0
 Notify the observer that a document load has finished.
virtual void BeginReflow (nsIDocument *aDocument, nsIPresShell *aShell)=0
 Notify the observer that the document is being reflowed in the given presentation shell.
virtual void EndReflow (nsIDocument *aDocument, nsIPresShell *aShell)=0
 Notify the observer that the document is done being reflowed in the given presentation shell.
virtual void CharacterDataChanged (nsIDocument *aDocument, nsIContent *aContent, PRBool aAppend)=0
 Notification that the content model has changed.
virtual void ContentStatesChanged (nsIDocument *aDocument, nsIContent *aContent1, nsIContent *aContent2, PRInt32 aStateMask)=0
 Notification that the state of a content node has changed.
virtual void StyleSheetAdded (nsIDocument *aDocument, nsIStyleSheet *aStyleSheet, PRBool aDocumentSheet)=0
 A StyleSheet has just been added to the document.
virtual void StyleSheetRemoved (nsIDocument *aDocument, nsIStyleSheet *aStyleSheet, PRBool aDocumentSheet)=0
 A StyleSheet has just been removed from the document.
virtual void StyleSheetApplicableStateChanged (nsIDocument *aDocument, nsIStyleSheet *aStyleSheet, PRBool aApplicable)=0
 A StyleSheet has just changed its applicable state.
virtual void StyleRuleChanged (nsIDocument *aDocument, nsIStyleSheet *aStyleSheet, nsIStyleRule *aOldStyleRule, nsIStyleRule *aNewStyleRule)=0
 A StyleRule has just been modified within a style sheet.
virtual void StyleRuleAdded (nsIDocument *aDocument, nsIStyleSheet *aStyleSheet, nsIStyleRule *aStyleRule)=0
 A StyleRule has just been added to a style sheet.
virtual void StyleRuleRemoved (nsIDocument *aDocument, nsIStyleSheet *aStyleSheet, nsIStyleRule *aStyleRule)=0
 A StyleRule has just been removed from a style sheet.

Private Member Functions

void MaybeUnhook (nsIContent *aContent)
 Signals for unhooking by setting mUnhookPending if the node changed is non-anonymous content.

Private Attributes

nsIDocumentmDocument
PRUint32 mUpdateDepth
PRPackedBool mUnhookPending

Detailed Description

Definition at line 46 of file nsXMLPrettyPrinter.h.


Constructor & Destructor Documentation

Definition at line 68 of file nsXMLPrettyPrinter.cpp.

{
    NS_ASSERTION(!mDocument, "we shouldn't be referencing the document still");
}

Member Function Documentation

void nsXMLPrettyPrinter::AttributeChanged ( nsIDocument aDocument,
nsIContent aContent,
PRInt32  aNameSpaceID,
nsIAtom aAttribute,
PRInt32  aModType 
) [virtual]

Notification that the content model has changed.

This method is called automatically by content objects when an attribute's value has changed (therefore there is normally no need to invoke this method directly). The notification is passed to any IDocumentObservers document observers.

Parameters:
aDocumentThe document being observed
aContentthe piece of content whose attribute changed
aAttributethe atom name of the attribute
aModTypeWhether or not the attribute was added, changed, or removed. The constants are defined in nsIDOMMutationEvent.h.

Implements nsIDocumentObserver.

Definition at line 241 of file nsXMLPrettyPrinter.cpp.

{
    MaybeUnhook(aContent);
}

Here is the call graph for this function:

virtual void nsIDocumentObserver::BeginLoad ( nsIDocument aDocument) [pure virtual, inherited]

Notify the observer that a document load is beginning.

Implemented in PresShell.

virtual void nsIDocumentObserver::BeginReflow ( nsIDocument aDocument,
nsIPresShell aShell 
) [pure virtual, inherited]

Notify the observer that the document is being reflowed in the given presentation shell.

void nsXMLPrettyPrinter::BeginUpdate ( nsIDocument aDocument,
nsUpdateType  aUpdateType 
) [virtual]

Notify that a content model update is beginning.

This call can be nested.

Implements nsIDocumentObserver.

Definition at line 208 of file nsXMLPrettyPrinter.cpp.

{
    mUpdateDepth++;
}
virtual void nsIDocumentObserver::CharacterDataChanged ( nsIDocument aDocument,
nsIContent aContent,
PRBool  aAppend 
) [pure virtual, inherited]

Notification that the content model has changed.

This method is called automatically by content objects when their state is changed (therefore there is normally no need to invoke this method directly). The notification is passed to any IDocumentObservers. The notification is passed on to all of the document observers.

This notification is not sent when a piece of content is added/removed from the document (the other notifications are used for that).

Parameters:
aDocumentThe document being observed
aContentthe piece of content that changed
aAppendWhether the change was an append

Implemented in PresShell.

void nsXMLPrettyPrinter::ContentAppended ( nsIDocument aDocument,
nsIContent aContainer,
PRInt32  aNewIndexInContainer 
) [virtual]

Notifcation that the content model has had data appended to the given content object.

This method is called automatically by the content container objects when a new content object is appended to the container (therefore there is normally no need to invoke this method directly). The notification is passed on to all of the document observers.

Parameters:
aDocumentThe document being observed
aContainerthe container that had a new child appended
aNewIndexInContainerthe index in the container of the first new child

Implements nsIDocumentObserver.

Definition at line 251 of file nsXMLPrettyPrinter.cpp.

{
    MaybeUnhook(aContainer);
}

Here is the call graph for this function:

void nsXMLPrettyPrinter::ContentInserted ( nsIDocument aDocument,
nsIContent aContainer,
nsIContent aChild,
PRInt32  aIndexInContainer 
) [virtual]

Notification that content has been inserted.

This method is called automatically by the content container objects when a new content object is inserted in the container (therefore there is normally no need to invoke this method directly). The notification is passed on to all of the document observers.

Parameters:
aDocumentThe document being observed
aContainerthe container that now contains aChild
aChildthe child that was inserted
aIndexInContainerthe index of the child in the container

Implements nsIDocumentObserver.

Definition at line 259 of file nsXMLPrettyPrinter.cpp.

{
    MaybeUnhook(aContainer);
}

Here is the call graph for this function:

void nsXMLPrettyPrinter::ContentRemoved ( nsIDocument aDocument,
nsIContent aContainer,
nsIContent aChild,
PRInt32  aIndexInContainer 
) [virtual]

Content has just been removed.

This method is called automatically by content container objects when a content object has just been removed from the container (therefore there is normally no need to invoke this method directly). The notification is passed on to all of the document observers.

Parameters:
aDocumentThe document being observed
aContainerthe container that had a child removed
aChildthe child that was just removed
aIndexInContainerthe index of the child in the container before it was removed

Implements nsIDocumentObserver.

Definition at line 268 of file nsXMLPrettyPrinter.cpp.

{
    MaybeUnhook(aContainer);
}

Here is the call graph for this function:

virtual void nsIDocumentObserver::ContentStatesChanged ( nsIDocument aDocument,
nsIContent aContent1,
nsIContent aContent2,
PRInt32  aStateMask 
) [pure virtual, inherited]

Notification that the state of a content node has changed.

(ie: gained or lost focus, became active or hovered over) This method is called automatically by content objects when their state is changed (therefore there is normally no need to invoke this method directly). The notification is passed to any IDocumentObservers. The notification is passed on to all of the document observers.

This notification is not sent when a piece of content is added/removed from the document or the content itself changed (the other notifications are used for that).

The optional second content node is to allow optimization of the case where state moves from one node to another (as is likely for :focus and :hover)

Either content node may be nsnull, but not both

Parameters:
aDocumentThe document being observed
aContent1the piece of content that changed
aContent2optional second piece of content that changed

Implemented in PresShell, and nsTreeContentView.

The document is in the process of being destroyed.

This method is called automatically during document destruction.

Parameters:
aDocumentThe document being observed

Implements nsIDocumentObserver.

Definition at line 277 of file nsXMLPrettyPrinter.cpp.

virtual void nsIDocumentObserver::EndLoad ( nsIDocument aDocument) [pure virtual, inherited]

Notify the observer that a document load has finished.

Note that the associated reflow of the document will be done before EndLoad is invoked, not after.

Implemented in PresShell.

virtual void nsIDocumentObserver::EndReflow ( nsIDocument aDocument,
nsIPresShell aShell 
) [pure virtual, inherited]

Notify the observer that the document is done being reflowed in the given presentation shell.

void nsXMLPrettyPrinter::EndUpdate ( nsIDocument aDocument,
nsUpdateType  aUpdateType 
) [virtual]

Notify that a content model update is finished.

This call can be nested.

Implements nsIDocumentObserver.

Definition at line 215 of file nsXMLPrettyPrinter.cpp.

{
    mUpdateDepth--;

    // Only remove the binding once we're outside all updates. This protects us
    // from nasty surprices of elements being removed from the document in the
    // midst of setting attributes etc.
    if (mUnhookPending && mUpdateDepth == 0) {
        mDocument->RemoveObserver(this);
        nsCOMPtr<nsIDOMDocument> document = do_QueryInterface(mDocument);
        nsCOMPtr<nsIDOMElement> rootElem;
        document->GetDocumentElement(getter_AddRefs(rootElem));

        if (rootElem) {
            nsCOMPtr<nsIDOMDocumentXBL> xblDoc = do_QueryInterface(mDocument);
            xblDoc->RemoveBinding(rootElem,
                                  NS_LITERAL_STRING("chrome://global/content/xml/XMLPrettyPrint.xml#prettyprint"));
        }

        mDocument = nsnull;

        NS_RELEASE_THIS();
    }
}

Here is the call graph for this function:

void nsXMLPrettyPrinter::MaybeUnhook ( nsIContent aContent) [private]

Signals for unhooking by setting mUnhookPending if the node changed is non-anonymous content.

Parameters:
aContentcontent that has changed

Definition at line 196 of file nsXMLPrettyPrinter.cpp.

{
    // If there either aContent is null (the document-node was modified) or
    // there isn't a binding parent we know it's non-anonymous content.
    if (!aContent || !aContent->GetBindingParent()) {
        mUnhookPending = PR_TRUE;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

This will prettyprint the document if the document is loaded in a displayed window.

Parameters:
aDocumentdocument to prettyprint

Definition at line 74 of file nsXMLPrettyPrinter.cpp.

{
    // Check for iframe with display:none. Such iframes don't have presshells
    if (!aDocument->GetNumberOfShells()) {
        return NS_OK;
    }

    // check if we're in an invisible iframe
    nsCOMPtr<nsIDOMWindowInternal> internalWin = do_QueryInterface(aDocument->GetScriptGlobalObject());
    nsCOMPtr<nsIDOMElement> frameElem;
    if (internalWin) {
        internalWin->GetFrameElement(getter_AddRefs(frameElem));
    }

    if (frameElem) {
        nsCOMPtr<nsIDOMCSSStyleDeclaration> computedStyle;
        nsCOMPtr<nsIDOMDocument> frameOwnerDoc;
        frameElem->GetOwnerDocument(getter_AddRefs(frameOwnerDoc));
        nsCOMPtr<nsIDOMDocumentView> docView = do_QueryInterface(frameOwnerDoc);
        if (docView) {
            nsCOMPtr<nsIDOMAbstractView> defaultView;
            docView->GetDefaultView(getter_AddRefs(defaultView));
            nsCOMPtr<nsIDOMViewCSS> defaultCSSView =
                do_QueryInterface(defaultView);
            if (defaultCSSView) {
                defaultCSSView->GetComputedStyle(frameElem,
                                                 EmptyString(),
                                                 getter_AddRefs(computedStyle));
            }
        }

        if (computedStyle) {
            nsAutoString visibility;
            computedStyle->GetPropertyValue(NS_LITERAL_STRING("visibility"),
                                            visibility);
            if (!visibility.EqualsLiteral("visible")) {

                return NS_OK;
            }
        }
    }

    // check the pref
    if (!nsContentUtils::GetBoolPref("layout.xml.prettyprint", PR_TRUE)) {
        return NS_OK;
    }

    // Ok, we should prettyprint. Let's do it!
    nsresult rv = NS_OK;

    // Load the XSLT
    nsCOMPtr<nsIURI> xslUri;
    rv = NS_NewURI(getter_AddRefs(xslUri),
                   NS_LITERAL_CSTRING("chrome://global/content/xml/XMLPrettyPrint.xsl"));
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIChannel> channel;
    rv = NS_NewChannel(getter_AddRefs(channel), xslUri, nsnull, nsnull);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIDOMDocument> xslDocument;
    nsCOMPtr<nsISyncLoadDOMService> loader =
       do_GetService("@mozilla.org/content/syncload-dom-service;1", &rv);
    NS_ENSURE_SUCCESS(rv, rv);
    rv = loader->LoadLocalDocument(channel, nsnull, getter_AddRefs(xslDocument));
    NS_ENSURE_SUCCESS(rv, rv);

    // Transform the document
    nsCOMPtr<nsIXSLTProcessor> transformer =
        do_CreateInstance("@mozilla.org/document-transformer;1?type=xslt", &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = transformer->ImportStylesheet(xslDocument);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIDOMDocumentFragment> resultFragment;
    nsCOMPtr<nsIDOMDocument> sourceDocument = do_QueryInterface(aDocument);
    rv = transformer->TransformToFragment(sourceDocument, sourceDocument,
                                          getter_AddRefs(resultFragment));
    NS_ENSURE_SUCCESS(rv, rv);

    // Add the binding
    nsCOMPtr<nsIDOMDocumentXBL> xblDoc = do_QueryInterface(aDocument);
    NS_ASSERTION(xblDoc, "xml document doesn't implement nsIDOMDocumentXBL");
    NS_ENSURE_TRUE(xblDoc, NS_ERROR_FAILURE);

    nsCOMPtr<nsIDOMDocument> dummy;
    xblDoc->LoadBindingDocument(NS_LITERAL_STRING("chrome://global/content/xml/XMLPrettyPrint.xml"),
                                getter_AddRefs(dummy));

    nsCOMPtr<nsIDOMElement> rootElem;
    sourceDocument->GetDocumentElement(getter_AddRefs(rootElem));
    NS_ENSURE_TRUE(rootElem, NS_ERROR_UNEXPECTED);

    rv = xblDoc->AddBinding(rootElem,
                            NS_LITERAL_STRING("chrome://global/content/xml/XMLPrettyPrint.xml#prettyprint"));
    NS_ENSURE_SUCCESS(rv, rv);

    // Hand the result document to the binding
    nsCOMPtr<nsIObserver> binding;
    nsCOMPtr<nsIContent> rootCont = do_QueryInterface(rootElem);
    NS_ASSERTION(rootCont, "Element doesn't implement nsIContent");
    aDocument->BindingManager()->GetBindingImplementation(rootCont,
                                              NS_GET_IID(nsIObserver),
                                              (void**)getter_AddRefs(binding));
    NS_ASSERTION(binding, "Prettyprint binding doesn't implement nsIObserver");
    NS_ENSURE_TRUE(binding, NS_ERROR_UNEXPECTED);
    
    rv = binding->Observe(resultFragment, "prettyprint-dom-created",
                          EmptyString().get());
    NS_ENSURE_SUCCESS(rv, rv);

    // Observe the document so we know when to switch to "normal" view
    aDocument->AddObserver(this);
    mDocument = aDocument;

    NS_ADDREF_THIS();

    return NS_OK;
}

Here is the call graph for this function:

virtual void nsIDocumentObserver::StyleRuleAdded ( nsIDocument aDocument,
nsIStyleSheet aStyleSheet,
nsIStyleRule aStyleRule 
) [pure virtual, inherited]

A StyleRule has just been added to a style sheet.

This method is called automatically when the rule gets added to the sheet. The style sheet passes this notification to the document. The notification is passed on to all of the document observers.

Parameters:
aDocumentThe document being observed
aStyleSheetthe StyleSheet that has been modified
aStyleRulethe rule that was added

Implemented in PresShell.

virtual void nsIDocumentObserver::StyleRuleChanged ( nsIDocument aDocument,
nsIStyleSheet aStyleSheet,
nsIStyleRule aOldStyleRule,
nsIStyleRule aNewStyleRule 
) [pure virtual, inherited]

A StyleRule has just been modified within a style sheet.

This method is called automatically when the rule gets modified. The style sheet passes this notification to the document. The notification is passed on to all of the document observers.

Since nsIStyleRule objects are immutable, there is a new object replacing the old one. However, the use of this method (rather than StyleRuleAdded and StyleRuleRemoved) implies that the new rule matches the same elements and has the same priority (weight, origin, specificity) as the old one. (However, if it is a CSS style rule, there may be a change in whether it has an important rule.)

Parameters:
aDocumentThe document being observed
aStyleSheetthe StyleSheet that contians the rule
aOldStyleRuleThe rule being removed. This rule may not be fully valid anymore -- however, it can still be used for pointer comparison and |QueryInterface|.
aNewStyleRuleThe rule being added.

Implemented in PresShell.

virtual void nsIDocumentObserver::StyleRuleRemoved ( nsIDocument aDocument,
nsIStyleSheet aStyleSheet,
nsIStyleRule aStyleRule 
) [pure virtual, inherited]

A StyleRule has just been removed from a style sheet.

This method is called automatically when the rule gets removed from the sheet. The style sheet passes this notification to the document. The notification is passed on to all of the document observers.

Parameters:
aDocumentThe document being observed
aStyleSheetthe StyleSheet that has been modified
aStyleRulethe rule that was removed

Implemented in PresShell.

virtual void nsIDocumentObserver::StyleSheetAdded ( nsIDocument aDocument,
nsIStyleSheet aStyleSheet,
PRBool  aDocumentSheet 
) [pure virtual, inherited]

A StyleSheet has just been added to the document.

This method is called automatically when a StyleSheet gets added to the document, even if the stylesheet is not applicable. The notification is passed on to all of the document observers.

Parameters:
aDocumentThe document being observed
aStyleSheetthe StyleSheet that has been added
aDocumentSheetTrue if sheet is in document's style sheet list, false if sheet is not (i.e., UA or user sheet)

Implemented in PresShell, and nsDOMStyleSheetList.

virtual void nsIDocumentObserver::StyleSheetApplicableStateChanged ( nsIDocument aDocument,
nsIStyleSheet aStyleSheet,
PRBool  aApplicable 
) [pure virtual, inherited]

A StyleSheet has just changed its applicable state.

This method is called automatically when the applicable state of a StyleSheet gets changed. The style sheet passes this notification to the document. The notification is passed on to all of the document observers.

Parameters:
aDocumentThe document being observed
aStyleSheetthe StyleSheet that has changed state
aApplicablePR_TRUE if the sheet is applicable, PR_FALSE if it is not applicable

Implemented in PresShell.

virtual void nsIDocumentObserver::StyleSheetRemoved ( nsIDocument aDocument,
nsIStyleSheet aStyleSheet,
PRBool  aDocumentSheet 
) [pure virtual, inherited]

A StyleSheet has just been removed from the document.

This method is called automatically when a StyleSheet gets removed from the document, even if the stylesheet is not applicable. The notification is passed on to all of the document observers.

Parameters:
aDocumentThe document being observed
aStyleSheetthe StyleSheet that has been removed
aDocumentSheetTrue if sheet is in document's style sheet list, false if sheet is not (i.e., UA or user sheet)

Implemented in PresShell, and nsDOMStyleSheetList.


Member Data Documentation

Definition at line 87 of file nsXMLPrettyPrinter.h.

Definition at line 89 of file nsXMLPrettyPrinter.h.

Definition at line 88 of file nsXMLPrettyPrinter.h.


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