|
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/. */ |
|
5 |
|
6 #ifndef NS_SMILTIMEVALUESPEC_H_ |
|
7 #define NS_SMILTIMEVALUESPEC_H_ |
|
8 |
|
9 #include "mozilla/Attributes.h" |
|
10 #include "nsSMILTimeValueSpecParams.h" |
|
11 #include "nsReferencedElement.h" |
|
12 #include "nsAutoPtr.h" |
|
13 #include "nsIDOMEventListener.h" |
|
14 |
|
15 class nsAString; |
|
16 class nsSMILTimeValue; |
|
17 class nsSMILTimedElement; |
|
18 class nsSMILTimeContainer; |
|
19 class nsSMILInstanceTime; |
|
20 class nsSMILInterval; |
|
21 |
|
22 namespace mozilla { |
|
23 class EventListenerManager; |
|
24 } // namespace mozilla |
|
25 |
|
26 //---------------------------------------------------------------------- |
|
27 // nsSMILTimeValueSpec class |
|
28 // |
|
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). |
|
33 // |
|
34 // For an overview of how this class is related to other SMIL time classes see |
|
35 // the documentation in nsSMILTimeValue.h |
|
36 |
|
37 class nsSMILTimeValueSpec |
|
38 { |
|
39 public: |
|
40 typedef mozilla::dom::Element Element; |
|
41 |
|
42 nsSMILTimeValueSpec(nsSMILTimedElement& aOwner, bool aIsBegin); |
|
43 ~nsSMILTimeValueSpec(); |
|
44 |
|
45 nsresult SetSpec(const nsAString& aStringSpec, Element* aContextNode); |
|
46 void ResolveReferences(nsIContent* aContextNode); |
|
47 bool IsEventBased() const; |
|
48 |
|
49 void HandleNewInterval(nsSMILInterval& aInterval, |
|
50 const nsSMILTimeContainer* aSrcContainer); |
|
51 void HandleTargetElementChange(Element* aNewTarget); |
|
52 |
|
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); |
|
60 |
|
61 // Cycle-collection support |
|
62 void Traverse(nsCycleCollectionTraversalCallback* aCallback); |
|
63 void Unlink(); |
|
64 |
|
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; |
|
80 |
|
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; |
|
88 |
|
89 class TimeReferenceElement : public nsReferencedElement |
|
90 { |
|
91 public: |
|
92 TimeReferenceElement(nsSMILTimeValueSpec* aOwner) : mSpec(aOwner) { } |
|
93 void ResetWithElement(Element* aTo) { |
|
94 nsRefPtr<Element> from = get(); |
|
95 Unlink(); |
|
96 ElementChanged(from, aTo); |
|
97 } |
|
98 |
|
99 protected: |
|
100 virtual void ElementChanged(Element* aFrom, Element* aTo) MOZ_OVERRIDE |
|
101 { |
|
102 nsReferencedElement::ElementChanged(aFrom, aTo); |
|
103 mSpec->UpdateReferencedElement(aFrom, aTo); |
|
104 } |
|
105 virtual bool IsPersistent() MOZ_OVERRIDE { return true; } |
|
106 private: |
|
107 nsSMILTimeValueSpec* mSpec; |
|
108 }; |
|
109 |
|
110 TimeReferenceElement mReferencedElement; |
|
111 |
|
112 class EventListener MOZ_FINAL : public nsIDOMEventListener |
|
113 { |
|
114 public: |
|
115 EventListener(nsSMILTimeValueSpec* aOwner) : mSpec(aOwner) { } |
|
116 void Disconnect() |
|
117 { |
|
118 mSpec = nullptr; |
|
119 } |
|
120 |
|
121 NS_DECL_ISUPPORTS |
|
122 NS_DECL_NSIDOMEVENTLISTENER |
|
123 |
|
124 private: |
|
125 nsSMILTimeValueSpec* mSpec; |
|
126 }; |
|
127 nsRefPtr<EventListener> mEventListener; |
|
128 }; |
|
129 |
|
130 #endif // NS_SMILTIMEVALUESPEC_H_ |