no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / smil / SMILTimeValueSpec.h
blobcb0d2dd9ab04c75a48aad94b14826d3846d0a167
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 DOM_SMIL_SMILTIMEVALUESPEC_H_
8 #define DOM_SMIL_SMILTIMEVALUESPEC_H_
10 #include "mozilla/Attributes.h"
11 #include "mozilla/SMILTimeValueSpecParams.h"
12 #include "mozilla/dom/IDTracker.h"
13 #include "nsStringFwd.h"
14 #include "nsIDOMEventListener.h"
16 // XXX Avoid including this here by moving function bodies to the cpp file
17 #include "mozilla/dom/Element.h"
19 namespace mozilla {
21 class EventListenerManager;
22 class SMILInstanceTime;
23 class SMILInterval;
24 class SMILTimeContainer;
25 class SMILTimedElement;
26 class SMILTimeValue;
28 namespace dom {
29 class Event;
30 } // namespace dom
32 //----------------------------------------------------------------------
33 // SMILTimeValueSpec class
35 // An individual element of a 'begin' or 'end' attribute, e.g. '5s', 'a.end'.
36 // This class handles the parsing of such specifications and performs the
37 // necessary event handling (for event and repeat specifications)
38 // and synchronisation (for syncbase specifications).
40 // For an overview of how this class is related to other SMIL time classes see
41 // the documentation in SMILTimeValue.h
43 class SMILTimeValueSpec {
44 public:
45 using Element = dom::Element;
46 using Event = dom::Event;
47 using IDTracker = dom::IDTracker;
49 SMILTimeValueSpec(SMILTimedElement& aOwner, bool aIsBegin);
50 ~SMILTimeValueSpec();
52 nsresult SetSpec(const nsAString& aStringSpec, Element& aContextElement);
53 void ResolveReferences(Element& aContextElement);
54 bool IsEventBased() const;
56 void HandleNewInterval(SMILInterval& aInterval,
57 const SMILTimeContainer* aSrcContainer);
58 void HandleTargetElementChange(Element* aNewTarget);
60 // For created SMILInstanceTime objects
61 bool DependsOnBegin() const;
62 void HandleChangedInstanceTime(const SMILInstanceTime& aBaseTime,
63 const SMILTimeContainer* aSrcContainer,
64 SMILInstanceTime& aInstanceTimeToUpdate,
65 bool aObjectChanged);
66 void HandleDeletedInstanceTime(SMILInstanceTime& aInstanceTime);
68 // Cycle-collection support
69 void Traverse(nsCycleCollectionTraversalCallback* aCallback);
70 void Unlink();
72 protected:
73 void UpdateReferencedElement(Element* aFrom, Element* aTo);
74 void UnregisterFromReferencedElement(Element* aElement);
75 SMILTimedElement* GetTimedElement(Element* aElement);
76 bool IsEventAllowedWhenScriptingIsDisabled();
77 void RegisterEventListener(Element* aTarget);
78 void UnregisterEventListener(Element* aTarget);
79 void HandleEvent(Event* aEvent);
80 bool CheckRepeatEventDetail(Event* aEvent);
81 SMILTimeValue ConvertBetweenTimeContainers(
82 const SMILTimeValue& aSrcTime, const SMILTimeContainer* aSrcContainer);
83 bool ApplyOffset(SMILTimeValue& aTime) const;
85 SMILTimedElement* mOwner;
86 bool mIsBegin; // Indicates if *we* are a begin spec,
87 // not to be confused with
88 // mParams.mSyncBegin which indicates
89 // if we're synced with the begin of
90 // the target.
91 SMILTimeValueSpecParams mParams;
93 /**
94 * If our SMILTimeValueSpec exists for a 'begin' or 'end' attribute with a
95 * value that specifies a time that is relative to the animation of some
96 * other element, it will create an instance of this class to reference and
97 * track that other element. For example, if the SMILTimeValueSpec is for
98 * end='a.end+2s', an instance of this class will be created to track the
99 * element associated with the element ID "a". This class will notify the
100 * SMILTimeValueSpec if the element that that ID identifies changes to a
101 * different element (or none).
103 class TimeReferenceTracker final : public IDTracker {
104 public:
105 explicit TimeReferenceTracker(SMILTimeValueSpec* aOwner) : mSpec(aOwner) {}
106 void ResetWithElement(Element* aTo) {
107 RefPtr<Element> from = get();
108 Unlink();
109 ElementChanged(from, aTo);
112 protected:
113 void ElementChanged(Element* aFrom, Element* aTo) override {
114 IDTracker::ElementChanged(aFrom, aTo);
115 mSpec->UpdateReferencedElement(aFrom, aTo);
117 bool IsPersistent() override { return true; }
119 private:
120 SMILTimeValueSpec* mSpec;
123 TimeReferenceTracker mReferencedElement;
125 class EventListener final : public nsIDOMEventListener {
126 ~EventListener() {}
128 public:
129 explicit EventListener(SMILTimeValueSpec* aOwner) : mSpec(aOwner) {}
130 void Disconnect() { mSpec = nullptr; }
132 NS_DECL_ISUPPORTS
133 NS_DECL_NSIDOMEVENTLISTENER
135 private:
136 SMILTimeValueSpec* mSpec;
138 RefPtr<EventListener> mEventListener;
141 } // namespace mozilla
143 #endif // DOM_SMIL_SMILTIMEVALUESPEC_H_