content/base/src/mozAutoDocUpdate.h

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #ifndef mozAutoDocUpdate_h_
     6 #define mozAutoDocUpdate_h_
     8 #include "nsContentUtils.h" // For AddScriptBlocker() and RemoveScriptBlocker().
     9 #include "nsIDocument.h"
    10 #include "nsIDocumentObserver.h"
    12 /**
    13  * Helper class to automatically handle batching of document updates.  This
    14  * class will call BeginUpdate on construction and EndUpdate on destruction on
    15  * the given document with the given update type.  The document could be null,
    16  * in which case no updates will be called.  The constructor also takes a
    17  * boolean that can be set to false to prevent notifications.
    18  */
    19 class MOZ_STACK_CLASS mozAutoDocUpdate
    20 {
    21 public:
    22   mozAutoDocUpdate(nsIDocument* aDocument, nsUpdateType aUpdateType,
    23                    bool aNotify) :
    24     mDocument(aNotify ? aDocument : nullptr),
    25     mUpdateType(aUpdateType)
    26   {
    27     if (mDocument) {
    28       mDocument->BeginUpdate(mUpdateType);
    29     }
    30     else {
    31       nsContentUtils::AddScriptBlocker();
    32     }
    33   }
    35   ~mozAutoDocUpdate()
    36   {
    37     if (mDocument) {
    38       mDocument->EndUpdate(mUpdateType);
    39     }
    40     else {
    41       nsContentUtils::RemoveScriptBlocker();
    42     }
    43   }
    45 private:
    46   nsCOMPtr<nsIDocument> mDocument;
    47   nsUpdateType mUpdateType;
    48 };
    50 #define MOZ_AUTO_DOC_UPDATE_PASTE2(tok,line) tok##line
    51 #define MOZ_AUTO_DOC_UPDATE_PASTE(tok,line) \
    52   MOZ_AUTO_DOC_UPDATE_PASTE2(tok,line)
    53 #define MOZ_AUTO_DOC_UPDATE(doc,type,notify) \
    54   mozAutoDocUpdate MOZ_AUTO_DOC_UPDATE_PASTE(_autoDocUpdater_, __LINE__) \
    55   (doc,type,notify)
    58 /**
    59  * Creates an update batch only under certain conditions.
    60  * Use this rather than mozAutoDocUpdate when you expect inner updates
    61  * to notify but you don't always want to spec cycles creating a batch.
    62  * This is needed to avoid having this batch always create a blocker,
    63  * but then have inner mozAutoDocUpdate call the last EndUpdate before.
    64  * we remove that blocker. See bug 423269.
    65  */
    66 class MOZ_STACK_CLASS mozAutoDocConditionalContentUpdateBatch
    67 {
    68 public:
    69   mozAutoDocConditionalContentUpdateBatch(nsIDocument* aDocument,
    70                                           bool aNotify) :
    71     mDocument(aNotify ? aDocument : nullptr)
    72   {
    73     if (mDocument) {
    74       mDocument->BeginUpdate(UPDATE_CONTENT_MODEL);
    75     }
    76   }
    78   ~mozAutoDocConditionalContentUpdateBatch()
    79   {
    80     if (mDocument) {
    81       mDocument->EndUpdate(UPDATE_CONTENT_MODEL);
    82     }
    83   }
    85 private:
    86   nsCOMPtr<nsIDocument> mDocument;
    87 };
    89 #endif

mercurial