Bug 864145 - Cleanup nsDOMTouchEvent's TouchList getters; r=smaug

This commit is contained in:
Ms2ger 2013-04-26 08:48:00 +02:00
parent f25020c780
commit 6739364f0a
4 changed files with 70 additions and 80 deletions

View File

@ -143,9 +143,9 @@ nsDOMTouchEvent::InitTouchEvent(const nsAString& aType,
static_cast<nsInputEvent*>(mEvent)->InitBasicModifiers(aCtrlKey, aAltKey,
aShiftKey, aMetaKey);
mTouches = aTouches;
mTargetTouches = aTargetTouches;
mChangedTouches = aChangedTouches;
mTouches = static_cast<nsDOMTouchList*>(aTouches);
mTargetTouches = static_cast<nsDOMTouchList*>(aTargetTouches);
mChangedTouches = static_cast<nsDOMTouchList*>(aChangedTouches);
return NS_OK;
}
@ -153,79 +153,86 @@ NS_IMETHODIMP
nsDOMTouchEvent::GetTouches(nsIDOMTouchList** aTouches)
{
NS_ENSURE_ARG_POINTER(aTouches);
NS_ENSURE_STATE(mEvent);
nsRefPtr<nsDOMTouchList> t;
NS_ADDREF(*aTouches = Touches());
return NS_OK;
}
if (mTouches) {
return CallQueryInterface(mTouches, aTouches);
}
nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(mEvent);
if (mEvent->message == NS_TOUCH_END || mEvent->message == NS_TOUCH_CANCEL) {
// for touchend events, remove any changed touches from the touches array
nsTArray<nsCOMPtr<nsIDOMTouch> > unchangedTouches;
const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
for (uint32_t i = 0; i < touches.Length(); ++i) {
if (!touches[i]->mChanged) {
unchangedTouches.AppendElement(touches[i]);
nsDOMTouchList*
nsDOMTouchEvent::Touches()
{
if (!mTouches) {
nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(mEvent);
if (mEvent->message == NS_TOUCH_END || mEvent->message == NS_TOUCH_CANCEL) {
// for touchend events, remove any changed touches from the touches array
nsTArray<nsCOMPtr<nsIDOMTouch> > unchangedTouches;
const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
for (uint32_t i = 0; i < touches.Length(); ++i) {
if (!touches[i]->mChanged) {
unchangedTouches.AppendElement(touches[i]);
}
}
mTouches = new nsDOMTouchList(unchangedTouches);
} else {
mTouches = new nsDOMTouchList(touchEvent->touches);
}
t = new nsDOMTouchList(unchangedTouches);
} else {
t = new nsDOMTouchList(touchEvent->touches);
}
mTouches = t;
return CallQueryInterface(mTouches, aTouches);
return mTouches;
}
NS_IMETHODIMP
nsDOMTouchEvent::GetTargetTouches(nsIDOMTouchList** aTargetTouches)
{
NS_ENSURE_ARG_POINTER(aTargetTouches);
NS_ENSURE_STATE(mEvent);
NS_ADDREF(*aTargetTouches = TargetTouches());
return NS_OK;
}
if (mTargetTouches) {
return CallQueryInterface(mTargetTouches, aTargetTouches);
}
nsTArray<nsCOMPtr<nsIDOMTouch> > targetTouches;
nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(mEvent);
const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
for (uint32_t i = 0; i < touches.Length(); ++i) {
// for touchend/cancel events, don't append to the target list if this is a
// touch that is ending
if ((mEvent->message != NS_TOUCH_END &&
mEvent->message != NS_TOUCH_CANCEL) || !touches[i]->mChanged) {
EventTarget* targetPtr = touches[i]->GetTarget();
if (targetPtr == mEvent->originalTarget) {
targetTouches.AppendElement(touches[i]);
nsDOMTouchList*
nsDOMTouchEvent::TargetTouches()
{
if (!mTargetTouches) {
nsTArray<nsCOMPtr<nsIDOMTouch> > targetTouches;
nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(mEvent);
const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
for (uint32_t i = 0; i < touches.Length(); ++i) {
// for touchend/cancel events, don't append to the target list if this is a
// touch that is ending
if ((mEvent->message != NS_TOUCH_END &&
mEvent->message != NS_TOUCH_CANCEL) || !touches[i]->mChanged) {
EventTarget* targetPtr = touches[i]->GetTarget();
if (targetPtr == mEvent->originalTarget) {
targetTouches.AppendElement(touches[i]);
}
}
}
mTargetTouches = new nsDOMTouchList(targetTouches);
}
mTargetTouches = new nsDOMTouchList(targetTouches);
return CallQueryInterface(mTargetTouches, aTargetTouches);
return mTargetTouches;
}
NS_IMETHODIMP
nsDOMTouchEvent::GetChangedTouches(nsIDOMTouchList** aChangedTouches)
{
NS_ENSURE_ARG_POINTER(aChangedTouches);
NS_ENSURE_STATE(mEvent);
NS_ADDREF(*aChangedTouches = ChangedTouches());
return NS_OK;
}
if (mChangedTouches) {
return CallQueryInterface(mChangedTouches, aChangedTouches);
}
nsTArray<nsCOMPtr<nsIDOMTouch> > changedTouches;
nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(mEvent);
const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
for (uint32_t i = 0; i < touches.Length(); ++i) {
if (touches[i]->mChanged) {
changedTouches.AppendElement(touches[i]);
nsDOMTouchList*
nsDOMTouchEvent::ChangedTouches()
{
if (!mChangedTouches) {
nsTArray<nsCOMPtr<nsIDOMTouch> > changedTouches;
nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(mEvent);
const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
for (uint32_t i = 0; i < touches.Length(); ++i) {
if (touches[i]->mChanged) {
changedTouches.AppendElement(touches[i]);
}
}
mChangedTouches = new nsDOMTouchList(changedTouches);
}
mChangedTouches = new nsDOMTouchList(changedTouches);
return CallQueryInterface(mChangedTouches, aChangedTouches);
return mChangedTouches;
}
NS_IMETHODIMP

View File

@ -60,26 +60,9 @@ public:
return mozilla::dom::TouchEventBinding::Wrap(aCx, aScope, this);
}
already_AddRefed<nsIDOMTouchList> GetTouches()
{
nsCOMPtr<nsIDOMTouchList> t;
GetTouches(getter_AddRefs(t));
return t.forget();
}
already_AddRefed<nsIDOMTouchList> GetTargetTouches()
{
nsCOMPtr<nsIDOMTouchList> t;
GetTargetTouches(getter_AddRefs(t));
return t.forget();
}
already_AddRefed<nsIDOMTouchList> GetChangedTouches()
{
nsCOMPtr<nsIDOMTouchList> t;
GetChangedTouches(getter_AddRefs(t));
return t.forget();
}
nsDOMTouchList* Touches();
nsDOMTouchList* TargetTouches();
nsDOMTouchList* ChangedTouches();
bool AltKey()
{
@ -122,9 +105,9 @@ public:
static bool PrefEnabled();
protected:
nsCOMPtr<nsIDOMTouchList> mTouches;
nsCOMPtr<nsIDOMTouchList> mTargetTouches;
nsCOMPtr<nsIDOMTouchList> mChangedTouches;
nsRefPtr<nsDOMTouchList> mTouches;
nsRefPtr<nsDOMTouchList> mTargetTouches;
nsRefPtr<nsDOMTouchList> mChangedTouches;
};
#endif /* !defined(nsDOMTouchEvent_h_) */

View File

@ -38,7 +38,7 @@ interface nsIDOMTouch : nsISupports {
%}
};
[scriptable, uuid(60706eb7-d50d-4379-b01c-e78e6af84213)]
[scriptable, builtinclass, uuid(60706eb7-d50d-4379-b01c-e78e6af84213)]
interface nsIDOMTouchList : nsISupports {
readonly attribute unsigned long length;
nsIDOMTouch item(in unsigned long index);

View File

@ -9,9 +9,9 @@ interface WindowProxy;
[PrefControlled]
interface TouchEvent : UIEvent {
readonly attribute TouchList? touches;
readonly attribute TouchList? targetTouches;
readonly attribute TouchList? changedTouches;
readonly attribute TouchList touches;
readonly attribute TouchList targetTouches;
readonly attribute TouchList changedTouches;
readonly attribute boolean altKey;
readonly attribute boolean metaKey;