editor/libeditor/ChangeAttributeTransaction.h
author Nathan Froyd <froydnj@gmail.com>
Fri, 12 Aug 2016 22:43:49 -0400
changeset 400339 e3608df9fe09f509a8fe62be0cd6743151e4f7a3
parent 386002 b97cb7c9d1e34abea935f5a1827a88471531afa9
child 489668 cbb8fdf1daf98a15f7d57f6b08d273bdf96aa1a0
child 555597 20dde05f33729bd827cd4a1b90670cf5aec1a80a
child 670903 d95ad1fea6c89fff59b23d52550b584d5ea66312
permissions -rw-r--r--
Bug 1294537 - introduce a non-null-checking placement operator new; r=sunfish,nbp The default placement operator new is defined to always require that its result be null-checked. A sufficiently smart compiler can remove this check, but not all compilers are sufficiently smart. Better to have a custom placement operator new that will remove null checks in a way defined by the standard.

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef ChangeAttributeTransaction_h
#define ChangeAttributeTransaction_h

#include "mozilla/Attributes.h"           // override
#include "mozilla/EditTransactionBase.h"  // base class
#include "nsCOMPtr.h"                     // nsCOMPtr members
#include "nsCycleCollectionParticipant.h" // NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED
#include "nsISupportsImpl.h"              // NS_DECL_ISUPPORTS_INHERITED
#include "nsString.h"                     // nsString members

class nsIAtom;

namespace mozilla {

namespace dom {
class Element;
} // namespace dom

/**
 * A transaction that changes an attribute of a content node.  This transaction
 * covers add, remove, and change attribute.
 */
class ChangeAttributeTransaction final : public EditTransactionBase
{
public:
  /**
   * @param aElement   the element whose attribute will be changed
   * @param aAttribute the name of the attribute to change
   * @param aValue     the new value for aAttribute, or null to remove
   */
  ChangeAttributeTransaction(dom::Element& aElement,
                             nsIAtom& aAttribute,
                             const nsAString* aValue);

  NS_DECL_ISUPPORTS_INHERITED
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ChangeAttributeTransaction,
                                           EditTransactionBase)

  NS_DECL_EDITTRANSACTIONBASE

  NS_IMETHOD RedoTransaction() override;

private:
  virtual ~ChangeAttributeTransaction();

  // The element to operate upon
  nsCOMPtr<dom::Element> mElement;

  // The attribute to change
  nsCOMPtr<nsIAtom> mAttribute;

  // The value to set the attribute to (ignored if mRemoveAttribute==true)
  nsString mValue;

  // True if the operation is to remove mAttribute from mElement
  bool mRemoveAttribute;

  // True if the mAttribute was set on mElement at the time of execution
  bool mAttributeWasSet;

  // The value to set the attribute to for undo
  nsString mUndoValue;
};

} // namespace mozilla

#endif // #ifndef ChangeAttributeTransaction_h