Bug 1936278 - Prevent search mode chiclet from being dismissed when clicking in page...
[gecko.git] / dom / svg / SVGViewportElement.h
blob07323f24ae5d9f43c073be6bbc4741ca181bc484
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef DOM_SVG_SVGVIEWPORTELEMENT_H_
8 #define DOM_SVG_SVGVIEWPORTELEMENT_H_
10 #include "mozilla/Attributes.h"
11 #include "nsIContentInlines.h"
12 #include "SVGAnimatedEnumeration.h"
13 #include "SVGAnimatedLength.h"
14 #include "SVGAnimatedPreserveAspectRatio.h"
15 #include "SVGAnimatedViewBox.h"
16 #include "SVGGraphicsElement.h"
17 #include "SVGPoint.h"
18 #include "SVGPreserveAspectRatio.h"
20 namespace mozilla {
21 class AutoPreserveAspectRatioOverride;
22 class SVGOuterSVGFrame;
23 class SVGViewportFrame;
25 namespace dom {
26 class DOMSVGAnimatedPreserveAspectRatio;
27 class SVGAnimatedRect;
28 class SVGViewElement;
29 class SVGViewportElement;
31 class SVGViewportElement : public SVGGraphicsElement {
32 friend class mozilla::SVGOuterSVGFrame;
33 friend class mozilla::SVGViewportFrame;
35 protected:
36 explicit SVGViewportElement(
37 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
38 ~SVGViewportElement() = default;
40 public:
41 // nsIContent interface
42 NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override;
44 // SVGElement specializations:
45 gfxMatrix ChildToUserSpaceTransform() const override;
47 bool HasValidDimensions() const override;
49 // SVGViewportElement methods:
51 float GetLength(uint8_t aCtxType) const;
53 // public helpers:
55 /**
56 * Returns true if this element has a base/anim value for its "viewBox"
57 * attribute that defines a viewBox rectangle with finite values, or
58 * if there is a view element overriding this element's viewBox and it
59 * has a valid viewBox.
61 * Note that this does not check whether we need to synthesize a viewBox,
62 * so you must call ShouldSynthesizeViewBox() if you need to chck that too.
64 * Note also that this method does not pay attention to whether the width or
65 * height values of the viewBox rect are positive!
67 bool HasViewBox() const { return GetViewBoxInternal().HasRect(); }
69 /**
70 * Returns true if we should synthesize a viewBox for ourselves (that is, if
71 * we're the root element in an image document, and we're not currently being
72 * painted for an <svg:image> element).
74 * Only call this method if HasViewBox() returns false.
76 bool ShouldSynthesizeViewBox() const;
78 bool HasViewBoxOrSyntheticViewBox() const {
79 return HasViewBox() || ShouldSynthesizeViewBox();
82 bool HasChildrenOnlyTransform() const { return mHasChildrenOnlyTransform; }
84 void UpdateHasChildrenOnlyTransform();
86 enum ChildrenOnlyTransformChangedFlags { eDuringReflow = 1 };
88 /**
89 * This method notifies the style system that the overflow rects of our
90 * immediate childrens' frames need to be updated. It is called by our own
91 * frame when changes (e.g. to currentScale) cause our children-only
92 * transform to change.
94 * The reason we have this method instead of overriding
95 * GetAttributeChangeHint is because we need to act on non-attribute (e.g.
96 * currentScale) changes in addition to attribute (e.g. viewBox) changes.
98 void ChildrenOnlyTransformChanged(uint32_t aFlags = 0);
100 gfx::Matrix GetViewBoxTransform() const;
102 gfx::Size GetViewportSize() const { return mViewportSize; }
104 void SetViewportSize(const gfx::Size& aSize) { mViewportSize = aSize; }
107 * Returns true if either this is an SVG <svg> element that is the child of
108 * another non-foreignObject SVG element, or this is a SVG <symbol> element
109 * that is the root of a use-element shadow tree.
111 bool IsInner() const {
112 const nsIContent* parent = GetFlattenedTreeParent();
113 return parent && parent->IsSVGElement() &&
114 !parent->IsSVGElement(nsGkAtoms::foreignObject);
117 // WebIDL
118 already_AddRefed<SVGAnimatedRect> ViewBox();
119 already_AddRefed<DOMSVGAnimatedPreserveAspectRatio> PreserveAspectRatio();
120 SVGAnimatedViewBox* GetAnimatedViewBox() override;
122 protected:
123 // implementation helpers:
125 bool IsRootSVGSVGElement() const {
126 NS_ASSERTION((IsInUncomposedDoc() && !GetParent()) ==
127 (OwnerDoc()->GetRootElement() == this),
128 "Can't determine if we're root");
129 return !GetParent() && IsInUncomposedDoc() && IsSVGElement(nsGkAtoms::svg);
133 * Returns the explicit or default preserveAspectRatio, unless we're
134 * synthesizing a viewBox, in which case it returns the "none" value.
136 virtual SVGPreserveAspectRatio GetPreserveAspectRatioWithOverride() const {
137 return mPreserveAspectRatio.GetAnimValue();
141 * Returns the explicit viewBox rect, if specified, or else a synthesized
142 * viewBox, if appropriate, or else a viewBox matching the dimensions of the
143 * SVG viewport.
145 SVGViewBox GetViewBoxWithSynthesis(float aViewportWidth,
146 float aViewportHeight) const;
148 enum { ATTR_X, ATTR_Y, ATTR_WIDTH, ATTR_HEIGHT };
149 SVGAnimatedLength mLengthAttributes[4];
150 static LengthInfo sLengthInfo[4];
151 LengthAttributesInfo GetLengthInfo() override;
153 SVGAnimatedPreserveAspectRatio* GetAnimatedPreserveAspectRatio() override;
155 virtual const SVGAnimatedViewBox& GetViewBoxInternal() const {
156 return mViewBox;
158 SVGAnimatedViewBox mViewBox;
159 SVGAnimatedPreserveAspectRatio mPreserveAspectRatio;
161 // The size of the rectangular SVG viewport into which we render. This is
162 // not (necessarily) the same as the content area. See:
164 // http://www.w3.org/TR/SVG11/coords.html#ViewportSpace
166 // XXXjwatt Currently only used for outer <svg>, but maybe we could use -1 to
167 // flag this as an inner <svg> to save the overhead of GetCtx calls?
168 // XXXjwatt our frame should probably reset this when it's destroyed.
169 gfx::Size mViewportSize;
171 bool mHasChildrenOnlyTransform;
174 } // namespace dom
176 } // namespace mozilla
178 #endif // DOM_SVG_SVGVIEWPORTELEMENT_H_