/src/mozilla-central/dom/base/mozAutoDocUpdate.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #ifndef mozAutoDocUpdate_h_ |
8 | | #define mozAutoDocUpdate_h_ |
9 | | |
10 | | #include "nsContentUtils.h" // For AddScriptBlocker() and RemoveScriptBlocker(). |
11 | | #include "nsIDocument.h" |
12 | | #include "nsIDocumentObserver.h" |
13 | | |
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. |
20 | | */ |
21 | | class MOZ_STACK_CLASS mozAutoDocUpdate |
22 | | { |
23 | | public: |
24 | | mozAutoDocUpdate(nsIDocument* aDocument, bool aNotify) |
25 | | : mDocument(aNotify ? aDocument : nullptr) |
26 | 0 | { |
27 | 0 | if (mDocument) { |
28 | 0 | mDocument->BeginUpdate(); |
29 | 0 | } else { |
30 | 0 | nsContentUtils::AddScriptBlocker(); |
31 | 0 | } |
32 | 0 | } |
33 | | |
34 | | ~mozAutoDocUpdate() |
35 | 0 | { |
36 | 0 | if (mDocument) { |
37 | 0 | mDocument->EndUpdate(); |
38 | 0 | } else { |
39 | 0 | nsContentUtils::RemoveScriptBlocker(); |
40 | 0 | } |
41 | 0 | } |
42 | | |
43 | | private: |
44 | | nsCOMPtr<nsIDocument> mDocument; |
45 | | }; |
46 | | |
47 | 0 | #define MOZ_AUTO_DOC_UPDATE_PASTE2(tok,line) tok##line |
48 | | #define MOZ_AUTO_DOC_UPDATE_PASTE(tok,line) \ |
49 | 0 | MOZ_AUTO_DOC_UPDATE_PASTE2(tok,line) |
50 | | #define MOZ_AUTO_DOC_UPDATE(doc,notify) \ |
51 | 0 | mozAutoDocUpdate MOZ_AUTO_DOC_UPDATE_PASTE(_autoDocUpdater_, __LINE__) \ |
52 | 0 | (doc,notify) |
53 | | |
54 | | |
55 | | #endif |