Exemple #1
0
 public void RegisterBehavior(IHTMLElement element, HtmlEditorElementBehavior behavior)
 {
     lock (this)
     {
         _activeBehaviors[element]  = behavior;
         _elementBehaviors[element] = behavior;
     }
 }
 public void RegisterBehavior( IHTMLElement element, HtmlEditorElementBehavior behavior)
 {
     lock(this)
     {
         _activeBehaviors[element] = behavior;
         _elementBehaviors[element] = behavior;
     }
 }
Exemple #3
0
        public void RefreshBehaviors(IHTMLDocument2 document)
        {
            lock (this)
            {
                // get interface needed for element enumeration
                IHTMLDocument3 document3 = (IHTMLDocument3)document;

                // build new list of active behaviors
                Hashtable newActiveBehaviors = new Hashtable();

                //register global behaviors
                IDictionaryEnumerator behaviorEnumerator = _globalElementBehaviors.GetEnumerator();
                while (behaviorEnumerator.MoveNext())
                {
                    string tagName = (string)behaviorEnumerator.Key;
                    foreach (IHTMLElement element in document3.getElementsByTagName(tagName))
                    {
                        // if the element is already assigned an active behavior then move it
                        if (_activeBehaviors.ContainsKey(element))
                        {
                            newActiveBehaviors[element] = _activeBehaviors[element];
                            _activeBehaviors.Remove(element);
                        }
                        else // otherwise create a new behavior and add it
                        {
                            HtmlEditorElementBehavior elementBehavior = (HtmlEditorElementBehavior)Activator.CreateInstance(
                                (Type)behaviorEnumerator.Value, new object[] { element, _editorContext });
                            newActiveBehaviors[element] = elementBehavior;
                        }
                    }
                }

                //register element behaviors
                behaviorEnumerator = _elementBehaviors.GetEnumerator();
                while (behaviorEnumerator.MoveNext())
                {
                    IHTMLElement element = (IHTMLElement)behaviorEnumerator.Key;
                    // if the element is already assigned an active behavior then move it
                    if (_activeBehaviors.ContainsKey(element))
                    {
                        newActiveBehaviors[element] = _activeBehaviors[element];
                        _activeBehaviors.Remove(element);
                    }
                    else // otherwise create a new behavior and add it
                    {
                        Debug.Fail("illegal state: element behavior is not in the _activeBehaviors table");
                    }
                }

                // all of the elements left in the activeBehaviors list are no longer in the document
                // so we should dispose and remove them from the list
                foreach (HtmlEditorElementBehavior elementBehavior in _activeBehaviors.Values)
                {
                    elementBehavior.DetachFromElement();
                }
                _activeBehaviors.Clear();

                // swap for new list
                _activeBehaviors = newActiveBehaviors;
            }
        }