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
|
|
|
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2004-12-09 06:16:15 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2010-12-20 03:45:29 +03:00
|
|
|
#include "SVGAnimatedPreserveAspectRatio.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2013-01-30 02:11:44 +04:00
|
|
|
#include "mozilla/dom/SVGAngle.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/SVGMarkerElement.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"
|
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
|
|
|
};
|
|
|
|
|
2013-01-30 02:11:44 +04:00
|
|
|
nsSVGEnumMapping 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
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement::AngleInfo SVGMarkerElement::sAngleInfo[1] = {
|
2018-03-29 12:45:24 +03:00
|
|
|
{nsGkAtoms::orient, 0, SVG_ANGLETYPE_UNSPECIFIED}};
|
2007-10-10 14:07:59 +04:00
|
|
|
|
2004-12-09 06:16:15 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult nsSVGOrientType::SetBaseValue(uint16_t aValue,
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement* aSVGElement) {
|
2013-07-12 10:39:38 +04:00
|
|
|
if (aValue == SVG_MARKER_ORIENT_AUTO || aValue == SVG_MARKER_ORIENT_ANGLE ||
|
|
|
|
aValue == SVG_MARKER_ORIENT_AUTO_START_REVERSE) {
|
2008-01-09 12:52:14 +03:00
|
|
|
SetBaseValue(aValue);
|
2012-07-30 18:20:58 +04:00
|
|
|
aSVGElement->SetAttr(kNameSpaceID_None, nsGkAtoms::orient, nullptr,
|
2013-02-19 02:48:54 +04:00
|
|
|
(aValue == SVG_MARKER_ORIENT_AUTO
|
2013-07-12 10:39:38 +04:00
|
|
|
? NS_LITERAL_STRING("auto")
|
|
|
|
: aValue == SVG_MARKER_ORIENT_ANGLE
|
|
|
|
? NS_LITERAL_STRING("0")
|
|
|
|
: NS_LITERAL_STRING("auto-start-reverse")),
|
2011-10-17 18:59:28 +04:00
|
|
|
true);
|
2008-01-09 12:52:14 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2018-06-30 20:41:37 +03:00
|
|
|
return NS_ERROR_DOM_TYPE_ERR;
|
2008-01-09 12:52:14 +03:00
|
|
|
}
|
|
|
|
|
2013-07-01 11:02:46 +04:00
|
|
|
already_AddRefed<SVGAnimatedEnumeration> nsSVGOrientType::ToDOMAnimatedEnum(
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement* aSVGElement) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SVGAnimatedEnumeration> toReturn =
|
2013-01-30 02:11:44 +04:00
|
|
|
new DOMAnimatedEnum(this, aSVGElement);
|
|
|
|
return toReturn.forget();
|
2008-01-09 12:52:14 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
already_AddRefed<SVGAnimatedLength> SVGMarkerElement::RefX() {
|
|
|
|
return mLengthAttributes[REFX].ToDOMAnimatedLength(this);
|
2004-12-09 06:16:15 +03:00
|
|
|
}
|
|
|
|
|
2013-01-30 02:11:44 +04:00
|
|
|
already_AddRefed<SVGAnimatedLength> SVGMarkerElement::RefY() {
|
|
|
|
return mLengthAttributes[REFY].ToDOMAnimatedLength(this);
|
2004-12-09 06:16:15 +03:00
|
|
|
}
|
|
|
|
|
2013-07-01 11:02:46 +04:00
|
|
|
already_AddRefed<SVGAnimatedEnumeration> SVGMarkerElement::MarkerUnits() {
|
2013-01-30 02:11:44 +04:00
|
|
|
return mEnumAttributes[MARKERUNITS].ToDOMAnimatedEnum(this);
|
2004-12-09 06:16:15 +03:00
|
|
|
}
|
|
|
|
|
2013-01-30 02:11:44 +04:00
|
|
|
already_AddRefed<SVGAnimatedLength> SVGMarkerElement::MarkerWidth() {
|
|
|
|
return mLengthAttributes[MARKERWIDTH].ToDOMAnimatedLength(this);
|
2004-12-09 06:16:15 +03:00
|
|
|
}
|
|
|
|
|
2013-01-30 02:11:44 +04:00
|
|
|
already_AddRefed<SVGAnimatedLength> SVGMarkerElement::MarkerHeight() {
|
|
|
|
return mLengthAttributes[MARKERHEIGHT].ToDOMAnimatedLength(this);
|
2004-12-09 06:16:15 +03:00
|
|
|
}
|
|
|
|
|
2013-07-01 11:02:46 +04:00
|
|
|
already_AddRefed<SVGAnimatedEnumeration> SVGMarkerElement::OrientType() {
|
2013-01-30 02:11:44 +04:00
|
|
|
return mOrientType.ToDOMAnimatedEnum(this);
|
2004-12-09 06:16:15 +03:00
|
|
|
}
|
|
|
|
|
2013-01-30 02:11:44 +04:00
|
|
|
already_AddRefed<SVGAnimatedAngle> SVGMarkerElement::OrientAngle() {
|
|
|
|
return mAngleAttributes[ORIENT].ToDOMAnimatedAngle(this);
|
2004-12-09 06:16:15 +03:00
|
|
|
}
|
|
|
|
|
2013-02-19 02:48:54 +04:00
|
|
|
void SVGMarkerElement::SetOrientToAuto() {
|
2012-07-30 18:20:58 +04:00
|
|
|
SetAttr(kNameSpaceID_None, nsGkAtoms::orient, nullptr,
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_LITERAL_STRING("auto"), true);
|
2013-01-30 02:11:44 +04:00
|
|
|
}
|
2013-01-29 13:45:50 +04:00
|
|
|
|
2013-01-30 02:11:44 +04:00
|
|
|
void SVGMarkerElement::SetOrientToAngle(SVGAngle& angle, ErrorResult& rv) {
|
|
|
|
float f = angle.Value();
|
2014-10-01 13:26:00 +04:00
|
|
|
if (!IsFinite(f)) {
|
2013-01-30 02:11:44 +04:00
|
|
|
rv.Throw(NS_ERROR_DOM_SVG_WRONG_TYPE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2015-07-13 09:08:00 +03:00
|
|
|
mOrientType.SetBaseValue(SVG_MARKER_ORIENT_ANGLE);
|
2018-07-01 18:12:14 +03:00
|
|
|
mAngleAttributes[ORIENT].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-03 01:05:19 +03:00
|
|
|
bool SVGMarkerElement::ParseAttribute(int32_t aNameSpaceID, nsAtom* aName,
|
2013-01-30 02:11:44 +04:00
|
|
|
const nsAString& aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2013-01-30 02:11:44 +04:00
|
|
|
nsAttrValue& aResult) {
|
2007-09-15 02:12:20 +04:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::orient) {
|
2007-11-20 14:36:39 +03:00
|
|
|
if (aValue.EqualsLiteral("auto")) {
|
|
|
|
mOrientType.SetBaseValue(SVG_MARKER_ORIENT_AUTO);
|
|
|
|
aResult.SetTo(aValue);
|
2018-07-01 18:12:14 +03:00
|
|
|
mAngleAttributes[ORIENT].SetBaseValue(0.f, SVG_ANGLETYPE_UNSPECIFIED,
|
|
|
|
this, false);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2007-11-20 14:36:39 +03:00
|
|
|
}
|
2018-07-31 23:45:29 +03:00
|
|
|
if (aValue.EqualsLiteral("auto-start-reverse")) {
|
2013-07-12 10:39:38 +04:00
|
|
|
mOrientType.SetBaseValue(SVG_MARKER_ORIENT_AUTO_START_REVERSE);
|
|
|
|
aResult.SetTo(aValue);
|
2018-07-01 18:12:14 +03:00
|
|
|
mAngleAttributes[ORIENT].SetBaseValue(0.f, SVG_ANGLETYPE_UNSPECIFIED,
|
|
|
|
this, false);
|
2013-07-12 10:39:38 +04:00
|
|
|
return true;
|
|
|
|
}
|
2007-11-20 14:36:39 +03:00
|
|
|
mOrientType.SetBaseValue(SVG_MARKER_ORIENT_ANGLE);
|
2007-08-28 03:11:14 +04:00
|
|
|
}
|
2013-01-30 02:11:44 +04:00
|
|
|
return SVGMarkerElementBase::ParseAttribute(aNameSpaceID, aName, aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
aMaybeScriptedPrincipal, aResult);
|
2007-08-28 03:11:14 +04:00
|
|
|
}
|
|
|
|
|
2018-01-04 05:03:45 +03:00
|
|
|
nsresult SVGMarkerElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
|
|
|
|
const nsAttrValue* aValue,
|
|
|
|
const nsAttrValue* aOldValue,
|
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
|
|
|
bool aNotify) {
|
|
|
|
if (!aValue && aNamespaceID == kNameSpaceID_None &&
|
|
|
|
aName == nsGkAtoms::orient) {
|
|
|
|
mOrientType.SetBaseValue(SVG_MARKER_ORIENT_ANGLE);
|
2006-04-27 01:02:25 +04:00
|
|
|
}
|
|
|
|
|
2018-01-04 05:03:45 +03:00
|
|
|
return SVGMarkerElementBase::AfterSetAttr(
|
|
|
|
aNamespaceID, aName, aValue, aOldValue, aMaybeScriptedPrincipal, aNotify);
|
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
|
|
|
}
|
|
|
|
|
2013-01-30 02:11:44 +04:00
|
|
|
/* virtual */ bool SVGMarkerElement::HasValidDimensions() const {
|
2012-03-03 13:21:09 +04:00
|
|
|
return (!mLengthAttributes[MARKERWIDTH].IsExplicitlySet() ||
|
|
|
|
mLengthAttributes[MARKERWIDTH].GetAnimValInSpecifiedUnits() > 0) &&
|
2017-07-06 15:00:35 +03:00
|
|
|
(!mLengthAttributes[MARKERHEIGHT].IsExplicitlySet() ||
|
2012-03-03 13:21:09 +04:00
|
|
|
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::AngleAttributesInfo SVGMarkerElement::GetAngleInfo() {
|
2007-10-10 14:07:59 +04:00
|
|
|
return AngleAttributesInfo(mAngleAttributes, sAngleInfo,
|
2011-10-11 09:50:08 +04:00
|
|
|
ArrayLength(sAngleInfo));
|
2007-10-10 14:07:59 +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));
|
|
|
|
}
|
|
|
|
|
2013-01-30 02:11:44 +04:00
|
|
|
nsSVGViewBox* SVGMarkerElement::GetViewBox() { return &mViewBox; }
|
2009-02-03 17:42:24 +03:00
|
|
|
|
2013-01-30 02:11:44 +04:00
|
|
|
SVGAnimatedPreserveAspectRatio* SVGMarkerElement::GetPreserveAspectRatio() {
|
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,
|
2017-06-08 08:17:07 +03:00
|
|
|
const nsSVGMark& 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;
|
2013-07-12 10:39:38 +04:00
|
|
|
switch (mOrientType.GetAnimValueInternal()) {
|
|
|
|
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:
|
2017-06-08 08:17:07 +03:00
|
|
|
angle = aMark.angle + (aMark.type == nsSVGMark::eStart ? M_PI : 0.0f);
|
2013-07-12 10:39:38 +04:00
|
|
|
break;
|
|
|
|
default: // SVG_MARKER_ORIENT_ANGLE
|
2014-03-18 06:41:35 +04:00
|
|
|
angle = mAngleAttributes[ORIENT].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
|
|
|
}
|
|
|
|
|
2013-01-30 02:11:44 +04:00
|
|
|
nsSVGViewBoxRect SVGMarkerElement::GetViewBoxRect() {
|
2013-02-26 20:58:06 +04:00
|
|
|
if (mViewBox.HasRect()) {
|
2011-09-21 11:53:09 +04:00
|
|
|
return mViewBox.GetAnimValue();
|
|
|
|
}
|
|
|
|
return nsSVGViewBoxRect(
|
|
|
|
0, 0, mLengthAttributes[MARKERWIDTH].GetAnimValue(mCoordCtx),
|
|
|
|
mLengthAttributes[MARKERHEIGHT].GetAnimValue(mCoordCtx));
|
|
|
|
}
|
|
|
|
|
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);
|
2017-07-06 15:00:35 +03:00
|
|
|
float viewportHeight =
|
2006-04-14 19:09:39 +04:00
|
|
|
mLengthAttributes[MARKERHEIGHT].GetAnimValue(mCoordCtx);
|
2013-12-30 10:50:17 +04:00
|
|
|
|
2011-09-21 11:53:09 +04:00
|
|
|
nsSVGViewBoxRect viewbox = GetViewBoxRect();
|
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
|
|
|
|
2013-12-30 10:50:17 +04:00
|
|
|
mViewBoxToViewportTransform = new 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
|