Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / dom / smil / nsSMILTimeValueSpec.h
blob9009fc865e539e722ca71054b134f54c206d237d
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"
15 class nsAString;
16 class nsSMILTimeValue;
17 class nsSMILTimedElement;
18 class nsSMILTimeContainer;
19 class nsSMILInstanceTime;
20 class nsSMILInterval;
22 namespace mozilla {
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
39 public:
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,
58 bool aObjectChanged);
59 void HandleDeletedInstanceTime(nsSMILInstanceTime& aInstanceTime);
61 // Cycle-collection support
62 void Traverse(nsCycleCollectionTraversalCallback* aCallback);
63 void Unlink();
65 protected:
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
86 // the target.
87 nsSMILTimeValueSpecParams mParams;
89 class TimeReferenceElement : public nsReferencedElement
91 public:
92 explicit TimeReferenceElement(nsSMILTimeValueSpec* aOwner) : mSpec(aOwner) { }
93 void ResetWithElement(Element* aTo) {
94 nsRefPtr<Element> from = get();
95 Unlink();
96 ElementChanged(from, aTo);
99 protected:
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; }
106 private:
107 nsSMILTimeValueSpec* mSpec;
110 TimeReferenceElement mReferencedElement;
112 class EventListener MOZ_FINAL : public nsIDOMEventListener
114 ~EventListener() {}
115 public:
116 explicit EventListener(nsSMILTimeValueSpec* aOwner) : mSpec(aOwner) { }
117 void Disconnect()
119 mSpec = nullptr;
122 NS_DECL_ISUPPORTS
123 NS_DECL_NSIDOMEVENTLISTENER
125 private:
126 nsSMILTimeValueSpec* mSpec;
128 nsRefPtr<EventListener> mEventListener;
131 #endif // NS_SMILTIMEVALUESPEC_H_