tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

MutationObservers.h (6915B)


      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 DOM_BASE_MUTATIONOBSERVERS_H_
      8 #define DOM_BASE_MUTATIONOBSERVERS_H_
      9 
     10 #include "mozilla/DoublyLinkedList.h"
     11 #include "nsIContent.h"  // for use in inline function (NotifyParentChainChanged)
     12 #include "nsIMutationObserver.h"  // for use in inline function (NotifyParentChainChanged)
     13 #include "nsINode.h"
     14 
     15 class nsAtom;
     16 class nsAttrValue;
     17 struct BatchRemovalState;
     18 
     19 namespace mozilla::dom {
     20 class Animation;
     21 class Element;
     22 
     23 class MutationObservers {
     24 public:
     25  /**
     26   * Send CharacterDataWillChange notifications to nsIMutationObservers.
     27   * @param aContent  Node whose data changed
     28   * @param aInfo     Struct with information details about the change
     29   * @see nsIMutationObserver::CharacterDataWillChange
     30   */
     31  static void NotifyCharacterDataWillChange(nsIContent* aContent,
     32                                            const CharacterDataChangeInfo&);
     33 
     34  /**
     35   * Send CharacterDataChanged notifications to nsIMutationObservers.
     36   * @param aContent  Node whose data changed
     37   * @param aInfo     Struct with information details about the change
     38   * @see nsIMutationObserver::CharacterDataChanged
     39   */
     40  static void NotifyCharacterDataChanged(nsIContent* aContent,
     41                                         const CharacterDataChangeInfo&);
     42 
     43  /**
     44   * Send AttributeWillChange notifications to nsIMutationObservers.
     45   * @param aElement      Element whose data will change
     46   * @param aNameSpaceID  Namespace of changing attribute
     47   * @param aAttribute    Local-name of changing attribute
     48   * @param aModType      Type of change (add/change/removal)
     49   * @see nsIMutationObserver::AttributeWillChange
     50   */
     51  static void NotifyAttributeWillChange(mozilla::dom::Element* aElement,
     52                                        int32_t aNameSpaceID,
     53                                        nsAtom* aAttribute,
     54                                        AttrModType aModType);
     55 
     56  /**
     57   * Send AttributeChanged notifications to nsIMutationObservers.
     58   * @param aElement      Element whose data changed
     59   * @param aNameSpaceID  Namespace of changed attribute
     60   * @param aAttribute    Local-name of changed attribute
     61   * @param aModType      Type of change (add/change/removal)
     62   * @param aOldValue     If the old value was StoresOwnData() (or absent),
     63   *                      that value, otherwise null
     64   * @see nsIMutationObserver::AttributeChanged
     65   */
     66  static void NotifyAttributeChanged(mozilla::dom::Element* aElement,
     67                                     int32_t aNameSpaceID, nsAtom* aAttribute,
     68                                     AttrModType aModType,
     69                                     const nsAttrValue* aOldValue);
     70 
     71  /**
     72   * Send AttributeSetToCurrentValue notifications to nsIMutationObservers.
     73   * @param aElement      Element whose data changed
     74   * @param aNameSpaceID  Namespace of the attribute
     75   * @param aAttribute    Local-name of the attribute
     76   * @see nsIMutationObserver::AttributeSetToCurrentValue
     77   */
     78  static void NotifyAttributeSetToCurrentValue(mozilla::dom::Element* aElement,
     79                                               int32_t aNameSpaceID,
     80                                               nsAtom* aAttribute);
     81 
     82  /**
     83   * Send ContentAppended notifications to nsIMutationObservers
     84   * @param aContainer           Node into which new child/children were added
     85   * @param aFirstNewContent     First new child
     86   * @param aInfo                Struct with information details about the
     87   *                             change
     88   * @see nsIMutationObserver::ContentAppended
     89   */
     90  static void NotifyContentAppended(nsIContent* aContainer,
     91                                    nsIContent* aFirstNewContent,
     92                                    const ContentAppendInfo&);
     93 
     94  /**
     95   * Send ContentInserted notifications to nsIMutationObservers
     96   * @param aContainer        Node into which new child was inserted
     97   * @param aChild            Newly inserted child
     98   * @param aInfo             Struct with information details about the change
     99   * @see nsIMutationObserver::ContentInserted
    100   */
    101  static void NotifyContentInserted(nsINode* aContainer, nsIContent* aChild,
    102                                    const ContentInsertInfo&);
    103  /**
    104   * Send ContentWillBeRemoved notifications to nsIMutationObservers
    105   * @param aContainer        Node from which child was removed
    106   * @param aChild            Removed child
    107   * @param aInfo             Struct with information details about the change
    108   * @see nsIMutationObserver::ContentWillBeRemoved
    109   */
    110  static void NotifyContentWillBeRemoved(nsINode* aContainer,
    111                                         nsIContent* aChild,
    112                                         const ContentRemoveInfo&);
    113 
    114  /**
    115   * Send ParentChainChanged notifications to nsIMutationObservers
    116   * @param aContent  The piece of content that had its parent changed.
    117   * @see nsIMutationObserver::ParentChainChanged
    118   */
    119  static inline void NotifyParentChainChanged(nsIContent* aContent) {
    120    mozilla::SafeDoublyLinkedList<nsIMutationObserver>* observers =
    121        aContent->GetMutationObservers();
    122    if (observers) {
    123      for (auto iter = observers->begin(); iter != observers->end(); ++iter) {
    124        if (iter->IsCallbackEnabled(nsIMutationObserver::kParentChainChanged)) {
    125          iter->ParentChainChanged(aContent);
    126        }
    127      }
    128    }
    129  }
    130 
    131  static void NotifyARIAAttributeDefaultWillChange(
    132      mozilla::dom::Element* aElement, nsAtom* aAttribute,
    133      AttrModType aModType);
    134  static void NotifyARIAAttributeDefaultChanged(mozilla::dom::Element* aElement,
    135                                                nsAtom* aAttribute,
    136                                                AttrModType aModType);
    137 
    138  /**
    139   * Notify that an animation is added/changed/removed.
    140   * @param aAnimation The animation we added/changed/removed.
    141   */
    142  static void NotifyAnimationAdded(mozilla::dom::Animation* aAnimation);
    143  static void NotifyAnimationChanged(mozilla::dom::Animation* aAnimation);
    144  static void NotifyAnimationRemoved(mozilla::dom::Animation* aAnimation);
    145 
    146 private:
    147  enum class AnimationMutationType { Added, Changed, Removed };
    148  /**
    149   * Notify the observers of the target of an animation
    150   * @param aAnimation The mutated animation.
    151   * @param aMutationType The mutation type of this animation. It could be
    152   *                      Added, Changed, or Removed.
    153   */
    154  static void NotifyAnimationMutated(mozilla::dom::Animation* aAnimation,
    155                                     AnimationMutationType aMutatedType);
    156 };
    157 }  // namespace mozilla::dom
    158 
    159 #endif  // DOM_BASE_MUTATIONOBSERVERS_H_