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