blob: 4ec36a67dff3e7555fdf9917ee578ac1b8d730a2 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.com8a1c16f2008-12-17 15:59:43 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#ifndef SkViewInflate_DEFINED
11#define SkViewInflate_DEFINED
12
13#include "SkDOM.h"
reed76a834a2016-01-03 18:36:05 -080014#include "../private/SkTDict.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000015#include "SkEvent.h"
16
17class SkView;
18
19class SkViewInflate {
rmistry@google.comfbfcd562012-08-23 18:09:54 +000020public:
reed@android.com8a1c16f2008-12-17 15:59:43 +000021 SkViewInflate();
22 virtual ~SkViewInflate();
23
24 /** Return the tree of inflated views. If root is null, create the root element
25 as a view, otherwise assume root is that view, and just "inflate" it.
26
27 Returns null if the tree cannot be built.
28 */
29 SkView* inflate(const SkDOM& dom, const SkDOM::Node* node, SkView* root = NULL);
30 SkView* inflate(const char xml[], size_t len, SkView* root = NULL);
31
32 /** Given an id attribute value, return the corresponding view, or null
33 if no match is found.
34 */
35 SkView* findViewByID(const char id[]) const;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000036
reed@android.com8a1c16f2008-12-17 15:59:43 +000037 SkDEBUGCODE(void dump() const;)
38
39protected:
40 /* Override this in your subclass to handle instantiating views
41 Call the inherited version for nodes you don't recognize.
42
43 Do not call "inflate" on the view, just return it. This will
44 get called automatically after createView returns.
45 */
46 virtual SkView* createView(const SkDOM& dom, const SkDOM::Node* node);
47 /** Base implementation calls view->inflate(dom, node). Subclasses may override this
48 to perform additional initializations to view, either before or after calling
49 the inherited version.
50 */
51 virtual void inflateView(SkView* view, const SkDOM& dom, const SkDOM::Node* node);
52
53private:
54 enum {
55 kMinIDStrAlloc = 64
56 };
57 SkTDict<SkView*> fIDs;
58
59 struct IDStr {
60 SkView* fView;
61 char* fStr;
62 };
63 SkTDArray<IDStr> fListenTo, fBroadcastTo;
64 SkChunkAlloc fStrings;
65
66 void addIDStr(SkTDArray<IDStr>* list, SkView*, const char* str);
67
68 void rInflate(const SkDOM& dom, const SkDOM::Node* node, SkView* parent);
69};
70
71#endif