blob: 38a17d86338efa6197a64f3d86cac0cf05216533 [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,
fmalitabffc2562016-08-03 10:21:11 -070022 kRect,
fmalita58649cc2016-07-29 08:52:03 -070023 kSvg
fmalita6ceef3d2016-07-26 18:46:34 -070024};
25
26class SkSVGNode : public SkRefCnt {
27public:
28 virtual ~SkSVGNode();
29
30 SkSVGTag tag() const { return fTag; }
31
32 virtual void appendChild(sk_sp<SkSVGNode>) = 0;
33
fmalita397a5172016-08-08 11:38:55 -070034 void render(const SkSVGRenderContext&) const;
fmalita6ceef3d2016-07-26 18:46:34 -070035
36 void setAttribute(SkSVGAttribute, const SkSVGValue&);
37
38protected:
39 SkSVGNode(SkSVGTag);
40
fmalita397a5172016-08-08 11:38:55 -070041 // Called before onRender(), to apply local attributes to the context. Unlike onRender(),
42 // onPrepareToRender() bubbles up the inheritance chain: overriders should always call
43 // INHERITED::onPrepareToRender(), unless they intend to short-circuit rendering
44 // (return false).
45 // Implementations are expected to return true if rendering is to continue, or false if
46 // the node/subtree rendering is disabled.
47 virtual bool onPrepareToRender(SkSVGRenderContext*) const;
48
49 virtual void onRender(const SkSVGRenderContext&) const = 0;
fmalita6ceef3d2016-07-26 18:46:34 -070050
51 virtual void onSetAttribute(SkSVGAttribute, const SkSVGValue&);
52
fmalita6ceef3d2016-07-26 18:46:34 -070053private:
54 SkSVGTag fTag;
55
56 // FIXME: this should be sparse
57 SkSVGPresentationAttributes fPresentationAttributes;
58
59 typedef SkRefCnt INHERITED;
60};
61
62#endif // SkSVGNode_DEFINED