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/. */
|
2001-12-12 07:59:31 +00:00
|
|
|
|
2017-06-14 12:38:10 +00:00
|
|
|
#include "mozilla/dom/SVGSVGElement.h"
|
2018-12-28 02:47:10 +00:00
|
|
|
|
|
|
|
#include "mozilla/ContentEvents.h"
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 04:27:04 +00:00
|
|
|
#include "mozilla/dom/BindContext.h"
|
2017-06-14 12:38:10 +00:00
|
|
|
#include "mozilla/dom/SVGSVGElementBinding.h"
|
|
|
|
#include "mozilla/dom/SVGMatrix.h"
|
2018-12-21 23:29:24 +00:00
|
|
|
#include "mozilla/dom/SVGRect.h"
|
2017-06-14 12:38:10 +00:00
|
|
|
#include "mozilla/dom/SVGViewElement.h"
|
2014-03-18 04:48:21 +00:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2019-03-29 15:12:47 +00:00
|
|
|
#include "mozilla/PresShell.h"
|
2018-12-28 11:47:58 +00:00
|
|
|
#include "mozilla/SMILAnimationController.h"
|
2019-01-02 07:21:13 +00:00
|
|
|
#include "mozilla/SMILTimeContainer.h"
|
2011-10-11 05:50:08 +00:00
|
|
|
|
2018-12-30 18:18:30 +00:00
|
|
|
#include "DOMSVGAngle.h"
|
2010-07-16 21:42:12 +00:00
|
|
|
#include "DOMSVGLength.h"
|
2017-06-14 12:38:10 +00:00
|
|
|
#include "DOMSVGNumber.h"
|
2010-12-08 12:15:53 +00:00
|
|
|
#include "DOMSVGPoint.h"
|
2013-07-03 07:41:53 +00:00
|
|
|
#include "nsFrameSelection.h"
|
2018-12-27 17:30:38 +00:00
|
|
|
#include "nsLayoutStylesheetCache.h"
|
2017-06-14 12:38:10 +00:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsISVGSVGFrame.h"
|
2017-02-09 18:24:31 +00:00
|
|
|
#include "nsSVGDisplayableFrame.h"
|
2012-09-22 19:26:05 +00:00
|
|
|
#include "nsSVGUtils.h"
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2018-12-21 11:43:29 +00:00
|
|
|
NS_IMPL_NS_NEW_SVG_ELEMENT_CHECK_PARSER(SVG)
|
2013-01-09 23:02:45 +00:00
|
|
|
|
2013-12-30 06:50:17 +00:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2013-01-09 23:02:45 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2010-08-15 15:19:34 +00:00
|
|
|
|
2018-06-25 21:20:54 +00:00
|
|
|
using namespace SVGPreserveAspectRatio_Binding;
|
|
|
|
using namespace SVGSVGElement_Binding;
|
2018-02-18 15:53:13 +00:00
|
|
|
|
2019-01-02 18:24:11 +00:00
|
|
|
SVGEnumMapping SVGSVGElement::sZoomAndPanMap[] = {
|
2018-03-29 09:45:28 +00:00
|
|
|
{nsGkAtoms::disable, SVG_ZOOMANDPAN_DISABLE},
|
|
|
|
{nsGkAtoms::magnify, SVG_ZOOMANDPAN_MAGNIFY},
|
2017-06-14 12:38:10 +00:00
|
|
|
{nullptr, 0}};
|
2013-03-11 22:05:58 +00:00
|
|
|
|
2018-12-21 08:58:14 +00:00
|
|
|
SVGElement::EnumInfo SVGSVGElement::sEnumInfo[1] = {
|
2018-03-29 09:45:24 +00:00
|
|
|
{nsGkAtoms::zoomAndPan, sZoomAndPanMap, SVG_ZOOMANDPAN_MAGNIFY}};
|
2013-01-09 23:02:47 +00:00
|
|
|
|
2014-04-25 16:49:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(DOMSVGTranslatePoint, nsISVGPoint, mElement)
|
2013-03-04 15:40:25 +00:00
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(DOMSVGTranslatePoint, nsISVGPoint)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(DOMSVGTranslatePoint, nsISVGPoint)
|
2009-04-28 13:25:03 +00:00
|
|
|
|
2013-01-17 01:35:24 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMSVGTranslatePoint)
|
2012-12-23 04:54:20 +00:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2013-01-09 23:10:59 +00:00
|
|
|
// We have to qualify nsISVGPoint because NS_GET_IID looks for a class in the
|
|
|
|
// global namespace
|
2019-09-21 14:38:56 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISVGPoint)
|
2009-04-28 13:25:03 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2014-08-06 13:58:57 +00:00
|
|
|
DOMSVGPoint* DOMSVGTranslatePoint::Copy() {
|
|
|
|
return new DOMSVGPoint(mPt.GetX(), mPt.GetY());
|
2009-04-28 13:25:03 +00:00
|
|
|
}
|
|
|
|
|
2013-01-17 01:35:24 +00:00
|
|
|
nsISupports* DOMSVGTranslatePoint::GetParentObject() {
|
2018-05-30 02:58:51 +00:00
|
|
|
return ToSupports(mElement);
|
2012-12-23 04:54:20 +00:00
|
|
|
}
|
|
|
|
|
2013-01-17 01:35:24 +00:00
|
|
|
void DOMSVGTranslatePoint::SetX(float aValue, ErrorResult& rv) {
|
2013-02-08 19:55:07 +00:00
|
|
|
mElement->SetCurrentTranslate(aValue, mPt.GetY());
|
2012-12-23 04:54:20 +00:00
|
|
|
}
|
|
|
|
|
2013-01-17 01:35:24 +00:00
|
|
|
void DOMSVGTranslatePoint::SetY(float aValue, ErrorResult& rv) {
|
2013-02-08 19:55:07 +00:00
|
|
|
mElement->SetCurrentTranslate(mPt.GetX(), aValue);
|
2012-12-23 04:54:20 +00:00
|
|
|
}
|
|
|
|
|
2013-01-17 01:35:24 +00:00
|
|
|
already_AddRefed<nsISVGPoint> DOMSVGTranslatePoint::MatrixTransform(
|
|
|
|
SVGMatrix& matrix) {
|
2012-12-23 04:54:20 +00:00
|
|
|
float a = matrix.A(), b = matrix.B(), c = matrix.C();
|
|
|
|
float d = matrix.D(), e = matrix.E(), f = matrix.F();
|
2013-01-17 01:35:24 +00:00
|
|
|
float x = mPt.GetX();
|
|
|
|
float y = mPt.GetY();
|
2010-12-08 12:15:53 +00:00
|
|
|
|
2012-12-23 04:54:20 +00:00
|
|
|
nsCOMPtr<nsISVGPoint> point =
|
|
|
|
new DOMSVGPoint(a * x + c * y + e, b * x + d * y + f);
|
|
|
|
return point.forget();
|
2009-04-28 13:25:03 +00:00
|
|
|
}
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2017-06-14 12:38:10 +00:00
|
|
|
JSObject* SVGSVGElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-25 21:20:54 +00:00
|
|
|
return SVGSVGElement_Binding::Wrap(aCx, this, aGivenProto);
|
2015-12-14 00:58:01 +00:00
|
|
|
}
|
|
|
|
|
2001-12-12 07:59:31 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports methods
|
|
|
|
|
2013-08-02 01:29:05 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(SVGSVGElement)
|
|
|
|
|
2013-01-09 23:02:45 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(SVGSVGElement,
|
|
|
|
SVGSVGElementBase)
|
2010-01-12 20:00:49 +00:00
|
|
|
if (tmp->mTimedDocumentRoot) {
|
|
|
|
tmp->mTimedDocumentRoot->Unlink();
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2013-01-09 23:02:45 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(SVGSVGElement,
|
|
|
|
SVGSVGElementBase)
|
2010-01-12 20:00:49 +00:00
|
|
|
if (tmp->mTimedDocumentRoot) {
|
|
|
|
tmp->mTimedDocumentRoot->Traverse(&cb);
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2018-05-30 02:58:51 +00:00
|
|
|
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(SVGSVGElement, SVGSVGElementBase)
|
2001-12-12 07:59:31 +00:00
|
|
|
|
2017-06-14 12:38:10 +00:00
|
|
|
SVGView::SVGView() {
|
|
|
|
mZoomAndPan.Init(SVGSVGElement::ZOOMANDPAN, SVG_ZOOMANDPAN_MAGNIFY);
|
|
|
|
mViewBox.Init();
|
|
|
|
mPreserveAspectRatio.Init();
|
|
|
|
}
|
|
|
|
|
2001-12-12 07:59:31 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2018-09-21 20:45:49 +00:00
|
|
|
SVGSVGElement::SVGSVGElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
|
2014-03-15 19:00:17 +00:00
|
|
|
FromParser aFromParser)
|
2018-09-21 20:45:49 +00:00
|
|
|
: SVGSVGElementBase(std::move(aNodeInfo)),
|
2009-04-28 13:25:03 +00:00
|
|
|
mCurrentTranslate(0.0f, 0.0f),
|
|
|
|
mCurrentScale(1.0f),
|
|
|
|
mPreviousTranslate(0.0f, 0.0f),
|
|
|
|
mPreviousScale(1.0f),
|
2012-10-23 08:21:49 +00:00
|
|
|
mStartAnimationOnBindToTree(aFromParser == NOT_FROM_PARSER ||
|
|
|
|
aFromParser == FROM_PARSER_FRAGMENT ||
|
|
|
|
aFromParser == FROM_PARSER_XSLT),
|
2017-06-14 12:38:10 +00:00
|
|
|
mImageNeedsTransformInvalidation(false) {}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2001-12-12 07:59:31 +00:00
|
|
|
//----------------------------------------------------------------------
|
2018-05-30 02:58:49 +00:00
|
|
|
// nsINode methods
|
2001-12-12 07:59:31 +00:00
|
|
|
|
2017-06-14 11:57:40 +00:00
|
|
|
NS_IMPL_ELEMENT_CLONE_WITH_INIT_AND_PARSER(SVGSVGElement)
|
2001-12-12 07:59:31 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIDOMSVGSVGElement methods:
|
|
|
|
|
2019-03-19 00:01:03 +00:00
|
|
|
already_AddRefed<DOMSVGAnimatedLength> SVGSVGElement::X() {
|
2013-01-09 23:02:47 +00:00
|
|
|
return mLengthAttributes[ATTR_X].ToDOMAnimatedLength(this);
|
2001-12-12 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2019-03-19 00:01:03 +00:00
|
|
|
already_AddRefed<DOMSVGAnimatedLength> SVGSVGElement::Y() {
|
2013-01-09 23:02:47 +00:00
|
|
|
return mLengthAttributes[ATTR_Y].ToDOMAnimatedLength(this);
|
2001-12-12 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2019-03-19 00:01:03 +00:00
|
|
|
already_AddRefed<DOMSVGAnimatedLength> SVGSVGElement::Width() {
|
2013-01-09 23:02:47 +00:00
|
|
|
return mLengthAttributes[ATTR_WIDTH].ToDOMAnimatedLength(this);
|
2001-12-12 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2019-03-19 00:01:03 +00:00
|
|
|
already_AddRefed<DOMSVGAnimatedLength> SVGSVGElement::Height() {
|
2013-01-09 23:02:47 +00:00
|
|
|
return mLengthAttributes[ATTR_HEIGHT].ToDOMAnimatedLength(this);
|
2001-12-12 07:59:31 +00:00
|
|
|
}
|
2013-01-09 23:02:47 +00:00
|
|
|
|
2015-12-14 00:58:01 +00:00
|
|
|
bool SVGSVGElement::UseCurrentView() { return mSVGView || mCurrentViewID; }
|
2013-01-09 23:02:47 +00:00
|
|
|
|
|
|
|
float SVGSVGElement::CurrentScale() { return mCurrentScale; }
|
|
|
|
|
2005-09-30 18:51:43 +00:00
|
|
|
#define CURRENT_SCALE_MAX 16.0f
|
|
|
|
#define CURRENT_SCALE_MIN 0.0625f
|
|
|
|
|
2013-01-09 23:02:45 +00:00
|
|
|
void SVGSVGElement::SetCurrentScale(float aCurrentScale) {
|
2009-04-28 13:25:03 +00:00
|
|
|
SetCurrentScaleTranslate(aCurrentScale, mCurrentTranslate.GetX(),
|
|
|
|
mCurrentTranslate.GetY());
|
2001-12-12 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2013-01-09 23:02:47 +00:00
|
|
|
already_AddRefed<nsISVGPoint> SVGSVGElement::CurrentTranslate() {
|
2013-01-17 01:35:24 +00:00
|
|
|
nsCOMPtr<nsISVGPoint> point =
|
|
|
|
new DOMSVGTranslatePoint(&mCurrentTranslate, this);
|
2013-01-09 23:02:47 +00:00
|
|
|
return point.forget();
|
2001-12-12 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2013-01-09 23:02:47 +00: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-01-09 23:02:45 +00:00
|
|
|
void SVGSVGElement::UnsuspendRedraw(uint32_t suspend_handle_id) {
|
2012-03-20 12:15:53 +00:00
|
|
|
// no-op
|
2001-12-12 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2013-01-09 23:02:45 +00:00
|
|
|
void SVGSVGElement::UnsuspendRedrawAll() {
|
2012-03-20 12:15:53 +00:00
|
|
|
// no-op
|
2013-01-09 23:02:47 +00:00
|
|
|
}
|
|
|
|
|
2015-01-24 09:35:22 +00:00
|
|
|
void SVGSVGElement::ForceRedraw() {
|
2015-01-23 15:28:25 +00:00
|
|
|
// no-op
|
2001-12-12 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 19:55:07 +00:00
|
|
|
void SVGSVGElement::PauseAnimations() {
|
2013-01-27 19:30:21 +00:00
|
|
|
if (mTimedDocumentRoot) {
|
2019-01-02 07:21:13 +00:00
|
|
|
mTimedDocumentRoot->Pause(SMILTimeContainer::PAUSE_SCRIPT);
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
2013-01-27 19:30:21 +00:00
|
|
|
// else we're not the outermost <svg> or not bound to a tree, so silently fail
|
2001-12-12 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 19:55:07 +00:00
|
|
|
void SVGSVGElement::UnpauseAnimations() {
|
2013-01-27 19:30:21 +00:00
|
|
|
if (mTimedDocumentRoot) {
|
2019-01-02 07:21:13 +00:00
|
|
|
mTimedDocumentRoot->Resume(SMILTimeContainer::PAUSE_SCRIPT);
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
2013-01-27 19:30:21 +00:00
|
|
|
// else we're not the outermost <svg> or not bound to a tree, so silently fail
|
2001-12-12 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 19:55:07 +00:00
|
|
|
bool SVGSVGElement::AnimationsPaused() {
|
2019-01-02 07:21:13 +00:00
|
|
|
SMILTimeContainer* root = GetTimedDocumentRoot();
|
|
|
|
return root && root->IsPausedByType(SMILTimeContainer::PAUSE_SCRIPT);
|
2001-12-12 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2018-12-21 05:37:58 +00:00
|
|
|
float SVGSVGElement::GetCurrentTimeAsFloat() {
|
2019-01-02 07:21:13 +00:00
|
|
|
SMILTimeContainer* root = GetTimedDocumentRoot();
|
2013-01-27 19:30:21 +00:00
|
|
|
if (root) {
|
2018-12-21 05:37:58 +00:00
|
|
|
double fCurrentTimeMs = double(root->GetCurrentTimeAsSMILTime());
|
2013-01-27 19:30:21 +00:00
|
|
|
return (float)(fCurrentTimeMs / PR_MSEC_PER_SEC);
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
2019-04-20 10:26:19 +00:00
|
|
|
return 0.f;
|
2001-12-12 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 19:55:07 +00:00
|
|
|
void SVGSVGElement::SetCurrentTime(float seconds) {
|
2013-01-27 19:30:21 +00: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
|
2019-01-25 03:24:01 +00:00
|
|
|
SMILTime lMilliseconds = int64_t(NS_round(fMilliseconds));
|
2013-01-27 19:30:21 +00:00
|
|
|
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 01:20:17 +00:00
|
|
|
}
|
2013-01-27 19:30:21 +00:00
|
|
|
// else we're not the outermost <svg> or not bound to a tree, so silently fail
|
2001-12-12 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2013-07-03 07:41:53 +00:00
|
|
|
void SVGSVGElement::DeselectAll() {
|
|
|
|
nsIFrame* frame = GetPrimaryFrame();
|
|
|
|
if (frame) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsFrameSelection> frameSelection = frame->GetFrameSelection();
|
2013-07-03 07:41:53 +00:00
|
|
|
frameSelection->ClearNormalSelection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-09 23:02:47 +00:00
|
|
|
already_AddRefed<DOMSVGNumber> SVGSVGElement::CreateSVGNumber() {
|
2019-01-26 17:12:16 +00:00
|
|
|
return do_AddRef(new DOMSVGNumber(this));
|
2013-01-09 23:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMSVGLength> SVGSVGElement::CreateSVGLength() {
|
2019-01-26 17:12:16 +00:00
|
|
|
return do_AddRef(new DOMSVGLength());
|
2013-01-09 23:02:47 +00:00
|
|
|
}
|
|
|
|
|
2018-12-30 18:18:30 +00:00
|
|
|
already_AddRefed<DOMSVGAngle> SVGSVGElement::CreateSVGAngle() {
|
|
|
|
return do_AddRef(new DOMSVGAngle(this));
|
2001-12-12 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2013-01-09 23:02:47 +00:00
|
|
|
already_AddRefed<nsISVGPoint> SVGSVGElement::CreateSVGPoint() {
|
2019-01-26 17:12:16 +00:00
|
|
|
return do_AddRef(new DOMSVGPoint(0, 0));
|
2013-01-09 23:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<SVGMatrix> SVGSVGElement::CreateSVGMatrix() {
|
2019-01-26 17:12:16 +00:00
|
|
|
return do_AddRef(new SVGMatrix());
|
2013-01-09 23:02:47 +00:00
|
|
|
}
|
|
|
|
|
2019-06-20 14:03:54 +00:00
|
|
|
already_AddRefed<SVGRect> SVGSVGElement::CreateSVGRect() {
|
|
|
|
return do_AddRef(new SVGRect(this));
|
2001-12-12 07:59:31 +00:00
|
|
|
}
|
|
|
|
|
2018-12-28 17:20:15 +00:00
|
|
|
already_AddRefed<DOMSVGTransform> SVGSVGElement::CreateSVGTransform() {
|
2019-01-26 17:12:16 +00:00
|
|
|
return do_AddRef(new DOMSVGTransform());
|
2013-01-09 23:02:47 +00:00
|
|
|
}
|
|
|
|
|
2018-12-28 17:20:15 +00:00
|
|
|
already_AddRefed<DOMSVGTransform> SVGSVGElement::CreateSVGTransformFromMatrix(
|
2013-01-11 20:30:21 +00:00
|
|
|
SVGMatrix& matrix) {
|
2019-01-26 17:12:16 +00:00
|
|
|
return do_AddRef(new DOMSVGTransform(matrix.GetMatrix()));
|
2013-01-09 23:02:47 +00:00
|
|
|
}
|
|
|
|
|
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 12:39:26 +00:00
|
|
|
//----------------------------------------------------------------------
|
2017-03-28 12:55:05 +00: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 12:39:26 +00:00
|
|
|
|
2013-01-09 23:02:45 +00:00
|
|
|
void SVGSVGElement::SetCurrentScaleTranslate(float s, float x, float y) {
|
2009-04-28 13:25:03 +00:00
|
|
|
if (s == mCurrentScale && x == mCurrentTranslate.GetX() &&
|
|
|
|
y == mCurrentTranslate.GetY()) {
|
2013-02-08 19:55:07 +00:00
|
|
|
return;
|
2005-08-25 21:31:09 +00:00
|
|
|
}
|
|
|
|
|
2009-04-28 13:25:03 +00: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 12:38:10 +00:00
|
|
|
|
2009-04-28 13:25:03 +00: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 12:55:05 +00:00
|
|
|
//
|
|
|
|
// XXX This comment is out-of-date due to removal of SVGZoomEvent. Can we
|
|
|
|
// remove some of this code?
|
2009-04-28 13:25:03 +00:00
|
|
|
mPreviousScale = mCurrentScale;
|
|
|
|
mPreviousTranslate = mCurrentTranslate;
|
2017-06-14 12:38:10 +00:00
|
|
|
|
2009-04-28 13:25:03 +00:00
|
|
|
mCurrentScale = s;
|
2013-01-17 01:35:24 +00:00
|
|
|
mCurrentTranslate = SVGPoint(x, y);
|
2005-08-25 21:31:09 +00:00
|
|
|
|
2009-04-28 13:25:03 +00:00
|
|
|
// now dispatch the appropriate event if we are the root element
|
2019-01-02 13:05:23 +00:00
|
|
|
Document* doc = GetUncomposedDoc();
|
2005-08-25 21:31:09 +00:00
|
|
|
if (doc) {
|
2019-03-29 15:12:47 +00:00
|
|
|
RefPtr<PresShell> presShell = doc->GetPresShell();
|
2007-12-12 02:26:09 +00:00
|
|
|
if (presShell && IsRoot()) {
|
2005-08-25 21:31:09 +00:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2017-03-28 12:55:05 +00:00
|
|
|
if (mPreviousScale == mCurrentScale) {
|
2015-09-07 14:55:52 +00:00
|
|
|
WidgetEvent svgScrollEvent(true, eSVGScroll);
|
2014-07-30 17:16:57 +00:00
|
|
|
presShell->HandleDOMEventWithTarget(this, &svgScrollEvent, &status);
|
|
|
|
}
|
2009-04-28 13:25:03 +00:00
|
|
|
InvalidateTransformNotifyFrame();
|
2005-08-25 21:31:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-09 23:02:45 +00:00
|
|
|
void SVGSVGElement::SetCurrentTranslate(float x, float y) {
|
2013-02-08 19:55:07 +00:00
|
|
|
SetCurrentScaleTranslate(mCurrentScale, x, y);
|
2005-08-25 21:31:09 +00:00
|
|
|
}
|
|
|
|
|
2017-06-14 12:38:10 +00: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>();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2019-01-02 07:21:13 +00:00
|
|
|
SMILTimeContainer* SVGSVGElement::GetTimedDocumentRoot() {
|
2009-01-15 04:38:07 +00:00
|
|
|
if (mTimedDocumentRoot) {
|
2011-02-26 10:21:11 +00:00
|
|
|
return mTimedDocumentRoot;
|
|
|
|
}
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2011-02-26 10:21:11 +00:00
|
|
|
// We must not be the outermost <svg> element, try to find it
|
2012-09-22 19:26:05 +00:00
|
|
|
SVGSVGElement* outerSVGElement = SVGContentUtils::GetOuterSVGElement(this);
|
2009-01-15 04:38:07 +00:00
|
|
|
|
2011-02-26 10:21:11 +00:00
|
|
|
if (outerSVGElement) {
|
|
|
|
return outerSVGElement->GetTimedDocumentRoot();
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
2011-02-26 10:21:11 +00:00
|
|
|
// invalid structure
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
2006-04-26 21:02:25 +00:00
|
|
|
//----------------------------------------------------------------------
|
2018-12-21 08:58:14 +00:00
|
|
|
// SVGElement
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 04:27:04 +00:00
|
|
|
nsresult SVGSVGElement::BindToTree(BindContext& aContext, nsINode& aParent) {
|
2018-12-28 11:47:58 +00:00
|
|
|
SMILAnimationController* smilController = nullptr;
|
2009-03-07 21:40:08 +00:00
|
|
|
|
2019-06-01 14:40:33 +00:00
|
|
|
// FIXME(emilio, bug 1555948): Should probably use composed doc.
|
|
|
|
if (Document* doc = aContext.GetUncomposedDoc()) {
|
|
|
|
if ((smilController = doc->GetAnimationController())) {
|
2009-03-07 21:40:08 +00:00
|
|
|
// SMIL is enabled in this document
|
2019-11-15 10:19:55 +00:00
|
|
|
if (WillBeOutermostSVG(aParent)) {
|
2009-03-07 21:40:08 +00:00
|
|
|
// We'll be the outermost <svg> element. We'll need a time container.
|
|
|
|
if (!mTimedDocumentRoot) {
|
2019-01-02 07:21:13 +00:00
|
|
|
mTimedDocumentRoot = new SMILTimeContainer();
|
2009-03-07 21:40:08 +00:00
|
|
|
}
|
|
|
|
} 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 14:20:58 +00:00
|
|
|
mTimedDocumentRoot = nullptr;
|
2011-10-17 14:59:28 +00:00
|
|
|
mStartAnimationOnBindToTree = true;
|
2009-03-07 21:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 04:27:04 +00:00
|
|
|
nsresult rv = SVGGraphicsElement::BindToTree(aContext, aParent);
|
2009-01-15 04:38:07 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-03-07 21:40:08 +00:00
|
|
|
if (mTimedDocumentRoot && smilController) {
|
|
|
|
rv = mTimedDocumentRoot->SetParent(smilController);
|
2009-01-15 04:38:07 +00:00
|
|
|
if (mStartAnimationOnBindToTree) {
|
|
|
|
mTimedDocumentRoot->Begin();
|
2011-10-17 14:59:28 +00:00
|
|
|
mStartAnimationOnBindToTree = false;
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2019-05-28 22:47:08 +00:00
|
|
|
void SVGSVGElement::UnbindFromTree(bool aNullParent) {
|
2009-01-15 04:38:07 +00:00
|
|
|
if (mTimedDocumentRoot) {
|
2012-07-30 14:20:58 +00:00
|
|
|
mTimedDocumentRoot->SetParent(nullptr);
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 22:47:08 +00:00
|
|
|
SVGGraphicsElement::UnbindFromTree(aNullParent);
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
|
2018-12-26 23:46:38 +00:00
|
|
|
SVGAnimatedTransformList* SVGSVGElement::GetAnimatedTransformList(
|
2017-06-14 12:38:10 +00:00
|
|
|
uint32_t aFlags) {
|
|
|
|
if (!(aFlags & DO_ALLOCATE) && mSVGView && mSVGView->mTransforms) {
|
|
|
|
return mSVGView->mTransforms;
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
2017-06-14 12:38:10 +00:00
|
|
|
return SVGGraphicsElement::GetAnimatedTransformList(aFlags);
|
2009-01-15 04:38:07 +00:00
|
|
|
}
|
|
|
|
|
2017-06-14 12:38:10 +00:00
|
|
|
void SVGSVGElement::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
|
|
|
|
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 14:39:54 +00:00
|
|
|
}
|
2018-04-05 17:42:41 +00:00
|
|
|
SVGSVGElementBase::GetEventTargetParent(aVisitor);
|
2007-01-04 14:39:54 +00:00
|
|
|
}
|
|
|
|
|
2017-10-02 22:05:19 +00:00
|
|
|
bool SVGSVGElement::IsEventAttributeNameInternal(nsAtom* aName) {
|
2017-06-14 12:38:10 +00: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 00:45:29 +00:00
|
|
|
}
|
|
|
|
|
2017-06-14 12:38:10 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// public helpers:
|
2012-09-09 11:44:03 +00:00
|
|
|
|
2017-06-14 12:38:10 +00:00
|
|
|
int32_t SVGSVGElement::GetIntrinsicWidth() {
|
|
|
|
if (mLengthAttributes[ATTR_WIDTH].IsPercentage()) {
|
|
|
|
return -1;
|
2012-05-17 10:02:41 +00:00
|
|
|
}
|
2017-06-14 12:38:10 +00: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 10:02:41 +00:00
|
|
|
}
|
|
|
|
|
2017-06-14 12:38:10 +00:00
|
|
|
int32_t SVGSVGElement::GetIntrinsicHeight() {
|
|
|
|
if (mLengthAttributes[ATTR_HEIGHT].IsPercentage()) {
|
|
|
|
return -1;
|
2015-12-14 00:58:01 +00:00
|
|
|
}
|
2017-06-14 12:38:10 +00: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 10:02:41 +00:00
|
|
|
}
|
|
|
|
|
2017-06-14 12:38:10 +00:00
|
|
|
void SVGSVGElement::FlushImageTransformInvalidation() {
|
|
|
|
MOZ_ASSERT(!GetParent(), "Should only be called on root node");
|
|
|
|
MOZ_ASSERT(OwnerDoc()->IsBeingUsedAsImage(),
|
|
|
|
"Should only be called on image documents");
|
2008-02-21 17:43:25 +00:00
|
|
|
|
2017-06-14 12:38:10 +00:00
|
|
|
if (mImageNeedsTransformInvalidation) {
|
|
|
|
InvalidateTransformNotifyFrame();
|
|
|
|
mImageNeedsTransformInvalidation = false;
|
2007-03-09 16:27:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-06-14 12:38:10 +00:00
|
|
|
// implementation helpers
|
2013-05-05 07:20:25 +00:00
|
|
|
|
2019-11-15 10:19:55 +00:00
|
|
|
bool SVGSVGElement::WillBeOutermostSVG(nsINode& aParent) const {
|
|
|
|
nsINode* parent = &aParent;
|
2017-06-14 12:38:10 +00: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;
|
|
|
|
}
|
2019-11-15 10:19:55 +00:00
|
|
|
parent = parent->GetParentOrShadowHostNode();
|
2009-07-21 22:55:48 +00:00
|
|
|
}
|
2009-07-23 08:35:59 +00:00
|
|
|
|
2017-06-14 12:38:10 +00:00
|
|
|
return true;
|
2009-04-29 04:31:34 +00:00
|
|
|
}
|
|
|
|
|
2017-06-14 12:38:10 +00:00
|
|
|
void SVGSVGElement::InvalidateTransformNotifyFrame() {
|
|
|
|
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 00:58:01 +00:00
|
|
|
}
|
2012-03-03 09:21:09 +00:00
|
|
|
}
|
|
|
|
|
2018-12-21 08:58:14 +00:00
|
|
|
SVGElement::EnumAttributesInfo SVGSVGElement::GetEnumInfo() {
|
2007-08-27 23:11:14 +00:00
|
|
|
return EnumAttributesInfo(mEnumAttributes, sEnumInfo, ArrayLength(sEnumInfo));
|
|
|
|
}
|
2009-01-05 01:19:38 +00:00
|
|
|
|
2017-06-14 12:38:10 +00:00
|
|
|
void SVGSVGElement::SetImageOverridePreserveAspectRatio(
|
|
|
|
const SVGPreserveAspectRatio& aPAR) {
|
|
|
|
MOZ_ASSERT(OwnerDoc()->IsBeingUsedAsImage(),
|
|
|
|
"should only override preserveAspectRatio in images");
|
2009-02-03 14:42:24 +00:00
|
|
|
|
2019-04-10 04:08:14 +00:00
|
|
|
bool hasViewBox = HasViewBox();
|
|
|
|
if (!hasViewBox && ShouldSynthesizeViewBox()) {
|
2017-06-14 12:38:10 +00:00
|
|
|
// 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-16 23:19:21 +00:00
|
|
|
|
2019-04-10 04:08:14 +00:00
|
|
|
if (!hasViewBox) {
|
2017-06-14 12:38:10 +00:00
|
|
|
return; // preserveAspectRatio irrelevant (only matters if we have viewBox)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SetPreserveAspectRatioProperty(aPAR)) {
|
|
|
|
mImageNeedsTransformInvalidation = true;
|
2012-09-09 11:44:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-14 12:38:10 +00:00
|
|
|
void SVGSVGElement::ClearImageOverridePreserveAspectRatio() {
|
|
|
|
MOZ_ASSERT(OwnerDoc()->IsBeingUsedAsImage(),
|
|
|
|
"should only override image preserveAspectRatio in images");
|
2011-02-09 20:13:18 +00:00
|
|
|
|
2019-04-10 04:08:14 +00:00
|
|
|
if (!HasViewBox() && ShouldSynthesizeViewBox()) {
|
2017-06-14 12:38:10 +00:00
|
|
|
// 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 20:13:18 +00:00
|
|
|
}
|
|
|
|
|
2013-01-09 23:02:45 +00:00
|
|
|
bool SVGSVGElement::SetPreserveAspectRatioProperty(
|
|
|
|
const SVGPreserveAspectRatio& aPAR) {
|
2012-05-17 10:02:41 +00:00
|
|
|
SVGPreserveAspectRatio* pAROverridePtr = new SVGPreserveAspectRatio(aPAR);
|
|
|
|
nsresult rv =
|
|
|
|
SetProperty(nsGkAtoms::overridePreserveAspectRatio, pAROverridePtr,
|
2014-03-25 13:25:47 +00:00
|
|
|
nsINode::DeleteProperty<SVGPreserveAspectRatio>, true);
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(rv != NS_PROPTABLE_PROP_OVERWRITTEN,
|
|
|
|
"Setting override value when it's already set...?");
|
2012-05-17 10:02:41 +00:00
|
|
|
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(NS_FAILED(rv))) {
|
2012-05-17 10:02:41 +00:00
|
|
|
// property-insertion failed (e.g. OOM in property-table code)
|
|
|
|
delete pAROverridePtr;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-09 23:02:45 +00:00
|
|
|
const SVGPreserveAspectRatio* SVGSVGElement::GetPreserveAspectRatioProperty()
|
2012-05-17 10:02:41 +00:00
|
|
|
const {
|
|
|
|
void* valPtr = GetProperty(nsGkAtoms::overridePreserveAspectRatio);
|
|
|
|
if (valPtr) {
|
|
|
|
return static_cast<SVGPreserveAspectRatio*>(valPtr);
|
|
|
|
}
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2012-05-17 10:02:41 +00:00
|
|
|
}
|
|
|
|
|
2013-01-09 23:02:45 +00:00
|
|
|
bool SVGSVGElement::ClearPreserveAspectRatioProperty() {
|
2012-05-17 10:02:41 +00:00
|
|
|
void* valPtr = UnsetProperty(nsGkAtoms::overridePreserveAspectRatio);
|
2017-07-27 01:03:43 +00:00
|
|
|
bool didHaveProperty = !!valPtr;
|
2012-05-17 10:02:41 +00:00
|
|
|
delete static_cast<SVGPreserveAspectRatio*>(valPtr);
|
2017-07-27 01:03:43 +00:00
|
|
|
return didHaveProperty;
|
2012-05-17 10:02:41 +00:00
|
|
|
}
|
|
|
|
|
2017-06-14 12:38:10 +00:00
|
|
|
SVGPreserveAspectRatio SVGSVGElement::GetPreserveAspectRatioWithOverride()
|
|
|
|
const {
|
2019-01-02 13:05:23 +00:00
|
|
|
Document* doc = GetUncomposedDoc();
|
2017-06-14 12:38:10 +00:00
|
|
|
if (doc && doc->IsBeingUsedAsImage()) {
|
|
|
|
const SVGPreserveAspectRatio* pAROverridePtr =
|
|
|
|
GetPreserveAspectRatioProperty();
|
|
|
|
if (pAROverridePtr) {
|
|
|
|
return *pAROverridePtr;
|
|
|
|
}
|
2011-02-09 20:13:18 +00:00
|
|
|
}
|
|
|
|
|
2017-06-14 12:38:10 +00:00
|
|
|
SVGViewElement* viewElement = GetCurrentViewElement();
|
2010-12-20 00:45:29 +00:00
|
|
|
|
2019-04-10 04:08:14 +00:00
|
|
|
// This check is equivalent to "!HasViewBox() &&
|
2017-06-14 12:38:10 +00:00
|
|
|
// ShouldSynthesizeViewBox()". We're just holding onto the viewElement that
|
2019-04-10 04:08:14 +00:00
|
|
|
// HasViewBox() would look up, so that we don't have to look it up again
|
2017-06-14 12:38:10 +00:00
|
|
|
// 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 00:45:29 +00:00
|
|
|
}
|
|
|
|
|
2017-06-14 12:38:10 +00:00
|
|
|
if (viewElement && viewElement->mPreserveAspectRatio.IsExplicitlySet()) {
|
|
|
|
return viewElement->mPreserveAspectRatio.GetAnimValue();
|
2011-02-09 20:13:18 +00:00
|
|
|
}
|
2017-06-14 12:38:10 +00:00
|
|
|
if (mSVGView && mSVGView->mPreserveAspectRatio.IsExplicitlySet()) {
|
|
|
|
return mSVGView->mPreserveAspectRatio.GetAnimValue();
|
2010-12-20 00:45:29 +00:00
|
|
|
}
|
2017-06-14 12:38:10 +00:00
|
|
|
return mPreserveAspectRatio.GetAnimValue();
|
2010-12-20 00:45:29 +00:00
|
|
|
}
|
|
|
|
|
2017-06-14 12:38:10 +00:00
|
|
|
SVGViewElement* SVGSVGElement::GetCurrentViewElement() const {
|
|
|
|
if (mCurrentViewID) {
|
|
|
|
// XXXsmaug It is unclear how this should work in case we're in Shadow DOM.
|
2019-01-02 13:05:23 +00:00
|
|
|
Document* doc = GetUncomposedDoc();
|
2017-06-14 12:38:10 +00:00
|
|
|
if (doc) {
|
|
|
|
Element* element = doc->GetElementById(*mCurrentViewID);
|
|
|
|
if (element && element->IsSVGElement(nsGkAtoms::view)) {
|
|
|
|
return static_cast<SVGViewElement*>(element);
|
|
|
|
}
|
|
|
|
}
|
2010-12-20 00:45:29 +00:00
|
|
|
}
|
2017-06-14 12:38:10 +00:00
|
|
|
return nullptr;
|
2010-12-20 00:45:29 +00:00
|
|
|
}
|
2012-05-17 10:02:41 +00:00
|
|
|
|
2019-04-04 17:40:56 +00:00
|
|
|
const SVGAnimatedViewBox& SVGSVGElement::GetViewBoxInternal() const {
|
2017-06-14 12:38:10 +00:00
|
|
|
SVGViewElement* viewElement = GetCurrentViewElement();
|
|
|
|
|
|
|
|
if (viewElement && viewElement->mViewBox.HasRect()) {
|
|
|
|
return viewElement->mViewBox;
|
2019-04-20 10:26:19 +00:00
|
|
|
}
|
|
|
|
if (mSVGView && mSVGView->mViewBox.HasRect()) {
|
2017-06-14 12:38:10 +00:00
|
|
|
return mSVGView->mViewBox;
|
2015-01-20 14:27:16 +00:00
|
|
|
}
|
2017-06-14 12:38:10 +00:00
|
|
|
|
|
|
|
return mViewBox;
|
2015-01-20 14:27:16 +00:00
|
|
|
}
|
|
|
|
|
2018-12-26 23:46:38 +00:00
|
|
|
SVGAnimatedTransformList* SVGSVGElement::GetTransformInternal() const {
|
2017-06-14 12:38:10 +00:00
|
|
|
return (mSVGView && mSVGView->mTransforms) ? mSVGView->mTransforms
|
|
|
|
: mTransforms;
|
2015-01-20 14:27:16 +00:00
|
|
|
}
|
|
|
|
|
2013-01-09 23:02:45 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|