2006-01-20 20:00:43 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2005-04-05 01:42:26 +04:00
|
|
|
|
2012-03-26 15:58:59 +04:00
|
|
|
// Main header first:
|
|
|
|
// This is also necessary to ensure our definition of M_SQRT1_2 is picked up
|
2009-04-03 00:29:31 +04:00
|
|
|
#include "nsSVGUtils.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2012-03-20 16:15:55 +04:00
|
|
|
|
2012-03-26 15:58:59 +04:00
|
|
|
// Keep others in (case-insensitive) order:
|
2013-11-18 18:29:51 +04:00
|
|
|
#include "gfx2DGlue.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxMatrix.h"
|
|
|
|
#include "gfxPlatform.h"
|
|
|
|
#include "gfxRect.h"
|
|
|
|
#include "gfxUtils.h"
|
|
|
|
#include "mozilla/gfx/2D.h"
|
2014-09-29 17:26:15 +04:00
|
|
|
#include "mozilla/gfx/PatternHelpers.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-05-17 08:05:09 +04:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2012-06-24 16:59:26 +04:00
|
|
|
#include "nsDisplayList.h"
|
2014-02-24 19:22:58 +04:00
|
|
|
#include "nsFilterInstance.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsFrameList.h"
|
|
|
|
#include "nsGkAtoms.h"
|
2005-04-05 01:42:26 +04:00
|
|
|
#include "nsIContent.h"
|
2005-08-05 00:32:02 +04:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIPresShell.h"
|
2005-08-26 06:49:52 +04:00
|
|
|
#include "nsISVGChildFrame.h"
|
2014-10-20 13:55:48 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsStyleCoord.h"
|
|
|
|
#include "nsStyleStruct.h"
|
2006-03-21 18:49:20 +03:00
|
|
|
#include "nsSVGClipPathFrame.h"
|
2006-06-01 19:31:15 +04:00
|
|
|
#include "nsSVGContainerFrame.h"
|
2008-08-08 05:34:43 +04:00
|
|
|
#include "nsSVGEffects.h"
|
2008-09-11 04:24:16 +04:00
|
|
|
#include "nsSVGFilterPaintCallback.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsSVGForeignObjectFrame.h"
|
2013-11-18 18:29:51 +04:00
|
|
|
#include "gfxSVGGlyphs.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsSVGInnerSVGFrame.h"
|
|
|
|
#include "nsSVGIntegrationUtils.h"
|
|
|
|
#include "nsSVGLength2.h"
|
|
|
|
#include "nsSVGMaskFrame.h"
|
|
|
|
#include "nsSVGOuterSVGFrame.h"
|
2014-05-13 05:24:35 +04:00
|
|
|
#include "mozilla/dom/SVGClipPathElement.h"
|
2013-01-13 02:22:31 +04:00
|
|
|
#include "mozilla/dom/SVGPathElement.h"
|
2011-09-05 21:53:34 +04:00
|
|
|
#include "nsSVGPathGeometryElement.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsSVGPathGeometryFrame.h"
|
2012-08-05 23:10:21 +04:00
|
|
|
#include "nsSVGPaintServerFrame.h"
|
2013-01-10 03:02:45 +04:00
|
|
|
#include "mozilla/dom/SVGSVGElement.h"
|
2012-08-10 15:13:44 +04:00
|
|
|
#include "nsTextFrame.h"
|
2012-09-22 23:26:05 +04:00
|
|
|
#include "SVGContentUtils.h"
|
2012-06-01 13:48:39 +04:00
|
|
|
#include "mozilla/unused.h"
|
2012-01-05 11:17:52 +04:00
|
|
|
|
2010-12-20 03:45:29 +03:00
|
|
|
using namespace mozilla;
|
2010-04-30 17:12:06 +04:00
|
|
|
using namespace mozilla::dom;
|
2012-01-05 11:17:52 +04:00
|
|
|
using namespace mozilla::gfx;
|
2007-04-26 12:36:16 +04:00
|
|
|
|
2014-10-04 15:13:30 +04:00
|
|
|
static bool sSVGPathCachingEnabled;
|
2012-05-17 08:05:04 +04:00
|
|
|
static bool sSVGDisplayListHitTestingEnabled;
|
|
|
|
static bool sSVGDisplayListPaintingEnabled;
|
2014-05-13 05:24:35 +04:00
|
|
|
static bool sSVGNewGetBBoxEnabled;
|
2009-03-10 04:20:17 +03:00
|
|
|
|
2014-10-04 15:13:30 +04:00
|
|
|
bool
|
|
|
|
NS_SVGPathCachingEnabled()
|
|
|
|
{
|
|
|
|
return sSVGPathCachingEnabled;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-05-17 08:05:04 +04:00
|
|
|
NS_SVGDisplayListHitTestingEnabled()
|
2009-03-10 04:20:17 +03:00
|
|
|
{
|
2012-05-17 08:05:04 +04:00
|
|
|
return sSVGDisplayListHitTestingEnabled;
|
|
|
|
}
|
2009-03-10 04:20:17 +03:00
|
|
|
|
2012-05-17 08:05:04 +04:00
|
|
|
bool
|
|
|
|
NS_SVGDisplayListPaintingEnabled()
|
|
|
|
{
|
|
|
|
return sSVGDisplayListPaintingEnabled;
|
2009-03-10 04:20:17 +03:00
|
|
|
}
|
|
|
|
|
2014-05-13 05:24:35 +04:00
|
|
|
bool
|
|
|
|
NS_SVGNewGetBBoxEnabled()
|
|
|
|
{
|
|
|
|
return sSVGNewGetBBoxEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-02 12:28:59 +04:00
|
|
|
// we only take the address of this:
|
|
|
|
static mozilla::gfx::UserDataKey sSVGAutoRenderStateKey;
|
|
|
|
|
2014-10-11 12:24:44 +04:00
|
|
|
SVGAutoRenderState::SVGAutoRenderState(DrawTarget* aDrawTarget
|
2013-12-26 22:49:49 +04:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL)
|
2014-09-30 21:08:13 +04:00
|
|
|
: mDrawTarget(aDrawTarget)
|
2012-07-30 18:20:58 +04:00
|
|
|
, mOriginalRenderState(nullptr)
|
2012-03-02 12:28:59 +04:00
|
|
|
, mPaintingToWindow(false)
|
|
|
|
{
|
2013-12-26 22:49:49 +04:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2014-09-05 21:11:35 +04:00
|
|
|
mOriginalRenderState =
|
2014-09-30 21:08:13 +04:00
|
|
|
aDrawTarget->RemoveUserData(&sSVGAutoRenderStateKey);
|
2012-03-02 12:28:59 +04:00
|
|
|
// We always remove ourselves from aContext before it dies, so
|
2012-07-30 18:20:58 +04:00
|
|
|
// passing nullptr as the destroy function is okay.
|
2014-09-30 21:08:13 +04:00
|
|
|
aDrawTarget->AddUserData(&sSVGAutoRenderStateKey, this, nullptr);
|
2012-03-02 12:28:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
SVGAutoRenderState::~SVGAutoRenderState()
|
|
|
|
{
|
2014-09-30 21:08:13 +04:00
|
|
|
mDrawTarget->RemoveUserData(&sSVGAutoRenderStateKey);
|
2012-03-02 12:28:59 +04:00
|
|
|
if (mOriginalRenderState) {
|
2014-09-30 21:08:13 +04:00
|
|
|
mDrawTarget->AddUserData(&sSVGAutoRenderStateKey,
|
|
|
|
mOriginalRenderState, nullptr);
|
2012-03-02 12:28:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVGAutoRenderState::SetPaintingToWindow(bool aPaintingToWindow)
|
|
|
|
{
|
|
|
|
mPaintingToWindow = aPaintingToWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ bool
|
2014-09-30 21:08:13 +04:00
|
|
|
SVGAutoRenderState::IsPaintingToWindow(DrawTarget* aDrawTarget)
|
2012-03-02 12:28:59 +04:00
|
|
|
{
|
2014-09-30 21:08:13 +04:00
|
|
|
void *state = aDrawTarget->GetUserData(&sSVGAutoRenderStateKey);
|
2012-03-02 12:28:59 +04:00
|
|
|
if (state) {
|
|
|
|
return static_cast<SVGAutoRenderState*>(state)->mPaintingToWindow;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-17 08:05:04 +04:00
|
|
|
void
|
|
|
|
nsSVGUtils::Init()
|
|
|
|
{
|
2014-10-04 15:13:30 +04:00
|
|
|
Preferences::AddBoolVarCache(&sSVGPathCachingEnabled,
|
|
|
|
"svg.path-caching.enabled");
|
|
|
|
|
2012-05-17 08:05:04 +04:00
|
|
|
Preferences::AddBoolVarCache(&sSVGDisplayListHitTestingEnabled,
|
|
|
|
"svg.display-lists.hit-testing.enabled");
|
|
|
|
|
|
|
|
Preferences::AddBoolVarCache(&sSVGDisplayListPaintingEnabled,
|
|
|
|
"svg.display-lists.painting.enabled");
|
2014-05-13 05:24:35 +04:00
|
|
|
|
|
|
|
Preferences::AddBoolVarCache(&sSVGNewGetBBoxEnabled,
|
|
|
|
"svg.new-getBBox.enabled");
|
2012-05-17 08:05:04 +04:00
|
|
|
}
|
|
|
|
|
2009-04-25 03:17:43 +04:00
|
|
|
nsSVGDisplayContainerFrame*
|
|
|
|
nsSVGUtils::GetNearestSVGViewport(nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aFrame->IsFrameOfType(nsIFrame::eSVG), "SVG frame expected");
|
|
|
|
if (aFrame->GetType() == nsGkAtoms::svgOuterSVGFrame) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-04-25 03:17:43 +04:00
|
|
|
}
|
|
|
|
while ((aFrame = aFrame->GetParent())) {
|
|
|
|
NS_ASSERTION(aFrame->IsFrameOfType(nsIFrame::eSVG), "SVG frame expected");
|
|
|
|
if (aFrame->GetType() == nsGkAtoms::svgInnerSVGFrame ||
|
|
|
|
aFrame->GetType() == nsGkAtoms::svgOuterSVGFrame) {
|
|
|
|
return do_QueryFrame(aFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_NOTREACHED("This is not reached. It's only needed to compile.");
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-04-25 03:17:43 +04:00
|
|
|
}
|
|
|
|
|
2012-05-17 08:05:09 +04:00
|
|
|
nsRect
|
|
|
|
nsSVGUtils::GetPostFilterVisualOverflowRect(nsIFrame *aFrame,
|
2012-06-17 00:23:48 +04:00
|
|
|
const nsRect &aPreFilterRect)
|
2012-05-17 08:05:09 +04:00
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT,
|
|
|
|
"Called on invalid frame type");
|
2012-05-17 08:05:09 +04:00
|
|
|
|
2014-02-24 19:22:58 +04:00
|
|
|
nsSVGFilterProperty *property = nsSVGEffects::GetFilterProperty(aFrame);
|
|
|
|
if (!property || !property->ReferencesValidResources()) {
|
2012-06-17 00:23:48 +04:00
|
|
|
return aPreFilterRect;
|
2012-05-17 08:05:09 +04:00
|
|
|
}
|
|
|
|
|
2014-02-24 19:22:58 +04:00
|
|
|
return nsFilterInstance::GetPostFilterBounds(aFrame, nullptr, &aPreFilterRect);
|
2012-05-17 08:05:09 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 16:15:53 +04:00
|
|
|
bool
|
2012-07-22 04:01:44 +04:00
|
|
|
nsSVGUtils::OuterSVGIsCallingReflowSVG(nsIFrame *aFrame)
|
2012-03-20 16:15:53 +04:00
|
|
|
{
|
2012-09-22 23:26:05 +04:00
|
|
|
return GetOuterSVGFrame(aFrame)->IsCallingReflowSVG();
|
2012-03-20 16:15:53 +04:00
|
|
|
}
|
|
|
|
|
2013-06-03 18:15:29 +04:00
|
|
|
bool
|
|
|
|
nsSVGUtils::AnyOuterSVGIsCallingReflowSVG(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsSVGOuterSVGFrame* outer = GetOuterSVGFrame(aFrame);
|
|
|
|
do {
|
|
|
|
if (outer->IsCallingReflowSVG()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
outer = GetOuterSVGFrame(outer->GetParent());
|
|
|
|
} while (outer);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-04-08 16:51:19 +04:00
|
|
|
void
|
2012-07-22 04:01:44 +04:00
|
|
|
nsSVGUtils::ScheduleReflowSVG(nsIFrame *aFrame)
|
2008-04-08 16:51:19 +04:00
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aFrame->IsFrameOfType(nsIFrame::eSVG),
|
|
|
|
"Passed bad frame!");
|
2008-04-08 16:51:19 +04:00
|
|
|
|
2012-03-20 16:15:53 +04:00
|
|
|
// If this is triggered, the callers should be fixed to call us before
|
2012-07-22 04:01:44 +04:00
|
|
|
// ReflowSVG is called. If we try to mark dirty bits on frames while we're
|
2012-03-20 16:15:53 +04:00
|
|
|
// in the process of removing them, things will get messed up.
|
2012-07-22 04:01:44 +04:00
|
|
|
NS_ASSERTION(!OuterSVGIsCallingReflowSVG(aFrame),
|
|
|
|
"Do not call under nsISVGChildFrame::ReflowSVG!");
|
2012-03-20 16:15:53 +04:00
|
|
|
|
|
|
|
// We don't call nsSVGEffects::InvalidateRenderingObservers here because
|
2012-08-27 11:51:48 +04:00
|
|
|
// we should only be called under InvalidateAndScheduleReflowSVG (which
|
2012-03-20 16:15:53 +04:00
|
|
|
// calls InvalidateBounds) or nsSVGDisplayContainerFrame::InsertFrames
|
|
|
|
// (at which point the frame has no observers).
|
2008-10-01 04:51:05 +04:00
|
|
|
|
2013-07-12 11:13:07 +04:00
|
|
|
if (aFrame->GetStateBits() & NS_FRAME_IS_NONDISPLAY) {
|
2008-04-08 16:51:19 +04:00
|
|
|
return;
|
2012-02-04 17:58:46 +04:00
|
|
|
}
|
|
|
|
|
2012-03-20 16:15:53 +04:00
|
|
|
if (aFrame->GetStateBits() &
|
|
|
|
(NS_FRAME_IS_DIRTY | NS_FRAME_FIRST_REFLOW)) {
|
|
|
|
// Nothing to do if we're already dirty, or if the outer-<svg>
|
|
|
|
// hasn't yet had its initial reflow.
|
2012-02-04 17:58:46 +04:00
|
|
|
return;
|
2012-03-20 16:15:53 +04:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsSVGOuterSVGFrame *outerSVGFrame = nullptr;
|
2012-03-20 16:15:53 +04:00
|
|
|
|
|
|
|
// We must not add dirty bits to the nsSVGOuterSVGFrame or else
|
|
|
|
// PresShell::FrameNeedsReflow won't work when we pass it in below.
|
|
|
|
if (aFrame->GetStateBits() & NS_STATE_IS_OUTER_SVG) {
|
|
|
|
outerSVGFrame = static_cast<nsSVGOuterSVGFrame*>(aFrame);
|
|
|
|
} else {
|
|
|
|
aFrame->AddStateBits(NS_FRAME_IS_DIRTY);
|
|
|
|
|
|
|
|
nsIFrame *f = aFrame->GetParent();
|
|
|
|
while (f && !(f->GetStateBits() & NS_STATE_IS_OUTER_SVG)) {
|
|
|
|
if (f->GetStateBits() &
|
|
|
|
(NS_FRAME_IS_DIRTY | NS_FRAME_HAS_DIRTY_CHILDREN)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
f->AddStateBits(NS_FRAME_HAS_DIRTY_CHILDREN);
|
|
|
|
f = f->GetParent();
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(f->IsFrameOfType(nsIFrame::eSVG),
|
|
|
|
"NS_STATE_IS_OUTER_SVG check above not valid!");
|
2012-03-20 16:15:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
outerSVGFrame = static_cast<nsSVGOuterSVGFrame*>(f);
|
|
|
|
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(outerSVGFrame &&
|
|
|
|
outerSVGFrame->GetType() == nsGkAtoms::svgOuterSVGFrame,
|
|
|
|
"Did not find nsSVGOuterSVGFrame!");
|
2012-03-20 16:15:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (outerSVGFrame->GetStateBits() & NS_FRAME_IN_REFLOW) {
|
|
|
|
// We're currently under an nsSVGOuterSVGFrame::Reflow call so there is no
|
|
|
|
// need to call PresShell::FrameNeedsReflow, since we have an
|
|
|
|
// nsSVGOuterSVGFrame::DidReflow call pending.
|
2008-04-08 16:51:19 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-20 16:15:53 +04:00
|
|
|
nsFrameState dirtyBit =
|
|
|
|
(outerSVGFrame == aFrame ? NS_FRAME_IS_DIRTY : NS_FRAME_HAS_DIRTY_CHILDREN);
|
2008-04-08 16:51:19 +04:00
|
|
|
|
2012-03-20 16:15:53 +04:00
|
|
|
aFrame->PresContext()->PresShell()->FrameNeedsReflow(
|
|
|
|
outerSVGFrame, nsIPresShell::eResize, dirtyBit);
|
|
|
|
}
|
2012-02-04 17:58:46 +04:00
|
|
|
|
2012-03-20 16:15:53 +04:00
|
|
|
bool
|
2012-07-22 04:01:44 +04:00
|
|
|
nsSVGUtils::NeedsReflowSVG(nsIFrame *aFrame)
|
2012-03-20 16:15:53 +04:00
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aFrame->IsFrameOfType(nsIFrame::eSVG),
|
|
|
|
"SVG uses bits differently!");
|
2012-03-20 16:15:53 +04:00
|
|
|
|
|
|
|
// The flags we test here may change, hence why we have this separate
|
|
|
|
// function.
|
|
|
|
return NS_SUBTREE_DIRTY(aFrame);
|
2008-04-08 16:51:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-03-20 00:27:33 +03:00
|
|
|
nsSVGUtils::NotifyAncestorsOfFilterRegionChange(nsIFrame *aFrame)
|
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!(aFrame->GetStateBits() & NS_STATE_IS_OUTER_SVG),
|
|
|
|
"Not expecting to be called on the outer SVG Frame");
|
2008-04-15 12:31:06 +04:00
|
|
|
|
2008-03-20 00:27:33 +03:00
|
|
|
aFrame = aFrame->GetParent();
|
|
|
|
|
|
|
|
while (aFrame) {
|
|
|
|
if (aFrame->GetStateBits() & NS_STATE_IS_OUTER_SVG)
|
|
|
|
return;
|
|
|
|
|
2008-08-08 05:34:43 +04:00
|
|
|
nsSVGFilterProperty *property = nsSVGEffects::GetFilterProperty(aFrame);
|
2008-08-06 04:25:33 +04:00
|
|
|
if (property) {
|
2008-03-20 00:27:33 +03:00
|
|
|
property->Invalidate();
|
|
|
|
}
|
|
|
|
aFrame = aFrame->GetParent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-07 02:30:40 +04:00
|
|
|
float
|
2009-06-11 19:21:03 +04:00
|
|
|
nsSVGUtils::ObjectSpace(const gfxRect &aRect, const nsSVGLength2 *aLength)
|
2005-09-07 02:30:40 +04:00
|
|
|
{
|
2012-07-01 00:21:31 +04:00
|
|
|
float axis;
|
2005-09-07 02:30:40 +04:00
|
|
|
|
2006-04-14 19:09:39 +04:00
|
|
|
switch (aLength->GetCtxType()) {
|
2012-09-22 23:26:05 +04:00
|
|
|
case SVGContentUtils::X:
|
2009-06-11 19:21:03 +04:00
|
|
|
axis = aRect.Width();
|
2005-09-07 02:30:40 +04:00
|
|
|
break;
|
2012-09-22 23:26:05 +04:00
|
|
|
case SVGContentUtils::Y:
|
2009-06-11 19:21:03 +04:00
|
|
|
axis = aRect.Height();
|
2005-09-07 02:30:40 +04:00
|
|
|
break;
|
2012-09-22 23:26:05 +04:00
|
|
|
case SVGContentUtils::XY:
|
|
|
|
axis = float(SVGContentUtils::ComputeNormalizedHypotenuse(
|
|
|
|
aRect.Width(), aRect.Height()));
|
2009-12-13 09:27:30 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("unexpected ctx type");
|
|
|
|
axis = 0.0f;
|
|
|
|
break;
|
2005-09-07 02:30:40 +04:00
|
|
|
}
|
2008-01-25 12:27:03 +03:00
|
|
|
if (aLength->IsPercentage()) {
|
2012-07-01 00:21:31 +04:00
|
|
|
// Multiply first to avoid precision errors:
|
|
|
|
return axis * aLength->GetAnimValInSpecifiedUnits() / 100;
|
2009-12-13 09:27:30 +03:00
|
|
|
}
|
2013-01-10 03:02:45 +04:00
|
|
|
return aLength->GetAnimValue(static_cast<SVGSVGElement*>(nullptr)) * axis;
|
2005-09-07 02:30:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
float
|
2008-09-11 04:24:16 +04:00
|
|
|
nsSVGUtils::UserSpace(nsSVGElement *aSVGElement, const nsSVGLength2 *aLength)
|
2005-09-07 02:30:40 +04:00
|
|
|
{
|
2006-04-14 19:09:39 +04:00
|
|
|
return aLength->GetAnimValue(aSVGElement);
|
2005-09-07 02:30:40 +04:00
|
|
|
}
|
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
float
|
|
|
|
nsSVGUtils::UserSpace(nsIFrame *aNonSVGContext, const nsSVGLength2 *aLength)
|
|
|
|
{
|
|
|
|
return aLength->GetAnimValue(aNonSVGContext);
|
|
|
|
}
|
|
|
|
|
2014-09-15 14:12:50 +04:00
|
|
|
float
|
|
|
|
nsSVGUtils::UserSpace(const UserSpaceMetrics& aMetrics, const nsSVGLength2 *aLength)
|
|
|
|
{
|
|
|
|
return aLength->GetAnimValue(aMetrics);
|
|
|
|
}
|
|
|
|
|
2006-06-15 23:10:28 +04:00
|
|
|
nsSVGOuterSVGFrame *
|
2006-02-14 00:22:41 +03:00
|
|
|
nsSVGUtils::GetOuterSVGFrame(nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
while (aFrame) {
|
|
|
|
if (aFrame->GetStateBits() & NS_STATE_IS_OUTER_SVG) {
|
2007-07-08 11:08:04 +04:00
|
|
|
return static_cast<nsSVGOuterSVGFrame*>(aFrame);
|
2006-02-14 00:22:41 +03:00
|
|
|
}
|
|
|
|
aFrame = aFrame->GetParent();
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2006-02-14 00:22:41 +03:00
|
|
|
}
|
2006-02-26 20:58:58 +03:00
|
|
|
|
2007-05-31 02:32:54 +04:00
|
|
|
nsIFrame*
|
|
|
|
nsSVGUtils::GetOuterSVGFrameAndCoveredRegion(nsIFrame* aFrame, nsRect* aRect)
|
|
|
|
{
|
2009-01-12 22:20:59 +03:00
|
|
|
nsISVGChildFrame* svg = do_QueryFrame(aFrame);
|
2007-05-31 02:32:54 +04:00
|
|
|
if (!svg)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2014-07-06 16:55:43 +04:00
|
|
|
nsSVGOuterSVGFrame* outer = GetOuterSVGFrame(aFrame);
|
|
|
|
if (outer == svg) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-07-12 11:13:07 +04:00
|
|
|
*aRect = (aFrame->GetStateBits() & NS_FRAME_IS_NONDISPLAY) ?
|
2010-12-29 13:29:54 +03:00
|
|
|
nsRect(0, 0, 0, 0) : svg->GetCoveredRegion();
|
2014-07-06 16:55:43 +04:00
|
|
|
return outer;
|
2007-05-31 02:32:54 +04:00
|
|
|
}
|
|
|
|
|
2009-04-29 08:31:34 +04:00
|
|
|
gfxMatrix
|
2014-09-08 15:28:50 +04:00
|
|
|
nsSVGUtils::GetCanvasTM(nsIFrame *aFrame)
|
2006-03-21 18:49:20 +03:00
|
|
|
{
|
2009-04-29 08:31:34 +04:00
|
|
|
// XXX yuck, we really need a common interface for GetCanvasTM
|
|
|
|
|
|
|
|
if (!aFrame->IsFrameOfType(nsIFrame::eSVG)) {
|
2012-06-21 04:29:50 +04:00
|
|
|
return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(aFrame);
|
2009-04-29 08:31:34 +04:00
|
|
|
}
|
2008-09-11 04:24:16 +04:00
|
|
|
|
2009-03-04 15:55:28 +03:00
|
|
|
nsIAtom* type = aFrame->GetType();
|
2009-04-29 08:31:34 +04:00
|
|
|
if (type == nsGkAtoms::svgForeignObjectFrame) {
|
2014-09-08 15:28:50 +04:00
|
|
|
return static_cast<nsSVGForeignObjectFrame*>(aFrame)->GetCanvasTM();
|
2009-04-29 08:31:34 +04:00
|
|
|
}
|
2012-07-17 23:44:39 +04:00
|
|
|
if (type == nsGkAtoms::svgOuterSVGFrame) {
|
|
|
|
return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(aFrame);
|
|
|
|
}
|
2009-04-29 08:31:34 +04:00
|
|
|
|
|
|
|
nsSVGContainerFrame *containerFrame = do_QueryFrame(aFrame);
|
|
|
|
if (containerFrame) {
|
2014-09-08 15:28:50 +04:00
|
|
|
return containerFrame->GetCanvasTM();
|
2006-03-21 18:49:20 +03:00
|
|
|
}
|
|
|
|
|
2014-09-08 15:28:50 +04:00
|
|
|
return static_cast<nsSVGPathGeometryFrame*>(aFrame)->GetCanvasTM();
|
2006-03-21 18:49:20 +03:00
|
|
|
}
|
|
|
|
|
2012-06-26 14:49:23 +04:00
|
|
|
gfxMatrix
|
2014-09-08 15:28:50 +04:00
|
|
|
nsSVGUtils::GetUserToCanvasTM(nsIFrame *aFrame)
|
2012-06-26 14:49:23 +04:00
|
|
|
{
|
|
|
|
nsISVGChildFrame* svgFrame = do_QueryFrame(aFrame);
|
|
|
|
NS_ASSERTION(svgFrame, "bad frame");
|
|
|
|
|
2013-12-27 00:13:57 +04:00
|
|
|
gfxMatrix tm;
|
2012-06-26 14:49:23 +04:00
|
|
|
if (svgFrame) {
|
|
|
|
nsSVGElement *content = static_cast<nsSVGElement*>(aFrame->GetContent());
|
2012-06-30 15:20:46 +04:00
|
|
|
tm = content->PrependLocalTransformsTo(
|
2014-09-08 15:28:50 +04:00
|
|
|
GetCanvasTM(aFrame->GetParent()),
|
2012-06-30 15:20:46 +04:00
|
|
|
nsSVGElement::eUserSpaceToParent);
|
2012-06-26 14:49:23 +04:00
|
|
|
}
|
2013-12-27 00:13:57 +04:00
|
|
|
return tm;
|
2012-06-26 14:49:23 +04:00
|
|
|
}
|
|
|
|
|
2007-12-20 17:26:34 +03:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGUtils::NotifyChildrenOfSVGChange(nsIFrame *aFrame, uint32_t aFlags)
|
2007-12-20 17:26:34 +03:00
|
|
|
{
|
2011-08-25 00:54:30 +04:00
|
|
|
nsIFrame *kid = aFrame->GetFirstPrincipalChild();
|
2007-12-20 17:26:34 +03:00
|
|
|
|
2010-01-13 14:09:58 +03:00
|
|
|
while (kid) {
|
|
|
|
nsISVGChildFrame* SVGFrame = do_QueryFrame(kid);
|
2007-12-20 17:26:34 +03:00
|
|
|
if (SVGFrame) {
|
2008-01-25 12:27:03 +03:00
|
|
|
SVGFrame->NotifySVGChanged(aFlags);
|
2007-12-20 17:26:34 +03:00
|
|
|
} else {
|
2012-08-23 05:23:23 +04:00
|
|
|
NS_ASSERTION(kid->IsFrameOfType(nsIFrame::eSVG) || kid->IsSVGText(),
|
|
|
|
"SVG frame expected");
|
2007-12-20 17:26:34 +03:00
|
|
|
// recurse into the children of container frames e.g. <clipPath>, <mask>
|
|
|
|
// in case they have child frames with transformation matrices
|
2012-08-23 05:23:23 +04:00
|
|
|
if (kid->IsFrameOfType(nsIFrame::eSVG)) {
|
|
|
|
NotifyChildrenOfSVGChange(kid, aFlags);
|
|
|
|
}
|
2007-12-20 17:26:34 +03:00
|
|
|
}
|
2010-01-13 14:09:58 +03:00
|
|
|
kid = kid->GetNextSibling();
|
2007-12-20 17:26:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-21 18:49:20 +03:00
|
|
|
// ************************************************************
|
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
class SVGPaintCallback : public nsSVGFilterPaintCallback
|
|
|
|
{
|
|
|
|
public:
|
2014-10-31 23:08:54 +03:00
|
|
|
virtual void Paint(gfxContext& aContext, nsIFrame *aTarget,
|
2014-08-29 23:42:07 +04:00
|
|
|
const gfxMatrix& aTransform,
|
2015-03-21 19:28:04 +03:00
|
|
|
const nsIntRect* aDirtyRect) override
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
2009-01-12 22:20:59 +03:00
|
|
|
nsISVGChildFrame *svgChildFrame = do_QueryFrame(aTarget);
|
2008-09-11 04:24:16 +04:00
|
|
|
NS_ASSERTION(svgChildFrame, "Expected SVG frame here");
|
2008-10-16 11:55:10 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIntRect* dirtyRect = nullptr;
|
2008-10-16 11:55:10 +04:00
|
|
|
nsIntRect tmpDirtyRect;
|
|
|
|
|
|
|
|
// aDirtyRect is in user-space pixels, we need to convert to
|
|
|
|
// outer-SVG-frame-relative device pixels.
|
|
|
|
if (aDirtyRect) {
|
2014-08-29 23:42:07 +04:00
|
|
|
gfxMatrix userToDeviceSpace = aTransform;
|
2009-04-29 08:31:34 +04:00
|
|
|
if (userToDeviceSpace.IsSingular()) {
|
|
|
|
return;
|
|
|
|
}
|
2009-02-10 03:54:28 +03:00
|
|
|
gfxRect dirtyBounds = userToDeviceSpace.TransformBounds(
|
2008-10-16 11:55:10 +04:00
|
|
|
gfxRect(aDirtyRect->x, aDirtyRect->y, aDirtyRect->width, aDirtyRect->height));
|
|
|
|
dirtyBounds.RoundOut();
|
2010-11-24 12:35:21 +03:00
|
|
|
if (gfxUtils::GfxRectToIntRect(dirtyBounds, &tmpDirtyRect)) {
|
2008-10-16 11:55:10 +04:00
|
|
|
dirtyRect = &tmpDirtyRect;
|
|
|
|
}
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
2014-10-31 23:08:54 +03:00
|
|
|
svgChildFrame->PaintSVG(aContext, aTransform, dirtyRect);
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-03-21 18:49:20 +03:00
|
|
|
void
|
2014-08-29 23:42:07 +04:00
|
|
|
nsSVGUtils::PaintFrameWithEffects(nsIFrame *aFrame,
|
2014-10-31 23:08:53 +03:00
|
|
|
gfxContext& aContext,
|
2014-08-29 23:42:07 +04:00
|
|
|
const gfxMatrix& aTransform,
|
|
|
|
const nsIntRect *aDirtyRect)
|
2006-03-21 18:49:20 +03:00
|
|
|
{
|
2012-07-20 22:12:29 +04:00
|
|
|
NS_ASSERTION(!NS_SVGDisplayListPaintingEnabled() ||
|
2013-07-12 11:13:07 +04:00
|
|
|
(aFrame->GetStateBits() & NS_FRAME_IS_NONDISPLAY) ||
|
2012-09-06 08:58:47 +04:00
|
|
|
aFrame->PresContext()->IsGlyph(),
|
2012-07-20 22:12:29 +04:00
|
|
|
"If display lists are enabled, only painting of non-display "
|
|
|
|
"SVG should take this code path");
|
|
|
|
|
2009-01-12 22:20:59 +03:00
|
|
|
nsISVGChildFrame *svgChildFrame = do_QueryFrame(aFrame);
|
2006-03-21 18:49:20 +03:00
|
|
|
if (!svgChildFrame)
|
|
|
|
return;
|
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
float opacity = aFrame->StyleDisplay()->mOpacity;
|
2007-01-04 18:05:39 +03:00
|
|
|
if (opacity == 0.0f)
|
|
|
|
return;
|
2006-03-21 18:49:20 +03:00
|
|
|
|
2012-03-03 13:21:09 +04:00
|
|
|
const nsIContent* content = aFrame->GetContent();
|
2015-03-03 14:08:59 +03:00
|
|
|
if (content->IsSVGElement() &&
|
2012-03-03 13:21:09 +04:00
|
|
|
!static_cast<const nsSVGElement*>(content)->HasValidDimensions()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-18 15:21:24 +04:00
|
|
|
/* Properties are added lazily and may have been removed by a restyle,
|
|
|
|
so make sure all applicable ones are set again. */
|
|
|
|
|
|
|
|
nsSVGEffects::EffectProperties effectProperties =
|
|
|
|
nsSVGEffects::GetEffectProperties(aFrame);
|
|
|
|
|
2014-02-24 19:22:58 +04:00
|
|
|
bool isOK = effectProperties.HasNoFilterOrHasValidFilter();
|
2012-05-18 15:21:24 +04:00
|
|
|
|
2012-05-17 08:05:09 +04:00
|
|
|
if (aDirtyRect &&
|
2013-07-12 11:13:07 +04:00
|
|
|
!(aFrame->GetStateBits() & NS_FRAME_IS_NONDISPLAY)) {
|
2012-05-17 08:05:09 +04:00
|
|
|
// Here we convert aFrame's paint bounds to outer-<svg> device space,
|
|
|
|
// compare it to aDirtyRect, and return early if they don't intersect.
|
|
|
|
// We don't do this optimization for nondisplay SVG since nondisplay
|
|
|
|
// SVG doesn't maintain bounds/overflow rects.
|
|
|
|
nsRect overflowRect = aFrame->GetVisualOverflowRectRelativeToSelf();
|
2013-02-11 10:22:17 +04:00
|
|
|
if (aFrame->IsFrameOfType(nsIFrame::eSVGGeometry) ||
|
|
|
|
aFrame->IsSVGText()) {
|
2012-05-17 08:05:09 +04:00
|
|
|
// Unlike containers, leaf frames do not include GetPosition() in
|
|
|
|
// GetCanvasTM().
|
|
|
|
overflowRect = overflowRect + aFrame->GetPosition();
|
|
|
|
}
|
2013-02-20 01:46:27 +04:00
|
|
|
int32_t appUnitsPerDevPx = aFrame->PresContext()->AppUnitsPerDevPixel();
|
2014-08-29 23:42:07 +04:00
|
|
|
gfxMatrix tm = aTransform;
|
2012-05-17 08:05:09 +04:00
|
|
|
if (aFrame->IsFrameOfType(nsIFrame::eSVG | nsIFrame::eSVGContainer)) {
|
2013-12-30 03:35:53 +04:00
|
|
|
gfx::Matrix childrenOnlyTM;
|
2012-05-17 08:05:09 +04:00
|
|
|
if (static_cast<nsSVGContainerFrame*>(aFrame)->
|
|
|
|
HasChildrenOnlyTransform(&childrenOnlyTM)) {
|
|
|
|
// Undo the children-only transform:
|
2014-07-11 11:06:39 +04:00
|
|
|
if (!childrenOnlyTM.Invert()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
tm = ThebesMatrix(childrenOnlyTM) * tm;
|
2012-05-17 08:05:09 +04:00
|
|
|
}
|
|
|
|
}
|
2012-09-22 23:26:05 +04:00
|
|
|
nsIntRect bounds = TransformFrameRectToOuterSVG(overflowRect,
|
2012-05-17 08:05:09 +04:00
|
|
|
tm, aFrame->PresContext()).
|
|
|
|
ToOutsidePixels(appUnitsPerDevPx);
|
|
|
|
if (!aDirtyRect->Intersects(bounds)) {
|
|
|
|
return;
|
2006-06-30 23:19:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-21 18:49:20 +03:00
|
|
|
/* SVG defines the following rendering model:
|
|
|
|
*
|
2009-10-26 20:17:49 +03:00
|
|
|
* 1. Render fill
|
|
|
|
* 2. Render stroke
|
|
|
|
* 3. Render markers
|
|
|
|
* 4. Apply filter
|
|
|
|
* 5. Apply clipping, masking, group opacity
|
2006-03-21 18:49:20 +03:00
|
|
|
*
|
2007-04-26 12:36:16 +04:00
|
|
|
* We follow this, but perform a couple of optimizations:
|
2006-03-21 18:49:20 +03:00
|
|
|
*
|
|
|
|
* + Use cairo's clipPath when representable natively (single object
|
|
|
|
* clip region).
|
|
|
|
*
|
|
|
|
* + Merge opacity and masking if both used together.
|
|
|
|
*/
|
|
|
|
|
2007-04-26 12:36:16 +04:00
|
|
|
if (opacity != 1.0f && CanOptimizeOpacity(aFrame))
|
|
|
|
opacity = 1.0f;
|
2007-01-04 18:05:39 +03:00
|
|
|
|
2014-10-31 23:08:53 +03:00
|
|
|
DrawTarget* drawTarget = aContext.GetDrawTarget();
|
2011-09-29 10:19:26 +04:00
|
|
|
bool complexEffects = false;
|
2006-03-21 18:49:20 +03:00
|
|
|
|
2008-10-01 04:51:05 +04:00
|
|
|
nsSVGClipPathFrame *clipPathFrame = effectProperties.GetClipPathFrame(&isOK);
|
|
|
|
nsSVGMaskFrame *maskFrame = effectProperties.GetMaskFrame(&isOK);
|
2007-04-26 12:36:16 +04:00
|
|
|
|
2012-05-18 15:21:24 +04:00
|
|
|
bool isTrivialClip = clipPathFrame ? clipPathFrame->IsTrivial() : true;
|
|
|
|
|
2008-08-06 04:25:33 +04:00
|
|
|
if (!isOK) {
|
2010-12-19 20:47:01 +03:00
|
|
|
// Some resource is invalid. We shouldn't paint anything.
|
2008-08-06 04:25:33 +04:00
|
|
|
return;
|
|
|
|
}
|
2007-04-26 12:36:16 +04:00
|
|
|
|
2006-03-21 18:49:20 +03:00
|
|
|
/* Check if we need to do additional operations on this child's
|
|
|
|
* rendering, which necessitates rendering into another surface. */
|
2013-09-15 07:40:11 +04:00
|
|
|
if (opacity != 1.0f || maskFrame || (clipPathFrame && !isTrivialClip)
|
|
|
|
|| aFrame->StyleDisplay()->mMixBlendMode != NS_STYLE_BLEND_NORMAL) {
|
2011-10-17 18:59:28 +04:00
|
|
|
complexEffects = true;
|
2014-10-31 23:08:53 +03:00
|
|
|
aContext.Save();
|
2013-07-12 11:13:07 +04:00
|
|
|
if (!(aFrame->GetStateBits() & NS_FRAME_IS_NONDISPLAY)) {
|
2012-06-20 13:02:43 +04:00
|
|
|
// aFrame has a valid visual overflow rect, so clip to it before calling
|
|
|
|
// PushGroup() to minimize the size of the surfaces we'll composite:
|
2014-10-31 23:08:53 +03:00
|
|
|
gfxContextMatrixAutoSaveRestore matrixAutoSaveRestore(&aContext);
|
|
|
|
aContext.Multiply(aTransform);
|
2012-06-20 13:02:43 +04:00
|
|
|
nsRect overflowRect = aFrame->GetVisualOverflowRectRelativeToSelf();
|
2013-02-11 10:22:17 +04:00
|
|
|
if (aFrame->IsFrameOfType(nsIFrame::eSVGGeometry) ||
|
|
|
|
aFrame->IsSVGText()) {
|
2012-06-20 13:02:43 +04:00
|
|
|
// Unlike containers, leaf frames do not include GetPosition() in
|
|
|
|
// GetCanvasTM().
|
|
|
|
overflowRect = overflowRect + aFrame->GetPosition();
|
|
|
|
}
|
2014-10-31 23:08:53 +03:00
|
|
|
aContext.Clip(NSRectToSnappedRect(overflowRect,
|
|
|
|
aFrame->PresContext()->AppUnitsPerDevPixel(),
|
|
|
|
*drawTarget));
|
2012-06-20 13:02:43 +04:00
|
|
|
}
|
2014-10-31 23:08:53 +03:00
|
|
|
aContext.PushGroup(gfxContentType::COLOR_ALPHA);
|
2006-03-21 18:49:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If this frame has only a trivial clipPath, set up cairo's clipping now so
|
|
|
|
* we can just do normal painting and get it clipped appropriately.
|
|
|
|
*/
|
2007-04-26 12:36:16 +04:00
|
|
|
if (clipPathFrame && isTrivialClip) {
|
2014-10-31 23:08:53 +03:00
|
|
|
aContext.Save();
|
|
|
|
clipPathFrame->ApplyClipOrPaintClipMask(aContext, aFrame, aTransform);
|
2006-03-21 18:49:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Paint the child */
|
2014-02-24 19:22:58 +04:00
|
|
|
if (effectProperties.HasValidFilter()) {
|
2014-04-24 12:25:17 +04:00
|
|
|
nsRegion* dirtyRegion = nullptr;
|
|
|
|
nsRegion tmpDirtyRegion;
|
2012-06-26 14:49:23 +04:00
|
|
|
if (aDirtyRect) {
|
|
|
|
// aDirtyRect is in outer-<svg> device pixels, but the filter code needs
|
|
|
|
// it in frame space.
|
2014-09-08 15:28:50 +04:00
|
|
|
gfxMatrix userToDeviceSpace = GetUserToCanvasTM(aFrame);
|
2012-06-26 14:49:23 +04:00
|
|
|
if (userToDeviceSpace.IsSingular()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gfxMatrix deviceToUserSpace = userToDeviceSpace;
|
|
|
|
deviceToUserSpace.Invert();
|
|
|
|
gfxRect dirtyBounds = deviceToUserSpace.TransformBounds(
|
|
|
|
gfxRect(aDirtyRect->x, aDirtyRect->y,
|
|
|
|
aDirtyRect->width, aDirtyRect->height));
|
2014-04-24 12:25:17 +04:00
|
|
|
tmpDirtyRegion =
|
2012-06-26 14:49:23 +04:00
|
|
|
nsLayoutUtils::RoundGfxRectToAppRect(
|
|
|
|
dirtyBounds, aFrame->PresContext()->AppUnitsPerCSSPixel()) -
|
|
|
|
aFrame->GetPosition();
|
2014-04-24 12:25:17 +04:00
|
|
|
dirtyRegion = &tmpDirtyRegion;
|
2012-06-26 14:49:23 +04:00
|
|
|
}
|
2008-09-11 04:24:16 +04:00
|
|
|
SVGPaintCallback paintCallback;
|
2014-10-31 23:08:54 +03:00
|
|
|
nsFilterInstance::PaintFilteredFrame(aFrame, aContext, aTransform,
|
2014-08-29 23:42:07 +04:00
|
|
|
&paintCallback, dirtyRegion);
|
2006-03-21 18:49:20 +03:00
|
|
|
} else {
|
2014-10-31 23:08:54 +03:00
|
|
|
svgChildFrame->PaintSVG(aContext, aTransform, aDirtyRect);
|
2006-03-21 18:49:20 +03:00
|
|
|
}
|
2006-09-28 19:08:41 +04:00
|
|
|
|
2007-04-26 12:36:16 +04:00
|
|
|
if (clipPathFrame && isTrivialClip) {
|
2014-10-31 23:08:53 +03:00
|
|
|
aContext.Restore();
|
2006-03-21 18:49:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* No more effects, we're done. */
|
2007-05-22 23:31:04 +04:00
|
|
|
if (!complexEffects)
|
2006-03-21 18:49:20 +03:00
|
|
|
return;
|
|
|
|
|
2014-10-31 23:08:53 +03:00
|
|
|
aContext.PopGroupToSource();
|
2006-03-21 18:49:20 +03:00
|
|
|
|
2014-09-12 11:20:12 +04:00
|
|
|
Matrix maskTransform;
|
|
|
|
RefPtr<SourceSurface> maskSurface =
|
2014-10-31 23:08:53 +03:00
|
|
|
maskFrame ? maskFrame->GetMaskForMaskedFrame(&aContext,
|
2014-09-12 11:20:12 +04:00
|
|
|
aFrame, aTransform, opacity, &maskTransform)
|
2014-06-23 08:45:31 +04:00
|
|
|
: nullptr;
|
2007-04-26 12:36:16 +04:00
|
|
|
|
|
|
|
if (clipPathFrame && !isTrivialClip) {
|
2014-10-31 23:08:53 +03:00
|
|
|
aContext.PushGroup(gfxContentType::COLOR_ALPHA);
|
2007-04-26 12:36:16 +04:00
|
|
|
|
2014-10-31 23:08:53 +03:00
|
|
|
nsresult rv = clipPathFrame->ApplyClipOrPaintClipMask(aContext, aFrame, aTransform);
|
2014-09-12 11:20:12 +04:00
|
|
|
Matrix clippedMaskTransform;
|
2014-10-31 23:08:53 +03:00
|
|
|
RefPtr<SourceSurface> clipMaskSurface = aContext.PopGroupToSurface(&clippedMaskTransform);
|
2007-04-26 12:36:16 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && clipMaskSurface) {
|
|
|
|
// Still more set after clipping, so clip to another surface
|
|
|
|
if (maskSurface || opacity != 1.0f) {
|
2014-10-31 23:08:53 +03:00
|
|
|
aContext.PushGroup(gfxContentType::COLOR_ALPHA);
|
|
|
|
aContext.Mask(clipMaskSurface, clippedMaskTransform);
|
|
|
|
aContext.PopGroupToSource();
|
2007-04-26 12:36:16 +04:00
|
|
|
} else {
|
2014-10-31 23:08:53 +03:00
|
|
|
aContext.Mask(clipMaskSurface, clippedMaskTransform);
|
2007-04-26 12:36:16 +04:00
|
|
|
}
|
2006-03-21 18:49:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-28 19:08:41 +04:00
|
|
|
if (maskSurface) {
|
2014-10-31 23:08:53 +03:00
|
|
|
aContext.Mask(maskSurface, maskTransform);
|
2014-10-17 22:37:54 +04:00
|
|
|
} else if (opacity != 1.0f ||
|
|
|
|
aFrame->StyleDisplay()->mMixBlendMode != NS_STYLE_BLEND_NORMAL) {
|
2014-10-31 23:08:53 +03:00
|
|
|
aContext.Paint(opacity);
|
2006-03-21 18:49:20 +03:00
|
|
|
}
|
|
|
|
|
2014-10-31 23:08:53 +03:00
|
|
|
aContext.Restore();
|
2006-03-21 18:49:20 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2014-08-07 11:09:31 +04:00
|
|
|
nsSVGUtils::HitTestClip(nsIFrame *aFrame, const gfxPoint &aPoint)
|
2006-03-21 18:49:20 +03:00
|
|
|
{
|
2008-08-08 05:34:43 +04:00
|
|
|
nsSVGEffects::EffectProperties props =
|
|
|
|
nsSVGEffects::GetEffectProperties(aFrame);
|
2008-08-06 04:25:33 +04:00
|
|
|
if (!props.mClipPath)
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2007-04-26 12:36:16 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isOK = true;
|
2010-03-02 12:31:07 +03:00
|
|
|
nsSVGClipPathFrame *clipPathFrame = props.GetClipPathFrame(&isOK);
|
2014-02-27 00:40:07 +04:00
|
|
|
if (!isOK) {
|
2008-08-06 04:25:33 +04:00
|
|
|
// clipPath is not a valid resource, so nothing gets painted, so
|
|
|
|
// hit-testing must fail.
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-03-21 18:49:20 +03:00
|
|
|
}
|
2014-02-27 00:40:07 +04:00
|
|
|
if (!clipPathFrame) {
|
|
|
|
// clipPath doesn't exist, ignore it.
|
|
|
|
return true;
|
|
|
|
}
|
2006-03-21 18:49:20 +03:00
|
|
|
|
2014-08-07 11:09:31 +04:00
|
|
|
return clipPathFrame->PointIsInsideClipPath(aFrame, aPoint);
|
2006-03-21 18:49:20 +03:00
|
|
|
}
|
|
|
|
|
2008-08-25 13:23:54 +04:00
|
|
|
nsIFrame *
|
2014-08-07 11:09:31 +04:00
|
|
|
nsSVGUtils::HitTestChildren(nsSVGDisplayContainerFrame* aFrame,
|
|
|
|
const gfxPoint& aPoint)
|
2006-03-21 18:49:20 +03:00
|
|
|
{
|
2014-08-07 11:09:31 +04:00
|
|
|
// First we transform aPoint into the coordinate space established by aFrame
|
|
|
|
// for its children (e.g. take account of any 'viewBox' attribute):
|
|
|
|
gfxPoint point = aPoint;
|
2015-03-03 14:08:59 +03:00
|
|
|
if (aFrame->GetContent()->IsSVGElement()) { // must check before cast
|
2014-08-07 11:09:31 +04:00
|
|
|
gfxMatrix m = static_cast<const nsSVGElement*>(aFrame->GetContent())->
|
|
|
|
PrependLocalTransformsTo(gfxMatrix(),
|
|
|
|
nsSVGElement::eChildToUserSpace);
|
|
|
|
if (!m.IsIdentity()) {
|
|
|
|
if (!m.Invert()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
point = m.Transform(point);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-02 20:31:45 +04:00
|
|
|
// Traverse the list in reverse order, so that if we get a hit we know that's
|
|
|
|
// the topmost frame that intersects the point; then we can just return it.
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIFrame* result = nullptr;
|
2011-08-25 00:54:30 +04:00
|
|
|
for (nsIFrame* current = aFrame->PrincipalChildList().LastChild();
|
2009-10-02 20:31:45 +04:00
|
|
|
current;
|
|
|
|
current = current->GetPrevSibling()) {
|
2009-01-12 22:20:59 +03:00
|
|
|
nsISVGChildFrame* SVGFrame = do_QueryFrame(current);
|
2006-03-21 18:49:20 +03:00
|
|
|
if (SVGFrame) {
|
2012-03-07 14:50:36 +04:00
|
|
|
const nsIContent* content = current->GetContent();
|
2015-03-03 14:08:59 +03:00
|
|
|
if (content->IsSVGElement() &&
|
2012-03-07 14:50:36 +04:00
|
|
|
!static_cast<const nsSVGElement*>(content)->HasValidDimensions()) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-08-07 11:09:31 +04:00
|
|
|
// GetFrameForPoint() expects a point in its frame's SVG user space, so
|
|
|
|
// we need to convert to that space:
|
|
|
|
gfxPoint p = point;
|
2015-03-03 14:08:59 +03:00
|
|
|
if (content->IsSVGElement()) { // must check before cast
|
2014-08-07 11:09:31 +04:00
|
|
|
gfxMatrix m = static_cast<const nsSVGElement*>(content)->
|
|
|
|
PrependLocalTransformsTo(gfxMatrix(),
|
|
|
|
nsSVGElement::eUserSpaceToParent);
|
|
|
|
if (!m.IsIdentity()) {
|
|
|
|
if (!m.Invert()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
p = m.Transform(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = SVGFrame->GetFrameForPoint(p);
|
2012-03-03 13:21:09 +04:00
|
|
|
if (result)
|
|
|
|
break;
|
2006-03-21 18:49:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-25 13:23:54 +04:00
|
|
|
if (result && !HitTestClip(aFrame, aPoint))
|
2012-07-30 18:20:58 +04:00
|
|
|
result = nullptr;
|
2008-08-25 13:23:54 +04:00
|
|
|
|
|
|
|
return result;
|
2006-03-21 18:49:20 +03:00
|
|
|
}
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2006-06-09 22:08:33 +04:00
|
|
|
nsRect
|
2006-05-12 01:24:59 +04:00
|
|
|
nsSVGUtils::GetCoveredRegion(const nsFrameList &aFrames)
|
|
|
|
{
|
2006-06-09 22:08:33 +04:00
|
|
|
nsRect rect;
|
|
|
|
|
2006-05-12 01:24:59 +04:00
|
|
|
for (nsIFrame* kid = aFrames.FirstChild();
|
|
|
|
kid;
|
|
|
|
kid = kid->GetNextSibling()) {
|
2009-01-12 22:20:59 +03:00
|
|
|
nsISVGChildFrame* child = do_QueryFrame(kid);
|
2006-05-12 01:24:59 +04:00
|
|
|
if (child) {
|
2006-06-09 22:08:33 +04:00
|
|
|
nsRect childRect = child->GetCoveredRegion();
|
|
|
|
rect.UnionRect(rect, childRect);
|
2006-05-12 01:24:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-09 22:08:33 +04:00
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2012-02-10 16:33:46 +04:00
|
|
|
nsRect
|
|
|
|
nsSVGUtils::TransformFrameRectToOuterSVG(const nsRect& aRect,
|
|
|
|
const gfxMatrix& aMatrix,
|
|
|
|
nsPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
gfxRect r(aRect.x, aRect.y, aRect.width, aRect.height);
|
|
|
|
r.Scale(1.0 / nsPresContext::AppUnitsPerCSSPixel());
|
|
|
|
return nsLayoutUtils::RoundGfxRectToAppRect(
|
|
|
|
aMatrix.TransformBounds(r), aPresContext->AppUnitsPerDevPixel());
|
|
|
|
}
|
|
|
|
|
2011-04-21 23:36:46 +04:00
|
|
|
gfxIntSize
|
|
|
|
nsSVGUtils::ConvertToSurfaceSize(const gfxSize& aSize,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool *aResultOverflows)
|
2011-04-21 23:36:46 +04:00
|
|
|
{
|
2011-10-26 12:52:11 +04:00
|
|
|
gfxIntSize surfaceSize(ClampToInt(ceil(aSize.width)), ClampToInt(ceil(aSize.height)));
|
2011-04-21 23:36:46 +04:00
|
|
|
|
2011-10-26 12:52:11 +04:00
|
|
|
*aResultOverflows = surfaceSize.width != ceil(aSize.width) ||
|
|
|
|
surfaceSize.height != ceil(aSize.height);
|
2011-04-21 23:36:46 +04:00
|
|
|
|
|
|
|
if (!gfxASurface::CheckSurfaceSize(surfaceSize)) {
|
2013-01-15 16:22:03 +04:00
|
|
|
surfaceSize.width = std::min(NS_SVG_OFFSCREEN_MAX_DIMENSION,
|
2011-04-21 23:36:46 +04:00
|
|
|
surfaceSize.width);
|
2013-01-15 16:22:03 +04:00
|
|
|
surfaceSize.height = std::min(NS_SVG_OFFSCREEN_MAX_DIMENSION,
|
2011-04-21 23:36:46 +04:00
|
|
|
surfaceSize.height);
|
2011-10-17 18:59:28 +04:00
|
|
|
*aResultOverflows = true;
|
2011-04-21 23:36:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return surfaceSize;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2013-12-31 01:42:26 +04:00
|
|
|
nsSVGUtils::HitTestRect(const gfx::Matrix &aMatrix,
|
2006-09-19 20:35:29 +04:00
|
|
|
float aRX, float aRY, float aRWidth, float aRHeight,
|
|
|
|
float aX, float aY)
|
|
|
|
{
|
2013-12-31 01:42:26 +04:00
|
|
|
gfx::Rect rect(aRX, aRY, aRWidth, aRHeight);
|
2012-06-15 07:02:27 +04:00
|
|
|
if (rect.IsEmpty() || aMatrix.IsSingular()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-09-19 20:35:29 +04:00
|
|
|
}
|
2013-12-31 01:42:26 +04:00
|
|
|
gfx::Matrix toRectSpace = aMatrix;
|
2012-06-15 07:02:27 +04:00
|
|
|
toRectSpace.Invert();
|
2013-12-31 01:42:26 +04:00
|
|
|
gfx::Point p = toRectSpace * gfx::Point(aX, aY);
|
2012-06-15 07:02:27 +04:00
|
|
|
return rect.x <= p.x && p.x <= rect.XMost() &&
|
|
|
|
rect.y <= p.y && p.y <= rect.YMost();
|
2006-09-19 20:35:29 +04:00
|
|
|
}
|
2006-09-27 02:27:56 +04:00
|
|
|
|
2009-06-18 00:51:40 +04:00
|
|
|
gfxRect
|
|
|
|
nsSVGUtils::GetClipRectForFrame(nsIFrame *aFrame,
|
|
|
|
float aX, float aY, float aWidth, float aHeight)
|
|
|
|
{
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleDisplay* disp = aFrame->StyleDisplay();
|
2009-06-18 00:51:40 +04:00
|
|
|
|
2015-03-20 07:12:17 +03:00
|
|
|
if (!(disp->mClipFlags & NS_STYLE_CLIP_RECT)) {
|
|
|
|
NS_ASSERTION(disp->mClipFlags == NS_STYLE_CLIP_AUTO,
|
2009-06-18 00:51:40 +04:00
|
|
|
"We don't know about this type of clip.");
|
|
|
|
return gfxRect(aX, aY, aWidth, aHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (disp->mOverflowX == NS_STYLE_OVERFLOW_HIDDEN ||
|
|
|
|
disp->mOverflowY == NS_STYLE_OVERFLOW_HIDDEN) {
|
|
|
|
|
|
|
|
nsIntRect clipPxRect =
|
2015-03-20 07:12:17 +03:00
|
|
|
disp->mClip.ToOutsidePixels(aFrame->PresContext()->AppUnitsPerDevPixel());
|
2009-06-18 00:51:40 +04:00
|
|
|
gfxRect clipRect =
|
|
|
|
gfxRect(clipPxRect.x, clipPxRect.y, clipPxRect.width, clipPxRect.height);
|
|
|
|
|
2015-03-20 07:12:17 +03:00
|
|
|
if (NS_STYLE_CLIP_RIGHT_AUTO & disp->mClipFlags) {
|
2011-04-19 07:07:21 +04:00
|
|
|
clipRect.width = aWidth - clipRect.X();
|
2009-06-18 00:51:40 +04:00
|
|
|
}
|
2015-03-20 07:12:17 +03:00
|
|
|
if (NS_STYLE_CLIP_BOTTOM_AUTO & disp->mClipFlags) {
|
2011-04-19 07:07:21 +04:00
|
|
|
clipRect.height = aHeight - clipRect.Y();
|
2009-06-18 00:51:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (disp->mOverflowX != NS_STYLE_OVERFLOW_HIDDEN) {
|
2011-04-19 07:07:21 +04:00
|
|
|
clipRect.x = aX;
|
|
|
|
clipRect.width = aWidth;
|
2009-06-18 00:51:40 +04:00
|
|
|
}
|
|
|
|
if (disp->mOverflowY != NS_STYLE_OVERFLOW_HIDDEN) {
|
2011-04-19 07:07:21 +04:00
|
|
|
clipRect.y = aY;
|
|
|
|
clipRect.height = aHeight;
|
2009-06-18 00:51:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return clipRect;
|
|
|
|
}
|
|
|
|
return gfxRect(aX, aY, aWidth, aHeight);
|
|
|
|
}
|
|
|
|
|
2006-11-27 20:30:57 +03:00
|
|
|
void
|
|
|
|
nsSVGUtils::SetClipRect(gfxContext *aContext,
|
2009-06-18 15:31:25 +04:00
|
|
|
const gfxMatrix &aCTM,
|
2009-06-18 00:51:40 +04:00
|
|
|
const gfxRect &aRect)
|
2006-11-27 20:30:57 +03:00
|
|
|
{
|
2009-06-18 15:31:25 +04:00
|
|
|
if (aCTM.IsSingular())
|
2006-11-27 20:30:57 +03:00
|
|
|
return;
|
|
|
|
|
2012-06-15 07:02:27 +04:00
|
|
|
gfxContextMatrixAutoSaveRestore matrixAutoSaveRestore(aContext);
|
2009-06-18 15:31:25 +04:00
|
|
|
aContext->Multiply(aCTM);
|
2009-06-18 00:51:40 +04:00
|
|
|
aContext->Clip(aRect);
|
2006-11-27 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
2009-06-11 19:21:03 +04:00
|
|
|
gfxRect
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGUtils::GetBBox(nsIFrame *aFrame, uint32_t aFlags)
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
2010-08-07 13:38:11 +04:00
|
|
|
if (aFrame->GetContent()->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
aFrame = aFrame->GetParent();
|
|
|
|
}
|
2009-06-11 19:21:03 +04:00
|
|
|
gfxRect bbox;
|
2009-01-12 22:20:59 +03:00
|
|
|
nsISVGChildFrame *svg = do_QueryFrame(aFrame);
|
2012-08-10 15:13:44 +04:00
|
|
|
if (svg || aFrame->IsSVGText()) {
|
2010-08-07 13:38:11 +04:00
|
|
|
// It is possible to apply a gradient, pattern, clipping path, mask or
|
|
|
|
// filter to text. When one of these facilities is applied to text
|
2011-05-25 10:31:59 +04:00
|
|
|
// the bounding box is the entire text element in all
|
2010-08-07 13:38:11 +04:00
|
|
|
// cases.
|
2013-02-11 10:22:18 +04:00
|
|
|
if (aFrame->IsSVGText()) {
|
2012-08-10 15:13:44 +04:00
|
|
|
nsIFrame* ancestor = GetFirstNonAAncestorFrame(aFrame);
|
|
|
|
if (ancestor && ancestor->IsSVGText()) {
|
2013-12-20 20:38:51 +04:00
|
|
|
while (ancestor->GetType() != nsGkAtoms::svgTextFrame) {
|
2012-08-10 15:13:44 +04:00
|
|
|
ancestor = ancestor->GetParent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
svg = do_QueryFrame(ancestor);
|
2010-08-07 13:38:11 +04:00
|
|
|
}
|
2012-03-03 13:21:09 +04:00
|
|
|
nsIContent* content = aFrame->GetContent();
|
2015-03-03 14:08:59 +03:00
|
|
|
if (content->IsSVGElement() &&
|
2012-03-03 13:21:09 +04:00
|
|
|
!static_cast<const nsSVGElement*>(content)->HasValidDimensions()) {
|
|
|
|
return bbox;
|
|
|
|
}
|
2015-04-27 13:15:36 +03:00
|
|
|
|
|
|
|
FrameProperties props = aFrame->Properties();
|
|
|
|
|
|
|
|
if (aFlags == eBBoxIncludeFillGeometry) {
|
|
|
|
gfxRect* prop =
|
|
|
|
static_cast<gfxRect*>(props.Get(ObjectBoundingBoxProperty()));
|
|
|
|
if (prop) {
|
|
|
|
return *prop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-27 00:13:57 +04:00
|
|
|
gfxMatrix matrix;
|
2014-05-13 05:24:35 +04:00
|
|
|
if (aFrame->GetType() == nsGkAtoms::svgForeignObjectFrame ||
|
|
|
|
aFrame->GetType() == nsGkAtoms::svgUseFrame) {
|
2012-02-17 12:12:47 +04:00
|
|
|
// The spec says getBBox "Returns the tight bounding box in *current user
|
|
|
|
// space*". So we should really be doing this for all elements, but that
|
|
|
|
// needs investigation to check that we won't break too much content.
|
2014-04-23 13:47:42 +04:00
|
|
|
// NOTE: When changing this to apply to other frame types, make sure to
|
|
|
|
// also update nsSVGUtils::FrameSpaceInCSSPxToUserSpaceOffset.
|
2015-03-03 14:08:59 +03:00
|
|
|
MOZ_ASSERT(content->IsSVGElement(), "bad cast");
|
2012-03-03 13:21:09 +04:00
|
|
|
nsSVGElement *element = static_cast<nsSVGElement*>(content);
|
2012-02-17 12:12:47 +04:00
|
|
|
matrix = element->PrependLocalTransformsTo(matrix,
|
|
|
|
nsSVGElement::eChildToUserSpace);
|
|
|
|
}
|
2014-05-13 05:24:35 +04:00
|
|
|
bbox = svg->GetBBoxContribution(ToMatrix(matrix), aFlags).ToThebesRect();
|
|
|
|
// Account for 'clipped'.
|
|
|
|
if (aFlags & nsSVGUtils::eBBoxIncludeClipped) {
|
|
|
|
gfxRect clipRect(0, 0, 0, 0);
|
|
|
|
float x, y, width, height;
|
|
|
|
gfxMatrix tm;
|
|
|
|
gfxRect fillBBox =
|
|
|
|
svg->GetBBoxContribution(ToMatrix(tm),
|
|
|
|
nsSVGUtils::eBBoxIncludeFill).ToThebesRect();
|
|
|
|
x = fillBBox.x;
|
|
|
|
y = fillBBox.y;
|
|
|
|
width = fillBBox.width;
|
|
|
|
height = fillBBox.height;
|
|
|
|
bool hasClip = aFrame->StyleDisplay()->IsScrollableOverflow();
|
|
|
|
if (hasClip) {
|
|
|
|
clipRect =
|
|
|
|
nsSVGUtils::GetClipRectForFrame(aFrame, x, y, width, height);
|
|
|
|
if (aFrame->GetType() == nsGkAtoms::svgForeignObjectFrame ||
|
|
|
|
aFrame->GetType() == nsGkAtoms::svgUseFrame) {
|
|
|
|
clipRect = matrix.TransformBounds(clipRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nsSVGEffects::EffectProperties effectProperties =
|
|
|
|
nsSVGEffects::GetEffectProperties(aFrame);
|
|
|
|
bool isOK = true;
|
|
|
|
nsSVGClipPathFrame *clipPathFrame =
|
|
|
|
effectProperties.GetClipPathFrame(&isOK);
|
|
|
|
if (clipPathFrame && isOK) {
|
|
|
|
SVGClipPathElement *clipContent =
|
|
|
|
static_cast<SVGClipPathElement*>(clipPathFrame->GetContent());
|
|
|
|
nsRefPtr<SVGAnimatedEnumeration> units = clipContent->ClipPathUnits();
|
|
|
|
if (units->AnimVal() == SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
|
2014-09-10 17:26:12 +04:00
|
|
|
matrix.Translate(gfxPoint(x, y));
|
|
|
|
matrix.Scale(width, height);
|
2014-05-13 05:24:35 +04:00
|
|
|
} else if (aFrame->GetType() == nsGkAtoms::svgForeignObjectFrame) {
|
|
|
|
matrix.Reset();
|
|
|
|
}
|
|
|
|
bbox =
|
|
|
|
clipPathFrame->GetBBoxForClipPathFrame(bbox, matrix).ToThebesRect();
|
|
|
|
if (hasClip) {
|
|
|
|
bbox = bbox.Intersect(clipRect);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!isOK) {
|
|
|
|
bbox = gfxRect(0, 0, 0, 0);
|
|
|
|
} else {
|
|
|
|
if (hasClip) {
|
|
|
|
bbox = bbox.Intersect(clipRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bbox.IsEmpty()) {
|
|
|
|
bbox = gfxRect(0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
2015-04-27 13:15:36 +03:00
|
|
|
|
|
|
|
if (aFlags == eBBoxIncludeFillGeometry) {
|
|
|
|
// Obtaining the bbox for objectBoundingBox calculations is common so we
|
|
|
|
// cache the result for future calls, since calculation can be expensive:
|
|
|
|
props.Set(ObjectBoundingBoxProperty(), new gfxRect(bbox));
|
|
|
|
}
|
|
|
|
|
2014-05-13 05:24:35 +04:00
|
|
|
return bbox;
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
2012-04-16 12:23:48 +04:00
|
|
|
return nsSVGIntegrationUtils::GetSVGBBoxForNonSVGFrame(aFrame);
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
2014-04-23 13:47:42 +04:00
|
|
|
gfxPoint
|
|
|
|
nsSVGUtils::FrameSpaceInCSSPxToUserSpaceOffset(nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
if (!(aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT)) {
|
|
|
|
// The user space for non-SVG frames is defined as the bounding box of the
|
|
|
|
// frame's border-box rects over all continuations.
|
|
|
|
return gfxPoint();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Leaf frames apply their own offset inside their user space.
|
|
|
|
if (aFrame->IsFrameOfType(nsIFrame::eSVGGeometry) ||
|
|
|
|
aFrame->IsSVGText()) {
|
|
|
|
return nsLayoutUtils::RectToGfxRect(aFrame->GetRect(),
|
|
|
|
nsPresContext::AppUnitsPerCSSPixel()).TopLeft();
|
|
|
|
}
|
|
|
|
|
|
|
|
// For foreignObject frames, nsSVGUtils::GetBBox applies their local
|
|
|
|
// transform, so we need to do the same here.
|
2014-05-13 05:24:35 +04:00
|
|
|
if (aFrame->GetType() == nsGkAtoms::svgForeignObjectFrame ||
|
|
|
|
aFrame->GetType() == nsGkAtoms::svgUseFrame) {
|
2014-04-23 13:47:42 +04:00
|
|
|
gfxMatrix transform = static_cast<nsSVGElement*>(aFrame->GetContent())->
|
|
|
|
PrependLocalTransformsTo(gfxMatrix(),
|
|
|
|
nsSVGElement::eChildToUserSpace);
|
|
|
|
NS_ASSERTION(!transform.HasNonTranslation(), "we're relying on this being an offset-only transform");
|
|
|
|
return transform.GetTranslation();
|
|
|
|
}
|
|
|
|
|
|
|
|
return gfxPoint();
|
|
|
|
}
|
|
|
|
|
2014-09-15 14:12:50 +04:00
|
|
|
static gfxRect
|
|
|
|
GetBoundingBoxRelativeRect(const nsSVGLength2 *aXYWH,
|
|
|
|
const gfxRect& aBBox)
|
|
|
|
{
|
|
|
|
return gfxRect(aBBox.x + nsSVGUtils::ObjectSpace(aBBox, &aXYWH[0]),
|
|
|
|
aBBox.y + nsSVGUtils::ObjectSpace(aBBox, &aXYWH[1]),
|
|
|
|
nsSVGUtils::ObjectSpace(aBBox, &aXYWH[2]),
|
|
|
|
nsSVGUtils::ObjectSpace(aBBox, &aXYWH[3]));
|
|
|
|
}
|
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
gfxRect
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGUtils::GetRelativeRect(uint16_t aUnits, const nsSVGLength2 *aXYWH,
|
2014-09-15 14:12:50 +04:00
|
|
|
const gfxRect& aBBox,
|
|
|
|
const UserSpaceMetrics& aMetrics)
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
2013-02-18 06:14:02 +04:00
|
|
|
if (aUnits == SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
|
2014-09-15 14:12:50 +04:00
|
|
|
return GetBoundingBoxRelativeRect(aXYWH, aBBox);
|
|
|
|
}
|
|
|
|
return gfxRect(UserSpace(aMetrics, &aXYWH[0]),
|
|
|
|
UserSpace(aMetrics, &aXYWH[1]),
|
|
|
|
UserSpace(aMetrics, &aXYWH[2]),
|
|
|
|
UserSpace(aMetrics, &aXYWH[3]));
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxRect
|
|
|
|
nsSVGUtils::GetRelativeRect(uint16_t aUnits, const nsSVGLength2 *aXYWH,
|
|
|
|
const gfxRect& aBBox, nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
if (aUnits == SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
|
|
|
|
return GetBoundingBoxRelativeRect(aXYWH, aBBox);
|
|
|
|
}
|
|
|
|
nsIContent* content = aFrame->GetContent();
|
2015-03-03 14:08:59 +03:00
|
|
|
if (content->IsSVGElement()) {
|
2014-09-15 14:12:50 +04:00
|
|
|
nsSVGElement* svgElement = static_cast<nsSVGElement*>(content);
|
|
|
|
return GetRelativeRect(aUnits, aXYWH, aBBox, SVGElementMetrics(svgElement));
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
2014-09-15 14:12:50 +04:00
|
|
|
return GetRelativeRect(aUnits, aXYWH, aBBox, NonSVGFrameUserSpaceMetrics(aFrame));
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2007-01-04 18:05:39 +03:00
|
|
|
nsSVGUtils::CanOptimizeOpacity(nsIFrame *aFrame)
|
|
|
|
{
|
2012-07-20 22:12:29 +04:00
|
|
|
if (!(aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT)) {
|
|
|
|
return false;
|
|
|
|
}
|
2009-10-26 20:17:49 +03:00
|
|
|
nsIAtom *type = aFrame->GetType();
|
|
|
|
if (type != nsGkAtoms::svgImageFrame &&
|
|
|
|
type != nsGkAtoms::svgPathGeometryFrame) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-10-26 20:17:49 +03:00
|
|
|
}
|
2014-02-10 08:31:03 +04:00
|
|
|
if (aFrame->StyleSVGReset()->HasFilters()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-10-26 20:17:49 +03:00
|
|
|
}
|
|
|
|
// XXX The SVG WG is intending to allow fill, stroke and markers on <image>
|
|
|
|
if (type == nsGkAtoms::svgImageFrame) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-10-26 20:17:49 +03:00
|
|
|
}
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleSVG *style = aFrame->StyleSVG();
|
2013-07-12 10:39:38 +04:00
|
|
|
if (style->HasMarker()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-10-26 20:17:49 +03:00
|
|
|
}
|
2013-11-23 17:32:21 +04:00
|
|
|
if (!style->HasFill() || !HasStroke(aFrame)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2007-01-04 18:05:39 +03:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-01-04 18:05:39 +03:00
|
|
|
}
|
|
|
|
|
2009-07-23 12:35:59 +04:00
|
|
|
gfxMatrix
|
|
|
|
nsSVGUtils::AdjustMatrixForUnits(const gfxMatrix &aMatrix,
|
2007-12-04 07:40:52 +03:00
|
|
|
nsSVGEnum *aUnits,
|
2008-09-11 04:24:16 +04:00
|
|
|
nsIFrame *aFrame)
|
2007-12-04 07:40:52 +03:00
|
|
|
{
|
|
|
|
if (aFrame &&
|
2013-02-18 06:14:02 +04:00
|
|
|
aUnits->GetAnimValue() == SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
|
2009-06-11 19:21:03 +04:00
|
|
|
gfxRect bbox = GetBBox(aFrame);
|
2014-09-10 17:26:12 +04:00
|
|
|
gfxMatrix tm = aMatrix;
|
|
|
|
tm.Translate(gfxPoint(bbox.X(), bbox.Y()));
|
|
|
|
tm.Scale(bbox.Width(), bbox.Height());
|
|
|
|
return tm;
|
2007-12-04 07:40:52 +03:00
|
|
|
}
|
2009-07-23 12:35:59 +04:00
|
|
|
return aMatrix;
|
2007-12-04 07:40:52 +03:00
|
|
|
}
|
|
|
|
|
2009-01-19 21:31:34 +03:00
|
|
|
nsIFrame*
|
|
|
|
nsSVGUtils::GetFirstNonAAncestorFrame(nsIFrame* aStartFrame)
|
|
|
|
{
|
|
|
|
for (nsIFrame *ancestorFrame = aStartFrame; ancestorFrame;
|
|
|
|
ancestorFrame = ancestorFrame->GetParent()) {
|
|
|
|
if (ancestorFrame->GetType() != nsGkAtoms::svgAFrame) {
|
|
|
|
return ancestorFrame;
|
|
|
|
}
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-01-19 21:31:34 +03:00
|
|
|
}
|
|
|
|
|
2014-09-30 21:08:14 +04:00
|
|
|
bool
|
|
|
|
nsSVGUtils::GetNonScalingStrokeTransform(nsIFrame *aFrame,
|
|
|
|
gfxMatrix* aUserToOuterSVG)
|
2012-05-18 12:34:25 +04:00
|
|
|
{
|
2013-06-16 15:05:39 +04:00
|
|
|
if (aFrame->GetContent()->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
aFrame = aFrame->GetParent();
|
|
|
|
}
|
|
|
|
|
2014-12-17 16:58:31 +03:00
|
|
|
if (!aFrame->StyleSVGReset()->HasNonScalingStroke()) {
|
2014-09-30 21:08:14 +04:00
|
|
|
return false;
|
2012-05-18 12:34:25 +04:00
|
|
|
}
|
2014-09-30 21:08:14 +04:00
|
|
|
|
|
|
|
nsIContent *content = aFrame->GetContent();
|
2015-03-03 14:08:59 +03:00
|
|
|
MOZ_ASSERT(content->IsSVGElement(), "bad cast");
|
2014-09-30 21:08:14 +04:00
|
|
|
|
|
|
|
*aUserToOuterSVG = ThebesMatrix(SVGContentUtils::GetCTM(
|
|
|
|
static_cast<nsSVGElement*>(content), true));
|
|
|
|
|
|
|
|
return !aUserToOuterSVG->IsIdentity();
|
2012-05-18 12:34:25 +04:00
|
|
|
}
|
|
|
|
|
2011-09-05 21:53:34 +04:00
|
|
|
// The logic here comes from _cairo_stroke_style_max_distance_from_path
|
|
|
|
static gfxRect
|
|
|
|
PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents,
|
2012-08-10 15:13:44 +04:00
|
|
|
nsIFrame* aFrame,
|
|
|
|
double aStyleExpansionFactor,
|
2012-02-10 16:33:39 +04:00
|
|
|
const gfxMatrix& aMatrix)
|
2009-03-31 16:19:39 +04:00
|
|
|
{
|
2011-09-05 21:53:34 +04:00
|
|
|
double style_expansion =
|
2012-08-10 15:13:44 +04:00
|
|
|
aStyleExpansionFactor * nsSVGUtils::GetStrokeWidth(aFrame);
|
2009-03-31 16:19:39 +04:00
|
|
|
|
2014-09-30 21:08:14 +04:00
|
|
|
gfxMatrix matrix = aMatrix;
|
|
|
|
|
|
|
|
gfxMatrix outerSVGToUser;
|
|
|
|
if (nsSVGUtils::GetNonScalingStrokeTransform(aFrame, &outerSVGToUser)) {
|
|
|
|
outerSVGToUser.Invert();
|
|
|
|
matrix *= outerSVGToUser;
|
|
|
|
}
|
2012-05-18 12:34:25 +04:00
|
|
|
|
2014-06-17 21:35:51 +04:00
|
|
|
double dx = style_expansion * (fabs(matrix._11) + fabs(matrix._21));
|
|
|
|
double dy = style_expansion * (fabs(matrix._22) + fabs(matrix._12));
|
2009-03-31 16:19:39 +04:00
|
|
|
|
|
|
|
gfxRect strokeExtents = aPathExtents;
|
2011-04-19 07:07:51 +04:00
|
|
|
strokeExtents.Inflate(dx, dy);
|
2009-03-31 16:19:39 +04:00
|
|
|
return strokeExtents;
|
|
|
|
}
|
|
|
|
|
2012-08-10 15:13:44 +04:00
|
|
|
/*static*/ gfxRect
|
|
|
|
nsSVGUtils::PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents,
|
|
|
|
nsTextFrame* aFrame,
|
|
|
|
const gfxMatrix& aMatrix)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aFrame->IsSVGText(), "expected an nsTextFrame for SVG text");
|
|
|
|
return ::PathExtentsToMaxStrokeExtents(aPathExtents, aFrame, 0.5, aMatrix);
|
|
|
|
}
|
|
|
|
|
2011-09-05 21:53:34 +04:00
|
|
|
/*static*/ gfxRect
|
|
|
|
nsSVGUtils::PathExtentsToMaxStrokeExtents(const gfxRect& aPathExtents,
|
2012-02-10 16:33:39 +04:00
|
|
|
nsSVGPathGeometryFrame* aFrame,
|
|
|
|
const gfxMatrix& aMatrix)
|
2011-09-05 21:53:34 +04:00
|
|
|
{
|
2015-03-03 14:09:00 +03:00
|
|
|
bool strokeMayHaveCorners =
|
|
|
|
!aFrame->GetContent()->IsAnyOfSVGElements(nsGkAtoms::circle,
|
|
|
|
nsGkAtoms::ellipse);
|
2014-11-01 13:45:10 +03:00
|
|
|
|
|
|
|
// For a shape without corners the stroke can only extend half the stroke
|
|
|
|
// width from the path in the x/y-axis directions. For shapes with corners
|
|
|
|
// the stroke can extend by sqrt(1/2) (think 45 degree rotated rect, or line
|
|
|
|
// with stroke-linecaps="square").
|
|
|
|
double styleExpansionFactor = strokeMayHaveCorners ? M_SQRT1_2 : 0.5;
|
|
|
|
|
|
|
|
// The stroke can extend even further for paths that can be affected by
|
|
|
|
// stroke-miterlimit.
|
2015-03-03 14:09:00 +03:00
|
|
|
bool affectedByMiterlimit =
|
|
|
|
aFrame->GetContent()->IsAnyOfSVGElements(nsGkAtoms::path,
|
|
|
|
nsGkAtoms::polyline,
|
|
|
|
nsGkAtoms::polygon);
|
|
|
|
|
2014-11-01 13:45:10 +03:00
|
|
|
if (affectedByMiterlimit) {
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleSVG* style = aFrame->StyleSVG();
|
2011-09-05 21:53:34 +04:00
|
|
|
if (style->mStrokeLinejoin == NS_STYLE_STROKE_LINEJOIN_MITER &&
|
2014-11-01 13:45:10 +03:00
|
|
|
styleExpansionFactor < style->mStrokeMiterlimit / 2.0) {
|
|
|
|
styleExpansionFactor = style->mStrokeMiterlimit / 2.0;
|
2011-09-05 21:53:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ::PathExtentsToMaxStrokeExtents(aPathExtents,
|
|
|
|
aFrame,
|
2012-02-10 16:33:39 +04:00
|
|
|
styleExpansionFactor,
|
|
|
|
aMatrix);
|
2011-09-05 21:53:34 +04:00
|
|
|
}
|
|
|
|
|
2006-11-27 20:30:57 +03:00
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
2012-08-05 23:10:21 +04:00
|
|
|
/* static */ nscolor
|
2014-09-28 13:06:22 +04:00
|
|
|
nsSVGUtils::GetFallbackOrPaintColor(nsStyleContext *aStyleContext,
|
2012-08-05 23:10:21 +04:00
|
|
|
nsStyleSVGPaint nsStyleSVG::*aFillOrStroke)
|
2012-02-04 17:11:09 +04:00
|
|
|
{
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleSVGPaint &paint = aStyleContext->StyleSVG()->*aFillOrStroke;
|
2012-02-04 17:11:09 +04:00
|
|
|
nsStyleContext *styleIfVisited = aStyleContext->GetStyleIfVisited();
|
2012-09-06 08:58:46 +04:00
|
|
|
bool isServer = paint.mType == eStyleSVGPaintType_Server ||
|
2013-05-16 06:35:15 +04:00
|
|
|
paint.mType == eStyleSVGPaintType_ContextFill ||
|
|
|
|
paint.mType == eStyleSVGPaintType_ContextStroke;
|
2012-08-05 23:10:21 +04:00
|
|
|
nscolor color = isServer ? paint.mFallbackColor : paint.mPaint.mColor;
|
2012-02-04 17:11:09 +04:00
|
|
|
if (styleIfVisited) {
|
|
|
|
const nsStyleSVGPaint &paintIfVisited =
|
2013-02-17 01:51:02 +04:00
|
|
|
styleIfVisited->StyleSVG()->*aFillOrStroke;
|
2012-02-04 17:11:09 +04:00
|
|
|
// To prevent Web content from detecting if a user has visited a URL
|
|
|
|
// (via URL loading triggered by paint servers or performance
|
|
|
|
// differences between paint servers or between a paint server and a
|
|
|
|
// color), we do not allow whether links are visited to change which
|
|
|
|
// paint server is used or switch between paint servers and simple
|
|
|
|
// colors. A :visited style may only override a simple color with
|
|
|
|
// another simple color.
|
|
|
|
if (paintIfVisited.mType == eStyleSVGPaintType_Color &&
|
|
|
|
paint.mType == eStyleSVGPaintType_Color) {
|
2012-08-05 23:10:21 +04:00
|
|
|
nscolor colors[2] = { color, paintIfVisited.mPaint.mColor };
|
|
|
|
return nsStyleContext::CombineVisitedColors(
|
|
|
|
colors, aStyleContext->RelevantLinkVisited());
|
2012-02-04 17:11:09 +04:00
|
|
|
}
|
|
|
|
}
|
2012-08-05 23:10:21 +04:00
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
|
|
|
static float
|
|
|
|
MaybeOptimizeOpacity(nsIFrame *aFrame, float aFillOrStrokeOpacity)
|
|
|
|
{
|
2013-02-17 01:51:02 +04:00
|
|
|
float opacity = aFrame->StyleDisplay()->mOpacity;
|
2012-08-05 23:10:21 +04:00
|
|
|
if (opacity < 1 && nsSVGUtils::CanOptimizeOpacity(aFrame)) {
|
|
|
|
return aFillOrStrokeOpacity * opacity;
|
|
|
|
}
|
|
|
|
return aFillOrStrokeOpacity;
|
|
|
|
}
|
|
|
|
|
2014-09-29 17:26:15 +04:00
|
|
|
/* static */ void
|
|
|
|
nsSVGUtils::MakeFillPatternFor(nsIFrame* aFrame,
|
2014-09-29 17:12:06 +04:00
|
|
|
gfxContext* aContext,
|
2014-09-29 17:26:15 +04:00
|
|
|
GeneralPattern* aOutPattern,
|
|
|
|
gfxTextContextPaint* aContextPaint)
|
2012-08-05 23:10:21 +04:00
|
|
|
{
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleSVG* style = aFrame->StyleSVG();
|
2014-09-29 17:12:06 +04:00
|
|
|
if (style->mFill.mType == eStyleSVGPaintType_None) {
|
2014-09-29 17:26:15 +04:00
|
|
|
return;
|
2014-09-29 17:12:06 +04:00
|
|
|
}
|
2012-08-28 18:47:01 +04:00
|
|
|
|
2012-09-06 08:58:47 +04:00
|
|
|
float opacity = MaybeOptimizeOpacity(aFrame,
|
|
|
|
GetOpacity(style->mFillOpacitySource,
|
|
|
|
style->mFillOpacity,
|
2013-05-16 06:35:12 +04:00
|
|
|
aContextPaint));
|
2014-09-29 17:15:19 +04:00
|
|
|
const DrawTarget* dt = aContext->GetDrawTarget();
|
|
|
|
|
2012-08-05 23:10:21 +04:00
|
|
|
nsSVGPaintServerFrame *ps =
|
2014-09-29 17:12:06 +04:00
|
|
|
nsSVGEffects::GetPaintServer(aFrame, &style->mFill,
|
|
|
|
nsSVGEffects::FillProperty());
|
|
|
|
if (ps) {
|
2014-09-29 17:26:15 +04:00
|
|
|
nsRefPtr<gfxPattern> pattern =
|
|
|
|
ps->GetPaintServerPattern(aFrame, dt, aContext->CurrentMatrix(),
|
|
|
|
&nsStyleSVG::mFill, opacity);
|
2014-09-29 17:12:06 +04:00
|
|
|
if (pattern) {
|
2014-09-29 17:15:19 +04:00
|
|
|
pattern->CacheColorStops(dt);
|
2014-09-29 17:26:15 +04:00
|
|
|
aOutPattern->Init(*pattern->GetPattern(dt));
|
|
|
|
return;
|
2014-09-29 17:12:06 +04:00
|
|
|
}
|
|
|
|
}
|
2012-08-05 23:10:21 +04:00
|
|
|
|
2014-09-29 17:12:06 +04:00
|
|
|
if (aContextPaint) {
|
2014-09-29 17:26:15 +04:00
|
|
|
nsRefPtr<gfxPattern> pattern;
|
2014-09-29 17:12:06 +04:00
|
|
|
switch (style->mFill.mType) {
|
|
|
|
case eStyleSVGPaintType_ContextFill:
|
2014-09-29 17:15:19 +04:00
|
|
|
pattern = aContextPaint->GetFillPattern(dt, opacity,
|
|
|
|
aContext->CurrentMatrix());
|
2014-09-29 17:12:06 +04:00
|
|
|
break;
|
|
|
|
case eStyleSVGPaintType_ContextStroke:
|
2014-09-29 17:15:19 +04:00
|
|
|
pattern = aContextPaint->GetStrokePattern(dt, opacity,
|
|
|
|
aContext->CurrentMatrix());
|
2014-09-29 17:12:06 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
if (pattern) {
|
2014-09-29 17:26:15 +04:00
|
|
|
aOutPattern->Init(*pattern->GetPattern(dt));
|
|
|
|
return;
|
2014-09-29 17:12:06 +04:00
|
|
|
}
|
2012-09-06 08:58:46 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 23:10:21 +04:00
|
|
|
// On failure, use the fallback colour in case we have an
|
|
|
|
// objectBoundingBox where the width or height of the object is zero.
|
|
|
|
// See http://www.w3.org/TR/SVG11/coords.html#ObjectBoundingBox
|
2014-10-17 15:53:16 +04:00
|
|
|
Color color(Color::FromABGR(GetFallbackOrPaintColor(aFrame->StyleContext(),
|
|
|
|
&nsStyleSVG::mFill)));
|
|
|
|
color.a *= opacity;
|
|
|
|
aOutPattern->InitColorPattern(ToDeviceColor(color));
|
2012-08-05 23:10:21 +04:00
|
|
|
}
|
|
|
|
|
2014-09-29 17:26:15 +04:00
|
|
|
/* static */ void
|
|
|
|
nsSVGUtils::MakeStrokePatternFor(nsIFrame* aFrame,
|
2014-09-29 17:12:06 +04:00
|
|
|
gfxContext* aContext,
|
2014-09-29 17:26:15 +04:00
|
|
|
GeneralPattern* aOutPattern,
|
|
|
|
gfxTextContextPaint* aContextPaint)
|
2012-08-05 23:10:21 +04:00
|
|
|
{
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleSVG* style = aFrame->StyleSVG();
|
2014-09-29 17:12:06 +04:00
|
|
|
if (style->mStroke.mType == eStyleSVGPaintType_None) {
|
2014-09-29 17:26:15 +04:00
|
|
|
return;
|
2014-09-29 17:12:06 +04:00
|
|
|
}
|
2012-08-05 23:10:21 +04:00
|
|
|
|
2012-09-06 08:58:47 +04:00
|
|
|
float opacity = MaybeOptimizeOpacity(aFrame,
|
|
|
|
GetOpacity(style->mStrokeOpacitySource,
|
|
|
|
style->mStrokeOpacity,
|
2013-05-16 06:35:12 +04:00
|
|
|
aContextPaint));
|
2014-09-29 17:15:19 +04:00
|
|
|
|
|
|
|
const DrawTarget* dt = aContext->GetDrawTarget();
|
|
|
|
|
2012-08-05 23:10:21 +04:00
|
|
|
nsSVGPaintServerFrame *ps =
|
2014-09-29 17:12:06 +04:00
|
|
|
nsSVGEffects::GetPaintServer(aFrame, &style->mStroke,
|
|
|
|
nsSVGEffects::StrokeProperty());
|
|
|
|
if (ps) {
|
2014-09-29 17:26:15 +04:00
|
|
|
nsRefPtr<gfxPattern> pattern =
|
|
|
|
ps->GetPaintServerPattern(aFrame, dt, aContext->CurrentMatrix(),
|
|
|
|
&nsStyleSVG::mStroke, opacity);
|
2014-09-29 17:12:06 +04:00
|
|
|
if (pattern) {
|
2014-09-29 17:15:19 +04:00
|
|
|
pattern->CacheColorStops(dt);
|
2014-09-29 17:26:15 +04:00
|
|
|
aOutPattern->Init(*pattern->GetPattern(dt));
|
|
|
|
return;
|
2014-09-29 17:12:06 +04:00
|
|
|
}
|
|
|
|
}
|
2012-08-05 23:10:21 +04:00
|
|
|
|
2014-09-29 17:12:06 +04:00
|
|
|
if (aContextPaint) {
|
2014-09-29 17:26:15 +04:00
|
|
|
nsRefPtr<gfxPattern> pattern;
|
2014-09-29 17:12:06 +04:00
|
|
|
switch (style->mStroke.mType) {
|
|
|
|
case eStyleSVGPaintType_ContextFill:
|
2014-09-29 17:15:19 +04:00
|
|
|
pattern = aContextPaint->GetFillPattern(dt, opacity,
|
|
|
|
aContext->CurrentMatrix());
|
2014-09-29 17:12:06 +04:00
|
|
|
break;
|
|
|
|
case eStyleSVGPaintType_ContextStroke:
|
2014-09-29 17:15:19 +04:00
|
|
|
pattern = aContextPaint->GetStrokePattern(dt, opacity,
|
|
|
|
aContext->CurrentMatrix());
|
2014-09-29 17:12:06 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
if (pattern) {
|
2014-09-29 17:26:15 +04:00
|
|
|
aOutPattern->Init(*pattern->GetPattern(dt));
|
|
|
|
return;
|
2014-09-29 17:12:06 +04:00
|
|
|
}
|
2012-09-06 08:58:46 +04:00
|
|
|
}
|
|
|
|
|
2012-08-05 23:10:21 +04:00
|
|
|
// On failure, use the fallback colour in case we have an
|
|
|
|
// objectBoundingBox where the width or height of the object is zero.
|
|
|
|
// See http://www.w3.org/TR/SVG11/coords.html#ObjectBoundingBox
|
2014-10-17 15:53:16 +04:00
|
|
|
Color color(Color::FromABGR(GetFallbackOrPaintColor(aFrame->StyleContext(),
|
|
|
|
&nsStyleSVG::mStroke)));
|
|
|
|
color.a *= opacity;
|
|
|
|
aOutPattern->InitColorPattern(ToDeviceColor(color));
|
2012-02-04 17:11:09 +04:00
|
|
|
}
|
2012-08-10 15:13:43 +04:00
|
|
|
|
2012-09-06 08:58:47 +04:00
|
|
|
/* static */ float
|
|
|
|
nsSVGUtils::GetOpacity(nsStyleSVGOpacitySource aOpacityType,
|
|
|
|
const float& aOpacity,
|
2014-11-07 01:07:36 +03:00
|
|
|
gfxTextContextPaint *aContextPaint)
|
2012-09-06 08:58:47 +04:00
|
|
|
{
|
|
|
|
float opacity = 1.0f;
|
|
|
|
switch (aOpacityType) {
|
|
|
|
case eStyleSVGOpacitySource_Normal:
|
|
|
|
opacity = aOpacity;
|
|
|
|
break;
|
2013-05-16 06:35:15 +04:00
|
|
|
case eStyleSVGOpacitySource_ContextFillOpacity:
|
2014-11-07 01:07:36 +03:00
|
|
|
if (aContextPaint) {
|
|
|
|
opacity = aContextPaint->GetFillOpacity();
|
2012-09-06 08:58:47 +04:00
|
|
|
} else {
|
2014-11-07 01:07:36 +03:00
|
|
|
NS_WARNING("Content used context-fill-opacity when not in a context element");
|
2012-09-06 08:58:47 +04:00
|
|
|
}
|
|
|
|
break;
|
2013-05-16 06:35:15 +04:00
|
|
|
case eStyleSVGOpacitySource_ContextStrokeOpacity:
|
2014-11-07 01:07:36 +03:00
|
|
|
if (aContextPaint) {
|
|
|
|
opacity = aContextPaint->GetStrokeOpacity();
|
2012-09-06 08:58:47 +04:00
|
|
|
} else {
|
2014-11-07 01:07:36 +03:00
|
|
|
NS_WARNING("Content used context-stroke-opacity when not in a context element");
|
2012-09-06 08:58:47 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unknown object opacity inheritance type for SVG glyph");
|
|
|
|
}
|
|
|
|
return opacity;
|
|
|
|
}
|
|
|
|
|
2012-08-10 15:13:43 +04:00
|
|
|
bool
|
2013-05-16 06:35:12 +04:00
|
|
|
nsSVGUtils::HasStroke(nsIFrame* aFrame, gfxTextContextPaint *aContextPaint)
|
2012-08-10 15:13:43 +04:00
|
|
|
{
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleSVG *style = aFrame->StyleSVG();
|
2013-11-23 17:32:21 +04:00
|
|
|
return style->HasStroke() && GetStrokeWidth(aFrame, aContextPaint) > 0;
|
2012-08-10 15:13:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
float
|
2013-05-16 06:35:12 +04:00
|
|
|
nsSVGUtils::GetStrokeWidth(nsIFrame* aFrame, gfxTextContextPaint *aContextPaint)
|
2012-08-10 15:13:43 +04:00
|
|
|
{
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleSVG *style = aFrame->StyleSVG();
|
2013-05-16 06:35:12 +04:00
|
|
|
if (aContextPaint && style->mStrokeWidthFromObject) {
|
|
|
|
return aContextPaint->GetStrokeWidth();
|
2012-09-06 08:58:47 +04:00
|
|
|
}
|
|
|
|
|
2012-08-10 15:13:43 +04:00
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
|
|
if (content->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
content = content->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGElement *ctx = static_cast<nsSVGElement*>(content);
|
|
|
|
|
2014-07-05 22:19:13 +04:00
|
|
|
return SVGContentUtils::CoordToFloat(ctx, style->mStrokeWidth);
|
2012-08-10 15:13:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
GetStrokeDashData(nsIFrame* aFrame,
|
|
|
|
FallibleTArray<gfxFloat>& aDashes,
|
2012-09-06 08:58:47 +04:00
|
|
|
gfxFloat* aDashOffset,
|
2013-05-16 06:35:12 +04:00
|
|
|
gfxTextContextPaint *aContextPaint)
|
2012-08-10 15:13:43 +04:00
|
|
|
{
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleSVG* style = aFrame->StyleSVG();
|
2012-09-06 08:58:47 +04:00
|
|
|
nsIContent *content = aFrame->GetContent();
|
|
|
|
nsSVGElement *ctx = static_cast<nsSVGElement*>
|
|
|
|
(content->IsNodeOfType(nsINode::eTEXT) ?
|
|
|
|
content->GetParent() : content);
|
2012-08-10 15:13:43 +04:00
|
|
|
|
2012-09-06 08:58:47 +04:00
|
|
|
gfxFloat totalLength = 0.0;
|
2013-05-16 06:35:12 +04:00
|
|
|
if (aContextPaint && style->mStrokeDasharrayFromObject) {
|
|
|
|
aDashes = aContextPaint->GetStrokeDashArray();
|
2012-08-10 15:13:43 +04:00
|
|
|
|
2012-09-06 08:58:47 +04:00
|
|
|
for (uint32_t i = 0; i < aDashes.Length(); i++) {
|
|
|
|
if (aDashes[i] < 0.0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
totalLength += aDashes[i];
|
|
|
|
}
|
2012-08-10 15:13:43 +04:00
|
|
|
|
2012-09-06 08:58:47 +04:00
|
|
|
} else {
|
|
|
|
uint32_t count = style->mStrokeDasharrayLength;
|
2015-05-18 23:50:35 +03:00
|
|
|
if (!count || !aDashes.SetLength(count, fallible)) {
|
2012-08-10 15:13:43 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-06 08:58:47 +04:00
|
|
|
gfxFloat pathScale = 1.0;
|
2012-08-10 15:13:43 +04:00
|
|
|
|
2015-03-03 14:09:00 +03:00
|
|
|
if (content->IsSVGElement(nsGkAtoms::path)) {
|
2013-01-13 02:22:31 +04:00
|
|
|
pathScale = static_cast<SVGPathElement*>(content)->
|
|
|
|
GetPathLengthScale(SVGPathElement::eForStroking);
|
2012-09-06 08:58:47 +04:00
|
|
|
if (pathScale <= 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2012-08-10 15:13:43 +04:00
|
|
|
|
2012-09-06 08:58:47 +04:00
|
|
|
const nsStyleCoord *dasharray = style->mStrokeDasharray;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
2014-07-05 22:19:13 +04:00
|
|
|
aDashes[i] = SVGContentUtils::CoordToFloat(ctx,
|
2013-11-02 15:10:38 +04:00
|
|
|
dasharray[i]) * pathScale;
|
2012-09-06 08:58:47 +04:00
|
|
|
if (aDashes[i] < 0.0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
totalLength += aDashes[i];
|
2012-08-10 15:13:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-16 06:35:12 +04:00
|
|
|
if (aContextPaint && style->mStrokeDashoffsetFromObject) {
|
|
|
|
*aDashOffset = aContextPaint->GetStrokeDashOffset();
|
2012-09-06 08:58:47 +04:00
|
|
|
} else {
|
2014-07-05 22:19:13 +04:00
|
|
|
*aDashOffset = SVGContentUtils::CoordToFloat(ctx,
|
2013-11-02 15:10:38 +04:00
|
|
|
style->mStrokeDashoffset);
|
2012-09-06 08:58:47 +04:00
|
|
|
}
|
|
|
|
|
2012-08-10 15:13:43 +04:00
|
|
|
return (totalLength > 0.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-29 17:12:06 +04:00
|
|
|
nsSVGUtils::SetupCairoStrokeGeometry(nsIFrame* aFrame,
|
|
|
|
gfxContext *aContext,
|
2013-05-16 06:35:12 +04:00
|
|
|
gfxTextContextPaint *aContextPaint)
|
2012-08-10 15:13:43 +04:00
|
|
|
{
|
2014-09-29 17:12:06 +04:00
|
|
|
float width = GetStrokeWidth(aFrame, aContextPaint);
|
|
|
|
if (width <= 0)
|
|
|
|
return;
|
|
|
|
aContext->SetLineWidth(width);
|
|
|
|
|
|
|
|
// Apply any stroke-specific transform
|
2014-09-30 21:08:14 +04:00
|
|
|
gfxMatrix outerSVGToUser;
|
|
|
|
if (GetNonScalingStrokeTransform(aFrame, &outerSVGToUser) &&
|
|
|
|
outerSVGToUser.Invert()) {
|
|
|
|
aContext->Multiply(outerSVGToUser);
|
2014-09-29 17:12:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
const nsStyleSVG* style = aFrame->StyleSVG();
|
|
|
|
|
|
|
|
switch (style->mStrokeLinecap) {
|
|
|
|
case NS_STYLE_STROKE_LINECAP_BUTT:
|
2014-11-03 13:01:57 +03:00
|
|
|
aContext->SetLineCap(CapStyle::BUTT);
|
2014-09-29 17:12:06 +04:00
|
|
|
break;
|
|
|
|
case NS_STYLE_STROKE_LINECAP_ROUND:
|
2014-11-03 13:01:57 +03:00
|
|
|
aContext->SetLineCap(CapStyle::ROUND);
|
2014-09-29 17:12:06 +04:00
|
|
|
break;
|
|
|
|
case NS_STYLE_STROKE_LINECAP_SQUARE:
|
2014-11-03 13:01:57 +03:00
|
|
|
aContext->SetLineCap(CapStyle::SQUARE);
|
2014-09-29 17:12:06 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
aContext->SetMiterLimit(style->mStrokeMiterlimit);
|
|
|
|
|
|
|
|
switch (style->mStrokeLinejoin) {
|
|
|
|
case NS_STYLE_STROKE_LINEJOIN_MITER:
|
2014-12-16 18:31:28 +03:00
|
|
|
aContext->SetLineJoin(JoinStyle::MITER_OR_BEVEL);
|
2014-09-29 17:12:06 +04:00
|
|
|
break;
|
|
|
|
case NS_STYLE_STROKE_LINEJOIN_ROUND:
|
2014-11-03 13:01:57 +03:00
|
|
|
aContext->SetLineJoin(JoinStyle::ROUND);
|
2014-09-29 17:12:06 +04:00
|
|
|
break;
|
|
|
|
case NS_STYLE_STROKE_LINEJOIN_BEVEL:
|
2014-11-03 13:01:57 +03:00
|
|
|
aContext->SetLineJoin(JoinStyle::BEVEL);
|
2014-09-29 17:12:06 +04:00
|
|
|
break;
|
|
|
|
}
|
2012-08-10 15:13:43 +04:00
|
|
|
|
|
|
|
AutoFallibleTArray<gfxFloat, 10> dashes;
|
|
|
|
gfxFloat dashOffset;
|
2013-05-16 06:35:12 +04:00
|
|
|
if (GetStrokeDashData(aFrame, dashes, &dashOffset, aContextPaint)) {
|
2012-08-10 15:13:43 +04:00
|
|
|
aContext->SetDash(dashes.Elements(), dashes.Length(), dashOffset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t
|
2012-08-10 15:13:43 +04:00
|
|
|
nsSVGUtils::GetGeometryHitTestFlags(nsIFrame* aFrame)
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t flags = 0;
|
2012-08-10 15:13:43 +04:00
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
switch(aFrame->StyleVisibility()->mPointerEvents) {
|
2012-08-10 15:13:43 +04:00
|
|
|
case NS_STYLE_POINTER_EVENTS_NONE:
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_AUTO:
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLEPAINTED:
|
2013-02-17 01:51:02 +04:00
|
|
|
if (aFrame->StyleVisibility()->IsVisible()) {
|
|
|
|
if (aFrame->StyleSVG()->mFill.mType != eStyleSVGPaintType_None)
|
2012-08-10 15:13:43 +04:00
|
|
|
flags |= SVG_HIT_TEST_FILL;
|
2013-02-17 01:51:02 +04:00
|
|
|
if (aFrame->StyleSVG()->mStroke.mType != eStyleSVGPaintType_None)
|
2012-08-10 15:13:43 +04:00
|
|
|
flags |= SVG_HIT_TEST_STROKE;
|
2013-02-17 01:51:02 +04:00
|
|
|
if (aFrame->StyleSVG()->mStrokeOpacity > 0)
|
2012-08-10 15:13:43 +04:00
|
|
|
flags |= SVG_HIT_TEST_CHECK_MRECT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLEFILL:
|
2013-02-17 01:51:02 +04:00
|
|
|
if (aFrame->StyleVisibility()->IsVisible()) {
|
2012-08-10 15:13:43 +04:00
|
|
|
flags |= SVG_HIT_TEST_FILL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLESTROKE:
|
2013-02-17 01:51:02 +04:00
|
|
|
if (aFrame->StyleVisibility()->IsVisible()) {
|
2012-08-10 15:13:43 +04:00
|
|
|
flags |= SVG_HIT_TEST_STROKE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLE:
|
2013-02-17 01:51:02 +04:00
|
|
|
if (aFrame->StyleVisibility()->IsVisible()) {
|
2012-08-10 15:13:43 +04:00
|
|
|
flags |= SVG_HIT_TEST_FILL | SVG_HIT_TEST_STROKE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_PAINTED:
|
2013-02-17 01:51:02 +04:00
|
|
|
if (aFrame->StyleSVG()->mFill.mType != eStyleSVGPaintType_None)
|
2012-08-10 15:13:43 +04:00
|
|
|
flags |= SVG_HIT_TEST_FILL;
|
2013-02-17 01:51:02 +04:00
|
|
|
if (aFrame->StyleSVG()->mStroke.mType != eStyleSVGPaintType_None)
|
2012-08-10 15:13:43 +04:00
|
|
|
flags |= SVG_HIT_TEST_STROKE;
|
2013-02-17 01:51:02 +04:00
|
|
|
if (aFrame->StyleSVG()->mStrokeOpacity)
|
2012-08-10 15:13:43 +04:00
|
|
|
flags |= SVG_HIT_TEST_CHECK_MRECT;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_FILL:
|
|
|
|
flags |= SVG_HIT_TEST_FILL;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_STROKE:
|
|
|
|
flags |= SVG_HIT_TEST_STROKE;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_ALL:
|
|
|
|
flags |= SVG_HIT_TEST_FILL | SVG_HIT_TEST_STROKE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("not reached");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2012-12-12 03:15:07 +04:00
|
|
|
bool
|
|
|
|
nsSVGUtils::PaintSVGGlyph(Element* aElement, gfxContext* aContext,
|
2013-10-02 01:02:16 +04:00
|
|
|
DrawMode aDrawMode,
|
2013-05-16 06:35:12 +04:00
|
|
|
gfxTextContextPaint* aContextPaint)
|
2012-12-12 03:15:07 +04:00
|
|
|
{
|
|
|
|
nsIFrame* frame = aElement->GetPrimaryFrame();
|
|
|
|
nsISVGChildFrame* svgFrame = do_QueryFrame(frame);
|
2013-08-19 17:08:43 +04:00
|
|
|
if (!svgFrame) {
|
|
|
|
return false;
|
2012-12-12 03:15:07 +04:00
|
|
|
}
|
2014-09-05 21:11:35 +04:00
|
|
|
aContext->GetDrawTarget()->AddUserData(&gfxTextContextPaint::sUserDataKey,
|
|
|
|
aContextPaint, nullptr);
|
2014-08-29 23:42:07 +04:00
|
|
|
gfxMatrix m;
|
2015-03-03 14:08:59 +03:00
|
|
|
if (frame->GetContent()->IsSVGElement()) {
|
2014-08-29 23:42:07 +04:00
|
|
|
// PaintSVG() expects the passed transform to be the transform to its own
|
|
|
|
// SVG user space, so we need to account for any 'transform' attribute:
|
|
|
|
m = static_cast<nsSVGElement*>(frame->GetContent())->
|
|
|
|
PrependLocalTransformsTo(gfxMatrix(), nsSVGElement::eUserSpaceToParent);
|
|
|
|
}
|
2014-10-31 23:08:54 +03:00
|
|
|
nsresult rv = svgFrame->PaintSVG(*aContext, m);
|
2013-08-19 17:08:43 +04:00
|
|
|
return NS_SUCCEEDED(rv);
|
2012-12-12 03:15:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsSVGUtils::GetSVGGlyphExtents(Element* aElement,
|
|
|
|
const gfxMatrix& aSVGToAppSpace,
|
|
|
|
gfxRect* aResult)
|
|
|
|
{
|
|
|
|
nsIFrame* frame = aElement->GetPrimaryFrame();
|
|
|
|
nsISVGChildFrame* svgFrame = do_QueryFrame(frame);
|
2013-08-19 17:08:43 +04:00
|
|
|
if (!svgFrame) {
|
|
|
|
return false;
|
2012-12-12 03:15:07 +04:00
|
|
|
}
|
2013-10-25 12:09:30 +04:00
|
|
|
|
2013-12-27 00:13:57 +04:00
|
|
|
gfxMatrix transform(aSVGToAppSpace);
|
2013-10-25 12:09:30 +04:00
|
|
|
nsIContent* content = frame->GetContent();
|
2015-03-03 14:08:59 +03:00
|
|
|
if (content->IsSVGElement()) {
|
2013-12-27 00:13:57 +04:00
|
|
|
transform = static_cast<nsSVGElement*>(content)->
|
|
|
|
PrependLocalTransformsTo(aSVGToAppSpace);
|
2013-10-25 12:09:30 +04:00
|
|
|
}
|
|
|
|
|
2013-12-30 10:50:07 +04:00
|
|
|
*aResult = svgFrame->GetBBoxContribution(gfx::ToMatrix(transform),
|
2013-08-19 17:08:43 +04:00
|
|
|
nsSVGUtils::eBBoxIncludeFill | nsSVGUtils::eBBoxIncludeFillGeometry |
|
|
|
|
nsSVGUtils::eBBoxIncludeStroke | nsSVGUtils::eBBoxIncludeStrokeGeometry |
|
2013-11-01 15:04:01 +04:00
|
|
|
nsSVGUtils::eBBoxIncludeMarkers).ToThebesRect();
|
2013-08-19 17:08:43 +04:00
|
|
|
return true;
|
2012-12-12 03:15:07 +04:00
|
|
|
}
|
2013-02-11 10:22:18 +04:00
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsSVGUtils::ToCanvasBounds(const gfxRect &aUserspaceRect,
|
|
|
|
const gfxMatrix &aToCanvas,
|
|
|
|
const nsPresContext *presContext)
|
|
|
|
{
|
|
|
|
return nsLayoutUtils::RoundGfxRectToAppRect(
|
|
|
|
aToCanvas.TransformBounds(aUserspaceRect),
|
|
|
|
presContext->AppUnitsPerDevPixel());
|
|
|
|
}
|