Bug 1045978 Create InternalSVGZoomEvent class and InternalSMILTimeEvent class r=smaug

This commit is contained in:
Masayuki Nakano 2014-07-31 02:16:57 +09:00
parent a413355c9b
commit c7581f07b6
11 changed files with 107 additions and 49 deletions

View File

@ -5,7 +5,7 @@
#include <stdint.h>
#include "mozilla/ArrayUtils.h"
#include "mozilla/BasicEvents.h"
#include "mozilla/ContentEvents.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/Likely.h"
@ -518,11 +518,14 @@ SVGSVGElement::SetCurrentScaleTranslate(float s, float x, float y)
if (doc) {
nsCOMPtr<nsIPresShell> presShell = doc->GetShell();
if (presShell && IsRoot()) {
bool scaling = (mPreviousScale != mCurrentScale);
nsEventStatus status = nsEventStatus_eIgnore;
WidgetGUIEvent event(true, scaling ? NS_SVG_ZOOM : NS_SVG_SCROLL, 0);
event.eventStructType = scaling ? NS_SVGZOOM_EVENT : NS_EVENT;
presShell->HandleDOMEventWithTarget(this, &event, &status);
if (mPreviousScale != mCurrentScale) {
InternalSVGZoomEvent svgZoomEvent(true, NS_SVG_ZOOM);
presShell->HandleDOMEventWithTarget(this, &svgZoomEvent, &status);
} else {
WidgetEvent svgScrollEvent(true, NS_SVG_SCROLL);
presShell->HandleDOMEventWithTarget(this, &svgScrollEvent, &status);
}
InvalidateTransformNotifyFrame();
}
}

View File

@ -3,12 +3,13 @@
* 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/. */
#include "mozilla/dom/SVGZoomEvent.h"
#include "DOMSVGPoint.h"
#include "mozilla/dom/SVGSVGElement.h"
#include "nsIPresShell.h"
#include "nsIDocument.h"
#include "mozilla/ContentEvents.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/SVGSVGElement.h"
#include "mozilla/dom/SVGZoomEvent.h"
#include "nsIDocument.h"
#include "nsIPresShell.h"
#include "prtime.h"
namespace mozilla {
@ -27,9 +28,9 @@ NS_INTERFACE_MAP_END_INHERITING(UIEvent)
SVGZoomEvent::SVGZoomEvent(EventTarget* aOwner,
nsPresContext* aPresContext,
WidgetGUIEvent* aEvent)
InternalSVGZoomEvent* aEvent)
: UIEvent(aOwner, aPresContext,
aEvent ? aEvent : new WidgetGUIEvent(false, NS_SVG_ZOOM, 0))
aEvent ? aEvent : new InternalSVGZoomEvent(false, NS_SVG_ZOOM))
, mPreviousScale(0)
, mNewScale(0)
{
@ -38,12 +39,9 @@ SVGZoomEvent::SVGZoomEvent(EventTarget* aOwner,
}
else {
mEventIsInternal = true;
mEvent->eventStructType = NS_SVGZOOM_EVENT;
mEvent->time = PR_Now();
}
mEvent->mFlags.mCancelable = false;
// We must store the "Previous" and "New" values before this event is
// dispatched. Reading the values from the root 'svg' element after we've
// been dispatched is not an option since event handler code may change
@ -95,7 +93,7 @@ nsresult
NS_NewDOMSVGZoomEvent(nsIDOMEvent** aInstancePtrResult,
mozilla::dom::EventTarget* aOwner,
nsPresContext* aPresContext,
mozilla::WidgetGUIEvent* aEvent)
mozilla::InternalSVGZoomEvent* aEvent)
{
mozilla::dom::SVGZoomEvent* it =
new mozilla::dom::SVGZoomEvent(aOwner, aPresContext, aEvent);

View File

@ -28,7 +28,7 @@ public:
NS_DECL_ISUPPORTS_INHERITED
SVGZoomEvent(EventTarget* aOwner, nsPresContext* aPresContext,
WidgetGUIEvent* aEvent);
InternalSVGZoomEvent* aEvent);
// Forward to base class
NS_FORWARD_TO_UIEVENT

View File

@ -729,10 +729,10 @@ EventDispatcher::CreateEvent(EventTarget* aOwner,
aEvent->AsClipboardEvent());
case NS_SVGZOOM_EVENT:
return NS_NewDOMSVGZoomEvent(aDOMEvent, aOwner, aPresContext,
aEvent->AsGUIEvent());
aEvent->AsSVGZoomEvent());
case NS_SMIL_TIME_EVENT:
return NS_NewDOMTimeEvent(aDOMEvent, aOwner, aPresContext, aEvent);
return NS_NewDOMTimeEvent(aDOMEvent, aOwner, aPresContext,
aEvent->AsSMILTimeEvent());
case NS_COMMAND_EVENT:
return NS_NewDOMCommandEvent(aDOMEvent, aOwner, aPresContext,
aEvent->AsCommandEvent());

View File

@ -306,12 +306,12 @@ nsresult
NS_NewDOMSVGZoomEvent(nsIDOMEvent** aResult,
mozilla::dom::EventTarget* aOwner,
nsPresContext* aPresContext,
mozilla::WidgetGUIEvent* aEvent);
mozilla::InternalSVGZoomEvent* aEvent);
nsresult
NS_NewDOMTimeEvent(nsIDOMEvent** aResult,
mozilla::dom::EventTarget* aOwner,
nsPresContext* aPresContext,
mozilla::WidgetEvent* aEvent);
mozilla::InternalSMILTimeEvent* aEvent);
nsresult
NS_NewDOMXULCommandEvent(nsIDOMEvent** aResult,
mozilla::dom::EventTarget* aOwner,

View File

@ -3,8 +3,8 @@
* 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/. */
#include "mozilla/ContentEvents.h"
#include "mozilla/dom/TimeEvent.h"
#include "mozilla/BasicEvents.h"
#include "nsIDocShell.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsPresContext.h"
@ -14,26 +14,18 @@ namespace dom {
TimeEvent::TimeEvent(EventTarget* aOwner,
nsPresContext* aPresContext,
WidgetEvent* aEvent)
InternalSMILTimeEvent* aEvent)
: Event(aOwner, aPresContext,
aEvent ? aEvent : new InternalUIEvent(false, 0))
, mDetail(0)
aEvent ? aEvent : new InternalSMILTimeEvent(false, 0))
, mDetail(mEvent->AsSMILTimeEvent()->detail)
{
SetIsDOMBinding();
if (aEvent) {
mEventIsInternal = false;
} else {
mEventIsInternal = true;
mEvent->eventStructType = NS_SMIL_TIME_EVENT;
}
if (mEvent->eventStructType == NS_SMIL_TIME_EVENT) {
mDetail = mEvent->AsUIEvent()->detail;
}
mEvent->mFlags.mBubbles = false;
mEvent->mFlags.mCancelable = false;
if (mPresContext) {
nsCOMPtr<nsIDocShell> docShell = mPresContext->GetDocShell();
if (docShell) {
@ -92,7 +84,7 @@ nsresult
NS_NewDOMTimeEvent(nsIDOMEvent** aInstancePtrResult,
EventTarget* aOwner,
nsPresContext* aPresContext,
WidgetEvent* aEvent)
InternalSMILTimeEvent* aEvent)
{
TimeEvent* it = new TimeEvent(aOwner, aPresContext, aEvent);
NS_ADDREF(it);

View File

@ -19,7 +19,7 @@ class TimeEvent MOZ_FINAL : public Event,
public:
TimeEvent(EventTarget* aOwner,
nsPresContext* aPresContext,
WidgetEvent* aEvent);
InternalSMILTimeEvent* aEvent);
// nsISupports interface:
NS_DECL_ISUPPORTS_INHERITED

View File

@ -5,7 +5,7 @@
#include "mozilla/DebugOnly.h"
#include "mozilla/BasicEvents.h"
#include "mozilla/ContentEvents.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/dom/SVGAnimationElement.h"
#include "nsSMILTimedElement.h"
@ -92,8 +92,7 @@ namespace
NS_IMETHOD Run()
{
InternalUIEvent event(true, mMsg);
event.eventStructType = NS_SMIL_TIME_EVENT;
InternalSMILTimeEvent event(true, mMsg);
event.detail = mDetail;
nsPresContext* context = nullptr;

View File

@ -58,6 +58,8 @@ enum nsEventStructType
NS_CLIPBOARD_EVENT, // InternalClipboardEvent
NS_TRANSITION_EVENT, // InternalTransitionEvent
NS_ANIMATION_EVENT, // InternalAnimationEvent
NS_SVGZOOM_EVENT, // InternalSVGZoomEvent
NS_SMIL_TIME_EVENT, // InternalSMILTimeEvent
// MiscEvents.h
NS_COMMAND_EVENT, // WidgetCommandEvent
@ -65,13 +67,7 @@ enum nsEventStructType
NS_PLUGIN_EVENT, // WidgetPluginEvent
// InternalMutationEvent.h (dom/events)
NS_MUTATION_EVENT, // InternalMutationEvent
// Follwoing struct type values are ugly. They indicate other struct type
// actually. However, they are used for distinguishing which DOM event
// should be created for the event.
NS_SVGZOOM_EVENT, // WidgetGUIEvent
NS_SMIL_TIME_EVENT // InternalUIEvent
NS_MUTATION_EVENT // InternalMutationEvent
};
/******************************************************************************
@ -862,8 +858,7 @@ public:
virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
{
MOZ_ASSERT(eventStructType == NS_GUI_EVENT ||
eventStructType == NS_SVGZOOM_EVENT,
MOZ_ASSERT(eventStructType == NS_GUI_EVENT,
"Duplicate() must be overridden by sub class");
// Not copying widget, it is a weak reference.
WidgetGUIEvent* result = new WidgetGUIEvent(false, message, nullptr);
@ -1175,8 +1170,7 @@ public:
virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
{
MOZ_ASSERT(eventStructType == NS_UI_EVENT ||
eventStructType == NS_SMIL_TIME_EVENT,
MOZ_ASSERT(eventStructType == NS_UI_EVENT,
"Duplicate() must be overridden by sub class");
InternalUIEvent* result = new InternalUIEvent(false, message);
result->AssignUIEventData(*this, true);

View File

@ -315,6 +315,76 @@ public:
}
};
/******************************************************************************
* mozilla::InternalSVGZoomEvent
******************************************************************************/
class InternalSVGZoomEvent : public WidgetGUIEvent
{
public:
virtual InternalSVGZoomEvent* AsSVGZoomEvent() MOZ_OVERRIDE { return this; }
InternalSVGZoomEvent(bool aIsTrusted, uint32_t aMessage) :
WidgetGUIEvent(aIsTrusted, aMessage, nullptr, NS_SVGZOOM_EVENT)
{
mFlags.mCancelable = false;
}
virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
{
MOZ_ASSERT(eventStructType == NS_SVGZOOM_EVENT,
"Duplicate() must be overridden by sub class");
// Not copying widget, it is a weak reference.
InternalSVGZoomEvent* result = new InternalSVGZoomEvent(false, message);
result->AssignSVGZoomEventData(*this, true);
result->mFlags = mFlags;
return result;
}
void AssignSVGZoomEventData(const InternalSVGZoomEvent& aEvent,
bool aCopyTargets)
{
AssignGUIEventData(aEvent, aCopyTargets);
}
};
/******************************************************************************
* mozilla::InternalSMILTimeEvent
******************************************************************************/
class InternalSMILTimeEvent : public InternalUIEvent
{
public:
virtual InternalSMILTimeEvent* AsSMILTimeEvent() MOZ_OVERRIDE
{
return this;
}
InternalSMILTimeEvent(bool aIsTrusted, uint32_t aMessage) :
InternalUIEvent(aIsTrusted, aMessage, NS_SMIL_TIME_EVENT)
{
mFlags.mBubbles = false;
mFlags.mCancelable = false;
}
virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
{
MOZ_ASSERT(eventStructType == NS_SMIL_TIME_EVENT,
"Duplicate() must be overridden by sub class");
InternalSMILTimeEvent* result = new InternalSMILTimeEvent(false, message);
result->AssignSMILTimeEventData(*this, true);
result->mFlags = mFlags;
return result;
}
void AssignSMILTimeEventData(const InternalSMILTimeEvent& aEvent,
bool aCopyTargets)
{
AssignUIEventData(aEvent, aCopyTargets);
}
};
} // namespace mozilla
#endif // mozilla_ContentEvents_h__

View File

@ -49,6 +49,8 @@ NS_EVENT_CLASS(Internal, ClipboardEvent)
NS_EVENT_CLASS(Internal, FocusEvent)
NS_EVENT_CLASS(Internal, TransitionEvent)
NS_EVENT_CLASS(Internal, AnimationEvent)
NS_EVENT_CLASS(Internal, SVGZoomEvent)
NS_EVENT_CLASS(Internal, SMILTimeEvent)
// MiscEvents.h
NS_EVENT_CLASS(Widget, CommandEvent)