LCOV - code coverage report
Current view: top level - dom/base - mozAutoDocUpdate.h (source / functions) Hit Total Coverage
Test: output.info Lines: 24 24 100.0 %
Date: 2017-07-14 16:53:18 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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        6427 :   mozAutoDocUpdate(nsIDocument* aDocument, nsUpdateType aUpdateType,
      25        6427 :                    bool aNotify) :
      26             :     mDocument(aNotify ? aDocument : nullptr),
      27        6427 :     mUpdateType(aUpdateType)
      28             :   {
      29        6427 :     if (mDocument) {
      30         655 :       mDocument->BeginUpdate(mUpdateType);
      31             :     }
      32             :     else {
      33        5772 :       nsContentUtils::AddScriptBlocker();
      34             :     }
      35        6427 :   }
      36             : 
      37        6427 :   ~mozAutoDocUpdate()
      38        6427 :   {
      39        6427 :     if (mDocument) {
      40         655 :       mDocument->EndUpdate(mUpdateType);
      41             :     }
      42             :     else {
      43        5772 :       nsContentUtils::RemoveScriptBlocker();
      44             :     }
      45        6427 :   }
      46             : 
      47             : private:
      48             :   nsCOMPtr<nsIDocument> mDocument;
      49             :   nsUpdateType mUpdateType;
      50             : };
      51             : 
      52             : #define MOZ_AUTO_DOC_UPDATE_PASTE2(tok,line) tok##line
      53             : #define MOZ_AUTO_DOC_UPDATE_PASTE(tok,line) \
      54             :   MOZ_AUTO_DOC_UPDATE_PASTE2(tok,line)
      55             : #define MOZ_AUTO_DOC_UPDATE(doc,type,notify) \
      56             :   mozAutoDocUpdate MOZ_AUTO_DOC_UPDATE_PASTE(_autoDocUpdater_, __LINE__) \
      57             :   (doc,type,notify)
      58             : 
      59             : 
      60             : /**
      61             :  * Creates an update batch only under certain conditions.
      62             :  * Use this rather than mozAutoDocUpdate when you expect inner updates
      63             :  * to notify but you don't always want to spec cycles creating a batch.
      64             :  * This is needed to avoid having this batch always create a blocker,
      65             :  * but then have inner mozAutoDocUpdate call the last EndUpdate before.
      66             :  * we remove that blocker. See bug 423269.
      67             :  */
      68             : class MOZ_STACK_CLASS mozAutoDocConditionalContentUpdateBatch
      69             : {
      70             : public:
      71           9 :   mozAutoDocConditionalContentUpdateBatch(nsIDocument* aDocument,
      72           9 :                                           bool aNotify) :
      73           9 :     mDocument(aNotify ? aDocument : nullptr)
      74             :   {
      75           9 :     if (mDocument) {
      76           9 :       mDocument->BeginUpdate(UPDATE_CONTENT_MODEL);
      77             :     }
      78           9 :   }
      79             : 
      80           9 :   ~mozAutoDocConditionalContentUpdateBatch()
      81           9 :   {
      82           9 :     if (mDocument) {
      83           9 :       mDocument->EndUpdate(UPDATE_CONTENT_MODEL);
      84             :     }
      85           9 :   }
      86             : 
      87             : private:
      88             :   nsCOMPtr<nsIDocument> mDocument;
      89             : };
      90             : 
      91             : #endif

Generated by: LCOV version 1.13