LCOV - code coverage report
Current view: directory - editor/libeditor/base - nsStyleSheetTxns.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 75 3 4.0 %
Date: 2012-06-02 Functions: 21 2 9.5 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Netscape Communications Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 1998-1999
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *
      24                 :  * Alternatively, the contents of this file may be used under the terms of
      25                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      26                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      28                 :  * of those above. If you wish to allow use of your version of this file only
      29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      30                 :  * use your version of this file under the terms of the MPL, indicate your
      31                 :  * decision by deleting the provisions above and replace them with the notice
      32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      33                 :  * the provisions above, a recipient may use your version of this file under
      34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      35                 :  *
      36                 :  * ***** END LICENSE BLOCK ***** */
      37                 : 
      38                 : 
      39                 : #include "nsEditor.h"
      40                 : 
      41                 : #include "nsCSSStyleSheet.h"
      42                 : #include "nsIDocument.h"
      43                 : #include "nsIDocumentObserver.h"
      44                 : #include "nsISelectionController.h"
      45                 : 
      46                 : 
      47                 : #include "nsStyleSheetTxns.h"
      48                 : 
      49                 : static void
      50               0 : AddStyleSheet(nsIEditor* aEditor, nsIStyleSheet* aSheet)
      51                 : {
      52               0 :   nsCOMPtr<nsIDOMDocument> domDoc;
      53               0 :   aEditor->GetDocument(getter_AddRefs(domDoc));
      54               0 :   nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
      55               0 :   if (doc) {
      56               0 :     doc->BeginUpdate(UPDATE_STYLE);
      57               0 :     doc->AddStyleSheet(aSheet);
      58               0 :     doc->EndUpdate(UPDATE_STYLE);
      59                 :   }
      60               0 : }
      61                 : 
      62                 : static void
      63               0 : RemoveStyleSheet(nsIEditor *aEditor, nsIStyleSheet *aSheet)
      64                 : {
      65               0 :   nsCOMPtr<nsIDOMDocument> domDoc;
      66               0 :   aEditor->GetDocument(getter_AddRefs(domDoc));
      67               0 :   nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
      68               0 :   if (doc) {
      69               0 :     doc->BeginUpdate(UPDATE_STYLE);
      70               0 :     doc->RemoveStyleSheet(aSheet);
      71               0 :     doc->EndUpdate(UPDATE_STYLE);
      72                 :   }
      73               0 : }
      74                 : 
      75               0 : AddStyleSheetTxn::AddStyleSheetTxn()
      76                 : :  EditTxn()
      77               0 : ,  mEditor(NULL)
      78                 : {
      79               0 : }
      80                 : 
      81            1464 : NS_IMPL_CYCLE_COLLECTION_CLASS(AddStyleSheetTxn)
      82                 : 
      83               0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(AddStyleSheetTxn, EditTxn)
      84               0 :   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mSheet)
      85               0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_END
      86                 : 
      87               0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(AddStyleSheetTxn, EditTxn)
      88               0 :   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mSheet, nsIStyleSheet)
      89               0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
      90                 : 
      91               0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AddStyleSheetTxn)
      92               0 : NS_INTERFACE_MAP_END_INHERITING(EditTxn)
      93                 : 
      94                 : NS_IMETHODIMP
      95               0 : AddStyleSheetTxn::Init(nsIEditor *aEditor, nsCSSStyleSheet *aSheet)
      96                 : {
      97               0 :   NS_ENSURE_TRUE(aEditor && aSheet, NS_ERROR_INVALID_ARG);
      98                 : 
      99               0 :   mEditor = aEditor;
     100               0 :   mSheet = aSheet;
     101                 :   
     102               0 :   return NS_OK;
     103                 : }
     104                 : 
     105                 : 
     106                 : NS_IMETHODIMP
     107               0 : AddStyleSheetTxn::DoTransaction()
     108                 : {
     109               0 :   NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED);
     110                 :   
     111               0 :   AddStyleSheet(mEditor, mSheet);
     112               0 :   return NS_OK;
     113                 : }
     114                 : 
     115                 : NS_IMETHODIMP
     116               0 : AddStyleSheetTxn::UndoTransaction()
     117                 : {
     118               0 :   NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED);
     119                 :   
     120               0 :   RemoveStyleSheet(mEditor, mSheet);
     121               0 :   return NS_OK;
     122                 : }
     123                 : 
     124                 : NS_IMETHODIMP
     125               0 : AddStyleSheetTxn::GetTxnDescription(nsAString& aString)
     126                 : {
     127               0 :   aString.AssignLiteral("AddStyleSheetTxn");
     128               0 :   return NS_OK;
     129                 : }
     130                 : 
     131                 : 
     132               0 : RemoveStyleSheetTxn::RemoveStyleSheetTxn()
     133                 : :  EditTxn()
     134               0 : ,  mEditor(NULL)
     135                 : {
     136               0 : }
     137                 : 
     138            1464 : NS_IMPL_CYCLE_COLLECTION_CLASS(RemoveStyleSheetTxn)
     139                 : 
     140               0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(RemoveStyleSheetTxn, EditTxn)
     141               0 :   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mSheet)
     142               0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_END
     143                 : 
     144               0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(RemoveStyleSheetTxn, EditTxn)
     145               0 :   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mSheet, nsIStyleSheet)
     146               0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
     147                 : 
     148               0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(RemoveStyleSheetTxn)
     149               0 : NS_INTERFACE_MAP_END_INHERITING(EditTxn)
     150                 : 
     151                 : NS_IMETHODIMP
     152               0 : RemoveStyleSheetTxn::Init(nsIEditor *aEditor, nsCSSStyleSheet *aSheet)
     153                 : {
     154               0 :   NS_ENSURE_TRUE(aEditor && aSheet, NS_ERROR_INVALID_ARG);
     155                 : 
     156               0 :   mEditor = aEditor;
     157               0 :   mSheet = aSheet;
     158                 : 
     159               0 :   return NS_OK;
     160                 : }
     161                 : 
     162                 : 
     163                 : NS_IMETHODIMP
     164               0 : RemoveStyleSheetTxn::DoTransaction()
     165                 : {
     166               0 :   NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED);
     167                 : 
     168               0 :   RemoveStyleSheet(mEditor, mSheet);
     169               0 :   return NS_OK;
     170                 : }
     171                 : 
     172                 : NS_IMETHODIMP
     173               0 : RemoveStyleSheetTxn::UndoTransaction()
     174                 : {
     175               0 :   NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED);
     176                 : 
     177               0 :   AddStyleSheet(mEditor, mSheet);
     178               0 :   return NS_OK;
     179                 : }
     180                 : 
     181                 : NS_IMETHODIMP
     182               0 : RemoveStyleSheetTxn::GetTxnDescription(nsAString& aString)
     183                 : {
     184               0 :   aString.AssignLiteral("RemoveStyleSheetTxn");
     185               0 :   return NS_OK;
     186            4392 : }

Generated by: LCOV version 1.7