LCOV - app.info - content/base/src/mozAutoDocUpdate.h

LCOV - code coverage report
| Current view: | directory - content/base/src - mozAutoDocUpdate.h (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 22 | 12 | 54.5 %
| Date: | 2012-06-02 | Functions: | 4 | 2 | 50.0 %

           1                 : /* ***** BEGIN LICENSE BLOCK *****
           2                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
           3                 :  *
           4                 :  * The contents of this file are subject to the Mozilla Public License Version
           5                 :  * 1.1 (the "License"); you may not use this file except in compliance with
           6                 :  * the License. You may obtain a copy of the License at
           7                 :  * http://www.mozilla.org/MPL/
           8                 :  *
           9                 :  * Software distributed under the License is distributed on an "AS IS" basis,
          10                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
          11                 :  * for the specific language governing rights and limitations under the
          12                 :  * License.
          13                 :  *
          14                 :  * The Original Code is mozilla.org code.
          15                 :  *
          16                 :  * The Initial Developer of the Original Code is
          17                 :  * Boris Zbarsky <bzbarsky@mit.edu>.
          18                 :  * Portions created by the Initial Developer are Copyright (C) 2003
          19                 :  * the Initial Developer. All Rights Reserved.
          20                 :  *
          21                 :  * Contributor(s):
          22                 :  *
          23                 :  * Alternatively, the contents of this file may be used under the terms of
          24                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
          25                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
          26                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
          27                 :  * of those above. If you wish to allow use of your version of this file only
          28                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
          29                 :  * use your version of this file under the terms of the MPL, indicate your
          30                 :  * decision by deleting the provisions above and replace them with the notice
          31                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
          32                 :  * the provisions above, a recipient may use your version of this file under
          33                 :  * the terms of any one of the MPL, the GPL or the LGPL.
          34                 :  *
          35                 :  * ***** END LICENSE BLOCK ***** */
          36                 :
          37                 : #include "nsContentUtils.h"
          38                 : #include "nsIDocument.h"
          39                 : #include "nsIDocumentObserver.h"
          40                 :
          41                 : /**
          42                 :  * Helper class to automatically handle batching of document updates.  This
          43                 :  * class will call BeginUpdate on construction and EndUpdate on destruction on
          44                 :  * the given document with the given update type.  The document could be null,
          45                 :  * in which case no updates will be called.  The constructor also takes a
          46                 :  * boolean that can be set to false to prevent notifications.
          47                 :  */
          48                 : class NS_STACK_CLASS mozAutoDocUpdate
          49                 : {
          50                 : public:
          51          203323 :   mozAutoDocUpdate(nsIDocument* aDocument, nsUpdateType aUpdateType,
          52                 :                    bool aNotify) :
          53                 :     mDocument(aNotify ? aDocument : nsnull),
          54          203323 :     mUpdateType(aUpdateType)
          55                 :   {
          56          203323 :     if (mDocument) {
          57            5969 :       mDocument->BeginUpdate(mUpdateType);
          58                 :     }
          59                 :     else {
          60          197354 :       nsContentUtils::AddScriptBlocker();
          61                 :     }
          62          203323 :   }
          63                 :
          64          203323 :   ~mozAutoDocUpdate()
          65          203323 :   {
          66          203323 :     if (mDocument) {
          67            5969 :       mDocument->EndUpdate(mUpdateType);
          68                 :     }
          69                 :     else {
          70          197354 :       nsContentUtils::RemoveScriptBlocker();
          71                 :     }
          72          203323 :   }
          73                 :
          74                 : private:
          75                 :   nsCOMPtr<nsIDocument> mDocument;
          76                 :   nsUpdateType mUpdateType;
          77                 : };
          78                 :
          79                 : #define MOZ_AUTO_DOC_UPDATE_PASTE2(tok,line) tok##line
          80                 : #define MOZ_AUTO_DOC_UPDATE_PASTE(tok,line) \
          81                 :   MOZ_AUTO_DOC_UPDATE_PASTE2(tok,line)
          82                 : #define MOZ_AUTO_DOC_UPDATE(doc,type,notify) \
          83                 :   mozAutoDocUpdate MOZ_AUTO_DOC_UPDATE_PASTE(_autoDocUpdater_, __LINE__) \
          84                 :   (doc,type,notify)
          85                 :
          86                 :
          87                 : /**
          88                 :  * Creates an update batch only under certain conditions.
          89                 :  * Use this rather than mozAutoDocUpdate when you expect inner updates
          90                 :  * to notify but you don't always want to spec cycles creating a batch.
          91                 :  * This is needed to avoid having this batch always create a blocker,
          92                 :  * but then have inner mozAutoDocUpdate call the last EndUpdate before.
          93                 :  * we remove that blocker. See bug 423269.
          94                 :  */
          95                 : class NS_STACK_CLASS mozAutoDocConditionalContentUpdateBatch
          96                 : {
          97                 : public:
          98               0 :   mozAutoDocConditionalContentUpdateBatch(nsIDocument* aDocument,
          99                 :                                           bool aNotify) :
         100               0 :     mDocument(aNotify ? aDocument : nsnull)
         101                 :   {
         102               0 :     if (mDocument) {
         103               0 :       mDocument->BeginUpdate(UPDATE_CONTENT_MODEL);
         104                 :     }
         105               0 :   }
         106                 :
         107               0 :   ~mozAutoDocConditionalContentUpdateBatch()
         108               0 :   {
         109               0 :     if (mDocument) {
         110               0 :       mDocument->EndUpdate(UPDATE_CONTENT_MODEL);
         111                 :     }
         112               0 :   }
         113                 :
         114                 : private:
         115                 :   nsCOMPtr<nsIDocument> mDocument;
         116                 : };

Generated by: LCOV version 1.7