SkDOMListSource(const SkDOM& dom, const SkDOM::Node* node) : fDirTail(">") { const SkDOM::Node* child = dom.getFirstChild(node, "item"); int count = 0; while (child) { count += 1; child = dom.getNextSibling(child, "item"); } fCount = count; fList = NULL; if (count) { ItemRec* rec = fList = new ItemRec[count]; child = dom.getFirstChild(node, "item"); while (child) { rec->fLabel.set(dom.findAttr(child, "label")); rec->fTail.set(dom.findAttr(child, "tail")); rec->fAltTail.set(dom.findAttr(child, "alt-tail")); rec->fTarget.set(dom.findAttr(child, "target")); rec->fType = kUnknown_Type; int index = dom.findList(child, "type", "dir,toggle"); if (index >= 0) rec->fType = (Type)(index + 1); child = dom.getNextSibling(child, "item"); rec += 1; } } }
void SkViewInflate::rInflate(const SkDOM& dom, const SkDOM::Node* node, SkView* parent) { const char* str = dom.findAttr(node, "id"); if (str) fIDs.set(str, parent); const SkDOM::Node* child = dom.getFirstChild(node); while (child) { SkView* view = this->createView(dom, child); if (view) { this->rInflate(dom, child, view); parent->attachChildToFront(view)->unref(); } else { const char* name = dom.getName(child); const char* target; if (!strcmp(name, "listenTo") && (target = dom.findAttr(child, "target")) != NULL) this->addIDStr(&fListenTo, parent, target); if (!strcmp(name, "broadcastTo") && (target = dom.findAttr(child, "target")) != NULL) this->addIDStr(&fBroadcastTo, parent, target); } child = dom.getNextSibling(child); } parent->setVisibleP(true); this->inflateView(parent, dom, node); }
static void write_dom(const SkDOM& dom, const SkDOM::Node* node, SkXMLWriter* w, bool skipRoot) { if (!skipRoot) { const char* elem = dom.getName(node); if (dom.getType(node) == SkDOM::kText_Type) { SkASSERT(dom.countChildren(node) == 0); w->addText(elem, strlen(elem)); return; } w->startElement(elem); SkDOM::AttrIter iter(dom, node); const char* name; const char* value; while ((name = iter.next(&value)) != nullptr) { w->addAttribute(name, value); } } node = dom.getFirstChild(node, nullptr); while (node) { write_dom(dom, node, w, false); node = dom.getNextSibling(node, nullptr); } if (!skipRoot) { w->endElement(); } }
SkXMLListSource::SkXMLListSource(const char doc[], size_t len) { fFieldCount = fRecordCount = 0; fFields = fRecords = NULL; SkDOM dom; const SkDOM::Node* node = dom.build(doc, len); SkASSERT(node); const SkDOM::Node* child; child = dom.getFirstChild(node, "fields"); if (child) { fFieldCount = dom.countChildren(child, "field"); fFields = new SkString[fFieldCount]; int n = 0; child = dom.getFirstChild(child, "field"); while (child) { fFields[n].set(dom.findAttr(child, "name")); child = dom.getNextSibling(child, "field"); n += 1; } SkASSERT(n == fFieldCount); } child = dom.getFirstChild(node, "records"); if (child) { fRecordCount = dom.countChildren(child, "record"); fRecords = new SkString[fRecordCount * fFieldCount]; int n = 0; child = dom.getFirstChild(child, "record"); while (child) { for (int i = 0; i < fFieldCount; i++) fRecords[n * fFieldCount + i].set(dom.findAttr(child, fFields[i].c_str())); child = dom.getNextSibling(child, "record"); n += 1; } SkASSERT(n == fRecordCount); } }
void SkListView::onInflate(const SkDOM& dom, const SkDOM::Node* node) { this->INHERITED::onInflate(dom, node); { bool hasScrollBar; if (dom.findBool(node, "scrollBar", &hasScrollBar)) this->setHasScrollBar(hasScrollBar); } const SkDOM::Node* child; if ((child = dom.getFirstChild(node, "bindings")) != NULL) { delete[] fBindings; fBindings = NULL; fBindingCount = 0; SkListSource* listSrc = SkListSource::Factory(dom.findAttr(child, "data-fields")); SkASSERT(listSrc); fSkinName.set(dom.findAttr(child, "skin-slots")); SkASSERT(fSkinName.size()); this->setListSource(listSrc)->unref(); int count = dom.countChildren(child, "bind"); if (count > 0) { fBindings = new BindingRec[count]; count = 0; // reuse this to count up to the number of valid bindings child = dom.getFirstChild(child, "bind"); SkASSERT(child); do { const char* fieldName = dom.findAttr(child, "field"); const char* slotName = dom.findAttr(child, "slot"); if (fieldName && slotName) { fBindings[count].fFieldIndex = listSrc->findFieldIndex(fieldName); if (fBindings[count].fFieldIndex >= 0) fBindings[count++].fSlotName.set(slotName); } } while ((child = dom.getNextSibling(child, "bind")) != NULL); fBindingCount = SkToU16(count); if (count == 0) { SkDEBUGF(("SkListView::onInflate: no valid <bind> elements in <listsource>\n")); delete[] fBindings; } } this->dirtyCache(kAnimCount_DirtyFlag); this->setSelection(0); } }
bool SkXMLParser::parse(const SkDOM& dom, const SkDOMNode* node) { const char* elemName = dom.getName(node); if (this->startElement(elemName)) return false; SkDOM::AttrIter iter(dom, node); const char* name, *value; while ((name = iter.next(&value)) != nullptr) if (this->addAttribute(name, value)) return false; if ((node = dom.getFirstChild(node)) != nullptr) do { if (!this->parse(dom, node)) return false; } while ((node = dom.getNextSibling(node)) != nullptr); return !this->endElement(elemName); }
static void write_dom(const SkDOM& dom, const SkDOM::Node* node, SkXMLWriter* w, bool skipRoot) { if (!skipRoot) { w->startElement(dom.getName(node)); SkDOM::AttrIter iter(dom, node); const char* name; const char* value; while ((name = iter.next(&value)) != NULL) w->addAttribute(name, value); } node = dom.getFirstChild(node, NULL); while (node) { write_dom(dom, node, w, false); node = dom.getNextSibling(node, NULL); } if (!skipRoot) w->endElement(); }