1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef NS_SMILTIMEVALUESPEC_H_
7 #define NS_SMILTIMEVALUESPEC_H_
9 #include "mozilla/Attributes.h"
10 #include "nsSMILTimeValueSpecParams.h"
11 #include "nsReferencedElement.h"
12 #include "nsAutoPtr.h"
13 #include "nsIDOMEventListener.h"
16 class nsSMILTimeValue
;
17 class nsSMILTimedElement
;
18 class nsSMILTimeContainer
;
19 class nsSMILInstanceTime
;
23 class EventListenerManager
;
24 } // namespace mozilla
26 //----------------------------------------------------------------------
27 // nsSMILTimeValueSpec class
29 // An individual element of a 'begin' or 'end' attribute, e.g. '5s', 'a.end'.
30 // This class handles the parsing of such specifications and performs the
31 // necessary event handling (for event, repeat, and accesskey specifications)
32 // and synchronisation (for syncbase specifications).
34 // For an overview of how this class is related to other SMIL time classes see
35 // the documentation in nsSMILTimeValue.h
37 class nsSMILTimeValueSpec
40 typedef mozilla::dom::Element Element
;
42 nsSMILTimeValueSpec(nsSMILTimedElement
& aOwner
, bool aIsBegin
);
43 ~nsSMILTimeValueSpec();
45 nsresult
SetSpec(const nsAString
& aStringSpec
, Element
* aContextNode
);
46 void ResolveReferences(nsIContent
* aContextNode
);
47 bool IsEventBased() const;
49 void HandleNewInterval(nsSMILInterval
& aInterval
,
50 const nsSMILTimeContainer
* aSrcContainer
);
51 void HandleTargetElementChange(Element
* aNewTarget
);
53 // For created nsSMILInstanceTime objects
54 bool DependsOnBegin() const;
55 void HandleChangedInstanceTime(const nsSMILInstanceTime
& aBaseTime
,
56 const nsSMILTimeContainer
* aSrcContainer
,
57 nsSMILInstanceTime
& aInstanceTimeToUpdate
,
59 void HandleDeletedInstanceTime(nsSMILInstanceTime
& aInstanceTime
);
61 // Cycle-collection support
62 void Traverse(nsCycleCollectionTraversalCallback
* aCallback
);
66 void UpdateReferencedElement(Element
* aFrom
, Element
* aTo
);
67 void UnregisterFromReferencedElement(Element
* aElement
);
68 nsSMILTimedElement
* GetTimedElement(Element
* aElement
);
69 bool IsWhitelistedEvent();
70 void RegisterEventListener(Element
* aElement
);
71 void UnregisterEventListener(Element
* aElement
);
72 mozilla::EventListenerManager
* GetEventListenerManager(Element
* aElement
);
73 void HandleEvent(nsIDOMEvent
* aEvent
);
74 bool CheckEventDetail(nsIDOMEvent
* aEvent
);
75 bool CheckRepeatEventDetail(nsIDOMEvent
* aEvent
);
76 bool CheckAccessKeyEventDetail(nsIDOMEvent
* aEvent
);
77 nsSMILTimeValue
ConvertBetweenTimeContainers(const nsSMILTimeValue
& aSrcTime
,
78 const nsSMILTimeContainer
* aSrcContainer
);
79 bool ApplyOffset(nsSMILTimeValue
& aTime
) const;
81 nsSMILTimedElement
* mOwner
;
82 bool mIsBegin
; // Indicates if *we* are a begin spec,
83 // not to be confused with
84 // mParams.mSyncBegin which indicates
85 // if we're synced with the begin of
87 nsSMILTimeValueSpecParams mParams
;
89 class TimeReferenceElement
: public nsReferencedElement
92 explicit TimeReferenceElement(nsSMILTimeValueSpec
* aOwner
) : mSpec(aOwner
) { }
93 void ResetWithElement(Element
* aTo
) {
94 nsRefPtr
<Element
> from
= get();
96 ElementChanged(from
, aTo
);
100 virtual void ElementChanged(Element
* aFrom
, Element
* aTo
) MOZ_OVERRIDE
102 nsReferencedElement::ElementChanged(aFrom
, aTo
);
103 mSpec
->UpdateReferencedElement(aFrom
, aTo
);
105 virtual bool IsPersistent() MOZ_OVERRIDE
{ return true; }
107 nsSMILTimeValueSpec
* mSpec
;
110 TimeReferenceElement mReferencedElement
;
112 class EventListener MOZ_FINAL
: public nsIDOMEventListener
116 explicit EventListener(nsSMILTimeValueSpec
* aOwner
) : mSpec(aOwner
) { }
123 NS_DECL_NSIDOMEVENTLISTENER
126 nsSMILTimeValueSpec
* mSpec
;
128 nsRefPtr
<EventListener
> mEventListener
;
131 #endif // NS_SMILTIMEVALUESPEC_H_