Bug 1729121 [wpt PR 30345] - Improve media queries JS test, a=testonly
[gecko.git] / dom / xul / XULBroadcastManager.h
blobc5fcbf3bf7ec66b18293165e3d8ca385b54dae3a
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/. */
7 #ifndef mozilla_dom_XULBroadcastManager_h
8 #define mozilla_dom_XULBroadcastManager_h
10 #include "nsAtom.h"
11 #include "nsTArray.h"
13 class PLDHashTable;
14 class nsXULElement;
16 namespace mozilla {
18 class ErrorResult;
20 namespace dom {
22 class Document;
23 class Element;
25 class XULBroadcastManager final {
26 public:
27 explicit XULBroadcastManager(Document* aDocument);
29 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(XULBroadcastManager)
31 /**
32 * Checks whether an element uses any of the special broadcaster attributes
33 * or is an observes element. This mimics the logic in FindBroadcaster, but
34 * is intended to be a lighter weight check and doesn't actually guarantee
35 * that the element will need a listener.
37 static bool MayNeedListener(const Element& aElement);
39 nsresult AddListener(Element* aElement);
40 nsresult RemoveListener(Element* aElement);
41 void AttributeChanged(Element* aElement, int32_t aNameSpaceID,
42 nsAtom* aAttribute);
43 void MaybeBroadcast();
44 void DropDocumentReference(); // notification that doc is going away
45 protected:
46 enum HookupAction { eHookupAdd = 0, eHookupRemove };
48 nsresult UpdateListenerHookup(Element* aElement, HookupAction aAction);
50 void RemoveListenerFor(Element& aBroadcaster, Element& aListener,
51 const nsAString& aAttr);
52 void AddListenerFor(Element& aBroadcaster, Element& aListener,
53 const nsAString& aAttr, ErrorResult& aRv);
55 nsresult ExecuteOnBroadcastHandlerFor(Element* aBroadcaster,
56 Element* aListener, nsAtom* aAttr);
57 // The out params of FindBroadcaster only have values that make sense when
58 // the method returns NS_FINDBROADCASTER_FOUND. In all other cases, the
59 // values of the out params should not be relied on (though *aListener and
60 // *aBroadcaster do need to be released if non-null, of course).
61 nsresult FindBroadcaster(Element* aElement, Element** aListener,
62 nsString& aBroadcasterID, nsString& aAttribute,
63 Element** aBroadcaster);
65 void SynchronizeBroadcastListener(Element* aBroadcaster, Element* aListener,
66 const nsAString& aAttr);
68 // This reference is nulled by the Document in it's destructor through
69 // DropDocumentReference().
70 Document* MOZ_NON_OWNING_REF mDocument;
72 /**
73 * A map from a broadcaster element to a list of listener elements.
75 PLDHashTable* mBroadcasterMap;
77 class nsDelayedBroadcastUpdate;
78 nsTArray<nsDelayedBroadcastUpdate> mDelayedBroadcasters;
79 nsTArray<nsDelayedBroadcastUpdate> mDelayedAttrChangeBroadcasts;
80 bool mHandlingDelayedAttrChange;
81 bool mHandlingDelayedBroadcasters;
83 private:
84 ~XULBroadcastManager();
87 } // namespace dom
88 } // namespace mozilla
90 #endif // mozilla_dom_XULBroadcastManager_h