tor-browser

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

ListMutationObserver.h (2131B)


      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 mozilla_ListMutationObserver_h
      8 #define mozilla_ListMutationObserver_h
      9 
     10 #include "IDTracker.h"
     11 #include "nsStubMutationObserver.h"
     12 
     13 class nsIFrame;
     14 
     15 namespace mozilla {
     16 
     17 namespace dom {
     18 class HTMLInputElement;
     19 }  // namespace dom
     20 
     21 /**
     22 * ListMutationObserver
     23 * This class invalidates paint for the input element's frame when the content
     24 * of its @list changes, or when the @list ID identifies a different element. It
     25 * does *not* invalidate paint when the @list attribute itself changes.
     26 */
     27 
     28 class ListMutationObserver final : public nsStubMutationObserver,
     29                                   public dom::IDTracker {
     30 public:
     31  explicit ListMutationObserver(nsIFrame& aOwningElementFrame,
     32                                bool aRepaint = false)
     33      : mOwningElementFrame(&aOwningElementFrame) {
     34    // We can skip invalidating paint if the frame is still being initialized.
     35    Attach(aRepaint);
     36  }
     37 
     38  NS_DECL_ISUPPORTS
     39 
     40  // We need to invalidate paint when the list or its options change.
     41  NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
     42  NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
     43  NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
     44  NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
     45  NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
     46 
     47  /**
     48   * Triggered when the same @list ID identifies a different element than
     49   * before.
     50   */
     51  void ElementChanged(dom::Element* aFrom, dom::Element* aTo) override;
     52 
     53  void Attach(bool aRepaint = true);
     54  void Detach();
     55  void AddObserverIfNeeded();
     56  void RemoveObserverIfNeeded(dom::Element* aList);
     57  void RemoveObserverIfNeeded() { RemoveObserverIfNeeded(get()); }
     58  dom::HTMLInputElement& InputElement() const;
     59 
     60 private:
     61  ~ListMutationObserver();
     62 
     63  nsIFrame* mOwningElementFrame;
     64 };
     65 }  // namespace mozilla
     66 
     67 #endif  // mozilla_ListMutationObserver_h