1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozAutoDocUpdate_h_
8 #define mozAutoDocUpdate_h_
10 #include "nsContentUtils.h" // For AddScriptBlocker() and RemoveScriptBlocker().
11 #include "mozilla/dom/Document.h"
12 #include "nsIDocumentObserver.h"
15 * Helper class to automatically handle batching of document updates. This
16 * class will call BeginUpdate on construction and EndUpdate on destruction on
17 * the given document with the given update type. The document could be null,
18 * in which case no updates will be called. The constructor also takes a
19 * boolean that can be set to false to prevent notifications.
21 class MOZ_STACK_CLASS mozAutoDocUpdate
{
23 mozAutoDocUpdate(mozilla::dom::Document
* aDocument
, bool aNotify
)
24 : mDocument(aNotify
? aDocument
: nullptr) {
26 mDocument
->BeginUpdate();
28 nsContentUtils::AddScriptBlocker();
34 mDocument
->EndUpdate();
36 nsContentUtils::RemoveScriptBlocker();
41 RefPtr
<mozilla::dom::Document
> mDocument
;
44 #define MOZ_AUTO_DOC_UPDATE_PASTE2(tok, line) tok##line
45 #define MOZ_AUTO_DOC_UPDATE_PASTE(tok, line) \
46 MOZ_AUTO_DOC_UPDATE_PASTE2(tok, line)
47 #define MOZ_AUTO_DOC_UPDATE(doc, notify) \
48 mozAutoDocUpdate MOZ_AUTO_DOC_UPDATE_PASTE(_autoDocUpdater_, __LINE__)( \