WebCore/rendering/RenderSVGViewportContainer.cpp
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2     Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
       
     3                   2004, 2005, 2007 Rob Buis <buis@kde.org>
       
     4                   2007 Eric Seidel <eric@webkit.org>
       
     5                   2009 Google, Inc.
       
     6     Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
       
     7 
       
     8     This library is free software; you can redistribute it and/or
       
     9     modify it under the terms of the GNU Library General Public
       
    10     License as published by the Free Software Foundation; either
       
    11     version 2 of the License, or (at your option) any later version.
       
    12 
       
    13     This library is distributed in the hope that it will be useful,
       
    14     but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    16     Library General Public License for more details.
       
    17 
       
    18     You should have received a copy of the GNU Library General Public License
       
    19     aint with this library; see the file COPYING.LIB.  If not, write to
       
    20     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
       
    21     Boston, MA 02110-1301, USA.
       
    22 */
       
    23 
       
    24 #include "config.h"
       
    25 
       
    26 #if ENABLE(SVG)
       
    27 #include "RenderSVGViewportContainer.h"
       
    28 
       
    29 #include "GraphicsContext.h"
       
    30 #include "RenderView.h"
       
    31 #include "SVGSVGElement.h"
       
    32 
       
    33 namespace WebCore {
       
    34 
       
    35 RenderSVGViewportContainer::RenderSVGViewportContainer(SVGStyledElement* node)
       
    36     : RenderSVGContainer(node)
       
    37 {
       
    38 }
       
    39 
       
    40 void RenderSVGViewportContainer::applyViewportClip(PaintInfo& paintInfo)
       
    41 {
       
    42     if (SVGRenderSupport::isOverflowHidden(this))
       
    43         paintInfo.context->clip(m_viewport);
       
    44 }
       
    45 
       
    46 void RenderSVGViewportContainer::calcViewport()
       
    47 {
       
    48      SVGElement* element = static_cast<SVGElement*>(node());
       
    49      if (element->hasTagName(SVGNames::svgTag)) {
       
    50          SVGSVGElement* svg = static_cast<SVGSVGElement*>(element);
       
    51          m_viewport = FloatRect(svg->x().value(svg)
       
    52                                 , svg->y().value(svg)
       
    53                                 , svg->width().value(svg)
       
    54                                 , svg->height().value(svg));
       
    55     }
       
    56 }
       
    57 
       
    58 AffineTransform RenderSVGViewportContainer::viewportTransform() const
       
    59 {
       
    60     if (node()->hasTagName(SVGNames::svgTag)) {
       
    61         SVGSVGElement* svg = static_cast<SVGSVGElement*>(node());
       
    62         return svg->viewBoxToViewTransform(m_viewport.width(), m_viewport.height());
       
    63     }
       
    64 
       
    65     return AffineTransform();
       
    66 }
       
    67 
       
    68 const AffineTransform& RenderSVGViewportContainer::localToParentTransform() const
       
    69 {
       
    70     AffineTransform viewportTranslation(viewportTransform());
       
    71     m_localToParentTransform = viewportTranslation.translateRight(m_viewport.x(), m_viewport.y());
       
    72     return m_localToParentTransform;
       
    73     // If this class were ever given a localTransform(), then the above would read:
       
    74     // return viewportTransform() * localTransform() * viewportTranslation;
       
    75 }
       
    76 
       
    77 bool RenderSVGViewportContainer::pointIsInsideViewportClip(const FloatPoint& pointInParent)
       
    78 {
       
    79     // Respect the viewport clip (which is in parent coords)
       
    80     if (!SVGRenderSupport::isOverflowHidden(this))
       
    81         return true;
       
    82     
       
    83     return m_viewport.contains(pointInParent);
       
    84 }
       
    85 
       
    86 }
       
    87 
       
    88 #endif // ENABLE(SVG)