public override DomElement CreateElement(string prefix, string localName) { //actual dom implementation *** HtmlElement htmlElement; switch (localName) { case "img": { htmlElement = new HtmlImageElement( this, AddStringIfNotExists(prefix), AddStringIfNotExists(localName)); } break; case "input": { //input type htmlElement = new HtmlInputElement( this, AddStringIfNotExists(prefix), AddStringIfNotExists(localName)); } break; case "textarea": { htmlElement = new HtmlTextAreaElement( this, AddStringIfNotExists(prefix), AddStringIfNotExists(localName)); } break; case "option": { htmlElement = new HtmlOptionElement( this, AddStringIfNotExists(prefix), AddStringIfNotExists(localName)); } break; default: { htmlElement = new HtmlElement(this, AddStringIfNotExists(prefix), AddStringIfNotExists(localName)); htmlElement.WellknownElementName = WellKnownDomNodeMap.EvaluateTagName(htmlElement.LocalName); } break; } return(htmlElement); }
public override DomElement CreateElement(string prefix, string localName) { //actual implementation var htmlElement = new HtmlElement(this, AddStringIfNotExists(prefix), AddStringIfNotExists(localName)); htmlElement.WellknownElementName = WellKnownDomNodeMap.EvaluateTagName(htmlElement.LocalName); return(htmlElement); }
public static HtmlElement CreateHtmlElement(this HtmlDocument doc, string prefix, string localName) { //wellknown name? HtmlElement htmlElement; switch (localName) { case "img": { htmlElement = new HtmlImageElement( doc, doc.AddStringIfNotExists(prefix), doc.AddStringIfNotExists(localName)); } break; case "input": { //input type htmlElement = new HtmlInputElement( doc, doc.AddStringIfNotExists(prefix), doc.AddStringIfNotExists(localName)); } break; case "option": { htmlElement = new HtmlOptionElement( doc, doc.AddStringIfNotExists(prefix), doc.AddStringIfNotExists(localName)); } break; default: { htmlElement = new HtmlElement(doc, doc.AddStringIfNotExists(prefix), doc.AddStringIfNotExists(localName)); htmlElement.WellknownElementName = WellKnownDomNodeMap.EvaluateTagName(htmlElement.LocalName); } break; } return(htmlElement); }
void PrepareStylesAndContentOfChildNodes( HtmlElement parentElement, TopDownActiveCssTemplate activeCssTemplate) { //recursive CssBox principalCssBox = parentElement.CurrentPrincipalBox; bool isblockContext = true;//default if (principalCssBox != null) { isblockContext = principalCssBox.IsBlock; } foreach (WebDom.DomNode node in parentElement.GetChildNodeIterForward()) { activeCssTemplate.EnterLevel(); switch (node.NodeKind) { case WebDom.HtmlNodeKind.OpenElement: case WebDom.HtmlNodeKind.ShortElement: { HtmlElement htmlElement = (HtmlElement)node; htmlElement.WellknownElementName = WellKnownDomNodeMap.EvaluateTagName(htmlElement.LocalName); switch (htmlElement.WellknownElementName) { case WellKnownDomNodeName.style: { //style element should have textnode child int j = htmlElement.ChildrenCount; for (int i = 0; i < j; ++i) { var ch = htmlElement.GetChildNode(i); switch (ch.NodeKind) { case HtmlNodeKind.TextNode: { HtmlTextNode textNode = (HtmlTextNode)htmlElement.GetChildNode(0); activeCssTemplate.LoadRawStyleElementContent(new string(textNode.GetOriginalBuffer())); //break i = j; } break; } } activeCssTemplate.ExitLevel(); continue; } case WellKnownDomNodeName.link: { //<link rel="stylesheet" DomAttribute relAttr; if (htmlElement.TryGetAttribute(WellknownName.Rel, out relAttr)) { //switch link type switch (relAttr.Value.ToLower()) { case "stylesheet": { //if found DomAttribute hrefAttr; if (htmlElement.TryGetAttribute(WellknownName.Href, out hrefAttr)) { string stylesheet = RaiseRequestStyleSheet(hrefAttr.Value); if (stylesheet != null) { activeCssTemplate.LoadRawStyleElementContent(stylesheet); } } } break; case "import": { //load data canbe sync or async DomAttribute hrefAttr; if (htmlElement.TryGetAttribute(WellknownName.Href, out hrefAttr)) { //import other html, reuseable html component //TODO: implement import request algo here } } break; } } activeCssTemplate.ExitLevel(); continue; } } //----------------------------- //apply style for this node ApplyStyleSheetForSingleHtmlElement(htmlElement, parentElement.Spec, activeCssTemplate); //----------------------------- //recursive PrepareStylesAndContentOfChildNodes(htmlElement, activeCssTemplate); //----------------------------- } break; case WebDom.HtmlNodeKind.TextNode: { UpdateTextNode(parentElement, (HtmlTextNode)node, isblockContext); } break; } activeCssTemplate.ExitLevel(); } }