2017-06-14 15:38:10 +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: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_SVGViewportElement_h
|
|
|
|
#define mozilla_dom_SVGViewportElement_h
|
|
|
|
|
2018-12-27 20:30:38 +03:00
|
|
|
#include "mozilla/Attributes.h"
|
2017-06-14 15:38:10 +03:00
|
|
|
#include "mozilla/dom/FromParser.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsIContentInlines.h"
|
2019-04-04 20:40:56 +03:00
|
|
|
#include "SVGAnimatedEnumeration.h"
|
2019-04-09 23:04:33 +03:00
|
|
|
#include "SVGAnimatedLength.h"
|
2018-12-27 20:30:38 +03:00
|
|
|
#include "SVGAnimatedPreserveAspectRatio.h"
|
2019-04-04 20:40:56 +03:00
|
|
|
#include "SVGAnimatedViewBox.h"
|
2017-06-14 15:38:10 +03:00
|
|
|
#include "SVGGraphicsElement.h"
|
|
|
|
#include "SVGImageContext.h"
|
2019-01-02 21:24:11 +03:00
|
|
|
#include "nsISVGPoint.h"
|
|
|
|
#include "SVGPreserveAspectRatio.h"
|
2017-06-14 15:38:10 +03:00
|
|
|
|
|
|
|
class nsSVGOuterSVGFrame;
|
2017-06-14 16:05:37 +03:00
|
|
|
class nsSVGViewportFrame;
|
2017-06-14 15:38:10 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
class AutoPreserveAspectRatioOverride;
|
|
|
|
|
|
|
|
namespace dom {
|
2019-04-10 07:21:44 +03:00
|
|
|
class DOMSVGAnimatedPreserveAspectRatio;
|
2017-06-14 15:38:10 +03:00
|
|
|
class SVGAnimatedRect;
|
|
|
|
class SVGViewElement;
|
|
|
|
class SVGViewportElement;
|
|
|
|
|
|
|
|
class svgFloatSize {
|
|
|
|
public:
|
|
|
|
svgFloatSize(float aWidth, float aHeight) : width(aWidth), height(aHeight) {}
|
|
|
|
bool operator!=(const svgFloatSize& rhs) {
|
|
|
|
return width != rhs.width || height != rhs.height;
|
|
|
|
}
|
|
|
|
float width;
|
|
|
|
float height;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SVGViewportElement : public SVGGraphicsElement {
|
|
|
|
friend class ::nsSVGOuterSVGFrame;
|
2017-06-14 16:05:37 +03:00
|
|
|
friend class ::nsSVGViewportFrame;
|
2017-06-14 15:38:10 +03:00
|
|
|
|
|
|
|
protected:
|
2019-04-24 23:39:43 +03:00
|
|
|
explicit SVGViewportElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
|
2019-04-18 01:38:02 +03:00
|
|
|
~SVGViewportElement() = default;
|
2017-06-14 15:38:10 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
// nsIContent interface
|
2017-10-03 01:05:19 +03:00
|
|
|
NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override;
|
2017-06-14 15:38:10 +03:00
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
// SVGElement specializations:
|
2017-06-14 15:38:10 +03:00
|
|
|
virtual gfxMatrix PrependLocalTransformsTo(
|
|
|
|
const gfxMatrix& aMatrix,
|
|
|
|
SVGTransformTypes aWhich = eAllTransforms) const override;
|
|
|
|
|
|
|
|
virtual bool HasValidDimensions() const override;
|
|
|
|
|
|
|
|
// SVGViewportElement methods:
|
|
|
|
|
2019-04-27 10:57:50 +03:00
|
|
|
float GetLength(uint8_t aCtxType);
|
2017-06-14 15:38:10 +03:00
|
|
|
|
|
|
|
// public helpers:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this element has a base/anim value for its "viewBox"
|
|
|
|
* attribute that defines a viewBox rectangle with finite values, or
|
|
|
|
* if there is a view element overriding this element's viewBox and it
|
|
|
|
* has a valid viewBox.
|
|
|
|
*
|
|
|
|
* Note that this does not check whether we need to synthesize a viewBox,
|
|
|
|
* so you must call ShouldSynthesizeViewBox() if you need to chck that too.
|
|
|
|
*
|
|
|
|
* Note also that this method does not pay attention to whether the width or
|
|
|
|
* height values of the viewBox rect are positive!
|
|
|
|
*/
|
2019-04-10 07:08:14 +03:00
|
|
|
bool HasViewBox() const { return GetViewBoxInternal().HasRect(); }
|
2017-06-14 15:38:10 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if we should synthesize a viewBox for ourselves (that is, if
|
|
|
|
* we're the root element in an image document, and we're not currently being
|
|
|
|
* painted for an <svg:image> element).
|
|
|
|
*
|
2019-04-10 07:08:14 +03:00
|
|
|
* Only call this method if HasViewBox() returns false.
|
2017-06-14 15:38:10 +03:00
|
|
|
*/
|
|
|
|
bool ShouldSynthesizeViewBox() const;
|
|
|
|
|
|
|
|
bool HasViewBoxOrSyntheticViewBox() const {
|
2019-04-10 07:08:14 +03:00
|
|
|
return HasViewBox() || ShouldSynthesizeViewBox();
|
2017-06-14 15:38:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HasChildrenOnlyTransform() const { return mHasChildrenOnlyTransform; }
|
|
|
|
|
|
|
|
void UpdateHasChildrenOnlyTransform();
|
|
|
|
|
|
|
|
enum ChildrenOnlyTransformChangedFlags { eDuringReflow = 1 };
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method notifies the style system that the overflow rects of our
|
|
|
|
* immediate childrens' frames need to be updated. It is called by our own
|
|
|
|
* frame when changes (e.g. to currentScale) cause our children-only
|
|
|
|
* transform to change.
|
|
|
|
*
|
|
|
|
* The reason we have this method instead of overriding
|
|
|
|
* GetAttributeChangeHint is because we need to act on non-attribute (e.g.
|
|
|
|
* currentScale) changes in addition to attribute (e.g. viewBox) changes.
|
|
|
|
*/
|
|
|
|
void ChildrenOnlyTransformChanged(uint32_t aFlags = 0);
|
|
|
|
|
|
|
|
gfx::Matrix GetViewBoxTransform() const;
|
|
|
|
|
2017-10-10 09:58:34 +03:00
|
|
|
svgFloatSize GetViewportSize() const {
|
|
|
|
return svgFloatSize(mViewportWidth, mViewportHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetViewportSize(const svgFloatSize& aSize) {
|
|
|
|
mViewportWidth = aSize.width;
|
|
|
|
mViewportHeight = aSize.height;
|
|
|
|
}
|
|
|
|
|
2019-05-16 16:21:20 +03:00
|
|
|
/**
|
|
|
|
* Returns true if either this is an SVG <svg> element that is the child of
|
|
|
|
* another non-foreignObject SVG element, or this is a SVG <symbol> element
|
|
|
|
* this is the root of a use-element shadow tree.
|
|
|
|
*/
|
|
|
|
bool IsInner() const {
|
|
|
|
const nsIContent* parent = GetFlattenedTreeParent();
|
|
|
|
return parent && parent->IsSVGElement() &&
|
|
|
|
!parent->IsSVGElement(nsGkAtoms::foreignObject);
|
|
|
|
}
|
|
|
|
|
2017-06-14 15:38:10 +03:00
|
|
|
// WebIDL
|
|
|
|
already_AddRefed<SVGAnimatedRect> ViewBox();
|
|
|
|
already_AddRefed<DOMSVGAnimatedPreserveAspectRatio> PreserveAspectRatio();
|
2019-04-10 07:08:14 +03:00
|
|
|
virtual SVGAnimatedViewBox* GetAnimatedViewBox() override;
|
2017-06-14 15:38:10 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// implementation helpers:
|
|
|
|
|
|
|
|
bool IsRoot() const {
|
|
|
|
NS_ASSERTION((IsInUncomposedDoc() && !GetParent()) ==
|
2018-02-25 18:44:51 +03:00
|
|
|
(OwnerDoc()->GetRootElement() == this),
|
2017-06-14 15:38:10 +03:00
|
|
|
"Can't determine if we're root");
|
|
|
|
return IsInUncomposedDoc() && !GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the explicit or default preserveAspectRatio, unless we're
|
|
|
|
* synthesizing a viewBox, in which case it returns the "none" value.
|
|
|
|
*/
|
|
|
|
virtual SVGPreserveAspectRatio GetPreserveAspectRatioWithOverride() const {
|
|
|
|
return mPreserveAspectRatio.GetAnimValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the explicit viewBox rect, if specified, or else a synthesized
|
|
|
|
* viewBox, if appropriate, or else a viewBox matching the dimensions of the
|
|
|
|
* SVG viewport.
|
|
|
|
*/
|
2019-04-10 07:08:14 +03:00
|
|
|
SVGViewBox GetViewBoxWithSynthesis(float aViewportWidth,
|
|
|
|
float aViewportHeight) const;
|
2017-06-14 15:38:10 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the value of currentScale and currentTranslate.
|
|
|
|
*/
|
|
|
|
virtual SVGPoint GetCurrentTranslate() const { return SVGPoint(0.0f, 0.0f); }
|
|
|
|
virtual float GetCurrentScale() const { return 1.0f; }
|
|
|
|
|
|
|
|
enum { ATTR_X, ATTR_Y, ATTR_WIDTH, ATTR_HEIGHT };
|
2019-04-09 23:04:33 +03:00
|
|
|
SVGAnimatedLength mLengthAttributes[4];
|
2017-06-14 15:38:10 +03:00
|
|
|
static LengthInfo sLengthInfo[4];
|
|
|
|
virtual LengthAttributesInfo GetLengthInfo() override;
|
|
|
|
|
2019-04-10 07:08:14 +03:00
|
|
|
virtual SVGAnimatedPreserveAspectRatio* GetAnimatedPreserveAspectRatio()
|
|
|
|
override;
|
2017-06-14 15:38:10 +03:00
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
virtual const SVGAnimatedViewBox& GetViewBoxInternal() const {
|
|
|
|
return mViewBox;
|
|
|
|
}
|
2018-12-27 02:46:38 +03:00
|
|
|
virtual SVGAnimatedTransformList* GetTransformInternal() const {
|
2017-06-14 15:38:10 +03:00
|
|
|
return mTransforms;
|
|
|
|
}
|
2019-04-04 20:40:56 +03:00
|
|
|
SVGAnimatedViewBox mViewBox;
|
2017-06-14 15:38:10 +03:00
|
|
|
SVGAnimatedPreserveAspectRatio mPreserveAspectRatio;
|
|
|
|
|
|
|
|
// The size of the rectangular SVG viewport into which we render. This is
|
|
|
|
// not (necessarily) the same as the content area. See:
|
|
|
|
//
|
|
|
|
// http://www.w3.org/TR/SVG11/coords.html#ViewportSpace
|
|
|
|
//
|
|
|
|
// XXXjwatt Currently only used for outer <svg>, but maybe we could use -1 to
|
|
|
|
// flag this as an inner <svg> to save the overhead of GetCtx calls?
|
|
|
|
// XXXjwatt our frame should probably reset these when it's destroyed.
|
|
|
|
float mViewportWidth, mViewportHeight;
|
|
|
|
|
|
|
|
bool mHasChildrenOnlyTransform;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // SVGViewportElement_h
|