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 SkStaticTextView::onInflate(const SkDOM& dom, const SkDOM::Node* node) { #if 0 this->INHERITED::onInflate(dom, node); int index; if ((index = dom.findList(node, "mode", "fixed,auto-width,auto-height")) >= 0) this->setMode((Mode)index); else assert_no_attr(dom, node, "mode"); if ((index = dom.findList(node, "spacing-align", "start,center,end")) >= 0) this->setSpacingAlign((SkTextBox::SpacingAlign)index); else assert_no_attr(dom, node, "spacing-align"); SkScalar s[2]; if (dom.findScalars(node, "margin", s, 2)) this->setMargin(s[0], s[1]); else assert_no_attr(dom, node, "margin"); const char* text = dom.findAttr(node, "text"); if (text) this->setText(text); if ((node = dom.getFirstChild(node, "paint")) != NULL && (node = dom.getFirstChild(node, "screenplay")) != NULL) { inflate_paint(dom, node, &fPaint); } #endif }
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); } }
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); }
DEF_TEST(SVGDevice_image_shader_tileboth, reporter) { SkDOM dom; SkPaint paint; int imageWidth = 3, imageHeight = 3; int rectWidth = 10, rectHeight = 10; ImageShaderTestSetup(&dom, &paint, imageWidth, imageHeight, rectWidth, rectHeight, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode); const SkDOM::Node* root = dom.finishParsing(); const SkDOM::Node *patternNode, *imageNode, *rectNode; const SkDOM::Node* innerSvg = dom.getFirstChild(root, "svg"); if (innerSvg == nullptr) { ERRORF(reporter, "inner svg element not found"); return; } bool structureAppropriate = FindImageShaderNodes(reporter, &dom, innerSvg, &patternNode, &imageNode, &rectNode); REPORTER_ASSERT(reporter, structureAppropriate); // the imageNode should always maintain its size. REPORTER_ASSERT(reporter, atoi(dom.findAttr(imageNode, "width")) == imageWidth); REPORTER_ASSERT(reporter, atoi(dom.findAttr(imageNode, "height")) == imageHeight); REPORTER_ASSERT(reporter, atoi(dom.findAttr(patternNode, "width")) == imageWidth); REPORTER_ASSERT(reporter, atoi(dom.findAttr(patternNode, "height")) == imageHeight); }
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 SkGridView::onInflate(const SkDOM& dom, const SkDOM::Node* node) { this->INHERITED::onInflate(dom, node); SkScalar x[2]; const SkDOM::Node* child; if (dom.findScalars(node, "cell-size", x, 2)) this->setCellSize(x[0], x[1]); if ((child = dom.getFirstChild(node, "hilite-paint")) != NULL) SkPaint_Inflate(&this->paint(kHiliteCell_Attr), dom, child); // look for a listsource { SkListSource* src = NULL; if ((child = dom.getFirstChild(node, "file-listsource")) != NULL) { const char* path = dom.findAttr(child, "path"); if (path) src = SkListSource::CreateFromDir( path, dom.findAttr(child, "filter"), dom.findAttr(child, "target")); } else if ((child = dom.getFirstChild(node, "xml-listsource")) != NULL) { src = SkListSource::CreateFromDOM(dom, child); } if (src) { this->setListSource(src)->unref(); this->setSelection(0); } } this->onSizeChange(); }
void SkListView::onInflate(const SkDOM& dom, const SkDOM::Node* node) { this->INHERITED::onInflate(dom, node); SkScalar x; const SkDOM::Node* child; if (dom.findScalar(node, "row-height", &x)) this->setRowHeight(x); if ((child = dom.getFirstChild(node, "hilite-paint")) != NULL) SkPaint_Inflate(&this->paint(kHiliteCell_Attr), dom, child); // look for a listsource { SkListSource* src = NULL; if ((child = dom.getFirstChild(node, "file-listsource")) != NULL) { const char* path = dom.findAttr(child, "path"); if (path) src = SkListSource::CreateFromDir( path, dom.findAttr(child, "filter"), dom.findAttr(child, "target")); } else if ((child = dom.getFirstChild(node, "xml-listsource")) != NULL) { src = SkListSource::CreateFromDOM(dom, child); } if (src) { this->setListSource(src)->unref(); 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(); }