epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 10 | #ifndef SkViewInflate_DEFINED |
| 11 | #define SkViewInflate_DEFINED |
| 12 | |
| 13 | #include "SkDOM.h" |
reed | 76a834a | 2016-01-03 18:36:05 -0800 | [diff] [blame] | 14 | #include "../private/SkTDict.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 15 | #include "SkEvent.h" |
| 16 | |
| 17 | class SkView; |
| 18 | |
| 19 | class SkViewInflate { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 20 | public: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 21 | 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.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 36 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 37 | SkDEBUGCODE(void dump() const;) |
| 38 | |
| 39 | protected: |
| 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 | |
| 53 | private: |
| 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 |