2009-01-14 20:38:07 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
#include "nsSMILTimeValueSpec.h"
|
2010-01-12 12:00:49 -08:00
|
|
|
#include "nsSMILInterval.h"
|
|
|
|
#include "nsSMILTimeContainer.h"
|
2009-01-14 20:38:07 -08:00
|
|
|
#include "nsSMILTimeValue.h"
|
|
|
|
#include "nsSMILTimedElement.h"
|
|
|
|
#include "nsSMILInstanceTime.h"
|
|
|
|
#include "nsSMILParserUtils.h"
|
2010-01-12 12:00:49 -08:00
|
|
|
#include "nsISMILAnimationElement.h"
|
2011-06-23 19:18:01 -07:00
|
|
|
#include "nsEventListenerManager.h"
|
2010-08-18 03:20:24 -07:00
|
|
|
#include "nsGUIEvent.h"
|
2010-08-18 03:20:24 -07:00
|
|
|
#include "nsIDOMTimeEvent.h"
|
2009-01-14 20:38:07 -08:00
|
|
|
#include "nsString.h"
|
2011-11-15 11:56:32 -08:00
|
|
|
#include <limits>
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2010-08-18 03:20:24 -07:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2010-08-18 03:20:24 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Nested class: EventListener
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsSMILTimeValueSpec::EventListener, nsIDOMEventListener)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSMILTimeValueSpec::EventListener::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
if (mSpec) {
|
|
|
|
mSpec->HandleEvent(aEvent);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
// Disable "warning C4355: 'this' : used in base member initializer list".
|
2010-08-18 03:20:24 -07:00
|
|
|
// We can ignore that warning because we know that mReferencedElement's
|
|
|
|
// constructor doesn't dereference the pointer passed to it.
|
2010-01-12 12:00:49 -08:00
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable:4355)
|
|
|
|
#endif
|
|
|
|
nsSMILTimeValueSpec::nsSMILTimeValueSpec(nsSMILTimedElement& aOwner,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aIsBegin)
|
2010-01-12 12:00:49 -08:00
|
|
|
: mOwner(&aOwner),
|
2009-01-14 20:38:07 -08:00
|
|
|
mIsBegin(aIsBegin),
|
2010-08-18 03:20:24 -07:00
|
|
|
mReferencedElement(this)
|
2010-01-12 12:00:49 -08:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILTimeValueSpec::~nsSMILTimeValueSpec()
|
|
|
|
{
|
2010-08-18 03:20:24 -07:00
|
|
|
UnregisterFromReferencedElement(mReferencedElement.get());
|
|
|
|
if (mEventListener) {
|
|
|
|
mEventListener->Disconnect();
|
2012-07-30 07:20:58 -07:00
|
|
|
mEventListener = nullptr;
|
2010-08-18 03:20:24 -07:00
|
|
|
}
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
2009-01-14 20:38:07 -08:00
|
|
|
|
|
|
|
nsresult
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILTimeValueSpec::SetSpec(const nsAString& aStringSpec,
|
2010-08-18 03:20:24 -07:00
|
|
|
Element* aContextNode)
|
2009-01-14 20:38:07 -08:00
|
|
|
{
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILTimeValueSpecParams params;
|
|
|
|
nsresult rv =
|
|
|
|
nsSMILParserUtils::ParseTimeValueSpecParams(aStringSpec, params);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2011-11-23 19:02:43 -08:00
|
|
|
mParams = params;
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
// According to SMIL 3.0:
|
|
|
|
// The special value "indefinite" does not yield an instance time in the
|
|
|
|
// begin list. It will, however yield a single instance with the value
|
|
|
|
// "indefinite" in an end list. This value is not removed by a reset.
|
2011-11-23 19:02:43 -08:00
|
|
|
if (mParams.mType == nsSMILTimeValueSpecParams::OFFSET ||
|
|
|
|
(!mIsBegin && mParams.mType == nsSMILTimeValueSpecParams::INDEFINITE)) {
|
|
|
|
mOwner->AddInstanceTime(new nsSMILInstanceTime(mParams.mOffset), mIsBegin);
|
2009-01-14 20:38:07 -08:00
|
|
|
}
|
|
|
|
|
2010-08-18 03:20:24 -07:00
|
|
|
// Fill in the event symbol to simplify handling later
|
2011-11-23 19:02:43 -08:00
|
|
|
if (mParams.mType == nsSMILTimeValueSpecParams::REPEAT) {
|
|
|
|
mParams.mEventSymbol = nsGkAtoms::repeatEvent;
|
|
|
|
} else if (mParams.mType == nsSMILTimeValueSpecParams::ACCESSKEY) {
|
|
|
|
mParams.mEventSymbol = nsGkAtoms::keypress;
|
2010-08-18 03:20:24 -07:00
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
ResolveReferences(aContextNode);
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
return rv;
|
|
|
|
}
|
2010-01-12 12:00:49 -08:00
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimeValueSpec::ResolveReferences(nsIContent* aContextNode)
|
|
|
|
{
|
2010-08-27 23:41:05 -07:00
|
|
|
if (mParams.mType != nsSMILTimeValueSpecParams::SYNCBASE && !IsEventBased())
|
2010-01-12 12:00:49 -08:00
|
|
|
return;
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(aContextNode,
|
|
|
|
"null context node for resolving timing references against");
|
|
|
|
|
|
|
|
// If we're not bound to the document yet, don't worry, we'll get called again
|
|
|
|
// when that happens
|
|
|
|
if (!aContextNode->IsInDoc())
|
|
|
|
return;
|
|
|
|
|
2010-08-18 03:20:24 -07:00
|
|
|
// Hold ref to the old element so that it isn't destroyed in between resetting
|
2010-08-18 03:20:24 -07:00
|
|
|
// the referenced element and using the pointer to update the referenced
|
|
|
|
// element.
|
2010-08-18 03:20:24 -07:00
|
|
|
nsRefPtr<Element> oldReferencedElement = mReferencedElement.get();
|
2010-01-12 12:00:49 -08:00
|
|
|
|
2010-08-18 03:20:24 -07:00
|
|
|
if (mParams.mDependentElemID) {
|
|
|
|
mReferencedElement.ResetWithID(aContextNode,
|
|
|
|
nsDependentAtomString(mParams.mDependentElemID));
|
2010-08-18 03:20:24 -07:00
|
|
|
} else if (mParams.mType == nsSMILTimeValueSpecParams::EVENT) {
|
2010-08-18 03:20:24 -07:00
|
|
|
Element* target = mOwner->GetTargetElement();
|
|
|
|
mReferencedElement.ResetWithElement(target);
|
2010-08-27 23:41:05 -07:00
|
|
|
} else if (mParams.mType == nsSMILTimeValueSpecParams::ACCESSKEY) {
|
|
|
|
nsIDocument* doc = aContextNode->GetCurrentDoc();
|
|
|
|
NS_ABORT_IF_FALSE(doc, "We are in the document but current doc is null");
|
|
|
|
mReferencedElement.ResetWithElement(doc->GetRootElement());
|
2010-08-18 03:20:24 -07:00
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ABORT_IF_FALSE(false, "Syncbase or repeat spec without ID");
|
2010-08-18 03:20:24 -07:00
|
|
|
}
|
2010-08-18 03:20:24 -07:00
|
|
|
UpdateReferencedElement(oldReferencedElement, mReferencedElement.get());
|
2010-08-18 03:20:24 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-08-18 03:20:24 -07:00
|
|
|
nsSMILTimeValueSpec::IsEventBased() const
|
|
|
|
{
|
|
|
|
return mParams.mType == nsSMILTimeValueSpecParams::EVENT ||
|
|
|
|
mParams.mType == nsSMILTimeValueSpecParams::REPEAT ||
|
|
|
|
mParams.mType == nsSMILTimeValueSpecParams::ACCESSKEY;
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-03-01 11:31:50 -08:00
|
|
|
nsSMILTimeValueSpec::HandleNewInterval(nsSMILInterval& aInterval,
|
2010-01-12 12:00:49 -08:00
|
|
|
const nsSMILTimeContainer* aSrcContainer)
|
|
|
|
{
|
|
|
|
const nsSMILInstanceTime& baseInstance = mParams.mSyncBegin
|
|
|
|
? *aInterval.Begin() : *aInterval.End();
|
|
|
|
nsSMILTimeValue newTime =
|
|
|
|
ConvertBetweenTimeContainers(baseInstance.Time(), aSrcContainer);
|
|
|
|
|
|
|
|
// Apply offset
|
2011-11-15 11:56:32 -08:00
|
|
|
if (!ApplyOffset(newTime)) {
|
|
|
|
NS_WARNING("New time overflows nsSMILTime, ignoring");
|
|
|
|
return;
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
|
|
|
|
2010-03-01 11:31:50 -08:00
|
|
|
// Create the instance time and register it with the interval
|
2010-01-12 12:00:49 -08:00
|
|
|
nsRefPtr<nsSMILInstanceTime> newInstance =
|
2010-03-01 11:31:50 -08:00
|
|
|
new nsSMILInstanceTime(newTime, nsSMILInstanceTime::SOURCE_SYNCBASE, this,
|
|
|
|
&aInterval);
|
2010-01-12 12:00:49 -08:00
|
|
|
mOwner->AddInstanceTime(newInstance, mIsBegin);
|
|
|
|
}
|
|
|
|
|
2010-08-18 03:20:24 -07:00
|
|
|
void
|
|
|
|
nsSMILTimeValueSpec::HandleTargetElementChange(Element* aNewTarget)
|
|
|
|
{
|
|
|
|
if (!IsEventBased() || mParams.mDependentElemID)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mReferencedElement.ResetWithElement(aNewTarget);
|
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
void
|
2010-03-01 11:31:50 -08:00
|
|
|
nsSMILTimeValueSpec::HandleChangedInstanceTime(
|
|
|
|
const nsSMILInstanceTime& aBaseTime,
|
|
|
|
const nsSMILTimeContainer* aSrcContainer,
|
|
|
|
nsSMILInstanceTime& aInstanceTimeToUpdate,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aObjectChanged)
|
2010-01-12 12:00:49 -08:00
|
|
|
{
|
2010-03-01 11:31:50 -08:00
|
|
|
// If the instance time is fixed (e.g. because it's being used as the begin
|
2010-07-02 22:52:50 -07:00
|
|
|
// time of an active or postactive interval) we just ignore the change.
|
|
|
|
if (aInstanceTimeToUpdate.IsFixedTime())
|
2010-01-12 12:00:49 -08:00
|
|
|
return;
|
|
|
|
|
|
|
|
nsSMILTimeValue updatedTime =
|
2010-03-01 11:31:50 -08:00
|
|
|
ConvertBetweenTimeContainers(aBaseTime.Time(), aSrcContainer);
|
2010-01-12 12:00:49 -08:00
|
|
|
|
|
|
|
// Apply offset
|
2011-11-15 11:56:32 -08:00
|
|
|
if (!ApplyOffset(updatedTime)) {
|
|
|
|
NS_WARNING("Updated time overflows nsSMILTime, ignoring");
|
|
|
|
return;
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// The timed element that owns the instance time does the updating so it can
|
|
|
|
// re-sort its array of instance times more efficiently
|
2010-03-01 11:31:50 -08:00
|
|
|
if (aInstanceTimeToUpdate.Time() != updatedTime || aObjectChanged) {
|
|
|
|
mOwner->UpdateInstanceTime(&aInstanceTimeToUpdate, updatedTime, mIsBegin);
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-03-01 11:31:50 -08:00
|
|
|
nsSMILTimeValueSpec::HandleDeletedInstanceTime(
|
|
|
|
nsSMILInstanceTime &aInstanceTime)
|
2010-01-12 12:00:49 -08:00
|
|
|
{
|
2010-03-01 11:31:50 -08:00
|
|
|
mOwner->RemoveInstanceTime(&aInstanceTime, mIsBegin);
|
|
|
|
}
|
2010-01-12 12:00:49 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-03-01 11:31:50 -08:00
|
|
|
nsSMILTimeValueSpec::DependsOnBegin() const
|
|
|
|
{
|
|
|
|
return mParams.mSyncBegin;
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimeValueSpec::Traverse(nsCycleCollectionTraversalCallback* aCallback)
|
|
|
|
{
|
2010-08-18 03:20:24 -07:00
|
|
|
mReferencedElement.Traverse(aCallback);
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimeValueSpec::Unlink()
|
|
|
|
{
|
2010-08-18 03:20:24 -07:00
|
|
|
UnregisterFromReferencedElement(mReferencedElement.get());
|
|
|
|
mReferencedElement.Unlink();
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation helpers
|
|
|
|
|
|
|
|
void
|
2010-08-18 03:20:24 -07:00
|
|
|
nsSMILTimeValueSpec::UpdateReferencedElement(Element* aFrom, Element* aTo)
|
2010-01-12 12:00:49 -08:00
|
|
|
{
|
|
|
|
if (aFrom == aTo)
|
|
|
|
return;
|
|
|
|
|
2010-08-18 03:20:24 -07:00
|
|
|
UnregisterFromReferencedElement(aFrom);
|
2010-01-12 12:00:49 -08:00
|
|
|
|
2010-08-18 03:20:24 -07:00
|
|
|
switch (mParams.mType)
|
|
|
|
{
|
|
|
|
case nsSMILTimeValueSpecParams::SYNCBASE:
|
|
|
|
{
|
|
|
|
nsSMILTimedElement* to = GetTimedElement(aTo);
|
|
|
|
if (to) {
|
|
|
|
to->AddDependent(*this);
|
|
|
|
}
|
2010-08-18 03:20:24 -07:00
|
|
|
}
|
2010-08-18 03:20:24 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsSMILTimeValueSpecParams::EVENT:
|
|
|
|
case nsSMILTimeValueSpecParams::REPEAT:
|
2010-08-27 23:41:05 -07:00
|
|
|
case nsSMILTimeValueSpecParams::ACCESSKEY:
|
2010-08-18 03:20:24 -07:00
|
|
|
RegisterEventListener(aTo);
|
2010-08-18 03:20:24 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2010-08-27 23:41:05 -07:00
|
|
|
// not a referencing-type
|
2010-08-18 03:20:24 -07:00
|
|
|
break;
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-08-18 03:20:24 -07:00
|
|
|
nsSMILTimeValueSpec::UnregisterFromReferencedElement(Element* aElement)
|
2010-01-12 12:00:49 -08:00
|
|
|
{
|
2010-08-18 03:20:24 -07:00
|
|
|
if (!aElement)
|
2010-01-12 12:00:49 -08:00
|
|
|
return;
|
|
|
|
|
2010-08-18 03:20:24 -07:00
|
|
|
if (mParams.mType == nsSMILTimeValueSpecParams::SYNCBASE) {
|
2010-08-18 03:20:24 -07:00
|
|
|
nsSMILTimedElement* timedElement = GetTimedElement(aElement);
|
2010-08-18 03:20:24 -07:00
|
|
|
if (timedElement) {
|
|
|
|
timedElement->RemoveDependent(*this);
|
|
|
|
}
|
|
|
|
mOwner->RemoveInstanceTimesForCreator(this, mIsBegin);
|
2010-08-18 03:20:24 -07:00
|
|
|
} else if (IsEventBased()) {
|
2010-08-18 03:20:24 -07:00
|
|
|
UnregisterEventListener(aElement);
|
2010-08-18 03:20:24 -07:00
|
|
|
}
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILTimedElement*
|
2010-08-18 03:20:24 -07:00
|
|
|
nsSMILTimeValueSpec::GetTimedElement(Element* aElement)
|
2010-01-12 12:00:49 -08:00
|
|
|
{
|
2010-08-18 03:20:24 -07:00
|
|
|
if (!aElement)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-01-12 12:00:49 -08:00
|
|
|
|
2010-08-18 03:20:24 -07:00
|
|
|
nsCOMPtr<nsISMILAnimationElement> animElement = do_QueryInterface(aElement);
|
2010-01-12 12:00:49 -08:00
|
|
|
if (!animElement)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-01-12 12:00:49 -08:00
|
|
|
|
|
|
|
return &animElement->TimedElement();
|
|
|
|
}
|
|
|
|
|
2011-12-08 13:34:07 -08:00
|
|
|
// Indicates whether we're allowed to register an event-listener
|
|
|
|
// when scripting is disabled.
|
|
|
|
bool
|
|
|
|
nsSMILTimeValueSpec::IsWhitelistedEvent()
|
|
|
|
{
|
|
|
|
// The category of (SMIL-specific) "repeat(n)" events are allowed.
|
|
|
|
if (mParams.mType == nsSMILTimeValueSpecParams::REPEAT) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A specific list of other SMIL-related events are allowed, too.
|
|
|
|
if (mParams.mType == nsSMILTimeValueSpecParams::EVENT &&
|
|
|
|
(mParams.mEventSymbol == nsGkAtoms::repeat ||
|
2011-12-08 17:39:59 -08:00
|
|
|
mParams.mEventSymbol == nsGkAtoms::repeatEvent ||
|
|
|
|
mParams.mEventSymbol == nsGkAtoms::beginEvent ||
|
|
|
|
mParams.mEventSymbol == nsGkAtoms::endEvent)) {
|
2011-12-08 13:34:07 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-18 03:20:24 -07:00
|
|
|
void
|
2010-08-18 03:20:24 -07:00
|
|
|
nsSMILTimeValueSpec::RegisterEventListener(Element* aTarget)
|
2010-01-12 12:00:49 -08:00
|
|
|
{
|
2010-08-27 23:41:05 -07:00
|
|
|
NS_ABORT_IF_FALSE(IsEventBased(),
|
2010-08-18 03:20:24 -07:00
|
|
|
"Attempting to register event-listener for unexpected nsSMILTimeValueSpec"
|
|
|
|
" type");
|
2010-08-18 03:20:24 -07:00
|
|
|
NS_ABORT_IF_FALSE(mParams.mEventSymbol,
|
|
|
|
"Attempting to register event-listener but there is no event name");
|
|
|
|
|
|
|
|
if (!aTarget)
|
|
|
|
return;
|
|
|
|
|
2011-12-08 13:34:07 -08:00
|
|
|
// When script is disabled, only allow registration for whitelisted events.
|
|
|
|
if (!aTarget->GetOwnerDocument()->IsScriptEnabled() &&
|
|
|
|
!IsWhitelistedEvent()) {
|
2011-11-23 17:49:26 -08:00
|
|
|
return;
|
2011-12-08 13:34:07 -08:00
|
|
|
}
|
2011-11-23 17:49:26 -08:00
|
|
|
|
2010-08-18 03:20:24 -07:00
|
|
|
if (!mEventListener) {
|
|
|
|
mEventListener = new EventListener(this);
|
|
|
|
}
|
|
|
|
|
2011-06-23 19:18:02 -07:00
|
|
|
nsEventListenerManager* elm = GetEventListenerManager(aTarget);
|
2010-08-18 03:20:24 -07:00
|
|
|
if (!elm)
|
|
|
|
return;
|
2011-11-15 11:56:32 -08:00
|
|
|
|
2010-08-18 03:20:24 -07:00
|
|
|
elm->AddEventListenerByType(mEventListener,
|
|
|
|
nsDependentAtomString(mParams.mEventSymbol),
|
2012-12-15 17:26:05 -08:00
|
|
|
AllEventsAtSystemGroupBubble());
|
2010-08-18 03:20:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-08-18 03:20:24 -07:00
|
|
|
nsSMILTimeValueSpec::UnregisterEventListener(Element* aTarget)
|
2010-08-18 03:20:24 -07:00
|
|
|
{
|
|
|
|
if (!aTarget || !mEventListener)
|
|
|
|
return;
|
|
|
|
|
2011-06-23 19:18:02 -07:00
|
|
|
nsEventListenerManager* elm = GetEventListenerManager(aTarget);
|
2010-08-18 03:20:24 -07:00
|
|
|
if (!elm)
|
|
|
|
return;
|
|
|
|
|
|
|
|
elm->RemoveEventListenerByType(mEventListener,
|
|
|
|
nsDependentAtomString(mParams.mEventSymbol),
|
2012-12-15 17:26:05 -08:00
|
|
|
AllEventsAtSystemGroupBubble());
|
2010-08-18 03:20:24 -07:00
|
|
|
}
|
|
|
|
|
2011-06-23 19:18:01 -07:00
|
|
|
nsEventListenerManager*
|
2011-06-23 19:18:02 -07:00
|
|
|
nsSMILTimeValueSpec::GetEventListenerManager(Element* aTarget)
|
2010-08-18 03:20:24 -07:00
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aTarget, "null target; can't get EventListenerManager");
|
|
|
|
|
2011-06-23 19:18:01 -07:00
|
|
|
nsCOMPtr<nsIDOMEventTarget> target;
|
2010-08-27 23:41:05 -07:00
|
|
|
|
|
|
|
if (mParams.mType == nsSMILTimeValueSpecParams::ACCESSKEY) {
|
|
|
|
nsIDocument* doc = aTarget->GetCurrentDoc();
|
|
|
|
if (!doc)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-08-27 23:41:05 -07:00
|
|
|
nsPIDOMWindow* win = doc->GetWindow();
|
|
|
|
if (!win)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-06-23 19:18:01 -07:00
|
|
|
target = do_QueryInterface(win);
|
2010-08-27 23:41:05 -07:00
|
|
|
} else {
|
2011-06-23 19:18:01 -07:00
|
|
|
target = aTarget;
|
2010-08-27 23:41:05 -07:00
|
|
|
}
|
2011-06-23 19:18:01 -07:00
|
|
|
if (!target)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-08-27 23:41:05 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return target->GetListenerManager(true);
|
2010-08-18 03:20:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSMILTimeValueSpec::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(mEventListener, "Got event without an event listener");
|
2010-08-18 03:20:24 -07:00
|
|
|
NS_ABORT_IF_FALSE(IsEventBased(),
|
|
|
|
"Got event for non-event nsSMILTimeValueSpec");
|
|
|
|
NS_ABORT_IF_FALSE(aEvent, "No event supplied");
|
2010-08-18 03:20:24 -07:00
|
|
|
|
|
|
|
// XXX In the long run we should get the time from the event itself which will
|
|
|
|
// store the time in global document time which we'll need to convert to our
|
|
|
|
// time container
|
|
|
|
nsSMILTimeContainer* container = mOwner->GetTimeContainer();
|
|
|
|
if (!container)
|
|
|
|
return;
|
|
|
|
|
2010-08-18 03:20:24 -07:00
|
|
|
if (!CheckEventDetail(aEvent))
|
|
|
|
return;
|
|
|
|
|
2010-08-18 03:20:24 -07:00
|
|
|
nsSMILTime currentTime = container->GetCurrentTime();
|
2011-11-15 11:56:32 -08:00
|
|
|
nsSMILTimeValue newTime(currentTime);
|
|
|
|
if (!ApplyOffset(newTime)) {
|
|
|
|
NS_WARNING("New time generated from event overflows nsSMILTime, ignoring");
|
|
|
|
return;
|
|
|
|
}
|
2010-08-18 03:20:24 -07:00
|
|
|
|
|
|
|
nsRefPtr<nsSMILInstanceTime> newInstance =
|
|
|
|
new nsSMILInstanceTime(newTime, nsSMILInstanceTime::SOURCE_EVENT);
|
|
|
|
mOwner->AddInstanceTime(newInstance, mIsBegin);
|
2010-01-12 12:00:49 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-08-18 03:20:24 -07:00
|
|
|
nsSMILTimeValueSpec::CheckEventDetail(nsIDOMEvent *aEvent)
|
|
|
|
{
|
2010-08-27 23:41:05 -07:00
|
|
|
switch (mParams.mType)
|
|
|
|
{
|
|
|
|
case nsSMILTimeValueSpecParams::REPEAT:
|
|
|
|
return CheckRepeatEventDetail(aEvent);
|
|
|
|
|
|
|
|
case nsSMILTimeValueSpecParams::ACCESSKEY:
|
|
|
|
return CheckAccessKeyEventDetail(aEvent);
|
|
|
|
|
|
|
|
default:
|
|
|
|
// nothing to check
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-08-27 23:41:05 -07:00
|
|
|
}
|
|
|
|
}
|
2010-08-18 03:20:24 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-08-27 23:41:05 -07:00
|
|
|
nsSMILTimeValueSpec::CheckRepeatEventDetail(nsIDOMEvent *aEvent)
|
|
|
|
{
|
2010-08-18 03:20:24 -07:00
|
|
|
nsCOMPtr<nsIDOMTimeEvent> timeEvent = do_QueryInterface(aEvent);
|
|
|
|
if (!timeEvent) {
|
|
|
|
NS_WARNING("Received a repeat event that was not a DOMTimeEvent");
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-18 03:20:24 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t detail;
|
2010-08-18 03:20:24 -07:00
|
|
|
timeEvent->GetDetail(&detail);
|
2012-08-22 08:56:38 -07:00
|
|
|
return detail > 0 && (uint32_t)detail == mParams.mRepeatIterationOrAccessKey;
|
2010-08-27 23:41:05 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-08-27 23:41:05 -07:00
|
|
|
nsSMILTimeValueSpec::CheckAccessKeyEventDetail(nsIDOMEvent *aEvent)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aEvent);
|
|
|
|
if (!keyEvent) {
|
|
|
|
NS_WARNING("Received an accesskey event that was not a DOMKeyEvent");
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-27 23:41:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore the key event if any modifier keys are pressed UNLESS we're matching
|
|
|
|
// on the charCode in which case we ignore the state of the shift and alt keys
|
|
|
|
// since they might be needed to generate the character in question.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isCtrl;
|
|
|
|
bool isMeta;
|
2010-08-27 23:41:05 -07:00
|
|
|
keyEvent->GetCtrlKey(&isCtrl);
|
|
|
|
keyEvent->GetMetaKey(&isMeta);
|
|
|
|
if (isCtrl || isMeta)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-27 23:41:05 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t code;
|
2010-08-27 23:41:05 -07:00
|
|
|
keyEvent->GetCharCode(&code);
|
|
|
|
if (code)
|
|
|
|
return code == mParams.mRepeatIterationOrAccessKey;
|
|
|
|
|
|
|
|
// Only match on the keyCode if it corresponds to some ASCII character that
|
|
|
|
// does not produce a charCode.
|
|
|
|
// In this case we can safely bail out if either alt or shift is pressed since
|
|
|
|
// they won't already be incorporated into the keyCode unlike the charCode.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isAlt;
|
|
|
|
bool isShift;
|
2010-08-27 23:41:05 -07:00
|
|
|
keyEvent->GetAltKey(&isAlt);
|
|
|
|
keyEvent->GetShiftKey(&isShift);
|
|
|
|
if (isAlt || isShift)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-27 23:41:05 -07:00
|
|
|
|
|
|
|
keyEvent->GetKeyCode(&code);
|
|
|
|
switch (code)
|
|
|
|
{
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_BACK_SPACE:
|
|
|
|
return mParams.mRepeatIterationOrAccessKey == 0x08;
|
|
|
|
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_RETURN:
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_ENTER:
|
|
|
|
return mParams.mRepeatIterationOrAccessKey == 0x0A ||
|
|
|
|
mParams.mRepeatIterationOrAccessKey == 0x0D;
|
|
|
|
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_ESCAPE:
|
|
|
|
return mParams.mRepeatIterationOrAccessKey == 0x1B;
|
|
|
|
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_DELETE:
|
|
|
|
return mParams.mRepeatIterationOrAccessKey == 0x7F;
|
|
|
|
|
|
|
|
default:
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-27 23:41:05 -07:00
|
|
|
}
|
2010-08-18 03:20:24 -07:00
|
|
|
}
|
|
|
|
|
2010-01-12 12:00:49 -08:00
|
|
|
nsSMILTimeValue
|
|
|
|
nsSMILTimeValueSpec::ConvertBetweenTimeContainers(
|
|
|
|
const nsSMILTimeValue& aSrcTime,
|
|
|
|
const nsSMILTimeContainer* aSrcContainer)
|
|
|
|
{
|
|
|
|
// If the source time is either indefinite or unresolved the result is going
|
|
|
|
// to be the same
|
2011-09-06 17:20:40 -07:00
|
|
|
if (!aSrcTime.IsDefinite())
|
2010-01-12 12:00:49 -08:00
|
|
|
return aSrcTime;
|
|
|
|
|
|
|
|
// Convert from source time container to our parent time container
|
|
|
|
const nsSMILTimeContainer* dstContainer = mOwner->GetTimeContainer();
|
|
|
|
if (dstContainer == aSrcContainer)
|
|
|
|
return aSrcTime;
|
|
|
|
|
|
|
|
// If one of the elements is not attached to a time container then we can't do
|
|
|
|
// any meaningful conversion
|
|
|
|
if (!aSrcContainer || !dstContainer)
|
|
|
|
return nsSMILTimeValue(); // unresolved
|
|
|
|
|
|
|
|
nsSMILTimeValue docTime =
|
|
|
|
aSrcContainer->ContainerToParentTime(aSrcTime.GetMillis());
|
|
|
|
|
|
|
|
if (docTime.IsIndefinite())
|
|
|
|
// This will happen if the source container is paused and we have a future
|
|
|
|
// time. Just return the indefinite time.
|
|
|
|
return docTime;
|
|
|
|
|
2011-09-06 17:20:40 -07:00
|
|
|
NS_ABORT_IF_FALSE(docTime.IsDefinite(),
|
2011-09-06 17:20:40 -07:00
|
|
|
"ContainerToParentTime gave us an unresolved or indefinite time");
|
2010-01-12 12:00:49 -08:00
|
|
|
|
|
|
|
return dstContainer->ParentToContainerTime(docTime.GetMillis());
|
|
|
|
}
|
2011-11-15 11:56:32 -08:00
|
|
|
|
|
|
|
bool
|
|
|
|
nsSMILTimeValueSpec::ApplyOffset(nsSMILTimeValue& aTime) const
|
|
|
|
{
|
|
|
|
// indefinite + offset = indefinite. Likewise for unresolved times.
|
|
|
|
if (!aTime.IsDefinite()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
double resultAsDouble =
|
|
|
|
(double)aTime.GetMillis() + mParams.mOffset.GetMillis();
|
|
|
|
if (resultAsDouble > std::numeric_limits<nsSMILTime>::max() ||
|
|
|
|
resultAsDouble < std::numeric_limits<nsSMILTime>::min()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aTime.SetMillis(aTime.GetMillis() + mParams.mOffset.GetMillis());
|
|
|
|
return true;
|
|
|
|
}
|