Bug 485157: SMIL event timing, part 4 refactor nsIContent usage to use mozilla::dom::Element instead, r=dholbert, sr=roc, a=roc

This commit is contained in:
Brian Birtles 2010-08-18 19:20:24 +09:00
parent b34a18028c
commit e5574fcbf1
9 changed files with 59 additions and 58 deletions

View File

@ -53,7 +53,6 @@ class nsISMILAttr;
class nsSMILAnimationFunction;
class nsSMILTimeContainer;
class nsSMILTimedElement;
class nsIContent;
class nsIAtom;
class nsAttrValue;
@ -75,14 +74,14 @@ public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISMILANIMATIONELEMENT_IID)
/*
* Returns this element as nsIContent.
* Returns this element as a mozilla::dom::Element.
*/
virtual const nsIContent& Content() const = 0;
virtual const mozilla::dom::Element& AsElement() const = 0;
/*
* Non-const version of Content()
* Non-const version of Element()
*/
virtual nsIContent& Content() = 0;
virtual mozilla::dom::Element& AsElement() = 0;
/*
* Returns the source attribute as an nsAttrValue. The global namespace will

View File

@ -324,8 +324,8 @@ nsSMILAnimationFunction::CompareTo(const nsSMILAnimationFunction* aOther) const
// Animations that appear later in the document sort after those earlier in
// the document
nsIContent& thisContent = mAnimationElement->Content();
nsIContent& otherContent = aOther->mAnimationElement->Content();
nsIContent& thisContent = mAnimationElement->AsElement();
nsIContent& otherContent = aOther->mAnimationElement->AsElement();
NS_ABORT_IF_FALSE(&thisContent != &otherContent,
"Two animations cannot have the same animation content element!");

View File

@ -49,6 +49,8 @@
#include "nsGUIEvent.h"
#include "nsString.h"
using namespace mozilla::dom;
//----------------------------------------------------------------------
// Nested class: EventListener
@ -95,7 +97,7 @@ nsSMILTimeValueSpec::~nsSMILTimeValueSpec()
nsresult
nsSMILTimeValueSpec::SetSpec(const nsAString& aStringSpec,
nsIContent* aContextNode)
Element* aContextNode)
{
nsSMILTimeValueSpecParams params;
nsresult rv =
@ -135,17 +137,17 @@ nsSMILTimeValueSpec::ResolveReferences(nsIContent* aContextNode)
if (!aContextNode->IsInDoc())
return;
// Hold ref to the old content so that it isn't destroyed in between resetting
// Hold ref to the old element so that it isn't destroyed in between resetting
// the referenced element and using the pointer to update the referenced
// element.
nsRefPtr<nsIContent> oldReferencedContent = mReferencedElement.get();
nsRefPtr<Element> oldReferencedElement = mReferencedElement.get();
// XXX Support default event targets
NS_ABORT_IF_FALSE(mParams.mDependentElemID, "NULL dependent element id");
nsString idStr;
mParams.mDependentElemID->ToString(idStr);
mReferencedElement.ResetWithID(aContextNode, idStr);
UpdateReferencedElement(oldReferencedContent, mReferencedElement.get());
UpdateReferencedElement(oldReferencedElement, mReferencedElement.get());
}
PRBool
@ -235,7 +237,7 @@ nsSMILTimeValueSpec::Unlink()
// Implementation helpers
void
nsSMILTimeValueSpec::UpdateReferencedElement(nsIContent* aFrom, nsIContent* aTo)
nsSMILTimeValueSpec::UpdateReferencedElement(Element* aFrom, Element* aTo)
{
if (aFrom == aTo)
return;
@ -243,7 +245,7 @@ nsSMILTimeValueSpec::UpdateReferencedElement(nsIContent* aFrom, nsIContent* aTo)
UnregisterFromReferencedElement(aFrom);
if (mParams.mType == nsSMILTimeValueSpecParams::SYNCBASE) {
nsSMILTimedElement* to = GetTimedElementFromContent(aTo);
nsSMILTimedElement* to = GetTimedElement(aTo);
if (to) {
to->AddDependent(*this);
}
@ -253,29 +255,29 @@ nsSMILTimeValueSpec::UpdateReferencedElement(nsIContent* aFrom, nsIContent* aTo)
}
void
nsSMILTimeValueSpec::UnregisterFromReferencedElement(nsIContent* aContent)
nsSMILTimeValueSpec::UnregisterFromReferencedElement(Element* aElement)
{
if (!aContent)
if (!aElement)
return;
if (mParams.mType == nsSMILTimeValueSpecParams::SYNCBASE) {
nsSMILTimedElement* timedElement = GetTimedElementFromContent(aContent);
nsSMILTimedElement* timedElement = GetTimedElement(aElement);
if (timedElement) {
timedElement->RemoveDependent(*this);
}
mOwner->RemoveInstanceTimesForCreator(this, mIsBegin);
} else if (mParams.mType == nsSMILTimeValueSpecParams::EVENT) {
UnregisterEventListener(aContent);
UnregisterEventListener(aElement);
}
}
nsSMILTimedElement*
nsSMILTimeValueSpec::GetTimedElementFromContent(nsIContent* aContent)
nsSMILTimeValueSpec::GetTimedElement(Element* aElement)
{
if (!aContent)
if (!aElement)
return nsnull;
nsCOMPtr<nsISMILAnimationElement> animElement = do_QueryInterface(aContent);
nsCOMPtr<nsISMILAnimationElement> animElement = do_QueryInterface(aElement);
if (!animElement)
return nsnull;
@ -283,7 +285,7 @@ nsSMILTimeValueSpec::GetTimedElementFromContent(nsIContent* aContent)
}
void
nsSMILTimeValueSpec::RegisterEventListener(nsIContent* aTarget)
nsSMILTimeValueSpec::RegisterEventListener(Element* aTarget)
{
NS_ABORT_IF_FALSE(mParams.mType == nsSMILTimeValueSpecParams::EVENT,
"Attempting to register event-listener for non-event nsSMILTimeValueSpec");
@ -312,7 +314,7 @@ nsSMILTimeValueSpec::RegisterEventListener(nsIContent* aTarget)
}
void
nsSMILTimeValueSpec::UnregisterEventListener(nsIContent* aTarget)
nsSMILTimeValueSpec::UnregisterEventListener(Element* aTarget)
{
if (!aTarget || !mEventListener)
return;
@ -331,7 +333,7 @@ nsSMILTimeValueSpec::UnregisterEventListener(nsIContent* aTarget)
}
nsIEventListenerManager*
nsSMILTimeValueSpec::GetEventListenerManager(nsIContent* aTarget,
nsSMILTimeValueSpec::GetEventListenerManager(Element* aTarget,
nsIDOMEventGroup** aSystemGroup)
{
NS_ABORT_IF_FALSE(aTarget, "null target; can't get EventListenerManager");

View File

@ -64,10 +64,12 @@ class nsSMILInterval;
class nsSMILTimeValueSpec
{
public:
typedef mozilla::dom::Element Element;
nsSMILTimeValueSpec(nsSMILTimedElement& aOwner, PRBool aIsBegin);
~nsSMILTimeValueSpec();
nsresult SetSpec(const nsAString& aStringSpec, nsIContent* aContextNode);
nsresult SetSpec(const nsAString& aStringSpec, Element* aContextNode);
void ResolveReferences(nsIContent* aContextNode);
PRBool IsEventBased() const;
@ -87,12 +89,12 @@ public:
void Unlink();
protected:
void UpdateReferencedElement(nsIContent* aFrom, nsIContent* aTo);
void UnregisterFromReferencedElement(nsIContent* aContent);
nsSMILTimedElement* GetTimedElementFromContent(nsIContent* aContent);
void RegisterEventListener(nsIContent* aTarget);
void UnregisterEventListener(nsIContent* aTarget);
nsIEventListenerManager* GetEventListenerManager(nsIContent* aTarget,
void UpdateReferencedElement(Element* aFrom, Element* aTo);
void UnregisterFromReferencedElement(Element* aElement);
nsSMILTimedElement* GetTimedElement(Element* aElement);
void RegisterEventListener(Element* aElement);
void UnregisterEventListener(Element* aElement);
nsIEventListenerManager* GetEventListenerManager(Element* aElement,
nsIDOMEventGroup** aSystemGroup);
void HandleEvent(nsIDOMEvent* aEvent);
nsSMILTimeValue ConvertBetweenTimeContainers(const nsSMILTimeValue& aSrcTime,

View File

@ -709,13 +709,13 @@ nsSMILTimedElement::Rewind()
if (mAnimationElement->HasAnimAttr(nsGkAtoms::begin)) {
nsAutoString attValue;
mAnimationElement->GetAnimAttr(nsGkAtoms::begin, attValue);
SetBeginSpec(attValue, &mAnimationElement->Content(), RemoveNonDynamic);
SetBeginSpec(attValue, &mAnimationElement->AsElement(), RemoveNonDynamic);
}
if (mAnimationElement->HasAnimAttr(nsGkAtoms::end)) {
nsAutoString attValue;
mAnimationElement->GetAnimAttr(nsGkAtoms::end, attValue);
SetEndSpec(attValue, &mAnimationElement->Content(), RemoveNonDynamic);
SetEndSpec(attValue, &mAnimationElement->AsElement(), RemoveNonDynamic);
}
mPrevRegisteredMilestone = sMaxMilestone;
@ -733,7 +733,8 @@ namespace
PRBool
nsSMILTimedElement::SetAttr(nsIAtom* aAttribute, const nsAString& aValue,
nsAttrValue& aResult, nsIContent* aContextNode,
nsAttrValue& aResult,
Element* aContextNode,
nsresult* aParseResult)
{
PRBool foundMatch = PR_TRUE;
@ -806,7 +807,7 @@ nsSMILTimedElement::UnsetAttr(nsIAtom* aAttribute)
nsresult
nsSMILTimedElement::SetBeginSpec(const nsAString& aBeginSpec,
nsIContent* aContextNode,
Element* aContextNode,
RemovalTestFunction aRemove)
{
return SetBeginOrEndSpec(aBeginSpec, aContextNode, PR_TRUE /*isBegin*/,
@ -822,7 +823,7 @@ nsSMILTimedElement::UnsetBeginSpec(RemovalTestFunction aRemove)
nsresult
nsSMILTimedElement::SetEndSpec(const nsAString& aEndSpec,
nsIContent* aContextNode,
Element* aContextNode,
RemovalTestFunction aRemove)
{
return SetBeginOrEndSpec(aEndSpec, aContextNode, PR_FALSE /*!isBegin*/,
@ -1105,17 +1106,12 @@ nsSMILTimedElement::BindToTree(nsIContent* aContextNode)
// Resolve references to other parts of the tree
PRUint32 count = mBeginSpecs.Length();
for (PRUint32 i = 0; i < count; ++i) {
nsSMILTimeValueSpec* beginSpec = mBeginSpecs[i];
NS_ABORT_IF_FALSE(beginSpec,
"null nsSMILTimeValueSpec in list of begin specs");
beginSpec->ResolveReferences(aContextNode);
mBeginSpecs[i]->ResolveReferences(aContextNode);
}
count = mEndSpecs.Length();
for (PRUint32 j = 0; j < count; ++j) {
nsSMILTimeValueSpec* endSpec = mEndSpecs[j];
NS_ABORT_IF_FALSE(endSpec, "null nsSMILTimeValueSpec in list of end specs");
endSpec->ResolveReferences(aContextNode);
mEndSpecs[j]->ResolveReferences(aContextNode);
}
// Clear any previous milestone since it might be been processed whilst we
@ -1168,7 +1164,7 @@ nsSMILTimedElement::Unlink()
nsresult
nsSMILTimedElement::SetBeginOrEndSpec(const nsAString& aSpec,
nsIContent* aContextNode,
Element* aContextNode,
PRBool aIsBegin,
RemovalTestFunction aRemove)
{
@ -2053,7 +2049,7 @@ nsSMILTimedElement::FireTimeEventAsync(PRUint32 aMsg, PRInt32 aDetail)
return;
nsCOMPtr<nsIRunnable> event =
new AsyncTimeEventRunner(&mAnimationElement->Content(), aMsg, aDetail);
new AsyncTimeEventRunner(&mAnimationElement->AsElement(), aMsg, aDetail);
NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);
}

View File

@ -65,6 +65,8 @@ public:
nsSMILTimedElement();
~nsSMILTimedElement();
typedef mozilla::dom::Element Element;
/*
* Sets the owning animation element which this class uses to convert between
* container times and to register timebase elements.
@ -249,8 +251,8 @@ public:
* @param aValue The attribute value.
* @param aResult The nsAttrValue object that may be used for storing the
* parsed result.
* @param aContextNode The node to use for context when resolving references
* to other elements.
* @param aContextNode The element to use for context when resolving
* references to other elements.
* @param[out] aParseResult The result of parsing the attribute. Will be set
* to NS_OK if parsing is successful.
*
@ -258,7 +260,7 @@ public:
* otherwise.
*/
PRBool SetAttr(nsIAtom* aAttribute, const nsAString& aValue,
nsAttrValue& aResult, nsIContent* aContextNode,
nsAttrValue& aResult, Element* aContextNode,
nsresult* aParseResult = nsnull);
/**
@ -360,10 +362,10 @@ protected:
//
nsresult SetBeginSpec(const nsAString& aBeginSpec,
nsIContent* aContextNode,
Element* aContextNode,
RemovalTestFunction aRemove);
nsresult SetEndSpec(const nsAString& aEndSpec,
nsIContent* aContextNode,
Element* aContextNode,
RemovalTestFunction aRemove);
nsresult SetSimpleDuration(const nsAString& aDurSpec);
nsresult SetMin(const nsAString& aMinSpec);
@ -384,7 +386,7 @@ protected:
void UnsetFillMode();
nsresult SetBeginOrEndSpec(const nsAString& aSpec,
nsIContent* aContextNode,
Element* aContextNode,
PRBool aIsBegin,
RemovalTestFunction aRemove);
void ClearSpecs(TimeValueSpecList& aSpecs,

View File

@ -346,7 +346,7 @@ SVGMotionSMILAnimationFunction::
// Do we have a mpath child? if so, it trumps everything. Otherwise, we look
// through our list of path-defining attributes, in order of priority.
nsSVGMpathElement* firstMpathChild =
GetFirstMpathChild(&mAnimationElement->Content());
GetFirstMpathChild(&mAnimationElement->AsElement());
if (firstMpathChild) {
RebuildPathAndVerticesFromMpathElem(firstMpathChild);

View File

@ -106,14 +106,14 @@ nsSVGAnimationElement::Init()
//----------------------------------------------------------------------
// nsISMILAnimationElement methods
const nsIContent&
nsSVGAnimationElement::Content() const
const Element&
nsSVGAnimationElement::AsElement() const
{
return *this;
}
nsIContent&
nsSVGAnimationElement::Content()
Element&
nsSVGAnimationElement::AsElement()
{
return *this;
}

View File

@ -86,12 +86,12 @@ public:
nsAttrValue& aResult);
// nsISMILAnimationElement interface
virtual const nsIContent& Content() const;
virtual nsIContent& Content();
virtual const Element& AsElement() const;
virtual Element& AsElement();
virtual const nsAttrValue* GetAnimAttr(nsIAtom* aName) const;
virtual PRBool GetAnimAttr(nsIAtom* aAttName, nsAString& aResult) const;
virtual PRBool HasAnimAttr(nsIAtom* aAttName) const;
virtual mozilla::dom::Element* GetTargetElementContent();
virtual Element* GetTargetElementContent();
virtual nsIAtom* GetTargetAttributeName() const;
virtual nsSMILTargetAttrType GetTargetAttributeType() const;
virtual nsSMILTimedElement& TimedElement();