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/. */
|
2001-12-12 10:59:31 +03:00
|
|
|
|
2014-07-30 21:16:57 +04:00
|
|
|
#include "mozilla/ContentEvents.h"
|
2017-06-14 15:38:10 +03:00
|
|
|
#include "mozilla/dom/SVGSVGElement.h"
|
|
|
|
#include "mozilla/dom/SVGSVGElementBinding.h"
|
|
|
|
#include "mozilla/dom/SVGMatrix.h"
|
|
|
|
#include "mozilla/dom/SVGViewElement.h"
|
2014-03-18 08:48:21 +04:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2010-07-17 01:42:12 +04:00
|
|
|
#include "DOMSVGLength.h"
|
2017-06-14 15:38:10 +03:00
|
|
|
#include "DOMSVGNumber.h"
|
2010-12-08 15:15:53 +03:00
|
|
|
#include "DOMSVGPoint.h"
|
2017-06-14 15:38:10 +03:00
|
|
|
#include "nsLayoutStylesheetCache.h"
|
|
|
|
#include "nsSVGAngle.h"
|
2013-07-03 11:41:53 +04:00
|
|
|
#include "nsFrameSelection.h"
|
2017-06-14 15:38:10 +03:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsISVGSVGFrame.h"
|
|
|
|
#include "nsSMILAnimationController.h"
|
|
|
|
#include "nsSMILTimeContainer.h"
|
2017-02-09 21:24:31 +03:00
|
|
|
#include "nsSVGDisplayableFrame.h"
|
2012-09-22 23:26:05 +04:00
|
|
|
#include "nsSVGUtils.h"
|
2012-12-23 08:54:23 +04:00
|
|
|
#include "SVGAngle.h"
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT_CHECK_PARSER(SVG)
|
|
|
|
|
2013-12-30 10:50:17 +04:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2010-08-15 19:19:34 +04:00
|
|
|
|
2018-06-26 00:20:54 +03:00
|
|
|
using namespace SVGPreserveAspectRatio_Binding;
|
|
|
|
using namespace SVGSVGElement_Binding;
|
2018-02-18 18:53:13 +03:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
nsSVGEnumMapping SVGSVGElement::sZoomAndPanMap[] = {
|
|
|
|
{&nsGkAtoms::disable, SVG_ZOOMANDPAN_DISABLE},
|
|
|
|
{&nsGkAtoms::magnify, SVG_ZOOMANDPAN_MAGNIFY},
|
|
|
|
{nullptr, 0}
|
|
|
|
};
|
2013-03-12 02:05:58 +04:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
nsSVGElement::EnumInfo SVGSVGElement::sEnumInfo[1] =
|
2013-01-10 03:02:47 +04:00
|
|
|
{
|
2017-06-14 15:38:10 +03:00
|
|
|
{ &nsGkAtoms::zoomAndPan,
|
|
|
|
sZoomAndPanMap,
|
|
|
|
SVG_ZOOMANDPAN_MAGNIFY
|
|
|
|
}
|
|
|
|
};
|
2013-01-10 03:02:47 +04:00
|
|
|
|
2014-04-25 20:49:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(DOMSVGTranslatePoint, nsISVGPoint,
|
|
|
|
mElement)
|
2013-03-04 19:40:25 +04:00
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(DOMSVGTranslatePoint, nsISVGPoint)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(DOMSVGTranslatePoint, nsISVGPoint)
|
2009-04-28 17:25:03 +04:00
|
|
|
|
2013-01-17 05:35:24 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMSVGTranslatePoint)
|
2012-12-23 08:54:20 +04:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2013-01-10 03:10:59 +04:00
|
|
|
// We have to qualify nsISVGPoint because NS_GET_IID looks for a class in the
|
|
|
|
// global namespace
|
2013-01-10 03:02:45 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(mozilla::nsISVGPoint)
|
2009-04-28 17:25:03 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2014-08-06 17:58:57 +04:00
|
|
|
DOMSVGPoint*
|
|
|
|
DOMSVGTranslatePoint::Copy()
|
2009-04-28 17:25:03 +04:00
|
|
|
{
|
2014-08-06 17:58:57 +04:00
|
|
|
return new DOMSVGPoint(mPt.GetX(), mPt.GetY());
|
2009-04-28 17:25:03 +04:00
|
|
|
}
|
|
|
|
|
2012-12-23 08:54:20 +04:00
|
|
|
nsISupports*
|
2013-01-17 05:35:24 +04:00
|
|
|
DOMSVGTranslatePoint::GetParentObject()
|
2012-12-23 08:54:20 +04:00
|
|
|
{
|
2018-05-30 05:58:51 +03:00
|
|
|
return ToSupports(mElement);
|
2012-12-23 08:54:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-17 05:35:24 +04:00
|
|
|
DOMSVGTranslatePoint::SetX(float aValue, ErrorResult& rv)
|
2012-12-23 08:54:20 +04:00
|
|
|
{
|
2013-02-08 23:55:07 +04:00
|
|
|
mElement->SetCurrentTranslate(aValue, mPt.GetY());
|
2012-12-23 08:54:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-17 05:35:24 +04:00
|
|
|
DOMSVGTranslatePoint::SetY(float aValue, ErrorResult& rv)
|
2012-12-23 08:54:20 +04:00
|
|
|
{
|
2013-02-08 23:55:07 +04:00
|
|
|
mElement->SetCurrentTranslate(mPt.GetX(), aValue);
|
2012-12-23 08:54:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsISVGPoint>
|
2013-01-17 05:35:24 +04:00
|
|
|
DOMSVGTranslatePoint::MatrixTransform(SVGMatrix& matrix)
|
2012-12-23 08:54:20 +04:00
|
|
|
{
|
2012-12-23 08:54:20 +04:00
|
|
|
float a = matrix.A(), b = matrix.B(), c = matrix.C();
|
|
|
|
float d = matrix.D(), e = matrix.E(), f = matrix.F();
|
2013-01-17 05:35:24 +04:00
|
|
|
float x = mPt.GetX();
|
|
|
|
float y = mPt.GetY();
|
2010-12-08 15:15:53 +03:00
|
|
|
|
2012-12-23 08:54:20 +04:00
|
|
|
nsCOMPtr<nsISVGPoint> point = new DOMSVGPoint(a*x + c*y + e, b*x + d*y + f);
|
|
|
|
return point.forget();
|
2009-04-28 17:25:03 +04:00
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
JSObject*
|
|
|
|
SVGSVGElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
|
2015-12-14 03:58:01 +03:00
|
|
|
{
|
2018-06-26 00:20:54 +03:00
|
|
|
return SVGSVGElement_Binding::Wrap(aCx, this, aGivenProto);
|
2015-12-14 03:58:01 +03:00
|
|
|
}
|
|
|
|
|
2001-12-12 10:59:31 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports methods
|
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(SVGSVGElement)
|
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(SVGSVGElement,
|
|
|
|
SVGSVGElementBase)
|
2010-01-12 23:00:49 +03:00
|
|
|
if (tmp->mTimedDocumentRoot) {
|
|
|
|
tmp->mTimedDocumentRoot->Unlink();
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2013-01-10 03:02:45 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(SVGSVGElement,
|
|
|
|
SVGSVGElementBase)
|
2010-01-12 23:00:49 +03:00
|
|
|
if (tmp->mTimedDocumentRoot) {
|
|
|
|
tmp->mTimedDocumentRoot->Traverse(&cb);
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2018-05-30 05:58:51 +03:00
|
|
|
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(SVGSVGElement,
|
|
|
|
SVGSVGElementBase)
|
2001-12-12 10:59:31 +03:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
SVGView::SVGView()
|
|
|
|
{
|
|
|
|
mZoomAndPan.Init(SVGSVGElement::ZOOMANDPAN,
|
|
|
|
SVG_ZOOMANDPAN_MAGNIFY);
|
|
|
|
mViewBox.Init();
|
|
|
|
mPreserveAspectRatio.Init();
|
|
|
|
}
|
|
|
|
|
2001-12-12 10:59:31 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2018-09-21 23:45:49 +03:00
|
|
|
SVGSVGElement::SVGSVGElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
2014-03-15 23:00:17 +04:00
|
|
|
FromParser aFromParser)
|
2018-09-21 23:45:49 +03:00
|
|
|
: SVGSVGElementBase(std::move(aNodeInfo)),
|
2009-04-28 17:25:03 +04:00
|
|
|
mCurrentTranslate(0.0f, 0.0f),
|
|
|
|
mCurrentScale(1.0f),
|
|
|
|
mPreviousTranslate(0.0f, 0.0f),
|
|
|
|
mPreviousScale(1.0f),
|
2012-10-23 12:21:49 +04:00
|
|
|
mStartAnimationOnBindToTree(aFromParser == NOT_FROM_PARSER ||
|
|
|
|
aFromParser == FROM_PARSER_FRAGMENT ||
|
|
|
|
aFromParser == FROM_PARSER_XSLT),
|
2017-06-14 15:38:10 +03:00
|
|
|
mImageNeedsTransformInvalidation(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SVGSVGElement::~SVGSVGElement()
|
2001-12-12 10:59:31 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-05-30 05:58:49 +03:00
|
|
|
// nsINode methods
|
2001-12-12 10:59:31 +03:00
|
|
|
|
2017-06-14 14:57:40 +03:00
|
|
|
NS_IMPL_ELEMENT_CLONE_WITH_INIT_AND_PARSER(SVGSVGElement)
|
2001-12-12 10:59:31 +03:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIDOMSVGSVGElement methods:
|
|
|
|
|
2013-01-20 00:56:00 +04:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-10 03:02:47 +04:00
|
|
|
SVGSVGElement::X()
|
|
|
|
{
|
|
|
|
return mLengthAttributes[ATTR_X].ToDOMAnimatedLength(this);
|
2001-12-12 10:59:31 +03:00
|
|
|
}
|
|
|
|
|
2013-01-20 00:56:00 +04:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-10 03:02:47 +04:00
|
|
|
SVGSVGElement::Y()
|
|
|
|
{
|
|
|
|
return mLengthAttributes[ATTR_Y].ToDOMAnimatedLength(this);
|
2001-12-12 10:59:31 +03:00
|
|
|
}
|
|
|
|
|
2013-01-20 00:56:00 +04:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-10 03:02:47 +04:00
|
|
|
SVGSVGElement::Width()
|
|
|
|
{
|
|
|
|
return mLengthAttributes[ATTR_WIDTH].ToDOMAnimatedLength(this);
|
2001-12-12 10:59:31 +03:00
|
|
|
}
|
|
|
|
|
2013-01-20 00:56:00 +04:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-10 03:02:47 +04:00
|
|
|
SVGSVGElement::Height()
|
|
|
|
{
|
|
|
|
return mLengthAttributes[ATTR_HEIGHT].ToDOMAnimatedLength(this);
|
2001-12-12 10:59:31 +03:00
|
|
|
}
|
2013-01-10 03:02:47 +04:00
|
|
|
|
|
|
|
bool
|
|
|
|
SVGSVGElement::UseCurrentView()
|
|
|
|
{
|
2015-12-14 03:58:01 +03:00
|
|
|
return mSVGView || mCurrentViewID;
|
2013-01-10 03:02:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
SVGSVGElement::CurrentScale()
|
|
|
|
{
|
|
|
|
return mCurrentScale;
|
|
|
|
}
|
|
|
|
|
2005-09-30 22:51:43 +04:00
|
|
|
#define CURRENT_SCALE_MAX 16.0f
|
|
|
|
#define CURRENT_SCALE_MIN 0.0625f
|
|
|
|
|
2013-02-08 23:55:07 +04:00
|
|
|
void
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement::SetCurrentScale(float aCurrentScale)
|
2001-12-12 10:59:31 +03:00
|
|
|
{
|
2013-02-08 23:55:07 +04:00
|
|
|
SetCurrentScaleTranslate(aCurrentScale,
|
2009-04-28 17:25:03 +04:00
|
|
|
mCurrentTranslate.GetX(), mCurrentTranslate.GetY());
|
2001-12-12 10:59:31 +03:00
|
|
|
}
|
|
|
|
|
2013-01-10 03:02:47 +04:00
|
|
|
already_AddRefed<nsISVGPoint>
|
|
|
|
SVGSVGElement::CurrentTranslate()
|
|
|
|
{
|
2013-01-17 05:35:24 +04:00
|
|
|
nsCOMPtr<nsISVGPoint> point = new DOMSVGTranslatePoint(&mCurrentTranslate, this);
|
2013-01-10 03:02:47 +04:00
|
|
|
return point.forget();
|
2001-12-12 10:59:31 +03:00
|
|
|
}
|
|
|
|
|
2013-01-10 03:02:47 +04:00
|
|
|
uint32_t
|
|
|
|
SVGSVGElement::SuspendRedraw(uint32_t max_wait_milliseconds)
|
|
|
|
{
|
|
|
|
// suspendRedraw is a no-op in Mozilla, so it doesn't matter what
|
|
|
|
// we return
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-02-08 23:55:07 +04:00
|
|
|
void
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement::UnsuspendRedraw(uint32_t suspend_handle_id)
|
2001-12-12 10:59:31 +03:00
|
|
|
{
|
2012-03-20 16:15:53 +04:00
|
|
|
// no-op
|
2001-12-12 10:59:31 +03:00
|
|
|
}
|
|
|
|
|
2013-02-08 23:55:07 +04:00
|
|
|
void
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement::UnsuspendRedrawAll()
|
2001-12-12 10:59:31 +03:00
|
|
|
{
|
2012-03-20 16:15:53 +04:00
|
|
|
// no-op
|
2013-01-10 03:02:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-01-24 12:35:22 +03:00
|
|
|
SVGSVGElement::ForceRedraw()
|
2001-12-12 10:59:31 +03:00
|
|
|
{
|
2015-01-23 18:28:25 +03:00
|
|
|
// no-op
|
2001-12-12 10:59:31 +03:00
|
|
|
}
|
|
|
|
|
2013-01-10 03:02:47 +04:00
|
|
|
void
|
2013-02-08 23:55:07 +04:00
|
|
|
SVGSVGElement::PauseAnimations()
|
2001-12-12 10:59:31 +03:00
|
|
|
{
|
2013-01-27 23:30:21 +04:00
|
|
|
if (mTimedDocumentRoot) {
|
|
|
|
mTimedDocumentRoot->Pause(nsSMILTimeContainer::PAUSE_SCRIPT);
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
2013-01-27 23:30:21 +04:00
|
|
|
// else we're not the outermost <svg> or not bound to a tree, so silently fail
|
2001-12-12 10:59:31 +03:00
|
|
|
}
|
|
|
|
|
2013-01-10 03:02:47 +04:00
|
|
|
void
|
2013-02-08 23:55:07 +04:00
|
|
|
SVGSVGElement::UnpauseAnimations()
|
2001-12-12 10:59:31 +03:00
|
|
|
{
|
2013-01-27 23:30:21 +04:00
|
|
|
if (mTimedDocumentRoot) {
|
|
|
|
mTimedDocumentRoot->Resume(nsSMILTimeContainer::PAUSE_SCRIPT);
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
2013-01-27 23:30:21 +04:00
|
|
|
// else we're not the outermost <svg> or not bound to a tree, so silently fail
|
2001-12-12 10:59:31 +03:00
|
|
|
}
|
|
|
|
|
2013-01-10 03:02:47 +04:00
|
|
|
bool
|
2013-02-08 23:55:07 +04:00
|
|
|
SVGSVGElement::AnimationsPaused()
|
2001-12-12 10:59:31 +03:00
|
|
|
{
|
2013-01-27 23:30:21 +04:00
|
|
|
nsSMILTimeContainer* root = GetTimedDocumentRoot();
|
|
|
|
return root && root->IsPausedByType(nsSMILTimeContainer::PAUSE_SCRIPT);
|
2001-12-12 10:59:31 +03:00
|
|
|
}
|
|
|
|
|
2013-01-10 03:02:47 +04:00
|
|
|
float
|
2013-02-08 23:55:07 +04:00
|
|
|
SVGSVGElement::GetCurrentTime()
|
2001-12-12 10:59:31 +03:00
|
|
|
{
|
2013-01-27 23:30:21 +04:00
|
|
|
nsSMILTimeContainer* root = GetTimedDocumentRoot();
|
|
|
|
if (root) {
|
|
|
|
double fCurrentTimeMs = double(root->GetCurrentTime());
|
|
|
|
return (float)(fCurrentTimeMs / PR_MSEC_PER_SEC);
|
|
|
|
} else {
|
|
|
|
return 0.f;
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
2001-12-12 10:59:31 +03:00
|
|
|
}
|
|
|
|
|
2013-01-10 03:02:47 +04:00
|
|
|
void
|
2013-02-08 23:55:07 +04:00
|
|
|
SVGSVGElement::SetCurrentTime(float seconds)
|
2013-01-10 03:02:47 +04:00
|
|
|
{
|
2013-01-27 23:30:21 +04:00
|
|
|
if (mTimedDocumentRoot) {
|
|
|
|
// Make sure the timegraph is up-to-date
|
|
|
|
FlushAnimations();
|
|
|
|
double fMilliseconds = double(seconds) * PR_MSEC_PER_SEC;
|
|
|
|
// Round to nearest whole number before converting, to avoid precision
|
|
|
|
// errors
|
|
|
|
nsSMILTime lMilliseconds = int64_t(NS_round(fMilliseconds));
|
|
|
|
mTimedDocumentRoot->SetCurrentTime(lMilliseconds);
|
|
|
|
AnimationNeedsResample();
|
|
|
|
// Trigger synchronous sample now, to:
|
|
|
|
// - Make sure we get an up-to-date paint after this method
|
|
|
|
// - re-enable event firing (it got disabled during seeking, and it
|
|
|
|
// doesn't get re-enabled until the first sample after the seek -- so
|
|
|
|
// let's make that happen now.)
|
|
|
|
FlushAnimations();
|
2009-03-10 04:20:17 +03:00
|
|
|
}
|
2013-01-27 23:30:21 +04:00
|
|
|
// else we're not the outermost <svg> or not bound to a tree, so silently fail
|
2001-12-12 10:59:31 +03:00
|
|
|
}
|
|
|
|
|
2013-07-03 11:41:53 +04:00
|
|
|
void
|
|
|
|
SVGSVGElement::DeselectAll()
|
|
|
|
{
|
|
|
|
nsIFrame* frame = GetPrimaryFrame();
|
|
|
|
if (frame) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsFrameSelection> frameSelection = frame->GetFrameSelection();
|
2013-07-03 11:41:53 +04:00
|
|
|
frameSelection->ClearNormalSelection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-30 11:36:52 +04:00
|
|
|
already_AddRefed<DOMSVGNumber>
|
2013-01-10 03:02:47 +04:00
|
|
|
SVGSVGElement::CreateSVGNumber()
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMSVGNumber> number = new DOMSVGNumber(ToSupports(this));
|
2013-01-10 03:02:47 +04:00
|
|
|
return number.forget();
|
|
|
|
}
|
|
|
|
|
2014-04-12 01:26:29 +04:00
|
|
|
already_AddRefed<DOMSVGLength>
|
2013-01-10 03:02:47 +04:00
|
|
|
SVGSVGElement::CreateSVGLength()
|
|
|
|
{
|
2014-04-12 01:26:29 +04:00
|
|
|
nsCOMPtr<DOMSVGLength> length = new DOMSVGLength();
|
2013-01-10 03:02:47 +04:00
|
|
|
return length.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<SVGAngle>
|
|
|
|
SVGSVGElement::CreateSVGAngle()
|
2001-12-12 10:59:31 +03:00
|
|
|
{
|
2012-12-23 08:54:23 +04:00
|
|
|
nsSVGAngle* angle = new nsSVGAngle();
|
|
|
|
angle->Init();
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SVGAngle> svgangle = new SVGAngle(angle, this, SVGAngle::CreatedValue);
|
2013-01-10 03:02:47 +04:00
|
|
|
return svgangle.forget();
|
2001-12-12 10:59:31 +03:00
|
|
|
}
|
|
|
|
|
2013-01-10 03:02:47 +04:00
|
|
|
already_AddRefed<nsISVGPoint>
|
|
|
|
SVGSVGElement::CreateSVGPoint()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISVGPoint> point = new DOMSVGPoint(0, 0);
|
|
|
|
return point.forget();
|
|
|
|
}
|
|
|
|
|
2013-01-12 00:30:21 +04:00
|
|
|
already_AddRefed<SVGMatrix>
|
2013-01-10 03:02:47 +04:00
|
|
|
SVGSVGElement::CreateSVGMatrix()
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SVGMatrix> matrix = new SVGMatrix();
|
2013-01-10 03:02:47 +04:00
|
|
|
return matrix.forget();
|
|
|
|
}
|
|
|
|
|
2013-03-26 19:53:13 +04:00
|
|
|
already_AddRefed<SVGIRect>
|
2013-01-10 03:02:47 +04:00
|
|
|
SVGSVGElement::CreateSVGRect()
|
|
|
|
{
|
2013-05-09 21:42:12 +04:00
|
|
|
return NS_NewSVGRect(this);
|
2001-12-12 10:59:31 +03:00
|
|
|
}
|
|
|
|
|
2013-04-02 23:17:41 +04:00
|
|
|
already_AddRefed<SVGTransform>
|
2013-01-10 03:02:47 +04:00
|
|
|
SVGSVGElement::CreateSVGTransform()
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SVGTransform> transform = new SVGTransform();
|
2013-01-10 03:02:47 +04:00
|
|
|
return transform.forget();
|
|
|
|
}
|
|
|
|
|
2013-04-02 23:17:41 +04:00
|
|
|
already_AddRefed<SVGTransform>
|
2013-01-12 00:30:21 +04:00
|
|
|
SVGSVGElement::CreateSVGTransformFromMatrix(SVGMatrix& matrix)
|
2013-01-10 03:02:47 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SVGTransform> transform = new SVGTransform(matrix.GetMatrix());
|
2013-01-10 03:02:47 +04:00
|
|
|
return transform.forget();
|
|
|
|
}
|
|
|
|
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 15:39:26 +03:00
|
|
|
//----------------------------------------------------------------------
|
2017-03-28 15:55:05 +03:00
|
|
|
// helper method for implementing SetCurrentScale/Translate
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 15:39:26 +03:00
|
|
|
|
2013-02-08 23:55:07 +04:00
|
|
|
void
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement::SetCurrentScaleTranslate(float s, float x, float y)
|
2005-08-26 01:31:09 +04:00
|
|
|
{
|
2009-04-28 17:25:03 +04:00
|
|
|
if (s == mCurrentScale &&
|
|
|
|
x == mCurrentTranslate.GetX() && y == mCurrentTranslate.GetY()) {
|
2013-02-08 23:55:07 +04:00
|
|
|
return;
|
2005-08-26 01:31:09 +04:00
|
|
|
}
|
|
|
|
|
2009-04-28 17:25:03 +04:00
|
|
|
// Prevent bizarre behaviour and maxing out of CPU and memory by clamping
|
|
|
|
if (s < CURRENT_SCALE_MIN)
|
|
|
|
s = CURRENT_SCALE_MIN;
|
|
|
|
else if (s > CURRENT_SCALE_MAX)
|
|
|
|
s = CURRENT_SCALE_MAX;
|
2017-06-14 15:38:10 +03:00
|
|
|
|
2009-04-28 17:25:03 +04:00
|
|
|
// IMPORTANT: If either mCurrentTranslate *or* mCurrentScale is changed then
|
|
|
|
// mPreviousTranslate_x, mPreviousTranslate_y *and* mPreviousScale must all
|
|
|
|
// be updated otherwise SVGZoomEvents will end up with invalid data. I.e. an
|
|
|
|
// SVGZoomEvent's properties previousScale and previousTranslate must contain
|
|
|
|
// the state of currentScale and currentTranslate immediately before the
|
|
|
|
// change that caused the event's dispatch, which is *not* necessarily the
|
|
|
|
// same thing as the values of currentScale and currentTranslate prior to
|
|
|
|
// their own last change.
|
2017-03-28 15:55:05 +03:00
|
|
|
//
|
|
|
|
// XXX This comment is out-of-date due to removal of SVGZoomEvent. Can we
|
|
|
|
// remove some of this code?
|
2009-04-28 17:25:03 +04:00
|
|
|
mPreviousScale = mCurrentScale;
|
|
|
|
mPreviousTranslate = mCurrentTranslate;
|
2017-06-14 15:38:10 +03:00
|
|
|
|
2009-04-28 17:25:03 +04:00
|
|
|
mCurrentScale = s;
|
2013-01-17 05:35:24 +04:00
|
|
|
mCurrentTranslate = SVGPoint(x, y);
|
2005-08-26 01:31:09 +04:00
|
|
|
|
2009-04-28 17:25:03 +04:00
|
|
|
// now dispatch the appropriate event if we are the root element
|
2014-10-03 16:32:26 +04:00
|
|
|
nsIDocument* doc = GetUncomposedDoc();
|
2005-08-26 01:31:09 +04:00
|
|
|
if (doc) {
|
2010-06-25 17:59:57 +04:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = doc->GetShell();
|
2007-12-12 05:26:09 +03:00
|
|
|
if (presShell && IsRoot()) {
|
2005-08-26 01:31:09 +04:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2017-03-28 15:55:05 +03:00
|
|
|
if (mPreviousScale == mCurrentScale) {
|
2015-09-07 17:55:52 +03:00
|
|
|
WidgetEvent svgScrollEvent(true, eSVGScroll);
|
2014-07-30 21:16:57 +04:00
|
|
|
presShell->HandleDOMEventWithTarget(this, &svgScrollEvent, &status);
|
|
|
|
}
|
2009-04-28 17:25:03 +04:00
|
|
|
InvalidateTransformNotifyFrame();
|
2005-08-26 01:31:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-08 23:55:07 +04:00
|
|
|
void
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement::SetCurrentTranslate(float x, float y)
|
2005-08-26 01:31:09 +04:00
|
|
|
{
|
2013-02-08 23:55:07 +04:00
|
|
|
SetCurrentScaleTranslate(mCurrentScale, x, y);
|
2005-08-26 01:31:09 +04:00
|
|
|
}
|
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// SVGZoomAndPanValues
|
|
|
|
uint16_t
|
|
|
|
SVGSVGElement::ZoomAndPan()
|
|
|
|
{
|
|
|
|
return mEnumAttributes[ZOOMANDPAN].GetAnimValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVGSVGElement::SetZoomAndPan(uint16_t aZoomAndPan, ErrorResult& rv)
|
|
|
|
{
|
|
|
|
if (aZoomAndPan == SVG_ZOOMANDPAN_DISABLE ||
|
|
|
|
aZoomAndPan == SVG_ZOOMANDPAN_MAGNIFY) {
|
|
|
|
mEnumAttributes[ZOOMANDPAN].SetBaseValue(aZoomAndPan, this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv.ThrowRangeError<MSG_INVALID_ZOOMANDPAN_VALUE_ERROR>();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2009-01-15 07:38:07 +03:00
|
|
|
nsSMILTimeContainer*
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement::GetTimedDocumentRoot()
|
2009-01-15 07:38:07 +03:00
|
|
|
{
|
|
|
|
if (mTimedDocumentRoot) {
|
2011-02-26 13:21:11 +03:00
|
|
|
return mTimedDocumentRoot;
|
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2011-02-26 13:21:11 +03:00
|
|
|
// We must not be the outermost <svg> element, try to find it
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement *outerSVGElement =
|
2012-09-22 23:26:05 +04:00
|
|
|
SVGContentUtils::GetOuterSVGElement(this);
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2011-02-26 13:21:11 +03:00
|
|
|
if (outerSVGElement) {
|
|
|
|
return outerSVGElement->GetTimedDocumentRoot();
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
2011-02-26 13:21:11 +03:00
|
|
|
// invalid structure
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
2006-04-27 01:02:25 +04:00
|
|
|
//----------------------------------------------------------------------
|
2017-06-14 15:38:10 +03:00
|
|
|
// nsSVGElement
|
2009-01-15 07:38:07 +03:00
|
|
|
nsresult
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement::BindToTree(nsIDocument* aDocument,
|
|
|
|
nsIContent* aParent,
|
2018-07-31 21:18:38 +03:00
|
|
|
nsIContent* aBindingParent)
|
2009-01-15 07:38:07 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
nsSMILAnimationController* smilController = nullptr;
|
2009-03-08 00:40:08 +03:00
|
|
|
|
|
|
|
if (aDocument) {
|
|
|
|
smilController = aDocument->GetAnimationController();
|
|
|
|
if (smilController) {
|
|
|
|
// SMIL is enabled in this document
|
|
|
|
if (WillBeOutermostSVG(aParent, aBindingParent)) {
|
|
|
|
// We'll be the outermost <svg> element. We'll need a time container.
|
|
|
|
if (!mTimedDocumentRoot) {
|
|
|
|
mTimedDocumentRoot = new nsSMILTimeContainer();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// We're a child of some other <svg> element, so we don't need our own
|
|
|
|
// time container. However, we need to make sure that we'll get a
|
|
|
|
// kick-start if we get promoted to be outermost later on.
|
2012-07-30 18:20:58 +04:00
|
|
|
mTimedDocumentRoot = nullptr;
|
2011-10-17 18:59:28 +04:00
|
|
|
mStartAnimationOnBindToTree = true;
|
2009-03-08 00:40:08 +03:00
|
|
|
}
|
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
nsresult rv = SVGGraphicsElement::BindToTree(aDocument, aParent,
|
2018-07-31 21:18:38 +03:00
|
|
|
aBindingParent);
|
2009-01-15 07:38:07 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
|
2009-03-08 00:40:08 +03:00
|
|
|
if (mTimedDocumentRoot && smilController) {
|
|
|
|
rv = mTimedDocumentRoot->SetParent(smilController);
|
2009-01-15 07:38:07 +03:00
|
|
|
if (mStartAnimationOnBindToTree) {
|
|
|
|
mTimedDocumentRoot->Begin();
|
2011-10-17 18:59:28 +04:00
|
|
|
mStartAnimationOnBindToTree = false;
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
2009-01-15 07:38:07 +03:00
|
|
|
{
|
|
|
|
if (mTimedDocumentRoot) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mTimedDocumentRoot->SetParent(nullptr);
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
SVGGraphicsElement::UnbindFromTree(aDeep, aNullParent);
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
nsSVGAnimatedTransformList*
|
|
|
|
SVGSVGElement::GetAnimatedTransformList(uint32_t aFlags)
|
2009-01-15 07:38:07 +03:00
|
|
|
{
|
2017-06-14 15:38:10 +03:00
|
|
|
if (!(aFlags & DO_ALLOCATE) && mSVGView && mSVGView->mTransforms) {
|
|
|
|
return mSVGView->mTransforms;
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
2017-06-14 15:38:10 +03:00
|
|
|
return SVGGraphicsElement::GetAnimatedTransformList(aFlags);
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2018-04-05 20:42:41 +03:00
|
|
|
void
|
2017-06-14 15:38:10 +03:00
|
|
|
SVGSVGElement::GetEventTargetParent(EventChainPreVisitor& aVisitor)
|
2007-01-04 17:39:54 +03:00
|
|
|
{
|
2017-06-14 15:38:10 +03:00
|
|
|
if (aVisitor.mEvent->mMessage == eSVGLoad) {
|
|
|
|
if (mTimedDocumentRoot) {
|
|
|
|
mTimedDocumentRoot->Begin();
|
|
|
|
// Set 'resample needed' flag, so that if any script calls a DOM method
|
|
|
|
// that requires up-to-date animations before our first sample callback,
|
|
|
|
// we'll force a synchronous sample.
|
|
|
|
AnimationNeedsResample();
|
|
|
|
}
|
2007-01-04 17:39:54 +03:00
|
|
|
}
|
2018-04-05 20:42:41 +03:00
|
|
|
SVGSVGElementBase::GetEventTargetParent(aVisitor);
|
2007-01-04 17:39:54 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2017-10-03 01:05:19 +03:00
|
|
|
SVGSVGElement::IsEventAttributeNameInternal(nsAtom* aName)
|
2010-12-20 03:45:29 +03:00
|
|
|
{
|
2017-06-14 15:38:10 +03:00
|
|
|
/* The events in EventNameType_SVGSVG are for events that are only
|
|
|
|
applicable to outermost 'svg' elements. We don't check if we're an outer
|
|
|
|
'svg' element in case we're not inserted into the document yet, but since
|
|
|
|
the target of the events in question will always be the outermost 'svg'
|
|
|
|
element, this shouldn't cause any real problems.
|
|
|
|
*/
|
|
|
|
return nsContentUtils::IsEventAttributeName(aName,
|
|
|
|
(EventNameType_SVGGraphic | EventNameType_SVGSVG));
|
2010-12-20 03:45:29 +03:00
|
|
|
}
|
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// public helpers:
|
2012-09-09 15:44:03 +04:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
int32_t
|
|
|
|
SVGSVGElement::GetIntrinsicWidth()
|
2012-05-17 14:02:41 +04:00
|
|
|
{
|
2017-06-14 15:38:10 +03:00
|
|
|
if (mLengthAttributes[ATTR_WIDTH].IsPercentage()) {
|
|
|
|
return -1;
|
2012-05-17 14:02:41 +04:00
|
|
|
}
|
2017-06-14 15:38:10 +03:00
|
|
|
// Passing |this| as a SVGViewportElement* invokes the variant of GetAnimValue
|
|
|
|
// that uses the passed argument as the context, but that's fine since we
|
|
|
|
// know the length isn't a percentage so the context won't be used (and we
|
|
|
|
// need to pass the element to be able to resolve em/ex units).
|
|
|
|
float width = mLengthAttributes[ATTR_WIDTH].GetAnimValue(this);
|
|
|
|
return nsSVGUtils::ClampToInt(width);
|
2012-05-17 14:02:41 +04:00
|
|
|
}
|
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
int32_t
|
|
|
|
SVGSVGElement::GetIntrinsicHeight()
|
2012-05-17 14:02:41 +04:00
|
|
|
{
|
2017-06-14 15:38:10 +03:00
|
|
|
if (mLengthAttributes[ATTR_HEIGHT].IsPercentage()) {
|
|
|
|
return -1;
|
2015-12-14 03:58:01 +03:00
|
|
|
}
|
2017-06-14 15:38:10 +03:00
|
|
|
// Passing |this| as a SVGViewportElement* invokes the variant of GetAnimValue
|
|
|
|
// that uses the passed argument as the context, but that's fine since we
|
|
|
|
// know the length isn't a percentage so the context won't be used (and we
|
|
|
|
// need to pass the element to be able to resolve em/ex units).
|
|
|
|
float height = mLengthAttributes[ATTR_HEIGHT].GetAnimValue(this);
|
|
|
|
return nsSVGUtils::ClampToInt(height);
|
2012-05-17 14:02:41 +04:00
|
|
|
}
|
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
void
|
|
|
|
SVGSVGElement::FlushImageTransformInvalidation()
|
2007-07-02 13:54:11 +04:00
|
|
|
{
|
2017-06-14 15:38:10 +03:00
|
|
|
MOZ_ASSERT(!GetParent(), "Should only be called on root node");
|
|
|
|
MOZ_ASSERT(OwnerDoc()->IsBeingUsedAsImage(),
|
|
|
|
"Should only be called on image documents");
|
2008-02-21 20:43:25 +03:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
if (mImageNeedsTransformInvalidation) {
|
|
|
|
InvalidateTransformNotifyFrame();
|
|
|
|
mImageNeedsTransformInvalidation = false;
|
2007-03-09 19:27:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-06-14 15:38:10 +03:00
|
|
|
// implementation helpers
|
2013-05-05 11:20:25 +04:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
bool
|
|
|
|
SVGSVGElement::WillBeOutermostSVG(nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent) const
|
|
|
|
{
|
|
|
|
nsIContent* parent = aBindingParent ? aBindingParent : aParent;
|
2009-07-22 00:34:37 +04:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
while (parent && parent->IsSVGElement()) {
|
|
|
|
if (parent->IsSVGElement(nsGkAtoms::foreignObject)) {
|
|
|
|
// SVG in a foreignObject must have its own <svg> (nsSVGOuterSVGFrame).
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (parent->IsSVGElement(nsGkAtoms::svg)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
parent = parent->GetParent();
|
2009-07-22 02:55:48 +04:00
|
|
|
}
|
2009-07-23 12:35:59 +04:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
return true;
|
2009-04-29 08:31:34 +04:00
|
|
|
}
|
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
void
|
|
|
|
SVGSVGElement::InvalidateTransformNotifyFrame()
|
2015-12-14 03:58:01 +03:00
|
|
|
{
|
2017-06-14 15:38:10 +03:00
|
|
|
nsISVGSVGFrame* svgframe = do_QueryFrame(GetPrimaryFrame());
|
|
|
|
// might fail this check if we've failed conditional processing
|
|
|
|
if (svgframe) {
|
|
|
|
svgframe->NotifyViewportOrTransformChanged(
|
|
|
|
nsSVGDisplayableFrame::TRANSFORM_CHANGED);
|
2015-12-14 03:58:01 +03:00
|
|
|
}
|
2012-03-03 13:21:09 +04:00
|
|
|
}
|
|
|
|
|
2007-08-28 03:11:14 +04:00
|
|
|
nsSVGElement::EnumAttributesInfo
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement::GetEnumInfo()
|
2007-08-28 03:11:14 +04:00
|
|
|
{
|
|
|
|
return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
|
2011-10-11 09:50:08 +04:00
|
|
|
ArrayLength(sEnumInfo));
|
2007-08-28 03:11:14 +04:00
|
|
|
}
|
2009-01-05 04:19:38 +03:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
void
|
|
|
|
SVGSVGElement::
|
|
|
|
SetImageOverridePreserveAspectRatio(const SVGPreserveAspectRatio& aPAR)
|
2009-02-03 17:42:24 +03:00
|
|
|
{
|
2017-06-14 15:38:10 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
MOZ_ASSERT(OwnerDoc()->IsBeingUsedAsImage(),
|
|
|
|
"should only override preserveAspectRatio in images");
|
|
|
|
#endif
|
2009-02-03 17:42:24 +03:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
bool hasViewBoxRect = HasViewBoxRect();
|
|
|
|
if (!hasViewBoxRect && ShouldSynthesizeViewBox()) {
|
|
|
|
// My non-<svg:image> clients will have been painting me with a synthesized
|
|
|
|
// viewBox, but my <svg:image> client that's about to paint me now does NOT
|
|
|
|
// want that. Need to tell ourselves to flush our transform.
|
|
|
|
mImageNeedsTransformInvalidation = true;
|
|
|
|
}
|
2010-11-17 02:19:21 +03:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
if (!hasViewBoxRect) {
|
|
|
|
return; // preserveAspectRatio irrelevant (only matters if we have viewBox)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SetPreserveAspectRatioProperty(aPAR)) {
|
|
|
|
mImageNeedsTransformInvalidation = true;
|
2012-09-09 15:44:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
void
|
|
|
|
SVGSVGElement::ClearImageOverridePreserveAspectRatio()
|
2011-02-09 23:13:18 +03:00
|
|
|
{
|
2017-06-14 15:38:10 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
MOZ_ASSERT(OwnerDoc()->IsBeingUsedAsImage(),
|
|
|
|
"should only override image preserveAspectRatio in images");
|
|
|
|
#endif
|
2011-02-09 23:13:18 +03:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
if (!HasViewBoxRect() && ShouldSynthesizeViewBox()) {
|
|
|
|
// My non-<svg:image> clients will want to paint me with a synthesized
|
|
|
|
// viewBox, but my <svg:image> client that just painted me did NOT
|
|
|
|
// use that. Need to tell ourselves to flush our transform.
|
|
|
|
mImageNeedsTransformInvalidation = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ClearPreserveAspectRatioProperty()) {
|
|
|
|
mImageNeedsTransformInvalidation = true;
|
|
|
|
}
|
2011-02-09 23:13:18 +03:00
|
|
|
}
|
|
|
|
|
2012-05-17 14:02:41 +04:00
|
|
|
bool
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement::SetPreserveAspectRatioProperty(const SVGPreserveAspectRatio& aPAR)
|
2012-05-17 14:02:41 +04:00
|
|
|
{
|
|
|
|
SVGPreserveAspectRatio* pAROverridePtr = new SVGPreserveAspectRatio(aPAR);
|
|
|
|
nsresult rv = SetProperty(nsGkAtoms::overridePreserveAspectRatio,
|
|
|
|
pAROverridePtr,
|
2014-03-25 17:25:47 +04:00
|
|
|
nsINode::DeleteProperty<SVGPreserveAspectRatio>,
|
2012-06-06 12:15:53 +04:00
|
|
|
true);
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(rv != NS_PROPTABLE_PROP_OVERWRITTEN,
|
|
|
|
"Setting override value when it's already set...?");
|
2012-05-17 14:02:41 +04:00
|
|
|
|
2012-10-26 17:32:10 +04:00
|
|
|
if (MOZ_UNLIKELY(NS_FAILED(rv))) {
|
2012-05-17 14:02:41 +04:00
|
|
|
// property-insertion failed (e.g. OOM in property-table code)
|
|
|
|
delete pAROverridePtr;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SVGPreserveAspectRatio*
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement::GetPreserveAspectRatioProperty() const
|
2012-05-17 14:02:41 +04:00
|
|
|
{
|
|
|
|
void* valPtr = GetProperty(nsGkAtoms::overridePreserveAspectRatio);
|
|
|
|
if (valPtr) {
|
|
|
|
return static_cast<SVGPreserveAspectRatio*>(valPtr);
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-05-17 14:02:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement::ClearPreserveAspectRatioProperty()
|
2012-05-17 14:02:41 +04:00
|
|
|
{
|
|
|
|
void* valPtr = UnsetProperty(nsGkAtoms::overridePreserveAspectRatio);
|
2017-07-27 04:03:43 +03:00
|
|
|
bool didHaveProperty = !!valPtr;
|
2012-05-17 14:02:41 +04:00
|
|
|
delete static_cast<SVGPreserveAspectRatio*>(valPtr);
|
2017-07-27 04:03:43 +03:00
|
|
|
return didHaveProperty;
|
2012-05-17 14:02:41 +04:00
|
|
|
}
|
|
|
|
|
2010-12-20 03:45:29 +03:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
SVGPreserveAspectRatio
|
|
|
|
SVGSVGElement::GetPreserveAspectRatioWithOverride() const
|
|
|
|
{
|
|
|
|
nsIDocument* doc = GetUncomposedDoc();
|
|
|
|
if (doc && doc->IsBeingUsedAsImage()) {
|
|
|
|
const SVGPreserveAspectRatio *pAROverridePtr = GetPreserveAspectRatioProperty();
|
|
|
|
if (pAROverridePtr) {
|
|
|
|
return *pAROverridePtr;
|
|
|
|
}
|
2011-02-09 23:13:18 +03:00
|
|
|
}
|
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
SVGViewElement* viewElement = GetCurrentViewElement();
|
2010-12-20 03:45:29 +03:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
// This check is equivalent to "!HasViewBoxRect() && ShouldSynthesizeViewBox()".
|
|
|
|
// We're just holding onto the viewElement that HasViewBoxRect() would look up,
|
|
|
|
// so that we don't have to look it up again later.
|
|
|
|
if (!((viewElement && viewElement->mViewBox.HasRect()) ||
|
|
|
|
(mSVGView && mSVGView->mViewBox.HasRect()) ||
|
|
|
|
mViewBox.HasRect()) &&
|
|
|
|
ShouldSynthesizeViewBox()) {
|
|
|
|
// If we're synthesizing a viewBox, use preserveAspectRatio="none";
|
|
|
|
return SVGPreserveAspectRatio(SVG_PRESERVEASPECTRATIO_NONE, SVG_MEETORSLICE_SLICE);
|
2010-12-20 03:45:29 +03:00
|
|
|
}
|
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
if (viewElement && viewElement->mPreserveAspectRatio.IsExplicitlySet()) {
|
|
|
|
return viewElement->mPreserveAspectRatio.GetAnimValue();
|
2011-02-09 23:13:18 +03:00
|
|
|
}
|
2017-06-14 15:38:10 +03:00
|
|
|
if (mSVGView && mSVGView->mPreserveAspectRatio.IsExplicitlySet()) {
|
|
|
|
return mSVGView->mPreserveAspectRatio.GetAnimValue();
|
2010-12-20 03:45:29 +03:00
|
|
|
}
|
2017-06-14 15:38:10 +03:00
|
|
|
return mPreserveAspectRatio.GetAnimValue();
|
2010-12-20 03:45:29 +03:00
|
|
|
}
|
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
SVGViewElement*
|
|
|
|
SVGSVGElement::GetCurrentViewElement() const
|
2010-12-20 03:45:29 +03:00
|
|
|
{
|
2017-06-14 15:38:10 +03:00
|
|
|
if (mCurrentViewID) {
|
|
|
|
//XXXsmaug It is unclear how this should work in case we're in Shadow DOM.
|
|
|
|
nsIDocument* doc = GetUncomposedDoc();
|
|
|
|
if (doc) {
|
|
|
|
Element *element = doc->GetElementById(*mCurrentViewID);
|
|
|
|
if (element && element->IsSVGElement(nsGkAtoms::view)) {
|
|
|
|
return static_cast<SVGViewElement*>(element);
|
|
|
|
}
|
|
|
|
}
|
2010-12-20 03:45:29 +03:00
|
|
|
}
|
2017-06-14 15:38:10 +03:00
|
|
|
return nullptr;
|
2010-12-20 03:45:29 +03:00
|
|
|
}
|
2012-05-17 14:02:41 +04:00
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
const nsSVGViewBox&
|
|
|
|
SVGSVGElement::GetViewBoxInternal() const
|
2015-01-20 17:27:16 +03:00
|
|
|
{
|
2017-06-14 15:38:10 +03:00
|
|
|
SVGViewElement* viewElement = GetCurrentViewElement();
|
|
|
|
|
|
|
|
if (viewElement && viewElement->mViewBox.HasRect()) {
|
|
|
|
return viewElement->mViewBox;
|
|
|
|
} else if (mSVGView && mSVGView->mViewBox.HasRect()) {
|
|
|
|
return mSVGView->mViewBox;
|
2015-01-20 17:27:16 +03:00
|
|
|
}
|
2017-06-14 15:38:10 +03:00
|
|
|
|
|
|
|
return mViewBox;
|
2015-01-20 17:27:16 +03:00
|
|
|
}
|
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
nsSVGAnimatedTransformList*
|
|
|
|
SVGSVGElement::GetTransformInternal() const
|
2015-01-20 17:27:16 +03:00
|
|
|
{
|
2017-06-14 15:38:10 +03:00
|
|
|
return (mSVGView && mSVGView->mTransforms)
|
|
|
|
? mSVGView->mTransforms: mTransforms;
|
2015-01-20 17:27:16 +03:00
|
|
|
}
|
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|