2017-10-27 17:33:53 +00: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 11:44:03 +00: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 07:24:49 +00:00
|
|
|
#include "mozilla/PresShell.h"
|
|
|
|
#include "mozilla/dom/SVGSVGElement.h"
|
|
|
|
#include "mozilla/dom/SVGViewElement.h"
|
2012-09-09 11:44:03 +00:00
|
|
|
#include "nsFrame.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsSVGOuterSVGFrame.h"
|
|
|
|
|
2018-11-12 22:20:52 +00:00
|
|
|
using namespace mozilla;
|
2013-01-09 23:02:45 +00:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2012-09-09 11:44:03 +00: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).
|
|
|
|
**/
|
2018-09-06 01:23:14 +00:00
|
|
|
class SVGViewFrame final : public nsFrame {
|
2019-04-16 07:24:49 +00:00
|
|
|
friend nsIFrame* NS_NewSVGViewFrame(mozilla::PresShell* aPresShell,
|
2018-03-22 18:20:41 +00:00
|
|
|
ComputedStyle* aStyle);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2012-09-09 11:44:03 +00:00
|
|
|
protected:
|
2019-02-05 16:45:54 +00:00
|
|
|
explicit SVGViewFrame(ComputedStyle* aStyle, nsPresContext* aPresContext)
|
|
|
|
: nsFrame(aStyle, aPresContext, kClassID) {
|
2019-05-29 23:50:55 +00:00
|
|
|
AddStateBits(NS_FRAME_SVG_LAYOUT | NS_FRAME_IS_NONDISPLAY);
|
2012-09-09 11:44:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2017-05-26 10:11:11 +00:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS(SVGViewFrame)
|
2012-09-09 11:44:03 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2014-05-24 22:20:40 +00:00
|
|
|
virtual void Init(nsIContent* aContent, nsContainerFrame* aParent,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsIFrame* aPrevInFlow) override;
|
2012-09-09 11:44:03 +00:00
|
|
|
#endif
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool IsFrameOfType(uint32_t aFlags) const override {
|
2018-08-07 22:02:07 +00:00
|
|
|
if (aFlags & eSupportsContainLayoutAndPaint) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-18 07:57:01 +00:00
|
|
|
return nsFrame::IsFrameOfType(aFlags & ~(nsIFrame::eSVG));
|
2012-09-09 11:44:03 +00:00
|
|
|
}
|
|
|
|
|
2014-01-05 23:31:14 +00:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const override {
|
2012-09-09 11:44:03 +00:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("SVGView"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-02-18 07:47:48 +00:00
|
|
|
virtual nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
|
2015-03-21 16:28:04 +00:00
|
|
|
int32_t aModType) override;
|
2012-09-09 11:44:03 +00:00
|
|
|
|
2016-05-04 00:27:43 +00:00
|
|
|
virtual bool ComputeCustomOverflow(nsOverflowAreas& aOverflowAreas) override {
|
2012-09-09 11:44:03 +00:00
|
|
|
// We don't maintain a visual overflow rect
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-04-16 07:24:49 +00:00
|
|
|
nsIFrame* NS_NewSVGViewFrame(PresShell* aPresShell, ComputedStyle* aStyle) {
|
2019-02-05 16:45:54 +00:00
|
|
|
return new (aPresShell) SVGViewFrame(aStyle, aPresShell->GetPresContext());
|
2012-09-09 11:44:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(SVGViewFrame)
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2014-05-24 22:20:40 +00:00
|
|
|
void SVGViewFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) {
|
2015-03-03 11:08:59 +00:00
|
|
|
NS_ASSERTION(aContent->IsSVGElement(nsGkAtoms::view),
|
2013-01-08 03:22:41 +00:00
|
|
|
"Content is not an SVG view");
|
2012-09-09 11:44:03 +00:00
|
|
|
|
2016-04-18 07:57:01 +00:00
|
|
|
nsFrame::Init(aContent, aParent, aPrevInFlow);
|
2012-09-09 11:44:03 +00:00
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
nsresult SVGViewFrame::AttributeChanged(int32_t aNameSpaceID,
|
2017-10-02 22:05:19 +00:00
|
|
|
nsAtom* aAttribute, int32_t aModType) {
|
2012-09-09 11:44:03 +00:00
|
|
|
// Ignore zoomAndPan as it does not cause the <svg> element to re-render
|
2017-07-06 12:00:35 +00:00
|
|
|
|
2012-09-09 11:44:03 +00:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
(aAttribute == nsGkAtoms::preserveAspectRatio ||
|
2018-04-25 21:44:31 +00:00
|
|
|
aAttribute == nsGkAtoms::viewBox)) {
|
2012-09-09 11:44:03 +00:00
|
|
|
nsSVGOuterSVGFrame* outerSVGFrame = nsSVGUtils::GetOuterSVGFrame(this);
|
2015-03-03 11:08:59 +00:00
|
|
|
NS_ASSERTION(outerSVGFrame->GetContent()->IsSVGElement(nsGkAtoms::svg),
|
2012-09-09 11:44:03 +00:00
|
|
|
"Expecting an <svg> element");
|
|
|
|
|
2013-01-09 23:02:45 +00:00
|
|
|
SVGSVGElement* svgElement =
|
|
|
|
static_cast<SVGSVGElement*>(outerSVGFrame->GetContent());
|
2012-09-09 11:44:03 +00:00
|
|
|
|
|
|
|
nsAutoString viewID;
|
2017-12-07 18:13:50 +00:00
|
|
|
mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::id, viewID);
|
2012-09-09 11:44:03 +00: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-18 07:57:01 +00:00
|
|
|
return nsFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
|
2012-09-09 11:44:03 +00:00
|
|
|
}
|