Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann (at) kde.org>
      3  * Copyright (C) 2004, 2005, 2007 Rob Buis <buis (at) kde.org>
      4  * Copyright (C) 2007 Eric Seidel <eric (at) webkit.org>
      5  * Copyright (C) 2009 Google, Inc.
      6  *
      7  * This library is free software; you can redistribute it and/or
      8  * modify it under the terms of the GNU Library General Public
      9  * License as published by the Free Software Foundation; either
     10  * version 2 of the License, or (at your option) any later version.
     11  *
     12  * This library is distributed in the hope that it will be useful,
     13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15  * Library General Public License for more details.
     16  *
     17  * You should have received a copy of the GNU Library General Public License
     18  * along with this library; see the file COPYING.LIB.  If not, write to
     19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     20  * Boston, MA 02110-1301, USA.
     21  */
     22 
     23 #include "config.h"
     24 
     25 #if ENABLE(SVG)
     26 #include "RenderSVGViewportContainer.h"
     27 
     28 #include "GraphicsContext.h"
     29 #include "RenderView.h"
     30 #include "SVGNames.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 
     52          FloatRect oldViewport = m_viewport;
     53          m_viewport = FloatRect(svg->x().value(svg)
     54                                 , svg->y().value(svg)
     55                                 , svg->width().value(svg)
     56                                 , svg->height().value(svg));
     57 
     58         if (oldViewport != m_viewport)
     59             setNeedsBoundariesUpdate();
     60     }
     61 }
     62 
     63 AffineTransform RenderSVGViewportContainer::viewportTransform() const
     64 {
     65     if (node()->hasTagName(SVGNames::svgTag)) {
     66         SVGSVGElement* svg = static_cast<SVGSVGElement*>(node());
     67         return svg->viewBoxToViewTransform(m_viewport.width(), m_viewport.height());
     68     }
     69 
     70     return AffineTransform();
     71 }
     72 
     73 const AffineTransform& RenderSVGViewportContainer::localToParentTransform() const
     74 {
     75     m_localToParentTransform = AffineTransform::translation(m_viewport.x(), m_viewport.y()) * viewportTransform();
     76     return m_localToParentTransform;
     77     // If this class were ever given a localTransform(), then the above would read:
     78     // return viewportTranslation * localTransform() * viewportTransform()
     79 }
     80 
     81 bool RenderSVGViewportContainer::pointIsInsideViewportClip(const FloatPoint& pointInParent)
     82 {
     83     // Respect the viewport clip (which is in parent coords)
     84     if (!SVGRenderSupport::isOverflowHidden(this))
     85         return true;
     86 
     87     return m_viewport.contains(pointInParent);
     88 }
     89 
     90 }
     91 
     92 #endif // ENABLE(SVG)
     93