Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) 2006 Oliver Hunt <ojh16 (at) student.canterbury.ac.nz>
      3  * Copyright (C) 2006 Apple Inc. All rights reserved.
      4  * Copyright (C) Research In Motion Limited 2010. All rights reserved.
      5  *
      6  * This library is free software; you can redistribute it and/or
      7  * modify it under the terms of the GNU Library General Public
      8  * License as published by the Free Software Foundation; either
      9  * version 2 of the License, or (at your option) any later version.
     10  *
     11  * This library is distributed in the hope that it will be useful,
     12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14  * Library General Public License for more details.
     15  *
     16  * You should have received a copy of the GNU Library General Public License
     17  * along with this library; see the file COPYING.LIB.  If not, write to
     18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     19  * Boston, MA 02110-1301, USA.
     20  */
     21 
     22 #include "config.h"
     23 
     24 #include "core/rendering/svg/RenderSVGInline.h"
     25 
     26 #include "core/rendering/svg/RenderSVGText.h"
     27 #include "core/rendering/svg/SVGInlineFlowBox.h"
     28 #include "core/rendering/svg/SVGRenderSupport.h"
     29 #include "core/rendering/svg/SVGResourcesCache.h"
     30 
     31 namespace WebCore {
     32 
     33 bool RenderSVGInline::isChildAllowed(RenderObject* child, RenderStyle* style) const
     34 {
     35     if (SVGRenderSupport::isEmptySVGInlineText(child))
     36         return false;
     37 
     38     return RenderInline::isChildAllowed(child, style);
     39 }
     40 
     41 RenderSVGInline::RenderSVGInline(Element* element)
     42     : RenderInline(element)
     43 {
     44     setAlwaysCreateLineBoxes();
     45 }
     46 
     47 InlineFlowBox* RenderSVGInline::createInlineFlowBox()
     48 {
     49     InlineFlowBox* box = new SVGInlineFlowBox(this);
     50     box->setHasVirtualLogicalHeight();
     51     return box;
     52 }
     53 
     54 FloatRect RenderSVGInline::objectBoundingBox() const
     55 {
     56     if (const RenderObject* object = RenderSVGText::locateRenderSVGTextAncestor(this))
     57         return object->objectBoundingBox();
     58 
     59     return FloatRect();
     60 }
     61 
     62 FloatRect RenderSVGInline::strokeBoundingBox() const
     63 {
     64     if (const RenderObject* object = RenderSVGText::locateRenderSVGTextAncestor(this))
     65         return object->strokeBoundingBox();
     66 
     67     return FloatRect();
     68 }
     69 
     70 FloatRect RenderSVGInline::repaintRectInLocalCoordinates() const
     71 {
     72     if (const RenderObject* object = RenderSVGText::locateRenderSVGTextAncestor(this))
     73         return object->repaintRectInLocalCoordinates();
     74 
     75     return FloatRect();
     76 }
     77 
     78 LayoutRect RenderSVGInline::clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const
     79 {
     80     return SVGRenderSupport::clippedOverflowRectForRepaint(this, repaintContainer);
     81 }
     82 
     83 void RenderSVGInline::computeFloatRectForRepaint(const RenderLayerModelObject* repaintContainer, FloatRect& repaintRect, bool fixed) const
     84 {
     85     SVGRenderSupport::computeFloatRectForRepaint(this, repaintContainer, repaintRect, fixed);
     86 }
     87 
     88 void RenderSVGInline::mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState& transformState, MapCoordinatesFlags, bool* wasFixed) const
     89 {
     90     SVGRenderSupport::mapLocalToContainer(this, repaintContainer, transformState, wasFixed);
     91 }
     92 
     93 const RenderObject* RenderSVGInline::pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap& geometryMap) const
     94 {
     95     return SVGRenderSupport::pushMappingToContainer(this, ancestorToStopAt, geometryMap);
     96 }
     97 
     98 void RenderSVGInline::absoluteQuads(Vector<FloatQuad>& quads, bool* wasFixed) const
     99 {
    100     const RenderObject* object = RenderSVGText::locateRenderSVGTextAncestor(this);
    101     if (!object)
    102         return;
    103 
    104     FloatRect textBoundingBox = object->strokeBoundingBox();
    105     for (InlineFlowBox* box = firstLineBox(); box; box = box->nextLineBox())
    106         quads.append(localToAbsoluteQuad(FloatRect(textBoundingBox.x() + box->x(), textBoundingBox.y() + box->y(), box->logicalWidth(), box->logicalHeight()), false, wasFixed));
    107 }
    108 
    109 void RenderSVGInline::willBeDestroyed()
    110 {
    111     SVGResourcesCache::clientDestroyed(this);
    112     RenderInline::willBeDestroyed();
    113 }
    114 
    115 void RenderSVGInline::styleWillChange(StyleDifference diff, const RenderStyle* newStyle)
    116 {
    117     if (diff == StyleDifferenceLayout)
    118         setNeedsBoundariesUpdate();
    119     RenderInline::styleWillChange(diff, newStyle);
    120 }
    121 
    122 void RenderSVGInline::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
    123 {
    124     RenderInline::styleDidChange(diff, oldStyle);
    125     SVGResourcesCache::clientStyleChanged(this, diff, style());
    126 }
    127 
    128 void RenderSVGInline::addChild(RenderObject* child, RenderObject* beforeChild)
    129 {
    130     RenderInline::addChild(child, beforeChild);
    131     SVGResourcesCache::clientWasAddedToTree(child, child->style());
    132 
    133     if (RenderSVGText* textRenderer = RenderSVGText::locateRenderSVGTextAncestor(this))
    134         textRenderer->subtreeChildWasAdded(child);
    135 }
    136 
    137 void RenderSVGInline::removeChild(RenderObject* child)
    138 {
    139     SVGResourcesCache::clientWillBeRemovedFromTree(child);
    140 
    141     RenderSVGText* textRenderer = RenderSVGText::locateRenderSVGTextAncestor(this);
    142     if (!textRenderer) {
    143         RenderInline::removeChild(child);
    144         return;
    145     }
    146     Vector<SVGTextLayoutAttributes*, 2> affectedAttributes;
    147     textRenderer->subtreeChildWillBeRemoved(child, affectedAttributes);
    148     RenderInline::removeChild(child);
    149     textRenderer->subtreeChildWasRemoved(affectedAttributes);
    150 }
    151 
    152 }
    153