dom/smil/nsSMILTimeValueSpec.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/smil/nsSMILTimeValueSpec.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,130 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef NS_SMILTIMEVALUESPEC_H_
    1.10 +#define NS_SMILTIMEVALUESPEC_H_
    1.11 +
    1.12 +#include "mozilla/Attributes.h"
    1.13 +#include "nsSMILTimeValueSpecParams.h"
    1.14 +#include "nsReferencedElement.h"
    1.15 +#include "nsAutoPtr.h"
    1.16 +#include "nsIDOMEventListener.h"
    1.17 +
    1.18 +class nsAString;
    1.19 +class nsSMILTimeValue;
    1.20 +class nsSMILTimedElement;
    1.21 +class nsSMILTimeContainer;
    1.22 +class nsSMILInstanceTime;
    1.23 +class nsSMILInterval;
    1.24 +
    1.25 +namespace mozilla {
    1.26 +class EventListenerManager;
    1.27 +} // namespace mozilla
    1.28 +
    1.29 +//----------------------------------------------------------------------
    1.30 +// nsSMILTimeValueSpec class
    1.31 +//
    1.32 +// An individual element of a 'begin' or 'end' attribute, e.g. '5s', 'a.end'.
    1.33 +// This class handles the parsing of such specifications and performs the
    1.34 +// necessary event handling (for event, repeat, and accesskey specifications)
    1.35 +// and synchronisation (for syncbase specifications).
    1.36 +//
    1.37 +// For an overview of how this class is related to other SMIL time classes see
    1.38 +// the documentation in nsSMILTimeValue.h
    1.39 +
    1.40 +class nsSMILTimeValueSpec
    1.41 +{
    1.42 +public:
    1.43 +  typedef mozilla::dom::Element Element;
    1.44 +
    1.45 +  nsSMILTimeValueSpec(nsSMILTimedElement& aOwner, bool aIsBegin);
    1.46 +  ~nsSMILTimeValueSpec();
    1.47 +
    1.48 +  nsresult SetSpec(const nsAString& aStringSpec, Element* aContextNode);
    1.49 +  void     ResolveReferences(nsIContent* aContextNode);
    1.50 +  bool     IsEventBased() const;
    1.51 +
    1.52 +  void     HandleNewInterval(nsSMILInterval& aInterval,
    1.53 +                             const nsSMILTimeContainer* aSrcContainer);
    1.54 +  void     HandleTargetElementChange(Element* aNewTarget);
    1.55 +
    1.56 +  // For created nsSMILInstanceTime objects
    1.57 +  bool     DependsOnBegin() const;
    1.58 +  void     HandleChangedInstanceTime(const nsSMILInstanceTime& aBaseTime,
    1.59 +                                     const nsSMILTimeContainer* aSrcContainer,
    1.60 +                                     nsSMILInstanceTime& aInstanceTimeToUpdate,
    1.61 +                                     bool aObjectChanged);
    1.62 +  void     HandleDeletedInstanceTime(nsSMILInstanceTime& aInstanceTime);
    1.63 +
    1.64 +  // Cycle-collection support
    1.65 +  void Traverse(nsCycleCollectionTraversalCallback* aCallback);
    1.66 +  void Unlink();
    1.67 +
    1.68 +protected:
    1.69 +  void UpdateReferencedElement(Element* aFrom, Element* aTo);
    1.70 +  void UnregisterFromReferencedElement(Element* aElement);
    1.71 +  nsSMILTimedElement* GetTimedElement(Element* aElement);
    1.72 +  bool IsWhitelistedEvent();
    1.73 +  void RegisterEventListener(Element* aElement);
    1.74 +  void UnregisterEventListener(Element* aElement);
    1.75 +  mozilla::EventListenerManager* GetEventListenerManager(Element* aElement);
    1.76 +  void HandleEvent(nsIDOMEvent* aEvent);
    1.77 +  bool CheckEventDetail(nsIDOMEvent* aEvent);
    1.78 +  bool CheckRepeatEventDetail(nsIDOMEvent* aEvent);
    1.79 +  bool CheckAccessKeyEventDetail(nsIDOMEvent* aEvent);
    1.80 +  nsSMILTimeValue ConvertBetweenTimeContainers(const nsSMILTimeValue& aSrcTime,
    1.81 +                                      const nsSMILTimeContainer* aSrcContainer);
    1.82 +  bool ApplyOffset(nsSMILTimeValue& aTime) const;
    1.83 +
    1.84 +  nsSMILTimedElement*           mOwner;
    1.85 +  bool                          mIsBegin; // Indicates if *we* are a begin spec,
    1.86 +                                          // not to be confused with
    1.87 +                                          // mParams.mSyncBegin which indicates
    1.88 +                                          // if we're synced with the begin of
    1.89 +                                          // the target.
    1.90 +  nsSMILTimeValueSpecParams     mParams;
    1.91 +
    1.92 +  class TimeReferenceElement : public nsReferencedElement
    1.93 +  {
    1.94 +  public:
    1.95 +    TimeReferenceElement(nsSMILTimeValueSpec* aOwner) : mSpec(aOwner) { }
    1.96 +    void ResetWithElement(Element* aTo) {
    1.97 +      nsRefPtr<Element> from = get();
    1.98 +      Unlink();
    1.99 +      ElementChanged(from, aTo);
   1.100 +    }
   1.101 +
   1.102 +  protected:
   1.103 +    virtual void ElementChanged(Element* aFrom, Element* aTo) MOZ_OVERRIDE
   1.104 +    {
   1.105 +      nsReferencedElement::ElementChanged(aFrom, aTo);
   1.106 +      mSpec->UpdateReferencedElement(aFrom, aTo);
   1.107 +    }
   1.108 +    virtual bool IsPersistent() MOZ_OVERRIDE { return true; }
   1.109 +  private:
   1.110 +    nsSMILTimeValueSpec* mSpec;
   1.111 +  };
   1.112 +
   1.113 +  TimeReferenceElement mReferencedElement;
   1.114 +
   1.115 +  class EventListener MOZ_FINAL : public nsIDOMEventListener
   1.116 +  {
   1.117 +  public:
   1.118 +    EventListener(nsSMILTimeValueSpec* aOwner) : mSpec(aOwner) { }
   1.119 +    void Disconnect()
   1.120 +    {
   1.121 +      mSpec = nullptr;
   1.122 +    }
   1.123 +
   1.124 +    NS_DECL_ISUPPORTS
   1.125 +    NS_DECL_NSIDOMEVENTLISTENER
   1.126 +
   1.127 +  private:
   1.128 +    nsSMILTimeValueSpec* mSpec;
   1.129 +  };
   1.130 +  nsRefPtr<EventListener> mEventListener;
   1.131 +};
   1.132 +
   1.133 +#endif // NS_SMILTIMEVALUESPEC_H_

mercurial