Esempio n. 1
0
        public override DomElement GetPresentationDomNode(WebDom.Impl.HtmlDocument htmldoc)
        {
            //TODO: use template engine,
            //ideas:  AngularJS style ?

            //1. create body node
            // and content
            //style 2, lambda and adhoc attach event
            if (pnode != null)
            {
                return(pnode);
            }
            //---------------------------------------------------
            pnode = htmldoc.CreateElement("div");

            pnode.AddChild("img", img =>
            {
                //init
                bool is_close = true;
                img.SetAttribute("src", "../../Demo/arrow_close.png");
                img.AttachMouseDownEvent(e =>
                {
                    img.SetAttribute("src", is_close ?
                                     "../../Demo/arrow_open.png" :
                                     "../../Demo/arrow_close.png");
                    is_close = !is_close;
                    e.StopPropagation();
                });
            });

            //pnode.AddChild("img", img =>
            //{

            //    //change style
            //    bool is_close = true;
            //    img.SetAttribute("src", "../../Demo/arrow_close.png");
            //    //3. attach event to specific span
            //    img.AttachMouseDownEvent(e =>
            //    {
            //        img.SetAttribute("src", is_close ?
            //            "../../Demo/arrow_open.png" :
            //            "../../Demo/arrow_close.png");

            //        is_close = !is_close;
            //        e.StopPropagation();

            //        this.InvalidateGraphics();
            //    });

            //});
            pnode.AddChild("span", span =>
            {
                span.AddTextContent(this.checkBoxText);
            });

            return(pnode);
        }
Esempio n. 2
0
        public DomElement GetPrimaryPresentationNode(DomElement hostNode)
        {
            if (this.pnode != null)
            {
                return(pnode);
            }
            //---------------------------------
            var ownerdoc = hostNode.OwnerDocument;

            pnode = ownerdoc.CreateElement("div");
            //---------------------------------
            //bar part
            pnode.AddChild("div", node_bar =>
            {
                this.nodeBar = node_bar;
                node_bar.AddChild("img", node_icon =>
                {
                    this.nodeIcon = node_icon;
                    SetupNodeIconBehaviour(node_icon);
                });
                node_bar.AddChild("span", node_span =>
                {
                    this.nodeSpan = node_span;
                    if (this.nodeString != null)
                    {
                        node_span.AddTextContent(this.nodeString);
                    }
                });
            });
            //---------------------------------
            //content part
            //indent
            pnode.AddChild("div", node_body =>
            {
                this.nodeBody = node_body;
                node_body.SetAttribute("style", "padding-left:17px");
                node_body.AddChild("div", node_content =>
                {
                    this.nodeContent = node_content;
                    if (childNodes != null)
                    {
                        nodeContent.SetAttribute("style", "padding-left:0px");
                        int j = childNodes.Count;
                        for (int i = 0; i < j; ++i)
                        {
                            var childnode = childNodes[i].GetPrimaryPresentationNode(nodeContent);
                            node_content.AddChild(childnode);
                        }
                    }
                });
            });
            return(pnode);
        }
Esempio n. 3
0
        public override DomElement GetPresentationDomNode(WebDom.Impl.HtmlDocument htmldoc)
        {
            if (_presentationNode != null)
            {
                return(_presentationNode);
            }
            //-------------------
            _presentationNode = htmldoc.CreateElement("div");
            _presentationNode.AddChild("div", div =>
            {
                div.SetAttribute("style", "font:10pt tahoma;");
                div.AddChild("span", span1 =>
                {
                    _span_textLabel = span1;
                    span1.SetAttribute("style", "background-color:white;width:50px;height:20px;");
                    span1.AddTextContent("");
                });
                div.AddChild("img", img =>
                {
                    //init
                    img.SetAttribute("src", "arrow_close.png");
                    img.AttachMouseDownEvent(e =>
                    {
                        if (this.IsOpen)
                        {
                            img.SetAttribute("src", "arrow_close.png");
                            this.CloseHinge();
                        }
                        else
                        {
                            img.SetAttribute("src", "arrow_open.png");
                            this.OpenHinge();
                        }

                        //-----------------------------
                        e.StopPropagation();
                    });
                });
            });

            _div_landingPoint = _presentationNode.AddChild("div", div =>
            {
                div.SetAttribute("style", "display:block");
            });
            //-------------------

            _floatPartDomElement = this.CreateFloatPartDom(htmldoc);
            return(_presentationNode);
        }
Esempio n. 4
0
        public DomElement GetPageBody(DomElement hostNode)
        {
            if (_contentNode != null)
            {
                return(_contentNode);
            }
            WebDocument ownerdoc = hostNode.OwnerDocument;

            _contentNode = ownerdoc.CreateElement("div");
            if (_contentUI != null)
            {
                //add content ui to the body of page
                //creat html wrapper for this ...

                //  throw new NotImplementedException();
                //reimpl here again
                LayoutFarm.Composers.HtmlDocument htmldoc = (LayoutFarm.Composers.HtmlDocument)ownerdoc;
                var wrapperElement = htmldoc.CreateWrapperElement("x",
                                                                  (RootGraphic rootgfx, out RenderElement renderE, out object controller) =>
                {
                    renderE    = _contentUI.GetPrimaryRenderElement(rootgfx);
                    controller = _contentUI;
                });
                _contentNode.AddChild(wrapperElement);
            }
            return(_contentNode);
        }
Esempio n. 5
0
        public override DomElement GetPresentationDomNode(WebDom.Impl.HtmlDocument htmldoc)
        {
            if (pnode != null)
            {
                return(pnode);
            }
            this.htmldoc = htmldoc;

            pnode = htmldoc.CreateElement("div");
            //TODO: review IsLandPart again, this is temp fixed
            if (!this.IsLandPart)
            {
                pnode.SetAttribute("style", "position:absolute;width:100px;height:200px");
            }

            if (menuItems != null)
            {
                int j = menuItems.Count;
                for (int i = 0; i < j; ++i)
                {
                    pnode.AddChild(menuItems[i].GetPresentationDomNode(pnode));
                }
            }
            return(pnode);
        }
Esempio n. 6
0
        //level 1
        public static DomElement AddChild(this DomElement elem, string elementName)
        {
            var newchild = elem.OwnerDocument.CreateElement(elementName);

            elem.AddChild(newchild);
            return(newchild);
        }
Esempio n. 7
0
        public static DomElement AddChild(this DomElement elem, string elementName, Decorate d)
        {
            DomElement newchild = elem.OwnerDocument.CreateElement(elementName);

            elem.AddChild(newchild);
            d?.Invoke(newchild);
            return(newchild);
        }
        public static DomElement AddChild(this DomElement elem, string elementName, out DomElement elemExit)
        {
            DomElement newchild = elem.OwnerDocument.CreateElement(elementName);

            elem.AddChild(newchild);
            elemExit = newchild;
            return(newchild);
        }
Esempio n. 9
0
        public static DomElement AddChild(this DomElement elem, string elementName, Decorate d)
        {
            var newchild = elem.OwnerDocument.CreateElement(elementName);

            elem.AddChild(newchild);
            if (d != null)
            {
                d(newchild);
            }

            return(newchild);
        }
Esempio n. 10
0
 public void AddChildBox(MenuItem mnuItem)
 {
     if (menuItems == null)
     {
         menuItems = new List <MenuItem>();
     }
     this.menuItems.Add(mnuItem);
     if (pnode != null)
     {
         pnode.AddChild(mnuItem.GetPresentationDomNode(pnode));
     }
     mnuItem.OwnerMenuBox = this;
 }
Esempio n. 11
0
        public override WebDom.DomElement GetPresentationDomNode(WebDom.Impl.HtmlDocument htmldoc)
        {
            if (pnode != null)
            {
                return(pnode);
            }
            //------------------------------

            pnode = htmldoc.CreateElement("div");
            pnode.SetAttribute("style", "font:10pt tahoma");
            //------------------------------
            titleBar = htmldoc.CreateElement("div");
            titleBar.AddTextContent("hello tabPage");
            pnode.AddChild(titleBar);
            //------------------------------
            tabTitleList = htmldoc.CreateElement("div");
            pnode.AddChild(tabTitleList);
            //------------------------------
            contentNode = htmldoc.CreateElement("div");
            pnode.AddChild(contentNode);
            //------------------------------
            return(pnode);
        }
Esempio n. 12
0
        public void AddItem(TabPage tabPage)
        {
            //1. store in collection

            tabPageCollection.Add(tabPage);
            tabPage.OwnerContainer = this;
            if (pnode != null)
            {
                if (currentPage == null)
                {
                    currentPage = tabPage;
                    //add tab button into list
                    this.tabTitleList.AddChild(tabPage.GetTitleNode(pnode));
                    //add page body
                    contentNode.AddChild(tabPage.GetPageBody(pnode));
                }
                else
                {
                    //add tab button into list
                    this.tabTitleList.AddChild(tabPage.GetTitleNode(pnode));
                }
            }
        }
Esempio n. 13
0
        public void AddItem(DomElement item)
        {
            if (_items == null)
            {
                _items = new List <DomElement>();
            }
            item.AttachMouseDownEvent(ItemSelected);

            _items.Add(item);
            //
            //
            if (_div_floatingPart != null)
            {
                _div_floatingPart.AddChild(item);
            }
        }
Esempio n. 14
0
        public void Expand()
        {
            if (this.isOpen)
            {
                return;
            }
            this.isOpen = true;
            if (this.nodeBody != null)
            {
                if (nodeBody.ParentNode == null)
                {
                    pnode.AddChild(nodeBody);
                }
            }

            //this.TreeView.PerformContentLayout();
        }
Esempio n. 15
0
        public override DomElement GetPresentationDomNode(WebDom.Impl.HtmlDocument htmldoc)
        {
            if (pnode != null)
            {
                return(pnode);
            }
            //----------------------------------
            pnode = htmldoc.CreateElement("div");
            pnode.SetAttribute("style", "display:inline-block;width:" + Width + "px;height:" + this.Height + "px;");

            pnode.AddChild("div", div2 =>
            {
                //init
                div2.SetAttribute("style", "padding:5px;background-color:#dddddd;");
                div2.AddChild("span", span =>
                {
                    span.AddTextContent(this.buttonText);
                });
                //------------------------------

                div2.AttachMouseDownEvent(e =>
                {
#if DEBUG
                    div2.dbugMark = 1;
#endif
                    // div2.SetAttribute("style", "padding:5px;background-color:#aaaaaa;");
                    EaseScriptElement ee = new EaseScriptElement(div2);
                    ee.ChangeBackgroundColor(Color.FromArgb(0xaa, 0xaa, 0xaa));
                    //div2.SetAttribute("style", "padding:5px;background-color:#aaaaaa;");
                    e.StopPropagation();
                });
                div2.AttachMouseUpEvent(e =>
                {
#if DEBUG
                    div2.dbugMark = 2;
#endif
                    //div2.SetAttribute("style", "padding:5px;background-color:#dddddd;");

                    EaseScriptElement ee = new EaseScriptElement(div2);
                    ee.ChangeBackgroundColor(Color.FromArgb(0xdd, 0xdd, 0xdd));
                    e.StopPropagation();
                });
            });

            return(pnode);
        }
Esempio n. 16
0
        public override DomElement GetPresentationDomNode(WebDom.Impl.HtmlDocument htmldoc)
        {
            if (pnode != null)
            {
                return(pnode);
            }
            //create primary presentation node

            pnode = htmldoc.CreateElement("div");
            pnode.SetAttribute("style", "font:10pt tahoma");
            int j = treeNodes.Count;

            for (int i = 0; i < j; ++i)
            {
                pnode.AddChild(treeNodes[i].GetPrimaryPresentationNode(pnode));
            }
            return(pnode);
        }
Esempio n. 17
0
        public override DomElement GetPresentationDomNode(WebDom.Impl.HtmlDocument htmldoc)
        {
            if (presentationNode != null)
            {
                return(presentationNode);
            }
            //-------------------
            presentationNode = htmldoc.CreateElement("div");
            presentationNode.AddChild("div", div =>
            {
                div.SetAttribute("style", "font:10pt tahoma;");
                div.AddChild("img", img =>
                {
                    //init
                    img.SetAttribute("src", "../../Demo/arrow_close.png");
                    img.AttachMouseDownEvent(e =>
                    {
                        //img.SetAttribute("src", this.IsOpen ?
                        //    "../../Demo/arrow_open.png" :
                        //    "../../Demo/arrow_close.png");
                        ////------------------------------

                        if (this.IsOpen)
                        {
                            img.SetAttribute("src", "../../Demo/arrow_close.png");
                            this.CloseHinge();
                        }
                        else
                        {
                            img.SetAttribute("src", "../../Demo/arrow_open.png");
                            this.OpenHinge();
                        }

                        //-----------------------------
                        e.StopPropagation();
                    });
                });
            });
            //-------------------

            this.floatPartDomElement = this.CreateFloatPartDom(htmldoc);

            return(presentationNode);
        }
Esempio n. 18
0
 public void AddChildNode(TreeNode treeNode)
 {
     if (childNodes == null)
     {
         childNodes = new List <TreeNode>();
     }
     this.childNodes.Add(treeNode);
     treeNode.parentNode = this;
     //---------------------------
     //add treenode presentaion
     if (this.isOpen)
     {
         if (this.nodeContent != null)
         {
             //add child presentation
             nodeContent.AddChild(
                 treeNode.GetPrimaryPresentationNode(nodeContent));
         }
     }
     //---------------------------
 }
Esempio n. 19
0
        public DomElement GetTitleNode(DomElement hostNode)
        {
            //-------------------------------------
            if (_titleNode != null)
            {
                return(_titleNode);
            }
            //create dom node
            var ownerdoc = hostNode.OwnerDocument;

            _titleNode = ownerdoc.CreateElement("div");
            _titleNode.SetAttribute("style", "display:inline");
            _titleNode.AddChild("span", span =>
            {
                if (PageTitle == null)
                {
                    span.AddTextContent("");
                }
                else
                {
                    span.AddTextContent(this.PageTitle);
                }
                span.AttachMouseDownEvent(e =>
                {
                    if (this.OwnerContainer != null)
                    {
                        this.OwnerContainer.ChildNotifyTabMouseDown(this);
                    }
                });
            });
            ////mouse down on title
            //titleNode.AttachMouseDownEvent(e =>
            //{


            //});
            //-------------------------------------
            return(_titleNode);
        }
Esempio n. 20
0
 DomElement CreateFloatPartDom(WebDom.Impl.HtmlDocument htmldoc)
 {
     //create land part
     _div_floatingPart = htmldoc.CreateElement("div");
     _div_floatingPart.SetAttribute("style", "background-color:white;position:absolute;left:0px;top:0px;width:300px;height:500px;");
     if (_items != null)
     {
         int j = _items.Count;
         for (int i = 0; i < j; ++i)
         {
             _div_floatingPart.AddChild(_items[i]);
         }
     }
     //---------------------------------------
     _div_glassCover = htmldoc.CreateElement("div");
     _div_glassCover.SetAttribute("style", "position:absolute;width:100%;height:100%;");
     _div_glassCover.AddChild(_div_floatingPart);
     _div_glassCover.AttachMouseDownEvent(e =>
     {
         //when click on cover glass
         CloseHinge();
     });
     return(_div_floatingPart);
 }
Esempio n. 21
0
        public override void Parse(TextSource textSnapshot, WebDocument htmldoc, DomElement currentNode)
        {
            this._resultHtmlDoc = htmldoc;
            char[] copyBuffer = textSnapshot.ActualSnapshot.Copy(0, textSnapshot.ActualSnapshot.Length);
            using (var ms = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(copyBuffer)))
                using (var textReader = new System.IO.StreamReader(ms))
                {
                    var       tokenizer = new HtmlTokenizer(textReader);
                    HtmlToken token;
                    while (tokenizer.ReadNextToken(out token))
                    {
                        switch (token.Kind)
                        {
                        case HtmlTokenKind.Data:
                        {
                            var text = (HtmlDataToken)token;
                            currentNode.AddChild(_resultHtmlDoc.CreateTextNode(text.Data.ToCharArray()));
                        }
                        break;

                        case HtmlTokenKind.Tag:
                        {
                            var tag = (HtmlTagToken)token;
                            if (!tag.IsEndTag)
                            {
                                //open tag
                                DomElement elem = this._resultHtmlDoc.CreateElement(null, tag.Name);
                                currentNode.AddChild(elem);
                                foreach (var attribute in tag.Attributes)
                                {
                                    var attr = this._resultHtmlDoc.CreateAttribute(null, attribute.Name);
                                    if (attribute.Value != null)
                                    {
                                        attr.Value = attribute.Value;
                                    }
                                    elem.AddAttribute(attr);
                                }
                                if (!tag.IsEmptyElement)
                                {
                                    openEltStack.Push(currentNode);
                                    currentNode = elem;
                                }
                            }
                            else
                            {
                                //this is end tag
                                //check end tag match or not
                                int tagNameIndex = _resultHtmlDoc.AddStringIfNotExists(tag.Name);
                                if (currentNode.Name == tag.Name)
                                {
                                    currentNode = openEltStack.Pop();
                                }
                                else
                                {
                                    //if not equal then check if current node need close tag or not
                                    int  count = 3;   //?
                                    bool ok    = false;
                                    while (count > 0)
                                    {
                                        if (HtmlTagMatching.IsSingleTag(currentNode.LocalNameIndex))
                                        {
                                            if (openEltStack.Count > 0)
                                            {
                                                currentNode = openEltStack.Pop();
                                            }
                                            if (currentNode.LocalName == tag.Name)
                                            {
                                                if (openEltStack.Count > 0)
                                                {
                                                    currentNode = openEltStack.Pop();
                                                    ok          = true;
                                                    break;
                                                }
                                            }
                                        }
                                        else if (HtmlTagMatching.CanAutoClose(currentNode.LocalNameIndex))
                                        {
                                            if (openEltStack.Count > 0)
                                            {
                                                currentNode = openEltStack.Pop();
                                            }
                                            if (currentNode.LocalName == tag.Name)
                                            {
                                                if (openEltStack.Count > 0)
                                                {
                                                    currentNode = openEltStack.Pop();
                                                    ok          = true;
                                                    break;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            //implement err handling here!
                                            throw new NotSupportedException();
                                        }
                                        count--;
                                    }
                                    if (!ok)
                                    {
                                        throw new NotSupportedException();
                                    }
                                }
                            }
                        }
                        break;

                        case HtmlTokenKind.Comment:

                            break;

                        case HtmlTokenKind.DocType:

                            break;

                        default:
                        {
                        }
                        break;
                        }
                    }
                }
        }
Esempio n. 22
0
        DomElement GetPrimaryPresentationNode2(DomElement hostNode)
        {
            //implement wth table

            if (this.pnode != null)
            {
                return(pnode);
            }
            //---------------------------------
            var ownerdoc = hostNode.OwnerDocument;

            pnode = ownerdoc.CreateElement("div");
            //---------------------------------
            //bar part
            pnode.AddChild("div", node_bar =>
            {
                this.nodeBar = node_bar;
                node_bar.AddChild("img", node_icon =>
                {
                    this.nodeIcon = node_icon;
                    SetupNodeIconBehaviour(node_icon);
                });
                node_bar.AddChild("span", node_span =>
                {
                    this.nodeSpan = node_span;
                    if (this.nodeString != null)
                    {
                        node_span.AddTextContent(this.nodeString);
                    }
                });
            });
            //---------------------------------
            //content part
            //indent
            pnode.AddChild("div", node_body =>
            {
                this.nodeBody = node_body;
                //implement with table
                //plan: => implement with inline div***

                node_body.AddChild("table", table =>
                {
                    table.AddChild("tr", tr =>
                    {
                        tr.AddChild("td", td1 =>
                        {
                            //indent
                            td1.SetAttribute("style", "width:20px");
                        });
                        tr.AddChild("td", td1 =>
                        {
                            this.nodeContent = td1;
                            if (childNodes != null)
                            {
                                int j = childNodes.Count;
                                for (int i = 0; i < j; ++i)
                                {
                                    var childnode = childNodes[i].GetPrimaryPresentationNode(nodeContent);
                                    nodeContent.AddChild(childnode);
                                }
                            }
                        });
                    });
                });
                //node_body.SetAttribute("style", "background-color:yellow");
                //node_body.AddChild("div", node_indent =>
                //{
                //    node_indent.SetAttribute("style", "width:32px;display:inline");
                //    node_indent.AddChild("img", img2 => { });

                //});
                //node_body.AddChild("div", node_content =>
                //{
                //    node_content.SetAttribute("style", "display:inline");
                //    //start with blank content
                //    this.nodeContent = node_content;
                //    if (childNodes != null)
                //    {
                //        int j = childNodes.Count;
                //        for (int i = 0; i < j; ++i)
                //        {
                //            var childnode = childNodes[i].GetPrimaryPresentationNode(node_content);
                //            node_content.AddChild(childnode);
                //        }
                //    }

                //});
            });
            //---------------------
            return(pnode);
        }
Esempio n. 23
0
        public override void Parse(TextSource textSnapshot, WebDocument htmldoc, DomElement currentNode)
        {
            this._resultHtmlDoc = htmldoc;
            char[] copyBuffer = textSnapshot.ActualSnapshot.Copy(0, textSnapshot.ActualSnapshot.Length);
            using (var ms = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(copyBuffer)))
            using (var textReader = new System.IO.StreamReader(ms))
            {
                var tokenizer = new HtmlTokenizer(textReader);
                HtmlToken token;
                while (tokenizer.ReadNextToken(out token))
                {
                    switch (token.Kind)
                    {
                        case HtmlTokenKind.Data:
                            {
                                var text = (HtmlDataToken)token;
                                currentNode.AddChild(_resultHtmlDoc.CreateTextNode(text.Data.ToCharArray()));
                            }
                            break;
                        case HtmlTokenKind.Tag:
                            {
                                var tag = (HtmlTagToken)token;
                                if (!tag.IsEndTag)
                                {
                                    //open tag 
                                    DomElement elem = this._resultHtmlDoc.CreateElement(null, tag.Name);
                                    currentNode.AddChild(elem);
                                    foreach (var attribute in tag.Attributes)
                                    {
                                        var attr = this._resultHtmlDoc.CreateAttribute(null, attribute.Name);
                                        if (attribute.Value != null)
                                        {
                                            attr.Value = attribute.Value;
                                        }
                                        elem.AddAttribute(attr);
                                    }
                                    if (!tag.IsEmptyElement)
                                    {
                                        openEltStack.Push(currentNode);
                                        currentNode = elem;
                                    }
                                }
                                else
                                {
                                    //this is end tag
                                    //check end tag match or not
                                    int tagNameIndex = _resultHtmlDoc.AddStringIfNotExists(tag.Name);
                                    if (currentNode.Name == tag.Name)
                                    {
                                        currentNode = openEltStack.Pop();
                                    }
                                    else
                                    {
                                        //if not equal then check if current node need close tag or not
                                        int count = 3;//?
                                        bool ok = false;
                                        while (count > 0)
                                        {
                                            if (HtmlTagMatching.IsSingleTag(currentNode.LocalNameIndex))
                                            {
                                                if (openEltStack.Count > 0)
                                                {
                                                    currentNode = openEltStack.Pop();
                                                }
                                                if (currentNode.LocalName == tag.Name)
                                                {
                                                    if (openEltStack.Count > 0)
                                                    {
                                                        currentNode = openEltStack.Pop();
                                                        ok = true;
                                                        break;
                                                    }
                                                }
                                            }
                                            else if (HtmlTagMatching.CanAutoClose(currentNode.LocalNameIndex))
                                            {
                                                if (openEltStack.Count > 0)
                                                {
                                                    currentNode = openEltStack.Pop();
                                                }
                                                if (currentNode.LocalName == tag.Name)
                                                {
                                                    if (openEltStack.Count > 0)
                                                    {
                                                        currentNode = openEltStack.Pop();
                                                        ok = true;
                                                        break;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                //implement err handling here!
                                                throw new NotSupportedException();
                                            }
                                            count--;
                                        }
                                        if (!ok)
                                        {
                                            throw new NotSupportedException();
                                        }
                                    }
                                }
                            }
                            break;
                        case HtmlTokenKind.Comment:

                            break;
                        case HtmlTokenKind.DocType:

                            break;
                        default:
                            {
                            }
                            break;
                    }
                }
            }
        }
Esempio n. 24
0
        public static void AddTextContent(this DomElement elem, string text)
        {
            var newTextNode = elem.OwnerDocument.CreateTextNode(text.ToCharArray());

            elem.AddChild(newTextNode);
        }
Esempio n. 25
0
        void LexStateChanged(HtmlLexerEvent lexEvent, int startIndex, int len)
        {
            switch (lexEvent)
            {
            case HtmlLexerEvent.CommentContent:
            {
                //var commentContent = this.textSnapshot.Copy(startIndex, len);
            }
            break;

            case HtmlLexerEvent.FromContentPart:
            {
                if (curTextNode == null)
                {
                    curTextNode = _resultHtmlDoc.CreateTextNode(
                        HtmlDecodeHelper.DecodeHtml(this.textSnapshot, startIndex, len));
                    if (curHtmlNode != null)
                    {
                        curHtmlNode.AddChild(curTextNode);
                    }
                }
                else
                {
                    curTextNode.AppendTextContent(HtmlDecodeHelper.DecodeHtml(this.textSnapshot, startIndex, len));
                }
            }
            break;

            case HtmlLexerEvent.AttributeValueAsLiteralString:
            {
                //assign value and add to parent
                if (parseState == 11)
                {
                    //document node
                    //doc
                    domDocNode.AddParameter(textSnapshot.Substring(startIndex, len));
                }
                else
                {
                    curAttr.Value = textSnapshot.Substring(startIndex, len);
                    curHtmlNode.AddAttribute(curAttr);
                }
            }
            break;

            case HtmlLexerEvent.Attribute:
            {
                //create attribute node and wait for its value
                string nodename = textSnapshot.Substring(startIndex, len);
                curAttr = this._resultHtmlDoc.CreateAttribute(null, nodename);
            }
            break;

            case HtmlLexerEvent.NodeNameOrAttribute:
            {
                //the lexer dose not store state of element name or attribute name
                //so we use parseState to decide here


                string name = textSnapshot.Substring(startIndex, len);
                switch (parseState)
                {
                case 0:
                {
                    //create element
                    DomElement elem = this._resultHtmlDoc.CreateElement(null, name);
                    if (curHtmlNode != null)
                    {
                        curHtmlNode.AddChild(elem);
                        openEltStack.Push(curHtmlNode);
                    }
                    curHtmlNode     = elem;
                    parseState      = 1;           //attribute
                    curTextNode     = null;
                    curAttr         = null;
                    waitingAttrName = null;
                }
                break;

                case 1:
                {
                    //wait for attr value
                    if (waitingAttrName != null)
                    {
                        //push waiting attr
                        curAttr       = this._resultHtmlDoc.CreateAttribute(null, waitingAttrName);
                        curAttr.Value = "";
                        curHtmlNode.AddAttribute(curAttr);
                        curAttr = null;
                    }
                    waitingAttrName = name;
                }
                break;

                case 2:
                {
                    //****
                    //node name after open slash
                    //TODO: review here,avoid direct string comparison
                    if (curHtmlNode.LocalName == name)
                    {
                        if (openEltStack.Count > 0)
                        {
                            waitingAttrName = null;
                            curTextNode     = null;
                            curAttr         = null;
                            curHtmlNode     = openEltStack.Pop();
                        }
                        parseState = 3;
                    }
                    else
                    {
                        //if not equal then check if current node need close tag or not
                        if (HtmlTagMatching.IsSingleTag(curHtmlNode.LocalNameIndex))
                        {
                            if (openEltStack.Count > 0)
                            {
                                waitingAttrName = null;
                                curHtmlNode     = openEltStack.Pop();
                                curAttr         = null;
                                curTextNode     = null;
                            }
                            if (curHtmlNode.LocalName == name)
                            {
                                if (openEltStack.Count > 0)
                                {
                                    curTextNode     = null;
                                    curAttr         = null;
                                    curHtmlNode     = openEltStack.Pop();
                                    waitingAttrName = null;
                                }
                                parseState = 3;
                            }
                            else
                            {
                                //implement err handling here!
                                throw new NotSupportedException();
                            }
                        }
                        else
                        {
                            //implement err handling here!
                            throw new NotSupportedException();
                        }
                    }
                }
                break;

                case 4:
                {
                    //attribute value as id
                    if (curAttr != null)
                    {
                        curAttr.Value   = name;
                        curAttr         = null;
                        parseState      = 0;
                        waitingAttrName = null;
                    }
                    else
                    {
                    }
                }
                break;

                case 10:
                {
                    //document node

                    parseState = 11;
                    //after docnodename , this may be attr of the document node
                    this.domDocNode        = (DomDocumentNode)this._resultHtmlDoc.CreateDocumentNodeElement();
                    domDocNode.DocNodeName = name;
                }
                break;

                case 11:
                {
                    //doc
                    domDocNode.AddParameter(name);
                }
                break;

                default:
                {
                }
                break;
                }
            }
            break;

            case HtmlLexerEvent.VisitCloseAngle:
            {
                //close angle of current new node
                //enter into its content

                if (parseState == 11)
                {
                    //add doctype to html
                    this._resultHtmlDoc.RootNode.AddChild(this.domDocNode);
                    domDocNode = null;
                }

                if (waitingAttrName != null)
                {
                    curAttr       = this._resultHtmlDoc.CreateAttribute(null, waitingAttrName);
                    curAttr.Value = "";
                    curHtmlNode.AddAttribute(curAttr);
                    curAttr = null;
                }


                waitingAttrName = null;
                parseState      = 0;
                curTextNode     = null;
                curAttr         = null;
            }
            break;

            case HtmlLexerEvent.VisitAttrAssign:
            {
                parseState = 4;
            }
            break;

            case HtmlLexerEvent.VisitOpenSlashAngle:
            {
                parseState = 2;
            }
            break;

            case HtmlLexerEvent.VisitCloseSlashAngle:
            {
                if (openEltStack.Count > 0)
                {
                    curTextNode     = null;
                    curAttr         = null;
                    waitingAttrName = null;
                    curHtmlNode     = openEltStack.Pop();
                }
                parseState = 0;
            }
            break;

            case HtmlLexerEvent.VisitOpenAngleExclimation:
            {
                //eg. doctype
                parseState = 10;
            }
            break;

            default:
            {
                //1. visit open angle
            }
            break;
            }
        }
Esempio n. 26
0
        public DomElement GetPresentationDomNode(DomElement hostNode)
        {
            if (pnode != null)
            {
                return(pnode);
            }
            //-----------------------------------
            var doc = hostNode.OwnerDocument;

            this.pnode = doc.CreateElement("div");
            pnode.AddChild("img", item_icon =>
            {
                menuIcon = item_icon;
                menuIcon.AttachMouseDownEvent(e =>
                {
                    //****
                    this.MaintenanceParentOpenState();
                    if (this.IsOpened)
                    {
                        this.Close();
                    }
                    else
                    {
                        this.Open();
                    }
                    e.StopPropagation();
                });
                menuIcon.AttachMouseUpEvent(e =>
                {
                    this.UnmaintenanceParentOpenState();
                    e.StopPropagation();
                });
                menuIcon.AttachEventOnMouseLostFocus(e =>
                {
                    if (!this.MaintenaceOpenState)
                    {
                        this.CloseRecursiveUp();
                    }
                });
            });
            pnode.AddChild("span", content =>
            {
                if (menuItemText != null)
                {
                    pnode.AddTextContent(this.menuItemText);
                }
            });
            //--------------------------------------------------------
            //create simple menu item box

            if (childItems != null)
            {
                floatPart = new MenuBox(400, 200);
                int j = childItems.Count;
                for (int i = 0; i < j; ++i)
                {
                    floatPart.AddChildBox(childItems[i]);
                }
            }
            return(pnode);
        }