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"
21 class EventListenerManager
;
22 class SMILInstanceTime
;
24 class SMILTimeContainer
;
25 class SMILTimedElement
;
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
{
45 using Element
= dom::Element
;
46 using Event
= dom::Event
;
47 using IDTracker
= dom::IDTracker
;
49 SMILTimeValueSpec(SMILTimedElement
& aOwner
, bool aIsBegin
);
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
,
66 void HandleDeletedInstanceTime(SMILInstanceTime
& aInstanceTime
);
68 // Cycle-collection support
69 void Traverse(nsCycleCollectionTraversalCallback
* aCallback
);
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
91 SMILTimeValueSpecParams mParams
;
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
{
105 explicit TimeReferenceTracker(SMILTimeValueSpec
* aOwner
) : mSpec(aOwner
) {}
106 void ResetWithElement(Element
* aTo
) {
107 RefPtr
<Element
> from
= get();
109 ElementChanged(from
, aTo
);
113 void ElementChanged(Element
* aFrom
, Element
* aTo
) override
{
114 IDTracker::ElementChanged(aFrom
, aTo
);
115 mSpec
->UpdateReferencedElement(aFrom
, aTo
);
117 bool IsPersistent() override
{ return true; }
120 SMILTimeValueSpec
* mSpec
;
123 TimeReferenceTracker mReferencedElement
;
125 class EventListener final
: public nsIDOMEventListener
{
129 explicit EventListener(SMILTimeValueSpec
* aOwner
) : mSpec(aOwner
) {}
130 void Disconnect() { mSpec
= nullptr; }
133 NS_DECL_NSIDOMEVENTLISTENER
136 SMILTimeValueSpec
* mSpec
;
138 RefPtr
<EventListener
> mEventListener
;
141 } // namespace mozilla
143 #endif // DOM_SMIL_SMILTIMEVALUESPEC_H_