OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SkViewInflate.h" | 8 #include "SkViewInflate.h" |
9 #include "SkView.h" | 9 #include "SkView.h" |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 19 matching lines...) Expand all Loading... |
30 if (view) | 30 if (view) |
31 { | 31 { |
32 this->rInflate(dom, child, view); | 32 this->rInflate(dom, child, view); |
33 parent->attachChildToFront(view)->unref(); | 33 parent->attachChildToFront(view)->unref(); |
34 } | 34 } |
35 else | 35 else |
36 { | 36 { |
37 const char* name = dom.getName(child); | 37 const char* name = dom.getName(child); |
38 const char* target; | 38 const char* target; |
39 | 39 |
40 if (!strcmp(name, "listenTo") && (target = dom.findAttr(child, "targ
et")) != NULL) | 40 if (!strcmp(name, "listenTo") && (target = dom.findAttr(child, "targ
et")) != nullptr) |
41 this->addIDStr(&fListenTo, parent, target); | 41 this->addIDStr(&fListenTo, parent, target); |
42 | 42 |
43 if (!strcmp(name, "broadcastTo") && (target = dom.findAttr(child, "t
arget")) != NULL) | 43 if (!strcmp(name, "broadcastTo") && (target = dom.findAttr(child, "t
arget")) != nullptr) |
44 this->addIDStr(&fBroadcastTo, parent, target); | 44 this->addIDStr(&fBroadcastTo, parent, target); |
45 } | 45 } |
46 child = dom.getNextSibling(child); | 46 child = dom.getNextSibling(child); |
47 } | 47 } |
48 | 48 |
49 parent->setVisibleP(true); | 49 parent->setVisibleP(true); |
50 this->inflateView(parent, dom, node); | 50 this->inflateView(parent, dom, node); |
51 } | 51 } |
52 | 52 |
53 void SkViewInflate::inflateView(SkView* view, const SkDOM& dom, const SkDOM::Nod
e* node) | 53 void SkViewInflate::inflateView(SkView* view, const SkDOM& dom, const SkDOM::Nod
e* node) |
54 { | 54 { |
55 // called after all of view's children have been instantiated. | 55 // called after all of view's children have been instantiated. |
56 // this may be overridden by a subclass, to load in layout or other helpers | 56 // this may be overridden by a subclass, to load in layout or other helpers |
57 // they should call through to us (INHERITED) before or after their patch | 57 // they should call through to us (INHERITED) before or after their patch |
58 view->inflate(dom, node); | 58 view->inflate(dom, node); |
59 } | 59 } |
60 | 60 |
61 SkView* SkViewInflate::inflate(const SkDOM& dom, const SkDOM::Node* node, SkView
* root) | 61 SkView* SkViewInflate::inflate(const SkDOM& dom, const SkDOM::Node* node, SkView
* root) |
62 { | 62 { |
63 fIDs.reset(); | 63 fIDs.reset(); |
64 | 64 |
65 if (root == NULL) | 65 if (root == nullptr) |
66 { | 66 { |
67 root = this->createView(dom, node); | 67 root = this->createView(dom, node); |
68 if (root == NULL) | 68 if (root == nullptr) |
69 { | 69 { |
70 printf("createView returned NULL on <%s>\n", dom.getName(node)); | 70 printf("createView returned nullptr on <%s>\n", dom.getName(node)); |
71 return NULL; | 71 return nullptr; |
72 } | 72 } |
73 } | 73 } |
74 this->rInflate(dom, node, root); | 74 this->rInflate(dom, node, root); |
75 | 75 |
76 // resolve listeners and broadcasters | 76 // resolve listeners and broadcasters |
77 { | 77 { |
78 SkView* target; | 78 SkView* target; |
79 const IDStr* iter = fListenTo.begin(); | 79 const IDStr* iter = fListenTo.begin(); |
80 const IDStr* stop = fListenTo.end(); | 80 const IDStr* stop = fListenTo.end(); |
81 for (; iter < stop; iter++) | 81 for (; iter < stop; iter++) |
(...skipping 14 matching lines...) Expand all Loading... |
96 // now that the tree is built, give everyone a shot at the ID dict | 96 // now that the tree is built, give everyone a shot at the ID dict |
97 root->postInflate(fIDs); | 97 root->postInflate(fIDs); |
98 return root; | 98 return root; |
99 } | 99 } |
100 | 100 |
101 SkView* SkViewInflate::inflate(const char xml[], size_t len, SkView* root) | 101 SkView* SkViewInflate::inflate(const char xml[], size_t len, SkView* root) |
102 { | 102 { |
103 SkDOM dom; | 103 SkDOM dom; |
104 const SkDOM::Node* node = dom.build(xml, len); | 104 const SkDOM::Node* node = dom.build(xml, len); |
105 | 105 |
106 return node ? this->inflate(dom, node, root) : NULL; | 106 return node ? this->inflate(dom, node, root) : nullptr; |
107 } | 107 } |
108 | 108 |
109 SkView* SkViewInflate::findViewByID(const char id[]) const | 109 SkView* SkViewInflate::findViewByID(const char id[]) const |
110 { | 110 { |
111 SkASSERT(id); | 111 SkASSERT(id); |
112 SkView* view; | 112 SkView* view; |
113 return fIDs.find(id, &view) ? view : NULL; | 113 return fIDs.find(id, &view) ? view : nullptr; |
114 } | 114 } |
115 | 115 |
116 SkView* SkViewInflate::createView(const SkDOM& dom, const SkDOM::Node* node) | 116 SkView* SkViewInflate::createView(const SkDOM& dom, const SkDOM::Node* node) |
117 { | 117 { |
118 if (!strcmp(dom.getName(node), "view")) | 118 if (!strcmp(dom.getName(node), "view")) |
119 return new SkView; | 119 return new SkView; |
120 return NULL; | 120 return nullptr; |
121 } | 121 } |
122 | 122 |
123 void SkViewInflate::addIDStr(SkTDArray<IDStr>* list, SkView* view, const char* s
tr) | 123 void SkViewInflate::addIDStr(SkTDArray<IDStr>* list, SkView* view, const char* s
tr) |
124 { | 124 { |
125 size_t len = strlen(str) + 1; | 125 size_t len = strlen(str) + 1; |
126 IDStr* pair = list->append(); | 126 IDStr* pair = list->append(); |
127 pair->fView = view; | 127 pair->fView = view; |
128 pair->fStr = (char*)fStrings.alloc(len, SkChunkAlloc::kThrow_AllocFailType); | 128 pair->fStr = (char*)fStrings.alloc(len, SkChunkAlloc::kThrow_AllocFailType); |
129 memcpy(pair->fStr, str, len); | 129 memcpy(pair->fStr, str, len); |
130 } | 130 } |
131 | 131 |
132 #ifdef SK_DEBUG | 132 #ifdef SK_DEBUG |
133 void SkViewInflate::dump() const | 133 void SkViewInflate::dump() const |
134 { | 134 { |
135 const IDStr* iter = fListenTo.begin(); | 135 const IDStr* iter = fListenTo.begin(); |
136 const IDStr* stop = fListenTo.end(); | 136 const IDStr* stop = fListenTo.end(); |
137 for (; iter < stop; iter++) | 137 for (; iter < stop; iter++) |
138 SkDebugf("inflate: listenTo(\"%s\")\n", iter->fStr); | 138 SkDebugf("inflate: listenTo(\"%s\")\n", iter->fStr); |
139 | 139 |
140 iter = fBroadcastTo.begin(); | 140 iter = fBroadcastTo.begin(); |
141 stop = fBroadcastTo.end(); | 141 stop = fBroadcastTo.end(); |
142 for (; iter < stop; iter++) | 142 for (; iter < stop; iter++) |
143 SkDebugf("inflate: broadcastFrom(\"%s\")\n", iter->fStr); | 143 SkDebugf("inflate: broadcastFrom(\"%s\")\n", iter->fStr); |
144 } | 144 } |
145 #endif | 145 #endif |
OLD | NEW |