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: */
|
2013-01-03 10:17:02 +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/. */
|
|
|
|
|
2014-03-18 06:41:33 +04:00
|
|
|
#include "gfx2DGlue.h"
|
2013-04-15 02:56:34 +04:00
|
|
|
#include "mozilla/dom/SVGAnimatedTransformList.h"
|
2014-05-13 05:24:35 +04:00
|
|
|
#include "mozilla/dom/SVGGraphicsElementBinding.h"
|
2013-01-06 10:25:54 +04:00
|
|
|
#include "mozilla/dom/SVGTransformableElement.h"
|
2013-02-01 13:55:45 +04:00
|
|
|
#include "mozilla/dom/SVGMatrix.h"
|
|
|
|
#include "mozilla/dom/SVGSVGElement.h"
|
|
|
|
#include "nsContentUtils.h"
|
2013-01-06 10:25:54 +04:00
|
|
|
#include "nsIDOMMutationEvent.h"
|
|
|
|
#include "nsIFrame.h"
|
2013-02-01 13:55:45 +04:00
|
|
|
#include "nsISVGChildFrame.h"
|
2013-03-26 19:52:41 +04:00
|
|
|
#include "mozilla/dom/SVGRect.h"
|
2013-01-06 10:25:54 +04:00
|
|
|
#include "nsSVGUtils.h"
|
2013-02-01 13:55:45 +04:00
|
|
|
#include "SVGContentUtils.h"
|
2013-01-03 10:17:02 +04:00
|
|
|
|
2014-03-18 06:41:33 +04:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2013-01-03 10:17:02 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-04-15 02:56:34 +04:00
|
|
|
already_AddRefed<SVGAnimatedTransformList>
|
2013-01-03 10:17:02 +04:00
|
|
|
SVGTransformableElement::Transform()
|
|
|
|
{
|
|
|
|
// We're creating a DOM wrapper, so we must tell GetAnimatedTransformList
|
|
|
|
// to allocate the SVGAnimatedTransformList if it hasn't already done so:
|
2013-04-15 02:56:34 +04:00
|
|
|
return SVGAnimatedTransformList::GetDOMWrapper(
|
2013-04-22 15:15:59 +04:00
|
|
|
GetAnimatedTransformList(DO_ALLOCATE), this);
|
2013-01-03 10:17:02 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-01-06 10:25:54 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIContent methods
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
SVGTransformableElement::IsAttributeMapped(const nsIAtom* name) const
|
|
|
|
{
|
|
|
|
static const MappedAttributeEntry* const map[] = {
|
|
|
|
sColorMap,
|
|
|
|
sFillStrokeMap,
|
|
|
|
sGraphicsMap
|
|
|
|
};
|
|
|
|
|
|
|
|
return FindAttributeDependence(name, map) ||
|
2013-02-01 13:55:45 +04:00
|
|
|
nsSVGElement::IsAttributeMapped(name);
|
2013-01-06 10:25:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsChangeHint
|
|
|
|
SVGTransformableElement::GetAttributeChangeHint(const nsIAtom* aAttribute,
|
|
|
|
int32_t aModType) const
|
|
|
|
{
|
|
|
|
nsChangeHint retval =
|
2013-02-01 13:55:45 +04:00
|
|
|
nsSVGElement::GetAttributeChangeHint(aAttribute, aModType);
|
2013-01-06 10:25:54 +04:00
|
|
|
if (aAttribute == nsGkAtoms::transform ||
|
|
|
|
aAttribute == nsGkAtoms::mozAnimateMotionDummyAttr) {
|
|
|
|
nsIFrame* frame =
|
|
|
|
const_cast<SVGTransformableElement*>(this)->GetPrimaryFrame();
|
2016-05-23 06:26:03 +03:00
|
|
|
retval |= nsChangeHint_InvalidateRenderingObservers;
|
2013-07-12 11:13:07 +04:00
|
|
|
if (!frame || (frame->GetStateBits() & NS_FRAME_IS_NONDISPLAY)) {
|
2014-11-04 17:52:27 +03:00
|
|
|
return retval;
|
2013-01-06 10:25:54 +04:00
|
|
|
}
|
2016-03-15 03:37:32 +03:00
|
|
|
|
|
|
|
bool isAdditionOrRemoval = false;
|
2013-01-06 10:25:54 +04:00
|
|
|
if (aModType == nsIDOMMutationEvent::ADDITION ||
|
2016-03-15 03:37:32 +03:00
|
|
|
aModType == nsIDOMMutationEvent::REMOVAL) {
|
|
|
|
isAdditionOrRemoval = true;
|
2013-01-06 10:25:54 +04:00
|
|
|
} else {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aModType == nsIDOMMutationEvent::MODIFICATION,
|
|
|
|
"Unknown modification type.");
|
2016-03-15 03:37:32 +03:00
|
|
|
if (!mTransforms ||
|
2016-03-15 03:37:36 +03:00
|
|
|
!mTransforms->HasTransform() ||
|
|
|
|
!mTransforms->HadTransformBeforeLastBaseValChange()) {
|
|
|
|
// New or old value is empty; this is effectively addition or removal.
|
2016-03-15 03:37:32 +03:00
|
|
|
isAdditionOrRemoval = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isAdditionOrRemoval) {
|
|
|
|
// Reconstruct the frame tree to handle stacking context changes:
|
2016-05-23 06:26:03 +03:00
|
|
|
retval |= nsChangeHint_ReconstructFrame;
|
2016-03-15 03:37:32 +03:00
|
|
|
} else {
|
2013-01-06 10:25:54 +04:00
|
|
|
// We just assume the old and new transforms are different.
|
2016-05-23 06:26:03 +03:00
|
|
|
retval |= nsChangeHint_UpdatePostTransformOverflow |
|
|
|
|
nsChangeHint_UpdateTransformLayer;
|
2013-01-06 10:25:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SVGTransformableElement::IsEventAttributeName(nsIAtom* aName)
|
|
|
|
{
|
|
|
|
return nsContentUtils::IsEventAttributeName(aName, EventNameType_SVGGraphic);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGElement overrides
|
|
|
|
|
2013-12-27 00:13:57 +04:00
|
|
|
gfxMatrix
|
2015-12-03 01:36:23 +03:00
|
|
|
SVGTransformableElement::PrependLocalTransformsTo(
|
|
|
|
const gfxMatrix &aMatrix,
|
|
|
|
SVGTransformTypes aWhich) const
|
2013-01-06 10:25:54 +04:00
|
|
|
{
|
2015-12-03 01:36:23 +03:00
|
|
|
return SVGContentUtils::PrependLocalTransformsTo(
|
|
|
|
aMatrix, aWhich, mAnimateMotionTransform, mTransforms);
|
2013-01-06 10:25:54 +04:00
|
|
|
}
|
|
|
|
|
2013-12-29 01:37:40 +04:00
|
|
|
const gfx::Matrix*
|
2013-01-06 10:25:54 +04:00
|
|
|
SVGTransformableElement::GetAnimateMotionTransform() const
|
|
|
|
{
|
|
|
|
return mAnimateMotionTransform.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-12-29 01:37:40 +04:00
|
|
|
SVGTransformableElement::SetAnimateMotionTransform(const gfx::Matrix* aMatrix)
|
2013-01-06 10:25:54 +04:00
|
|
|
{
|
|
|
|
if ((!aMatrix && !mAnimateMotionTransform) ||
|
|
|
|
(aMatrix && mAnimateMotionTransform && *aMatrix == *mAnimateMotionTransform)) {
|
|
|
|
return;
|
|
|
|
}
|
2014-04-07 23:52:12 +04:00
|
|
|
bool transformSet = mTransforms && mTransforms->IsExplicitlySet();
|
|
|
|
bool prevSet = mAnimateMotionTransform || transformSet;
|
2013-12-29 01:37:40 +04:00
|
|
|
mAnimateMotionTransform = aMatrix ? new gfx::Matrix(*aMatrix) : nullptr;
|
2014-04-07 23:52:12 +04:00
|
|
|
bool nowSet = mAnimateMotionTransform || transformSet;
|
|
|
|
int32_t modType;
|
|
|
|
if (prevSet && !nowSet) {
|
|
|
|
modType = nsIDOMMutationEvent::REMOVAL;
|
|
|
|
} else if(!prevSet && nowSet) {
|
|
|
|
modType = nsIDOMMutationEvent::ADDITION;
|
|
|
|
} else {
|
|
|
|
modType = nsIDOMMutationEvent::MODIFICATION;
|
|
|
|
}
|
|
|
|
DidAnimateTransformList(modType);
|
2013-05-23 11:04:21 +04:00
|
|
|
nsIFrame* frame = GetPrimaryFrame();
|
|
|
|
if (frame) {
|
|
|
|
// If the result of this transform and any other transforms on this frame
|
|
|
|
// is the identity matrix, then DoApplyRenderingChangeToTree won't handle
|
|
|
|
// our nsChangeHint_UpdateTransformLayer hint since aFrame->IsTransformed()
|
|
|
|
// will return false. That's fine, but we still need to schedule a repaint,
|
|
|
|
// and that won't otherwise happen. Since it's cheap to call SchedulePaint,
|
|
|
|
// we don't bother to check IsTransformed().
|
|
|
|
frame->SchedulePaint();
|
|
|
|
}
|
2013-01-06 10:25:54 +04:00
|
|
|
}
|
|
|
|
|
2013-04-15 02:56:34 +04:00
|
|
|
nsSVGAnimatedTransformList*
|
2013-01-06 10:25:54 +04:00
|
|
|
SVGTransformableElement::GetAnimatedTransformList(uint32_t aFlags)
|
|
|
|
{
|
|
|
|
if (!mTransforms && (aFlags & DO_ALLOCATE)) {
|
2013-04-15 02:56:34 +04:00
|
|
|
mTransforms = new nsSVGAnimatedTransformList();
|
2013-01-06 10:25:54 +04:00
|
|
|
}
|
|
|
|
return mTransforms;
|
|
|
|
}
|
|
|
|
|
2013-02-01 13:55:45 +04:00
|
|
|
nsSVGElement*
|
|
|
|
SVGTransformableElement::GetNearestViewportElement()
|
|
|
|
{
|
|
|
|
return SVGContentUtils::GetNearestViewportElement(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGElement*
|
|
|
|
SVGTransformableElement::GetFarthestViewportElement()
|
|
|
|
{
|
|
|
|
return SVGContentUtils::GetOuterSVGElement(this);
|
|
|
|
}
|
|
|
|
|
2013-03-26 19:53:13 +04:00
|
|
|
already_AddRefed<SVGIRect>
|
2014-05-13 05:24:35 +04:00
|
|
|
SVGTransformableElement::GetBBox(const SVGBoundingBoxOptions& aOptions,
|
|
|
|
ErrorResult& rv)
|
2013-02-01 13:55:45 +04:00
|
|
|
{
|
|
|
|
nsIFrame* frame = GetPrimaryFrame(Flush_Layout);
|
|
|
|
|
2013-07-12 11:13:07 +04:00
|
|
|
if (!frame || (frame->GetStateBits() & NS_FRAME_IS_NONDISPLAY)) {
|
2013-02-01 13:55:45 +04:00
|
|
|
rv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsISVGChildFrame* svgframe = do_QueryFrame(frame);
|
|
|
|
if (!svgframe) {
|
|
|
|
rv.Throw(NS_ERROR_NOT_IMPLEMENTED); // XXX: outer svg
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-05-13 05:24:35 +04:00
|
|
|
if (!NS_SVGNewGetBBoxEnabled()) {
|
|
|
|
return NS_NewSVGRect(this, ToRect(nsSVGUtils::GetBBox(frame)));
|
|
|
|
} else {
|
2015-04-22 19:14:27 +03:00
|
|
|
uint32_t flags = 0;
|
2014-05-13 05:24:35 +04:00
|
|
|
if (aOptions.mFill) {
|
2015-04-22 19:14:27 +03:00
|
|
|
flags |= nsSVGUtils::eBBoxIncludeFill;
|
2014-05-13 05:24:35 +04:00
|
|
|
}
|
|
|
|
if (aOptions.mStroke) {
|
2015-04-22 19:14:27 +03:00
|
|
|
flags |= nsSVGUtils::eBBoxIncludeStroke;
|
2014-05-13 05:24:35 +04:00
|
|
|
}
|
|
|
|
if (aOptions.mMarkers) {
|
2015-04-22 19:14:27 +03:00
|
|
|
flags |= nsSVGUtils::eBBoxIncludeMarkers;
|
2014-05-13 05:24:35 +04:00
|
|
|
}
|
|
|
|
if (aOptions.mClipped) {
|
2015-04-22 19:14:27 +03:00
|
|
|
flags |= nsSVGUtils::eBBoxIncludeClipped;
|
2014-05-13 05:24:35 +04:00
|
|
|
}
|
2015-04-22 19:14:27 +03:00
|
|
|
if (flags == 0) {
|
2014-05-13 05:24:35 +04:00
|
|
|
return NS_NewSVGRect(this,0,0,0,0);
|
|
|
|
}
|
2015-04-22 19:14:27 +03:00
|
|
|
if (flags == nsSVGUtils::eBBoxIncludeMarkers ||
|
|
|
|
flags == nsSVGUtils::eBBoxIncludeClipped) {
|
|
|
|
flags |= nsSVGUtils::eBBoxIncludeFill;
|
2014-05-13 05:24:35 +04:00
|
|
|
}
|
2015-04-22 19:14:27 +03:00
|
|
|
return NS_NewSVGRect(this, ToRect(nsSVGUtils::GetBBox(frame, flags)));
|
2014-05-13 05:24:35 +04:00
|
|
|
}
|
2013-02-01 13:55:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<SVGMatrix>
|
|
|
|
SVGTransformableElement::GetCTM()
|
|
|
|
{
|
2014-10-03 16:32:26 +04:00
|
|
|
nsIDocument* currentDoc = GetComposedDoc();
|
2013-02-01 13:55:45 +04:00
|
|
|
if (currentDoc) {
|
|
|
|
// Flush all pending notifications so that our frames are up to date
|
|
|
|
currentDoc->FlushPendingNotifications(Flush_Layout);
|
|
|
|
}
|
2013-12-31 22:44:27 +04:00
|
|
|
gfx::Matrix m = SVGContentUtils::GetCTM(this, false);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SVGMatrix> mat = m.IsSingular() ? nullptr : new SVGMatrix(ThebesMatrix(m));
|
2013-02-01 13:55:45 +04:00
|
|
|
return mat.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<SVGMatrix>
|
|
|
|
SVGTransformableElement::GetScreenCTM()
|
|
|
|
{
|
2014-10-03 16:32:26 +04:00
|
|
|
nsIDocument* currentDoc = GetComposedDoc();
|
2013-02-01 13:55:45 +04:00
|
|
|
if (currentDoc) {
|
|
|
|
// Flush all pending notifications so that our frames are up to date
|
|
|
|
currentDoc->FlushPendingNotifications(Flush_Layout);
|
|
|
|
}
|
2013-12-31 22:44:27 +04:00
|
|
|
gfx::Matrix m = SVGContentUtils::GetCTM(this, true);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SVGMatrix> mat = m.IsSingular() ? nullptr : new SVGMatrix(ThebesMatrix(m));
|
2013-02-01 13:55:45 +04:00
|
|
|
return mat.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<SVGMatrix>
|
|
|
|
SVGTransformableElement::GetTransformToElement(SVGGraphicsElement& aElement,
|
|
|
|
ErrorResult& rv)
|
|
|
|
{
|
|
|
|
// the easiest way to do this (if likely to increase rounding error):
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SVGMatrix> ourScreenCTM = GetScreenCTM();
|
|
|
|
RefPtr<SVGMatrix> targetScreenCTM = aElement.GetScreenCTM();
|
2013-02-01 13:55:45 +04:00
|
|
|
if (!ourScreenCTM || !targetScreenCTM) {
|
|
|
|
rv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SVGMatrix> tmp = targetScreenCTM->Inverse(rv);
|
2013-02-01 13:55:45 +04:00
|
|
|
if (rv.Failed()) return nullptr;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SVGMatrix> mat = tmp->Multiply(*ourScreenCTM);
|
2013-02-01 13:55:45 +04:00
|
|
|
return mat.forget();
|
|
|
|
}
|
|
|
|
|
2013-01-03 10:17:02 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|