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 "nsSVGPathGeometryElement.h"
|
2013-11-02 04:10:38 -07:00
|
|
|
|
|
|
|
#include "gfxPlatform.h"
|
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "nsComputedDOMStyle.h"
|
2014-10-04 04:13:30 -07:00
|
|
|
#include "nsSVGUtils.h"
|
2013-05-08 10:13:11 -07:00
|
|
|
#include "nsSVGLength2.h"
|
2013-11-02 04:10:38 -07:00
|
|
|
#include "SVGContentUtils.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gfx;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-12-31 01:44:03 -08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2014-06-19 19:01:40 -07:00
|
|
|
nsSVGPathGeometryElement::nsSVGPathGeometryElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2007-03-22 10:30:00 -07:00
|
|
|
: nsSVGPathGeometryElementBase(aNodeInfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-10-04 04:13:30 -07:00
|
|
|
nsresult
|
|
|
|
nsSVGPathGeometryElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
|
|
|
|
const nsAttrValue* aValue, bool aNotify)
|
|
|
|
{
|
|
|
|
if (mCachedPath &&
|
|
|
|
aNamespaceID == kNameSpaceID_None &&
|
|
|
|
AttributeDefinesGeometry(aName)) {
|
|
|
|
mCachedPath = nullptr;
|
|
|
|
}
|
|
|
|
return nsSVGPathGeometryElementBase::AfterSetAttr(aNamespaceID, aName,
|
|
|
|
aValue, aNotify);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-04-23 16:41:17 -07:00
|
|
|
nsSVGPathGeometryElement::AttributeDefinesGeometry(const nsIAtom *aName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Check for nsSVGLength2 attribute
|
|
|
|
LengthAttributesInfo info = GetLengthInfo();
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < info.mLengthCount; i++) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aName == *info.mLengthInfo[i].mName) {
|
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
|
|
|
}
|
|
|
|
|
2013-05-08 10:13:11 -07: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-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSVGPathGeometryElement::IsMarkable()
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGPathGeometryElement::GetMarkPoints(nsTArray<nsSVGMark> *aMarks)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-06-17 07:00:52 -07:00
|
|
|
already_AddRefed<Path>
|
2014-10-04 04:13:30 -07:00
|
|
|
nsSVGPathGeometryElement::GetOrBuildPath(const DrawTarget& aDrawTarget,
|
|
|
|
FillRule aFillRule)
|
|
|
|
{
|
|
|
|
// We only cache the path if it matches the backend used for screen painting:
|
|
|
|
bool cacheable = aDrawTarget.GetBackendType() ==
|
2015-10-01 23:06:43 -07:00
|
|
|
gfxPlatform::GetPlatform()->GetDefaultContentBackend();
|
2014-10-04 04:13:30 -07:00
|
|
|
|
|
|
|
// Checking for and returning mCachedPath before checking the pref means
|
|
|
|
// that the pref is only live on page reload (or app restart for SVG in
|
|
|
|
// chrome). The benefit is that we avoid causing a CPU memory cache miss by
|
|
|
|
// looking at the global variable that the pref's stored in.
|
|
|
|
if (cacheable && mCachedPath) {
|
2015-01-07 16:10:49 -08:00
|
|
|
if (aDrawTarget.GetBackendType() == mCachedPath->GetBackendType()) {
|
2015-10-17 22:24:48 -07:00
|
|
|
RefPtr<Path> path(mCachedPath);
|
2015-05-01 06:14:16 -07:00
|
|
|
return path.forget();
|
2015-01-07 16:10:49 -08:00
|
|
|
}
|
2014-10-04 04:13:30 -07:00
|
|
|
}
|
2015-10-17 22:24:48 -07:00
|
|
|
RefPtr<PathBuilder> builder = aDrawTarget.CreatePathBuilder(aFillRule);
|
|
|
|
RefPtr<Path> path = BuildPath(builder);
|
2014-10-04 04:13:30 -07:00
|
|
|
if (cacheable && NS_SVGPathCachingEnabled()) {
|
|
|
|
mCachedPath = path;
|
|
|
|
}
|
|
|
|
return path.forget();
|
|
|
|
}
|
|
|
|
|
2015-06-17 07:00:52 -07:00
|
|
|
already_AddRefed<Path>
|
2014-10-04 04:13:30 -07:00
|
|
|
nsSVGPathGeometryElement::GetOrBuildPathForMeasuring()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-11-02 04:10:38 -07:00
|
|
|
|
|
|
|
FillRule
|
|
|
|
nsSVGPathGeometryElement::GetFillRule()
|
|
|
|
{
|
2014-01-10 11:06:17 -08:00
|
|
|
FillRule fillRule = FillRule::FILL_WINDING; // Equivalent to NS_STYLE_FILL_RULE_NONZERO
|
2013-11-02 04:10:38 -07:00
|
|
|
|
2015-10-17 22:24:48 -07:00
|
|
|
RefPtr<nsStyleContext> styleContext =
|
2013-11-02 04:10:38 -07:00
|
|
|
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) {
|
2014-01-10 11:06:17 -08:00
|
|
|
fillRule = FillRule::FILL_EVEN_ODD;
|
2013-11-02 04:10:38 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// ReportToConsole
|
|
|
|
NS_WARNING("Couldn't get style context for content in GetFillRule");
|
|
|
|
}
|
|
|
|
|
|
|
|
return fillRule;
|
|
|
|
}
|