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 std::vector<sk_sp<SkSVGNode>> getChild() override; 25 26 protected: 27 explicit SkSVGContainer(SkSVGTag); 28 29 void onRender(const SkSVGRenderContext&) const override; 30 31 SkPath onAsPath(const SkSVGRenderContext&) const override; 32 33 SkRect onTransformableObjectBoundingBox(const SkSVGRenderContext&) const final; 34 35 bool hasChildren() const final; 36 37 template <typename NodeType, typename Func> forEachChild(Func func)38 void forEachChild(Func func) const { 39 for (const auto& child : fChildren) { 40 if (child->tag() == NodeType::tag) { 41 func(static_cast<const NodeType*>(child.get())); 42 } 43 } 44 } 45 46 // TODO: convert remaining direct users to iterators, and make the container private. 47 skia_private::STArray<1, sk_sp<SkSVGNode>, true> fChildren; 48 49 private: 50 using INHERITED = SkSVGTransformableNode; 51 }; 52 53 #endif // SkSVGContainer_DEFINED 54