tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

mozAutoDocUpdate.h (1724B)


      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 "mozilla/dom/Document.h"
     11 #include "nsContentUtils.h"  // For AddScriptBlocker() and RemoveScriptBlocker().
     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 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();
     29    }
     30  }
     31 
     32  ~mozAutoDocUpdate() {
     33    if (mDocument) {
     34      mDocument->EndUpdate();
     35    } else {
     36      nsContentUtils::RemoveScriptBlocker();
     37    }
     38  }
     39 
     40 private:
     41  RefPtr<mozilla::dom::Document> mDocument;
     42 };
     43 
     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)
     50 
     51 #endif