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/. */
|
2004-12-09 06:16:15 +03:00
|
|
|
|
2018-12-28 05:47:10 +03:00
|
|
|
#include "mozilla/dom/SVGMarkerElement.h"
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2019-03-19 03:01:03 +03:00
|
|
|
#include "DOMSVGAngle.h"
|
2010-12-20 03:45:29 +03:00
|
|
|
#include "SVGAnimatedPreserveAspectRatio.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2018-12-28 05:47:10 +03:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2018-12-22 02:29:24 +03:00
|
|
|
#include "mozilla/dom/SVGGeometryElement.h"
|
2018-02-02 16:21:33 +03:00
|
|
|
#include "mozilla/dom/SVGLengthBinding.h"
|
2013-01-30 02:11:44 +04:00
|
|
|
#include "mozilla/dom/SVGMarkerElementBinding.h"
|
2013-12-30 10:50:17 +04:00
|
|
|
#include "mozilla/gfx/Matrix.h"
|
2014-10-01 13:26:00 +04:00
|
|
|
#include "mozilla/FloatingPoint.h"
|
2019-01-25 02:40:25 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2012-09-22 23:26:05 +04:00
|
|
|
#include "SVGContentUtils.h"
|
2004-12-09 06:16:15 +03:00
|
|
|
|
2014-09-10 17:26:12 +04:00
|
|
|
using namespace mozilla::gfx;
|
2018-06-26 00:20:54 +03:00
|
|
|
using namespace mozilla::dom::SVGMarkerElement_Binding;
|
2014-09-10 17:26:12 +04:00
|
|
|
|
2018-12-21 14:43:29 +03:00
|
|
|
NS_IMPL_NS_NEW_SVG_ELEMENT(Marker)
|
2010-12-20 03:45:29 +03:00
|
|
|
|
2013-01-30 02:11:44 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2018-06-26 00:20:54 +03:00
|
|
|
using namespace SVGAngle_Binding;
|
2018-02-18 18:53:13 +03:00
|
|
|
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
JSObject* SVGMarkerElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return SVGMarkerElement_Binding::Wrap(aCx, this, aGivenProto);
|
2013-01-30 02:11:44 +04:00
|
|
|
}
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::LengthInfo SVGMarkerElement::sLengthInfo[4] = {
|
2018-03-29 12:45:24 +03:00
|
|
|
{nsGkAtoms::refX, 0, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER,
|
|
|
|
SVGContentUtils::X},
|
|
|
|
{nsGkAtoms::refY, 0, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER,
|
|
|
|
SVGContentUtils::Y},
|
|
|
|
{nsGkAtoms::markerWidth, 3, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER,
|
|
|
|
SVGContentUtils::X},
|
|
|
|
{nsGkAtoms::markerHeight, 3, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER,
|
|
|
|
SVGContentUtils::Y},
|
2004-12-09 06:16:15 +03:00
|
|
|
};
|
|
|
|
|
2019-01-02 21:24:11 +03:00
|
|
|
SVGEnumMapping SVGMarkerElement::sUnitsMap[] = {
|
2018-03-29 12:45:28 +03:00
|
|
|
{nsGkAtoms::strokeWidth, SVG_MARKERUNITS_STROKEWIDTH},
|
|
|
|
{nsGkAtoms::userSpaceOnUse, SVG_MARKERUNITS_USERSPACEONUSE},
|
2012-07-30 18:20:58 +04:00
|
|
|
{nullptr, 0}};
|
2007-08-28 03:11:14 +04:00
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::EnumInfo SVGMarkerElement::sEnumInfo[1] = {
|
2013-02-19 02:48:54 +04:00
|
|
|
{nsGkAtoms::markerUnits, sUnitsMap, SVG_MARKERUNITS_STROKEWIDTH}};
|
2007-08-28 03:11:14 +04:00
|
|
|
|
2004-12-09 06:16:15 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2018-09-21 23:45:49 +03:00
|
|
|
SVGMarkerElement::SVGMarkerElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
|
|
|
: SVGMarkerElementBase(std::move(aNodeInfo)), mCoordCtx(nullptr) {}
|
2004-12-09 06:16:15 +03:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-05-30 05:58:49 +03:00
|
|
|
// nsINode methods
|
2004-12-09 06:16:15 +03:00
|
|
|
|
2013-01-30 02:11:44 +04:00
|
|
|
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGMarkerElement)
|
2004-12-09 06:16:15 +03:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2013-01-30 02:11:44 +04:00
|
|
|
|
2013-05-09 21:42:12 +04:00
|
|
|
already_AddRefed<SVGAnimatedRect> SVGMarkerElement::ViewBox() {
|
2013-05-20 15:46:12 +04:00
|
|
|
return mViewBox.ToSVGAnimatedRect(this);
|
2004-12-09 06:16:15 +03:00
|
|
|
}
|
|
|
|
|
2013-01-30 02:11:44 +04:00
|
|
|
already_AddRefed<DOMSVGAnimatedPreserveAspectRatio>
|
|
|
|
SVGMarkerElement::PreserveAspectRatio() {
|
2015-01-27 12:51:34 +03:00
|
|
|
return mPreserveAspectRatio.ToDOMAnimatedPreserveAspectRatio(this);
|
2004-12-09 06:16:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2013-01-30 02:11:44 +04:00
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedLength> SVGMarkerElement::RefX() {
|
2013-01-30 02:11:44 +04:00
|
|
|
return mLengthAttributes[REFX].ToDOMAnimatedLength(this);
|
2004-12-09 06:16:15 +03:00
|
|
|
}
|
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedLength> SVGMarkerElement::RefY() {
|
2013-01-30 02:11:44 +04:00
|
|
|
return mLengthAttributes[REFY].ToDOMAnimatedLength(this);
|
2004-12-09 06:16:15 +03:00
|
|
|
}
|
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedEnumeration> SVGMarkerElement::MarkerUnits() {
|
2013-01-30 02:11:44 +04:00
|
|
|
return mEnumAttributes[MARKERUNITS].ToDOMAnimatedEnum(this);
|
2004-12-09 06:16:15 +03:00
|
|
|
}
|
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedLength> SVGMarkerElement::MarkerWidth() {
|
2013-01-30 02:11:44 +04:00
|
|
|
return mLengthAttributes[MARKERWIDTH].ToDOMAnimatedLength(this);
|
2004-12-09 06:16:15 +03:00
|
|
|
}
|
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedLength> SVGMarkerElement::MarkerHeight() {
|
2013-01-30 02:11:44 +04:00
|
|
|
return mLengthAttributes[MARKERHEIGHT].ToDOMAnimatedLength(this);
|
2004-12-09 06:16:15 +03:00
|
|
|
}
|
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedEnumeration> SVGMarkerElement::OrientType() {
|
2019-02-15 11:41:37 +03:00
|
|
|
return mOrient.ToDOMAnimatedEnum(this);
|
2004-12-09 06:16:15 +03:00
|
|
|
}
|
|
|
|
|
2019-03-19 03:01:03 +03:00
|
|
|
already_AddRefed<DOMSVGAnimatedAngle> SVGMarkerElement::OrientAngle() {
|
2019-02-15 11:41:37 +03:00
|
|
|
return mOrient.ToDOMAnimatedAngle(this);
|
2004-12-09 06:16:15 +03:00
|
|
|
}
|
|
|
|
|
2013-02-19 02:48:54 +04:00
|
|
|
void SVGMarkerElement::SetOrientToAuto() {
|
2020-02-20 01:06:09 +03:00
|
|
|
mOrient.SetBaseType(SVG_MARKER_ORIENT_AUTO, this, IgnoreErrors());
|
2013-01-30 02:11:44 +04:00
|
|
|
}
|
2013-01-29 13:45:50 +04:00
|
|
|
|
2018-12-30 21:18:30 +03:00
|
|
|
void SVGMarkerElement::SetOrientToAngle(DOMSVGAngle& angle, ErrorResult& rv) {
|
2013-01-30 02:11:44 +04:00
|
|
|
float f = angle.Value();
|
2014-10-01 13:26:00 +04:00
|
|
|
if (!IsFinite(f)) {
|
2021-05-13 02:32:38 +03:00
|
|
|
rv.ThrowTypeError("Unknown or invalid type");
|
2013-01-30 02:11:44 +04:00
|
|
|
return;
|
|
|
|
}
|
2019-02-15 11:41:37 +03:00
|
|
|
mOrient.SetBaseValue(f, angle.UnitType(), this, true);
|
2004-12-09 06:16:15 +03:00
|
|
|
}
|
|
|
|
|
2006-04-27 01:02:25 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIContent methods
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
2017-10-03 01:05:19 +03:00
|
|
|
SVGMarkerElement::IsAttributeMapped(const nsAtom* name) const {
|
2006-04-27 01:02:25 +04:00
|
|
|
static const MappedAttributeEntry* const map[] = {sFEFloodMap,
|
2007-01-30 16:19:55 +03:00
|
|
|
sFiltersMap,
|
2006-10-20 03:48:12 +04:00
|
|
|
sFontSpecificationMap,
|
|
|
|
sGradientStopMap,
|
2007-07-26 10:57:42 +04:00
|
|
|
sLightingEffectsMap,
|
2006-10-20 03:48:12 +04:00
|
|
|
sMarkersMap,
|
|
|
|
sTextContentElementsMap,
|
2013-01-30 02:11:44 +04:00
|
|
|
sViewportsMap,
|
|
|
|
sColorMap,
|
|
|
|
sFillStrokeMap,
|
|
|
|
sGraphicsMap};
|
2006-10-20 03:48:12 +04:00
|
|
|
|
2011-12-18 14:09:27 +04:00
|
|
|
return FindAttributeDependence(name, map) ||
|
2013-01-30 02:11:44 +04:00
|
|
|
SVGMarkerElementBase::IsAttributeMapped(name);
|
2006-04-27 01:02:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-12-21 11:58:14 +03:00
|
|
|
// SVGElement methods
|
2006-04-27 01:02:25 +04:00
|
|
|
|
2017-10-10 09:58:34 +03:00
|
|
|
void SVGMarkerElement::SetParentCoordCtxProvider(SVGViewportElement* aContext) {
|
2006-07-26 16:33:24 +04:00
|
|
|
mCoordCtx = aContext;
|
2012-07-30 18:20:58 +04:00
|
|
|
mViewBoxToViewportTransform = nullptr;
|
2006-07-26 16:33:24 +04:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* virtual */
|
|
|
|
bool SVGMarkerElement::HasValidDimensions() const {
|
2012-03-03 13:21:09 +04:00
|
|
|
return (!mLengthAttributes[MARKERWIDTH].IsExplicitlySet() ||
|
|
|
|
mLengthAttributes[MARKERWIDTH].GetAnimValInSpecifiedUnits() > 0) &&
|
|
|
|
(!mLengthAttributes[MARKERHEIGHT].IsExplicitlySet() ||
|
|
|
|
mLengthAttributes[MARKERHEIGHT].GetAnimValInSpecifiedUnits() > 0);
|
|
|
|
}
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::LengthAttributesInfo SVGMarkerElement::GetLengthInfo() {
|
2006-04-27 01:02:25 +04:00
|
|
|
return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
|
2011-10-11 09:50:08 +04:00
|
|
|
ArrayLength(sLengthInfo));
|
2006-04-27 01:02:25 +04:00
|
|
|
}
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::EnumAttributesInfo SVGMarkerElement::GetEnumInfo() {
|
2007-08-28 03:11:14 +04:00
|
|
|
return EnumAttributesInfo(mEnumAttributes, sEnumInfo, ArrayLength(sEnumInfo));
|
|
|
|
}
|
|
|
|
|
2019-04-10 07:08:14 +03:00
|
|
|
SVGAnimatedOrient* SVGMarkerElement::GetAnimatedOrient() { return &mOrient; }
|
2019-02-15 11:41:37 +03:00
|
|
|
|
2019-04-10 07:08:14 +03:00
|
|
|
SVGAnimatedViewBox* SVGMarkerElement::GetAnimatedViewBox() { return &mViewBox; }
|
2009-02-03 17:42:24 +03:00
|
|
|
|
2019-04-10 07:08:14 +03:00
|
|
|
SVGAnimatedPreserveAspectRatio*
|
|
|
|
SVGMarkerElement::GetAnimatedPreserveAspectRatio() {
|
2009-01-05 04:19:38 +03:00
|
|
|
return &mPreserveAspectRatio;
|
|
|
|
}
|
|
|
|
|
2006-04-27 01:02:25 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// public helpers
|
|
|
|
|
2013-01-30 02:11:44 +04:00
|
|
|
gfx::Matrix SVGMarkerElement::GetMarkerTransform(float aStrokeWidth,
|
2019-01-26 16:01:31 +03:00
|
|
|
const SVGMark& aMark) {
|
2014-03-18 06:41:35 +04:00
|
|
|
float scale =
|
|
|
|
mEnumAttributes[MARKERUNITS].GetAnimValue() == SVG_MARKERUNITS_STROKEWIDTH
|
|
|
|
? aStrokeWidth
|
|
|
|
: 1.0f;
|
2004-12-09 06:16:15 +03:00
|
|
|
|
2014-03-18 06:41:35 +04:00
|
|
|
float angle;
|
2019-02-15 11:41:37 +03:00
|
|
|
switch (mOrient.GetAnimType()) {
|
2013-07-12 10:39:38 +04:00
|
|
|
case SVG_MARKER_ORIENT_AUTO:
|
2017-06-08 08:17:07 +03:00
|
|
|
angle = aMark.angle;
|
2013-07-12 10:39:38 +04:00
|
|
|
break;
|
|
|
|
case SVG_MARKER_ORIENT_AUTO_START_REVERSE:
|
2019-01-26 16:01:31 +03:00
|
|
|
angle = aMark.angle + (aMark.type == SVGMark::eStart ? M_PI : 0.0f);
|
2013-07-12 10:39:38 +04:00
|
|
|
break;
|
|
|
|
default: // SVG_MARKER_ORIENT_ANGLE
|
2019-02-15 11:41:37 +03:00
|
|
|
angle = mOrient.GetAnimValue() * M_PI / 180.0f;
|
2013-07-12 10:39:38 +04:00
|
|
|
break;
|
|
|
|
}
|
2004-12-09 06:16:15 +03:00
|
|
|
|
2013-12-30 10:50:08 +04:00
|
|
|
return gfx::Matrix(cos(angle) * scale, sin(angle) * scale,
|
|
|
|
-sin(angle) * scale, cos(angle) * scale, aMark.x, aMark.y);
|
2004-12-09 06:16:15 +03:00
|
|
|
}
|
|
|
|
|
2019-04-10 07:08:14 +03:00
|
|
|
SVGViewBox SVGMarkerElement::GetViewBox() {
|
2013-02-26 20:58:06 +04:00
|
|
|
if (mViewBox.HasRect()) {
|
2011-09-21 11:53:09 +04:00
|
|
|
return mViewBox.GetAnimValue();
|
|
|
|
}
|
2019-04-10 07:08:14 +03:00
|
|
|
return SVGViewBox(0, 0,
|
|
|
|
mLengthAttributes[MARKERWIDTH].GetAnimValue(mCoordCtx),
|
|
|
|
mLengthAttributes[MARKERHEIGHT].GetAnimValue(mCoordCtx));
|
2011-09-21 11:53:09 +04:00
|
|
|
}
|
|
|
|
|
2013-01-30 02:11:44 +04:00
|
|
|
gfx::Matrix SVGMarkerElement::GetViewBoxTransform() {
|
2004-12-09 06:16:15 +03:00
|
|
|
if (!mViewBoxToViewportTransform) {
|
2006-04-14 19:09:39 +04:00
|
|
|
float viewportWidth =
|
|
|
|
mLengthAttributes[MARKERWIDTH].GetAnimValue(mCoordCtx);
|
|
|
|
float viewportHeight =
|
|
|
|
mLengthAttributes[MARKERHEIGHT].GetAnimValue(mCoordCtx);
|
2013-12-30 10:50:17 +04:00
|
|
|
|
2019-04-10 07:08:14 +03:00
|
|
|
SVGViewBox viewbox = GetViewBox();
|
2009-02-03 17:42:24 +03:00
|
|
|
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(viewbox.width > 0.0f && viewbox.height > 0.0f,
|
|
|
|
"Rendering should be disabled");
|
2004-12-09 06:16:15 +03:00
|
|
|
|
2013-03-03 12:11:03 +04:00
|
|
|
gfx::Matrix viewBoxTM = SVGContentUtils::GetViewBoxTransform(
|
2012-09-22 23:26:05 +04:00
|
|
|
viewportWidth, viewportHeight, viewbox.x, viewbox.y, viewbox.width,
|
|
|
|
viewbox.height, mPreserveAspectRatio);
|
2009-07-23 12:35:59 +04:00
|
|
|
|
2011-09-21 11:53:09 +04:00
|
|
|
float refX = mLengthAttributes[REFX].GetAnimValue(mCoordCtx);
|
|
|
|
float refY = mLengthAttributes[REFY].GetAnimValue(mCoordCtx);
|
|
|
|
|
2016-09-08 19:26:03 +03:00
|
|
|
gfx::Point ref = viewBoxTM.TransformPoint(gfx::Point(refX, refY));
|
2009-07-23 12:35:59 +04:00
|
|
|
|
2014-09-10 17:26:12 +04:00
|
|
|
Matrix TM = viewBoxTM;
|
|
|
|
TM.PostTranslate(-ref.x, -ref.y);
|
2009-07-23 12:35:59 +04:00
|
|
|
|
2020-02-25 23:03:26 +03:00
|
|
|
mViewBoxToViewportTransform = MakeUnique<gfx::Matrix>(TM);
|
2004-12-09 06:16:15 +03:00
|
|
|
}
|
|
|
|
|
2011-09-26 01:04:31 +04:00
|
|
|
return *mViewBoxToViewportTransform;
|
2004-12-09 06:16:15 +03:00
|
|
|
}
|
|
|
|
|
2013-01-30 02:11:44 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|