layout/svg/nsSVGContainerFrame.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/svg/nsSVGContainerFrame.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,160 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef NS_SVGCONTAINERFRAME_H
    1.10 +#define NS_SVGCONTAINERFRAME_H
    1.11 +
    1.12 +#include "mozilla/Attributes.h"
    1.13 +#include "nsContainerFrame.h"
    1.14 +#include "nsFrame.h"
    1.15 +#include "nsIFrame.h"
    1.16 +#include "nsISVGChildFrame.h"
    1.17 +#include "nsQueryFrame.h"
    1.18 +#include "nsRect.h"
    1.19 +#include "nsSVGUtils.h"
    1.20 +
    1.21 +class nsFrameList;
    1.22 +class nsIContent;
    1.23 +class nsIPresShell;
    1.24 +class nsRenderingContext;
    1.25 +class nsStyleContext;
    1.26 +
    1.27 +struct nsPoint;
    1.28 +struct nsRect;
    1.29 +struct nsIntRect;
    1.30 +
    1.31 +typedef nsContainerFrame nsSVGContainerFrameBase;
    1.32 +
    1.33 +/**
    1.34 + * Base class for SVG container frames. Frame sub-classes that do not
    1.35 + * display their contents directly (such as the frames for <marker> or
    1.36 + * <pattern>) just inherit this class. Frame sub-classes that do or can
    1.37 + * display their contents directly (such as the frames for inner-<svg> or
    1.38 + * <g>) inherit our nsDisplayContainerFrame sub-class.
    1.39 + *
    1.40 + *                               *** WARNING ***
    1.41 + *
    1.42 + * Do *not* blindly cast to SVG element types in this class's methods (see the
    1.43 + * warning comment for nsSVGDisplayContainerFrame below). 
    1.44 + */
    1.45 +class nsSVGContainerFrame : public nsSVGContainerFrameBase
    1.46 +{
    1.47 +  friend nsIFrame* NS_NewSVGContainerFrame(nsIPresShell* aPresShell,
    1.48 +                                           nsStyleContext* aContext);
    1.49 +protected:
    1.50 +  nsSVGContainerFrame(nsStyleContext* aContext)
    1.51 +    : nsSVGContainerFrameBase(aContext)
    1.52 +  {
    1.53 +    AddStateBits(NS_FRAME_SVG_LAYOUT);
    1.54 +  }
    1.55 +
    1.56 +public:
    1.57 +  NS_DECL_QUERYFRAME_TARGET(nsSVGContainerFrame)
    1.58 +  NS_DECL_QUERYFRAME
    1.59 +  NS_DECL_FRAMEARENA_HELPERS
    1.60 +
    1.61 +  // Returns the transform to our gfxContext (to device pixels, not CSS px)
    1.62 +  virtual gfxMatrix GetCanvasTM(uint32_t aFor,
    1.63 +                                nsIFrame* aTransformRoot = nullptr) {
    1.64 +    return gfxMatrix();
    1.65 +  }
    1.66 +
    1.67 +  /**
    1.68 +   * Returns true if the frame's content has a transform that applies only to
    1.69 +   * its children, and not to the frame itself. For example, an implicit
    1.70 +   * transform introduced by a 'viewBox' attribute, or an explicit transform
    1.71 +   * due to a root-<svg> having its currentScale/currentTransform properties
    1.72 +   * set. If aTransform is non-null, then it will be set to the transform.
    1.73 +   */
    1.74 +  virtual bool HasChildrenOnlyTransform(Matrix *aTransform) const {
    1.75 +    return false;
    1.76 +  }
    1.77 +
    1.78 +  // nsIFrame:
    1.79 +  virtual nsresult AppendFrames(ChildListID     aListID,
    1.80 +                                nsFrameList&    aFrameList) MOZ_OVERRIDE;
    1.81 +  virtual nsresult InsertFrames(ChildListID     aListID,
    1.82 +                                nsIFrame*       aPrevFrame,
    1.83 +                                nsFrameList&    aFrameList) MOZ_OVERRIDE;
    1.84 +  virtual nsresult RemoveFrame(ChildListID     aListID,
    1.85 +                               nsIFrame*       aOldFrame) MOZ_OVERRIDE;
    1.86 +
    1.87 +  virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
    1.88 +  {
    1.89 +    return nsSVGContainerFrameBase::IsFrameOfType(
    1.90 +            aFlags & ~(nsIFrame::eSVG | nsIFrame::eSVGContainer));
    1.91 +  }
    1.92 +
    1.93 +  virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
    1.94 +                                const nsRect&           aDirtyRect,
    1.95 +                                const nsDisplayListSet& aLists) MOZ_OVERRIDE {}
    1.96 +
    1.97 +  virtual bool UpdateOverflow() MOZ_OVERRIDE;
    1.98 +
    1.99 +protected:
   1.100 +  /**
   1.101 +   * Traverses a frame tree, marking any SVGTextFrame frames as dirty
   1.102 +   * and calling InvalidateRenderingObservers() on it.
   1.103 +   */
   1.104 +  static void ReflowSVGNonDisplayText(nsIFrame* aContainer);
   1.105 +};
   1.106 +
   1.107 +/**
   1.108 + * Frame class or base-class for SVG containers that can or do display their
   1.109 + * contents directly.
   1.110 + *
   1.111 + *                               *** WARNING ***
   1.112 + *
   1.113 + * This class's methods can *not* assume that mContent points to an instance of
   1.114 + * an SVG element class since this class is inherited by
   1.115 + * nsSVGGenericContainerFrame which is used for unrecognized elements in the
   1.116 + * SVG namespace. Do *not* blindly cast to SVG element types.
   1.117 + */
   1.118 +class nsSVGDisplayContainerFrame : public nsSVGContainerFrame,
   1.119 +                                   public nsISVGChildFrame
   1.120 +{
   1.121 +protected:
   1.122 +  nsSVGDisplayContainerFrame(nsStyleContext* aContext)
   1.123 +    : nsSVGContainerFrame(aContext)
   1.124 +  {
   1.125 +     AddStateBits(NS_FRAME_MAY_BE_TRANSFORMED);
   1.126 +  }
   1.127 +
   1.128 +public:
   1.129 +  NS_DECL_QUERYFRAME_TARGET(nsSVGDisplayContainerFrame)
   1.130 +  NS_DECL_QUERYFRAME
   1.131 +  NS_DECL_FRAMEARENA_HELPERS
   1.132 +
   1.133 +  // nsIFrame:
   1.134 +  virtual nsresult InsertFrames(ChildListID     aListID,
   1.135 +                                nsIFrame*       aPrevFrame,
   1.136 +                                nsFrameList&    aFrameList) MOZ_OVERRIDE;
   1.137 +  virtual nsresult RemoveFrame(ChildListID     aListID,
   1.138 +                               nsIFrame*       aOldFrame) MOZ_OVERRIDE;
   1.139 + virtual void Init(nsIContent*      aContent,
   1.140 +                   nsIFrame*        aParent,
   1.141 +                   nsIFrame*        aPrevInFlow) MOZ_OVERRIDE;
   1.142 +
   1.143 +  virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
   1.144 +                                const nsRect&           aDirtyRect,
   1.145 +                                const nsDisplayListSet& aLists) MOZ_OVERRIDE;
   1.146 +
   1.147 +  virtual bool IsSVGTransformed(Matrix *aOwnTransform = nullptr,
   1.148 +                                Matrix *aFromParentTransform = nullptr) const MOZ_OVERRIDE;
   1.149 +
   1.150 +  // nsISVGChildFrame interface:
   1.151 +  virtual nsresult PaintSVG(nsRenderingContext* aContext,
   1.152 +                            const nsIntRect *aDirtyRect,
   1.153 +                            nsIFrame* aTransformRoot = nullptr) MOZ_OVERRIDE;
   1.154 +  virtual nsIFrame* GetFrameForPoint(const nsPoint &aPoint) MOZ_OVERRIDE;
   1.155 +  virtual nsRect GetCoveredRegion() MOZ_OVERRIDE;
   1.156 +  virtual void ReflowSVG() MOZ_OVERRIDE;
   1.157 +  virtual void NotifySVGChanged(uint32_t aFlags) MOZ_OVERRIDE;
   1.158 +  virtual SVGBBox GetBBoxContribution(const Matrix &aToBBoxUserspace,
   1.159 +                                      uint32_t aFlags) MOZ_OVERRIDE;
   1.160 +  virtual bool IsDisplayContainer() MOZ_OVERRIDE { return true; }
   1.161 +};
   1.162 +
   1.163 +#endif

mercurial