Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 12:39:26 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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/. */
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 12:39:26 +00:00
|
|
|
|
2012-03-26 11:58:59 +00:00
|
|
|
// Main header first:
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 12:39:26 +00:00
|
|
|
#include "nsSVGPathGeometryFrame.h"
|
2012-03-20 12:15:55 +00:00
|
|
|
|
2012-03-26 11:58:59 +00:00
|
|
|
// Keep others in (case-insensitive) order:
|
2014-07-05 20:53:04 +00:00
|
|
|
#include "gfx2DGlue.h"
|
2012-03-26 11:58:59 +00:00
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxPlatform.h"
|
2012-09-06 04:58:46 +00:00
|
|
|
#include "gfxSVGGlyphs.h"
|
2014-10-17 11:53:16 +00:00
|
|
|
#include "gfxUtils.h"
|
2014-07-06 15:30:55 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2014-09-30 17:08:13 +00:00
|
|
|
#include "mozilla/gfx/Helpers.h"
|
2015-10-18 05:24:48 +00:00
|
|
|
#include "mozilla/RefPtr.h"
|
2012-07-20 18:12:29 +00:00
|
|
|
#include "nsDisplayList.h"
|
2006-12-26 17:47:52 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2014-08-07 07:09:31 +00:00
|
|
|
#include "nsLayoutUtils.h"
|
2012-03-20 12:15:55 +00:00
|
|
|
#include "nsRenderingContext.h"
|
2008-10-10 13:14:05 +00:00
|
|
|
#include "nsSVGEffects.h"
|
2012-06-30 11:20:46 +00:00
|
|
|
#include "nsSVGIntegrationUtils.h"
|
2012-03-26 11:58:59 +00:00
|
|
|
#include "nsSVGMarkerFrame.h"
|
2006-06-21 15:42:28 +00:00
|
|
|
#include "nsSVGPathGeometryElement.h"
|
2012-03-26 11:58:59 +00:00
|
|
|
#include "nsSVGUtils.h"
|
2014-01-30 18:26:54 +00:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2012-05-17 04:05:09 +00:00
|
|
|
#include "SVGAnimatedTransformList.h"
|
2014-07-05 20:53:04 +00:00
|
|
|
#include "SVGContentUtils.h"
|
2013-01-03 06:17:03 +00:00
|
|
|
#include "SVGGraphicsElement.h"
|
2012-05-17 04:05:09 +00:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2013-12-30 21:42:32 +00:00
|
|
|
using namespace mozilla::gfx;
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 12:39:26 +00:00
|
|
|
|
2006-06-21 15:42:28 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewSVGPathGeometryFrame(nsIPresShell* aPresShell,
|
|
|
|
nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsSVGPathGeometryFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGPathGeometryFrame)
|
|
|
|
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 12:39:26 +00:00
|
|
|
//----------------------------------------------------------------------
|
2009-01-12 19:20:59 +00:00
|
|
|
// nsQueryFrame methods
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 12:39:26 +00:00
|
|
|
|
2009-01-12 19:20:59 +00:00
|
|
|
NS_QUERYFRAME_HEAD(nsSVGPathGeometryFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsISVGChildFrame)
|
2013-01-04 04:26:00 +00:00
|
|
|
NS_QUERYFRAME_ENTRY(nsSVGPathGeometryFrame)
|
2009-01-12 19:20:59 +00:00
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsSVGPathGeometryFrameBase)
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 12:39:26 +00:00
|
|
|
|
2012-07-20 18:12:29 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Display list item:
|
|
|
|
|
|
|
|
class nsDisplaySVGPathGeometry : public nsDisplayItem {
|
|
|
|
public:
|
|
|
|
nsDisplaySVGPathGeometry(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsSVGPathGeometryFrame* aFrame)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsDisplaySVGPathGeometry);
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(aFrame, "Must have a frame!");
|
2012-07-20 18:12:29 +00:00
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplaySVGPathGeometry() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplaySVGPathGeometry);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_DISPLAY_DECL_NAME("nsDisplaySVGPathGeometry", TYPE_SVG_PATH_GEOMETRY)
|
|
|
|
|
|
|
|
virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
2015-03-21 16:28:04 +00:00
|
|
|
HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames) override;
|
2012-07-20 18:12:29 +00:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsRenderingContext* aCtx) override;
|
2012-07-20 18:12:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplaySVGPathGeometry::HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
|
|
|
HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames)
|
|
|
|
{
|
|
|
|
nsSVGPathGeometryFrame *frame = static_cast<nsSVGPathGeometryFrame*>(mFrame);
|
|
|
|
nsPoint pointRelativeToReferenceFrame = aRect.Center();
|
|
|
|
// ToReferenceFrame() includes frame->GetPosition(), our user space position.
|
2014-08-07 07:09:31 +00:00
|
|
|
nsPoint userSpacePtInAppUnits = pointRelativeToReferenceFrame -
|
|
|
|
(ToReferenceFrame() - frame->GetPosition());
|
|
|
|
gfxPoint userSpacePt =
|
|
|
|
gfxPoint(userSpacePtInAppUnits.x, userSpacePtInAppUnits.y) /
|
|
|
|
frame->PresContext()->AppUnitsPerCSSPixel();
|
2012-07-20 18:12:29 +00:00
|
|
|
if (frame->GetFrameForPoint(userSpacePt)) {
|
|
|
|
aOutFrames->AppendElement(frame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplaySVGPathGeometry::Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRenderingContext* aCtx)
|
|
|
|
{
|
2014-08-29 19:42:07 +00:00
|
|
|
uint32_t appUnitsPerDevPixel = mFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
|
2012-07-20 18:12:29 +00:00
|
|
|
// ToReferenceFrame includes our mRect offset, but painting takes
|
|
|
|
// account of that too. To avoid double counting, we subtract that
|
|
|
|
// here.
|
|
|
|
nsPoint offset = ToReferenceFrame() - mFrame->GetPosition();
|
|
|
|
|
2014-08-29 19:42:07 +00:00
|
|
|
gfxPoint devPixelOffset =
|
|
|
|
nsLayoutUtils::PointToGfxPoint(offset, appUnitsPerDevPixel);
|
|
|
|
|
|
|
|
gfxMatrix tm = nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(mFrame) *
|
|
|
|
gfxMatrix::Translation(devPixelOffset);
|
2014-10-31 20:08:54 +00:00
|
|
|
static_cast<nsSVGPathGeometryFrame*>(mFrame)->PaintSVG(*aCtx->ThebesContext(), tm);
|
2012-07-20 18:12:29 +00:00
|
|
|
}
|
|
|
|
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 12:39:26 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIFrame methods
|
2006-06-20 17:01:09 +00:00
|
|
|
|
2014-01-04 08:29:02 +00:00
|
|
|
void
|
2014-05-24 22:20:40 +00:00
|
|
|
nsSVGPathGeometryFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2014-01-04 08:29:02 +00:00
|
|
|
{
|
|
|
|
AddStateBits(aParent->GetStateBits() & NS_STATE_SVG_CLIPPATH_CHILD);
|
|
|
|
nsSVGPathGeometryFrameBase::Init(aContent, aParent, aPrevInFlow);
|
|
|
|
}
|
|
|
|
|
2014-02-18 07:47:48 +00:00
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
nsSVGPathGeometryFrame::AttributeChanged(int32_t aNameSpaceID,
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 12:39:26 +00:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aModType)
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 12:39:26 +00:00
|
|
|
{
|
2013-05-23 07:04:21 +00:00
|
|
|
// We don't invalidate for transform changes (the layers code does that).
|
|
|
|
// Also note that SVGTransformableElement::GetAttributeChangeHint will
|
|
|
|
// return nsChangeHint_UpdateOverflow for "transform" attribute changes
|
|
|
|
// and cause DoApplyRenderingChangeToTree to make the SchedulePaint call.
|
|
|
|
|
2006-03-02 20:22:19 +00:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None &&
|
2007-07-08 07:08:04 +00:00
|
|
|
(static_cast<nsSVGPathGeometryElement*>
|
2013-04-25 09:18:42 +00:00
|
|
|
(mContent)->AttributeDefinesGeometry(aAttribute))) {
|
2014-11-06 09:30:11 +00:00
|
|
|
nsLayoutUtils::PostRestyleEvent(
|
|
|
|
mContent->AsElement(), nsRestyleHint(0),
|
|
|
|
nsChangeHint_InvalidateRenderingObservers);
|
2013-04-25 09:18:42 +00:00
|
|
|
nsSVGUtils::ScheduleReflowSVG(this);
|
2012-11-28 09:42:13 +00:00
|
|
|
}
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 12:39:26 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-08-14 09:51:00 +00:00
|
|
|
/* virtual */ void
|
|
|
|
nsSVGPathGeometryFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
|
|
|
|
{
|
|
|
|
nsSVGPathGeometryFrameBase::DidSetStyleContext(aOldStyleContext);
|
|
|
|
|
|
|
|
if (aOldStyleContext) {
|
2015-11-11 21:31:32 +00:00
|
|
|
auto oldStyleDisplay = aOldStyleContext->PeekStyleDisplay();
|
|
|
|
if (oldStyleDisplay &&
|
|
|
|
StyleDisplay()->mOpacity != oldStyleDisplay->mOpacity &&
|
2013-08-14 09:51:00 +00:00
|
|
|
nsSVGUtils::CanOptimizeOpacity(this)) {
|
|
|
|
// nsIFrame::BuildDisplayListForStackingContext() is not going to create an
|
|
|
|
// nsDisplayOpacity display list item, so DLBI won't invalidate for us.
|
|
|
|
InvalidateFrame();
|
|
|
|
}
|
2014-10-04 11:13:30 +00:00
|
|
|
|
|
|
|
nsSVGPathGeometryElement* element =
|
|
|
|
static_cast<nsSVGPathGeometryElement*>(mContent);
|
|
|
|
|
2015-11-11 21:31:32 +00:00
|
|
|
auto oldStyleSVG = aOldStyleContext->PeekStyleSVG();
|
|
|
|
if (oldStyleSVG && !SVGContentUtils::ShapeTypeHasNoCorners(mContent)) {
|
|
|
|
if (StyleSVG()->mStrokeLinecap != oldStyleSVG->mStrokeLinecap &&
|
2015-03-03 11:09:00 +00:00
|
|
|
element->IsSVGElement(nsGkAtoms::path)) {
|
2014-10-04 11:13:30 +00:00
|
|
|
// If the stroke-linecap changes to or from "butt" then our element
|
|
|
|
// needs to update its cached Moz2D Path, since SVGPathData::BuildPath
|
|
|
|
// decides whether or not to insert little lines into the path for zero
|
|
|
|
// length subpaths base on that property.
|
|
|
|
element->ClearAnyCachedPath();
|
2014-10-06 13:19:14 +00:00
|
|
|
} else if (GetStateBits() & NS_STATE_SVG_CLIPPATH_CHILD) {
|
2015-11-11 21:31:32 +00:00
|
|
|
if (StyleSVG()->mClipRule != oldStyleSVG->mClipRule) {
|
2014-10-06 13:19:14 +00:00
|
|
|
// Moz2D Path objects are fill-rule specific.
|
|
|
|
// For clipPath we use clip-rule as the path's fill-rule.
|
|
|
|
element->ClearAnyCachedPath();
|
|
|
|
}
|
|
|
|
} else {
|
2015-11-11 21:31:32 +00:00
|
|
|
if (StyleSVG()->mFillRule != oldStyleSVG->mFillRule) {
|
2014-10-06 13:19:14 +00:00
|
|
|
// Moz2D Path objects are fill-rule specific.
|
|
|
|
element->ClearAnyCachedPath();
|
|
|
|
}
|
2014-10-04 11:13:30 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-14 09:51:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-01 19:56:08 +00:00
|
|
|
nsIAtom *
|
|
|
|
nsSVGPathGeometryFrame::GetType() const
|
|
|
|
{
|
2006-12-26 17:47:52 +00:00
|
|
|
return nsGkAtoms::svgPathGeometryFrame;
|
2005-04-01 19:56:08 +00:00
|
|
|
}
|
|
|
|
|
2012-05-17 04:05:09 +00:00
|
|
|
bool
|
2013-12-29 23:35:53 +00:00
|
|
|
nsSVGPathGeometryFrame::IsSVGTransformed(gfx::Matrix *aOwnTransform,
|
|
|
|
gfx::Matrix *aFromParentTransform) const
|
2012-05-17 04:05:09 +00:00
|
|
|
{
|
|
|
|
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);
|
2013-04-14 22:56:34 +00:00
|
|
|
nsSVGAnimatedTransformList* transformList =
|
2013-04-14 07:17:36 +00:00
|
|
|
content->GetAnimatedTransformList();
|
|
|
|
if ((transformList && transformList->HasTransform()) ||
|
2012-07-09 17:41:12 +00:00
|
|
|
content->GetAnimateMotionTransform()) {
|
2012-05-17 04:05:09 +00:00
|
|
|
if (aOwnTransform) {
|
2015-12-02 22:36:23 +00:00
|
|
|
*aOwnTransform = gfx::ToMatrix(
|
|
|
|
content->PrependLocalTransformsTo(
|
|
|
|
gfxMatrix(),
|
|
|
|
eUserSpaceToParent));
|
2012-05-17 04:05:09 +00:00
|
|
|
}
|
|
|
|
foundTransform = true;
|
|
|
|
}
|
|
|
|
return foundTransform;
|
|
|
|
}
|
|
|
|
|
2013-02-14 11:12:27 +00:00
|
|
|
void
|
2012-07-20 18:12:29 +00:00
|
|
|
nsSVGPathGeometryFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
if (!static_cast<const nsSVGElement*>(mContent)->HasValidDimensions()) {
|
2013-02-14 11:12:27 +00:00
|
|
|
return;
|
2012-07-20 18:12:29 +00:00
|
|
|
}
|
2013-02-14 11:08:08 +00:00
|
|
|
aLists.Content()->AppendNewToTop(
|
|
|
|
new (aBuilder) nsDisplaySVGPathGeometry(aBuilder, this));
|
2012-07-20 18:12:29 +00:00
|
|
|
}
|
|
|
|
|
2006-04-06 13:02:53 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISVGChildFrame methods
|
|
|
|
|
2014-02-19 22:34:31 +00:00
|
|
|
nsresult
|
2014-10-31 20:08:54 +00:00
|
|
|
nsSVGPathGeometryFrame::PaintSVG(gfxContext& aContext,
|
2014-08-29 19:42:07 +00:00
|
|
|
const gfxMatrix& aTransform,
|
|
|
|
const nsIntRect* aDirtyRect)
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 12:39:26 +00:00
|
|
|
{
|
2013-02-16 21:51:02 +00:00
|
|
|
if (!StyleVisibility()->IsVisible())
|
2004-10-04 18:56:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2014-09-30 17:08:13 +00:00
|
|
|
// Matrix to the geometry's user space:
|
|
|
|
gfxMatrix newMatrix =
|
2014-10-31 20:08:54 +00:00
|
|
|
aContext.CurrentMatrix().PreMultiply(aTransform).NudgeToIntegers();
|
2014-09-30 17:08:13 +00:00
|
|
|
if (newMatrix.IsSingular()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-02-16 21:51:02 +00:00
|
|
|
uint32_t paintOrder = StyleSVG()->mPaintOrder;
|
2013-01-12 23:27:53 +00:00
|
|
|
if (paintOrder == NS_STYLE_PAINT_ORDER_NORMAL) {
|
2014-10-31 20:08:54 +00:00
|
|
|
Render(&aContext, eRenderFill | eRenderStroke, newMatrix);
|
2014-08-29 19:42:07 +00:00
|
|
|
PaintMarkers(aContext, aTransform);
|
2013-01-12 23:27:53 +00:00
|
|
|
} else {
|
|
|
|
while (paintOrder) {
|
|
|
|
uint32_t component =
|
|
|
|
paintOrder & ((1 << NS_STYLE_PAINT_ORDER_BITWIDTH) - 1);
|
|
|
|
switch (component) {
|
|
|
|
case NS_STYLE_PAINT_ORDER_FILL:
|
2014-10-31 20:08:54 +00:00
|
|
|
Render(&aContext, eRenderFill, newMatrix);
|
2013-01-12 23:27:53 +00:00
|
|
|
break;
|
|
|
|
case NS_STYLE_PAINT_ORDER_STROKE:
|
2014-10-31 20:08:54 +00:00
|
|
|
Render(&aContext, eRenderStroke, newMatrix);
|
2013-01-12 23:27:53 +00:00
|
|
|
break;
|
|
|
|
case NS_STYLE_PAINT_ORDER_MARKERS:
|
2014-08-29 19:42:07 +00:00
|
|
|
PaintMarkers(aContext, aTransform);
|
2013-01-12 23:27:53 +00:00
|
|
|
break;
|
2007-04-10 10:19:59 +00:00
|
|
|
}
|
2013-01-12 23:27:53 +00:00
|
|
|
paintOrder >>= NS_STYLE_PAINT_ORDER_BITWIDTH;
|
2005-04-06 19:02:13 +00:00
|
|
|
}
|
2004-12-09 03:16:15 +00:00
|
|
|
}
|
|
|
|
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 12:39:26 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-19 22:34:31 +00:00
|
|
|
nsIFrame*
|
2014-08-07 07:09:31 +00:00
|
|
|
nsSVGPathGeometryFrame::GetFrameForPoint(const gfxPoint& aPoint)
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 12:39:26 +00:00
|
|
|
{
|
2014-07-05 20:53:04 +00:00
|
|
|
FillRule fillRule;
|
|
|
|
uint16_t hitTestFlags;
|
2010-12-06 20:57:18 +00:00
|
|
|
if (GetStateBits() & NS_STATE_SVG_CLIPPATH_CHILD) {
|
2011-07-08 13:20:14 +00:00
|
|
|
hitTestFlags = SVG_HIT_TEST_FILL;
|
2014-10-11 08:24:44 +00:00
|
|
|
fillRule = nsSVGUtils::ToFillRule(StyleSVG()->mClipRule);
|
2007-12-04 05:11:49 +00:00
|
|
|
} else {
|
2011-07-08 13:20:14 +00:00
|
|
|
hitTestFlags = GetHitTestFlags();
|
2014-08-07 07:09:31 +00:00
|
|
|
if (!hitTestFlags) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2014-07-05 20:53:04 +00:00
|
|
|
}
|
2014-08-07 07:09:31 +00:00
|
|
|
if (hitTestFlags & SVG_HIT_TEST_CHECK_MRECT) {
|
|
|
|
gfxRect rect =
|
|
|
|
nsLayoutUtils::RectToGfxRect(mRect, PresContext()->AppUnitsPerCSSPixel());
|
|
|
|
if (!rect.Contains(aPoint)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
2014-10-11 08:24:44 +00:00
|
|
|
fillRule = nsSVGUtils::ToFillRule(StyleSVG()->mFillRule);
|
2007-12-04 05:11:49 +00:00
|
|
|
}
|
2006-06-09 18:08:33 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isHit = false;
|
2006-06-20 17:01:09 +00:00
|
|
|
|
2014-07-05 20:53:04 +00:00
|
|
|
nsSVGPathGeometryElement* content =
|
|
|
|
static_cast<nsSVGPathGeometryElement*>(mContent);
|
|
|
|
|
|
|
|
// Using ScreenReferenceDrawTarget() opens us to Moz2D backend specific hit-
|
|
|
|
// testing bugs. Maybe we should use a BackendType::CAIRO DT for hit-testing
|
|
|
|
// so that we get more consistent/backwards compatible results?
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DrawTarget> drawTarget =
|
2014-07-05 20:53:04 +00:00
|
|
|
gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget();
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Path> path = content->GetOrBuildPath(*drawTarget, fillRule);
|
2014-07-05 20:53:04 +00:00
|
|
|
if (!path) {
|
|
|
|
return nullptr; // no path, so we don't paint anything that can be hit
|
|
|
|
}
|
2006-06-20 17:01:09 +00:00
|
|
|
|
2014-07-05 20:53:04 +00:00
|
|
|
if (hitTestFlags & SVG_HIT_TEST_FILL) {
|
2014-08-07 07:09:31 +00:00
|
|
|
isHit = path->ContainsPoint(ToPoint(aPoint), Matrix());
|
2014-07-05 20:53:04 +00:00
|
|
|
}
|
2011-07-08 13:20:14 +00:00
|
|
|
if (!isHit && (hitTestFlags & SVG_HIT_TEST_STROKE)) {
|
2014-08-07 07:09:31 +00:00
|
|
|
Point point = ToPoint(aPoint);
|
2014-07-05 20:53:04 +00:00
|
|
|
SVGContentUtils::AutoStrokeOptions stroke;
|
|
|
|
SVGContentUtils::GetStrokeOptions(&stroke, content, StyleContext(), nullptr);
|
2014-09-30 17:08:14 +00:00
|
|
|
gfxMatrix userToOuterSVG;
|
|
|
|
if (nsSVGUtils::GetNonScalingStrokeTransform(this, &userToOuterSVG)) {
|
2014-07-05 20:53:04 +00:00
|
|
|
// We need to transform the path back into the appropriate ancestor
|
|
|
|
// coordinate system in order for non-scaled stroke to be correct.
|
|
|
|
// Naturally we also need to transform the point into the same
|
|
|
|
// coordinate system in order to hit-test against the path.
|
2014-09-30 17:08:14 +00:00
|
|
|
point = ToMatrix(userToOuterSVG) * point;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<PathBuilder> builder =
|
2014-09-30 17:08:14 +00:00
|
|
|
path->TransformedCopyToBuilder(ToMatrix(userToOuterSVG), fillRule);
|
2014-07-05 20:53:04 +00:00
|
|
|
path = builder->Finish();
|
|
|
|
}
|
2014-08-07 07:09:31 +00:00
|
|
|
isHit = path->StrokeContainsPoint(stroke, point, Matrix());
|
2006-08-07 16:41:58 +00:00
|
|
|
}
|
2006-06-20 17:01:09 +00:00
|
|
|
|
2008-08-25 09:23:54 +00:00
|
|
|
if (isHit && nsSVGUtils::HitTestClip(this, aPoint))
|
|
|
|
return this;
|
2006-06-20 17:01:09 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 12:39:26 +00:00
|
|
|
}
|
|
|
|
|
2014-02-19 22:34:31 +00:00
|
|
|
nsRect
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 12:39:26 +00:00
|
|
|
nsSVGPathGeometryFrame::GetCoveredRegion()
|
|
|
|
{
|
2015-09-22 08:31:00 +00:00
|
|
|
gfxMatrix canvasTM = GetCanvasTM();
|
|
|
|
if (canvasTM.PreservesAxisAlignedRectangles()) {
|
|
|
|
return nsSVGUtils::TransformFrameRectToOuterSVG(
|
|
|
|
mRect, canvasTM, PresContext());
|
|
|
|
}
|
|
|
|
|
|
|
|
// To get tight bounds we need to compute directly in outer SVG coordinates
|
|
|
|
uint32_t flags = nsSVGUtils::eBBoxIncludeFill |
|
|
|
|
nsSVGUtils::eBBoxIncludeStroke |
|
|
|
|
nsSVGUtils::eBBoxIncludeMarkers;
|
|
|
|
gfxRect extent =
|
|
|
|
GetBBoxContribution(ToMatrix(canvasTM), flags).ToThebesRect();
|
|
|
|
nsRect region = nsLayoutUtils::RoundGfxRectToAppRect(
|
|
|
|
extent, PresContext()->AppUnitsPerCSSPixel());
|
|
|
|
|
2012-07-23 11:00:40 +00:00
|
|
|
return nsSVGUtils::TransformFrameRectToOuterSVG(
|
2015-09-22 08:31:00 +00:00
|
|
|
region, gfxMatrix(), PresContext());
|
2006-06-09 18:08:33 +00:00
|
|
|
}
|
|
|
|
|
2012-03-20 12:15:53 +00:00
|
|
|
void
|
2012-07-22 00:01:44 +00:00
|
|
|
nsSVGPathGeometryFrame::ReflowSVG()
|
2006-06-09 18:08:33 +00:00
|
|
|
{
|
2012-07-22 00:01:44 +00:00
|
|
|
NS_ASSERTION(nsSVGUtils::OuterSVGIsCallingReflowSVG(this),
|
|
|
|
"This call is probably a wasteful mistake");
|
2012-03-20 12:15:53 +00:00
|
|
|
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(!(GetStateBits() & NS_FRAME_IS_NONDISPLAY),
|
|
|
|
"ReflowSVG mechanism not designed for this");
|
2012-03-20 12:15:53 +00:00
|
|
|
|
2012-07-22 00:01:44 +00:00
|
|
|
if (!nsSVGUtils::NeedsReflowSVG(this)) {
|
2012-03-20 12:15:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t flags = nsSVGUtils::eBBoxIncludeFill |
|
2012-07-09 11:55:16 +00:00
|
|
|
nsSVGUtils::eBBoxIncludeStroke |
|
|
|
|
nsSVGUtils::eBBoxIncludeMarkers;
|
2012-07-11 11:25:27 +00:00
|
|
|
// Our "visual" overflow rect needs to be valid for building display lists
|
|
|
|
// for hit testing, which means that for certain values of 'pointer-events'
|
|
|
|
// it needs to include the geometry of the fill or stroke even when the fill/
|
|
|
|
// stroke don't actually render (e.g. when stroke="none" or
|
|
|
|
// stroke-opacity="0"). GetHitTestFlags() accounts for 'pointer-events'.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t hitTestFlags = GetHitTestFlags();
|
2012-07-11 11:25:27 +00:00
|
|
|
if ((hitTestFlags & SVG_HIT_TEST_FILL)) {
|
|
|
|
flags |= nsSVGUtils::eBBoxIncludeFillGeometry;
|
|
|
|
}
|
|
|
|
if ((hitTestFlags & SVG_HIT_TEST_STROKE)) {
|
|
|
|
flags |= nsSVGUtils::eBBoxIncludeStrokeGeometry;
|
2012-07-09 11:55:16 +00:00
|
|
|
}
|
2012-12-20 13:49:54 +00:00
|
|
|
|
2014-10-04 11:13:30 +00:00
|
|
|
gfxRect extent = GetBBoxContribution(Matrix(), flags).ToThebesRect();
|
2012-02-10 12:33:18 +00:00
|
|
|
mRect = nsLayoutUtils::RoundGfxRectToAppRect(extent,
|
2012-02-17 06:07:51 +00:00
|
|
|
PresContext()->AppUnitsPerCSSPixel());
|
2012-02-10 12:33:49 +00:00
|
|
|
|
2012-05-17 04:05:09 +00: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);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect overflow = nsRect(nsPoint(0,0), mRect.Size());
|
|
|
|
nsOverflowAreas overflowAreas(overflow, overflow);
|
|
|
|
FinishAndStoreOverflow(overflowAreas, mRect.Size());
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
mState &= ~(NS_FRAME_FIRST_REFLOW | NS_FRAME_IS_DIRTY |
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
2012-03-20 12:15:53 +00:00
|
|
|
|
2012-11-28 10:34:58 +00:00
|
|
|
// Invalidate, but only if this is not our first reflow (since if it is our
|
|
|
|
// first reflow then we haven't had our first paint yet).
|
|
|
|
if (!(GetParent()->GetStateBits() & NS_FRAME_FIRST_REFLOW)) {
|
|
|
|
InvalidateFrame();
|
2012-03-20 12:15:53 +00:00
|
|
|
}
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 12:39:26 +00:00
|
|
|
}
|
|
|
|
|
2008-01-25 09:27:03 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsSVGPathGeometryFrame::NotifySVGChanged(uint32_t aFlags)
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 12:39:26 +00:00
|
|
|
{
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(aFlags & (TRANSFORM_CHANGED | COORD_CONTEXT_CHANGED),
|
|
|
|
"Invalidation logic may need adjusting");
|
2012-03-11 15:53:36 +00:00
|
|
|
|
2013-05-08 17:13:11 +00:00
|
|
|
// Changes to our ancestors may affect how we render when we are rendered as
|
|
|
|
// part of our ancestor (specifically, if our coordinate context changes size
|
|
|
|
// and we have percentage lengths defining our geometry, then we need to be
|
|
|
|
// reflowed). However, ancestor changes cannot affect how we render when we
|
|
|
|
// are rendered as part of any rendering observers that we may have.
|
|
|
|
// Therefore no need to notify rendering observers here.
|
|
|
|
|
2013-05-23 14:30:14 +00:00
|
|
|
// Don't try to be too smart trying to avoid the ScheduleReflowSVG calls
|
|
|
|
// for the stroke properties examined below. Checking HasStroke() is not
|
|
|
|
// enough, since what we care about is whether we include the stroke in our
|
|
|
|
// overflow rects or not, and we sometimes deliberately include stroke
|
|
|
|
// when it's not visible. See the complexities of GetBBoxContribution.
|
|
|
|
|
|
|
|
if (aFlags & COORD_CONTEXT_CHANGED) {
|
|
|
|
// Stroke currently contributes to our mRect, which is why we have to take
|
|
|
|
// account of stroke-width here. Note that we do not need to take account
|
|
|
|
// of stroke-dashoffset since, although that can have a percentage value
|
|
|
|
// that is resolved against our coordinate context, it does not affect our
|
|
|
|
// mRect.
|
|
|
|
if (static_cast<nsSVGPathGeometryElement*>(mContent)->GeometryDependsOnCoordCtx() ||
|
|
|
|
StyleSVG()->mStrokeWidth.HasPercent()) {
|
2014-10-04 11:13:30 +00:00
|
|
|
static_cast<nsSVGPathGeometryElement*>(mContent)->ClearAnyCachedPath();
|
2013-05-23 14:30:14 +00:00
|
|
|
nsSVGUtils::ScheduleReflowSVG(this);
|
|
|
|
}
|
2013-05-08 17:13:11 +00:00
|
|
|
}
|
2013-05-23 14:30:14 +00:00
|
|
|
|
2014-12-17 13:58:31 +00:00
|
|
|
if ((aFlags & TRANSFORM_CHANGED) && StyleSVGReset()->HasNonScalingStroke()) {
|
2013-05-23 14:30:14 +00:00
|
|
|
// Stroke currently contributes to our mRect, and our stroke depends on
|
|
|
|
// the transform to our outer-<svg> if |vector-effect:non-scaling-stroke|.
|
|
|
|
nsSVGUtils::ScheduleReflowSVG(this);
|
|
|
|
}
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 12:39:26 +00:00
|
|
|
}
|
|
|
|
|
2012-04-16 08:23:48 +00:00
|
|
|
SVGBBox
|
2013-12-30 06:50:07 +00:00
|
|
|
nsSVGPathGeometryFrame::GetBBoxContribution(const Matrix &aToBBoxUserspace,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aFlags)
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 12:39:26 +00:00
|
|
|
{
|
2012-04-16 08:23:48 +00:00
|
|
|
SVGBBox bbox;
|
|
|
|
|
2009-04-29 04:31:34 +00:00
|
|
|
if (aToBBoxUserspace.IsSingular()) {
|
|
|
|
// XXX ReportToConsole
|
2012-04-16 08:23:48 +00:00
|
|
|
return bbox;
|
2009-04-29 04:31:34 +00:00
|
|
|
}
|
2011-09-30 09:25:37 +00:00
|
|
|
|
2014-10-03 08:50:43 +00:00
|
|
|
nsSVGPathGeometryElement* element =
|
|
|
|
static_cast<nsSVGPathGeometryElement*>(mContent);
|
|
|
|
|
2014-10-26 18:00:03 +00:00
|
|
|
bool getFill = (aFlags & nsSVGUtils::eBBoxIncludeFillGeometry) ||
|
|
|
|
((aFlags & nsSVGUtils::eBBoxIncludeFill) &&
|
|
|
|
StyleSVG()->mFill.mType != eStyleSVGPaintType_None);
|
|
|
|
|
|
|
|
bool getStroke = (aFlags & nsSVGUtils::eBBoxIncludeStrokeGeometry) ||
|
|
|
|
((aFlags & nsSVGUtils::eBBoxIncludeStroke) &&
|
|
|
|
nsSVGUtils::HasStroke(this));
|
|
|
|
|
2015-09-01 04:17:00 +00:00
|
|
|
SVGContentUtils::AutoStrokeOptions strokeOptions;
|
|
|
|
if (getStroke) {
|
|
|
|
SVGContentUtils::GetStrokeOptions(&strokeOptions, element,
|
|
|
|
StyleContext(), nullptr,
|
|
|
|
SVGContentUtils::eIgnoreStrokeDashing);
|
|
|
|
} else {
|
|
|
|
// Override the default line width of 1.f so that when we call
|
|
|
|
// GetGeometryBounds below the result doesn't include stroke bounds.
|
2015-01-22 09:36:08 +00:00
|
|
|
strokeOptions.mLineWidth = 0.f;
|
2015-09-01 04:17:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Rect simpleBounds;
|
|
|
|
bool gotSimpleBounds = false;
|
|
|
|
gfxMatrix userToOuterSVG;
|
|
|
|
if (getStroke &&
|
|
|
|
nsSVGUtils::GetNonScalingStrokeTransform(this, &userToOuterSVG)) {
|
|
|
|
Matrix moz2dUserToOuterSVG = ToMatrix(userToOuterSVG);
|
2015-09-30 06:05:00 +00:00
|
|
|
if (moz2dUserToOuterSVG.IsSingular()) {
|
|
|
|
return bbox;
|
|
|
|
}
|
2015-09-01 04:17:00 +00:00
|
|
|
gotSimpleBounds = element->GetGeometryBounds(&simpleBounds,
|
|
|
|
strokeOptions,
|
|
|
|
aToBBoxUserspace,
|
|
|
|
&moz2dUserToOuterSVG);
|
|
|
|
} else {
|
2015-01-22 09:36:08 +00:00
|
|
|
gotSimpleBounds = element->GetGeometryBounds(&simpleBounds,
|
2015-02-03 18:36:32 +00:00
|
|
|
strokeOptions,
|
2014-10-26 18:00:03 +00:00
|
|
|
aToBBoxUserspace);
|
|
|
|
}
|
|
|
|
|
2015-09-01 04:17:00 +00:00
|
|
|
if (gotSimpleBounds) {
|
|
|
|
bbox = simpleBounds;
|
|
|
|
} else {
|
2014-10-26 18:00:03 +00:00
|
|
|
// Get the bounds using a Moz2D Path object (more expensive):
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DrawTarget> tmpDT;
|
2014-07-06 15:30:55 +00:00
|
|
|
#ifdef XP_WIN
|
2014-10-26 18:00:03 +00:00
|
|
|
// Unfortunately D2D backed DrawTarget produces bounds with rounding errors
|
|
|
|
// when whole number results are expected, even in the case of trivial
|
|
|
|
// calculations. To avoid that and meet the expectations of web content we
|
|
|
|
// have to use a CAIRO DrawTarget. The most efficient way to do that is to
|
|
|
|
// wrap the cached cairo_surface_t from ScreenReferenceSurface():
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<gfxASurface> refSurf =
|
2014-10-26 18:00:03 +00:00
|
|
|
gfxPlatform::GetPlatform()->ScreenReferenceSurface();
|
|
|
|
tmpDT = gfxPlatform::GetPlatform()->
|
|
|
|
CreateDrawTargetForSurface(refSurf, IntSize(1, 1));
|
2014-07-06 15:30:55 +00:00
|
|
|
#else
|
2014-10-26 18:00:03 +00:00
|
|
|
tmpDT = gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget();
|
2014-07-06 15:30:55 +00:00
|
|
|
#endif
|
2011-09-30 09:25:37 +00:00
|
|
|
|
2014-10-26 18:00:03 +00:00
|
|
|
FillRule fillRule = nsSVGUtils::ToFillRule(StyleSVG()->mFillRule);
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Path> pathInUserSpace = element->GetOrBuildPath(*tmpDT, fillRule);
|
2014-10-26 18:00:03 +00:00
|
|
|
if (!pathInUserSpace) {
|
2014-10-03 08:50:43 +00:00
|
|
|
return bbox;
|
|
|
|
}
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Path> pathInBBoxSpace;
|
2014-10-26 18:00:03 +00:00
|
|
|
if (aToBBoxUserspace.IsIdentity()) {
|
|
|
|
pathInBBoxSpace = pathInUserSpace;
|
|
|
|
} else {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<PathBuilder> builder =
|
2014-10-26 18:00:03 +00:00
|
|
|
pathInUserSpace->TransformedCopyToBuilder(aToBBoxUserspace, fillRule);
|
|
|
|
pathInBBoxSpace = builder->Finish();
|
|
|
|
if (!pathInBBoxSpace) {
|
|
|
|
return bbox;
|
|
|
|
}
|
|
|
|
}
|
2011-09-30 09:25:37 +00:00
|
|
|
|
2014-10-26 18:00:03 +00: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.
|
|
|
|
|
|
|
|
Rect pathBBoxExtents = pathInBBoxSpace->GetBounds();
|
|
|
|
if (!pathBBoxExtents.IsFinite()) {
|
|
|
|
// This can happen in the case that we only have a move-to command in the
|
|
|
|
// path commands, in which case we know nothing gets rendered.
|
|
|
|
return bbox;
|
|
|
|
}
|
2011-09-30 09:25:37 +00:00
|
|
|
|
2014-10-26 18:00:03 +00:00
|
|
|
// Account for fill:
|
|
|
|
if (getFill) {
|
|
|
|
bbox = pathBBoxExtents;
|
|
|
|
}
|
2011-09-30 09:25:37 +00:00
|
|
|
|
2014-10-26 18:00:03 +00:00
|
|
|
// Account for stroke:
|
|
|
|
if (getStroke) {
|
2014-10-03 08:50:43 +00:00
|
|
|
#if 0
|
2014-10-26 18:00:03 +00:00
|
|
|
// This disabled code is how we would calculate the stroke bounds using
|
|
|
|
// Moz2D Path::GetStrokedBounds(). Unfortunately at the time of writing
|
|
|
|
// it there are two problems that prevent us from using it.
|
|
|
|
//
|
|
|
|
// First, it seems that some of the Moz2D backends are really dumb. Not
|
|
|
|
// only do some GetStrokeOptions() implementations sometimes
|
|
|
|
// significantly overestimate the stroke bounds, but if an argument is
|
|
|
|
// passed for the aTransform parameter then they just return bounds-of-
|
|
|
|
// transformed-bounds. These two things combined can lead the bounds to
|
|
|
|
// be unacceptably oversized, leading to massive over-invalidation.
|
|
|
|
//
|
|
|
|
// Second, the way we account for non-scaling-stroke by transforming the
|
|
|
|
// path using the transform to the outer-<svg> element is not compatible
|
|
|
|
// with the way that nsSVGPathGeometryFrame::Reflow() inserts a scale
|
|
|
|
// into aToBBoxUserspace and then scales the bounds that we return.
|
|
|
|
SVGContentUtils::AutoStrokeOptions strokeOptions;
|
|
|
|
SVGContentUtils::GetStrokeOptions(&strokeOptions, element,
|
|
|
|
StyleContext(), nullptr,
|
|
|
|
SVGContentUtils::eIgnoreStrokeDashing);
|
|
|
|
Rect strokeBBoxExtents;
|
|
|
|
gfxMatrix userToOuterSVG;
|
|
|
|
if (nsSVGUtils::GetNonScalingStrokeTransform(this, &userToOuterSVG)) {
|
|
|
|
Matrix outerSVGToUser = ToMatrix(userToOuterSVG);
|
|
|
|
outerSVGToUser.Invert();
|
|
|
|
Matrix outerSVGToBBox = aToBBoxUserspace * outerSVGToUser;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<PathBuilder> builder =
|
2014-10-26 18:00:03 +00:00
|
|
|
pathInUserSpace->TransformedCopyToBuilder(ToMatrix(userToOuterSVG));
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Path> pathInOuterSVGSpace = builder->Finish();
|
2014-10-26 18:00:03 +00:00
|
|
|
strokeBBoxExtents =
|
|
|
|
pathInOuterSVGSpace->GetStrokedBounds(strokeOptions, outerSVGToBBox);
|
|
|
|
} else {
|
|
|
|
strokeBBoxExtents =
|
|
|
|
pathInUserSpace->GetStrokedBounds(strokeOptions, aToBBoxUserspace);
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(strokeBBoxExtents.IsFinite(), "bbox is about to go bad");
|
|
|
|
bbox.UnionEdges(strokeBBoxExtents);
|
2014-10-03 08:50:43 +00:00
|
|
|
#else
|
|
|
|
// For now we just use nsSVGUtils::PathExtentsToMaxStrokeExtents:
|
2014-10-26 18:00:03 +00:00
|
|
|
gfxRect strokeBBoxExtents =
|
|
|
|
nsSVGUtils::PathExtentsToMaxStrokeExtents(ThebesRect(pathBBoxExtents),
|
|
|
|
this,
|
|
|
|
ThebesMatrix(aToBBoxUserspace));
|
|
|
|
MOZ_ASSERT(ToRect(strokeBBoxExtents).IsFinite(), "bbox is about to go bad");
|
|
|
|
bbox.UnionEdges(strokeBBoxExtents);
|
2014-10-03 08:50:43 +00:00
|
|
|
#endif
|
2014-10-26 18:00:03 +00:00
|
|
|
}
|
2011-09-30 09:25:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Account for markers:
|
|
|
|
if ((aFlags & nsSVGUtils::eBBoxIncludeMarkers) != 0 &&
|
|
|
|
static_cast<nsSVGPathGeometryElement*>(mContent)->IsMarkable()) {
|
|
|
|
|
2012-08-10 11:13:43 +00:00
|
|
|
float strokeWidth = nsSVGUtils::GetStrokeWidth(this);
|
2011-09-30 09:25:37 +00:00
|
|
|
MarkerProperties properties = GetMarkerProperties(this);
|
|
|
|
|
|
|
|
if (properties.MarkersExist()) {
|
|
|
|
nsTArray<nsSVGMark> marks;
|
|
|
|
static_cast<nsSVGPathGeometryElement*>(mContent)->GetMarkPoints(&marks);
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t num = marks.Length();
|
2011-09-30 09:25:37 +00:00
|
|
|
|
2013-07-12 06:39:38 +00:00
|
|
|
// These are in the same order as the nsSVGMark::Type constants.
|
|
|
|
nsSVGMarkerFrame* markerFrames[] = {
|
|
|
|
properties.GetMarkerStartFrame(),
|
|
|
|
properties.GetMarkerMidFrame(),
|
|
|
|
properties.GetMarkerEndFrame(),
|
|
|
|
};
|
2014-01-30 18:26:54 +00:00
|
|
|
PR_STATIC_ASSERT(MOZ_ARRAY_LENGTH(markerFrames) == nsSVGMark::eTypeCount);
|
2013-07-12 06:39:38 +00:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < num; i++) {
|
|
|
|
nsSVGMark& mark = marks[i];
|
|
|
|
nsSVGMarkerFrame* frame = markerFrames[mark.type];
|
2011-09-30 09:25:37 +00:00
|
|
|
if (frame) {
|
2012-04-16 08:23:48 +00:00
|
|
|
SVGBBox mbbox =
|
2011-09-30 09:25:37 +00:00
|
|
|
frame->GetMarkBBoxContribution(aToBBoxUserspace, aFlags, this,
|
2013-07-12 06:39:38 +00:00
|
|
|
&marks[i], strokeWidth);
|
2014-10-03 08:50:43 +00:00
|
|
|
MOZ_ASSERT(mbbox.IsFinite(), "bbox is about to go bad");
|
2012-04-16 08:23:48 +00:00
|
|
|
bbox.UnionEdges(mbbox);
|
2011-09-30 09:25:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bbox;
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 12:39:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2014-01-04 08:29:02 +00:00
|
|
|
// nsSVGPathGeometryFrame methods:
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 12:39:26 +00:00
|
|
|
|
2009-04-29 04:31:34 +00:00
|
|
|
gfxMatrix
|
2014-09-08 11:28:50 +00:00
|
|
|
nsSVGPathGeometryFrame::GetCanvasTM()
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 12:39:26 +00:00
|
|
|
{
|
2014-05-24 22:20:41 +00:00
|
|
|
NS_ASSERTION(GetParent(), "null parent");
|
2004-08-05 09:01:13 +00:00
|
|
|
|
2014-05-24 22:20:41 +00:00
|
|
|
nsSVGContainerFrame *parent = static_cast<nsSVGContainerFrame*>(GetParent());
|
2013-01-03 06:17:03 +00:00
|
|
|
dom::SVGGraphicsElement *content = static_cast<dom::SVGGraphicsElement*>(mContent);
|
2006-04-20 15:24:51 +00:00
|
|
|
|
2014-09-08 11:28:50 +00:00
|
|
|
return content->PrependLocalTransformsTo(parent->GetCanvasTM());
|
Landing of SVG_20020806_BRANCH, Bug 182533. Refactoring of SVG backend, new GDI+ and Libart rendering
backends, text support on Windows (GDI+), rudimentary text support on Linux (libart/freetype2), presentation
attributes, lots of bug fixes (see bug 182533 for dependency list).
Not part of default build; code is #ifdef'ed out.
r=sicking, sr=jst for dom and htmlparser changes
r=bsmedberg, sr=tor for config changes
r=dbaron, sr=bzbarsky for content and layout changes
r=tor, sr=bzbarsky for gfx changes
2004-02-07 12:39:26 +00:00
|
|
|
}
|
|
|
|
|
2008-10-10 13:14:05 +00:00
|
|
|
nsSVGPathGeometryFrame::MarkerProperties
|
|
|
|
nsSVGPathGeometryFrame::GetMarkerProperties(nsSVGPathGeometryFrame *aFrame)
|
2007-07-24 09:05:37 +00:00
|
|
|
{
|
2008-10-10 13:14:05 +00:00
|
|
|
NS_ASSERTION(!aFrame->GetPrevContinuation(), "aFrame should be first continuation");
|
2007-07-24 09:05:37 +00:00
|
|
|
|
2008-10-10 13:14:05 +00:00
|
|
|
MarkerProperties result;
|
2013-02-16 21:51:02 +00:00
|
|
|
const nsStyleSVG *style = aFrame->StyleSVG();
|
2010-03-29 01:46:55 +00: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 13:14:05 +00:00
|
|
|
return result;
|
2007-07-24 09:05:37 +00:00
|
|
|
}
|
|
|
|
|
2008-10-10 13:14:05 +00:00
|
|
|
nsSVGMarkerFrame *
|
|
|
|
nsSVGPathGeometryFrame::MarkerProperties::GetMarkerStartFrame()
|
2007-07-24 09:05:37 +00:00
|
|
|
{
|
2008-10-10 13:14:05 +00:00
|
|
|
if (!mMarkerStart)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2008-10-10 13:14:05 +00:00
|
|
|
return static_cast<nsSVGMarkerFrame *>
|
2012-07-30 14:20:58 +00:00
|
|
|
(mMarkerStart->GetReferencedFrame(nsGkAtoms::svgMarkerFrame, nullptr));
|
2007-07-24 09:05:37 +00:00
|
|
|
}
|
|
|
|
|
2008-10-10 13:14:05 +00:00
|
|
|
nsSVGMarkerFrame *
|
|
|
|
nsSVGPathGeometryFrame::MarkerProperties::GetMarkerMidFrame()
|
2007-07-24 09:05:37 +00:00
|
|
|
{
|
2008-10-10 13:14:05 +00:00
|
|
|
if (!mMarkerMid)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2008-10-10 13:14:05 +00:00
|
|
|
return static_cast<nsSVGMarkerFrame *>
|
2012-07-30 14:20:58 +00:00
|
|
|
(mMarkerMid->GetReferencedFrame(nsGkAtoms::svgMarkerFrame, nullptr));
|
2008-10-10 13:14:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGMarkerFrame *
|
|
|
|
nsSVGPathGeometryFrame::MarkerProperties::GetMarkerEndFrame()
|
|
|
|
{
|
|
|
|
if (!mMarkerEnd)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2008-10-10 13:14:05 +00:00
|
|
|
return static_cast<nsSVGMarkerFrame *>
|
2012-07-30 14:20:58 +00:00
|
|
|
(mMarkerEnd->GetReferencedFrame(nsGkAtoms::svgMarkerFrame, nullptr));
|
2007-07-24 09:05:37 +00:00
|
|
|
}
|
|
|
|
|
2006-06-20 17:01:09 +00:00
|
|
|
void
|
2014-09-30 17:08:13 +00:00
|
|
|
nsSVGPathGeometryFrame::Render(gfxContext* aContext,
|
2013-09-11 07:27:45 +00:00
|
|
|
uint32_t aRenderComponents,
|
2014-09-30 17:08:13 +00:00
|
|
|
const gfxMatrix& aNewTransform)
|
2006-06-20 17:01:09 +00:00
|
|
|
{
|
2014-09-30 17:08:13 +00:00
|
|
|
MOZ_ASSERT(!aNewTransform.IsSingular());
|
2006-06-20 17:01:09 +00:00
|
|
|
|
2014-09-30 17:08:13 +00:00
|
|
|
DrawTarget* drawTarget = aContext->GetDrawTarget();
|
|
|
|
|
2014-09-29 13:26:15 +00:00
|
|
|
FillRule fillRule =
|
2014-10-11 08:24:44 +00:00
|
|
|
nsSVGUtils::ToFillRule((GetStateBits() & NS_STATE_SVG_CLIPPATH_CHILD) ?
|
|
|
|
StyleSVG()->mClipRule : StyleSVG()->mFillRule);
|
2014-09-29 13:26:15 +00:00
|
|
|
|
2014-10-04 11:13:30 +00:00
|
|
|
nsSVGPathGeometryElement* element =
|
|
|
|
static_cast<nsSVGPathGeometryElement*>(mContent);
|
2014-09-29 13:26:15 +00:00
|
|
|
|
2014-09-30 17:08:13 +00:00
|
|
|
AntialiasMode aaMode =
|
|
|
|
(StyleSVG()->mShapeRendering == NS_STYLE_SHAPE_RENDERING_OPTIMIZESPEED ||
|
|
|
|
StyleSVG()->mShapeRendering == NS_STYLE_SHAPE_RENDERING_CRISPEDGES) ?
|
|
|
|
AntialiasMode::NONE : AntialiasMode::SUBPIXEL;
|
2006-06-20 17:01:09 +00:00
|
|
|
|
2014-09-30 17:08:13 +00:00
|
|
|
// We wait as late as possible before setting the transform so that we don't
|
|
|
|
// set it unnecessarily if we return early (it's an expensive operation for
|
|
|
|
// some backends).
|
|
|
|
gfxContextMatrixAutoSaveRestore autoRestoreTransform(aContext);
|
|
|
|
aContext->SetMatrix(aNewTransform);
|
2014-09-29 13:26:15 +00:00
|
|
|
|
2014-10-11 08:24:44 +00:00
|
|
|
if (GetStateBits() & NS_STATE_SVG_CLIPPATH_CHILD) {
|
2014-10-22 11:29:05 +00:00
|
|
|
// We don't complicate this code with GetAsSimplePath since the cost of
|
|
|
|
// masking will dwarf Path creation overhead anyway.
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Path> path = element->GetOrBuildPath(*drawTarget, fillRule);
|
2014-10-22 11:29:05 +00:00
|
|
|
if (path) {
|
|
|
|
ColorPattern white(ToDeviceColor(Color(1.0f, 1.0f, 1.0f, 1.0f)));
|
|
|
|
drawTarget->Fill(path, white,
|
|
|
|
DrawOptions(1.0f, CompositionOp::OP_OVER, aaMode));
|
|
|
|
}
|
2006-06-20 17:01:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-22 11:29:05 +00:00
|
|
|
nsSVGPathGeometryElement::SimplePath simplePath;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Path> path;
|
2014-10-22 11:29:05 +00:00
|
|
|
|
|
|
|
element->GetAsSimplePath(&simplePath);
|
|
|
|
if (!simplePath.IsPath()) {
|
|
|
|
path = element->GetOrBuildPath(*drawTarget, fillRule);
|
|
|
|
if (!path) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-16 02:35:12 +00:00
|
|
|
gfxTextContextPaint *contextPaint =
|
2014-09-30 17:08:13 +00:00
|
|
|
(gfxTextContextPaint*)drawTarget->
|
|
|
|
GetUserData(&gfxTextContextPaint::sUserDataKey);
|
2012-09-06 04:58:46 +00:00
|
|
|
|
2014-09-30 17:08:13 +00:00
|
|
|
if (aRenderComponents & eRenderFill) {
|
2014-09-29 13:26:15 +00:00
|
|
|
GeneralPattern fillPattern;
|
2014-09-30 17:08:13 +00:00
|
|
|
nsSVGUtils::MakeFillPatternFor(this, aContext, &fillPattern, contextPaint);
|
2014-09-29 13:26:15 +00:00
|
|
|
if (fillPattern.GetPattern()) {
|
2014-10-22 11:29:05 +00:00
|
|
|
DrawOptions drawOptions(1.0f, CompositionOp::OP_OVER, aaMode);
|
|
|
|
if (simplePath.IsRect()) {
|
|
|
|
drawTarget->FillRect(simplePath.AsRect(), fillPattern, drawOptions);
|
|
|
|
} else if (path) {
|
|
|
|
drawTarget->Fill(path, fillPattern, drawOptions);
|
|
|
|
}
|
2014-09-29 13:12:06 +00:00
|
|
|
}
|
2006-06-20 17:01:09 +00:00
|
|
|
}
|
|
|
|
|
2013-01-12 23:27:53 +00:00
|
|
|
if ((aRenderComponents & eRenderStroke) &&
|
2014-09-29 13:12:07 +00:00
|
|
|
nsSVGUtils::HasStroke(this, contextPaint)) {
|
2014-09-30 17:08:13 +00:00
|
|
|
// Account for vector-effect:non-scaling-stroke:
|
2014-09-30 17:08:14 +00:00
|
|
|
gfxMatrix userToOuterSVG;
|
|
|
|
if (nsSVGUtils::GetNonScalingStrokeTransform(this, &userToOuterSVG)) {
|
2014-10-22 11:29:05 +00:00
|
|
|
// A simple Rect can't be transformed with rotate/skew, so let's switch
|
|
|
|
// to using a real path:
|
|
|
|
if (!path) {
|
|
|
|
path = element->GetOrBuildPath(*drawTarget, fillRule);
|
|
|
|
if (!path) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
simplePath.Reset();
|
|
|
|
}
|
2014-09-30 17:08:13 +00:00
|
|
|
// We need to transform the path back into the appropriate ancestor
|
|
|
|
// coordinate system, and paint it it that coordinate system, in order
|
|
|
|
// for non-scaled stroke to paint correctly.
|
2014-09-30 17:08:14 +00:00
|
|
|
gfxMatrix outerSVGToUser = userToOuterSVG;
|
|
|
|
outerSVGToUser.Invert();
|
|
|
|
aContext->Multiply(outerSVGToUser);
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<PathBuilder> builder =
|
2014-10-04 11:13:30 +00:00
|
|
|
path->TransformedCopyToBuilder(ToMatrix(userToOuterSVG), fillRule);
|
2014-09-30 17:08:13 +00:00
|
|
|
path = builder->Finish();
|
|
|
|
}
|
2014-09-29 13:26:15 +00:00
|
|
|
GeneralPattern strokePattern;
|
2014-09-30 17:08:13 +00:00
|
|
|
nsSVGUtils::MakeStrokePatternFor(this, aContext, &strokePattern, contextPaint);
|
2014-09-29 13:26:15 +00:00
|
|
|
if (strokePattern.GetPattern()) {
|
2014-09-30 17:08:13 +00:00
|
|
|
SVGContentUtils::AutoStrokeOptions strokeOptions;
|
|
|
|
SVGContentUtils::GetStrokeOptions(&strokeOptions,
|
|
|
|
static_cast<nsSVGElement*>(mContent),
|
|
|
|
StyleContext(), contextPaint);
|
|
|
|
// GetStrokeOptions may set the line width to zero as an optimization
|
|
|
|
if (strokeOptions.mLineWidth <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
2014-10-22 11:29:05 +00:00
|
|
|
DrawOptions drawOptions(1.0f, CompositionOp::OP_OVER, aaMode);
|
|
|
|
if (simplePath.IsRect()) {
|
|
|
|
drawTarget->StrokeRect(simplePath.AsRect(), strokePattern,
|
|
|
|
strokeOptions, drawOptions);
|
|
|
|
} else if (simplePath.IsLine()) {
|
|
|
|
drawTarget->StrokeLine(simplePath.Point1(), simplePath.Point2(),
|
|
|
|
strokePattern, strokeOptions, drawOptions);
|
|
|
|
} else {
|
|
|
|
drawTarget->Stroke(path, strokePattern, strokeOptions, drawOptions);
|
|
|
|
}
|
2014-09-29 13:12:07 +00:00
|
|
|
}
|
2006-06-20 17:01:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-12 23:27:53 +00:00
|
|
|
void
|
2014-10-31 20:08:54 +00:00
|
|
|
nsSVGPathGeometryFrame::PaintMarkers(gfxContext& aContext,
|
2014-08-29 19:42:07 +00:00
|
|
|
const gfxMatrix& aTransform)
|
2013-01-12 23:27:53 +00:00
|
|
|
{
|
2013-05-16 02:35:12 +00:00
|
|
|
gfxTextContextPaint *contextPaint =
|
2014-10-31 20:08:54 +00:00
|
|
|
(gfxTextContextPaint*)aContext.GetDrawTarget()->GetUserData(&gfxTextContextPaint::sUserDataKey);
|
2013-01-12 23:27:53 +00:00
|
|
|
|
|
|
|
if (static_cast<nsSVGPathGeometryElement*>(mContent)->IsMarkable()) {
|
|
|
|
MarkerProperties properties = GetMarkerProperties(this);
|
|
|
|
|
|
|
|
if (properties.MarkersExist()) {
|
2013-05-16 02:35:12 +00:00
|
|
|
float strokeWidth = nsSVGUtils::GetStrokeWidth(this, contextPaint);
|
2013-01-12 23:27:53 +00:00
|
|
|
|
|
|
|
nsTArray<nsSVGMark> marks;
|
|
|
|
static_cast<nsSVGPathGeometryElement*>
|
|
|
|
(mContent)->GetMarkPoints(&marks);
|
|
|
|
|
|
|
|
uint32_t num = marks.Length();
|
|
|
|
if (num) {
|
2013-07-12 06:39:38 +00:00
|
|
|
// These are in the same order as the nsSVGMark::Type constants.
|
|
|
|
nsSVGMarkerFrame* markerFrames[] = {
|
|
|
|
properties.GetMarkerStartFrame(),
|
|
|
|
properties.GetMarkerMidFrame(),
|
|
|
|
properties.GetMarkerEndFrame(),
|
|
|
|
};
|
2014-01-30 18:26:54 +00:00
|
|
|
PR_STATIC_ASSERT(MOZ_ARRAY_LENGTH(markerFrames) == nsSVGMark::eTypeCount);
|
2013-07-12 06:39:38 +00:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < num; i++) {
|
|
|
|
nsSVGMark& mark = marks[i];
|
|
|
|
nsSVGMarkerFrame* frame = markerFrames[mark.type];
|
|
|
|
if (frame) {
|
2014-10-31 20:08:54 +00:00
|
|
|
frame->PaintMark(aContext, aTransform, this, &mark, strokeWidth);
|
2013-07-12 06:39:38 +00:00
|
|
|
}
|
2013-01-12 23:27:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-01-04 08:29:02 +00:00
|
|
|
|
|
|
|
uint16_t
|
|
|
|
nsSVGPathGeometryFrame::GetHitTestFlags()
|
|
|
|
{
|
|
|
|
return nsSVGUtils::GetGeometryHitTestFlags(this);
|
|
|
|
}
|