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-09-09 15:44:03 +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/. */
|
|
|
|
|
|
|
|
// Keep in (case-insensitive) order:
|
2019-04-16 10:24:49 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2020-07-09 04:33:33 +03:00
|
|
|
#include "mozilla/SVGOuterSVGFrame.h"
|
2020-07-11 05:20:20 +03:00
|
|
|
#include "mozilla/SVGUtils.h"
|
2019-04-16 10:24:49 +03:00
|
|
|
#include "mozilla/dom/SVGSVGElement.h"
|
|
|
|
#include "mozilla/dom/SVGViewElement.h"
|
2020-07-07 01:38:11 +03:00
|
|
|
#include "nsIFrame.h"
|
2012-09-09 15:44:03 +04:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2020-06-24 01:59:34 +03:00
|
|
|
nsIFrame* NS_NewSVGViewFrame(mozilla::PresShell* aPresShell,
|
2020-06-27 08:39:42 +03:00
|
|
|
mozilla::ComputedStyle* aStyle);
|
2020-06-24 01:59:34 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2012-09-09 15:44:03 +04:00
|
|
|
/**
|
|
|
|
* While views are not directly rendered in SVG they can be linked to
|
|
|
|
* and thereby override attributes of an <svg> element via a fragment
|
|
|
|
* identifier. The SVGViewFrame class passes on any attribute changes
|
|
|
|
* the view receives to the overridden <svg> element (if there is one).
|
|
|
|
**/
|
2020-07-07 01:29:42 +03:00
|
|
|
class SVGViewFrame final : public nsIFrame {
|
2020-06-24 01:59:34 +03:00
|
|
|
friend nsIFrame* ::NS_NewSVGViewFrame(mozilla::PresShell* aPresShell,
|
|
|
|
ComputedStyle* aStyle);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-09-09 15:44:03 +04:00
|
|
|
protected:
|
2019-02-05 19:45:54 +03:00
|
|
|
explicit SVGViewFrame(ComputedStyle* aStyle, nsPresContext* aPresContext)
|
2020-07-07 01:29:42 +03:00
|
|
|
: nsIFrame(aStyle, aPresContext, kClassID) {
|
2019-05-30 02:50:55 +03:00
|
|
|
AddStateBits(NS_FRAME_SVG_LAYOUT | NS_FRAME_IS_NONDISPLAY);
|
2012-09-09 15:44:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2017-05-26 13:11:11 +03:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS(SVGViewFrame)
|
2012-09-09 15:44:03 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2014-05-25 02:20:40 +04:00
|
|
|
virtual void Init(nsIContent* aContent, nsContainerFrame* aParent,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsIFrame* aPrevInFlow) override;
|
2012-09-09 15:44:03 +04:00
|
|
|
#endif
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool IsFrameOfType(uint32_t aFlags) const override {
|
2018-08-08 01:02:07 +03:00
|
|
|
if (aFlags & eSupportsContainLayoutAndPaint) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-07 01:29:42 +03:00
|
|
|
return nsIFrame::IsFrameOfType(aFlags & ~(nsIFrame::eSVG));
|
2012-09-09 15:44:03 +04:00
|
|
|
}
|
|
|
|
|
2014-01-06 03:31:14 +04:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const override {
|
2012-09-09 15:44:03 +04:00
|
|
|
return MakeFrameName(u"SVGView"_ns, aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
virtual nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
|
2015-03-21 19:28:04 +03:00
|
|
|
int32_t aModType) override;
|
2012-09-09 15:44:03 +04:00
|
|
|
|
2020-11-18 03:08:12 +03:00
|
|
|
virtual bool ComputeCustomOverflow(OverflowAreas& aOverflowAreas) override {
|
2020-07-20 23:17:36 +03:00
|
|
|
// We don't maintain a ink overflow rect
|
2012-09-09 15:44:03 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-06-24 01:59:34 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
nsIFrame* NS_NewSVGViewFrame(mozilla::PresShell* aPresShell,
|
2020-06-27 08:39:42 +03:00
|
|
|
mozilla::ComputedStyle* aStyle) {
|
2020-06-24 01:59:34 +03:00
|
|
|
return new (aPresShell)
|
|
|
|
mozilla::SVGViewFrame(aStyle, aPresShell->GetPresContext());
|
2012-09-09 15:44:03 +04:00
|
|
|
}
|
|
|
|
|
2020-06-24 01:59:34 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2012-09-09 15:44:03 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(SVGViewFrame)
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2014-05-25 02:20:40 +04:00
|
|
|
void SVGViewFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) {
|
2015-03-03 14:08:59 +03:00
|
|
|
NS_ASSERTION(aContent->IsSVGElement(nsGkAtoms::view),
|
2013-01-08 07:22:41 +04:00
|
|
|
"Content is not an SVG view");
|
2012-09-09 15:44:03 +04:00
|
|
|
|
2020-07-07 01:29:42 +03:00
|
|
|
nsIFrame::Init(aContent, aParent, aPrevInFlow);
|
2012-09-09 15:44:03 +04:00
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
nsresult SVGViewFrame::AttributeChanged(int32_t aNameSpaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute, int32_t aModType) {
|
2012-09-09 15:44:03 +04:00
|
|
|
// Ignore zoomAndPan as it does not cause the <svg> element to re-render
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2012-09-09 15:44:03 +04:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
(aAttribute == nsGkAtoms::preserveAspectRatio ||
|
2018-04-26 00:44:31 +03:00
|
|
|
aAttribute == nsGkAtoms::viewBox)) {
|
2020-07-11 05:20:20 +03:00
|
|
|
SVGOuterSVGFrame* outerSVGFrame = SVGUtils::GetOuterSVGFrame(this);
|
2015-03-03 14:08:59 +03:00
|
|
|
NS_ASSERTION(outerSVGFrame->GetContent()->IsSVGElement(nsGkAtoms::svg),
|
2012-09-09 15:44:03 +04:00
|
|
|
"Expecting an <svg> element");
|
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement* svgElement =
|
|
|
|
static_cast<SVGSVGElement*>(outerSVGFrame->GetContent());
|
2012-09-09 15:44:03 +04:00
|
|
|
|
|
|
|
nsAutoString viewID;
|
2017-12-07 21:13:50 +03:00
|
|
|
mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::id, viewID);
|
2012-09-09 15:44:03 +04:00
|
|
|
|
|
|
|
if (svgElement->IsOverriddenBy(viewID)) {
|
|
|
|
// We're the view that's providing overrides, so pretend that the frame
|
|
|
|
// we're overriding was updated.
|
|
|
|
outerSVGFrame->AttributeChanged(aNameSpaceID, aAttribute, aModType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-07 01:29:42 +03:00
|
|
|
return nsIFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
|
2012-09-09 15:44:03 +04:00
|
|
|
}
|
2020-06-24 01:59:34 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|