2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-26 04:58:59 -07:00
|
|
|
// Main header first:
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsSVGForeignObjectFrame.h"
|
|
|
|
|
2012-03-26 04:58:59 -07:00
|
|
|
// Keep others in (case-insensitive) order:
|
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "nsGkAtoms.h"
|
2014-02-27 15:04:46 -08:00
|
|
|
#include "nsNameSpaceManager.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsLayoutUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsRegion.h"
|
2012-03-20 05:15:55 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsSVGContainerFrame.h"
|
2012-03-20 05:15:53 -07:00
|
|
|
#include "nsSVGEffects.h"
|
2013-01-05 22:25:55 -08:00
|
|
|
#include "mozilla/dom/SVGForeignObjectElement.h"
|
2012-06-30 04:20:46 -07:00
|
|
|
#include "nsSVGIntegrationUtils.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsSVGOuterSVGFrame.h"
|
|
|
|
#include "nsSVGUtils.h"
|
2012-04-16 15:32:12 -07:00
|
|
|
#include "mozilla/AutoRestore.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
2013-01-05 22:25:55 -08:00
|
|
|
using namespace mozilla::dom;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2014-05-24 15:20:40 -07:00
|
|
|
nsContainerFrame*
|
2007-06-21 16:01:10 -07:00
|
|
|
NS_NewSVGForeignObjectFrame(nsIPresShell *aPresShell,
|
|
|
|
nsStyleContext *aContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return new (aPresShell) nsSVGForeignObjectFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGForeignObjectFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSVGForeignObjectFrame::nsSVGForeignObjectFrame(nsStyleContext* aContext)
|
|
|
|
: nsSVGForeignObjectFrameBase(aContext),
|
2011-10-17 07:59:28 -07:00
|
|
|
mInReflow(false)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-05-16 21:05:09 -07:00
|
|
|
AddStateBits(NS_FRAME_REFLOW_ROOT | NS_FRAME_MAY_BE_TRANSFORMED |
|
|
|
|
NS_FRAME_SVG_LAYOUT);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-01-09 08:35:24 -08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIFrame methods
|
2008-11-05 11:25:30 -08:00
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
NS_QUERYFRAME_HEAD(nsSVGForeignObjectFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsISVGChildFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsSVGForeignObjectFrameBase)
|
|
|
|
|
2013-03-19 18:47:48 -07:00
|
|
|
void
|
2014-05-24 15:20:40 -07:00
|
|
|
nsSVGForeignObjectFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2007-11-20 01:10:18 -08:00
|
|
|
{
|
2013-01-07 19:22:41 -08:00
|
|
|
NS_ASSERTION(aContent->IsSVG(nsGkAtoms::foreignObject),
|
|
|
|
"Content is not an SVG foreignObject!");
|
2009-01-19 10:31:34 -08:00
|
|
|
|
2013-03-19 18:47:48 -07:00
|
|
|
nsSVGForeignObjectFrameBase::Init(aContent, aParent, aPrevInFlow);
|
2013-07-12 00:13:07 -07:00
|
|
|
AddStateBits(aParent->GetStateBits() & NS_STATE_SVG_CLIPPATH_CHILD);
|
2012-04-16 15:32:12 -07:00
|
|
|
AddStateBits(NS_FRAME_FONT_INFLATION_CONTAINER |
|
|
|
|
NS_FRAME_FONT_INFLATION_FLOW_ROOT);
|
2013-07-12 00:13:07 -07:00
|
|
|
if (!(mState & NS_FRAME_IS_NONDISPLAY)) {
|
2012-07-17 10:03:51 -07:00
|
|
|
nsSVGUtils::GetOuterSVGFrame(this)->RegisterForeignObject(this);
|
|
|
|
}
|
2007-11-20 01:10:18 -08:00
|
|
|
}
|
|
|
|
|
2012-07-17 10:03:51 -07:00
|
|
|
void nsSVGForeignObjectFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
|
|
|
{
|
|
|
|
// Only unregister if we registered in the first place:
|
2013-07-12 00:13:07 -07:00
|
|
|
if (!(mState & NS_FRAME_IS_NONDISPLAY)) {
|
2012-07-17 10:03:51 -07:00
|
|
|
nsSVGUtils::GetOuterSVGFrame(this)->UnregisterForeignObject(this);
|
|
|
|
}
|
|
|
|
nsSVGForeignObjectFrameBase::DestroyFrom(aDestructRoot);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom *
|
|
|
|
nsSVGForeignObjectFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::svgForeignObjectFrame;
|
|
|
|
}
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGForeignObjectFrame::AttributeChanged(int32_t aNameSpaceID,
|
2007-06-21 16:01:10 -07:00
|
|
|
nsIAtom *aAttribute,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aModType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::width ||
|
|
|
|
aAttribute == nsGkAtoms::height) {
|
2013-04-25 02:18:42 -07:00
|
|
|
nsSVGEffects::InvalidateRenderingObservers(this);
|
2012-11-28 01:42:13 -08:00
|
|
|
nsSVGUtils::ScheduleReflowSVG(this);
|
2007-11-20 01:10:18 -08:00
|
|
|
// XXXjwatt: why mark intrinsic widths dirty? can't we just use eResize?
|
2007-05-05 04:11:07 -07:00
|
|
|
RequestReflow(nsIPresShell::eStyleChange);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if (aAttribute == nsGkAtoms::x ||
|
2013-04-25 02:18:42 -07:00
|
|
|
aAttribute == nsGkAtoms::y) {
|
|
|
|
// make sure our cached transform matrix gets (lazily) updated
|
|
|
|
mCanvasTM = nullptr;
|
|
|
|
nsSVGEffects::InvalidateRenderingObservers(this);
|
|
|
|
nsSVGUtils::ScheduleReflowSVG(this);
|
|
|
|
} else if (aAttribute == nsGkAtoms::transform) {
|
2013-05-23 00:04:21 -07:00
|
|
|
// We don't invalidate for transform changes (the layers code does that).
|
|
|
|
// Also note that SVGTransformableElement::GetAttributeChangeHint will
|
|
|
|
// return nsChangeHint_UpdateOverflow for "transform" attribute changes
|
|
|
|
// and cause DoApplyRenderingChangeToTree to make the SchedulePaint call.
|
2012-07-30 07:20:58 -07:00
|
|
|
mCanvasTM = nullptr;
|
2012-03-20 05:15:53 -07:00
|
|
|
} else if (aAttribute == nsGkAtoms::viewBox ||
|
|
|
|
aAttribute == nsGkAtoms::preserveAspectRatio) {
|
2013-04-25 02:18:42 -07:00
|
|
|
nsSVGEffects::InvalidateRenderingObservers(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-05-12 17:47:52 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSVGForeignObjectFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2013-07-12 00:13:07 -07:00
|
|
|
NS_ABORT_IF_FALSE(!(GetStateBits() & NS_FRAME_IS_NONDISPLAY),
|
2012-03-20 05:15:53 -07:00
|
|
|
"Should not have been called");
|
|
|
|
|
2012-03-20 05:15:53 -07:00
|
|
|
// Only InvalidateAndScheduleBoundsUpdate marks us with NS_FRAME_IS_DIRTY,
|
|
|
|
// so if that bit is still set we still have a resize pending. If we hit
|
|
|
|
// this assertion, then we should get the presShell to skip reflow roots
|
|
|
|
// that have a dirty parent since a reflow is going to come via the
|
|
|
|
// reflow root's parent anyway.
|
|
|
|
NS_ASSERTION(!(GetStateBits() & NS_FRAME_IS_DIRTY),
|
|
|
|
"Reflowing while a resize is pending is wasteful");
|
|
|
|
|
2012-07-21 17:01:44 -07:00
|
|
|
// ReflowSVG makes sure mRect is up to date before we're called.
|
2007-06-21 16:01:10 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(!aReflowState.parentReflowState,
|
|
|
|
"should only get reflow from being reflow root");
|
|
|
|
NS_ASSERTION(aReflowState.ComputedWidth() == GetSize().width &&
|
2007-08-02 11:08:05 -07:00
|
|
|
aReflowState.ComputedHeight() == GetSize().height,
|
2009-07-27 01:47:02 -07:00
|
|
|
"reflow roots should be reflowed at existing size and "
|
2007-03-22 10:30:00 -07:00
|
|
|
"svg.css should ensure we have no padding/border/margin");
|
|
|
|
|
|
|
|
DoReflow();
|
|
|
|
|
2014-07-24 01:30:07 -07:00
|
|
|
WritingMode wm = aReflowState.GetWritingMode();
|
|
|
|
LogicalSize finalSize(wm, aReflowState.ComputedISize(),
|
|
|
|
aReflowState.ComputedBSize());
|
|
|
|
aDesiredSize.SetSize(wm, finalSize);
|
2010-10-06 21:25:46 -07:00
|
|
|
aDesiredSize.SetOverflowAreasToDesiredBounds();
|
2007-03-22 10:30:00 -07:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2013-02-14 03:12:27 -08:00
|
|
|
void
|
2012-07-20 11:12:29 -07:00
|
|
|
nsSVGForeignObjectFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
if (!static_cast<const nsSVGElement*>(mContent)->HasValidDimensions()) {
|
2013-02-14 03:12:27 -08:00
|
|
|
return;
|
2012-07-20 11:12:29 -07:00
|
|
|
}
|
2013-02-14 03:08:08 -08:00
|
|
|
BuildDisplayListForNonBlockChildren(aBuilder, aDirtyRect, aLists);
|
2012-07-20 11:12:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-12-29 22:50:17 -08:00
|
|
|
nsSVGForeignObjectFrame::IsSVGTransformed(Matrix *aOwnTransform,
|
|
|
|
Matrix *aFromParentTransform) const
|
2012-07-20 11:12:29 -07:00
|
|
|
{
|
|
|
|
bool foundTransform = false;
|
|
|
|
|
|
|
|
// Check if our parent has children-only transforms:
|
|
|
|
nsIFrame *parent = GetParent();
|
|
|
|
if (parent &&
|
|
|
|
parent->IsFrameOfType(nsIFrame::eSVG | nsIFrame::eSVGContainer)) {
|
|
|
|
foundTransform = static_cast<nsSVGContainerFrame*>(parent)->
|
|
|
|
HasChildrenOnlyTransform(aFromParentTransform);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGElement *content = static_cast<nsSVGElement*>(mContent);
|
2013-04-14 15:56:34 -07:00
|
|
|
nsSVGAnimatedTransformList* transformList =
|
2013-04-14 00:17:36 -07:00
|
|
|
content->GetAnimatedTransformList();
|
2013-04-17 13:28:59 -07:00
|
|
|
if ((transformList && transformList->HasTransform()) ||
|
|
|
|
content->GetAnimateMotionTransform()) {
|
2012-07-20 11:12:29 -07:00
|
|
|
if (aOwnTransform) {
|
2013-12-29 15:35:53 -08:00
|
|
|
*aOwnTransform = gfx::ToMatrix(content->PrependLocalTransformsTo(gfxMatrix(),
|
|
|
|
nsSVGElement::eUserSpaceToParent));
|
2012-07-20 11:12:29 -07:00
|
|
|
}
|
|
|
|
foundTransform = true;
|
|
|
|
}
|
|
|
|
return foundTransform;
|
|
|
|
}
|
|
|
|
|
2014-02-19 14:34:31 -08:00
|
|
|
nsresult
|
2012-03-02 00:28:59 -08:00
|
|
|
nsSVGForeignObjectFrame::PaintSVG(nsRenderingContext *aContext,
|
2013-09-11 00:27:45 -07:00
|
|
|
const nsIntRect *aDirtyRect,
|
|
|
|
nsIFrame* aTransformRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-20 11:12:29 -07:00
|
|
|
NS_ASSERTION(!NS_SVGDisplayListPaintingEnabled() ||
|
2013-07-12 00:13:07 -07:00
|
|
|
(mState & NS_FRAME_IS_NONDISPLAY),
|
2012-07-20 11:12:29 -07:00
|
|
|
"If display lists are enabled, only painting of non-display "
|
|
|
|
"SVG should take this code path");
|
|
|
|
|
2007-06-25 01:31:31 -07:00
|
|
|
if (IsDisabled())
|
|
|
|
return NS_OK;
|
|
|
|
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame* kid = GetFirstPrincipalChild();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!kid)
|
|
|
|
return NS_OK;
|
|
|
|
|
2013-09-11 00:27:45 -07:00
|
|
|
gfxMatrix canvasTM = GetCanvasTM(FOR_PAINTING, aTransformRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-30 04:20:46 -07:00
|
|
|
if (canvasTM.IsSingular()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_WARNING("Can't render foreignObject element!");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-02-10 04:33:46 -08:00
|
|
|
nsRect kidDirtyRect = kid->GetVisualOverflowRect();
|
|
|
|
|
2008-12-06 07:22:01 -08:00
|
|
|
/* Check if we need to draw anything. */
|
2012-01-01 07:47:27 -08:00
|
|
|
if (aDirtyRect) {
|
2012-07-20 11:12:29 -07:00
|
|
|
NS_ASSERTION(!NS_SVGDisplayListPaintingEnabled() ||
|
2013-07-12 00:13:07 -07:00
|
|
|
(mState & NS_FRAME_IS_NONDISPLAY),
|
2012-07-20 11:12:29 -07:00
|
|
|
"Display lists handle dirty rect intersection test");
|
2012-02-10 04:33:46 -08:00
|
|
|
// Transform the dirty rect into app units in our userspace.
|
2012-06-30 04:20:46 -07:00
|
|
|
gfxMatrix invmatrix = canvasTM;
|
2014-07-11 00:06:39 -07:00
|
|
|
DebugOnly<bool> ok = invmatrix.Invert();
|
|
|
|
NS_ASSERTION(ok, "inverse of non-singular matrix should be non-singular");
|
2012-02-10 04:33:46 -08:00
|
|
|
|
|
|
|
gfxRect transDirtyRect = gfxRect(aDirtyRect->x, aDirtyRect->y,
|
|
|
|
aDirtyRect->width, aDirtyRect->height);
|
|
|
|
transDirtyRect = invmatrix.TransformBounds(transDirtyRect);
|
|
|
|
|
|
|
|
kidDirtyRect.IntersectRect(kidDirtyRect,
|
|
|
|
nsLayoutUtils::RoundGfxRectToAppRect(transDirtyRect,
|
|
|
|
PresContext()->AppUnitsPerCSSPixel()));
|
|
|
|
|
|
|
|
// XXX after bug 614732 is fixed, we will compare mRect with aDirtyRect,
|
|
|
|
// not with kidDirtyRect. I.e.
|
2012-08-22 08:56:38 -07:00
|
|
|
// int32_t appUnitsPerDevPx = PresContext()->AppUnitsPerDevPixel();
|
2012-02-10 04:33:46 -08:00
|
|
|
// mRect.ToOutsidePixels(appUnitsPerDevPx).Intersects(*aDirtyRect)
|
|
|
|
if (kidDirtyRect.IsEmpty())
|
2012-01-01 07:47:27 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-12-06 07:22:01 -08:00
|
|
|
|
2012-03-02 00:28:59 -08:00
|
|
|
gfxContext *gfx = aContext->ThebesContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
gfx->Save();
|
2007-04-30 02:02:38 -07:00
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
if (StyleDisplay()->IsScrollableOverflow()) {
|
2007-05-23 01:39:00 -07:00
|
|
|
float x, y, width, height;
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsSVGElement*>(mContent)->
|
2012-07-30 07:20:58 -07:00
|
|
|
GetAnimatedLengthValues(&x, &y, &width, &height, nullptr);
|
2007-04-30 02:02:38 -07:00
|
|
|
|
2009-06-17 13:51:40 -07:00
|
|
|
gfxRect clipRect =
|
2009-06-18 04:31:25 -07:00
|
|
|
nsSVGUtils::GetClipRectForFrame(this, 0.0f, 0.0f, width, height);
|
2012-06-30 04:20:46 -07:00
|
|
|
nsSVGUtils::SetClipRect(gfx, canvasTM, clipRect);
|
2007-04-30 02:02:38 -07:00
|
|
|
}
|
|
|
|
|
2012-06-30 04:20:46 -07:00
|
|
|
// SVG paints in CSS px, but normally frames paint in dev pixels. Here we
|
|
|
|
// multiply a CSS-px-to-dev-pixel factor onto canvasTM so our children paint
|
|
|
|
// correctly.
|
|
|
|
float cssPxPerDevPx = PresContext()->
|
|
|
|
AppUnitsToFloatCSSPixels(PresContext()->AppUnitsPerDevPixel());
|
|
|
|
gfxMatrix canvasTMForChildren = canvasTM;
|
|
|
|
canvasTMForChildren.Scale(cssPxPerDevPx, cssPxPerDevPx);
|
|
|
|
|
|
|
|
gfx->Multiply(canvasTMForChildren);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t flags = nsLayoutUtils::PAINT_IN_TRANSFORM;
|
2012-03-02 00:28:59 -08:00
|
|
|
if (SVGAutoRenderState::IsPaintingToWindow(aContext)) {
|
2010-10-14 18:03:45 -07:00
|
|
|
flags |= nsLayoutUtils::PAINT_TO_WINDOW;
|
|
|
|
}
|
2012-03-02 00:28:59 -08:00
|
|
|
nsresult rv = nsLayoutUtils::PaintFrame(aContext, kid, nsRegion(kidDirtyRect),
|
2010-10-14 18:03:45 -07:00
|
|
|
NS_RGBA(0,0,0,0), flags);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
gfx->Restore();
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-02-19 14:34:31 -08:00
|
|
|
nsIFrame*
|
2008-08-25 02:23:54 -07:00
|
|
|
nsSVGForeignObjectFrame::GetFrameForPoint(const nsPoint &aPoint)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-20 11:12:29 -07:00
|
|
|
NS_ASSERTION(!NS_SVGDisplayListHitTestingEnabled() ||
|
2013-07-12 00:13:07 -07:00
|
|
|
(mState & NS_FRAME_IS_NONDISPLAY),
|
2012-07-20 11:12:29 -07:00
|
|
|
"If display lists are enabled, only hit-testing of a "
|
|
|
|
"clipPath's contents should take this code path");
|
|
|
|
|
2013-07-12 00:13:07 -07:00
|
|
|
if (IsDisabled() || (GetStateBits() & NS_FRAME_IS_NONDISPLAY))
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-06-25 01:31:31 -07:00
|
|
|
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame* kid = GetFirstPrincipalChild();
|
2009-06-18 04:31:25 -07:00
|
|
|
if (!kid)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-06-18 04:31:25 -07:00
|
|
|
|
|
|
|
float x, y, width, height;
|
|
|
|
static_cast<nsSVGElement*>(mContent)->
|
2012-07-30 07:20:58 -07:00
|
|
|
GetAnimatedLengthValues(&x, &y, &width, &height, nullptr);
|
2009-06-18 04:31:25 -07:00
|
|
|
|
2014-07-11 00:06:39 -07:00
|
|
|
gfxMatrix tm = GetCanvasTM(FOR_HIT_TESTING);
|
|
|
|
if (!tm.Invert()) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2014-07-11 00:06:39 -07:00
|
|
|
}
|
|
|
|
|
2009-06-18 04:31:25 -07:00
|
|
|
// Convert aPoint from app units in canvas space to user space:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-05 11:19:13 -07:00
|
|
|
gfxPoint pt = gfxPoint(aPoint.x, aPoint.y) / PresContext()->AppUnitsPerCSSPixel();
|
2009-06-18 04:31:25 -07:00
|
|
|
pt = tm.Transform(pt);
|
|
|
|
|
|
|
|
if (!gfxRect(0.0f, 0.0f, width, height).Contains(pt))
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-06-18 04:31:25 -07:00
|
|
|
|
|
|
|
// Convert pt to app units in *local* space:
|
|
|
|
|
|
|
|
pt = pt * nsPresContext::AppUnitsPerCSSPixel();
|
|
|
|
nsPoint point = nsPoint(NSToIntRound(pt.x), NSToIntRound(pt.y));
|
|
|
|
|
2010-07-15 01:10:59 -07:00
|
|
|
nsIFrame *frame = nsLayoutUtils::GetFrameForPoint(kid, point);
|
|
|
|
if (frame && nsSVGUtils::HitTestClip(this, aPoint))
|
|
|
|
return frame;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-02-19 14:34:31 -08:00
|
|
|
nsRect
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSVGForeignObjectFrame::GetCoveredRegion()
|
|
|
|
{
|
2012-07-23 04:00:40 -07:00
|
|
|
float x, y, w, h;
|
2013-01-05 22:25:55 -08:00
|
|
|
static_cast<SVGForeignObjectElement*>(mContent)->
|
2012-07-30 07:20:58 -07:00
|
|
|
GetAnimatedLengthValues(&x, &y, &w, &h, nullptr);
|
2012-07-23 04:00:40 -07:00
|
|
|
if (w < 0.0f) w = 0.0f;
|
|
|
|
if (h < 0.0f) h = 0.0f;
|
|
|
|
// GetCanvasTM includes the x,y translation
|
2013-02-10 22:22:18 -08:00
|
|
|
return nsSVGUtils::ToCanvasBounds(gfxRect(0.0, 0.0, w, h),
|
|
|
|
GetCanvasTM(FOR_OUTERSVG_TM),
|
|
|
|
PresContext());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-20 05:15:53 -07:00
|
|
|
void
|
2012-07-21 17:01:44 -07:00
|
|
|
nsSVGForeignObjectFrame::ReflowSVG()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-21 17:01:44 -07:00
|
|
|
NS_ASSERTION(nsSVGUtils::OuterSVGIsCallingReflowSVG(this),
|
|
|
|
"This call is probably a wasteful mistake");
|
2012-03-20 05:15:53 -07:00
|
|
|
|
2013-07-12 00:13:07 -07:00
|
|
|
NS_ABORT_IF_FALSE(!(GetStateBits() & NS_FRAME_IS_NONDISPLAY),
|
2012-07-21 17:01:44 -07:00
|
|
|
"ReflowSVG mechanism not designed for this");
|
2012-03-20 05:15:53 -07:00
|
|
|
|
2012-07-21 17:01:44 -07:00
|
|
|
if (!nsSVGUtils::NeedsReflowSVG(this)) {
|
2012-03-20 05:15:53 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We update mRect before the DoReflow call so that DoReflow uses the
|
|
|
|
// correct dimensions:
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-06-21 16:01:10 -07:00
|
|
|
float x, y, w, h;
|
2013-01-05 22:25:55 -08:00
|
|
|
static_cast<SVGForeignObjectElement*>(mContent)->
|
2012-07-30 07:20:58 -07:00
|
|
|
GetAnimatedLengthValues(&x, &y, &w, &h, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-06-25 01:31:31 -07:00
|
|
|
// If mRect's width or height are negative, reflow blows up! We must clamp!
|
|
|
|
if (w < 0.0f) w = 0.0f;
|
|
|
|
if (h < 0.0f) h = 0.0f;
|
|
|
|
|
2012-02-10 04:33:46 -08:00
|
|
|
mRect = nsLayoutUtils::RoundGfxRectToAppRect(
|
2012-05-16 03:04:31 -07:00
|
|
|
gfxRect(x, y, w, h),
|
2012-02-16 22:07:51 -08:00
|
|
|
PresContext()->AppUnitsPerCSSPixel());
|
2012-02-10 04:33:46 -08:00
|
|
|
|
2012-03-20 05:15:53 -07:00
|
|
|
// Fully mark our kid dirty so that it gets resized if necessary
|
|
|
|
// (NS_FRAME_HAS_DIRTY_CHILDREN isn't enough in that case):
|
|
|
|
nsIFrame* kid = GetFirstPrincipalChild();
|
|
|
|
kid->AddStateBits(NS_FRAME_IS_DIRTY);
|
2009-04-21 16:53:52 -07:00
|
|
|
|
2012-03-20 05:15:53 -07:00
|
|
|
// Make sure to not allow interrupts if we're not being reflown as a root:
|
2009-04-21 16:53:52 -07:00
|
|
|
nsPresContext::InterruptPreventer noInterrupts(PresContext());
|
2012-03-20 05:15:53 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
DoReflow();
|
|
|
|
|
2012-05-16 21:05:09 -07:00
|
|
|
if (mState & NS_FRAME_FIRST_REFLOW) {
|
|
|
|
// Make sure we have our filter property (if any) before calling
|
|
|
|
// FinishAndStoreOverflow (subsequent filter changes are handled off
|
|
|
|
// nsChangeHint_UpdateEffects):
|
|
|
|
nsSVGEffects::UpdateEffects(this);
|
|
|
|
}
|
|
|
|
|
Bug 997735 - Invalidate when reflowing SVG containers. r=roc
Without this patch, when changing the x/y attributes of svg:use, innerSVG and foreignObject, we were relying on the transform changes of the children to trigger the right invalidations. However, changes to those attributes can also change the filter region. And there's a difference between moving children in a fixed filter region and moving the filter region along with the children: In the first case, we wouldn't need to invalidate anything outside the old filter region, because those parts of the children would be clipped away anyway. But when the filter region changes, we need to invalidate both the old and the new filter region. Also, when the filter has primitives without inputs, e.g. flood or turbulence, the filtered frame needs to be invalidate even if it has no children.
2014-04-23 02:48:07 -07:00
|
|
|
// If we have a filter, we need to invalidate ourselves because filter
|
|
|
|
// output can change even if none of our descendants need repainting.
|
|
|
|
if (StyleSVGReset()->HasFilters()) {
|
|
|
|
InvalidateFrame();
|
|
|
|
}
|
|
|
|
|
2012-05-16 21:05:09 -07:00
|
|
|
// TODO: once we support |overflow:visible| on foreignObject, then we will
|
|
|
|
// need to take account of our descendants here.
|
|
|
|
nsRect overflow = nsRect(nsPoint(0,0), mRect.Size());
|
|
|
|
nsOverflowAreas overflowAreas(overflow, overflow);
|
|
|
|
FinishAndStoreOverflow(overflowAreas, mRect.Size());
|
|
|
|
|
2012-03-20 05:15:53 -07:00
|
|
|
// Now unset the various reflow bits:
|
2007-03-22 10:30:00 -07:00
|
|
|
mState &= ~(NS_FRAME_FIRST_REFLOW | NS_FRAME_IS_DIRTY |
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
|
|
|
}
|
|
|
|
|
2008-01-25 01:27:03 -08:00
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGForeignObjectFrame::NotifySVGChanged(uint32_t aFlags)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-03-11 08:53:36 -07:00
|
|
|
NS_ABORT_IF_FALSE(aFlags & (TRANSFORM_CHANGED | COORD_CONTEXT_CHANGED),
|
|
|
|
"Invalidation logic may need adjusting");
|
|
|
|
|
2012-03-20 05:15:53 -07:00
|
|
|
bool needNewBounds = false; // i.e. mRect or visual overflow rect
|
|
|
|
bool needReflow = false;
|
|
|
|
bool needNewCanvasTM = false;
|
2008-01-25 01:27:03 -08:00
|
|
|
|
2012-03-20 05:15:53 -07:00
|
|
|
if (aFlags & COORD_CONTEXT_CHANGED) {
|
2013-01-05 22:25:55 -08:00
|
|
|
SVGForeignObjectElement *fO =
|
|
|
|
static_cast<SVGForeignObjectElement*>(mContent);
|
2012-02-01 08:25:44 -08:00
|
|
|
// Coordinate context changes affect mCanvasTM if we have a
|
|
|
|
// percentage 'x' or 'y'
|
2013-01-05 22:25:55 -08:00
|
|
|
if (fO->mLengthAttributes[SVGForeignObjectElement::ATTR_X].IsPercentage() ||
|
|
|
|
fO->mLengthAttributes[SVGForeignObjectElement::ATTR_Y].IsPercentage()) {
|
2012-03-20 05:15:53 -07:00
|
|
|
needNewBounds = true;
|
|
|
|
needNewCanvasTM = true;
|
2012-02-01 08:25:44 -08:00
|
|
|
}
|
|
|
|
// Our coordinate context's width/height has changed. If we have a
|
|
|
|
// percentage width/height our dimensions will change so we must reflow.
|
2013-01-05 22:25:55 -08:00
|
|
|
if (fO->mLengthAttributes[SVGForeignObjectElement::ATTR_WIDTH].IsPercentage() ||
|
|
|
|
fO->mLengthAttributes[SVGForeignObjectElement::ATTR_HEIGHT].IsPercentage()) {
|
2012-03-20 05:15:53 -07:00
|
|
|
needNewBounds = true;
|
|
|
|
needReflow = true;
|
2008-01-25 01:27:03 -08:00
|
|
|
}
|
2007-11-20 01:10:18 -08:00
|
|
|
}
|
|
|
|
|
2012-03-20 05:15:53 -07:00
|
|
|
if (aFlags & TRANSFORM_CHANGED) {
|
2012-06-23 09:36:46 -07:00
|
|
|
if (mCanvasTM && mCanvasTM->IsSingular()) {
|
|
|
|
needNewBounds = true; // old bounds are bogus
|
|
|
|
}
|
2012-03-20 05:15:53 -07:00
|
|
|
needNewCanvasTM = true;
|
|
|
|
// In an ideal world we would reflow when our CTM changes. This is because
|
|
|
|
// glyph metrics do not necessarily scale uniformly with change in scale
|
|
|
|
// and, as a result, CTM changes may require text to break at different
|
|
|
|
// points. The problem would be how to keep performance acceptable when
|
|
|
|
// e.g. the transform of an ancestor is animated.
|
|
|
|
// We also seem to get some sort of infinite loop post bug 421584 if we
|
|
|
|
// reflow.
|
|
|
|
}
|
|
|
|
|
2012-06-23 09:36:46 -07:00
|
|
|
if (needNewBounds) {
|
|
|
|
// 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.
|
2012-07-21 17:01:44 -07:00
|
|
|
nsSVGUtils::ScheduleReflowSVG(this);
|
2012-03-20 05:15:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we're called while the PresShell is handling reflow events then we
|
|
|
|
// must have been called as a result of the NotifyViewportChange() call in
|
|
|
|
// our nsSVGOuterSVGFrame's Reflow() method. We must not call RequestReflow
|
|
|
|
// at this point (i.e. during reflow) because it could confuse the
|
|
|
|
// PresShell and prevent it from reflowing us properly in future. Besides
|
|
|
|
// that, nsSVGOuterSVGFrame::DidReflow will take care of reflowing us
|
|
|
|
// synchronously, so there's no need.
|
|
|
|
if (needReflow && !PresContext()->PresShell()->IsReflowLocked()) {
|
|
|
|
RequestReflow(nsIPresShell::eResize);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (needNewCanvasTM) {
|
|
|
|
// Do this after calling InvalidateAndScheduleBoundsUpdate in case we
|
|
|
|
// change the code and it needs to use it.
|
2012-07-30 07:20:58 -07:00
|
|
|
mCanvasTM = nullptr;
|
2008-01-25 01:27:03 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-04-16 01:23:48 -07:00
|
|
|
SVGBBox
|
2013-12-29 22:50:07 -08:00
|
|
|
nsSVGForeignObjectFrame::GetBBoxContribution(const Matrix &aToBBoxUserspace,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFlags)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-01-05 22:25:55 -08:00
|
|
|
SVGForeignObjectElement *content =
|
|
|
|
static_cast<SVGForeignObjectElement*>(mContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
float x, y, w, h;
|
2012-07-30 07:20:58 -07:00
|
|
|
content->GetAnimatedLengthValues(&x, &y, &w, &h, nullptr);
|
2007-06-21 16:01:10 -07:00
|
|
|
|
2007-06-25 01:31:31 -07:00
|
|
|
if (w < 0.0f) w = 0.0f;
|
|
|
|
if (h < 0.0f) h = 0.0f;
|
|
|
|
|
2009-04-28 21:31:34 -07:00
|
|
|
if (aToBBoxUserspace.IsSingular()) {
|
|
|
|
// XXX ReportToConsole
|
2012-04-16 01:23:48 -07:00
|
|
|
return SVGBBox();
|
2009-04-28 21:31:34 -07:00
|
|
|
}
|
2013-12-29 22:50:07 -08:00
|
|
|
return aToBBoxUserspace.TransformBounds(gfx::Rect(0.0, 0.0, w, h));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2009-04-28 21:31:34 -07:00
|
|
|
gfxMatrix
|
2013-09-11 00:27:45 -07:00
|
|
|
nsSVGForeignObjectFrame::GetCanvasTM(uint32_t aFor, nsIFrame* aTransformRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-09-11 00:27:45 -07:00
|
|
|
if (!(GetStateBits() & NS_FRAME_IS_NONDISPLAY) && !aTransformRoot) {
|
2014-07-05 11:19:13 -07:00
|
|
|
if (aFor == FOR_PAINTING && NS_SVGDisplayListPaintingEnabled()) {
|
2012-06-30 04:20:46 -07:00
|
|
|
return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(this);
|
|
|
|
}
|
2014-07-05 11:19:13 -07:00
|
|
|
if (aFor == FOR_HIT_TESTING && NS_SVGDisplayListHitTestingEnabled()) {
|
|
|
|
return gfxMatrix();
|
|
|
|
}
|
2012-06-30 04:20:46 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!mCanvasTM) {
|
2014-05-24 15:20:41 -07:00
|
|
|
NS_ASSERTION(GetParent(), "null parent");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-05-24 15:20:41 -07:00
|
|
|
nsSVGContainerFrame *parent = static_cast<nsSVGContainerFrame*>(GetParent());
|
2013-01-05 22:25:55 -08:00
|
|
|
SVGForeignObjectElement *content =
|
|
|
|
static_cast<SVGForeignObjectElement*>(mContent);
|
2009-04-28 21:31:34 -07:00
|
|
|
|
2013-12-26 12:13:57 -08:00
|
|
|
gfxMatrix tm = content->PrependLocalTransformsTo(
|
|
|
|
this == aTransformRoot ? gfxMatrix() :
|
|
|
|
parent->GetCanvasTM(aFor, aTransformRoot));
|
2009-04-28 21:31:34 -07:00
|
|
|
|
2013-12-26 12:13:57 -08:00
|
|
|
mCanvasTM = new gfxMatrix(tm);
|
2009-04-28 21:31:34 -07:00
|
|
|
}
|
2011-09-25 14:04:32 -07:00
|
|
|
return *mCanvasTM;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation helpers
|
|
|
|
|
2007-05-05 04:11:07 -07:00
|
|
|
void nsSVGForeignObjectFrame::RequestReflow(nsIPresShell::IntrinsicDirty aType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-05-05 04:11:07 -07:00
|
|
|
if (GetStateBits() & NS_FRAME_FIRST_REFLOW)
|
2012-07-21 17:01:44 -07:00
|
|
|
// If we haven't had a ReflowSVG() yet, nothing to do.
|
2007-05-05 04:11:07 -07:00
|
|
|
return;
|
|
|
|
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame* kid = GetFirstPrincipalChild();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!kid)
|
|
|
|
return;
|
2007-05-05 04:11:07 -07:00
|
|
|
|
2007-05-06 12:16:51 -07:00
|
|
|
PresContext()->PresShell()->FrameNeedsReflow(kid, aType, NS_FRAME_IS_DIRTY);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGForeignObjectFrame::DoReflow()
|
|
|
|
{
|
2011-02-17 16:33:30 -08:00
|
|
|
// Skip reflow if we're zero-sized, unless this is our first reflow.
|
|
|
|
if (IsDisabled() &&
|
|
|
|
!(GetStateBits() & NS_FRAME_FIRST_REFLOW))
|
2007-06-25 01:31:31 -07:00
|
|
|
return;
|
|
|
|
|
2007-03-30 14:11:41 -07:00
|
|
|
nsPresContext *presContext = PresContext();
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame* kid = GetFirstPrincipalChild();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!kid)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// initiate a synchronous reflow here and now:
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRefPtr<nsRenderingContext> renderingContext =
|
2014-04-14 21:30:25 -07:00
|
|
|
presContext->PresShell()->CreateReferenceRenderingContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mInReflow = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-24 01:28:46 -07:00
|
|
|
WritingMode wm = kid->GetWritingMode();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLReflowState reflowState(presContext, kid,
|
|
|
|
renderingContext,
|
2014-07-24 01:28:46 -07:00
|
|
|
LogicalSize(wm, GetLogicalSize(wm).ISize(wm),
|
|
|
|
NS_UNCONSTRAINEDSIZE));
|
2013-12-31 05:50:31 -08:00
|
|
|
nsHTMLReflowMetrics desiredSize(reflowState);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsReflowStatus status;
|
|
|
|
|
2012-03-20 05:15:53 -07:00
|
|
|
// We don't use mRect.height above because that tells the child to do
|
2007-03-22 10:30:00 -07:00
|
|
|
// page/column breaking at that height.
|
2013-12-27 09:59:21 -08:00
|
|
|
NS_ASSERTION(reflowState.ComputedPhysicalBorderPadding() == nsMargin(0, 0, 0, 0) &&
|
|
|
|
reflowState.ComputedPhysicalMargin() == nsMargin(0, 0, 0, 0),
|
2012-02-06 15:52:01 -08:00
|
|
|
"style system should ensure that :-moz-svg-foreign-content "
|
2007-03-22 10:30:00 -07:00
|
|
|
"does not get styled");
|
2012-03-20 05:15:53 -07:00
|
|
|
NS_ASSERTION(reflowState.ComputedWidth() == mRect.width,
|
2007-03-22 10:30:00 -07:00
|
|
|
"reflow state made child wrong size");
|
2012-03-20 05:15:53 -07:00
|
|
|
reflowState.SetComputedHeight(mRect.height);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
ReflowChild(kid, presContext, desiredSize, reflowState, 0, 0,
|
|
|
|
NS_FRAME_NO_MOVE_FRAME, status);
|
2013-12-27 09:59:52 -08:00
|
|
|
NS_ASSERTION(mRect.width == desiredSize.Width() &&
|
|
|
|
mRect.height == desiredSize.Height(), "unexpected size");
|
2014-01-16 17:34:44 -08:00
|
|
|
FinishReflowChild(kid, presContext, desiredSize, &reflowState, 0, 0,
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_FRAME_NO_MOVE_FRAME);
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mInReflow = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-28 22:39:33 -07:00
|
|
|
nsRect
|
|
|
|
nsSVGForeignObjectFrame::GetInvalidRegion()
|
|
|
|
{
|
|
|
|
nsIFrame* kid = GetFirstPrincipalChild();
|
|
|
|
if (kid->HasInvalidFrameInSubtree()) {
|
|
|
|
gfxRect r(mRect.x, mRect.y, mRect.width, mRect.height);
|
|
|
|
r.Scale(1.0 / nsPresContext::AppUnitsPerCSSPixel());
|
2013-02-10 22:22:18 -08:00
|
|
|
nsRect rect = nsSVGUtils::ToCanvasBounds(r, GetCanvasTM(FOR_PAINTING), PresContext());
|
2012-08-28 22:39:33 -07:00
|
|
|
rect = nsSVGUtils::GetPostFilterVisualOverflowRect(this, rect);
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
return nsRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
|