LCOV - code coverage report
Current view: top level - editor/libeditor - ChangeAttributeTransaction.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 35 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 12 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #include "ChangeAttributeTransaction.h"
       7             : 
       8             : #include "mozilla/dom/Element.h"        // for Element
       9             : 
      10             : #include "nsAString.h"
      11             : #include "nsError.h"                    // for NS_ERROR_NOT_INITIALIZED, etc.
      12             : 
      13             : namespace mozilla {
      14             : 
      15             : using namespace dom;
      16             : 
      17           0 : ChangeAttributeTransaction::ChangeAttributeTransaction(Element& aElement,
      18             :                                                        nsIAtom& aAttribute,
      19           0 :                                                        const nsAString* aValue)
      20             :   : EditTransactionBase()
      21             :   , mElement(&aElement)
      22             :   , mAttribute(&aAttribute)
      23           0 :   , mValue(aValue ? *aValue : EmptyString())
      24           0 :   , mRemoveAttribute(!aValue)
      25             :   , mAttributeWasSet(false)
      26           0 :   , mUndoValue()
      27             : {
      28           0 : }
      29             : 
      30           0 : ChangeAttributeTransaction::~ChangeAttributeTransaction()
      31             : {
      32           0 : }
      33             : 
      34           0 : NS_IMPL_CYCLE_COLLECTION_INHERITED(ChangeAttributeTransaction,
      35             :                                    EditTransactionBase,
      36             :                                    mElement)
      37             : 
      38           0 : NS_IMPL_ADDREF_INHERITED(ChangeAttributeTransaction, EditTransactionBase)
      39           0 : NS_IMPL_RELEASE_INHERITED(ChangeAttributeTransaction, EditTransactionBase)
      40           0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ChangeAttributeTransaction)
      41           0 : NS_INTERFACE_MAP_END_INHERITING(EditTransactionBase)
      42             : 
      43             : NS_IMETHODIMP
      44           0 : ChangeAttributeTransaction::DoTransaction()
      45             : {
      46             :   // Need to get the current value of the attribute and save it, and set
      47             :   // mAttributeWasSet
      48           0 :   mAttributeWasSet = mElement->GetAttr(kNameSpaceID_None, mAttribute,
      49             :                                        mUndoValue);
      50             : 
      51             :   // XXX: hack until attribute-was-set code is implemented
      52           0 :   if (!mUndoValue.IsEmpty()) {
      53           0 :     mAttributeWasSet = true;
      54             :   }
      55             :   // XXX: end hack
      56             : 
      57             :   // Now set the attribute to the new value
      58           0 :   if (mRemoveAttribute) {
      59           0 :     return mElement->UnsetAttr(kNameSpaceID_None, mAttribute, true);
      60             :   }
      61             : 
      62           0 :   return mElement->SetAttr(kNameSpaceID_None, mAttribute, mValue, true);
      63             : }
      64             : 
      65             : NS_IMETHODIMP
      66           0 : ChangeAttributeTransaction::UndoTransaction()
      67             : {
      68           0 :   if (mAttributeWasSet) {
      69           0 :     return mElement->SetAttr(kNameSpaceID_None, mAttribute, mUndoValue, true);
      70             :   }
      71           0 :   return mElement->UnsetAttr(kNameSpaceID_None, mAttribute, true);
      72             : }
      73             : 
      74             : NS_IMETHODIMP
      75           0 : ChangeAttributeTransaction::RedoTransaction()
      76             : {
      77           0 :   if (mRemoveAttribute) {
      78           0 :     return mElement->UnsetAttr(kNameSpaceID_None, mAttribute, true);
      79             :   }
      80             : 
      81           0 :   return mElement->SetAttr(kNameSpaceID_None, mAttribute, mValue, true);
      82             : }
      83             : 
      84             : NS_IMETHODIMP
      85           0 : ChangeAttributeTransaction::GetTxnDescription(nsAString& aString)
      86             : {
      87           0 :   aString.AssignLiteral("ChangeAttributeTransaction: [mRemoveAttribute == ");
      88             : 
      89           0 :   if (mRemoveAttribute) {
      90           0 :     aString.AppendLiteral("true] ");
      91             :   } else {
      92           0 :     aString.AppendLiteral("false] ");
      93             :   }
      94           0 :   aString += nsDependentAtomString(mAttribute);
      95           0 :   return NS_OK;
      96             : }
      97             : 
      98             : } // namespace mozilla

Generated by: LCOV version 1.13