tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SVGContainerFrame.h (5510B)


      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/. */
      6 
      7 #ifndef LAYOUT_SVG_SVGCONTAINERFRAME_H_
      8 #define LAYOUT_SVG_SVGCONTAINERFRAME_H_
      9 
     10 #include "mozilla/ISVGDisplayableFrame.h"
     11 #include "mozilla/UniquePtr.h"
     12 #include "nsContainerFrame.h"
     13 #include "nsIFrame.h"
     14 #include "nsQueryFrame.h"
     15 #include "nsRect.h"
     16 
     17 class gfxContext;
     18 class nsFrameList;
     19 class nsIContent;
     20 
     21 struct nsRect;
     22 
     23 namespace mozilla {
     24 class PresShell;
     25 }  // namespace mozilla
     26 
     27 nsIFrame* NS_NewSVGContainerFrame(mozilla::PresShell* aPresShell,
     28                                  mozilla::ComputedStyle* aStyle);
     29 
     30 namespace mozilla {
     31 
     32 /**
     33 * Base class for SVG container frames. Frame sub-classes that do not
     34 * display their contents directly (such as the frames for <marker> or
     35 * <pattern>) just inherit this class. Frame sub-classes that do or can
     36 * display their contents directly (such as the frames for inner-<svg> or
     37 * <g>) inherit our SVGDisplayContainerFrame sub-class.
     38 *
     39 *                               *** WARNING ***
     40 *
     41 * Do *not* blindly cast to SVG element types in this class's methods (see the
     42 * warning comment for SVGDisplayContainerFrame below).
     43 */
     44 class SVGContainerFrame : public nsContainerFrame {
     45  friend nsIFrame* ::NS_NewSVGContainerFrame(mozilla::PresShell* aPresShell,
     46                                             ComputedStyle* aStyle);
     47 
     48 protected:
     49  SVGContainerFrame(ComputedStyle* aStyle, nsPresContext* aPresContext,
     50                    ClassID aID)
     51      : nsContainerFrame(aStyle, aPresContext, aID) {
     52    AddStateBits(NS_FRAME_SVG_LAYOUT);
     53  }
     54 
     55 public:
     56  NS_DECL_QUERYFRAME
     57  NS_DECL_FRAMEARENA_HELPERS(SVGContainerFrame)
     58 
     59  // Returns the transform to our gfxContext (to device pixels, not CSS px)
     60  virtual gfxMatrix GetCanvasTM() { return gfxMatrix(); }
     61 
     62  /**
     63   * Returns true if the frame's content has a transform that applies only to
     64   * its children, and not to the frame itself. For example, an implicit
     65   * transform introduced by a 'viewBox' attribute, or an explicit transform
     66   * due to a root-<svg> having its currentScale/currentTransform properties
     67   * set. If aTransform is non-null, then it will be set to the transform.
     68   */
     69  virtual bool HasChildrenOnlyTransform(Matrix* aTransform) const {
     70    return false;
     71  }
     72 
     73  // nsIFrame:
     74  void AppendFrames(ChildListID aListID, nsFrameList&& aFrameList) override;
     75  void InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
     76                    const nsLineList::iterator* aPrevFrameLine,
     77                    nsFrameList&& aFrameList) override;
     78  void RemoveFrame(DestroyContext&, ChildListID, nsIFrame*) override;
     79  void BuildDisplayList(nsDisplayListBuilder* aBuilder,
     80                        const nsDisplayListSet& aLists) override {}
     81 
     82  bool ComputeCustomOverflow(mozilla::OverflowAreas& aOverflowAreas) override;
     83 
     84 protected:
     85  /**
     86   * Traverses a frame tree, marking any SVGTextFrame frames as dirty
     87   * and calling InvalidateRenderingObservers() on it.
     88   */
     89  static void ReflowSVGNonDisplayText(nsIFrame* aContainer);
     90 };
     91 
     92 /**
     93 * Frame class or base-class for SVG containers that can or do display their
     94 * contents directly.
     95 *
     96 *                               *** WARNING ***
     97 *
     98 * This class's methods can *not* assume that mContent points to an instance of
     99 * an SVG element class since this class is inherited by
    100 * SVGGenericContainerFrame which is used for unrecognized elements in the
    101 * SVG namespace. Do *not* blindly cast to SVG element types.
    102 */
    103 class SVGDisplayContainerFrame : public SVGContainerFrame,
    104                                 public ISVGDisplayableFrame {
    105 protected:
    106  SVGDisplayContainerFrame(ComputedStyle* aStyle, nsPresContext* aPresContext,
    107                           nsIFrame::ClassID aID)
    108      : SVGContainerFrame(aStyle, aPresContext, aID) {
    109    AddStateBits(NS_FRAME_MAY_BE_TRANSFORMED);
    110  }
    111 
    112 public:
    113  NS_DECL_QUERYFRAME
    114  NS_DECL_QUERYFRAME_TARGET(SVGDisplayContainerFrame)
    115  NS_DECL_ABSTRACT_FRAME(SVGDisplayContainerFrame)
    116 
    117  // nsIFrame:
    118  void DidSetComputedStyle(ComputedStyle*) override;
    119  void InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
    120                    const nsLineList::iterator* aPrevFrameLine,
    121                    nsFrameList&& aFrameList) override;
    122  void RemoveFrame(DestroyContext&, ChildListID, nsIFrame*) override;
    123  void Init(nsIContent* aContent, nsContainerFrame* aParent,
    124            nsIFrame* aPrevInFlow) override;
    125 
    126  void BuildDisplayList(nsDisplayListBuilder* aBuilder,
    127                        const nsDisplayListSet& aLists) override;
    128 
    129  bool DoGetParentSVGTransforms(Matrix*) const override;
    130 
    131  // ISVGDisplayableFrame interface:
    132  void PaintSVG(gfxContext& aContext, const gfxMatrix& aTransform,
    133                imgDrawingParams& aImgParams) override;
    134  nsIFrame* GetFrameForPoint(const gfxPoint& aPoint) override;
    135  void ReflowSVG() override;
    136  void NotifySVGChanged(ChangeFlags aFlags) override;
    137  SVGBBox GetBBoxContribution(const Matrix& aToBBoxUserspace,
    138                              uint32_t aFlags) override;
    139  bool IsDisplayContainer() override { return true; }
    140  gfxMatrix GetCanvasTM() override;
    141 
    142 protected:
    143  /**
    144   * Cached canvasTM value.
    145   */
    146  UniquePtr<gfxMatrix> mCanvasTM;
    147 };
    148 
    149 }  // namespace mozilla
    150 
    151 #endif  // LAYOUT_SVG_SVGCONTAINERFRAME_H_