Esempio n. 1
0
 public static DomElement AddChild(this DomElement elem, string elementName, out DomElement elemExit)
 {
     var newchild = elem.OwnerDocument.CreateElement(elementName);
     elem.AddChild(newchild);
     elemExit = newchild;
     return newchild;
 }
Esempio n. 2
0
 public Accumulator(DomElement root,
                    DomQuery elements,
                    Evaluator eval)
 {
     this.root = root;
     this.elements = elements;
     this.eval = eval;
 }
            public override bool Matches(DomElement root, DomElement element)
            {
                foreach (DomElement e in element.Descendants) {
                    if (e != element && evaluator.Matches(root, e))
                        return true;

                }
                return false;
            }
            public override bool Matches(DomElement root, DomElement element)
            {
                var values = element.Attributes;

                foreach (var attribute in values) {
                    if (attribute.Name.StartsWith(prefix, StringComparison.Ordinal))
                        return true;
                }

                return false;
            }
Esempio n. 5
0
        public CssSelector(string query, DomElement root)
        {
            if (query == null)
                throw new ArgumentNullException("query");

            query = query.Trim();
            if (query.Length == 0)
                throw Failure.AllWhitespace("query");

            if (root == null)
                throw new ArgumentNullException("root");

            this.evaluator = QueryParser.Parse(query);
            this.root = root;
        }
Esempio n. 6
0
        public void Parse(TextSource textSnapshot, WebDocument htmldoc, DomElement currentNode)
        {
            this.Parse(textSnapshot.ActualSnapshot, htmldoc, currentNode);

        }
Esempio n. 7
0
 public void Push(DomElement node)
 {
     count++;
     this.nodes.Add(node);
 }
Esempio n. 8
0
 void IDomNodeVisitor.Visit(DomElement element)
 {
     VisitElement(element);
 }
Esempio n. 9
0
 public void ResetParser()
 {
     this._resultHtmlDoc = null;
     this.openEltStack.Clear();
     this.curHtmlNode = null;
     this.curAttr = null;
     this.curTextNode = null;
     this.parseState = 0;
     this.textSnapshot = null;
 }
 /// <summary>
 /// Parses <paramref name="text"/>.
 /// </summary>
 /// <param name="domElement"></param>
 /// <param name="text"></param>
 public void ParseBlockElement(DomElement domElement, String text)
 {
     blocke
     rootElementParser.Parse(domElement, AuthoringScope.All, text);
 }
		/// <summary>
		/// Loads the note into the WebKit view
		/// </summary>
		/// <param name='note'>
		/// Note.
		/// </param>
		private void loadNote (Note note)
		{
			mainWindow.Title = note.Title;
			paraBlock = document.GetElementById("main_content");
			paraBlock.TextContent = note.Text;
		}
Esempio n. 12
0
 /// <summary>
 /// 根据对象数据设置文档元素
 /// </summary>
 /// <param name="document">文档对象</param>
 /// <param name="element">要处理的文档元素对象</param>
 /// <param name="logUndo">是否记录撤销操作信息</param>
 /// <returns>操作是否成功</returns>
 public abstract bool ApplyToElement(DomDocument document, DomElement element, bool logUndo);
Esempio n. 13
0
 void IHxlElementTemplate.Render(DomElement element, HxlWriter output)
 {
 }
 /// <summary>
 /// 重复操作
 /// </summary>
 public override void Redo(DCSoft.CSharpWriter.Undo.XUndoEventArgs args)
 {
     if (myContainer != null)
     {
         DomContentElement ce = myContainer.ContentElement;
         //args.Parameters["ContentElement"] = ce;
         if (_OldElements != null && _NewElements == null)
         {
             // 光删除,重复操作就是重复删除数据
             int index = ce.PrivateContent.IndexOf(_OldElements.FirstContentElement);
             foreach (DomElement element in _OldElements)
             {
                 DomElement e2 = GetContentElement(element);
                 if (e2 != null)
                 {
                     if (e2.OwnerLine != null)
                     {
                         e2.OwnerLine.InvalidateState = true;
                     }
                 }
                 element.OwnerLine = null;
                 myContainer.Elements.Remove(element);
                 myContainer.OwnerDocument.HighlightManager.Remove(element);
             }
             myContainer.UpdateContentVersion();
             this.OwnerList.AddContentRefreshInfo(ce, index);
         }
         else if (_OldElements == null && _NewElements != null)
         {
             // 光插入,重复操作就是重复插入数据
             myContainer.Elements.InsertRange(intIndex, _NewElements);
             foreach (DomElement element in _NewElements)
             {
                 DomElement e2 = GetContentElement(element);
                 if (e2 != null && e2.OwnerLine != null)
                 {
                     e2.OwnerLine.InvalidateState = true;
                 }
                 element.OwnerLine = null;
             }//foreach
             myContainer.UpdateContentVersion();
             AddRefreshElements(
                 _NewElements.FirstContentElement,
                 _NewElements.LastContentElement);
         }
         else if (_OldElements != null && _NewElements != null)
         {
             // 替换,撤销操作就是删除旧数据并插入新数据
             int index = ce.PrivateContent.IndexOf(_OldElements.FirstContentElement);
             foreach (DomElement element in _OldElements)
             {
                 DomElement e2 = GetContentElement(element);
                 if (e2 != null && e2.OwnerLine != null)
                 {
                     e2.OwnerLine.InvalidateState = true;
                 }
                 element.OwnerLine = null;
                 myContainer.Elements.Remove(element);
                 myContainer.OwnerDocument.HighlightManager.Remove(element);
             }
             this.OwnerList.AddContentRefreshInfo(ce, index);
             myContainer.Elements.InsertRange(intIndex, _NewElements);
             foreach (DomElement element in _NewElements)
             {
                 if (element.OwnerLine != null)
                 {
                     element.OwnerLine.InvalidateState = true;
                     element.OwnerLine = null;
                 }
             }
             myContainer.UpdateContentVersion();
             ce.UpdateContentElements(true);
             AddRefreshElements(
                 _NewElements.FirstContentElement,
                 _NewElements.LastContentElement);
         }
         if (this.OwnerList.ContentChangedContainer.Contains(myContainer) == false)
         {
             this.OwnerList.ContentChangedContainer.Add(myContainer);
         }
     }
 }
Esempio n. 15
0
 /// <summary>
 /// 读取元素的属性值到本对象中
 /// </summary>
 /// <param name="element">文档元素对象</param>
 /// <returns>操作是否成功</returns>
 public abstract bool ReadProperties(DomElement element);
        /// <summary>
        /// 撤销操作
        /// </summary>
        public override void Undo(DCSoft.CSharpWriter.Undo.XUndoEventArgs args)
        {
            if (myContainer != null)
            {
                DomContentElement ce = myContainer.ContentElement;
                args.Parameters["ContentElement"] = ce;
                if (_OldElements != null && _NewElements == null)
                {
                    // 光删除,撤销操作就是恢复数据
                    myContainer.Elements.InsertRange(intIndex, _OldElements);
                    foreach (DomElement element in _OldElements)
                    {
                        DomElement e2 = GetContentElement(element);
                        if (e2 != null && e2.OwnerLine != null)
                        {
                            e2.OwnerLine.InvalidateState = true;
                        }
                        element.OwnerLine = null;
                        element.Parent    = myContainer;
                    }
                    myContainer.UpdateContentVersion();
                    AddRefreshElements(
                        _OldElements.FirstContentElement,
                        _OldElements.LastContentElement);
                }
                else if (_OldElements == null && _NewElements != null)
                {
                    // 光插入,撤销操作就是删除数据
                    int index      = ce.PrivateContent.IndexOf(_NewElements.FirstContentElement);
                    int startIndex = index;
                    foreach (DomElement element in _NewElements)
                    {
                        startIndex = Math.Min(startIndex, element.FirstContentElement.ViewIndex);
                        myContainer.Elements.Remove(element);
                        myContainer.OwnerDocument.HighlightManager.Remove(element);

                        DomElement fce = GetContentElement(element.FirstContentElement);
                        DomElement ece = GetContentElement(element.LastContentElement);

                        ce.SetLinesInvalidateState(
                            fce == null ? null : fce.OwnerLine,
                            ece == null ? null : ece.OwnerLine);

                        if (element.OwnerLine != null)
                        {
                            element.OwnerLine.InvalidateState = true;
                            element.OwnerLine = null;
                        }
                    }
                    myContainer.UpdateContentVersion();
                    this.OwnerList.AddContentRefreshInfo(ce, startIndex);
                }
                else if (_OldElements != null && _NewElements != null)
                {
                    // 替换,撤销操作就是删除新数据并恢复旧数据
                    int index      = ce.PrivateContent.IndexOf(_NewElements.FirstContentElement);
                    int startIndex = index;
                    foreach (DomElement element in _NewElements)
                    {
                        startIndex = Math.Min(startIndex, element.FirstContentElement.ViewIndex);
                        myContainer.Elements.Remove(element);
                        myContainer.OwnerDocument.HighlightManager.Remove(element);

                        DomElement fce = GetContentElement(element.FirstContentElement);
                        DomElement ece = GetContentElement(element.LastContentElement);

                        ce.SetLinesInvalidateState(
                            fce == null ? null : fce.OwnerLine,
                            ece == null ? null : ece.OwnerLine);

                        //ce.SetLinesInvalidateState(
                        //    element.FirstContentElement.OwnerLine,
                        //    element.LastContentElement.OwnerLine);
                        element.OwnerLine = null;
                    }
                    this.OwnerList.AddContentRefreshInfo(ce, startIndex);
                    myContainer.Elements.InsertRange(intIndex, _OldElements);
                    foreach (DomElement element in _OldElements)
                    {
                        if (element.OwnerLine != null)
                        {
                            element.OwnerLine.InvalidateState = true;
                            element.OwnerLine = null;
                        }
                        element.Parent = myContainer;
                    }
                    myContainer.UpdateContentVersion();
                    this.OwnerList.RefreshElements.Add(
                        GetContentElement(
                            _OldElements.FirstContentElement));
                    this.OwnerList.RefreshElements.Add(
                        GetContentElement(
                            _OldElements.LastContentElement));
                }
                if (this.OwnerList.ContentChangedContainer.Contains(myContainer) == false)
                {
                    this.OwnerList.ContentChangedContainer.Add(myContainer);
                }
            }
        }
Esempio n. 17
0
 /// <summary>
 /// Search for the prefix associated with specified namespace URI.
 /// </summary>
 /// <param name="element">the element to start searching from</param>
 /// <param name="ns">the namespace prefix</param>
 /// <returns>the prefix bound to the namespace URI; or null if there is no such namespace</returns>
 public static String LookupPrefix(DomElement element, String ns)
 {
     Dictionary<String, DomAttr> attributes = element.getAttributesMap();
     foreach (KeyValuePair<String, DomAttr> entry in attributes)
     {
         String name = entry.Key;
         DomAttr value = entry.Value;
         if (name.StartsWith("xmlns:") && String.Equals(value.getValue(), ns))
         {
             return name.Substring(6);
         }
     }
     foreach (DomNode child in element.getChildren())
     {
         if (child is DomElement)
         {
             String prefix = LookupPrefix((DomElement)child, ns);
             if (prefix != null)
             {
                 return prefix;
             }
         }
     }
     return null;
 }
Esempio n. 18
0
 /// <summary>
 /// Search for the namespace URI of the given prefix, starting from the specified element.
 /// The default namespace can be searched for by specifying "" as the prefix.
 /// </summary>
 /// <param name="element">the element to start searching from</param>
 /// <param name="prefix">the namespace prefix</param>
 /// <returns>the namespace URI bound to the prefix; or null if there is no such namespace</returns>
 public static String LookupNamespaceURI(DomElement element, String prefix)
 {
     String uri = DomElement.ATTRIBUTE_NOT_DEFINED;
     if (String.IsNullOrEmpty(prefix))
     {
         uri = element.getAttribute("xmlns");
     }
     else
     {
         uri = element.getAttribute("xmlns:" + prefix);
     }
     if (uri == DomElement.ATTRIBUTE_NOT_DEFINED)
     {
         DomNode parentNode = element.getParentNode();
         if (parentNode is DomElement)
         {
             uri = LookupNamespaceURI((DomElement)parentNode, prefix);
         }
     }
     return uri;
 }
Esempio n. 19
0
        /// <summary>
        /// Parse the HTML, and return it, based on options set.
        /// </summary>
        ///
        /// <returns>
        /// An enumerator of the top-level elements.
        /// </returns>

        protected IEnumerable <IDomObject> ParseImplementation()
        {
            int pos = 0;
            Stack <IterationData> stack = new Stack <IterationData>();

            while (pos <= EndPos)
            {
                IterationData current = new IterationData();
                if (WrapRootTextNodes)
                {
                    current.WrapLiterals = true;
                }

                current.Reset(pos);
                stack.Push(current);

                while (stack.Count != 0)
                {
                    current = stack.Pop();

                    while (current.TokenizerState != TokenizerState.Finished && current.Pos <= EndPos)
                    {
                        char c = Html[current.Pos];
                        switch (current.TokenizerState)
                        {
                        case TokenizerState.Default:
                            if (current.FindNextTag(Html))
                            {
                                // even if we fell through from ReadTextOnly (e.g. was never closed), we should proceeed to finish
                                current.TokenizerState = TokenizerState.TagStart;
                            }
                            break;

                        case TokenizerState.TagStart:
                            IDomObject literal;
                            if (current.TryGetLiteral(this, out literal))
                            {
                                yield return(literal);
                            }

                            int tagStartPos = current.Pos;

                            string newTag = current.GetTagOpener(Html);

                            if (newTag == String.Empty)
                            {
                                // It's a tag closer. Make sure it's the right one.
                                current.Pos = tagStartPos + 1;
                                ushort closeTagId = HtmlData.Tokenize(current.GetCloseTag(Html));

                                // Ignore empty tags, or closing tags found when no parent is open
                                bool isProperClose = closeTagId == current.ParentTagID();
                                if (closeTagId == 0)
                                {
                                    // ignore empty tags
                                    continue;
                                }
                                else
                                {
                                    // locate match for this closer up the heirarchy
                                    IterationData actualParent = null;

                                    if (!isProperClose)
                                    {
                                        actualParent = current.Parent;
                                        while (actualParent != null && actualParent.Element.NodeNameID != closeTagId)
                                        {
                                            actualParent = actualParent.Parent;
                                        }
                                    }
                                    // if no matching close tag was found up the tree, ignore it
                                    // otherwise always close this and repeat at the same position until the match is found
                                    if (!isProperClose && actualParent == null)
                                    {
                                        current.InsertionMode = InsertionMode.Invalid;
                                        continue;
                                    }
                                }
                                // element is closed

                                if (current.Parent.Parent == null)
                                {
                                    yield return(current.Parent.Element);
                                }
                                current.TokenizerState = TokenizerState.Finished;
                                if (isProperClose)
                                {
                                    current.Parent.Reset(current.Pos);
                                }
                                else
                                {
                                    current.Parent.Reset(tagStartPos);
                                }
                                // already been returned before we added the children
                                continue;
                            }
                            else if (newTag[0] == '!')
                            {
                                IDomSpecialElement specialElement = null;
                                string             newTagUpper    = newTag.ToUpper();
                                if (newTagUpper.StartsWith("!DOCTYPE"))
                                {
                                    specialElement  = new DomDocumentType();
                                    current.Element = specialElement;
                                }
                                else if (newTagUpper.StartsWith("![CDATA["))
                                {
                                    specialElement  = new DomCData();
                                    current.Element = specialElement;
                                    current.Pos     = tagStartPos + 9;
                                }
                                else
                                {
                                    specialElement  = new DomComment();
                                    current.Element = specialElement;
                                    if (newTag.StartsWith("!--"))
                                    {
                                        ((DomComment)specialElement).IsQuoted = true;
                                        current.Pos = tagStartPos + 4;
                                    }
                                    else
                                    {
                                        current.Pos = tagStartPos + 1;
                                    }
                                }

                                string endTag = (current.Element is IDomComment && ((IDomComment)current.Element).IsQuoted) ? "-->" : ">";

                                int tagEndPos = Html.Seek(endTag, current.Pos);
                                if (tagEndPos < 0)
                                {
                                    // if a tag is unclosed entirely, then just find a new line.
                                    tagEndPos = Html.Seek(System.Environment.NewLine, current.Pos);
                                }
                                if (tagEndPos < 0)
                                {
                                    // Never closed, no newline - junk, treat it like such
                                    tagEndPos = EndPos;
                                }

                                specialElement.NonAttributeData = Html.SubstringBetween(current.Pos, tagEndPos);
                                current.Pos = tagEndPos;
                            }
                            else
                            {
                                // seems to be a new element tag, parse it.

                                ushort newTagId = HtmlData.Tokenize(newTag);

                                // Before we keep going see if this is an implicit close
                                ushort parentTagId = current.ParentTagID();

                                int lastPos = current.Pos;

                                if (parentTagId == 0 && IsDocument)
                                {
                                    if (newTagId != HtmlData.tagHTML)
                                    {
                                        current.Element = DomElement.Create(HtmlData.tagHTML);
                                        current         = current.AddNewChild();
                                        parentTagId     = HtmlData.tagHTML;
                                    }
                                }

                                if (parentTagId != 0)
                                {
                                    ushort action = SpecialTagActionDelegate(parentTagId, newTagId);

                                    while (action != HtmlData.tagActionNothing)
                                    {
                                        if (action == HtmlData.tagActionClose)
                                        {
                                            // track the next parent up the chain

                                            var newNode = (current.Parent != null) ?
                                                          current.Parent : null;

                                            // same tag for a repeater like li occcurred - treat like a close tag

                                            if (current.Parent.Parent == null)
                                            {
                                                yield return(current.Parent.Element);
                                            }

                                            current.TokenizerState = TokenizerState.Finished;
                                            //current.Parent.Reset(tagStartPos);

                                            if (newNode != null && newNode.Parent != null && newNode.Parent.Element != null)
                                            {
                                                action = SpecialTagActionDelegate(newNode.Parent.Element.NodeNameID, newTagId);
                                                if (action != HtmlData.tagActionNothing)
                                                {
                                                    current = newNode;
                                                }
                                            }
                                            else
                                            {
                                                action = HtmlData.tagActionNothing;
                                            }
                                        }
                                        else
                                        {
                                            if (GenerateOptionalElements)
                                            {
                                                stack.Push(current);
                                                current = current.AddNewParent(action, lastPos);
                                            }
                                            action = HtmlData.tagActionNothing;
                                        }
                                    }
                                    if (current.TokenizerState == TokenizerState.Finished)
                                    {
                                        current.Parent.Reset(tagStartPos);
                                        continue;
                                    }
                                }


                                current.Element = DomElement.Create(newTagId);


                                if (!current.Element.InnerHtmlAllowed && current.Element.InnerTextAllowed)
                                {
                                    current.InsertionMode  = InsertionMode.Text;
                                    current.TokenizerState = TokenizerState.Default;
                                }

                                // Parse attribute data
                                while (current.Pos <= EndPos)
                                {
                                    if (!current.GetTagAttribute(Html))
                                    {
                                        break;
                                    }
                                }
                            }

                            IDomObject el;

                            if (current.FinishTagOpener(Html, out el))
                            {
                                stack.Push(current);
                                current = current.AddNewChild();
                            }

                            if (el != null)
                            {
                                yield return(el);
                            }

                            break;
                        }
                    }


                    // Catchall for unclosed tags -- if there's an "unfinished" carrier here, it's because  top-level tag was unclosed.
                    // THis will wrap up any straggling text and close any open tags after it.

                    if (current.TokenizerState != TokenizerState.Finished)
                    {
                        foreach (var el in current.CloseElement(this))
                        {
                            yield return(el);
                        }
                    }
                }
                pos = current.Pos;
            }
        }
Esempio n. 20
0
 public ModelElementInstanceImpl(ModelTypeInstanceContext instanceContext)
 {
     this.domElement    = instanceContext.DomElement;
     this.modelInstance = instanceContext.Model;
     this.elementType   = instanceContext.ModelType;
 }
Esempio n. 21
0
 public EaseScriptElement(DomElement elem)
 {
     _elem = elem as HtmlElement;
 }
 public override bool Matches(DomElement root, DomElement element)
 {
     return !value.Equals(element.Attribute(name), StringComparison.OrdinalIgnoreCase);
 }
Esempio n. 23
0
 /// <summary>
 /// 初始化对象
 /// </summary>
 /// <param name="element">操作的文档元素</param>
 /// <param name="oldStyleIndex">旧样式编号</param>
 /// <param name="newStyleIndex">新样式编号</param>
 public XTextUndoStyleIndex(DomElement element, int oldStyleIndex, int newStyleIndex)
 {
     _Element       = element;
     _OldStyleIndex = oldStyleIndex;
     _NewStyleIndex = newStyleIndex;
 }
Esempio n. 24
0
 public override bool Matches(DomElement root, DomElement element)
 {
     return id.Equals(element.Id);
 }
Esempio n. 25
0
        protected override void VisitElement(DomElement element)
        {
            if (element == null)
                throw new ArgumentNullException("element");

            writer.WriteStartElement(element.Name, element.NamespaceUri);
            Visit(element.Attributes);
            Visit(element.ChildNodes);
            writer.WriteEndElement();
        }
Esempio n. 26
0
 public void Push(DomElement node)
 {
     count++;
     this.nodes.Add(node);
 }
Esempio n. 27
0
 public XmlQName(DomElement element, string namespaceUri, string localName) : this(element.Document, element, namespaceUri, localName)
 {
 }
Esempio n. 28
0
        protected virtual void VisitElement(DomElement element)
        {
            if (element == null)
                throw new ArgumentNullException("element");

            DefaultVisit(element);
            Visit(element.Attributes);
        }
        /// <summary>
        /// Returns a literal object for the text between HtmlStart (the last position of the end of a tag) and the current position.
        /// If !AllowLiterals then it's wrapped in a span.
        /// </summary>
        /// <param name="current"></param>
        /// <returns></returns>
        protected IDomObject GetLiteral(IterationData current)
        {
            // There's plain text -return it as a literal.

            IDomObject textObj;
            DomText lit;
            if (current.Invalid) {
                lit = new DomInvalidElement();
            }
            else if (current.ReadTextOnly)
            {
                current.ReadTextOnly = false;
                lit = new DomInnerText();
            } else {
                lit = new DomText();
            }

            if (isBound)
            {
                lit.SetTextIndex(Document, Document.TokenizeString(current.HtmlStart, current.Pos - current.HtmlStart));
            }
            else
            {
                string text = BaseHtml.SubstringBetween(current.HtmlStart, current.Pos);
                lit.NodeValue = Objects.HtmlDecode(text);
            }

            if (!current.AllowLiterals)
            {
                IDomElement wrapper = new DomElement("span");
                wrapper.AppendChild(lit);
                textObj = wrapper;
            }
            else
            {
                textObj = lit;
            }

            if (current.Parent != null)
            {
                current.Parent.Element.AppendChild(textObj);
                current.Reset();
                return null;
            }
            else
            {
                current.Finished = true;
                return textObj;
            }
        }
Esempio n. 30
0
        /// <summary>
        /// Add a new parent of type tagId. In other words, wrap the current element in a new element.
        /// </summary>
        ///
        /// <param name="tagId">
        /// The token for the tag to add
        /// </param>
        /// <param name="pos">
        /// The index position for the iteration data
        /// </param>
        ///
        /// <returns>
        /// The iteration data representing the current element (replaces the
        /// </returns>

        public IterationData AddNewParent(ushort tagId, int pos)
        {
            Element = DomElement.Create(tagId);
            ((DomElement)Parent.Element).ChildNodesInternal.AddAlways(Element);
            return(AddNewChild(pos));
        }
Esempio n. 31
0
 public abstract void Parse(TextSource textSnapshot, WebDocument htmldoc, DomElement currentNode);
Esempio n. 32
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. 33
0
 public abstract void Parse(TextSource textSnapshot, WebDocument htmldoc, DomElement currentNode);
Esempio n. 34
0
 public HtmlDocument(UniqueStringTable sharedUniqueStringTable)
     : base(sharedUniqueStringTable)
 {
     //auto create root doc
     rootNode = new HtmlRootElement(this);
 }
Esempio n. 35
0
        /// <summary>
        /// parse to htmldom
        /// </summary>
        /// <param name="stbuilder"></param>
        internal void Parse(TextSnapshot textSnapshot, WebDocument htmldoc, DomElement currentNode)
        {
            this.textSnapshot = textSnapshot;
            //1. lex 
            lexer.BeginLex();
            //2. mini parser    
            this.curHtmlNode = currentNode;
            this._resultHtmlDoc = htmldoc;
            lexer.Analyze(textSnapshot);
            lexer.EndLex();

        }
Esempio n. 36
0
 protected void SetRootElement(DomElement rootE)
 {
     this.rootNode = rootE;
 }
Esempio n. 37
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
                        curAttr.Value = textSnapshot.Substring(startIndex, len);
                        curHtmlNode.AddAttribute(curAttr);

                    } break;

                case HtmlLexerEvent.Attribute:
                    {
                        string nodename = textSnapshot.Substring(startIndex, len);
                        curAttr = this._resultHtmlDoc.CreateAttribute(null, nodename);

                    } break;
                case HtmlLexerEvent.NodeNameOrAttribute:
                    {
                        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 (HtmlDecodeHelper.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:
                    {
                        parseState = 10;
                    } break;
                default:
                    {
                        //1. visit open angle
                    } break;

            }
        }
Esempio n. 38
0
 public ProductItem(IWebDriver driver, DomElement container) : base(driver)
 {
     Container = container;
 }
Esempio n. 39
0
 public DOMTable(IWebDriver driver, DomElement container)
 {
     Table = container;
 }
Esempio n. 40
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);
        }
 public override bool Matches(DomElement root, DomElement element)
 {
     return pattern.IsMatch(element.OwnText);
 }
        /// <summary>
        /// 弹出下拉列表
        /// </summary>
        /// <param name="control">要显示的数据内容控件</param>
        /// <returns>用户是否确认数据编辑操作</returns>
        public void DropDownControl(Control control)
        {
            _UserAccept = false;
            if (control == null)
            {
                throw new ArgumentNullException("control");
            }
            if (_PopupForm == null)
            {
                _PopupForm = new XPopupForm();
                _PopupForm.OwnerControl = this._EditControl;
                //_PopupForm.ControlBox = true;
            }
            Size size = control.GetPreferredSize(new Size(0, 300));    // .Size;

            _PopupForm.ClientSize = new Size(
                size.Width + 5 + PopupFormSizeFix.Width,
                size.Height + 5 + PopupFormSizeFix.Height);

            WindowInformation info   = new WindowInformation(_PopupForm.Handle);
            Rectangle         rect2  = info.Bounds;
            Rectangle         crect2 = info.ClientBounds;

            _PopupForm.Controls.Clear();
            _PopupForm.Controls.Add(control);
            control.Dock = DockStyle.Fill;


            if (_PopupForm.ClientSize.Width < control.Width)
            {
            }
            _PopupForm.AutoClose = true;
            //_PopupForm.CanGetFocus = true;
            //_PopupForm.Visible = true;
            //_PopupForm.Show();
            ImeMode back = ImeMode.NoControl;

            if (this._EditControl != null &&
                _EditControl.IsHandleCreated &&
                _EditControl.IsDisposed == false &&
                _ElementInstance != null)
            {
                _PopupForm.Owner   = this._EditControl.FindForm();
                _PopupForm.TopMost = (_PopupForm.Owner != null);

                if (this._ElementInstance is DomElement)
                {
                    DomElement element = (DomElement)this._ElementInstance;
                    if (!(element is DomParagraphFlagElement))
                    {
                        element = element.FirstContentElement;
                    }
                    if (element == null)
                    {
                        goto EndFunction;
                    }
                    Rectangle rect = this._EditControl.GetCompositionRect(
                        element.AbsLeft,
                        element.AbsTop,
                        element.Height);
                    _PopupForm.CompositionRect = rect;
                    _PopupForm.UpdateComposition();
                }
                _PopupForm.Show();
                if (control is MonthCalendar)
                {
                    MonthCalendar mc = (MonthCalendar)control;
                    size = mc.Size;
                    _PopupForm.ClientSize = new Size(
                        size.Width + PopupFormSizeFix.Width,
                        size.Height + PopupFormSizeFix.Height);
                }
                else if (control is DateTimeSelectControl)
                {
                    DateTimeSelectControl dtc = (DateTimeSelectControl)control;
                    size = dtc.GetPreferredSize(Size.Empty);
                    _PopupForm.ClientSize = new Size(
                        size.Width + PopupFormSizeFix.Width,
                        size.Height + PopupFormSizeFix.Height);
                }
                if (_PopupForm.CanGetFocus == false)
                {
                    if (ForceFousePopupControl)
                    {
                        this._EditControl.Focus();
                    }
                }
                back = _EditControl.ImeMode;
                _EditControl.ImeMode = ImeMode.Disable;
            }//if
            _PopupForm.WaitUserSelected();
EndFunction:
            _PopupForm.CloseList();
            if (_PopupForm != null)
            {
                _PopupForm.Controls.Clear();
            }
            if (control != null)
            {
                control.Dispose();
            }
            if (_EditControl != null)
            {
                _EditControl.ImeMode = back;
                _EditControl.Focus();
            }

            //_UserAccept = ( _PopupForm.UserProcessState == UserProcessState.Accept );
        }
Esempio n. 43
0
        public void ShowMiniCart()
        {
            DomElement cartButton = Container.GetElementWaitByCSS(CartButton.locator);

            HoverWebElement(cartButton);
        }
 public override bool Matches(DomContainer root, DomElement element)
 {
     return(element.ElementPosition < index);
 }
Esempio n. 45
0
 void IHxlElementTemplate.Render(DomElement element, HxlWriter output)
 {
     RenderElementStart(element, output.BaseWriter);
     output.Write(element.ChildNodes);
     RenderElementEnd(element, output.BaseWriter);
 }
 public override bool Matches(DomElement root, DomElement element)
 {
     return element.ElementPosition < index;
 }
        LayoutFarm.HtmlBoxes.CssBox CreateInputBox(DomElement domE,
                                                   LayoutFarm.HtmlBoxes.CssBox parentBox,
                                                   BoxSpec spec,
                                                   LayoutFarm.RootGraphic rootgfx, HtmlHost host)
        {
            var typeAttr = domE.FindAttribute("type");

            if (typeAttr != null)
            {
                switch (typeAttr.Value)
                {
                case "text":
                {
                    // user can specific width of textbox
                    //var textbox = new LayoutFarm.CustomWidgets.TextBox(100, 17, false);
                    var textbox    = new LayoutFarm.CustomWidgets.TextBoxContainer(100, 20, false);
                    var wrapperBox = CreateWrapper(
                        textbox,
                        textbox.GetPrimaryRenderElement(rootgfx),
                        spec, true);
                    //place holder support
                    var placeHolderAttr = domE.FindAttribute("placeholder");
                    if (placeHolderAttr != null)
                    {
                        textbox.PlaceHolderText = placeHolderAttr.Value;
                    }
                    parentBox.AppendChild(wrapperBox);
                    return(wrapperBox);
                }

                case "button":
                {
                    //use subdom? technique
                    //todo: review the technique here
                    var button       = new HtmlWidgets.Button(60, 30);
                    var ihtmlElement = domE as LayoutFarm.WebDom.IHtmlElement;
                    if (ihtmlElement != null)
                    {
                        button.Text = ihtmlElement.innerHTML;
                    }
                    else
                    {
                        button.Text = "";
                    }
                    button.Text = "testButton";
                    DomElement buttonDom    = button.GetPresentationDomNode((HtmlDocument)domE.OwnerDocument);
                    CssBox     buttonCssBox = host.CreateBox2(parentBox, (WebDom.Impl.HtmlElement)buttonDom, true);     // CreateCssBox(buttonDom, parentBox, spec, host);
                    //var ui = button.GetPrimaryUIElement(this.myHost);

                    //var wrapperBox = CreateWrapper(
                    //    button,
                    //    ui.GetPrimaryRenderElement(rootgfx),
                    //    spec, true);
                    //parentBox.AppendChild(wrapperBox);
                    //return wrapperBox;

                    parentBox.AppendChild(buttonCssBox);
                    return(buttonCssBox);
                }

                case "textbox":
                {
                    var    textbox    = new LayoutFarm.CustomWidgets.TextBox(100, 17, false);
                    CssBox wrapperBox = CreateWrapper(
                        textbox,
                        textbox.GetPrimaryRenderElement(rootgfx),
                        spec, true);
                    parentBox.AppendChild(wrapperBox);
                    return(wrapperBox);
                }

                case "radio":
                {
                    //tempfix -> just copy the Button code,
                    //TODO: review here, use proper radio button
                    var    box        = new LayoutFarm.CustomWidgets.SimpleBox(20, 20);
                    CssBox wrapperBox = CreateWrapper(
                        box,
                        box.GetPrimaryRenderElement(rootgfx),
                        spec, true);
                    parentBox.AppendChild(wrapperBox);
                    return(wrapperBox);
                }
                break;
                }
            }
            return(null);
        }
 public override bool Matches(DomContainer root, DomElement element)
 {
     return(element.InnerText.IndexOf(searchText, StringComparison.OrdinalIgnoreCase) >= 0);
 }
Esempio n. 49
0
 public void EndElement()
 {
     _currentElement = _stack.Pop();
 }
Esempio n. 50
0
 public override bool Matches(DomContainer root, DomElement element)
 {
     return(element.HasAttribute(name));
 }
		private void NewNote ()
		{
			Note note = AppDelegate.NoteEngine.NewNote ();
			note.Title = "New Note";
			paraBlock = document.GetElementById("main_content");
			paraBlock.TextContent = "Example Note";
			setTitle (note.Title);
			/* select the row that the new Note was added to.
			 * In TableNotesDataSource we assume and add the new Note to index 0 in the notes arraylist
			 */
			tblNotes.SelectRow (0, false);
			/* Set the new row to the viewable row */
			System.Drawing.PointF point = new System.Drawing.PointF (0, 0);
			notesScrollView.ScrollPoint (point);
			notesScrollView.ContentView.ScrollPoint (point);
			
			/* Example of programmically making element editable 
			* ((DomHtmlElement)document.GetElementById("main_content")).
			*/
		}
 public override bool Matches(DomElement root, DomElement element)
 {
     return element.HasAttribute(name);
 }
Esempio n. 53
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. 54
0
        protected void ElementProperties(object sender, WriterCommandEventArgs args)
        {
            if (args.Mode == WriterCommandEventMode.QueryState)
            {
                args.Enabled = args.DocumentControler != null &&
                               args.DocumentControler.CanSetStyle;
            }
            else if (args.Mode == WriterCommandEventMode.Invoke)
            {
                args.Result = false;
                DomElement element = args.Document.CurrentElement;
                if (args.Document.Selection.ContentElements.Count == 1)
                {
                    element = args.Document.Selection.ContentElements[0];
                }

                while (element != null)
                {
                    ElementEditor editor = (ElementEditor)TypeDescriptor.GetEditor(element, typeof(ElementEditor));
                    if (editor != null)
                    {
                        if (editor.IsSupportMethod(ElementEditMethod.Edit))
                        {
                            // 调用指定的编辑器
                            ElementEditEventArgs ea = new ElementEditEventArgs();
                            ea.Document = args.Document;
                            ea.Element  = element;
                            ea.Host     = args.Host;
                            ea.LogUndo  = true;
                            ea.Method   = ElementEditMethod.Edit;
                            bool changed = false;
                            args.Document.BeginLogUndo();
                            if (editor.Edit(ea))
                            {
                                // 更新元素内容版本号
                                if (element is DomContainerElement)
                                {
                                    DomContainerElement c = (DomContainerElement)element;
                                    c.EditorInvalidateContent();
                                }
                                element.UpdateContentVersion();
                                element.InvalidateView();
                                changed = true;
                            }
                            args.Document.EndLogUndo();
                            if (changed)
                            {
                                args.Result            = true;
                                args.Document.Modified = true;
                                //args.Document.OnSelectionChanged();
                                args.Document.OnDocumentContentChanged();
                                args.RefreshLevel = UIStateRefreshLevel.All;
                            }
                        }
                        return;
                    }
                    element = element.Parent;
                }//while

                element = args.Document.CurrentElement;
                if (args.Document.Selection.ContentElements.Count == 1)
                {
                    element = args.Document.Selection.ContentElements[0];
                }

                XTextElementProperties properties = null;
                while (element != null)
                {
                    properties = args.Host.CreateProperties(element.GetType());
                    if (properties != null)
                    {
                        break;
                    }
                    element = element.Parent;
                }//while
                if (properties != null)
                {
                    properties.Document = args.Document;
                    if (properties.ReadProperties(element))
                    {
                        args.SourceElement = element;
                        if (properties.PromptEditProperties(args))
                        {
                            args.Document.BeginLogUndo();
                            bool changed = false;
                            if (properties.ApplyToElement(args.Document, element, true))
                            {
                                // 更新元素内容版本号
                                if (element is DomContainerElement)
                                {
                                    DomContainerElement c = (DomContainerElement)element;
                                    c.EditorInvalidateContent();
                                }
                                element.UpdateContentVersion();
                                element.InvalidateView();
                                changed = true;
                            }
                            args.Document.EndLogUndo();
                            if (changed)
                            {
                                args.Result            = true;
                                args.Document.Modified = true;
                                //args.Document.OnSelectionChanged();
                                args.Document.OnDocumentContentChanged();
                                args.RefreshLevel = UIStateRefreshLevel.All;
                            }
                        }
                    }
                }
            }
        }
 public override bool Matches(DomElement root, DomElement element)
 {
     return element.HasAttribute(name) && pattern.IsMatch(element.Attribute(name));
 }
Esempio n. 56
0
        public override void Parse(TextSource textSnapshot, WebDocument htmldoc, DomElement currentNode)
        {
            _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);
                    while (tokenizer.ReadNextToken(out HtmlToken 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 = _resultHtmlDoc.CreateElement(null, tag.Name);

                                currentNode.AddChild(elem);
                                foreach (HtmlAttribute attribute in tag.Attributes)
                                {
                                    DomAttribute attr = _resultHtmlDoc.CreateAttribute(attribute.Name);
                                    if (attribute.Value != null)
                                    {
                                        attr.Value = attribute.Value;
                                    }
                                    elem.SetAttribute(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 = 20;   //?
                                    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. 57
0
 public override bool Matches(DomElement root, DomElement element)
 {
     throw new NotImplementedException(); // return (element.HasClass(className));
 }
Esempio n. 58
0
 public PlaceholderContent(DomElement element, string layout)
 {
     this.Element = element;
     this.Layout  = layout;
 }
Esempio n. 59
0
 /// <summary>
 /// 创建 DomAttribute 实例
 /// </summary>
 /// <param name="element">所属元素</param>
 /// <param name="name">属性名</param>
 /// <param name="value">属性值</param>
 public DomAttribute( DomElement element, string name, string value )
 {
     _element = element;
       _name = name;
       _value = value;
 }
Esempio n. 60
0
 public override bool Matches(DomContainer root, DomElement element)
 {
     return(element.Name == _tagName);
 }