1 /* 2 * Copyright 2016 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkSVGContainer_DEFINED 9 #define SkSVGContainer_DEFINED 10 11 #include "include/core/SkPath.h" 12 #include "include/core/SkRect.h" 13 #include "include/core/SkRefCnt.h" 14 #include "include/private/base/SkAPI.h" 15 #include "include/private/base/SkTArray.h" 16 #include "modules/svg/include/SkSVGNode.h" 17 #include "modules/svg/include/SkSVGTransformableNode.h" 18 19 class SkSVGRenderContext; 20 21 class SK_API SkSVGContainer : public SkSVGTransformableNode { 22 public: 23 void appendChild(sk_sp<SkSVGNode>) override; 24 25 protected: 26 explicit SkSVGContainer(SkSVGTag); 27 28 void onRender(const SkSVGRenderContext&) const override; 29 30 SkPath onAsPath(const SkSVGRenderContext&) const override; 31 32 SkRect onObjectBoundingBox(const SkSVGRenderContext&) const override; 33 34 bool hasChildren() const final; 35 36 template <typename NodeType, typename Func> forEachChild(Func func)37 void forEachChild(Func func) const { 38 for (const auto& child : fChildren) { 39 if (child->tag() == NodeType::tag) { 40 func(static_cast<const NodeType*>(child.get())); 41 } 42 } 43 } 44 45 // TODO: convert remaining direct users to iterators, and make the container private. 46 skia_private::STArray<1, sk_sp<SkSVGNode>, true> fChildren; 47 48 private: 49 using INHERITED = SkSVGTransformableNode; 50 }; 51 52 #endif // SkSVGContainer_DEFINED 53