2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Mozilla SVG project.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Crocodile Clips Ltd..
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2002
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Alex Fritze <alex.fritze@crocodile-clips.com> (original author)
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsSVGPathGeometryFrame.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsSVGMarkerFrame.h"
|
|
|
|
#include "nsSVGMatrix.h"
|
|
|
|
#include "nsSVGUtils.h"
|
2008-10-10 06:14:05 -07:00
|
|
|
#include "nsSVGEffects.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsSVGGraphicElement.h"
|
|
|
|
#include "nsSVGOuterSVGFrame.h"
|
|
|
|
#include "nsSVGRect.h"
|
|
|
|
#include "nsSVGPathGeometryElement.h"
|
|
|
|
#include "gfxContext.h"
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewSVGPathGeometryFrame(nsIPresShell* aPresShell,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsSVGPathGeometryFrame(aContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports methods
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsSVGPathGeometryFrame)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISVGChildFrame)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsSVGPathGeometryFrameBase)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIFrame methods
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGPathGeometryFrame::AttributeChanged(PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aModType)
|
|
|
|
{
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None &&
|
2007-07-08 00:08:04 -07:00
|
|
|
(static_cast<nsSVGPathGeometryElement*>
|
|
|
|
(mContent)->IsDependentAttribute(aAttribute) ||
|
2007-03-22 10:30:00 -07:00
|
|
|
aAttribute == nsGkAtoms::transform))
|
2008-04-08 05:51:19 -07:00
|
|
|
nsSVGUtils::UpdateGraphic(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-13 15:03:28 -07:00
|
|
|
/* virtual */ void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSVGPathGeometryFrame::DidSetStyleContext()
|
|
|
|
{
|
|
|
|
nsSVGPathGeometryFrameBase::DidSetStyleContext();
|
|
|
|
|
2007-12-03 08:57:34 -08:00
|
|
|
nsSVGOuterSVGFrame *outerSVGFrame = nsSVGUtils::GetOuterSVGFrame(this);
|
|
|
|
if (outerSVGFrame) {
|
|
|
|
// invalidate here while we still have the filter information
|
2008-03-19 14:27:33 -07:00
|
|
|
outerSVGFrame->InvalidateCoveredRegion(this);
|
2007-12-03 08:57:34 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXX: we'd like to use the style_hint mechanism and the
|
|
|
|
// ContentStateChanged/AttributeChanged functions for style changes
|
|
|
|
// to get slightly finer granularity, but unfortunately the
|
|
|
|
// style_hints don't map very well onto svg. Here seems to be the
|
|
|
|
// best place to deal with style changes:
|
|
|
|
|
2008-04-08 05:51:19 -07:00
|
|
|
nsSVGUtils::UpdateGraphic(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom *
|
|
|
|
nsSVGPathGeometryFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::svgPathGeometryFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISVGChildFrame methods
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGPathGeometryFrame::PaintSVG(nsSVGRenderState *aContext,
|
2008-08-25 02:23:54 -07:00
|
|
|
nsIntRect *aDirtyRect)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!GetStyleVisibility()->IsVisible())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
/* render */
|
|
|
|
Render(aContext);
|
|
|
|
|
2007-07-08 00:08:04 -07:00
|
|
|
if (static_cast<nsSVGPathGeometryElement*>(mContent)->IsMarkable()) {
|
2008-10-10 06:14:05 -07:00
|
|
|
MarkerProperties properties = GetMarkerProperties(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-10-10 06:14:05 -07:00
|
|
|
if (properties.MarkersExist()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
float strokeWidth = GetStrokeWidth();
|
|
|
|
|
|
|
|
nsTArray<nsSVGMark> marks;
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsSVGPathGeometryElement*>
|
|
|
|
(mContent)->GetMarkPoints(&marks);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PRUint32 num = marks.Length();
|
2007-04-10 03:19:59 -07:00
|
|
|
|
|
|
|
if (num) {
|
2008-10-10 06:14:05 -07:00
|
|
|
nsSVGMarkerFrame *frame = properties.GetMarkerStartFrame();
|
2007-04-10 03:19:59 -07:00
|
|
|
if (frame)
|
|
|
|
frame->PaintMark(aContext, this, &marks[0], strokeWidth);
|
|
|
|
|
2008-10-10 06:14:05 -07:00
|
|
|
frame = properties.GetMarkerMidFrame();
|
2007-04-10 03:19:59 -07:00
|
|
|
if (frame) {
|
|
|
|
for (PRUint32 i = 1; i < num - 1; i++)
|
|
|
|
frame->PaintMark(aContext, this, &marks[i], strokeWidth);
|
|
|
|
}
|
|
|
|
|
2008-10-10 06:14:05 -07:00
|
|
|
frame = properties.GetMarkerEndFrame();
|
2007-04-10 03:19:59 -07:00
|
|
|
if (frame)
|
|
|
|
frame->PaintMark(aContext, this, &marks[num-1], strokeWidth);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-08-25 02:23:54 -07:00
|
|
|
NS_IMETHODIMP_(nsIFrame*)
|
|
|
|
nsSVGPathGeometryFrame::GetFrameForPoint(const nsPoint &aPoint)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-12-03 21:11:49 -08:00
|
|
|
PRUint16 fillRule, mask;
|
|
|
|
// check if we're a clipPath - cheaper than IsClipChild(), and we shouldn't
|
|
|
|
// get in here for other nondisplay children
|
|
|
|
if (GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD) {
|
|
|
|
NS_ASSERTION(IsClipChild(), "should be in clipPath but we're not");
|
|
|
|
mask = HITTEST_MASK_FILL;
|
|
|
|
fillRule = GetClipRule();
|
|
|
|
} else {
|
|
|
|
mask = GetHittestMask();
|
|
|
|
if (!mask || (!(mask & HITTEST_MASK_FORCE_TEST) &&
|
2008-08-25 02:23:54 -07:00
|
|
|
!mRect.Contains(aPoint)))
|
|
|
|
return nsnull;
|
2007-12-03 21:11:49 -08:00
|
|
|
fillRule = GetStyleSVG()->mFillRule;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PRBool isHit = PR_FALSE;
|
|
|
|
|
|
|
|
gfxContext context(nsSVGUtils::GetThebesComputationalSurface());
|
|
|
|
|
|
|
|
GeneratePath(&context);
|
2008-08-25 02:23:54 -07:00
|
|
|
gfxPoint userSpacePoint =
|
|
|
|
context.DeviceToUser(gfxPoint(PresContext()->AppUnitsToGfxUnits(aPoint.x),
|
|
|
|
PresContext()->AppUnitsToGfxUnits(aPoint.y)));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (fillRule == NS_STYLE_FILL_RULE_EVENODD)
|
|
|
|
context.SetFillRule(gfxContext::FILL_RULE_EVEN_ODD);
|
|
|
|
else
|
|
|
|
context.SetFillRule(gfxContext::FILL_RULE_WINDING);
|
|
|
|
|
|
|
|
if (mask & HITTEST_MASK_FILL)
|
2008-08-25 02:23:54 -07:00
|
|
|
isHit = context.PointInFill(userSpacePoint);
|
2008-09-30 17:51:05 -07:00
|
|
|
if (!isHit && (mask & HITTEST_MASK_STROKE) &&
|
|
|
|
SetupCairoStrokeHitGeometry(&context)) {
|
2008-08-25 02:23:54 -07:00
|
|
|
isHit = context.PointInStroke(userSpacePoint);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-08-25 02:23:54 -07:00
|
|
|
if (isHit && nsSVGUtils::HitTestClip(this, aPoint))
|
|
|
|
return this;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-08-25 02:23:54 -07:00
|
|
|
return nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsRect)
|
|
|
|
nsSVGPathGeometryFrame::GetCoveredRegion()
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
if (static_cast<nsSVGPathGeometryElement*>(mContent)->IsMarkable()) {
|
2008-10-10 06:14:05 -07:00
|
|
|
MarkerProperties properties = GetMarkerProperties(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-10-10 06:14:05 -07:00
|
|
|
if (!properties.MarkersExist())
|
2007-03-22 10:30:00 -07:00
|
|
|
return mRect;
|
|
|
|
|
|
|
|
nsRect rect(mRect);
|
|
|
|
|
|
|
|
float strokeWidth = GetStrokeWidth();
|
|
|
|
|
|
|
|
nsTArray<nsSVGMark> marks;
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsSVGPathGeometryElement*>(mContent)->GetMarkPoints(&marks);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PRUint32 num = marks.Length();
|
|
|
|
|
2007-04-10 03:19:59 -07:00
|
|
|
if (num) {
|
2008-10-10 06:14:05 -07:00
|
|
|
nsSVGMarkerFrame *frame = properties.GetMarkerStartFrame();
|
2007-04-10 03:19:59 -07:00
|
|
|
if (frame) {
|
|
|
|
nsRect mark = frame->RegionMark(this, &marks[0], strokeWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
rect.UnionRect(rect, mark);
|
|
|
|
}
|
|
|
|
|
2008-10-10 06:14:05 -07:00
|
|
|
frame = properties.GetMarkerMidFrame();
|
2007-04-10 03:19:59 -07:00
|
|
|
if (frame) {
|
|
|
|
for (PRUint32 i = 1; i < num - 1; i++) {
|
|
|
|
nsRect mark = frame->RegionMark(this, &marks[i], strokeWidth);
|
|
|
|
rect.UnionRect(rect, mark);
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-10-10 06:14:05 -07:00
|
|
|
frame = properties.GetMarkerEndFrame();
|
2007-04-10 03:19:59 -07:00
|
|
|
if (frame) {
|
|
|
|
nsRect mark = frame->RegionMark(this, &marks[num-1], strokeWidth);
|
|
|
|
rect.UnionRect(rect, mark);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGPathGeometryFrame::UpdateCoveredRegion()
|
|
|
|
{
|
|
|
|
mRect.Empty();
|
|
|
|
|
|
|
|
gfxContext context(nsSVGUtils::GetThebesComputationalSurface());
|
|
|
|
|
|
|
|
GeneratePath(&context);
|
|
|
|
|
|
|
|
gfxRect extent;
|
|
|
|
|
2008-09-30 17:51:05 -07:00
|
|
|
if (SetupCairoStrokeGeometry(&context)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
extent = context.GetUserStrokeExtent();
|
|
|
|
if (!IsDegeneratePath(extent)) {
|
|
|
|
extent = context.UserToDevice(extent);
|
2008-08-25 02:23:54 -07:00
|
|
|
mRect = nsSVGUtils::ToAppPixelRect(PresContext(),extent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
context.IdentityMatrix();
|
2008-01-27 06:55:53 -08:00
|
|
|
extent = context.GetUserPathExtent();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!IsDegeneratePath(extent)) {
|
2008-08-25 02:23:54 -07:00
|
|
|
mRect = nsSVGUtils::ToAppPixelRect(PresContext(),extent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add in markers
|
|
|
|
mRect = GetCoveredRegion();
|
|
|
|
|
2008-04-08 05:51:19 -07:00
|
|
|
nsSVGUtils::UpdateFilterRegion(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGPathGeometryFrame::InitialUpdate()
|
|
|
|
{
|
2007-10-19 04:07:08 -07:00
|
|
|
NS_ASSERTION(GetStateBits() & NS_FRAME_FIRST_REFLOW,
|
|
|
|
"Yikes! We've been called already! Hopefully we weren't called "
|
|
|
|
"before our nsSVGOuterSVGFrame's initial Reflow()!!!");
|
|
|
|
|
2008-04-08 05:51:19 -07:00
|
|
|
nsSVGUtils::UpdateGraphic(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_ASSERTION(!(mState & NS_FRAME_IN_REFLOW),
|
|
|
|
"We don't actually participate in reflow");
|
|
|
|
|
|
|
|
// Do unset the various reflow bits, though.
|
|
|
|
mState &= ~(NS_FRAME_FIRST_REFLOW | NS_FRAME_IS_DIRTY |
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-01-25 01:27:03 -08:00
|
|
|
void
|
|
|
|
nsSVGPathGeometryFrame::NotifySVGChanged(PRUint32 aFlags)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-04-08 05:51:19 -07:00
|
|
|
if (!(aFlags & SUPPRESS_INVALIDATION)) {
|
|
|
|
nsSVGUtils::UpdateGraphic(this);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGPathGeometryFrame::NotifyRedrawSuspended()
|
|
|
|
{
|
|
|
|
// XXX should we cache the fact that redraw is suspended?
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGPathGeometryFrame::NotifyRedrawUnsuspended()
|
|
|
|
{
|
|
|
|
if (GetStateBits() & NS_STATE_SVG_DIRTY)
|
2008-04-08 05:51:19 -07:00
|
|
|
nsSVGUtils::UpdateGraphic(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGPathGeometryFrame::SetMatrixPropagation(PRBool aPropagate)
|
|
|
|
{
|
2008-09-10 17:24:16 -07:00
|
|
|
if (aPropagate) {
|
|
|
|
AddStateBits(NS_STATE_SVG_PROPAGATE_TRANSFORM);
|
|
|
|
} else {
|
|
|
|
RemoveStateBits(NS_STATE_SVG_PROPAGATE_TRANSFORM);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-09-10 17:24:16 -07:00
|
|
|
PRBool
|
|
|
|
nsSVGPathGeometryFrame::GetMatrixPropagation()
|
|
|
|
{
|
|
|
|
return (GetStateBits() & NS_STATE_SVG_PROPAGATE_TRANSFORM) != 0;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGPathGeometryFrame::GetBBox(nsIDOMSVGRect **_retval)
|
|
|
|
{
|
|
|
|
gfxContext context(nsSVGUtils::GetThebesComputationalSurface());
|
|
|
|
|
|
|
|
GeneratePath(&context);
|
|
|
|
context.IdentityMatrix();
|
|
|
|
|
2008-01-27 06:55:53 -08:00
|
|
|
return NS_NewSVGRect(_retval, context.GetUserPathExtent());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGGeometryFrame methods:
|
|
|
|
|
|
|
|
/* readonly attribute nsIDOMSVGMatrix canvasTM; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGPathGeometryFrame::GetCanvasTM(nsIDOMSVGMatrix * *aCTM)
|
|
|
|
{
|
|
|
|
*aCTM = nsnull;
|
|
|
|
|
2008-09-10 17:24:16 -07:00
|
|
|
if (!GetMatrixPropagation()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_NewSVGMatrix(aCTM);
|
|
|
|
}
|
|
|
|
|
2007-07-08 00:08:04 -07:00
|
|
|
nsSVGContainerFrame *containerFrame = static_cast<nsSVGContainerFrame*>
|
|
|
|
(mParent);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIDOMSVGMatrix> parentTM = containerFrame->GetCanvasTM();
|
|
|
|
NS_ASSERTION(parentTM, "null TM");
|
|
|
|
|
|
|
|
// append our local transformations if we have any:
|
|
|
|
nsSVGGraphicElement *element =
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsSVGGraphicElement*>(mContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIDOMSVGMatrix> localTM = element->GetLocalTransformMatrix();
|
|
|
|
|
|
|
|
if (localTM)
|
|
|
|
return parentTM->Multiply(localTM, aCTM);
|
|
|
|
|
|
|
|
*aCTM = parentTM;
|
|
|
|
NS_ADDREF(*aCTM);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGPathGeometryFrame methods:
|
|
|
|
|
2008-10-10 06:14:05 -07:00
|
|
|
nsSVGPathGeometryFrame::MarkerProperties
|
|
|
|
nsSVGPathGeometryFrame::GetMarkerProperties(nsSVGPathGeometryFrame *aFrame)
|
2007-07-24 02:05:37 -07:00
|
|
|
{
|
2008-10-10 06:14:05 -07:00
|
|
|
NS_ASSERTION(!aFrame->GetPrevContinuation(), "aFrame should be first continuation");
|
2007-07-24 02:05:37 -07:00
|
|
|
|
2008-10-10 06:14:05 -07:00
|
|
|
MarkerProperties result;
|
|
|
|
const nsStyleSVG *style = aFrame->GetStyleSVG();
|
|
|
|
result.mMarkerStart = nsSVGEffects::GetMarkerProperty(
|
|
|
|
style->mMarkerStart, aFrame, nsGkAtoms::marker_start);
|
|
|
|
result.mMarkerMid = nsSVGEffects::GetMarkerProperty(
|
|
|
|
style->mMarkerMid, aFrame, nsGkAtoms::marker_mid);
|
|
|
|
result.mMarkerEnd = nsSVGEffects::GetMarkerProperty(
|
|
|
|
style->mMarkerEnd, aFrame, nsGkAtoms::marker_end);
|
|
|
|
return result;
|
2007-07-24 02:05:37 -07:00
|
|
|
}
|
|
|
|
|
2008-10-10 06:14:05 -07:00
|
|
|
nsSVGMarkerFrame *
|
|
|
|
nsSVGPathGeometryFrame::MarkerProperties::GetMarkerStartFrame()
|
2007-07-24 02:05:37 -07:00
|
|
|
{
|
2008-10-10 06:14:05 -07:00
|
|
|
if (!mMarkerStart)
|
|
|
|
return nsnull;
|
|
|
|
return static_cast<nsSVGMarkerFrame *>
|
|
|
|
(mMarkerStart->GetReferencedFrame(nsGkAtoms::svgMarkerFrame, nsnull));
|
2007-07-24 02:05:37 -07:00
|
|
|
}
|
|
|
|
|
2008-10-10 06:14:05 -07:00
|
|
|
nsSVGMarkerFrame *
|
|
|
|
nsSVGPathGeometryFrame::MarkerProperties::GetMarkerMidFrame()
|
2007-07-24 02:05:37 -07:00
|
|
|
{
|
2008-10-10 06:14:05 -07:00
|
|
|
if (!mMarkerMid)
|
|
|
|
return nsnull;
|
|
|
|
return static_cast<nsSVGMarkerFrame *>
|
|
|
|
(mMarkerMid->GetReferencedFrame(nsGkAtoms::svgMarkerFrame, nsnull));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGMarkerFrame *
|
|
|
|
nsSVGPathGeometryFrame::MarkerProperties::GetMarkerEndFrame()
|
|
|
|
{
|
|
|
|
if (!mMarkerEnd)
|
|
|
|
return nsnull;
|
|
|
|
return static_cast<nsSVGMarkerFrame *>
|
|
|
|
(mMarkerEnd->GetReferencedFrame(nsGkAtoms::svgMarkerFrame, nsnull));
|
2007-07-24 02:05:37 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsSVGPathGeometryFrame::Render(nsSVGRenderState *aContext)
|
|
|
|
{
|
|
|
|
gfxContext *gfx = aContext->GetGfxContext();
|
|
|
|
|
|
|
|
PRUint16 renderMode = aContext->GetRenderMode();
|
|
|
|
|
|
|
|
/* save/pop the state so we don't screw up the xform */
|
|
|
|
gfx->Save();
|
|
|
|
|
|
|
|
GeneratePath(gfx);
|
|
|
|
|
|
|
|
if (renderMode != nsSVGRenderState::NORMAL) {
|
|
|
|
gfx->Restore();
|
|
|
|
|
|
|
|
if (GetClipRule() == NS_STYLE_FILL_RULE_EVENODD)
|
|
|
|
gfx->SetFillRule(gfxContext::FILL_RULE_EVEN_ODD);
|
|
|
|
else
|
|
|
|
gfx->SetFillRule(gfxContext::FILL_RULE_WINDING);
|
|
|
|
|
|
|
|
if (renderMode == nsSVGRenderState::CLIP_MASK) {
|
|
|
|
gfx->SetAntialiasMode(gfxContext::MODE_ALIASED);
|
|
|
|
gfx->SetColor(gfxRGBA(1.0f, 1.0f, 1.0f, 1.0f));
|
|
|
|
gfx->Fill();
|
|
|
|
gfx->NewPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (GetStyleSVG()->mShapeRendering) {
|
|
|
|
case NS_STYLE_SHAPE_RENDERING_OPTIMIZESPEED:
|
|
|
|
case NS_STYLE_SHAPE_RENDERING_CRISPEDGES:
|
|
|
|
gfx->SetAntialiasMode(gfxContext::MODE_ALIASED);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
gfx->SetAntialiasMode(gfxContext::MODE_COVERAGE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-09-30 17:51:05 -07:00
|
|
|
if (SetupCairoFill(gfx)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
gfx->Fill();
|
|
|
|
}
|
|
|
|
|
2008-09-30 17:51:05 -07:00
|
|
|
if (SetupCairoStroke(gfx)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
gfx->Stroke();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx->NewPath();
|
|
|
|
|
|
|
|
gfx->Restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGPathGeometryFrame::GeneratePath(gfxContext* aContext)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMSVGMatrix> ctm;
|
|
|
|
GetCanvasTM(getter_AddRefs(ctm));
|
|
|
|
NS_ASSERTION(ctm, "graphic source didn't specify a ctm");
|
|
|
|
|
|
|
|
gfxMatrix matrix = nsSVGUtils::ConvertSVGMatrixToThebes(ctm);
|
|
|
|
|
|
|
|
if (matrix.IsSingular()) {
|
|
|
|
aContext->IdentityMatrix();
|
|
|
|
aContext->NewPath();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-03-27 05:43:59 -07:00
|
|
|
aContext->Multiply(matrix);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
aContext->NewPath();
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsSVGPathGeometryElement*>(mContent)->ConstructPath(aContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
PRUint16
|
|
|
|
nsSVGPathGeometryFrame::GetHittestMask()
|
|
|
|
{
|
|
|
|
PRUint16 mask = 0;
|
|
|
|
|
|
|
|
switch(GetStyleSVG()->mPointerEvents) {
|
|
|
|
case NS_STYLE_POINTER_EVENTS_NONE:
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLEPAINTED:
|
|
|
|
if (GetStyleVisibility()->IsVisible()) {
|
|
|
|
if (GetStyleSVG()->mFill.mType != eStyleSVGPaintType_None)
|
|
|
|
mask |= HITTEST_MASK_FILL;
|
|
|
|
if (GetStyleSVG()->mStroke.mType != eStyleSVGPaintType_None)
|
|
|
|
mask |= HITTEST_MASK_STROKE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLEFILL:
|
|
|
|
if (GetStyleVisibility()->IsVisible()) {
|
2007-08-30 11:53:05 -07:00
|
|
|
mask |= HITTEST_MASK_FILL | HITTEST_MASK_FORCE_TEST;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLESTROKE:
|
|
|
|
if (GetStyleVisibility()->IsVisible()) {
|
2007-08-30 11:53:05 -07:00
|
|
|
mask |= HITTEST_MASK_STROKE | HITTEST_MASK_FORCE_TEST;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLE:
|
|
|
|
if (GetStyleVisibility()->IsVisible()) {
|
2007-08-30 11:53:05 -07:00
|
|
|
mask |=
|
|
|
|
HITTEST_MASK_FILL |
|
|
|
|
HITTEST_MASK_STROKE |
|
|
|
|
HITTEST_MASK_FORCE_TEST;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_PAINTED:
|
|
|
|
if (GetStyleSVG()->mFill.mType != eStyleSVGPaintType_None)
|
|
|
|
mask |= HITTEST_MASK_FILL;
|
|
|
|
if (GetStyleSVG()->mStroke.mType != eStyleSVGPaintType_None)
|
|
|
|
mask |= HITTEST_MASK_STROKE;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_FILL:
|
2007-08-30 11:53:05 -07:00
|
|
|
mask |= HITTEST_MASK_FILL | HITTEST_MASK_FORCE_TEST;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_STROKE:
|
2007-08-30 11:53:05 -07:00
|
|
|
mask |= HITTEST_MASK_STROKE | HITTEST_MASK_FORCE_TEST;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_ALL:
|
2007-08-30 11:53:05 -07:00
|
|
|
mask |=
|
|
|
|
HITTEST_MASK_FILL |
|
|
|
|
HITTEST_MASK_STROKE |
|
|
|
|
HITTEST_MASK_FORCE_TEST;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("not reached");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mask;
|
|
|
|
}
|