blob: 1e5c3be50f50a9973bc3e12960053364fe05cc18 [file] [log] [blame]
fmalita6ceef3d2016-07-26 18:46:34 -07001/*
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 SkSVGNode_DEFINED
9#define SkSVGNode_DEFINED
10
11#include "SkRefCnt.h"
12#include "SkSVGAttribute.h"
13
14class SkCanvas;
15class SkMatrix;
16class SkSVGRenderContext;
17class SkSVGValue;
18
19enum class SkSVGTag {
fmalita58649cc2016-07-29 08:52:03 -070020 kG,
21 kPath,
fmalita5b31f322016-08-12 12:15:33 -070022 kPolygon,
23 kPolyline,
fmalitabffc2562016-08-03 10:21:11 -070024 kRect,
fmalita58649cc2016-07-29 08:52:03 -070025 kSvg
fmalita6ceef3d2016-07-26 18:46:34 -070026};
27
28class SkSVGNode : public SkRefCnt {
29public:
30 virtual ~SkSVGNode();
31
32 SkSVGTag tag() const { return fTag; }
33
34 virtual void appendChild(sk_sp<SkSVGNode>) = 0;
35
fmalita397a5172016-08-08 11:38:55 -070036 void render(const SkSVGRenderContext&) const;
fmalita6ceef3d2016-07-26 18:46:34 -070037
38 void setAttribute(SkSVGAttribute, const SkSVGValue&);
39
40protected:
41 SkSVGNode(SkSVGTag);
42
fmalita397a5172016-08-08 11:38:55 -070043 // Called before onRender(), to apply local attributes to the context. Unlike onRender(),
44 // onPrepareToRender() bubbles up the inheritance chain: overriders should always call
45 // INHERITED::onPrepareToRender(), unless they intend to short-circuit rendering
46 // (return false).
47 // Implementations are expected to return true if rendering is to continue, or false if
48 // the node/subtree rendering is disabled.
49 virtual bool onPrepareToRender(SkSVGRenderContext*) const;
50
51 virtual void onRender(const SkSVGRenderContext&) const = 0;
fmalita6ceef3d2016-07-26 18:46:34 -070052
53 virtual void onSetAttribute(SkSVGAttribute, const SkSVGValue&);
54
fmalita6ceef3d2016-07-26 18:46:34 -070055private:
56 SkSVGTag fTag;
57
58 // FIXME: this should be sparse
59 SkSVGPresentationAttributes fPresentationAttributes;
60
61 typedef SkRefCnt INHERITED;
62};
63
64#endif // SkSVGNode_DEFINED