public HtmlEditorControlDamageServices(HtmlEditorControl editorControl, MshtmlEditor mshtmlControl, DamageCommitStrategy commitStrategy)
        {
            _editorControl = editorControl;
            _mshtmlControl = mshtmlControl;
            wordRangeDamager = new WordRangeDamager(editorControl, mshtmlControl);

            _commitStrategy = commitStrategy;
            _commitStrategy.CommitDamage += new EventHandler(damageCommitStrategy_CommitDamage);
        }
        private void _blogPostHtmlEditorControl_PostEditorEvent(object sender, MshtmlEditor.EditDesignerEventArgs e)
        {
            if (e.EventDispId != DISPID_HTMLELEMENTEVENTS2.ONKEYPRESS)
                return;
            char c = Convert.ToChar(e.EventObj.keyCode);

            try
            {
                MaybeExecuteDelayedAutoReplaceOperation(c);
            }
            catch (Exception ex)
            {
                Trace.Fail("Error while handling posteditorevent, suppressing autocomplete " + ex);
                _delayedAutoReplaceAction = null;
                _haltAutoReplace = true;
                throw;
            }
        }
Ejemplo n.º 3
0
 public ResumeNotificationHelper(MshtmlEditor _parent)
 {
     this._parent = _parent;
 }
        public WordRangeDamager(HtmlEditorControl editorControl, MshtmlEditor mshtmlControl)
        {
            _editorControl = editorControl;
            _mshtmlEditor = mshtmlControl;

            damageQueue = new DamageRegionQueue();
            Reset();
        }
Ejemplo n.º 5
0
        public HtmlEditorControl(IMainFrameWindow mainFrameWindow, IStatusBar statusBar, MshtmlOptions options, ISpellingChecker spellingChecker, IInternetSecurityManager internetSecurityManager, CommandManager commandManager)
        {
            _commandManager = commandManager;

            // save reference to main frame window
            _mainFrameWindow = mainFrameWindow;
            _statusBar = statusBar;

            _spellingChecker = spellingChecker;

            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            //initialize the data format handlers for this control
            DataFormatHandlerFactory = new HtmlEditorMarshallingHandler(this);
            MarshalImagesSupported = true;
            MarshalFilesSupported = true;
            MarshalUrlSupported = true;
            MarshalHtmlSupported = true;
            MarshalTextSupported = true;

            // The version host service provider tells MSHTML what feature versions are available (e.g. VML 1.0).
            VersionHostServiceProvider = new VersionHostServiceProvider(new DisableVmlVersionHost());

            // initialize the html editor
            if (_editorCache == null)
            {
                _internetSecurityManager = new InternetSecurityManagerShim(internetSecurityManager);
                // If mainFrameWindow == null, then we are pre-caching mshtml and don't want it to steal focus
                _mshtmlEditor = new MshtmlEditor(this, options, (mainFrameWindow == null));
            }
            else
            {
                _mshtmlEditor = _editorCache.Editor;
                _internetSecurityManager = _editorCache.SecurityManager;
                _internetSecurityManager.SecurityManager = internetSecurityManager;

                _editorCache = null;
                _mshtmlEditor.Active = true;
                _mshtmlEditor.MshtmlControl.ProtectFocus = false;
                _mshtmlEditor.ClearContextMenuHandlers();
                _mshtmlEditor.SetServiceProvider(this);
                _mshtmlEditor.UpdateOptions(options, true);
            }

            _mshtmlOptions = options;
            this.DefaultBlockElement = _mshtmlOptions.UseDivForCarriageReturn
                                           ? (DefaultBlockElement)new DivDefaultBlockElement()
                                           : new ParagraphDefaultBlockElement();

            PostEditorEvent += new MshtmlEditor.EditDesignerEventHandler(HtmlEditorControl_PostEditorEvent);
            HandleClear += new HtmlEditorSelectionOperationEventHandler(TryMoveIntoNextTable);

            // Hook the editor into the stream of the security manager so we
            // can allow our own objects (smart content, image resizing) to load in the editor
            _internetSecurityManager.HandleProcessUrlAction = HandleProcessUrlAction;

            //  Automation uses this to find the editor to automate it
            _mshtmlEditor.Name = "BorderControl";

            // subscribe to key events
            _mshtmlEditor.DocumentComplete += new EventHandler(_mshtmlEditor_DocumentComplete);
            _mshtmlEditor.DocumentEvents.GotFocus += htmlEditor_GotFocus;
            _mshtmlEditor.DocumentEvents.LostFocus += htmlEditor_LostFocus;
            _mshtmlEditor.DocumentEvents.KeyDown += new HtmlEventHandler(DocumentEvents_KeyDown);
            _mshtmlEditor.DocumentEvents.KeyUp += new HtmlEventHandler(DocumentEvents_KeyUp);
            _mshtmlEditor.DocumentEvents.KeyPress += new HtmlEventHandler(DocumentEvents_KeyPress);
            _mshtmlEditor.DocumentEvents.MouseDown += new HtmlEventHandler(DocumentEvents_MouseDown);
            _mshtmlEditor.DocumentEvents.MouseUp += new HtmlEventHandler(DocumentEvents_MouseUp);
            _mshtmlEditor.DocumentEvents.SelectionChanged += new EventHandler(DocumentEvents_SelectionChanged);
            _mshtmlEditor.DisplayChanged += new EventHandler(_mshtmlEditor_DisplayChanged);
            _mshtmlEditor.DocumentEvents.Click += new HtmlEventHandler(DocumentEvents_Click);
            _mshtmlEditor.CommandKey += new KeyEventHandler(_mshtmlEditor_CommandKey);
            _mshtmlEditor.DropTargetHandler = new MshtmlEditor.DropTargetUIHandler(_mshtmlEditor_GetDropTarget);
            _mshtmlEditor.BeforeShowContextMenu += new EventHandler(_mshtmlEditor_BeforeShowContextMenu);
            _mshtmlEditor.MshtmlControl.DLControlFlagsChanged += new EventHandler(_mshtmlControl_DLControlFlagsChanged);
            _mshtmlEditor.TranslateAccelerator += new HtmlEditDesignerEventHandler(_mshtmlEditor_TranslateAccelerator);

            InitDamageServices();

            // notify subclasses that the editor has been created
            OnEditorCreated();
        }
Ejemplo n.º 6
0
        void HtmlEditorControl_PostEditorEvent(object sender, MshtmlEditor.EditDesignerEventArgs args)
        {
            if (Editable && args.EventDispId == DISPID_HTMLELEMENTEVENTS2.ONKEYPRESS && SelectedMarkupRange.Positioned)
            {
                switch (args.EventObj.keyCode)
                {
                    case (int)Keys.Enter:
                        // WinLive 245925: Because we inline some CSS into the font tag (specifically, the font-size
                        // property), we need to make sure that when the user hits enter that the font-size persists
                        // onto the next line. MSHTML does not handle this for us.
                        MarkupRange currentSelection = SelectedMarkupRange.Clone();
                        currentSelection.Start.PushGravity(_POINTER_GRAVITY.POINTER_GRAVITY_Left);
                        currentSelection.End.PushGravity(_POINTER_GRAVITY.POINTER_GRAVITY_Right);

                        try
                        {
                            if (_fontSizeBeforeEnter != null)
                            {
                                using (IUndoUnit undoUnit = CreateInvisibleUndoUnit())
                                {
                                    // Apply the previous block's font size to this new block.
                                    var fontSizeTextStyle = new FontSizeTextStyle(_fontSizeBeforeEnter.Value);
                                    fontSizeTextStyle.Apply(MarkupServices, currentSelection, _mshtmlEditor.Commands);

                                    // Force MSHTML to re-select inside the font tag we just created.
                                    IHTMLElement fontElement = currentSelection.Start.SeekElementRight(_fontTagWithFontSizeFilter, currentSelection.End);
                                    if (fontElement != null)
                                    {
                                        MarkupServices.CreateMarkupRange(fontElement, false).ToTextRange().select();
                                    }
                                    else
                                    {
                                        Debug.Fail("Didn't find font tag to reselect!");
                                        OnSelectionChanged(EventArgs.Empty, _selection, false);
                                    }

                                    undoUnit.Commit();
                                }
                            }
                            else
                            {
                                OnSelectionChanged(EventArgs.Empty, _selection, false);
                            }
                        }
                        finally
                        {
                            _fontSizeBeforeEnter = null;
                        }
                        break;
                    case (int)Keys.Back:
                        // Bug 101165: MSHTML maintains internal state about font tag. After forcibly clearing the
                        // font backcolor, MSHTML will often insert an empty font tag on the next keystroke. This
                        // font tag can then mutate into <font size="+0">, which causes the font to be rendered
                        // incorrectly.
                        GetMshtmlCommand(IDM.BACKCOLOR).Execute(null);
                        _backColorWasReset = true;
                        break;
                    default:
                        if (_backColorWasReset)
                        {
                            using (IUndoUnit undoUnit = CreateInvisibleUndoUnit())
                            {
                                // Remove any empty font tags.
                                SelectedMarkupRange.RemoveElementsByTagId(_ELEMENT_TAG_ID.TAGID_FONT, true);
                                undoUnit.Commit();
                            }
                            _backColorWasReset = false;
                        }
                        break;
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        public virtual void Dispose()
        {
            _internetSecurityManager.ReleaseInnerSecurityManager();

            PostEditorEvent -= new MshtmlEditor.EditDesignerEventHandler(HtmlEditorControl_PostEditorEvent);
            HandleClear -= new HtmlEditorSelectionOperationEventHandler(TryMoveIntoNextTable);

            if (components != null)
            {
                components.Dispose();
            }

            // detach behaviors
            DetachBehaviors();

            // dispose drag and drop manager
            if (mshtmlEditorDragAndDropTarget != null)
            {
                mshtmlEditorDragAndDropTarget.Dispose();
                mshtmlEditorDragAndDropTarget = null;
            }

            if (_dataFormatHandlerFactory != null)
            {
                _dataFormatHandlerFactory.Dispose();
                _dataFormatHandlerFactory = null;
            }

            if (_damageServices != null)
                _damageServices.Dispose();

            // dispose link navigator
            if (linkNavigator != null)
                linkNavigator.Dispose();

            if (_mshtmlEditor != null)
            {
                _mshtmlEditor.DocumentComplete -= new EventHandler(_mshtmlEditor_DocumentComplete);
                _mshtmlEditor.DocumentEvents.GotFocus -= htmlEditor_GotFocus;
                _mshtmlEditor.DocumentEvents.LostFocus -= htmlEditor_LostFocus;
                _mshtmlEditor.DocumentEvents.KeyDown -= new HtmlEventHandler(DocumentEvents_KeyDown);
                _mshtmlEditor.DocumentEvents.KeyUp -= new HtmlEventHandler(DocumentEvents_KeyUp);
                _mshtmlEditor.DocumentEvents.KeyPress -= new HtmlEventHandler(DocumentEvents_KeyPress);
                _mshtmlEditor.DocumentEvents.MouseDown -= new HtmlEventHandler(DocumentEvents_MouseDown);
                _mshtmlEditor.DocumentEvents.MouseUp -= new HtmlEventHandler(DocumentEvents_MouseUp);
                _mshtmlEditor.DocumentEvents.SelectionChanged -= new EventHandler(DocumentEvents_SelectionChanged);
                _mshtmlEditor.DisplayChanged -= new EventHandler(_mshtmlEditor_DisplayChanged);
                _mshtmlEditor.DocumentEvents.Click -= new HtmlEventHandler(DocumentEvents_Click);
                _mshtmlEditor.CommandKey -= new KeyEventHandler(_mshtmlEditor_CommandKey);
                _mshtmlEditor.BeforeShowContextMenu -= new EventHandler(_mshtmlEditor_BeforeShowContextMenu);
                _mshtmlEditor.DropTargetHandler = null;
                _mshtmlEditor.PreHandleEvent -= new HtmlEditDesignerEventHandler(OnPreHandleEvent);
                _mshtmlEditor.MshtmlControl.DLControlFlagsChanged -= new EventHandler(_mshtmlControl_DLControlFlagsChanged);
                _mshtmlEditor.TranslateAccelerator -= new HtmlEditDesignerEventHandler(_mshtmlEditor_TranslateAccelerator);

                if (ShouldCacheEditor())
                {
                    _mshtmlEditor.Active = false;
                    _editorCache = new CachedEditorAndSecurityManager { Editor = _mshtmlEditor, SecurityManager = _internetSecurityManager };
                }
                else
                {
                    _mshtmlEditor.Dispose();
                    _mshtmlEditor = null;
                }
            }
        }
 void EditorContext_PostEventNotify(object sender, MshtmlEditor.EditDesignerEventArgs args)
 {
     if (Attached)
     {
         switch (args.EventDispId)
         {
             case 0:
                 // WinLive 233200: JA-JP: photoalbum is created with subject instead of album name when album name specified in email body contains Japanese only
                 // We don't get key press events with IME input for languages such as Japanese that employ IME composition
                 // (e.g. multiple keystrokes to generate a single character).
                 if (String.Compare("COMPOSITION", args.EventObj.type, StringComparison.OrdinalIgnoreCase) == 0)
                     PersistSelectedEditField();
                 break;
             case DISPID_HTMLELEMENTEVENTS2.ONKEYPRESS:
                 PersistSelectedEditField();
                 break;
             default:
                 break;
         }
     }
 }
 public HtmlEditorSelection(MshtmlEditor editor, IHTMLDocument2 document)
 {
     _document = document;
     _editor = editor;
     MarkupServices = _editor.MshtmlControl.MarkupServices;
 }