Bug 1700051: part 35) Reduce accessibility of `mSoftText.mDOMMapping` to `private...
[gecko.git] / dom / base / mozAutoDocUpdate.h
blob0b210c3dda26e61d62a5cf34ac719d483409f2b0
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"
14 /**
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 {
22 public:
23 mozAutoDocUpdate(mozilla::dom::Document* aDocument, bool aNotify)
24 : mDocument(aNotify ? aDocument : nullptr) {
25 if (mDocument) {
26 mDocument->BeginUpdate();
27 } else {
28 nsContentUtils::AddScriptBlocker();
32 ~mozAutoDocUpdate() {
33 if (mDocument) {
34 mDocument->EndUpdate();
35 } else {
36 nsContentUtils::RemoveScriptBlocker();
40 private:
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__)( \
49 doc, notify)
51 #endif