• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SkViewInflate_DEFINED
18 #define SkViewInflate_DEFINED
19 
20 #include "SkDOM.h"
21 #include "SkTDict.h"
22 #include "SkEvent.h"
23 
24 class SkView;
25 
26 class SkViewInflate {
27 public:
28             SkViewInflate();
29     virtual ~SkViewInflate();
30 
31     /** Return the tree of inflated views. If root is null, create the root element
32         as a view, otherwise assume root is that view, and just "inflate" it.
33 
34         Returns null if the tree cannot be built.
35     */
36     SkView* inflate(const SkDOM& dom, const SkDOM::Node* node, SkView* root = NULL);
37     SkView* inflate(const char xml[], size_t len, SkView* root = NULL);
38 
39     /** Given an id attribute value, return the corresponding view, or null
40         if no match is found.
41     */
42     SkView* findViewByID(const char id[]) const;
43 
44     SkDEBUGCODE(void dump() const;)
45 
46 protected:
47     /*  Override this in your subclass to handle instantiating views
48         Call the inherited version for nodes you don't recognize.
49 
50         Do not call "inflate" on the view, just return it. This will
51         get called automatically after createView returns.
52     */
53     virtual SkView* createView(const SkDOM& dom, const SkDOM::Node* node);
54     /** Base implementation calls view->inflate(dom, node). Subclasses may override this
55         to perform additional initializations to view, either before or after calling
56         the inherited version.
57     */
58     virtual void inflateView(SkView* view, const SkDOM& dom, const SkDOM::Node* node);
59 
60 private:
61     enum {
62         kMinIDStrAlloc = 64
63     };
64     SkTDict<SkView*> fIDs;
65 
66     struct IDStr {
67         SkView* fView;
68         char*   fStr;
69     };
70     SkTDArray<IDStr>    fListenTo, fBroadcastTo;
71     SkChunkAlloc        fStrings;
72 
73     void addIDStr(SkTDArray<IDStr>* list, SkView*, const char* str);
74 
75     void    rInflate(const SkDOM& dom, const SkDOM::Node* node, SkView* parent);
76 };
77 
78 #endif
79 
80