2006-06-21 15:42:28 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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-06-21 15:42:28 +00:00
|
|
|
|
|
|
|
#include "nsSVGPathGeometryElement.h"
|
2013-11-02 11:10:38 +00:00
|
|
|
|
|
|
|
#include "gfxPlatform.h"
|
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "nsComputedDOMStyle.h"
|
2013-05-08 17:13:11 +00:00
|
|
|
#include "nsSVGLength2.h"
|
2013-11-02 11:10:38 +00:00
|
|
|
#include "SVGContentUtils.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gfx;
|
2006-06-21 15:42:28 +00:00
|
|
|
|
2011-12-31 09:44:03 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2010-07-23 09:49:57 +00:00
|
|
|
nsSVGPathGeometryElement::nsSVGPathGeometryElement(already_AddRefed<nsINodeInfo> aNodeInfo)
|
2006-06-21 15:42:28 +00:00
|
|
|
: nsSVGPathGeometryElementBase(aNodeInfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2009-04-23 23:41:17 +00:00
|
|
|
nsSVGPathGeometryElement::AttributeDefinesGeometry(const nsIAtom *aName)
|
2006-06-21 15:42:28 +00:00
|
|
|
{
|
|
|
|
// Check for nsSVGLength2 attribute
|
|
|
|
LengthAttributesInfo info = GetLengthInfo();
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < info.mLengthCount; i++) {
|
2006-06-21 15:42:28 +00:00
|
|
|
if (aName == *info.mLengthInfo[i].mName) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2006-06-21 15:42:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2006-06-21 15:42:28 +00:00
|
|
|
}
|
|
|
|
|
2013-05-08 17:13:11 +00:00
|
|
|
bool
|
|
|
|
nsSVGPathGeometryElement::GeometryDependsOnCoordCtx()
|
|
|
|
{
|
|
|
|
// Check the nsSVGLength2 attribute
|
|
|
|
LengthAttributesInfo info = const_cast<nsSVGPathGeometryElement*>(this)->GetLengthInfo();
|
|
|
|
for (uint32_t i = 0; i < info.mLengthCount; i++) {
|
|
|
|
if (info.mLengths[i].GetSpecifiedUnitType() == nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2006-06-21 15:42:28 +00:00
|
|
|
nsSVGPathGeometryElement::IsMarkable()
|
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2006-06-21 15:42:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-06-21 19:35:59 +00:00
|
|
|
nsSVGPathGeometryElement::GetMarkPoints(nsTArray<nsSVGMark> *aMarks)
|
2006-06-21 15:42:28 +00:00
|
|
|
{
|
|
|
|
}
|
2006-06-27 22:54:31 +00:00
|
|
|
|
2013-10-15 03:23:21 +00:00
|
|
|
already_AddRefed<gfxPath>
|
|
|
|
nsSVGPathGeometryElement::GetPath(const gfxMatrix &aMatrix)
|
2006-06-27 22:54:31 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2006-06-27 22:54:31 +00:00
|
|
|
}
|
2013-11-02 11:10:38 +00:00
|
|
|
|
|
|
|
TemporaryRef<PathBuilder>
|
|
|
|
nsSVGPathGeometryElement::CreatePathBuilder()
|
|
|
|
{
|
|
|
|
RefPtr<DrawTarget> drawTarget =
|
|
|
|
gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget();
|
|
|
|
NS_ASSERTION(gfxPlatform::GetPlatform()->
|
|
|
|
SupportsAzureContentForDrawTarget(drawTarget),
|
|
|
|
"Should support Moz2D content drawing");
|
|
|
|
|
|
|
|
// The fill rule that we pass to CreatePathBuilder must be the current
|
|
|
|
// computed value of our CSS 'fill-rule' property if the path that we return
|
|
|
|
// will be used for painting or hit-testing. For all other uses (bounds
|
|
|
|
// calculatons, length measurement, position-at-offset calculations) the fill
|
|
|
|
// rule that we pass doesn't matter. As a result we can just pass the current
|
|
|
|
// computed value regardless of who's calling us, or what they're going to do
|
|
|
|
// with the path that we return.
|
|
|
|
|
|
|
|
return drawTarget->CreatePathBuilder(GetFillRule());
|
|
|
|
}
|
|
|
|
|
|
|
|
FillRule
|
|
|
|
nsSVGPathGeometryElement::GetFillRule()
|
|
|
|
{
|
|
|
|
FillRule fillRule = FILL_WINDING; // Equivalent to NS_STYLE_FILL_RULE_NONZERO
|
|
|
|
|
|
|
|
nsRefPtr<nsStyleContext> styleContext =
|
|
|
|
nsComputedDOMStyle::GetStyleContextForElementNoFlush(this, nullptr,
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
if (styleContext) {
|
|
|
|
MOZ_ASSERT(styleContext->StyleSVG()->mFillRule ==
|
|
|
|
NS_STYLE_FILL_RULE_NONZERO ||
|
|
|
|
styleContext->StyleSVG()->mFillRule ==
|
|
|
|
NS_STYLE_FILL_RULE_EVENODD);
|
|
|
|
|
|
|
|
if (styleContext->StyleSVG()->mFillRule == NS_STYLE_FILL_RULE_EVENODD) {
|
|
|
|
fillRule = FILL_EVEN_ODD;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// ReportToConsole
|
|
|
|
NS_WARNING("Couldn't get style context for content in GetFillRule");
|
|
|
|
}
|
|
|
|
|
|
|
|
return fillRule;
|
|
|
|
}
|
|
|
|
|
|
|
|
Float
|
|
|
|
nsSVGPathGeometryElement::GetStrokeWidth()
|
|
|
|
{
|
|
|
|
nsRefPtr<nsStyleContext> styleContext =
|
|
|
|
nsComputedDOMStyle::GetStyleContextForElementNoFlush(this, nullptr,
|
|
|
|
nullptr);
|
|
|
|
return styleContext ?
|
|
|
|
SVGContentUtils::CoordToFloat(styleContext->PresContext(), this,
|
|
|
|
styleContext->StyleSVG()->mStrokeWidth) :
|
|
|
|
0.0f;
|
|
|
|
}
|