2015-05-03 19:32:37 +00: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 11:12:37 +00: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-25 23:19:33 +00:00
|
|
|
|
2010-12-08 12:15:53 +00:00
|
|
|
#include "DOMSVGPoint.h"
|
2014-07-30 17:16:57 +00:00
|
|
|
#include "mozilla/ContentEvents.h"
|
|
|
|
#include "mozilla/dom/Element.h"
|
2013-01-09 23:02:45 +00:00
|
|
|
#include "mozilla/dom/SVGSVGElement.h"
|
2014-07-30 17:16:57 +00:00
|
|
|
#include "mozilla/dom/SVGZoomEvent.h"
|
2005-08-25 23:19:33 +00:00
|
|
|
#include "nsIDocument.h"
|
2014-07-30 17:16:57 +00:00
|
|
|
#include "nsIPresShell.h"
|
2013-07-03 15:56:26 +00:00
|
|
|
#include "prtime.h"
|
2010-04-30 13:12:05 +00:00
|
|
|
|
2013-04-30 17:43:07 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2005-08-25 23:19:33 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2014-04-25 16:49:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(SVGZoomEvent, UIEvent, mPreviousTranslate, mNewTranslate)
|
2014-04-01 03:33:28 +00: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 17:43:07 +00:00
|
|
|
SVGZoomEvent::SVGZoomEvent(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
2014-07-30 17:16:57 +00:00
|
|
|
InternalSVGZoomEvent* aEvent)
|
2014-02-28 14:58:43 +00:00
|
|
|
: UIEvent(aOwner, aPresContext,
|
2015-09-07 14:55:52 +00:00
|
|
|
aEvent ? aEvent : new InternalSVGZoomEvent(false, eSVGZoom))
|
2013-04-29 22:39:16 +00:00
|
|
|
, mPreviousScale(0)
|
|
|
|
, mNewScale(0)
|
2005-08-25 23:19:33 +00:00
|
|
|
{
|
|
|
|
if (aEvent) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mEventIsInternal = false;
|
2005-08-25 23:19:33 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-10-17 14:59:28 +00:00
|
|
|
mEventIsInternal = true;
|
2016-03-28 04:29:42 +00:00
|
|
|
mEvent->mTime = PR_Now();
|
2005-08-25 23:19:33 +00: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 13:12:05 +00:00
|
|
|
Element *rootElement = doc->GetRootElement();
|
|
|
|
if (rootElement) {
|
2013-01-08 03:22:41 +00:00
|
|
|
// If the root element isn't an SVG 'svg' element
|
2005-08-25 23:19:33 +00:00
|
|
|
// (e.g. if this event was created by calling createEvent on a
|
2013-01-08 03:22:41 +00:00
|
|
|
// non-SVGDocument), then the "New" and "Previous"
|
2005-08-25 23:19:33 +00:00
|
|
|
// properties will be left null which is probably what we want.
|
2015-03-03 11:08:59 +00:00
|
|
|
if (rootElement->IsSVGElement(nsGkAtoms::svg)) {
|
2013-01-09 23:02:45 +00:00
|
|
|
SVGSVGElement *SVGSVGElem =
|
|
|
|
static_cast<SVGSVGElement*>(rootElement);
|
2013-01-08 03:22:41 +00:00
|
|
|
|
2013-01-09 23:02:45 +00:00
|
|
|
mNewScale = SVGSVGElem->GetCurrentScale();
|
|
|
|
mPreviousScale = SVGSVGElem->GetPreviousScale();
|
2009-04-28 13:25:03 +00:00
|
|
|
|
2013-01-17 01:35:24 +00:00
|
|
|
const SVGPoint& translate = SVGSVGElem->GetCurrentTranslate();
|
2010-12-08 12:15:53 +00:00
|
|
|
mNewTranslate =
|
|
|
|
new DOMSVGPoint(translate.GetX(), translate.GetY());
|
2011-10-17 14:59:28 +00:00
|
|
|
mNewTranslate->SetReadonly(true);
|
2009-04-28 13:25:03 +00:00
|
|
|
|
2013-01-17 01:35:24 +00:00
|
|
|
const SVGPoint& prevTranslate = SVGSVGElem->GetPreviousTranslate();
|
2010-12-08 12:15:53 +00:00
|
|
|
mPreviousTranslate =
|
|
|
|
new DOMSVGPoint(prevTranslate.GetX(), prevTranslate.GetY());
|
2011-10-17 14:59:28 +00:00
|
|
|
mPreviousTranslate->SetReadonly(true);
|
2005-08-25 23:19:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-08 21:23:16 +00:00
|
|
|
SVGZoomEvent::~SVGZoomEvent()
|
|
|
|
{
|
|
|
|
}
|
2005-08-25 23:19:33 +00:00
|
|
|
|
2013-04-30 17:43:07 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2005-08-25 23:19:33 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Exported creation functions:
|
|
|
|
|
2015-08-12 11:39:31 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
|
|
already_AddRefed<SVGZoomEvent>
|
|
|
|
NS_NewDOMSVGZoomEvent(EventTarget* aOwner,
|
2005-08-25 23:19:33 +00:00
|
|
|
nsPresContext* aPresContext,
|
2014-07-30 17:16:57 +00:00
|
|
|
mozilla::InternalSVGZoomEvent* aEvent)
|
2005-08-25 23:19:33 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SVGZoomEvent> it = new SVGZoomEvent(aOwner, aPresContext, aEvent);
|
2015-08-12 11:39:31 +00:00
|
|
|
return it.forget();
|
2005-08-25 23:19:33 +00:00
|
|
|
}
|