2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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/. */
|
2006-06-01 19:31:15 +04:00
|
|
|
|
2012-03-26 15:58:59 +04:00
|
|
|
// Main header first:
|
2006-06-01 19:31:15 +04:00
|
|
|
#include "nsSVGContainerFrame.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
|
|
|
|
// Keep others in (case-insensitive) order:
|
2017-12-11 18:37:59 +03:00
|
|
|
#include "ImgDrawResult.h"
|
2017-02-13 06:21:33 +03:00
|
|
|
#include "mozilla/RestyleManager.h"
|
2013-04-24 13:13:28 +04:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2017-08-30 16:14:46 +03:00
|
|
|
#include "SVGObserverUtils.h"
|
2018-12-21 11:58:14 +03:00
|
|
|
#include "SVGElement.h"
|
2006-06-01 19:31:15 +04:00
|
|
|
#include "nsSVGUtils.h"
|
2013-04-15 02:56:34 +04:00
|
|
|
#include "nsSVGAnimatedTransformList.h"
|
2013-12-20 20:38:51 +04:00
|
|
|
#include "SVGTextFrame.h"
|
2012-05-17 08:05:09 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2016-11-29 22:41:16 +03:00
|
|
|
using namespace mozilla::image;
|
2006-06-01 19:31:15 +04:00
|
|
|
|
2009-04-29 08:31:34 +04:00
|
|
|
NS_QUERYFRAME_HEAD(nsSVGContainerFrame)
|
2018-12-07 23:00:18 +03:00
|
|
|
NS_QUERYFRAME_ENTRY(nsSVGContainerFrame)
|
2016-04-18 09:56:50 +03:00
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
|
2009-04-29 08:31:34 +04:00
|
|
|
|
2009-01-12 22:20:59 +03:00
|
|
|
NS_QUERYFRAME_HEAD(nsSVGDisplayContainerFrame)
|
2018-12-07 23:00:18 +03:00
|
|
|
NS_QUERYFRAME_ENTRY(nsSVGDisplayContainerFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsSVGDisplayableFrame)
|
2009-01-12 22:20:59 +03:00
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsSVGContainerFrame)
|
2006-06-01 19:31:15 +04:00
|
|
|
|
|
|
|
nsIFrame* NS_NewSVGContainerFrame(nsIPresShell* aPresShell,
|
2018-03-22 21:20:41 +03:00
|
|
|
ComputedStyle* aStyle) {
|
2017-04-30 18:30:08 +03:00
|
|
|
nsIFrame* frame = new (aPresShell)
|
2018-03-22 21:20:41 +03:00
|
|
|
nsSVGContainerFrame(aStyle, nsSVGContainerFrame::kClassID);
|
2012-03-10 23:28:06 +04:00
|
|
|
// If we were called directly, then the frame is for a <defs> or
|
|
|
|
// an unknown element type. In both cases we prevent the content
|
|
|
|
// from displaying directly.
|
2013-07-12 11:13:07 +04:00
|
|
|
frame->AddStateBits(NS_FRAME_IS_NONDISPLAY);
|
2012-03-10 23:28:06 +04:00
|
|
|
return frame;
|
2006-06-01 19:31:15 +04:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGContainerFrame)
|
|
|
|
|
2011-08-25 00:54:30 +04:00
|
|
|
void nsSVGContainerFrame::AppendFrames(ChildListID aListID,
|
2009-07-30 21:23:32 +04:00
|
|
|
nsFrameList& aFrameList) {
|
2017-07-06 15:00:35 +03:00
|
|
|
InsertFrames(aListID, mFrames.LastChild(), aFrameList);
|
2006-06-01 19:31:15 +04:00
|
|
|
}
|
|
|
|
|
2011-08-25 00:54:30 +04:00
|
|
|
void nsSVGContainerFrame::InsertFrames(ChildListID aListID,
|
2006-06-01 19:31:15 +04:00
|
|
|
nsIFrame* aPrevFrame,
|
2009-07-30 21:23:32 +04:00
|
|
|
nsFrameList& aFrameList) {
|
2011-08-25 00:54:30 +04:00
|
|
|
NS_ASSERTION(aListID == kPrincipalList, "unexpected child list");
|
2006-06-29 06:32:36 +04:00
|
|
|
NS_ASSERTION(!aPrevFrame || aPrevFrame->GetParent() == this,
|
|
|
|
"inserting after sibling frame with different parent");
|
|
|
|
|
2006-06-01 19:31:15 +04:00
|
|
|
mFrames.InsertFrames(this, aPrevFrame, aFrameList);
|
|
|
|
}
|
|
|
|
|
2011-08-25 00:54:30 +04:00
|
|
|
void nsSVGContainerFrame::RemoveFrame(ChildListID aListID,
|
2006-06-01 19:31:15 +04:00
|
|
|
nsIFrame* aOldFrame) {
|
2011-08-25 00:54:30 +04:00
|
|
|
NS_ASSERTION(aListID == kPrincipalList, "unexpected child list");
|
2006-06-29 06:32:36 +04:00
|
|
|
|
2009-09-18 15:09:36 +04:00
|
|
|
mFrames.DestroyFrame(aOldFrame);
|
2006-06-01 19:31:15 +04:00
|
|
|
}
|
|
|
|
|
2016-05-04 03:27:43 +03:00
|
|
|
bool nsSVGContainerFrame::ComputeCustomOverflow(
|
|
|
|
nsOverflowAreas& aOverflowAreas) {
|
2013-07-12 11:13:07 +04:00
|
|
|
if (mState & NS_FRAME_IS_NONDISPLAY) {
|
2012-05-17 08:05:09 +04:00
|
|
|
// We don't maintain overflow rects.
|
|
|
|
// XXX It would have be better if the restyle request hadn't even happened.
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-04 03:27:43 +03:00
|
|
|
return nsContainerFrame::ComputeCustomOverflow(aOverflowAreas);
|
2012-05-17 08:05:09 +04:00
|
|
|
}
|
|
|
|
|
2013-07-30 03:47:30 +04:00
|
|
|
/**
|
2013-12-20 20:38:51 +04:00
|
|
|
* Traverses a frame tree, marking any SVGTextFrame frames as dirty
|
2013-07-30 03:47:30 +04:00
|
|
|
* and calling InvalidateRenderingObservers() on it.
|
|
|
|
*
|
2013-12-20 20:38:51 +04:00
|
|
|
* The reason that this helper exists is because SVGTextFrame is special.
|
2013-07-30 03:47:30 +04:00
|
|
|
* None of the other SVG frames ever need to be reflowed when they have the
|
|
|
|
* NS_FRAME_IS_NONDISPLAY bit set on them because their PaintSVG methods
|
|
|
|
* (and those of any containers that they can validly be contained within) do
|
|
|
|
* not make use of mRect or overflow rects. "em" lengths, etc., are resolved
|
|
|
|
* as those elements are painted.
|
|
|
|
*
|
2013-12-20 20:38:51 +04:00
|
|
|
* SVGTextFrame is different because its anonymous block and inline frames
|
2013-07-30 03:47:30 +04:00
|
|
|
* need to be reflowed in order to get the correct metrics when things like
|
|
|
|
* inherited font-size of an ancestor changes, or a delayed webfont loads and
|
|
|
|
* applies.
|
|
|
|
*
|
2017-05-18 19:24:33 +03:00
|
|
|
* However, we only need to do this work if we were reflowed with
|
|
|
|
* NS_FRAME_IS_DIRTY, which implies that all descendants are dirty. When
|
2013-07-30 03:47:30 +04:00
|
|
|
* that reflow reaches an NS_FRAME_IS_NONDISPLAY frame it would normally
|
2013-12-20 20:38:51 +04:00
|
|
|
* stop, but this helper looks for any SVGTextFrame descendants of such
|
2017-05-18 19:24:33 +03:00
|
|
|
* frames and marks them NS_FRAME_IS_DIRTY so that the next time that they
|
|
|
|
* are painted their anonymous kid will first get the necessary reflow.
|
2013-07-30 03:47:30 +04:00
|
|
|
*/
|
|
|
|
/* static */ void nsSVGContainerFrame::ReflowSVGNonDisplayText(
|
|
|
|
nsIFrame* aContainer) {
|
2017-05-18 19:24:33 +03:00
|
|
|
if (!(aContainer->GetStateBits() & NS_FRAME_IS_DIRTY)) {
|
|
|
|
return;
|
|
|
|
}
|
2013-07-30 03:47:30 +04:00
|
|
|
NS_ASSERTION((aContainer->GetStateBits() & NS_FRAME_IS_NONDISPLAY) ||
|
|
|
|
!aContainer->IsFrameOfType(nsIFrame::eSVG),
|
|
|
|
"it is wasteful to call ReflowSVGNonDisplayText on a container "
|
|
|
|
"frame that is not NS_FRAME_IS_NONDISPLAY");
|
2016-01-29 17:42:15 +03:00
|
|
|
for (nsIFrame* kid : aContainer->PrincipalChildList()) {
|
2017-05-01 20:32:52 +03:00
|
|
|
LayoutFrameType type = kid->Type();
|
|
|
|
if (type == LayoutFrameType::SVGText) {
|
2013-12-20 20:38:51 +04:00
|
|
|
static_cast<SVGTextFrame*>(kid)->ReflowSVGNonDisplayText();
|
2013-07-30 03:47:30 +04:00
|
|
|
} else {
|
|
|
|
if (kid->IsFrameOfType(nsIFrame::eSVG | nsIFrame::eSVGContainer) ||
|
2017-05-01 20:32:52 +03:00
|
|
|
type == LayoutFrameType::SVGForeignObject ||
|
2013-07-30 03:47:30 +04:00
|
|
|
!kid->IsFrameOfType(nsIFrame::eSVG)) {
|
|
|
|
ReflowSVGNonDisplayText(kid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-25 02:20:40 +04:00
|
|
|
void nsSVGDisplayContainerFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) {
|
2008-06-22 19:59:48 +04:00
|
|
|
if (!(GetStateBits() & NS_STATE_IS_OUTER_SVG)) {
|
2013-07-12 11:13:07 +04:00
|
|
|
AddStateBits(aParent->GetStateBits() & NS_STATE_SVG_CLIPPATH_CHILD);
|
2008-06-22 19:59:48 +04:00
|
|
|
}
|
2013-03-20 05:47:48 +04:00
|
|
|
nsSVGContainerFrame::Init(aContent, aParent, aPrevInFlow);
|
2006-06-01 19:31:15 +04:00
|
|
|
}
|
|
|
|
|
2012-07-20 22:12:29 +04:00
|
|
|
void nsSVGDisplayContainerFrame::BuildDisplayList(
|
|
|
|
nsDisplayListBuilder* aBuilder, const nsDisplayListSet& aLists) {
|
2014-02-20 00:46:43 +04:00
|
|
|
// mContent could be a XUL element so check for an SVG element before casting
|
2015-03-03 14:08:59 +03:00
|
|
|
if (mContent->IsSVGElement() &&
|
2018-12-21 11:58:14 +03:00
|
|
|
!static_cast<const SVGElement*>(GetContent())->HasValidDimensions()) {
|
2013-02-14 15:12:27 +04:00
|
|
|
return;
|
2012-07-20 22:12:29 +04:00
|
|
|
}
|
2016-05-24 07:23:22 +03:00
|
|
|
DisplayOutline(aBuilder, aLists);
|
2017-08-07 05:23:35 +03:00
|
|
|
return BuildDisplayListForNonBlockChildren(aBuilder, aLists);
|
2012-07-20 22:12:29 +04:00
|
|
|
}
|
|
|
|
|
2011-08-25 00:54:30 +04:00
|
|
|
void nsSVGDisplayContainerFrame::InsertFrames(ChildListID aListID,
|
2006-06-01 19:31:15 +04:00
|
|
|
nsIFrame* aPrevFrame,
|
2009-07-30 21:23:32 +04:00
|
|
|
nsFrameList& aFrameList) {
|
|
|
|
// memorize first old frame after insertion point
|
|
|
|
// XXXbz once again, this would work a lot better if the nsIFrame
|
|
|
|
// methods returned framelist iterators....
|
2013-07-12 11:13:07 +04:00
|
|
|
nsIFrame* nextFrame = aPrevFrame ? aPrevFrame->GetNextSibling()
|
2011-08-25 00:54:30 +04:00
|
|
|
: GetChildList(aListID).FirstChild();
|
2009-07-30 21:23:32 +04:00
|
|
|
nsIFrame* firstNewFrame = aFrameList.FirstChild();
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2006-06-01 19:31:15 +04:00
|
|
|
// Insert the new frames
|
2011-08-25 00:54:30 +04:00
|
|
|
nsSVGContainerFrame::InsertFrames(aListID, aPrevFrame, aFrameList);
|
2006-06-01 19:31:15 +04:00
|
|
|
|
2012-03-20 16:15:53 +04:00
|
|
|
// If we are not a non-display SVG frame and we do not have a bounds update
|
|
|
|
// pending, then we need to schedule one for our new children:
|
|
|
|
if (!(GetStateBits() & (NS_FRAME_IS_DIRTY | NS_FRAME_HAS_DIRTY_CHILDREN |
|
2013-07-12 11:13:07 +04:00
|
|
|
NS_FRAME_IS_NONDISPLAY))) {
|
2013-07-12 11:13:07 +04:00
|
|
|
for (nsIFrame* kid = firstNewFrame; kid != nextFrame;
|
2007-10-19 15:07:08 +04:00
|
|
|
kid = kid->GetNextSibling()) {
|
2017-02-09 21:24:31 +03:00
|
|
|
nsSVGDisplayableFrame* SVGFrame = do_QueryFrame(kid);
|
2007-10-19 15:07:08 +04:00
|
|
|
if (SVGFrame) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!(kid->GetStateBits() & NS_FRAME_IS_NONDISPLAY),
|
|
|
|
"Check for this explicitly in the |if|, then");
|
2012-07-16 04:42:50 +04:00
|
|
|
bool isFirstReflow = (kid->GetStateBits() & NS_FRAME_FIRST_REFLOW);
|
2012-03-20 16:15:53 +04:00
|
|
|
// Remove bits so that ScheduleBoundsUpdate will work:
|
|
|
|
kid->RemoveStateBits(NS_FRAME_FIRST_REFLOW | NS_FRAME_IS_DIRTY |
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
|
|
|
// No need to invalidate the new kid's old bounds, so we just use
|
|
|
|
// nsSVGUtils::ScheduleBoundsUpdate.
|
2012-07-22 04:01:44 +04:00
|
|
|
nsSVGUtils::ScheduleReflowSVG(kid);
|
2012-07-16 04:42:50 +04:00
|
|
|
if (isFirstReflow) {
|
|
|
|
// Add back the NS_FRAME_FIRST_REFLOW bit:
|
|
|
|
kid->AddStateBits(NS_FRAME_FIRST_REFLOW);
|
|
|
|
}
|
2007-10-19 15:07:08 +04:00
|
|
|
}
|
2006-06-01 19:31:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-25 00:54:30 +04:00
|
|
|
void nsSVGDisplayContainerFrame::RemoveFrame(ChildListID aListID,
|
2006-06-01 19:31:15 +04:00
|
|
|
nsIFrame* aOldFrame) {
|
2017-08-30 17:58:31 +03:00
|
|
|
SVGObserverUtils::InvalidateRenderingObservers(aOldFrame);
|
2013-04-24 13:13:28 +04:00
|
|
|
|
|
|
|
// nsSVGContainerFrame::RemoveFrame doesn't call down into
|
|
|
|
// nsContainerFrame::RemoveFrame, so it doesn't call FrameNeedsReflow. We
|
|
|
|
// need to schedule a repaint and schedule an update to our overflow rects.
|
|
|
|
SchedulePaint();
|
2013-07-20 23:14:25 +04:00
|
|
|
PresContext()->RestyleManager()->PostRestyleEvent(
|
2013-04-24 13:13:28 +04:00
|
|
|
mContent->AsElement(), nsRestyleHint(0), nsChangeHint_UpdateOverflow);
|
2006-06-01 19:31:15 +04:00
|
|
|
|
2014-05-28 23:36:58 +04:00
|
|
|
nsSVGContainerFrame::RemoveFrame(aListID, aOldFrame);
|
2006-06-01 19:31:15 +04:00
|
|
|
}
|
|
|
|
|
2013-12-30 03:35:53 +04:00
|
|
|
bool nsSVGDisplayContainerFrame::IsSVGTransformed(
|
|
|
|
gfx::Matrix* aOwnTransform, gfx::Matrix* aFromParentTransform) const {
|
2012-05-17 08:05:09 +04: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);
|
|
|
|
}
|
|
|
|
|
2014-02-20 00:46:43 +04:00
|
|
|
// mContent could be a XUL element so check for an SVG element before casting
|
2015-03-03 14:08:59 +03:00
|
|
|
if (mContent->IsSVGElement()) {
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement* content = static_cast<SVGElement*>(GetContent());
|
2013-04-15 02:56:34 +04:00
|
|
|
nsSVGAnimatedTransformList* transformList =
|
2013-04-14 11:17:36 +04:00
|
|
|
content->GetAnimatedTransformList();
|
|
|
|
if ((transformList && transformList->HasTransform()) ||
|
2012-11-16 21:59:52 +04:00
|
|
|
content->GetAnimateMotionTransform()) {
|
|
|
|
if (aOwnTransform) {
|
2015-12-03 01:36:23 +03:00
|
|
|
*aOwnTransform = gfx::ToMatrix(
|
|
|
|
content->PrependLocalTransformsTo(gfxMatrix(), eUserSpaceToParent));
|
2012-11-16 21:59:52 +04:00
|
|
|
}
|
|
|
|
foundTransform = true;
|
2012-05-17 08:05:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return foundTransform;
|
|
|
|
}
|
|
|
|
|
2006-06-01 19:31:15 +04:00
|
|
|
//----------------------------------------------------------------------
|
2017-02-09 21:24:31 +03:00
|
|
|
// nsSVGDisplayableFrame methods
|
2006-06-01 19:31:15 +04:00
|
|
|
|
2014-10-31 23:08:54 +03:00
|
|
|
void nsSVGDisplayContainerFrame::PaintSVG(gfxContext& aContext,
|
2014-08-29 23:42:07 +04:00
|
|
|
const gfxMatrix& aTransform,
|
2017-05-18 23:03:41 +03:00
|
|
|
imgDrawingParams& aImgParams,
|
|
|
|
const nsIntRect* aDirtyRect) {
|
2012-07-20 22:12:29 +04:00
|
|
|
NS_ASSERTION(!NS_SVGDisplayListPaintingEnabled() ||
|
2013-07-12 11:13:07 +04:00
|
|
|
(mState & NS_FRAME_IS_NONDISPLAY) ||
|
2018-01-15 17:33:25 +03:00
|
|
|
PresContext()->Document()->IsSVGGlyphsDocument(),
|
2012-07-20 22:12:29 +04:00
|
|
|
"If display lists are enabled, only painting of non-display "
|
|
|
|
"SVG should take this code path");
|
|
|
|
|
2016-04-12 08:52:43 +03:00
|
|
|
if (StyleEffects()->mOpacity == 0.0) {
|
2017-05-18 23:03:41 +03:00
|
|
|
return;
|
2014-08-29 23:42:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxMatrix matrix = aTransform;
|
2015-03-03 14:08:59 +03:00
|
|
|
if (GetContent()->IsSVGElement()) { // must check before cast
|
2018-12-21 11:58:14 +03:00
|
|
|
matrix = static_cast<const SVGElement*>(GetContent())
|
2015-12-03 01:36:23 +03:00
|
|
|
->PrependLocalTransformsTo(matrix, eChildToUserSpace);
|
2014-08-29 23:42:07 +04:00
|
|
|
if (matrix.IsSingular()) {
|
2017-05-18 23:03:41 +03:00
|
|
|
return;
|
2014-08-29 23:42:07 +04:00
|
|
|
}
|
|
|
|
}
|
2006-06-01 19:31:15 +04:00
|
|
|
|
|
|
|
for (nsIFrame* kid = mFrames.FirstChild(); kid; kid = kid->GetNextSibling()) {
|
2014-08-29 23:42:07 +04:00
|
|
|
gfxMatrix m = matrix;
|
|
|
|
// PaintFrameWithEffects() expects the transform that is passed to it to
|
|
|
|
// include the transform to the passed frame's user space, so add it:
|
|
|
|
const nsIContent* content = kid->GetContent();
|
2015-03-03 14:08:59 +03:00
|
|
|
if (content->IsSVGElement()) { // must check before cast
|
2018-12-21 11:58:14 +03:00
|
|
|
const SVGElement* element = static_cast<const SVGElement*>(content);
|
2014-08-29 23:42:07 +04:00
|
|
|
if (!element->HasValidDimensions()) {
|
|
|
|
continue; // nothing to paint for kid
|
|
|
|
}
|
2015-12-03 01:36:23 +03:00
|
|
|
m = element->PrependLocalTransformsTo(m, eUserSpaceToParent);
|
2014-08-29 23:42:07 +04:00
|
|
|
if (m.IsSingular()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2017-05-18 23:03:41 +03:00
|
|
|
nsSVGUtils::PaintFrameWithEffects(kid, aContext, m, aImgParams, aDirtyRect);
|
2006-06-01 19:31:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-07 11:09:31 +04:00
|
|
|
nsIFrame* nsSVGDisplayContainerFrame::GetFrameForPoint(const gfxPoint& aPoint) {
|
2012-07-20 22:12:29 +04:00
|
|
|
NS_ASSERTION(!NS_SVGDisplayListHitTestingEnabled() ||
|
2013-07-12 11:13:07 +04:00
|
|
|
(mState & NS_FRAME_IS_NONDISPLAY),
|
2012-07-20 22:12:29 +04:00
|
|
|
"If display lists are enabled, only hit-testing of a "
|
|
|
|
"clipPath's contents should take this code path");
|
2008-08-25 13:23:54 +04:00
|
|
|
return nsSVGUtils::HitTestChildren(this, aPoint);
|
2006-06-01 19:31:15 +04:00
|
|
|
}
|
|
|
|
|
2012-07-22 04:01:44 +04:00
|
|
|
void nsSVGDisplayContainerFrame::ReflowSVG() {
|
|
|
|
NS_ASSERTION(nsSVGUtils::OuterSVGIsCallingReflowSVG(this),
|
|
|
|
"This call is probably a wasteful mistake");
|
2006-06-09 22:08:33 +04:00
|
|
|
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!(GetStateBits() & NS_FRAME_IS_NONDISPLAY),
|
|
|
|
"ReflowSVG mechanism not designed for this");
|
2012-03-20 16:15:53 +04:00
|
|
|
|
2017-04-30 18:30:08 +03:00
|
|
|
MOZ_ASSERT(!IsSVGOuterSVGFrame(), "Do not call on outer-<svg>");
|
2012-05-17 08:05:09 +04:00
|
|
|
|
2012-07-22 04:01:44 +04:00
|
|
|
if (!nsSVGUtils::NeedsReflowSVG(this)) {
|
2012-03-20 16:15:53 +04:00
|
|
|
return;
|
|
|
|
}
|
2007-10-19 15:07:08 +04:00
|
|
|
|
2012-03-20 16:15:53 +04:00
|
|
|
// If the NS_FRAME_FIRST_REFLOW bit has been removed from our parent frame,
|
|
|
|
// then our outer-<svg> has previously had its initial reflow. In that case
|
|
|
|
// we need to make sure that that bit has been removed from ourself _before_
|
|
|
|
// recursing over our children to ensure that they know too. Otherwise, we
|
|
|
|
// need to remove it _after_ recursing over our children so that they know
|
|
|
|
// the initial reflow is currently underway.
|
|
|
|
|
2013-08-24 15:31:48 +04:00
|
|
|
bool isFirstReflow = (mState & NS_FRAME_FIRST_REFLOW);
|
|
|
|
|
2012-03-20 16:15:53 +04:00
|
|
|
bool outerSVGHasHadFirstReflow =
|
|
|
|
(GetParent()->GetStateBits() & NS_FRAME_FIRST_REFLOW) == 0;
|
|
|
|
|
|
|
|
if (outerSVGHasHadFirstReflow) {
|
2017-08-24 12:55:28 +03:00
|
|
|
RemoveStateBits(NS_FRAME_FIRST_REFLOW); // tell our children
|
2012-03-20 16:15:53 +04:00
|
|
|
}
|
|
|
|
|
2012-05-17 08:05:09 +04:00
|
|
|
nsOverflowAreas overflowRects;
|
|
|
|
|
2006-06-01 19:31:15 +04:00
|
|
|
for (nsIFrame* kid = mFrames.FirstChild(); kid; kid = kid->GetNextSibling()) {
|
2017-02-09 21:24:31 +03:00
|
|
|
nsSVGDisplayableFrame* SVGFrame = do_QueryFrame(kid);
|
2006-06-01 19:31:15 +04:00
|
|
|
if (SVGFrame) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!(kid->GetStateBits() & NS_FRAME_IS_NONDISPLAY),
|
|
|
|
"Check for this explicitly in the |if|, then");
|
2013-02-11 10:22:16 +04:00
|
|
|
kid->AddStateBits(mState & NS_FRAME_IS_DIRTY);
|
2012-07-22 04:01:44 +04:00
|
|
|
SVGFrame->ReflowSVG();
|
2012-05-17 08:05:09 +04:00
|
|
|
|
|
|
|
// We build up our child frame overflows here instead of using
|
|
|
|
// nsLayoutUtils::UnionChildOverflow since SVG frame's all use the same
|
|
|
|
// frame list, and we're iterating over that list now anyway.
|
|
|
|
ConsiderChildOverflow(overflowRects, kid);
|
2013-06-03 18:15:29 +04:00
|
|
|
} else {
|
|
|
|
// Inside a non-display container frame, we might have some
|
2013-12-20 20:38:51 +04:00
|
|
|
// SVGTextFrames. We need to cause those to get reflowed in
|
2013-06-03 18:15:29 +04:00
|
|
|
// case they are the target of a rendering observer.
|
2013-07-12 11:13:07 +04:00
|
|
|
NS_ASSERTION(kid->GetStateBits() & NS_FRAME_IS_NONDISPLAY,
|
|
|
|
"expected kid to be a NS_FRAME_IS_NONDISPLAY frame");
|
2013-06-03 18:15:29 +04:00
|
|
|
if (kid->GetStateBits() & NS_FRAME_IS_DIRTY) {
|
|
|
|
nsSVGContainerFrame* container = do_QueryFrame(kid);
|
2015-03-03 14:08:59 +03:00
|
|
|
if (container && container->GetContent()->IsSVGElement()) {
|
2013-06-03 18:15:29 +04:00
|
|
|
ReflowSVGNonDisplayText(container);
|
|
|
|
}
|
|
|
|
}
|
2006-06-01 19:31:15 +04:00
|
|
|
}
|
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
2012-05-17 08:05:09 +04:00
|
|
|
// <svg> can create an SVG viewport with an offset due to its
|
|
|
|
// x/y/width/height attributes, and <use> can introduce an offset with an
|
|
|
|
// empty mRect (any width/height is copied to an anonymous <svg> child).
|
|
|
|
// Other than that containers should not set mRect since all other offsets
|
|
|
|
// come from transforms, which are accounted for by nsDisplayTransform.
|
|
|
|
// Note that we rely on |overflow:visible| to allow display list items to be
|
|
|
|
// created for our children.
|
2017-06-14 16:57:09 +03:00
|
|
|
MOZ_ASSERT(mContent->IsAnyOfSVGElements(nsGkAtoms::svg, nsGkAtoms::symbol) ||
|
2015-03-03 14:09:00 +03:00
|
|
|
(mContent->IsSVGElement(nsGkAtoms::use) &&
|
2015-02-10 01:34:50 +03:00
|
|
|
mRect.Size() == nsSize(0, 0)) ||
|
|
|
|
mRect.IsEqualEdges(nsRect()),
|
|
|
|
"Only inner-<svg>/<use> is expected to have mRect set");
|
2012-05-17 08:05:09 +04:00
|
|
|
|
2013-08-24 15:31:48 +04:00
|
|
|
if (isFirstReflow) {
|
2012-05-17 08:05:09 +04:00
|
|
|
// Make sure we have our filter property (if any) before calling
|
|
|
|
// FinishAndStoreOverflow (subsequent filter changes are handled off
|
|
|
|
// nsChangeHint_UpdateEffects):
|
2017-08-30 17:58:31 +03:00
|
|
|
SVGObserverUtils::UpdateEffects(this);
|
2012-05-17 08:05:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
FinishAndStoreOverflow(overflowRects, mRect.Size());
|
|
|
|
|
|
|
|
// Remove state bits after FinishAndStoreOverflow so that it doesn't
|
|
|
|
// invalidate on first reflow:
|
2017-08-24 12:55:28 +03:00
|
|
|
RemoveStateBits(NS_FRAME_FIRST_REFLOW | NS_FRAME_IS_DIRTY |
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
2017-07-06 15:00:35 +03:00
|
|
|
}
|
2006-06-01 19:31:15 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void nsSVGDisplayContainerFrame::NotifySVGChanged(uint32_t aFlags) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aFlags & (TRANSFORM_CHANGED | COORD_CONTEXT_CHANGED),
|
|
|
|
"Invalidation logic may need adjusting");
|
2008-01-25 12:27:03 +03:00
|
|
|
|
2017-09-05 12:26:46 +03:00
|
|
|
if (aFlags & TRANSFORM_CHANGED) {
|
|
|
|
// make sure our cached transform matrix gets (lazily) updated
|
|
|
|
mCanvasTM = nullptr;
|
|
|
|
}
|
|
|
|
|
2008-01-25 12:27:03 +03:00
|
|
|
nsSVGUtils::NotifyChildrenOfSVGChange(this, aFlags);
|
2006-06-01 19:31:15 +04:00
|
|
|
}
|
|
|
|
|
2011-09-30 13:25:37 +04:00
|
|
|
SVGBBox nsSVGDisplayContainerFrame::GetBBoxContribution(
|
2013-12-30 10:50:07 +04:00
|
|
|
const Matrix& aToBBoxUserspace, uint32_t aFlags) {
|
2012-04-16 12:23:48 +04:00
|
|
|
SVGBBox bboxUnion;
|
2009-04-29 08:31:34 +04:00
|
|
|
|
|
|
|
nsIFrame* kid = mFrames.FirstChild();
|
|
|
|
while (kid) {
|
2014-02-20 00:46:43 +04:00
|
|
|
nsIContent* content = kid->GetContent();
|
2017-02-09 21:24:31 +03:00
|
|
|
nsSVGDisplayableFrame* svgKid = do_QueryFrame(kid);
|
2014-02-20 00:46:43 +04:00
|
|
|
// content could be a XUL element so check for an SVG element before casting
|
2015-03-03 14:08:59 +03:00
|
|
|
if (svgKid &&
|
|
|
|
(!content->IsSVGElement() ||
|
2018-12-21 11:58:14 +03:00
|
|
|
static_cast<const SVGElement*>(content)->HasValidDimensions())) {
|
2013-12-30 10:50:07 +04:00
|
|
|
gfxMatrix transform = gfx::ThebesMatrix(aToBBoxUserspace);
|
2015-03-03 14:08:59 +03:00
|
|
|
if (content->IsSVGElement()) {
|
2018-12-21 11:58:14 +03:00
|
|
|
transform = static_cast<SVGElement*>(content)->PrependLocalTransformsTo(
|
|
|
|
transform);
|
2009-04-29 08:31:34 +04:00
|
|
|
}
|
2012-01-23 21:42:32 +04:00
|
|
|
// We need to include zero width/height vertical/horizontal lines, so we
|
2012-04-16 12:23:48 +04:00
|
|
|
// have to use UnionEdges.
|
2013-12-30 10:50:07 +04:00
|
|
|
bboxUnion.UnionEdges(
|
|
|
|
svgKid->GetBBoxContribution(gfx::ToMatrix(transform), aFlags));
|
2009-04-29 08:31:34 +04:00
|
|
|
}
|
|
|
|
kid = kid->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
return bboxUnion;
|
2006-06-01 19:31:15 +04:00
|
|
|
}
|
2017-09-05 12:26:46 +03:00
|
|
|
|
|
|
|
gfxMatrix nsSVGDisplayContainerFrame::GetCanvasTM() {
|
|
|
|
if (!mCanvasTM) {
|
|
|
|
NS_ASSERTION(GetParent(), "null parent");
|
|
|
|
|
|
|
|
nsSVGContainerFrame* parent =
|
|
|
|
static_cast<nsSVGContainerFrame*>(GetParent());
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement* content = static_cast<SVGElement*>(GetContent());
|
2017-09-05 12:26:46 +03:00
|
|
|
|
|
|
|
gfxMatrix tm = content->PrependLocalTransformsTo(parent->GetCanvasTM());
|
|
|
|
|
|
|
|
mCanvasTM = new gfxMatrix(tm);
|
|
|
|
}
|
|
|
|
|
|
|
|
return *mCanvasTM;
|
|
|
|
}
|