Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) Research In Motion Limited 2010. All rights reserved.
      3  *
      4  * This library is free software; you can redistribute it and/or
      5  * modify it under the terms of the GNU Library General Public
      6  * License as published by the Free Software Foundation; either
      7  * version 2 of the License, or (at your option) any later version.
      8  *
      9  * This library is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12  * Library General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU Library General Public License
     15  * along with this library; see the file COPYING.LIB.  If not, write to
     16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     17  * Boston, MA 02110-1301, USA.
     18  */
     19 
     20 #ifndef RenderSVGResourceContainer_h
     21 #define RenderSVGResourceContainer_h
     22 
     23 #include "core/rendering/svg/RenderSVGHiddenContainer.h"
     24 #include "core/rendering/svg/RenderSVGResource.h"
     25 
     26 namespace WebCore {
     27 
     28 class RenderLayer;
     29 
     30 class RenderSVGResourceContainer : public RenderSVGHiddenContainer,
     31                                    public RenderSVGResource {
     32 public:
     33     RenderSVGResourceContainer(SVGElement*);
     34     virtual ~RenderSVGResourceContainer();
     35 
     36     virtual void layout();
     37     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) OVERRIDE FINAL;
     38 
     39     virtual bool isSVGResourceContainer() const OVERRIDE FINAL { return true; }
     40     virtual RenderSVGResourceContainer* toRenderSVGResourceContainer() OVERRIDE FINAL { return this; }
     41 
     42     static bool shouldTransformOnTextPainting(RenderObject*, AffineTransform&);
     43     static AffineTransform transformOnNonScalingStroke(RenderObject*, const AffineTransform& resourceTransform);
     44 
     45     void idChanged();
     46     void addClientRenderLayer(RenderLayer*);
     47     void removeClientRenderLayer(RenderLayer*);
     48 
     49 protected:
     50     enum InvalidationMode {
     51         LayoutAndBoundariesInvalidation,
     52         BoundariesInvalidation,
     53         RepaintInvalidation,
     54         ParentOnlyInvalidation
     55     };
     56 
     57     // Used from the invalidateClient/invalidateClients methods from classes, inheriting from us.
     58     void markAllClientsForInvalidation(InvalidationMode);
     59     void markAllClientLayersForInvalidation();
     60     void markClientForInvalidation(RenderObject*, InvalidationMode);
     61 
     62 private:
     63     friend class SVGResourcesCache;
     64     void addClient(RenderObject*);
     65     void removeClient(RenderObject*);
     66 
     67 private:
     68     virtual void willBeDestroyed() OVERRIDE FINAL;
     69     void registerResource();
     70 
     71     AtomicString m_id;
     72     bool m_registered : 1;
     73     bool m_isInvalidating : 1;
     74     HashSet<RenderObject*> m_clients;
     75     HashSet<RenderLayer*> m_clientLayers;
     76 };
     77 
     78 inline RenderSVGResourceContainer* getRenderSVGResourceContainerById(Document* document, const AtomicString& id)
     79 {
     80     if (id.isEmpty())
     81         return 0;
     82 
     83     if (RenderSVGResourceContainer* renderResource = document->accessSVGExtensions()->resourceById(id))
     84         return renderResource;
     85 
     86     return 0;
     87 }
     88 
     89 template<typename Renderer>
     90 Renderer* getRenderSVGResourceById(Document* document, const AtomicString& id)
     91 {
     92     if (RenderSVGResourceContainer* container = getRenderSVGResourceContainerById(document, id))
     93         return container->cast<Renderer>();
     94 
     95     return 0;
     96 }
     97 
     98 }
     99 
    100 #endif
    101