2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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/. */
|
2005-08-26 03:19:33 +04:00
|
|
|
|
2010-12-08 15:15:53 +03:00
|
|
|
#include "DOMSVGPoint.h"
|
2014-07-30 21:16:57 +04:00
|
|
|
#include "mozilla/ContentEvents.h"
|
|
|
|
#include "mozilla/dom/Element.h"
|
2013-01-10 03:02:45 +04:00
|
|
|
#include "mozilla/dom/SVGSVGElement.h"
|
2014-07-30 21:16:57 +04:00
|
|
|
#include "mozilla/dom/SVGZoomEvent.h"
|
2005-08-26 03:19:33 +04:00
|
|
|
#include "nsIDocument.h"
|
2014-07-30 21:16:57 +04:00
|
|
|
#include "nsIPresShell.h"
|
2013-07-03 19:56:26 +04:00
|
|
|
#include "prtime.h"
|
2010-04-30 17:12:05 +04:00
|
|
|
|
2013-04-30 21:43:07 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2005-08-26 03:19:33 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2014-04-25 20:49:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(SVGZoomEvent, UIEvent, mPreviousTranslate, mNewTranslate)
|
2014-04-01 07:33:28 +04: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 21:43:07 +04:00
|
|
|
SVGZoomEvent::SVGZoomEvent(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
2014-07-30 21:16:57 +04:00
|
|
|
InternalSVGZoomEvent* aEvent)
|
2014-02-28 18:58:43 +04:00
|
|
|
: UIEvent(aOwner, aPresContext,
|
2014-07-30 21:16:57 +04:00
|
|
|
aEvent ? aEvent : new InternalSVGZoomEvent(false, NS_SVG_ZOOM))
|
2013-04-30 02:39:16 +04:00
|
|
|
, mPreviousScale(0)
|
|
|
|
, mNewScale(0)
|
2005-08-26 03:19:33 +04:00
|
|
|
{
|
|
|
|
if (aEvent) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mEventIsInternal = false;
|
2005-08-26 03:19:33 +04:00
|
|
|
}
|
|
|
|
else {
|
2011-10-17 18:59:28 +04:00
|
|
|
mEventIsInternal = true;
|
2005-08-26 03:19:33 +04:00
|
|
|
mEvent->time = PR_Now();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 17:12:05 +04:00
|
|
|
Element *rootElement = doc->GetRootElement();
|
|
|
|
if (rootElement) {
|
2013-01-08 07:22:41 +04:00
|
|
|
// If the root element isn't an SVG 'svg' element
|
2005-08-26 03:19:33 +04:00
|
|
|
// (e.g. if this event was created by calling createEvent on a
|
2013-01-08 07:22:41 +04:00
|
|
|
// non-SVGDocument), then the "New" and "Previous"
|
2005-08-26 03:19:33 +04:00
|
|
|
// properties will be left null which is probably what we want.
|
2015-03-03 14:08:59 +03:00
|
|
|
if (rootElement->IsSVGElement(nsGkAtoms::svg)) {
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement *SVGSVGElem =
|
|
|
|
static_cast<SVGSVGElement*>(rootElement);
|
2013-01-08 07:22:41 +04:00
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
mNewScale = SVGSVGElem->GetCurrentScale();
|
|
|
|
mPreviousScale = SVGSVGElem->GetPreviousScale();
|
2009-04-28 17:25:03 +04:00
|
|
|
|
2013-01-17 05:35:24 +04:00
|
|
|
const SVGPoint& translate = SVGSVGElem->GetCurrentTranslate();
|
2010-12-08 15:15:53 +03:00
|
|
|
mNewTranslate =
|
|
|
|
new DOMSVGPoint(translate.GetX(), translate.GetY());
|
2011-10-17 18:59:28 +04:00
|
|
|
mNewTranslate->SetReadonly(true);
|
2009-04-28 17:25:03 +04:00
|
|
|
|
2013-01-17 05:35:24 +04:00
|
|
|
const SVGPoint& prevTranslate = SVGSVGElem->GetPreviousTranslate();
|
2010-12-08 15:15:53 +03:00
|
|
|
mPreviousTranslate =
|
|
|
|
new DOMSVGPoint(prevTranslate.GetX(), prevTranslate.GetY());
|
2011-10-17 18:59:28 +04:00
|
|
|
mPreviousTranslate->SetReadonly(true);
|
2005-08-26 03:19:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-09 01:23:16 +04:00
|
|
|
SVGZoomEvent::~SVGZoomEvent()
|
|
|
|
{
|
|
|
|
}
|
2005-08-26 03:19:33 +04:00
|
|
|
|
2013-04-30 21:43:07 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2005-08-26 03:19:33 +04:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Exported creation functions:
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewDOMSVGZoomEvent(nsIDOMEvent** aInstancePtrResult,
|
2013-03-09 15:34:29 +04:00
|
|
|
mozilla::dom::EventTarget* aOwner,
|
2005-08-26 03:19:33 +04:00
|
|
|
nsPresContext* aPresContext,
|
2014-07-30 21:16:57 +04:00
|
|
|
mozilla::InternalSVGZoomEvent* aEvent)
|
2005-08-26 03:19:33 +04:00
|
|
|
{
|
2013-04-30 21:43:07 +04:00
|
|
|
mozilla::dom::SVGZoomEvent* it =
|
|
|
|
new mozilla::dom::SVGZoomEvent(aOwner, aPresContext, aEvent);
|
2005-08-26 03:19:33 +04:00
|
|
|
return CallQueryInterface(it, aInstancePtrResult);
|
|
|
|
}
|