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 #if ENABLE(SVG)
24 #include "RenderSVGHiddenContainer.h"
25 #include "RenderSVGResource.h"
26 
27 namespace WebCore {
28 
29 class RenderSVGResourceContainer : public RenderSVGHiddenContainer,
30                                    public RenderSVGResource {
31 public:
32     RenderSVGResourceContainer(SVGStyledElement*);
33     virtual ~RenderSVGResourceContainer();
34 
35     virtual void layout();
36     virtual void destroy();
37     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
38 
isSVGResourceContainer()39     virtual bool isSVGResourceContainer() const { return true; }
toRenderSVGResourceContainer()40     virtual RenderSVGResourceContainer* toRenderSVGResourceContainer() { return this; }
41 
42     static AffineTransform transformOnNonScalingStroke(RenderObject*, const AffineTransform& resourceTransform);
43 
44     void idChanged();
45 
46 protected:
47     enum InvalidationMode {
48         LayoutAndBoundariesInvalidation,
49         BoundariesInvalidation,
50         RepaintInvalidation,
51         ParentOnlyInvalidation
52     };
53 
54     // Used from the invalidateClient/invalidateClients methods from classes, inheriting from us.
55     void markAllClientsForInvalidation(InvalidationMode);
56     void markClientForInvalidation(RenderObject*, InvalidationMode);
57 
58 private:
59     friend class SVGResourcesCache;
60     void addClient(RenderObject*);
61     void removeClient(RenderObject*);
62 
63 private:
64     void registerResource();
65 
66     AtomicString m_id;
67     bool m_registered;
68     HashSet<RenderObject*> m_clients;
69 };
70 
getRenderSVGResourceContainerById(Document * document,const AtomicString & id)71 inline RenderSVGResourceContainer* getRenderSVGResourceContainerById(Document* document, const AtomicString& id)
72 {
73     if (id.isEmpty())
74         return 0;
75 
76     if (RenderSVGResourceContainer* renderResource = document->accessSVGExtensions()->resourceById(id))
77         return renderResource;
78 
79     return 0;
80 }
81 
82 template<typename Renderer>
getRenderSVGResourceById(Document * document,const AtomicString & id)83 Renderer* getRenderSVGResourceById(Document* document, const AtomicString& id)
84 {
85     if (RenderSVGResourceContainer* container = getRenderSVGResourceContainerById(document, id))
86         return container->cast<Renderer>();
87 
88     return 0;
89 }
90 
91 }
92 
93 #endif
94 #endif
95