2006-08-11 01:03:49 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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
|
|
|
|
|
|
|
#include "nsSVGPolyElement.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
|
|
|
|
|
|
|
using namespace mozilla;
|
2013-11-02 15:10:38 +04:00
|
|
|
using namespace mozilla::gfx;
|
2006-08-11 01:03:49 +04: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-20 06:01:40 +04:00
|
|
|
nsSVGPolyElement::nsSVGPolyElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2006-08-11 01:03:49 +04:00
|
|
|
: nsSVGPolyElementBase(aNodeInfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-07-09 01:23:16 +04:00
|
|
|
nsSVGPolyElement::~nsSVGPolyElement()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-01-06 13:32:01 +04: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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-11 01:03:49 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIContent methods
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
2006-08-11 01:03:49 +04:00
|
|
|
nsSVGPolyElement::IsAttributeMapped(const nsIAtom* name) const
|
|
|
|
{
|
|
|
|
static const MappedAttributeEntry* const map[] = {
|
2007-03-20 13:43:33 +03:00
|
|
|
sMarkersMap
|
2006-08-11 01:03:49 +04:00
|
|
|
};
|
|
|
|
|
2011-12-18 14:09:27 +04:00
|
|
|
return FindAttributeDependence(name, map) ||
|
2006-08-11 01:03:49 +04:00
|
|
|
nsSVGPolyElementBase::IsAttributeMapped(name);
|
|
|
|
}
|
|
|
|
|
2014-02-20 00:46:43 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGElement methods
|
|
|
|
|
|
|
|
/* virtual */ bool
|
|
|
|
nsSVGPolyElement::HasValidDimensions() const
|
|
|
|
{
|
|
|
|
return !mPoints.GetAnimValue().IsEmpty();
|
|
|
|
}
|
|
|
|
|
2006-08-11 01:03:49 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGPathGeometryElement methods
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2009-04-24 03:41:17 +04:00
|
|
|
nsSVGPolyElement::AttributeDefinesGeometry(const nsIAtom *aName)
|
2006-08-11 01:03:49 +04:00
|
|
|
{
|
|
|
|
if (aName == nsGkAtoms::points)
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2006-08-11 01:03:49 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-08-11 01:03:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGPolyElement::GetMarkPoints(nsTArray<nsSVGMark> *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())
|
2006-08-11 01:03:49 +04:00
|
|
|
return;
|
|
|
|
|
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
|
|
|
|
2013-07-12 10:39:38 +04:00
|
|
|
aMarks->AppendElement(nsSVGMark(px, py, 0, nsSVGMark::eStart));
|
|
|
|
|
|
|
|
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;
|
2006-08-11 01:03:49 +04:00
|
|
|
float angle = 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
|
|
|
|
2013-07-12 10:39:38 +04:00
|
|
|
aMarks->AppendElement(nsSVGMark(x, y, 0, nsSVGMark::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;
|
|
|
|
aMarks->LastElement().type = nsSVGMark::eEnd;
|
2006-08-11 01:03:49 +04:00
|
|
|
}
|