LCOV - app.info - layout/svg/base/src/nsSVGInnerSVGFrame.cpp

LCOV - code coverage report
| Current view: | directory - layout/svg/base/src - nsSVGInnerSVGFrame.cpp (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 88 | 0 | 0.0 %
| Date: | 2012-04-21 | Functions: | 14 | 0 | 0.0 %

           1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
           2                 : /* ***** BEGIN LICENSE BLOCK *****
           3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
           4                 :  *
           5                 :  * The contents of this file are subject to the Mozilla Public License Version
           6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
           7                 :  * the License. You may obtain a copy of the License at
           8                 :  * http://www.mozilla.org/MPL/
           9                 :  *
          10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
          11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
          12                 :  * for the specific language governing rights and limitations under the
          13                 :  * License.
          14                 :  *
          15                 :  * The Original Code is the Mozilla SVG project.
          16                 :  *
          17                 :  * The Initial Developer of the Original Code is
          18                 :  * Crocodile Clips Ltd..
          19                 :  * Portions created by the Initial Developer are Copyright (C) 2001
          20                 :  * the Initial Developer. All Rights Reserved.
          21                 :  *
          22                 :  * Contributor(s):
          23                 :  *   Alex Fritze <alex.fritze@crocodile-clips.com> (original author)
          24                 :  *
          25                 :  * Alternatively, the contents of this file may be used under the terms of
          26                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
          27                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
          28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
          29                 :  * of those above. If you wish to allow use of your version of this file only
          30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
          31                 :  * use your version of this file under the terms of the MPL, indicate your
          32                 :  * decision by deleting the provisions above and replace them with the notice
          33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
          34                 :  * the provisions above, a recipient may use your version of this file under
          35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
          36                 :  *
          37                 :  * ***** END LICENSE BLOCK ***** */
          38                 :
          39                 : #include "nsSVGInnerSVGFrame.h"
          40                 : #include "nsIFrame.h"
          41                 : #include "nsISVGChildFrame.h"
          42                 : #include "nsIDOMSVGAnimatedRect.h"
          43                 : #include "nsSVGSVGElement.h"
          44                 : #include "nsSVGContainerFrame.h"
          45                 : #include "gfxContext.h"
          46                 :
          47                 : nsIFrame*
          48               0 : NS_NewSVGInnerSVGFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
          49                 : {
          50               0 :   return new (aPresShell) nsSVGInnerSVGFrame(aContext);
          51                 : }
          52                 :
          53               0 : NS_IMPL_FRAMEARENA_HELPERS(nsSVGInnerSVGFrame)
          54                 :
          55                 : //----------------------------------------------------------------------
          56                 : // nsIFrame methods
          57                 :
          58               0 : NS_QUERYFRAME_HEAD(nsSVGInnerSVGFrame)
          59               0 :   NS_QUERYFRAME_ENTRY(nsSVGInnerSVGFrame)
          60               0 :   NS_QUERYFRAME_ENTRY(nsISVGSVGFrame)
          61               0 : NS_QUERYFRAME_TAIL_INHERITING(nsSVGInnerSVGFrameBase)
          62                 :
          63                 : #ifdef DEBUG
          64                 : NS_IMETHODIMP
          65               0 : nsSVGInnerSVGFrame::Init(nsIContent* aContent,
          66                 :                          nsIFrame* aParent,
          67                 :                          nsIFrame* aPrevInFlow)
          68                 : {
          69               0 :   nsCOMPtr<nsIDOMSVGSVGElement> svg = do_QueryInterface(aContent);
          70               0 :   NS_ASSERTION(svg, "Content is not an SVG 'svg' element!");
          71                 :
          72               0 :   return nsSVGInnerSVGFrameBase::Init(aContent, aParent, aPrevInFlow);
          73                 : }
          74                 : #endif /* DEBUG */
          75                 :
          76                 : nsIAtom *
          77               0 : nsSVGInnerSVGFrame::GetType() const
          78                 : {
          79               0 :   return nsGkAtoms::svgInnerSVGFrame;
          80                 : }
          81                 :
          82                 : //----------------------------------------------------------------------
          83                 : // nsISVGChildFrame methods
          84                 :
          85                 : NS_IMETHODIMP
          86               0 : nsSVGInnerSVGFrame::PaintSVG(nsRenderingContext *aContext,
          87                 :                              const nsIntRect *aDirtyRect)
          88                 : {
          89               0 :   gfxContextAutoSaveRestore autoSR;
          90                 :
          91               0 :   if (GetStyleDisplay()->IsScrollableOverflow()) {
          92                 :     float x, y, width, height;
          93                 :     static_cast<nsSVGSVGElement*>(mContent)->
          94               0 :       GetAnimatedLengthValues(&x, &y, &width, &height, nsnull);
          95                 :
          96               0 :     if (width <= 0 || height <= 0) {
          97               0 :       return NS_OK;
          98                 :     }
          99                 :
         100               0 :     nsSVGContainerFrame *parent = static_cast<nsSVGContainerFrame*>(mParent);
         101               0 :     gfxMatrix clipTransform = parent->GetCanvasTM();
         102                 :
         103               0 :     gfxContext *gfx = aContext->ThebesContext();
         104               0 :     autoSR.SetContext(gfx);
         105                 :     gfxRect clipRect =
         106               0 :       nsSVGUtils::GetClipRectForFrame(this, x, y, width, height);
         107               0 :     nsSVGUtils::SetClipRect(gfx, clipTransform, clipRect);
         108                 :   }
         109                 :
         110               0 :   return nsSVGInnerSVGFrameBase::PaintSVG(aContext, aDirtyRect);
         111                 : }
         112                 :
         113                 : void
         114               0 : nsSVGInnerSVGFrame::NotifySVGChanged(PRUint32 aFlags)
         115                 : {
         116               0 :   NS_ABORT_IF_FALSE(!(aFlags & DO_NOT_NOTIFY_RENDERING_OBSERVERS) ||
         117                 :                     (GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD),
         118                 :                     "Must be NS_STATE_SVG_NONDISPLAY_CHILD!");
         119                 :
         120               0 :   NS_ABORT_IF_FALSE(aFlags & (TRANSFORM_CHANGED | COORD_CONTEXT_CHANGED),
         121                 :                     "Invalidation logic may need adjusting");
         122                 :
         123               0 :   if (aFlags & COORD_CONTEXT_CHANGED) {
         124                 :
         125               0 :     nsSVGSVGElement *svg = static_cast<nsSVGSVGElement*>(mContent);
         126                 :
         127                 :     // Coordinate context changes affect mCanvasTM if we have a
         128                 :     // percentage 'x' or 'y', or if we have a percentage 'width' or 'height' AND
         129                 :     // a 'viewBox'.
         130                 :
         131               0 :     if (!(aFlags & TRANSFORM_CHANGED) &&
         132               0 :         (svg->mLengthAttributes[nsSVGSVGElement::X].IsPercentage() ||
         133               0 :          svg->mLengthAttributes[nsSVGSVGElement::Y].IsPercentage() ||
         134               0 :          (svg->mViewBox.IsValid() &&
         135               0 :           (svg->mLengthAttributes[nsSVGSVGElement::WIDTH].IsPercentage() ||
         136               0 :            svg->mLengthAttributes[nsSVGSVGElement::HEIGHT].IsPercentage())))) {
         137                 :
         138               0 :       aFlags |= TRANSFORM_CHANGED;
         139                 :     }
         140                 :
         141                 :     // XXX We could clear the COORD_CONTEXT_CHANGED flag in some circumstances
         142                 :     // if we have a non-percentage 'width' AND 'height, or if we have a 'viewBox'
         143                 :     // rect. This is because, when we have a viewBox rect, the viewBox rect
         144                 :     // is the coordinate context for our children, and it isn't changing.
         145                 :     // Percentage lengths on our children will continue to resolve to the
         146                 :     // same number of user units because they're relative to our viewBox rect. The
         147                 :     // same is true if we have a non-percentage width and height and don't have a
         148                 :     // viewBox. We (the <svg>) establish the coordinate context for our children. Our
         149                 :     // children don't care about changes to our parent coordinate context unless that
         150                 :     // change results in a change to the coordinate context that _we_ establish. Hence
         151                 :     // we can (should, really) stop propagating COORD_CONTEXT_CHANGED in these cases.
         152                 :     // We'd actually need to check that we have a viewBox rect and not just
         153                 :     // that viewBox is set, since it could be set to none.
         154                 :     // Take care not to break the testcase for bug 394463 when implementing this
         155                 :   }
         156                 :
         157               0 :   if (aFlags & TRANSFORM_CHANGED) {
         158                 :     // make sure our cached transform matrix gets (lazily) updated
         159               0 :     mCanvasTM = nsnull;
         160                 :   }
         161                 :
         162               0 :   nsSVGInnerSVGFrameBase::NotifySVGChanged(aFlags);
         163               0 : }
         164                 :
         165                 : NS_IMETHODIMP
         166               0 : nsSVGInnerSVGFrame::AttributeChanged(PRInt32  aNameSpaceID,
         167                 :                                      nsIAtom* aAttribute,
         168                 :                                      PRInt32  aModType)
         169                 : {
         170               0 :   if (aNameSpaceID == kNameSpaceID_None) {
         171               0 :     if (aAttribute == nsGkAtoms::width ||
         172                 :         aAttribute == nsGkAtoms::height) {
         173                 :
         174               0 :       nsSVGSVGElement* svg = static_cast<nsSVGSVGElement*>(mContent);
         175               0 :       if (svg->mViewBox.IsValid()) {
         176                 :
         177                 :         // make sure our cached transform matrix gets (lazily) updated
         178               0 :         mCanvasTM = nsnull;
         179                 :
         180               0 :         nsSVGUtils::NotifyChildrenOfSVGChange(this, TRANSFORM_CHANGED);
         181                 :       } else {
         182                 :
         183               0 :         PRUint32 flags = COORD_CONTEXT_CHANGED;
         184                 :
         185               0 :         if (mCanvasTM && mCanvasTM->IsSingular()) {
         186                 :
         187               0 :           mCanvasTM = nsnull;
         188                 :
         189               0 :           flags |= TRANSFORM_CHANGED;
         190                 :         }
         191               0 :         nsSVGUtils::NotifyChildrenOfSVGChange(this, flags);
         192               0 :       }
         193                 :
         194               0 :     } else if (aAttribute == nsGkAtoms::transform ||
         195                 :                aAttribute == nsGkAtoms::preserveAspectRatio ||
         196                 :                aAttribute == nsGkAtoms::viewBox ||
         197                 :                aAttribute == nsGkAtoms::x ||
         198                 :                aAttribute == nsGkAtoms::y) {
         199                 :       // make sure our cached transform matrix gets (lazily) updated
         200               0 :       mCanvasTM = nsnull;
         201                 :
         202                 :       nsSVGUtils::NotifyChildrenOfSVGChange(
         203                 :           this, aAttribute == nsGkAtoms::viewBox ?
         204               0 :                   TRANSFORM_CHANGED | COORD_CONTEXT_CHANGED : TRANSFORM_CHANGED);
         205                 :     }
         206                 :   }
         207                 :
         208               0 :   return NS_OK;
         209                 : }
         210                 :
         211                 : NS_IMETHODIMP_(nsIFrame*)
         212               0 : nsSVGInnerSVGFrame::GetFrameForPoint(const nsPoint &aPoint)
         213                 : {
         214               0 :   if (GetStyleDisplay()->IsScrollableOverflow()) {
         215               0 :     nsSVGElement *content = static_cast<nsSVGElement*>(mContent);
         216               0 :     nsSVGContainerFrame *parent = static_cast<nsSVGContainerFrame*>(mParent);
         217                 :
         218                 :     float clipX, clipY, clipWidth, clipHeight;
         219               0 :     content->GetAnimatedLengthValues(&clipX, &clipY, &clipWidth, &clipHeight, nsnull);
         220                 :
         221               0 :     if (!nsSVGUtils::HitTestRect(parent->GetCanvasTM(),
         222                 :                                  clipX, clipY, clipWidth, clipHeight,
         223               0 :                                  PresContext()->AppUnitsToDevPixels(aPoint.x),
         224               0 :                                  PresContext()->AppUnitsToDevPixels(aPoint.y))) {
         225               0 :       return nsnull;
         226                 :     }
         227                 :   }
         228                 :
         229               0 :   return nsSVGInnerSVGFrameBase::GetFrameForPoint(aPoint);
         230                 : }
         231                 :
         232                 : //----------------------------------------------------------------------
         233                 : // nsISVGSVGFrame methods:
         234                 :
         235                 : void
         236               0 : nsSVGInnerSVGFrame::SuspendRedraw()
         237                 : {
         238               0 :   if (GetParent()->GetStateBits() & NS_STATE_SVG_REDRAW_SUSPENDED)
         239               0 :     return;
         240                 :
         241               0 :   nsSVGUtils::NotifyRedrawSuspended(this);
         242                 : }
         243                 :
         244                 : void
         245               0 : nsSVGInnerSVGFrame::UnsuspendRedraw()
         246                 : {
         247               0 :   if (GetParent()->GetStateBits() & NS_STATE_SVG_REDRAW_SUSPENDED)
         248               0 :     return;
         249                 :
         250               0 :   nsSVGUtils::NotifyRedrawUnsuspended(this);
         251                 : }
         252                 :
         253                 : void
         254               0 : nsSVGInnerSVGFrame::NotifyViewportChange()
         255                 : {
         256               0 :   NS_ERROR("Inner SVG frames should not get Viewport changes.");
         257               0 : }
         258                 :
         259                 : //----------------------------------------------------------------------
         260                 : // nsSVGContainerFrame methods:
         261                 :
         262                 : gfxMatrix
         263               0 : nsSVGInnerSVGFrame::GetCanvasTM()
         264                 : {
         265               0 :   if (!mCanvasTM) {
         266               0 :     NS_ASSERTION(mParent, "null parent");
         267                 :
         268               0 :     nsSVGContainerFrame *parent = static_cast<nsSVGContainerFrame*>(mParent);
         269               0 :     nsSVGSVGElement *content = static_cast<nsSVGSVGElement*>(mContent);
         270                 :
         271               0 :     gfxMatrix tm = content->PrependLocalTransformsTo(parent->GetCanvasTM());
         272                 :
         273               0 :     mCanvasTM = new gfxMatrix(tm);
         274                 :   }
         275               0 :   return *mCanvasTM;
         276                 : }
         277                 :

Generated by: LCOV version 1.7