2015-05-03 12:32:37 -07: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 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsSVGPolyElement.h"
|
2010-12-08 04:15:53 -08:00
|
|
|
#include "DOMSVGPointList.h"
|
2013-11-02 04:10:38 -07:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2012-09-22 12:26:05 -07:00
|
|
|
#include "SVGContentUtils.h"
|
2010-12-08 04:15:53 -08:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2013-11-02 04:10:38 -07:00
|
|
|
using namespace mozilla::gfx;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports methods
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsSVGPolyElement,nsSVGPolyElementBase)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsSVGPolyElement,nsSVGPolyElementBase)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsSVGPolyElement)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsSVGPolyElementBase)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2014-06-19 19:01:40 -07:00
|
|
|
nsSVGPolyElement::nsSVGPolyElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2007-03-22 10:30:00 -07:00
|
|
|
: nsSVGPolyElementBase(aNodeInfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-07-08 14:23:16 -07:00
|
|
|
nsSVGPolyElement::~nsSVGPolyElement()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-01-06 01:32:01 -08:00
|
|
|
already_AddRefed<DOMSVGPointList>
|
|
|
|
nsSVGPolyElement::Points()
|
|
|
|
{
|
|
|
|
void *key = mPoints.GetBaseValKey();
|
|
|
|
nsRefPtr<DOMSVGPointList> points = DOMSVGPointList::GetDOMWrapper(key, this, false);
|
|
|
|
return points.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMSVGPointList>
|
|
|
|
nsSVGPolyElement::AnimatedPoints()
|
|
|
|
{
|
|
|
|
void *key = mPoints.GetAnimValKey();
|
|
|
|
nsRefPtr<DOMSVGPointList> points = DOMSVGPointList::GetDOMWrapper(key, this, true);
|
|
|
|
return points.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIContent methods
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP_(bool)
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSVGPolyElement::IsAttributeMapped(const nsIAtom* name) const
|
|
|
|
{
|
|
|
|
static const MappedAttributeEntry* const map[] = {
|
|
|
|
sMarkersMap
|
|
|
|
};
|
|
|
|
|
2011-12-18 02:09:27 -08:00
|
|
|
return FindAttributeDependence(name, map) ||
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSVGPolyElementBase::IsAttributeMapped(name);
|
|
|
|
}
|
|
|
|
|
2014-02-19 12:46:43 -08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGElement methods
|
|
|
|
|
|
|
|
/* virtual */ bool
|
|
|
|
nsSVGPolyElement::HasValidDimensions() const
|
|
|
|
{
|
|
|
|
return !mPoints.GetAnimValue().IsEmpty();
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGPathGeometryElement methods
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-04-23 16:41:17 -07:00
|
|
|
nsSVGPolyElement::AttributeDefinesGeometry(const nsIAtom *aName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aName == nsGkAtoms::points)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGPolyElement::GetMarkPoints(nsTArray<nsSVGMark> *aMarks)
|
|
|
|
{
|
2010-12-08 04:15:53 -08:00
|
|
|
const SVGPointList &points = mPoints.GetAnimValue();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-12-08 04:15:53 -08:00
|
|
|
if (!points.Length())
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
|
2013-07-11 23:39:38 -07:00
|
|
|
float px = points[0].mX, py = points[0].mY, prevAngle = 0.0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-11 23:39:38 -07:00
|
|
|
aMarks->AppendElement(nsSVGMark(px, py, 0, nsSVGMark::eStart));
|
|
|
|
|
|
|
|
for (uint32_t i = 1; i < points.Length(); ++i) {
|
2010-12-08 04:15:53 -08:00
|
|
|
float x = points[i].mX;
|
|
|
|
float y = points[i].mY;
|
2007-03-22 10:30:00 -07:00
|
|
|
float angle = atan2(y-py, x-px);
|
2013-07-11 23:39:38 -07:00
|
|
|
|
|
|
|
// Vertex marker.
|
|
|
|
if (i == 1) {
|
|
|
|
aMarks->ElementAt(0).angle = angle;
|
|
|
|
} else {
|
2014-11-10 06:40:43 -08:00
|
|
|
aMarks->ElementAt(aMarks->Length() - 1).angle =
|
2012-09-22 12:26:05 -07:00
|
|
|
SVGContentUtils::AngleBisect(prevAngle, angle);
|
2013-07-11 23:39:38 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-11 23:39:38 -07:00
|
|
|
aMarks->AppendElement(nsSVGMark(x, y, 0, nsSVGMark::eMid));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
prevAngle = angle;
|
|
|
|
px = x;
|
|
|
|
py = y;
|
|
|
|
}
|
|
|
|
|
2013-07-11 23:39:38 -07:00
|
|
|
aMarks->LastElement().angle = prevAngle;
|
|
|
|
aMarks->LastElement().type = nsSVGMark::eEnd;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-11-24 06:28:58 -08:00
|
|
|
|
|
|
|
bool
|
2015-02-03 10:36:32 -08:00
|
|
|
nsSVGPolyElement::GetGeometryBounds(
|
|
|
|
Rect* aBounds, const StrokeOptions& aStrokeOptions, const Matrix& aTransform)
|
2014-11-24 06:28:58 -08:00
|
|
|
{
|
|
|
|
const SVGPointList &points = mPoints.GetAnimValue();
|
|
|
|
|
|
|
|
if (!points.Length()) {
|
|
|
|
// Rendering of the element is disabled
|
|
|
|
aBounds->SetEmpty();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-03 10:36:32 -08:00
|
|
|
if (aStrokeOptions.mLineWidth > 0) {
|
2014-11-24 06:28:58 -08:00
|
|
|
// We don't handle stroke-miterlimit etc. yet
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aTransform.IsRectilinear()) {
|
|
|
|
// 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]);
|
|
|
|
}
|
|
|
|
*aBounds = aTransform.TransformBounds(bounds);
|
|
|
|
} else {
|
|
|
|
*aBounds = Rect(aTransform * points[0], Size());
|
|
|
|
for (uint32_t i = 1; i < points.Length(); ++i) {
|
|
|
|
aBounds->ExpandToEnclose(aTransform * points[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|