2004-08-05 13:01:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2004-08-05 13:01:13 +04:00
|
|
|
|
2012-03-26 15:58:59 +04:00
|
|
|
// Main header first:
|
2009-04-25 03:17:43 +04:00
|
|
|
#include "nsSVGInnerSVGFrame.h"
|
2012-03-20 16:15:55 +04:00
|
|
|
|
2012-03-26 15:58:59 +04:00
|
|
|
// Keep others in (case-insensitive) order:
|
|
|
|
#include "gfxContext.h"
|
2006-06-01 19:31:15 +04:00
|
|
|
#include "nsIFrame.h"
|
2004-08-05 13:01:13 +04:00
|
|
|
#include "nsISVGChildFrame.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsRenderingContext.h"
|
2006-06-01 19:31:15 +04:00
|
|
|
#include "nsSVGContainerFrame.h"
|
2012-06-30 15:20:46 +04:00
|
|
|
#include "nsSVGIntegrationUtils.h"
|
2013-01-10 03:02:45 +04:00
|
|
|
#include "mozilla/dom/SVGSVGElement.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
2004-08-05 13:01:13 +04:00
|
|
|
|
2005-11-11 05:36:29 +03:00
|
|
|
nsIFrame*
|
2009-01-19 21:31:34 +03:00
|
|
|
NS_NewSVGInnerSVGFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2004-08-05 13:01:13 +04:00
|
|
|
{
|
2007-07-25 13:16:02 +04:00
|
|
|
return new (aPresShell) nsSVGInnerSVGFrame(aContext);
|
2004-08-05 13:01:13 +04:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGInnerSVGFrame)
|
|
|
|
|
2004-08-05 13:01:13 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIFrame methods
|
2004-09-14 02:55:43 +04:00
|
|
|
|
2009-01-12 22:20:59 +03:00
|
|
|
NS_QUERYFRAME_HEAD(nsSVGInnerSVGFrame)
|
2009-04-25 03:17:43 +04:00
|
|
|
NS_QUERYFRAME_ENTRY(nsSVGInnerSVGFrame)
|
2009-01-12 22:20:59 +03:00
|
|
|
NS_QUERYFRAME_ENTRY(nsISVGSVGFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsSVGInnerSVGFrameBase)
|
|
|
|
|
2009-01-19 21:31:34 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGInnerSVGFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
2013-01-08 07:22:41 +04:00
|
|
|
NS_ASSERTION(aContent->IsSVG(nsGkAtoms::svg),
|
|
|
|
"Content is not an SVG 'svg' element!");
|
2009-01-19 21:31:34 +03:00
|
|
|
|
|
|
|
return nsSVGInnerSVGFrameBase::Init(aContent, aParent, aPrevInFlow);
|
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2005-04-01 23:56:08 +04:00
|
|
|
nsIAtom *
|
|
|
|
nsSVGInnerSVGFrame::GetType() const
|
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
return nsGkAtoms::svgInnerSVGFrame;
|
2005-04-01 23:56:08 +04:00
|
|
|
}
|
2004-08-05 13:01:13 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISVGChildFrame methods
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-03-02 12:28:59 +04:00
|
|
|
nsSVGInnerSVGFrame::PaintSVG(nsRenderingContext *aContext,
|
2008-10-20 12:42:03 +04:00
|
|
|
const nsIntRect *aDirtyRect)
|
2004-08-05 13:01:13 +04:00
|
|
|
{
|
2012-07-20 22:12:29 +04:00
|
|
|
NS_ASSERTION(!NS_SVGDisplayListPaintingEnabled() ||
|
|
|
|
(mState & NS_STATE_SVG_NONDISPLAY_CHILD),
|
|
|
|
"If display lists are enabled, only painting of non-display "
|
|
|
|
"SVG should take this code path");
|
|
|
|
|
2008-01-27 23:39:27 +03:00
|
|
|
gfxContextAutoSaveRestore autoSR;
|
2004-10-27 04:25:08 +04:00
|
|
|
|
2008-01-27 23:39:27 +03:00
|
|
|
if (GetStyleDisplay()->IsScrollableOverflow()) {
|
|
|
|
float x, y, width, height;
|
2013-01-10 03:02:45 +04:00
|
|
|
static_cast<SVGSVGElement*>(mContent)->
|
2012-07-30 18:20:58 +04:00
|
|
|
GetAnimatedLengthValues(&x, &y, &width, &height, nullptr);
|
2006-11-27 20:30:57 +03:00
|
|
|
|
2008-01-27 23:39:27 +03:00
|
|
|
if (width <= 0 || height <= 0) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2004-10-27 04:25:08 +04:00
|
|
|
|
2009-06-18 15:31:25 +04:00
|
|
|
nsSVGContainerFrame *parent = static_cast<nsSVGContainerFrame*>(mParent);
|
2012-06-30 15:20:46 +04:00
|
|
|
gfxMatrix clipTransform = parent->GetCanvasTM(FOR_PAINTING);
|
2009-06-18 15:31:25 +04:00
|
|
|
|
2012-03-02 12:28:59 +04:00
|
|
|
gfxContext *gfx = aContext->ThebesContext();
|
2009-06-18 15:31:25 +04:00
|
|
|
autoSR.SetContext(gfx);
|
|
|
|
gfxRect clipRect =
|
|
|
|
nsSVGUtils::GetClipRectForFrame(this, x, y, width, height);
|
|
|
|
nsSVGUtils::SetClipRect(gfx, clipTransform, clipRect);
|
2004-10-27 04:25:08 +04:00
|
|
|
}
|
|
|
|
|
2008-01-27 23:39:27 +03:00
|
|
|
return nsSVGInnerSVGFrameBase::PaintSVG(aContext, aDirtyRect);
|
2004-08-05 13:01:13 +04:00
|
|
|
}
|
|
|
|
|
2012-05-17 08:05:09 +04:00
|
|
|
void
|
2012-07-22 04:01:44 +04:00
|
|
|
nsSVGInnerSVGFrame::ReflowSVG()
|
2012-05-17 08:05:09 +04:00
|
|
|
{
|
|
|
|
// mRect must be set before FinishAndStoreOverflow is called in order
|
|
|
|
// for our overflow areas to be clipped correctly.
|
|
|
|
float x, y, width, height;
|
2013-01-10 03:02:45 +04:00
|
|
|
static_cast<SVGSVGElement*>(mContent)->
|
2012-07-30 18:20:58 +04:00
|
|
|
GetAnimatedLengthValues(&x, &y, &width, &height, nullptr);
|
2012-05-17 08:05:09 +04:00
|
|
|
mRect = nsLayoutUtils::RoundGfxRectToAppRect(
|
|
|
|
gfxRect(x, y, width, height),
|
|
|
|
PresContext()->AppUnitsPerCSSPixel());
|
2012-07-22 04:01:44 +04:00
|
|
|
nsSVGInnerSVGFrameBase::ReflowSVG();
|
2012-05-17 08:05:09 +04:00
|
|
|
}
|
|
|
|
|
2008-01-25 12:27:03 +03:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGInnerSVGFrame::NotifySVGChanged(uint32_t aFlags)
|
2004-08-05 13:01:13 +04:00
|
|
|
{
|
2012-03-11 19:53:36 +04:00
|
|
|
NS_ABORT_IF_FALSE(aFlags & (TRANSFORM_CHANGED | COORD_CONTEXT_CHANGED),
|
|
|
|
"Invalidation logic may need adjusting");
|
|
|
|
|
2008-01-25 12:27:03 +03:00
|
|
|
if (aFlags & COORD_CONTEXT_CHANGED) {
|
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement *svg = static_cast<SVGSVGElement*>(mContent);
|
2008-01-25 12:27:03 +03:00
|
|
|
|
2012-06-23 20:36:46 +04:00
|
|
|
bool xOrYIsPercentage =
|
2013-01-10 03:02:47 +04:00
|
|
|
svg->mLengthAttributes[SVGSVGElement::ATTR_X].IsPercentage() ||
|
|
|
|
svg->mLengthAttributes[SVGSVGElement::ATTR_Y].IsPercentage();
|
2012-06-23 20:36:46 +04:00
|
|
|
bool widthOrHeightIsPercentage =
|
2013-01-10 03:02:47 +04:00
|
|
|
svg->mLengthAttributes[SVGSVGElement::ATTR_WIDTH].IsPercentage() ||
|
|
|
|
svg->mLengthAttributes[SVGSVGElement::ATTR_HEIGHT].IsPercentage();
|
2012-06-23 20:36:46 +04:00
|
|
|
|
|
|
|
if (xOrYIsPercentage || widthOrHeightIsPercentage) {
|
|
|
|
// Ancestor changes can't affect how we render from the perspective of
|
|
|
|
// any rendering observers that we may have, so we don't need to
|
|
|
|
// invalidate them. We also don't need to invalidate ourself, since our
|
|
|
|
// changed ancestor will have invalidated its entire area, which includes
|
|
|
|
// our area.
|
|
|
|
// For perf reasons we call this before calling NotifySVGChanged() below.
|
2012-07-22 04:01:44 +04:00
|
|
|
nsSVGUtils::ScheduleReflowSVG(this);
|
2012-06-23 20:36:46 +04:00
|
|
|
}
|
|
|
|
|
2008-01-25 12:27:03 +03:00
|
|
|
// Coordinate context changes affect mCanvasTM if we have a
|
|
|
|
// percentage 'x' or 'y', or if we have a percentage 'width' or 'height' AND
|
|
|
|
// a 'viewBox'.
|
|
|
|
|
|
|
|
if (!(aFlags & TRANSFORM_CHANGED) &&
|
2012-06-23 20:36:46 +04:00
|
|
|
(xOrYIsPercentage ||
|
|
|
|
(widthOrHeightIsPercentage && svg->HasViewBox()))) {
|
2008-01-25 12:27:03 +03:00
|
|
|
aFlags |= TRANSFORM_CHANGED;
|
|
|
|
}
|
|
|
|
|
2012-06-23 20:36:46 +04:00
|
|
|
if (svg->HasViewBox() || !widthOrHeightIsPercentage) {
|
2012-05-19 17:50:07 +04:00
|
|
|
// Remove COORD_CONTEXT_CHANGED, since we establish the coordinate
|
|
|
|
// context for our descendants and this notification won't change its
|
|
|
|
// dimensions:
|
|
|
|
aFlags &= ~COORD_CONTEXT_CHANGED;
|
|
|
|
|
2012-07-23 15:00:43 +04:00
|
|
|
if (!aFlags) {
|
2012-05-19 17:50:07 +04:00
|
|
|
return; // No notification flags left
|
|
|
|
}
|
|
|
|
}
|
2008-01-25 12:27:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aFlags & TRANSFORM_CHANGED) {
|
|
|
|
// make sure our cached transform matrix gets (lazily) updated
|
2012-07-30 18:20:58 +04:00
|
|
|
mCanvasTM = nullptr;
|
2008-01-25 12:27:03 +03:00
|
|
|
}
|
2004-08-05 13:01:13 +04:00
|
|
|
|
2008-01-25 12:27:03 +03:00
|
|
|
nsSVGInnerSVGFrameBase::NotifySVGChanged(aFlags);
|
2004-08-05 13:01:13 +04:00
|
|
|
}
|
|
|
|
|
2010-10-07 23:19:32 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGInnerSVGFrame::AttributeChanged(int32_t aNameSpaceID,
|
2010-10-07 23:19:32 +04:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aModType)
|
2010-10-07 23:19:32 +04:00
|
|
|
{
|
2012-08-15 15:58:06 +04:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
!(GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD)) {
|
2012-05-17 08:05:09 +04:00
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement* content = static_cast<SVGSVGElement*>(mContent);
|
2012-05-17 08:05:09 +04:00
|
|
|
|
2010-10-07 23:19:32 +04:00
|
|
|
if (aAttribute == nsGkAtoms::width ||
|
2011-09-30 12:25:01 +04:00
|
|
|
aAttribute == nsGkAtoms::height) {
|
2012-11-28 13:42:13 +04:00
|
|
|
nsSVGUtils::InvalidateBounds(this, false);
|
|
|
|
nsSVGUtils::ScheduleReflowSVG(this);
|
2011-09-30 12:25:01 +04:00
|
|
|
|
2012-05-17 08:05:09 +04:00
|
|
|
if (content->HasViewBoxOrSyntheticViewBox()) {
|
2011-09-30 12:25:01 +04:00
|
|
|
// make sure our cached transform matrix gets (lazily) updated
|
2012-07-30 18:20:58 +04:00
|
|
|
mCanvasTM = nullptr;
|
2012-05-17 08:05:09 +04:00
|
|
|
content->ChildrenOnlyTransformChanged();
|
2011-09-30 12:25:01 +04:00
|
|
|
nsSVGUtils::NotifyChildrenOfSVGChange(this, TRANSFORM_CHANGED);
|
|
|
|
} else {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t flags = COORD_CONTEXT_CHANGED;
|
2012-03-03 13:21:09 +04:00
|
|
|
if (mCanvasTM && mCanvasTM->IsSingular()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mCanvasTM = nullptr;
|
2012-03-03 13:21:09 +04:00
|
|
|
flags |= TRANSFORM_CHANGED;
|
|
|
|
}
|
|
|
|
nsSVGUtils::NotifyChildrenOfSVGChange(this, flags);
|
2011-09-30 12:25:01 +04:00
|
|
|
}
|
|
|
|
|
2010-10-07 23:19:32 +04:00
|
|
|
} else if (aAttribute == nsGkAtoms::transform ||
|
2011-09-30 12:25:01 +04:00
|
|
|
aAttribute == nsGkAtoms::preserveAspectRatio ||
|
|
|
|
aAttribute == nsGkAtoms::viewBox ||
|
2010-10-07 23:19:32 +04:00
|
|
|
aAttribute == nsGkAtoms::x ||
|
|
|
|
aAttribute == nsGkAtoms::y) {
|
|
|
|
// make sure our cached transform matrix gets (lazily) updated
|
2012-07-30 18:20:58 +04:00
|
|
|
mCanvasTM = nullptr;
|
2010-10-07 23:19:32 +04:00
|
|
|
|
2013-02-12 05:29:48 +04:00
|
|
|
nsSVGUtils::InvalidateBounds(this, false);
|
|
|
|
nsSVGUtils::ScheduleReflowSVG(this);
|
|
|
|
|
2011-09-30 12:25:01 +04:00
|
|
|
nsSVGUtils::NotifyChildrenOfSVGChange(
|
|
|
|
this, aAttribute == nsGkAtoms::viewBox ?
|
|
|
|
TRANSFORM_CHANGED | COORD_CONTEXT_CHANGED : TRANSFORM_CHANGED);
|
2012-05-17 08:05:09 +04:00
|
|
|
|
2013-02-12 05:29:48 +04:00
|
|
|
if (aAttribute == nsGkAtoms::viewBox ||
|
|
|
|
(aAttribute == nsGkAtoms::preserveAspectRatio &&
|
|
|
|
content->HasViewBoxOrSyntheticViewBox())) {
|
2012-05-17 08:05:09 +04:00
|
|
|
content->ChildrenOnlyTransformChanged();
|
|
|
|
}
|
2010-10-07 23:19:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-08-25 13:23:54 +04:00
|
|
|
NS_IMETHODIMP_(nsIFrame*)
|
|
|
|
nsSVGInnerSVGFrame::GetFrameForPoint(const nsPoint &aPoint)
|
2006-09-19 20:35:29 +04:00
|
|
|
{
|
2012-07-20 22:12:29 +04:00
|
|
|
NS_ASSERTION(!NS_SVGDisplayListHitTestingEnabled() ||
|
|
|
|
(mState & NS_STATE_SVG_NONDISPLAY_CHILD),
|
|
|
|
"If display lists are enabled, only hit-testing of non-display "
|
|
|
|
"SVG should take this code path");
|
|
|
|
|
2006-09-19 20:35:29 +04:00
|
|
|
if (GetStyleDisplay()->IsScrollableOverflow()) {
|
2009-07-23 12:35:59 +04:00
|
|
|
nsSVGElement *content = static_cast<nsSVGElement*>(mContent);
|
|
|
|
nsSVGContainerFrame *parent = static_cast<nsSVGContainerFrame*>(mParent);
|
2009-07-22 02:55:48 +04:00
|
|
|
|
2009-07-23 12:35:59 +04:00
|
|
|
float clipX, clipY, clipWidth, clipHeight;
|
2012-07-30 18:20:58 +04:00
|
|
|
content->GetAnimatedLengthValues(&clipX, &clipY, &clipWidth, &clipHeight, nullptr);
|
2006-09-19 20:35:29 +04:00
|
|
|
|
2012-06-30 15:20:46 +04:00
|
|
|
if (!nsSVGUtils::HitTestRect(parent->GetCanvasTM(FOR_HIT_TESTING),
|
2006-09-19 20:35:29 +04:00
|
|
|
clipX, clipY, clipWidth, clipHeight,
|
2008-08-25 13:23:54 +04:00
|
|
|
PresContext()->AppUnitsToDevPixels(aPoint.x),
|
|
|
|
PresContext()->AppUnitsToDevPixels(aPoint.y))) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2006-09-19 20:35:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-25 13:23:54 +04:00
|
|
|
return nsSVGInnerSVGFrameBase::GetFrameForPoint(aPoint);
|
2006-09-19 20:35:29 +04:00
|
|
|
}
|
|
|
|
|
2004-08-05 13:01:13 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISVGSVGFrame methods:
|
|
|
|
|
2012-02-04 17:58:46 +04:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGInnerSVGFrame::NotifyViewportOrTransformChanged(uint32_t aFlags)
|
2004-08-05 13:01:13 +04:00
|
|
|
{
|
2012-05-03 20:05:53 +04:00
|
|
|
// The dimensions of inner-<svg> frames are purely defined by their "width"
|
|
|
|
// and "height" attributes, and transform changes can only occur as a result
|
|
|
|
// of changes to their "width", "height", "viewBox" or "preserveAspectRatio"
|
|
|
|
// attributes. Changes to all of these attributes are handled in
|
|
|
|
// AttributeChanged(), so we should never be called.
|
|
|
|
NS_ERROR("Not called for nsSVGInnerSVGFrame");
|
2004-08-05 13:01:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2006-06-01 19:31:15 +04:00
|
|
|
// nsSVGContainerFrame methods:
|
2004-08-05 13:01:13 +04:00
|
|
|
|
2009-04-29 08:31:34 +04:00
|
|
|
gfxMatrix
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGInnerSVGFrame::GetCanvasTM(uint32_t aFor)
|
2004-08-05 13:01:13 +04:00
|
|
|
{
|
2012-06-30 15:20:46 +04:00
|
|
|
if (!(GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD)) {
|
|
|
|
if ((aFor == FOR_PAINTING && NS_SVGDisplayListPaintingEnabled()) ||
|
|
|
|
(aFor == FOR_HIT_TESTING && NS_SVGDisplayListHitTestingEnabled())) {
|
|
|
|
return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(this);
|
|
|
|
}
|
|
|
|
}
|
2005-09-07 02:30:40 +04:00
|
|
|
if (!mCanvasTM) {
|
2004-08-05 13:01:13 +04:00
|
|
|
NS_ASSERTION(mParent, "null parent");
|
|
|
|
|
2009-04-29 08:31:34 +04:00
|
|
|
nsSVGContainerFrame *parent = static_cast<nsSVGContainerFrame*>(mParent);
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement *content = static_cast<SVGSVGElement*>(mContent);
|
2004-08-05 13:01:13 +04:00
|
|
|
|
2012-06-30 15:20:46 +04:00
|
|
|
gfxMatrix tm = content->PrependLocalTransformsTo(parent->GetCanvasTM(aFor));
|
2009-04-29 08:31:34 +04:00
|
|
|
|
2011-09-26 01:04:32 +04:00
|
|
|
mCanvasTM = new gfxMatrix(tm);
|
2009-04-29 08:31:34 +04:00
|
|
|
}
|
2011-09-26 01:04:32 +04:00
|
|
|
return *mCanvasTM;
|
2004-08-05 13:01:13 +04:00
|
|
|
}
|
|
|
|
|
2012-05-17 08:05:09 +04:00
|
|
|
bool
|
|
|
|
nsSVGInnerSVGFrame::HasChildrenOnlyTransform(gfxMatrix *aTransform) const
|
|
|
|
{
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement *content = static_cast<SVGSVGElement*>(mContent);
|
2012-05-17 08:05:09 +04:00
|
|
|
|
|
|
|
if (content->HasViewBoxOrSyntheticViewBox()) {
|
|
|
|
// XXX Maybe return false if the transform is the identity transform?
|
|
|
|
if (aTransform) {
|
|
|
|
*aTransform = content->GetViewBoxTransform();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|