2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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
|
|
|
|
2012-03-26 04:58:59 -07:00
|
|
|
// Main header first:
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsSVGTextPathFrame.h"
|
2012-03-20 05:15:55 -07:00
|
|
|
|
2012-03-26 04:58:59 -07:00
|
|
|
// Keep others in (case-insensitive) order:
|
|
|
|
#include "nsContentUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMSVGTextPathElement.h"
|
2008-10-11 04:29:35 -07:00
|
|
|
#include "nsSVGEffects.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsSVGLength2.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsSVGPathElement.h"
|
2007-12-03 22:51:36 -08:00
|
|
|
#include "nsSVGTextPathElement.h"
|
2012-03-20 05:15:55 -07:00
|
|
|
#include "SVGLengthList.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-16 14:42:12 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
|
|
|
nsIFrame*
|
2009-01-19 10:31:34 -08:00
|
|
|
NS_NewSVGTextPathFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-01-19 10:31:34 -08:00
|
|
|
return new (aPresShell) nsSVGTextPathFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGTextPathFrame)
|
|
|
|
|
2009-01-19 10:31:34 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGTextPathFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aParent, "null parent");
|
|
|
|
|
|
|
|
nsIFrame* ancestorFrame = nsSVGUtils::GetFirstNonAAncestorFrame(aParent);
|
|
|
|
NS_ASSERTION(ancestorFrame, "Must have ancestor");
|
|
|
|
|
|
|
|
NS_ASSERTION(ancestorFrame->GetType() == nsGkAtoms::svgTextFrame,
|
|
|
|
"trying to construct an SVGTextPathFrame for an invalid "
|
|
|
|
"container");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-25 02:16:02 -07:00
|
|
|
nsCOMPtr<nsIDOMSVGTextPathElement> textPath = do_QueryInterface(aContent);
|
2009-01-19 10:31:34 -08:00
|
|
|
NS_ASSERTION(textPath, "Content is not an SVG textPath");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-01-19 10:31:34 -08:00
|
|
|
return nsSVGTextPathFrameBase::Init(aContent, aParent, aPrevInFlow);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-01-19 10:31:34 -08:00
|
|
|
#endif /* DEBUG */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsIAtom *
|
|
|
|
nsSVGTextPathFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::svgTextPathFrame;
|
|
|
|
}
|
|
|
|
|
2010-07-16 14:42:12 -07:00
|
|
|
void
|
|
|
|
nsSVGTextPathFrame::GetXY(SVGUserUnitList *aX, SVGUserUnitList *aY)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-07-16 14:42:12 -07:00
|
|
|
// 'x' and 'y' don't apply to 'textPath'
|
|
|
|
aX->Clear();
|
|
|
|
aY->Clear();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-07-16 14:42:12 -07:00
|
|
|
void
|
|
|
|
nsSVGTextPathFrame::GetDxDy(SVGUserUnitList *aDx, SVGUserUnitList *aDy)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-07-16 14:42:12 -07:00
|
|
|
// 'dx' and 'dy' don't apply to 'textPath'
|
|
|
|
aDx->Clear();
|
|
|
|
aDy->Clear();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-12-03 08:40:23 -08:00
|
|
|
const SVGNumberList*
|
2010-03-30 03:21:19 -07:00
|
|
|
nsSVGTextPathFrame::GetRotate()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-03-30 03:21:19 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGTextPathFrame methods:
|
|
|
|
|
|
|
|
nsIFrame *
|
2007-07-25 02:16:02 -07:00
|
|
|
nsSVGTextPathFrame::GetPathFrame()
|
|
|
|
{
|
2010-03-28 18:46:55 -07:00
|
|
|
nsSVGTextPathProperty *property = static_cast<nsSVGTextPathProperty*>
|
|
|
|
(Properties().Get(nsSVGEffects::HrefProperty()));
|
2008-10-11 04:29:35 -07:00
|
|
|
|
|
|
|
if (!property) {
|
|
|
|
nsSVGTextPathElement *tp = static_cast<nsSVGTextPathElement*>(mContent);
|
2009-01-21 16:56:51 -08:00
|
|
|
nsAutoString href;
|
|
|
|
tp->mStringAttributes[nsSVGTextPathElement::HREF].GetAnimValue(href, tp);
|
2008-10-11 04:29:35 -07:00
|
|
|
if (href.IsEmpty()) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr; // no URL
|
2008-10-11 04:29:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> targetURI;
|
|
|
|
nsCOMPtr<nsIURI> base = mContent->GetBaseURI();
|
|
|
|
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(targetURI), href,
|
|
|
|
mContent->GetCurrentDoc(), base);
|
|
|
|
|
2010-03-28 18:46:55 -07:00
|
|
|
property =
|
|
|
|
nsSVGEffects::GetTextPathProperty(targetURI, this, nsSVGEffects::HrefProperty());
|
2008-10-11 04:29:35 -07:00
|
|
|
if (!property)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-10-11 04:29:35 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-11-16 10:03:45 -08:00
|
|
|
nsIFrame *frame = property->GetReferencedFrame(nsGkAtoms::svgPathGeometryFrame, nullptr);
|
|
|
|
return frame && frame->GetContent()->Tag() == nsGkAtoms::path ? frame : nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-04-16 13:57:09 -07:00
|
|
|
already_AddRefed<gfxFlattenedPath>
|
2007-07-25 02:16:02 -07:00
|
|
|
nsSVGTextPathFrame::GetFlattenedPath()
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame *path = GetPathFrame();
|
|
|
|
|
2011-05-01 11:26:20 -07:00
|
|
|
if (path) {
|
|
|
|
nsSVGPathGeometryElement *element =
|
|
|
|
static_cast<nsSVGPathGeometryElement*>(path->GetContent());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-02-17 00:12:47 -08:00
|
|
|
return element->GetFlattenedPath(element->PrependLocalTransformsTo(gfxMatrix()));
|
2011-05-01 11:26:20 -07:00
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-05-01 11:26:20 -07:00
|
|
|
|
2007-12-03 22:51:36 -08:00
|
|
|
gfxFloat
|
|
|
|
nsSVGTextPathFrame::GetStartOffset()
|
|
|
|
{
|
|
|
|
nsSVGTextPathElement *tp = static_cast<nsSVGTextPathElement*>(mContent);
|
|
|
|
nsSVGLength2 *length = &tp->mLengthAttributes[nsSVGTextPathElement::STARTOFFSET];
|
|
|
|
|
2008-01-25 01:27:03 -08:00
|
|
|
if (length->IsPercentage()) {
|
2007-12-03 22:51:36 -08:00
|
|
|
nsRefPtr<gfxFlattenedPath> data = GetFlattenedPath();
|
2012-05-24 03:43:10 -07:00
|
|
|
return data ? (length->GetAnimValInSpecifiedUnits() * data->GetLength() / 100.0) : 0.0;
|
2007-12-03 22:51:36 -08:00
|
|
|
}
|
2012-05-24 03:43:10 -07:00
|
|
|
return length->GetAnimValue(tp) * GetOffsetScale();
|
2007-12-03 22:51:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxFloat
|
2011-11-15 05:11:43 -08:00
|
|
|
nsSVGTextPathFrame::GetOffsetScale()
|
2007-12-03 22:51:36 -08:00
|
|
|
{
|
|
|
|
nsIFrame *pathFrame = GetPathFrame();
|
|
|
|
if (!pathFrame)
|
|
|
|
return 1.0;
|
|
|
|
|
2011-11-15 05:11:43 -08:00
|
|
|
return static_cast<nsSVGPathElement*>(pathFrame->GetContent())->
|
2011-11-21 13:22:19 -08:00
|
|
|
GetPathLengthScale(nsSVGPathElement::eForTextPath);
|
2007-12-03 22:51:36 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIFrame methods
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGTextPathFrame::AttributeChanged(int32_t aNameSpaceID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aModType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
aAttribute == nsGkAtoms::startOffset) {
|
2012-11-28 01:42:13 -08:00
|
|
|
nsSVGUtils::InvalidateBounds(this, false);
|
|
|
|
nsSVGUtils::ScheduleReflowSVG(this);
|
2008-04-08 05:51:19 -07:00
|
|
|
NotifyGlyphMetricsChange();
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if (aNameSpaceID == kNameSpaceID_XLink &&
|
|
|
|
aAttribute == nsGkAtoms::href) {
|
2012-11-28 01:42:13 -08:00
|
|
|
nsSVGUtils::InvalidateBounds(this, false);
|
|
|
|
nsSVGUtils::ScheduleReflowSVG(this);
|
2008-10-11 04:29:35 -07:00
|
|
|
// Blow away our reference, if any
|
2010-03-28 18:46:55 -07:00
|
|
|
Properties().Delete(nsSVGEffects::HrefProperty());
|
2008-04-08 05:51:19 -07:00
|
|
|
NotifyGlyphMetricsChange();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|