Bumping gaia.json for 8 gaia revision(s) a=gaia-bump
[gecko.git] / dom / base / mozAutoDocUpdate.h
blob7bedb4830b154b59232cb009914f31104f2c0101
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.
19 class MOZ_STACK_CLASS mozAutoDocUpdate
21 public:
22 mozAutoDocUpdate(nsIDocument* aDocument, nsUpdateType aUpdateType,
23 bool aNotify) :
24 mDocument(aNotify ? aDocument : nullptr),
25 mUpdateType(aUpdateType)
27 if (mDocument) {
28 mDocument->BeginUpdate(mUpdateType);
30 else {
31 nsContentUtils::AddScriptBlocker();
35 ~mozAutoDocUpdate()
37 if (mDocument) {
38 mDocument->EndUpdate(mUpdateType);
40 else {
41 nsContentUtils::RemoveScriptBlocker();
45 private:
46 nsCOMPtr<nsIDocument> mDocument;
47 nsUpdateType mUpdateType;
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.
66 class MOZ_STACK_CLASS mozAutoDocConditionalContentUpdateBatch
68 public:
69 mozAutoDocConditionalContentUpdateBatch(nsIDocument* aDocument,
70 bool aNotify) :
71 mDocument(aNotify ? aDocument : nullptr)
73 if (mDocument) {
74 mDocument->BeginUpdate(UPDATE_CONTENT_MODEL);
78 ~mozAutoDocConditionalContentUpdateBatch()
80 if (mDocument) {
81 mDocument->EndUpdate(UPDATE_CONTENT_MODEL);
85 private:
86 nsCOMPtr<nsIDocument> mDocument;
89 #endif