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"
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
22 mozAutoDocUpdate(nsIDocument
* aDocument
, nsUpdateType aUpdateType
,
24 mDocument(aNotify
? aDocument
: nullptr),
25 mUpdateType(aUpdateType
)
28 mDocument
->BeginUpdate(mUpdateType
);
31 nsContentUtils::AddScriptBlocker();
38 mDocument
->EndUpdate(mUpdateType
);
41 nsContentUtils::RemoveScriptBlocker();
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__) \
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
69 mozAutoDocConditionalContentUpdateBatch(nsIDocument
* aDocument
,
71 mDocument(aNotify
? aDocument
: nullptr)
74 mDocument
->BeginUpdate(UPDATE_CONTENT_MODEL
);
78 ~mozAutoDocConditionalContentUpdateBatch()
81 mDocument
->EndUpdate(UPDATE_CONTENT_MODEL
);
86 nsCOMPtr
<nsIDocument
> mDocument
;