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.)

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

mercurial