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/. */
|
2006-08-11 01:03:49 +04:00
|
|
|
|
2016-12-18 14:11:47 +03:00
|
|
|
#include "SVGPolyElement.h"
|
2010-12-08 15:15:53 +03:00
|
|
|
#include "DOMSVGPointList.h"
|
2013-11-02 15:10:38 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2012-09-22 23:26:05 +04:00
|
|
|
#include "SVGContentUtils.h"
|
2010-12-08 15:15:53 +03:00
|
|
|
|
2013-11-02 15:10:38 +04:00
|
|
|
using namespace mozilla::gfx;
|
2006-08-11 01:03:49 +04:00
|
|
|
|
2018-12-20 01:09:57 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2006-08-11 01:03:49 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2018-09-21 23:45:49 +03:00
|
|
|
SVGPolyElement::SVGPolyElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
|
|
|
: SVGPolyElementBase(std::move(aNodeInfo)) {}
|
2006-08-11 01:03:49 +04:00
|
|
|
|
2013-01-06 13:32:01 +04:00
|
|
|
already_AddRefed<DOMSVGPointList> SVGPolyElement::Points() {
|
|
|
|
void* key = mPoints.GetBaseValKey();
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMSVGPointList> points =
|
|
|
|
DOMSVGPointList::GetDOMWrapper(key, this, false);
|
2013-01-06 13:32:01 +04:00
|
|
|
return points.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMSVGPointList> SVGPolyElement::AnimatedPoints() {
|
|
|
|
void* key = mPoints.GetAnimValKey();
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMSVGPointList> points =
|
|
|
|
DOMSVGPointList::GetDOMWrapper(key, this, true);
|
2013-01-06 13:32:01 +04:00
|
|
|
return points.forget();
|
|
|
|
}
|
|
|
|
|
2006-08-11 01:03:49 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIContent methods
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
2017-10-03 01:05:19 +03:00
|
|
|
SVGPolyElement::IsAttributeMapped(const nsAtom* name) const {
|
2006-08-11 01:03:49 +04:00
|
|
|
static const MappedAttributeEntry* const map[] = {sMarkersMap};
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2011-12-18 14:09:27 +04:00
|
|
|
return FindAttributeDependence(name, map) ||
|
2016-12-18 14:11:47 +03:00
|
|
|
SVGPolyElementBase::IsAttributeMapped(name);
|
2006-08-11 01:03:49 +04:00
|
|
|
}
|
|
|
|
|
2014-02-20 00:46:43 +04:00
|
|
|
//----------------------------------------------------------------------
|
2018-12-21 11:58:14 +03:00
|
|
|
// SVGElement methods
|
2014-02-20 00:46:43 +04:00
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* virtual */
|
|
|
|
bool SVGPolyElement::HasValidDimensions() const {
|
2014-02-20 00:46:43 +04:00
|
|
|
return !mPoints.GetAnimValue().IsEmpty();
|
|
|
|
}
|
|
|
|
|
2006-08-11 01:03:49 +04:00
|
|
|
//----------------------------------------------------------------------
|
2016-12-18 14:11:47 +03:00
|
|
|
// SVGGeometryElement methods
|
2006-08-11 01:03:49 +04:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
bool SVGPolyElement::AttributeDefinesGeometry(const nsAtom* aName) {
|
2019-04-20 13:29:32 +03:00
|
|
|
return aName == nsGkAtoms::points;
|
2006-08-11 01:03:49 +04:00
|
|
|
}
|
|
|
|
|
2019-01-26 16:01:31 +03:00
|
|
|
void SVGPolyElement::GetMarkPoints(nsTArray<SVGMark>* aMarks) {
|
2010-12-08 15:15:53 +03:00
|
|
|
const SVGPointList& points = mPoints.GetAnimValue();
|
2006-08-11 01:03:49 +04:00
|
|
|
|
2010-12-08 15:15:53 +03:00
|
|
|
if (!points.Length()) return;
|
2006-08-11 01:03:49 +04:00
|
|
|
|
2013-07-12 10:39:38 +04:00
|
|
|
float px = points[0].mX, py = points[0].mY, prevAngle = 0.0;
|
2006-08-11 01:03:49 +04:00
|
|
|
|
2019-01-26 16:01:31 +03:00
|
|
|
aMarks->AppendElement(SVGMark(px, py, 0, SVGMark::eStart));
|
2013-07-12 10:39:38 +04:00
|
|
|
|
|
|
|
for (uint32_t i = 1; i < points.Length(); ++i) {
|
2010-12-08 15:15:53 +03:00
|
|
|
float x = points[i].mX;
|
|
|
|
float y = points[i].mY;
|
2019-04-26 00:46:33 +03:00
|
|
|
float angle = std::atan2(y - py, x - px);
|
2013-07-12 10:39:38 +04:00
|
|
|
|
|
|
|
// Vertex marker.
|
|
|
|
if (i == 1) {
|
|
|
|
aMarks->ElementAt(0).angle = angle;
|
|
|
|
} else {
|
2014-11-10 17:40:43 +03:00
|
|
|
aMarks->ElementAt(aMarks->Length() - 1).angle =
|
2012-09-22 23:26:05 +04:00
|
|
|
SVGContentUtils::AngleBisect(prevAngle, angle);
|
2013-07-12 10:39:38 +04:00
|
|
|
}
|
2006-08-11 01:03:49 +04:00
|
|
|
|
2019-01-26 16:01:31 +03:00
|
|
|
aMarks->AppendElement(SVGMark(x, y, 0, SVGMark::eMid));
|
2006-08-11 01:03:49 +04:00
|
|
|
|
|
|
|
prevAngle = angle;
|
|
|
|
px = x;
|
|
|
|
py = y;
|
|
|
|
}
|
|
|
|
|
2013-07-12 10:39:38 +04:00
|
|
|
aMarks->LastElement().angle = prevAngle;
|
2019-01-26 16:01:31 +03:00
|
|
|
aMarks->LastElement().type = SVGMark::eEnd;
|
2006-08-11 01:03:49 +04:00
|
|
|
}
|
2014-11-24 17:28:58 +03:00
|
|
|
|
2016-12-18 14:11:47 +03:00
|
|
|
bool SVGPolyElement::GetGeometryBounds(Rect* aBounds,
|
|
|
|
const StrokeOptions& aStrokeOptions,
|
|
|
|
const Matrix& aToBoundsSpace,
|
|
|
|
const Matrix* aToNonScalingStrokeSpace) {
|
2014-11-24 17:28:58 +03:00
|
|
|
const SVGPointList& points = mPoints.GetAnimValue();
|
|
|
|
|
|
|
|
if (!points.Length()) {
|
|
|
|
// Rendering of the element is disabled
|
|
|
|
aBounds->SetEmpty();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-01 07:17:00 +03:00
|
|
|
if (aStrokeOptions.mLineWidth > 0 || aToNonScalingStrokeSpace) {
|
|
|
|
// We don't handle non-scaling-stroke or stroke-miterlimit etc. yet
|
2014-11-24 17:28:58 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-01 07:17:00 +03:00
|
|
|
if (aToBoundsSpace.IsRectilinear()) {
|
2014-11-24 17:28:58 +03:00
|
|
|
// We can avoid transforming each point and just transform the result.
|
|
|
|
// Important for large point lists.
|
|
|
|
Rect bounds(points[0], Size());
|
|
|
|
for (uint32_t i = 1; i < points.Length(); ++i) {
|
|
|
|
bounds.ExpandToEnclose(points[i]);
|
|
|
|
}
|
2015-09-01 07:17:00 +03:00
|
|
|
*aBounds = aToBoundsSpace.TransformBounds(bounds);
|
2014-11-24 17:28:58 +03:00
|
|
|
} else {
|
2016-09-08 19:26:03 +03:00
|
|
|
*aBounds = Rect(aToBoundsSpace.TransformPoint(points[0]), Size());
|
2014-11-24 17:28:58 +03:00
|
|
|
for (uint32_t i = 1; i < points.Length(); ++i) {
|
2016-09-08 19:26:03 +03:00
|
|
|
aBounds->ExpandToEnclose(aToBoundsSpace.TransformPoint(points[i]));
|
2014-11-24 17:28:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2018-12-20 01:09:57 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|