2007-03-22 10:30:00 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-04-30 10:43:07 -07:00
|
|
|
#include "mozilla/dom/SVGZoomEvent.h"
|
2010-12-08 04:15:53 -08:00
|
|
|
#include "DOMSVGPoint.h"
|
2013-01-09 15:02:45 -08:00
|
|
|
#include "mozilla/dom/SVGSVGElement.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIDocument.h"
|
2010-05-05 11:18:05 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-07-03 08:56:26 -07:00
|
|
|
#include "prtime.h"
|
2010-04-30 06:12:05 -07:00
|
|
|
|
2013-04-30 10:43:07 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2014-04-25 09:49:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(SVGZoomEvent, UIEvent, mPreviousTranslate, mNewTranslate)
|
2014-03-31 20:33:28 -07:00
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(SVGZoomEvent, UIEvent)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(SVGZoomEvent, UIEvent)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SVGZoomEvent)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(UIEvent)
|
|
|
|
|
2013-04-30 10:43:07 -07:00
|
|
|
SVGZoomEvent::SVGZoomEvent(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
2013-10-01 20:46:03 -07:00
|
|
|
WidgetGUIEvent* aEvent)
|
2014-02-28 06:58:43 -08:00
|
|
|
: UIEvent(aOwner, aPresContext,
|
|
|
|
aEvent ? aEvent : new WidgetGUIEvent(false, NS_SVG_ZOOM, 0))
|
2013-04-29 15:39:16 -07:00
|
|
|
, mPreviousScale(0)
|
|
|
|
, mNewScale(0)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aEvent) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mEventIsInternal = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2011-10-17 07:59:28 -07:00
|
|
|
mEventIsInternal = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
mEvent->eventStructType = NS_SVGZOOM_EVENT;
|
|
|
|
mEvent->time = PR_Now();
|
|
|
|
}
|
|
|
|
|
2012-12-15 17:26:03 -08:00
|
|
|
mEvent->mFlags.mCancelable = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// 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
|
|
|
|
// currentScale and currentTranslate in response to this event.
|
|
|
|
nsIPresShell *presShell;
|
|
|
|
if (mPresContext && (presShell = mPresContext->GetPresShell())) {
|
|
|
|
nsIDocument *doc = presShell->GetDocument();
|
|
|
|
if (doc) {
|
2010-04-30 06:12:05 -07:00
|
|
|
Element *rootElement = doc->GetRootElement();
|
|
|
|
if (rootElement) {
|
2013-01-07 19:22:41 -08:00
|
|
|
// If the root element isn't an SVG 'svg' element
|
2007-03-22 10:30:00 -07:00
|
|
|
// (e.g. if this event was created by calling createEvent on a
|
2013-01-07 19:22:41 -08:00
|
|
|
// non-SVGDocument), then the "New" and "Previous"
|
2007-03-22 10:30:00 -07:00
|
|
|
// properties will be left null which is probably what we want.
|
2013-01-07 19:22:41 -08:00
|
|
|
if (rootElement->IsSVG(nsGkAtoms::svg)) {
|
2013-01-09 15:02:45 -08:00
|
|
|
SVGSVGElement *SVGSVGElem =
|
|
|
|
static_cast<SVGSVGElement*>(rootElement);
|
2013-01-07 19:22:41 -08:00
|
|
|
|
2013-01-09 15:02:45 -08:00
|
|
|
mNewScale = SVGSVGElem->GetCurrentScale();
|
|
|
|
mPreviousScale = SVGSVGElem->GetPreviousScale();
|
2009-04-28 06:25:03 -07:00
|
|
|
|
2013-01-16 17:35:24 -08:00
|
|
|
const SVGPoint& translate = SVGSVGElem->GetCurrentTranslate();
|
2010-12-08 04:15:53 -08:00
|
|
|
mNewTranslate =
|
|
|
|
new DOMSVGPoint(translate.GetX(), translate.GetY());
|
2011-10-17 07:59:28 -07:00
|
|
|
mNewTranslate->SetReadonly(true);
|
2009-04-28 06:25:03 -07:00
|
|
|
|
2013-01-16 17:35:24 -08:00
|
|
|
const SVGPoint& prevTranslate = SVGSVGElem->GetPreviousTranslate();
|
2010-12-08 04:15:53 -08:00
|
|
|
mPreviousTranslate =
|
|
|
|
new DOMSVGPoint(prevTranslate.GetX(), prevTranslate.GetY());
|
2011-10-17 07:59:28 -07:00
|
|
|
mPreviousTranslate->SetReadonly(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-30 10:43:07 -07:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Exported creation functions:
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewDOMSVGZoomEvent(nsIDOMEvent** aInstancePtrResult,
|
2013-03-09 03:34:29 -08:00
|
|
|
mozilla::dom::EventTarget* aOwner,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsPresContext* aPresContext,
|
2013-10-01 20:46:03 -07:00
|
|
|
mozilla::WidgetGUIEvent* aEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-04-30 10:43:07 -07:00
|
|
|
mozilla::dom::SVGZoomEvent* it =
|
|
|
|
new mozilla::dom::SVGZoomEvent(aOwner, aPresContext, aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
return CallQueryInterface(it, aInstancePtrResult);
|
|
|
|
}
|