public void insertMarker()
        {
            FormattingElement element = new FormattingElement();

            element.isMarker = true;
            append(element);
        }
Пример #2
0
        public bool isEqualTo(FormattingElement element)
        {
            if (this.isMarker != element.isMarker)
            {
                return(false);
            }

            if (this.isMarker)
            {
                // compare token.
                if (this.token.type != element.token.type)
                {
                    return(false);
                }

                else if (this.token.tagName != element.token.tagName)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                // compare element.
                return(ActiveFormattingElementList.IsSameDomElement(this.element, element.element));
            }
        }
        public void Push(FormattingElement element)
        {
            //When the steps below require the UA to push onto the list of active formatting elements an element element, the UA must perform the following steps:

            //If there are already three elements in the list of active formatting elements after the last list marker, if any, or anywhere in the list if there are no list markers, that have the same tag name, namespace, and attributes as element, then remove the earliest such element from the list of active formatting elements.
            if (CounterAfterLastMarker() >= 3 || !HasMark())
            {
                for (int i = 0; i < length; i++)
                {
                    if (!item[i].isMarker)
                    {
                        if (isSameElementAndAttributes(item[i], element))
                        {
                            item.RemoveAt(i);
                            break;
                        }
                    }
                }
            }

            //For these purposes, the attributes must be compared as they were when the elements were created by the parser; two elements have the same attributes if all their parsed attributes can be paired such that the two attributes in each pair have identical names, namespaces, and values (the order of the attributes does not matter).

            //This is the Noah's Ark clause. But with three per family instead of two.

            //Add element to the list of active formatting elements.
            append(element);
        }
        public void Push(Element element, HtmlToken token)
        {
            FormattingElement formatelement = new FormattingElement();

            formatelement.element  = element;
            formatelement.token    = token;
            formatelement.isMarker = false;

            Push(formatelement);
        }
        /// <summary>
        /// Compare two formatting elements.
        /// </summary>
        /// <param name="elementone"></param>
        /// <param name="elementtwo"></param>
        /// <returns></returns>
        private bool isSameElementAndAttributes(FormattingElement elementone, FormattingElement elementtwo)
        {
            //that have the same tag name, namespace, and attributes as element

            if (elementone.element == null || elementtwo.element == null)
            {
                return(false);
            }

            Element one = elementone.element;
            Element two = elementtwo.element;

            return(IsSameDomElement(one, two));
        }
 private void append(FormattingElement element)
 {
     item.Add(element);
 }
        public void Reconstruct()
        {
            // When the steps below require the UA to reconstruct the active formatting elements, the UA must perform the following steps:

            //If there are no entries in the list of active formatting elements, then there is nothing to reconstruct; stop this algorithm.
            if (_treeConstruction.activeFormatingElements.length == 0)
            {
                return;
            }

            //If the last (most recently added) entry in the list of active formatting elements is a marker, or if it is an element that is in the stack of open elements, then there is nothing to reconstruct; stop this algorithm.

            FormattingElement lastitem = LastItem();

            if (lastitem.isMarker || (lastitem.element != null && _treeConstruction.openElements.hasElement(lastitem.element.tagName)))
            {
                return;
            }

            int index = length - 1;

            //Let entry be the last (most recently added) element in the list of active formatting elements.
            FormattingElement entry = item[index];

            //Rewind: If there are no entries before entry in the list of active formatting elements, then jump to the step labeled create.
Rewind:

            if (index == 0)
            {
                goto Create;
            }

            //Let entry be the entry one earlier than entry in the list of active formatting elements.
            index = index - 1;
            entry = item[index];

            //If entry is neither a marker nor an element that is also in the stack of open elements, go to the step labeled rewind.
            if (!entry.isMarker && (entry.element != null && !_treeConstruction.openElements.hasTag(entry.element.tagName)))
            {
                goto Rewind;
            }

            //Advance: Let entry be the element one later than entry in the list of active formatting elements.

Advance:

            index = index + 1;
            entry = item[index];


Create:

            //Create: Insert an HTML element for the token for which the element entry was created, to obtain new element.
            Element newelement = _treeConstruction.createElement(entry.token);
            FormattingElement formatelement = new FormattingElement();

            formatelement.element = newelement;
            formatelement.token   = entry.token;

            //Replace the entry for entry in the list with an entry for new element.
            item[index] = formatelement;

            //If the entry for new element in the list of active formatting elements is not the last entry in the list, return to the step labeled advance.
            if (index < length - 1)
            {
                goto Advance;
            }

            //This has the effect of reopening all the formatting elements that were opened in the current body, cell, or caption (whichever is youngest) that haven't been explicitly closed.
        }