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 "nsSVGPathGeometryFrame.h"
|
2012-03-20 05:15:55 -07:00
|
|
|
|
2012-03-26 04:58:59 -07:00
|
|
|
// Keep others in (case-insensitive) order:
|
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxPlatform.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsGkAtoms.h"
|
2012-03-20 05:15:55 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2008-10-10 06:14:05 -07:00
|
|
|
#include "nsSVGEffects.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsSVGGraphicElement.h"
|
2012-06-30 04:20:46 -07:00
|
|
|
#include "nsSVGIntegrationUtils.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsSVGMarkerFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsSVGPathGeometryElement.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsSVGUtils.h"
|
2012-05-16 21:05:09 -07:00
|
|
|
#include "SVGAnimatedTransformList.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewSVGPathGeometryFrame(nsIPresShell* aPresShell,
|
|
|
|
nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsSVGPathGeometryFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGPathGeometryFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
2009-01-12 11:20:59 -08:00
|
|
|
// nsQueryFrame methods
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
NS_QUERYFRAME_HEAD(nsSVGPathGeometryFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsISVGChildFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsSVGPathGeometryFrameBase)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// 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*>
|
2009-04-23 16:41:17 -07:00
|
|
|
(mContent)->AttributeDefinesGeometry(aAttribute) ||
|
2007-03-22 10:30:00 -07:00
|
|
|
aAttribute == nsGkAtoms::transform))
|
2012-03-20 05:15:53 -07:00
|
|
|
nsSVGUtils::InvalidateAndScheduleBoundsUpdate(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-13 15:03:28 -07:00
|
|
|
/* virtual */ void
|
2008-10-26 03:11:34 -07:00
|
|
|
nsSVGPathGeometryFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-10-26 03:11:34 -07:00
|
|
|
nsSVGPathGeometryFrameBase::DidSetStyleContext(aOldStyleContext);
|
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:
|
|
|
|
|
2012-03-20 05:15:53 -07:00
|
|
|
nsSVGUtils::InvalidateAndScheduleBoundsUpdate(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom *
|
|
|
|
nsSVGPathGeometryFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::svgPathGeometryFrame;
|
|
|
|
}
|
|
|
|
|
2012-05-16 21:05:09 -07:00
|
|
|
bool
|
|
|
|
nsSVGPathGeometryFrame::IsSVGTransformed(gfxMatrix *aOwnTransform,
|
|
|
|
gfxMatrix *aFromParentTransform) const
|
|
|
|
{
|
|
|
|
bool foundTransform = false;
|
|
|
|
|
|
|
|
// Check if our parent has children-only transforms:
|
|
|
|
nsIFrame *parent = GetParent();
|
|
|
|
if (parent &&
|
|
|
|
parent->IsFrameOfType(nsIFrame::eSVG | nsIFrame::eSVGContainer)) {
|
|
|
|
foundTransform = static_cast<nsSVGContainerFrame*>(parent)->
|
|
|
|
HasChildrenOnlyTransform(aFromParentTransform);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGElement *content = static_cast<nsSVGElement*>(mContent);
|
|
|
|
const SVGAnimatedTransformList *list = content->GetAnimatedTransformList();
|
2012-07-09 10:41:12 -07:00
|
|
|
if ((list && !list->GetAnimValue().IsEmpty()) ||
|
|
|
|
content->GetAnimateMotionTransform()) {
|
2012-05-16 21:05:09 -07:00
|
|
|
if (aOwnTransform) {
|
|
|
|
*aOwnTransform = content->PrependLocalTransformsTo(gfxMatrix(),
|
|
|
|
nsSVGElement::eUserSpaceToParent);
|
|
|
|
}
|
|
|
|
foundTransform = true;
|
|
|
|
}
|
|
|
|
return foundTransform;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISVGChildFrame methods
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-03-02 00:28:59 -08:00
|
|
|
nsSVGPathGeometryFrame::PaintSVG(nsRenderingContext *aContext,
|
2008-10-20 01:42:03 -07:00
|
|
|
const 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
|
|
|
{
|
2012-06-30 04:20:46 -07:00
|
|
|
gfxMatrix canvasTM = GetCanvasTM(FOR_HIT_TESTING);
|
2011-07-08 06:20:14 -07:00
|
|
|
PRUint16 fillRule, hitTestFlags;
|
2010-12-06 12:57:18 -08:00
|
|
|
if (GetStateBits() & NS_STATE_SVG_CLIPPATH_CHILD) {
|
2011-07-08 06:20:14 -07:00
|
|
|
hitTestFlags = SVG_HIT_TEST_FILL;
|
2007-12-03 21:11:49 -08:00
|
|
|
fillRule = GetClipRule();
|
|
|
|
} else {
|
2011-07-08 06:20:14 -07:00
|
|
|
hitTestFlags = GetHitTestFlags();
|
2012-02-10 04:33:46 -08:00
|
|
|
// XXX once bug 614732 is fixed, aPoint won't need any conversion in order
|
|
|
|
// to compare it with mRect.
|
|
|
|
if (canvasTM.IsSingular()) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
nsPoint point =
|
|
|
|
nsSVGUtils::TransformOuterSVGPointToChildFrame(aPoint, canvasTM, PresContext());
|
2011-07-08 06:20:14 -07:00
|
|
|
if (!hitTestFlags || ((hitTestFlags & SVG_HIT_TEST_CHECK_MRECT) &&
|
2012-02-10 04:33:46 -08:00
|
|
|
!mRect.Contains(point)))
|
2008-08-25 02:23:54 -07:00
|
|
|
return nsnull;
|
2007-12-03 21:11:49 -08:00
|
|
|
fillRule = GetStyleSVG()->mFillRule;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isHit = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-14 20:02:29 -07:00
|
|
|
nsRefPtr<gfxContext> tmpCtx =
|
2010-10-15 03:20:22 -07:00
|
|
|
new gfxContext(gfxPlatform::GetPlatform()->ScreenReferenceSurface());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-30 04:20:46 -07:00
|
|
|
GeneratePath(tmpCtx, canvasTM);
|
2008-08-25 02:23:54 -07:00
|
|
|
gfxPoint userSpacePoint =
|
2012-06-14 20:02:29 -07:00
|
|
|
tmpCtx->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)
|
2012-06-14 20:02:29 -07:00
|
|
|
tmpCtx->SetFillRule(gfxContext::FILL_RULE_EVEN_ODD);
|
2007-03-22 10:30:00 -07:00
|
|
|
else
|
2012-06-14 20:02:29 -07:00
|
|
|
tmpCtx->SetFillRule(gfxContext::FILL_RULE_WINDING);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-07-08 06:20:14 -07:00
|
|
|
if (hitTestFlags & SVG_HIT_TEST_FILL)
|
2012-06-14 20:02:29 -07:00
|
|
|
isHit = tmpCtx->PointInFill(userSpacePoint);
|
2011-07-08 06:20:14 -07:00
|
|
|
if (!isHit && (hitTestFlags & SVG_HIT_TEST_STROKE)) {
|
2012-06-14 20:02:29 -07:00
|
|
|
SetupCairoStrokeHitGeometry(tmpCtx);
|
|
|
|
isHit = tmpCtx->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()
|
|
|
|
{
|
2012-02-10 04:33:49 -08:00
|
|
|
// See bug 614732 comment 32:
|
|
|
|
//return nsSVGUtils::TransformFrameRectToOuterSVG(mRect, GetCanvasTM(), PresContext());
|
|
|
|
return mCoveredRegion;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-20 05:15:53 -07:00
|
|
|
void
|
|
|
|
nsSVGPathGeometryFrame::UpdateBounds()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-03-20 05:15:53 -07:00
|
|
|
NS_ASSERTION(nsSVGUtils::OuterSVGIsCallingUpdateBounds(this),
|
|
|
|
"This call is probaby a wasteful mistake");
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(!(GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD),
|
|
|
|
"UpdateBounds mechanism not designed for this");
|
|
|
|
|
|
|
|
if (!nsSVGUtils::NeedsUpdatedBounds(this)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-09 04:55:16 -07:00
|
|
|
PRUint32 flags = nsSVGUtils::eBBoxIncludeFill |
|
|
|
|
nsSVGUtils::eBBoxIncludeStroke |
|
|
|
|
nsSVGUtils::eBBoxIncludeMarkers;
|
|
|
|
PRUint32 pointerEvents = GetStyleVisibility()->mPointerEvents;
|
|
|
|
if (pointerEvents == NS_STYLE_POINTER_EVENTS_AUTO ||
|
|
|
|
pointerEvents == NS_STYLE_POINTER_EVENTS_VISIBLEPAINTED ||
|
|
|
|
pointerEvents == NS_STYLE_POINTER_EVENTS_PAINTED ||
|
|
|
|
pointerEvents == NS_STYLE_POINTER_EVENTS_NONE) {
|
|
|
|
// We can only ignore 'none' stroke if the value of the pointer-events
|
|
|
|
// property doesn't require us to include it in our "visual" overflow rect
|
|
|
|
// so that our visual overflow rect is valid for building display lists for
|
|
|
|
// hit-testing.
|
|
|
|
flags |= nsSVGUtils::eBBoxIgnoreStrokeIfNone |
|
|
|
|
nsSVGUtils::eBBoxIgnoreFillIfNone;
|
|
|
|
}
|
|
|
|
gfxRect extent = GetBBoxContribution(gfxMatrix(), flags);
|
2012-02-10 04:33:18 -08:00
|
|
|
mRect = nsLayoutUtils::RoundGfxRectToAppRect(extent,
|
2012-02-16 22:07:51 -08:00
|
|
|
PresContext()->AppUnitsPerCSSPixel());
|
2012-02-10 04:33:49 -08:00
|
|
|
|
|
|
|
// See bug 614732 comment 32.
|
|
|
|
mCoveredRegion = nsSVGUtils::TransformFrameRectToOuterSVG(
|
2012-06-30 04:20:46 -07:00
|
|
|
mRect, GetCanvasTM(FOR_OUTERSVG_TM), PresContext());
|
2012-02-10 04:33:49 -08:00
|
|
|
|
2012-05-16 21:05:09 -07:00
|
|
|
if (mState & NS_FRAME_FIRST_REFLOW) {
|
|
|
|
// Make sure we have our filter property (if any) before calling
|
|
|
|
// FinishAndStoreOverflow (subsequent filter changes are handled off
|
|
|
|
// nsChangeHint_UpdateEffects):
|
|
|
|
nsSVGEffects::UpdateEffects(this);
|
|
|
|
}
|
|
|
|
|
2012-07-07 23:29:57 -07:00
|
|
|
// We only invalidate if we are dirty, if our outer-<svg> has already had its
|
|
|
|
// initial reflow (since if it hasn't, its entire area will be invalidated
|
|
|
|
// when it gets that initial reflow), and if our parent is not dirty (since
|
|
|
|
// if it is, then it will invalidate its entire new area, which will include
|
|
|
|
// our new area).
|
|
|
|
bool invalidate = (mState & NS_FRAME_IS_DIRTY) &&
|
|
|
|
!(GetParent()->GetStateBits() &
|
|
|
|
(NS_FRAME_FIRST_REFLOW | NS_FRAME_IS_DIRTY));
|
|
|
|
|
2012-05-16 21:05:09 -07:00
|
|
|
nsRect overflow = nsRect(nsPoint(0,0), mRect.Size());
|
|
|
|
nsOverflowAreas overflowAreas(overflow, overflow);
|
|
|
|
FinishAndStoreOverflow(overflowAreas, mRect.Size());
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
mState &= ~(NS_FRAME_FIRST_REFLOW | NS_FRAME_IS_DIRTY |
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
2012-03-20 05:15:53 -07:00
|
|
|
|
2012-07-07 23:29:57 -07:00
|
|
|
if (invalidate) {
|
|
|
|
// XXXSDL Let FinishAndStoreOverflow do this.
|
2012-03-20 05:15:53 -07:00
|
|
|
nsSVGUtils::InvalidateBounds(this, true);
|
2012-03-20 05:15:53 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-01-25 01:27:03 -08:00
|
|
|
void
|
|
|
|
nsSVGPathGeometryFrame::NotifySVGChanged(PRUint32 aFlags)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-03-11 08:53:36 -07:00
|
|
|
NS_ABORT_IF_FALSE(!(aFlags & DO_NOT_NOTIFY_RENDERING_OBSERVERS) ||
|
|
|
|
(GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD),
|
|
|
|
"Must be NS_STATE_SVG_NONDISPLAY_CHILD!");
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(aFlags & (TRANSFORM_CHANGED | COORD_CONTEXT_CHANGED),
|
|
|
|
"Invalidation logic may need adjusting");
|
|
|
|
|
2012-06-23 09:36:46 -07:00
|
|
|
// Ancestor changes can't affect how we render from the perspective of
|
|
|
|
// any rendering observers that we may have, so we don't need to
|
|
|
|
// invalidate them. We also don't need to invalidate ourself, since our
|
|
|
|
// changed ancestor will have invalidated its entire area, which includes
|
|
|
|
// our area.
|
|
|
|
nsSVGUtils::ScheduleBoundsUpdate(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-04-16 01:23:48 -07:00
|
|
|
SVGBBox
|
2011-09-30 02:25:37 -07:00
|
|
|
nsSVGPathGeometryFrame::GetBBoxContribution(const gfxMatrix &aToBBoxUserspace,
|
|
|
|
PRUint32 aFlags)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-04-16 01:23:48 -07:00
|
|
|
SVGBBox bbox;
|
|
|
|
|
2009-04-28 21:31:34 -07:00
|
|
|
if (aToBBoxUserspace.IsSingular()) {
|
|
|
|
// XXX ReportToConsole
|
2012-04-16 01:23:48 -07:00
|
|
|
return bbox;
|
2009-04-28 21:31:34 -07:00
|
|
|
}
|
2011-09-30 02:25:37 -07:00
|
|
|
|
2012-06-14 20:02:29 -07:00
|
|
|
nsRefPtr<gfxContext> tmpCtx =
|
2010-10-15 03:20:22 -07:00
|
|
|
new gfxContext(gfxPlatform::GetPlatform()->ScreenReferenceSurface());
|
2011-09-30 02:25:37 -07:00
|
|
|
|
2012-06-24 13:12:40 -07:00
|
|
|
GeneratePath(tmpCtx, aToBBoxUserspace);
|
2012-06-14 20:02:29 -07:00
|
|
|
tmpCtx->IdentityMatrix();
|
2011-09-30 02:25:37 -07:00
|
|
|
|
|
|
|
// Be careful when replacing the following logic to get the fill and stroke
|
|
|
|
// extents independently (instead of computing the stroke extents from the
|
|
|
|
// path extents). You may think that you can just use the stroke extents if
|
|
|
|
// there is both a fill and a stroke. In reality it's necessary to calculate
|
|
|
|
// both the fill and stroke extents, and take the union of the two. There are
|
|
|
|
// two reasons for this:
|
|
|
|
//
|
|
|
|
// # Due to stroke dashing, in certain cases the fill extents could actually
|
|
|
|
// extend outside the stroke extents.
|
|
|
|
// # If the stroke is very thin, cairo won't paint any stroke, and so the
|
|
|
|
// stroke bounds that it will return will be empty.
|
|
|
|
|
2012-06-14 20:02:29 -07:00
|
|
|
gfxRect pathExtents = tmpCtx->GetUserPathExtent();
|
2011-09-30 02:25:37 -07:00
|
|
|
|
|
|
|
// Account for fill:
|
|
|
|
if ((aFlags & nsSVGUtils::eBBoxIncludeFill) != 0 &&
|
|
|
|
((aFlags & nsSVGUtils::eBBoxIgnoreFillIfNone) == 0 ||
|
|
|
|
GetStyleSVG()->mFill.mType != eStyleSVGPaintType_None)) {
|
|
|
|
bbox = pathExtents;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Account for stroke:
|
|
|
|
if ((aFlags & nsSVGUtils::eBBoxIncludeStroke) != 0 &&
|
|
|
|
((aFlags & nsSVGUtils::eBBoxIgnoreStrokeIfNone) == 0 || HasStroke())) {
|
2012-06-14 20:02:29 -07:00
|
|
|
// We can't use tmpCtx->GetUserStrokeExtent() since it doesn't work for
|
2011-09-30 02:25:37 -07:00
|
|
|
// device space extents. Instead we approximate the stroke extents from
|
|
|
|
// pathExtents using PathExtentsToMaxStrokeExtents.
|
|
|
|
if (pathExtents.Width() <= 0 && pathExtents.Height() <= 0) {
|
|
|
|
// We have a zero length path, but it may still have non-empty stroke
|
|
|
|
// bounds depending on the value of stroke-linecap. We need to fix up
|
|
|
|
// pathExtents before it can be used with PathExtentsToMaxStrokeExtents
|
|
|
|
// though, because if pathExtents is empty, its position will not have
|
2012-06-14 20:02:29 -07:00
|
|
|
// been set. Happily we can use tmpCtx->GetUserStrokeExtent() to find
|
2011-09-30 02:25:37 -07:00
|
|
|
// the center point of the extents even though it gets the extents wrong.
|
2012-06-14 20:02:29 -07:00
|
|
|
SetupCairoStrokeGeometry(tmpCtx);
|
|
|
|
pathExtents.MoveTo(tmpCtx->GetUserStrokeExtent().Center());
|
2011-09-30 02:25:37 -07:00
|
|
|
pathExtents.SizeTo(0, 0);
|
|
|
|
}
|
2012-04-16 01:23:48 -07:00
|
|
|
bbox.UnionEdges(nsSVGUtils::PathExtentsToMaxStrokeExtents(pathExtents,
|
|
|
|
this,
|
|
|
|
aToBBoxUserspace));
|
2011-09-30 02:25:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Account for markers:
|
|
|
|
if ((aFlags & nsSVGUtils::eBBoxIncludeMarkers) != 0 &&
|
|
|
|
static_cast<nsSVGPathGeometryElement*>(mContent)->IsMarkable()) {
|
|
|
|
|
|
|
|
float strokeWidth = GetStrokeWidth();
|
|
|
|
MarkerProperties properties = GetMarkerProperties(this);
|
|
|
|
|
|
|
|
if (properties.MarkersExist()) {
|
|
|
|
nsTArray<nsSVGMark> marks;
|
|
|
|
static_cast<nsSVGPathGeometryElement*>(mContent)->GetMarkPoints(&marks);
|
|
|
|
PRUint32 num = marks.Length();
|
|
|
|
|
|
|
|
if (num) {
|
|
|
|
nsSVGMarkerFrame *frame = properties.GetMarkerStartFrame();
|
|
|
|
if (frame) {
|
2012-04-16 01:23:48 -07:00
|
|
|
SVGBBox mbbox =
|
2011-09-30 02:25:37 -07:00
|
|
|
frame->GetMarkBBoxContribution(aToBBoxUserspace, aFlags, this,
|
|
|
|
&marks[0], strokeWidth);
|
2012-04-16 01:23:48 -07:00
|
|
|
bbox.UnionEdges(mbbox);
|
2011-09-30 02:25:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
frame = properties.GetMarkerMidFrame();
|
|
|
|
if (frame) {
|
|
|
|
for (PRUint32 i = 1; i < num - 1; i++) {
|
2012-04-16 01:23:48 -07:00
|
|
|
SVGBBox mbbox =
|
2011-09-30 02:25:37 -07:00
|
|
|
frame->GetMarkBBoxContribution(aToBBoxUserspace, aFlags, this,
|
|
|
|
&marks[i], strokeWidth);
|
2012-04-16 01:23:48 -07:00
|
|
|
bbox.UnionEdges(mbbox);
|
2011-09-30 02:25:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
frame = properties.GetMarkerEndFrame();
|
|
|
|
if (frame) {
|
2012-04-16 01:23:48 -07:00
|
|
|
SVGBBox mbbox =
|
2011-09-30 02:25:37 -07:00
|
|
|
frame->GetMarkBBoxContribution(aToBBoxUserspace, aFlags, this,
|
|
|
|
&marks[num-1], strokeWidth);
|
2012-04-16 01:23:48 -07:00
|
|
|
bbox.UnionEdges(mbbox);
|
2011-09-30 02:25:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bbox;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGGeometryFrame methods:
|
|
|
|
|
2009-04-28 21:31:34 -07:00
|
|
|
gfxMatrix
|
2012-06-30 04:20:46 -07:00
|
|
|
nsSVGPathGeometryFrame::GetCanvasTM(PRUint32 aFor)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-06-30 04:20:46 -07:00
|
|
|
if (!(GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD)) {
|
|
|
|
if ((aFor == FOR_PAINTING && NS_SVGDisplayListPaintingEnabled()) ||
|
|
|
|
(aFor == FOR_HIT_TESTING && NS_SVGDisplayListHitTestingEnabled())) {
|
|
|
|
return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-28 21:31:34 -07:00
|
|
|
NS_ASSERTION(mParent, "null parent");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-04-28 21:31:34 -07:00
|
|
|
nsSVGContainerFrame *parent = static_cast<nsSVGContainerFrame*>(mParent);
|
|
|
|
nsSVGGraphicElement *content = static_cast<nsSVGGraphicElement*>(mContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-30 04:20:46 -07:00
|
|
|
return content->PrependLocalTransformsTo(parent->GetCanvasTM(aFor));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// 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();
|
2010-03-28 18:46:55 -07:00
|
|
|
result.mMarkerStart =
|
|
|
|
nsSVGEffects::GetMarkerProperty(style->mMarkerStart, aFrame,
|
|
|
|
nsSVGEffects::MarkerBeginProperty());
|
|
|
|
result.mMarkerMid =
|
|
|
|
nsSVGEffects::GetMarkerProperty(style->mMarkerMid, aFrame,
|
|
|
|
nsSVGEffects::MarkerMiddleProperty());
|
|
|
|
result.mMarkerEnd =
|
|
|
|
nsSVGEffects::GetMarkerProperty(style->mMarkerEnd, aFrame,
|
|
|
|
nsSVGEffects::MarkerEndProperty());
|
2008-10-10 06:14:05 -07:00
|
|
|
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
|
2012-03-02 00:28:59 -08:00
|
|
|
nsSVGPathGeometryFrame::Render(nsRenderingContext *aContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-03-02 00:28:59 -08:00
|
|
|
gfxContext *gfx = aContext->ThebesContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-02 00:28:59 -08:00
|
|
|
PRUint16 renderMode = SVGAutoRenderState::GetRenderMode(aContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-04-24 06:11:03 -07:00
|
|
|
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;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-10-30 13:21:49 -07:00
|
|
|
/* save/restore the state so we don't screw up the xform */
|
|
|
|
gfx->Save();
|
|
|
|
|
2012-06-30 04:20:46 -07:00
|
|
|
GeneratePath(gfx, GetCanvasTM(FOR_PAINTING));
|
2009-10-30 13:21:49 -07:00
|
|
|
|
2012-03-02 00:28:59 -08:00
|
|
|
if (renderMode != SVGAutoRenderState::NORMAL) {
|
2012-06-15 02:06:34 -07:00
|
|
|
NS_ABORT_IF_FALSE(renderMode == SVGAutoRenderState::CLIP ||
|
|
|
|
renderMode == SVGAutoRenderState::CLIP_MASK,
|
|
|
|
"Unknown render mode");
|
2009-10-30 13:21:49 -07:00
|
|
|
gfx->Restore();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (GetClipRule() == NS_STYLE_FILL_RULE_EVENODD)
|
|
|
|
gfx->SetFillRule(gfxContext::FILL_RULE_EVEN_ODD);
|
|
|
|
else
|
|
|
|
gfx->SetFillRule(gfxContext::FILL_RULE_WINDING);
|
|
|
|
|
2012-03-02 00:28:59 -08:00
|
|
|
if (renderMode == SVGAutoRenderState::CLIP_MASK) {
|
2007-03-22 10:30:00 -07:00
|
|
|
gfx->SetColor(gfxRGBA(1.0f, 1.0f, 1.0f, 1.0f));
|
|
|
|
gfx->Fill();
|
|
|
|
gfx->NewPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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
|
2009-04-28 21:31:34 -07:00
|
|
|
nsSVGPathGeometryFrame::GeneratePath(gfxContext* aContext,
|
2012-06-24 13:12:40 -07:00
|
|
|
const gfxMatrix &aTransform)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-06-24 13:12:40 -07:00
|
|
|
if (aTransform.IsSingular()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
aContext->IdentityMatrix();
|
|
|
|
aContext->NewPath();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-24 13:12:40 -07:00
|
|
|
aContext->Multiply(aTransform);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-20 02:16:02 -07:00
|
|
|
// Hack to let SVGPathData::ConstructPath know if we have square caps:
|
|
|
|
const nsStyleSVG* style = GetStyleSVG();
|
|
|
|
if (style->mStrokeLinecap == NS_STYLE_STROKE_LINECAP_SQUARE) {
|
|
|
|
aContext->SetLineCap(gfxContext::LINE_CAP_SQUARE);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|