content/xml/document/src/nsXMLPrettyPrinter.h
author David Anderson <danderson@mozilla.com>
Mon, 21 May 2012 14:40:04 -0700
changeset 106274 80e4ab0d24bc64ceaa7693ab5def36faffde7a40
parent 105276 8cfeba5239a9e4f20c462d6fb20421b4e4e7c735
parent 94484 f4157e8c410708d76703f19e4dfb61859bfe32d8
child 106724 22fe5c9f4433b25951d0471f44f1cf82f43b26c8
permissions -rw-r--r--
Merge from mozilla-central.

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
#ifndef nsXMLPrettyPrinter_h__
#define nsXMLPrettyPrinter_h__

#include "nsStubDocumentObserver.h"
#include "nsIDocument.h"
#include "nsCOMPtr.h"

class nsXMLPrettyPrinter : public nsStubDocumentObserver
{
public:
    nsXMLPrettyPrinter();
    virtual ~nsXMLPrettyPrinter();

    NS_DECL_ISUPPORTS

    // nsIMutationObserver
    NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
    NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
    NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
    NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
    NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED

    /**
     * This will prettyprint the document if the document is loaded in a
     * displayed window.
     *
     * @param aDocument  document to prettyprint
     * @param [out] aDidPrettyPrint if true, and error not returned, actually
     *              went ahead with prettyprinting the document.
     */
    nsresult PrettyPrint(nsIDocument* aDocument, bool* aDidPrettyPrint);

    /**
     * Unhook the prettyprinter
     */
    void Unhook();
private:
    /**
     * Signals for unhooking by setting mUnhookPending if the node changed is
     * non-anonymous content.
     *
     * @param aContent  content that has changed
     */
    void MaybeUnhook(nsIContent* aContent);

    nsIDocument* mDocument; //weak. Set as long as we're observing the document
    PRUint32 mUpdateDepth;
    bool mUnhookPending;
};

nsresult NS_NewXMLPrettyPrinter(nsXMLPrettyPrinter** aPrinter);

#endif //nsXMLPrettyPrinter_h__