private void EditorContext_KeyDown(object o, HtmlEventArgs e)
 {
     if (Attached && e.htmlEvt.keyCode == (int)Keys.Enter)
     {
         HandleEnterKey(e);
     }
 }
        protected override void OnKeyDown(object o, HtmlEventArgs e)
        {
            // this is orthoganal to keyboard processing (never cancels) so want to make
            // sure that we always do it if requested)
            if (HtmlEditorSettings.AggressivelyInvalidate)
                Invalidate();

            if (e.htmlEvt.altKey)
            {
                Keys keys = (Keys)e.htmlEvt.keyCode;
                //alt+Left/Right is the control navigation shortcut
                if (keys == Keys.Right || keys == Keys.Left)
                {
                    bool forward = keys == Keys.Right;
                    SelectNextControlElement(forward);
                    e.htmlEvt.cancelBubble = true;
                    return;
                }
            }

            base.OnKeyDown(o, e);

            if (e.WasCancelled)
                return;
        }
        private void _editorControl_KeyDown(object o, OpenLiveWriter.Mshtml.HtmlEventArgs e)
        {
            switch ((Keys)e.htmlEvt.keyCode)
            {
            case Keys.Back:
                //Bug fix: The backspace key triggers an extra selection change event that causes word damage to be
                //inappropriately committed, so we use a flag to suppress the selection change event for
                //this case.
                suppressSelectionChangeForDelete = true;
                break;
            }

            wordRangeDamager.OnKeyDown(e);
            _commitStrategy.OnKeyDown(e);
        }
        private void HandleEnterKey(HtmlEventArgs e)
        {
            //pressing the enter key on an empty line is used as a gesture for exiting the blockquote
            //If this situation is encountered, move the current empty block element outside of the blockquote
            MarkupRange selection = EditorContext.Selection.SelectedMarkupRange;
            if (selection.IsEmpty())
            {
                MarkupPointer selectionPoint = EditorContext.MarkupServices.CreateMarkupPointer(selection.Start);
                selectionPoint.Cling = true;

                IHTMLElement currBlock = selection.Start.CurrentBlockScope();
                MarkupRange currBlockRange = EditorContext.MarkupServices.CreateMarkupRange(currBlock, false);
                if (currBlockRange.IsEmptyOfContent())
                {
                    currBlockRange.MoveToElement(currBlock, true);

                    // Make sure there is no content between the end of this block range and the end of the blockquote.
                    MarkupPointer afterEndCurrBlock = EditorContext.MarkupServices.CreateMarkupPointer(currBlock, _ELEMENT_ADJACENCY.ELEM_ADJ_AfterEnd);
                    MarkupPointer beforeEndBlockQuote = EditorContext.MarkupServices.CreateMarkupPointer(HTMLElement, _ELEMENT_ADJACENCY.ELEM_ADJ_BeforeEnd);
                    MarkupRange restOfBlockQuote = EditorContext.MarkupServices.CreateMarkupRange(afterEndCurrBlock, beforeEndBlockQuote);
                    if (!restOfBlockQuote.IsEmpty() || !restOfBlockQuote.IsEmptyOfContent())
                        return;

                    //create a pointer for the new location that the block element will be moved to.
                    MarkupPointer insertionPoint =
                        EditorContext.MarkupServices.CreateMarkupPointer(HTMLElement, _ELEMENT_ADJACENCY.ELEM_ADJ_AfterEnd);

                    //move the current empty block to the DOM location after the blockquote
                    EditorContext.MarkupServices.Move(currBlockRange.Start, currBlockRange.End, insertionPoint);
                    currBlockRange.MoveToElement(currBlock, false);

                    //adjust the selection to the new location of the block element.
                    currBlockRange.Start.MoveToPointer(selectionPoint);
                    currBlockRange.End.MoveToPointer(selectionPoint);
                    currBlockRange.ToTextRange().select();

                    //cancel the key down event so that the editor doesn't try to handle it
                    e.Cancel();
                }
            }
        }
        public void OnKeyDown(HtmlEventArgs e)
        {
            switch ((Keys)e.htmlEvt.keyCode)
            {
                case Keys.Back:
                    //Trace.WriteLine("KeyDown: " + ((Keys)e.htmlEvt.keyCode).ToString());
                    ExpandDamageToPreviousWord(_currentSelectionDamage);
                    OnDamage();
                    break;
            }

            if (CharIsWordSeparator(Convert.ToChar(e.htmlEvt.keyCode)))
                ExpandDamageToAdjacentWords(_currentSelectionDamage);
        }
        public override void OnKeyPress(HtmlEventArgs e)
        {
            char ch = (char)e.htmlEvt.keyCode;
            if (!Char.IsLetterOrDigit(ch))
            {
                // Do not commit if we're backing in a correct region
                if ((Keys)e.htmlEvt.keyCode == Keys.Back && !_editor.IsSelectionMisspelled())
                    return;

                OnCommitDamage(EventArgs.Empty);
            }
        }
 public abstract void OnKeyPress(HtmlEventArgs e);
        private void DocumentEvents_KeyPress(object o, HtmlEventArgs e)
        {

            wordRangeDamager.OnKeyPress(e);
            _commitStrategy.OnKeyPress(e);

        }
        protected virtual void OnKeyPress(HtmlEventArgs evt)
        {
            if (KeyPress != null)
            {
                foreach (HtmlEventHandler handler in KeyPress.GetInvocationList())
                {
                    handler(this, evt);

                    if (evt.WasCancelled)
                        break;
                }
            }
        }
 protected abstract void HandleBackspaceKey(HtmlEventArgs e);
        protected override void HandleTabKey(HtmlEventArgs e)
        {
            // don't handle ctrl or alt key combos
            if (e.htmlEvt.ctrlKey || e.htmlEvt.altKey)
                return;

            if (GlobalEditorOptions.SupportsFeature(ContentEditorFeature.TabAsIndent))
            {
                if (!e.htmlEvt.shiftKey)
                    _keyBoardHandler.MaybeHandleInsert('\t', () => InsertHtml("    ", true));
            }
            else
            {
                IHtmlEditorCommandSource commandSource = this;
                if (e.htmlEvt.shiftKey)
                {
                    if (commandSource.CanOutdent)
                        commandSource.ApplyOutdent();
                }
                else
                {
                    if (commandSource.CanIndent)
                        commandSource.ApplyIndent();
                }
            }

            e.Cancel();
        }
        protected override void HandleKeyboardNavigationKey(HtmlEventArgs e)
        {
            MarkupRange selection = Selection.SelectedMarkupRange;
            if (!selection.IsEmpty())
            {
                // WinLive 196413: MSHTML seems to have a weird issue where if you have two hyperlinked images that
                // break onto two separate lines and you select the bottom image and hit the left arrow key, then
                // you'll end up between the anchor and the image (e.g. <a><img /></a><a>[caret]<img /></a>).
                // However, if you select the top image and hit the right arrow key, then you'll end up in the right
                // place -- in between the two anchors (e.g. <a><img /></a>[caret]<a><img></a>.
                if (e.htmlEvt.keyCode == (int)Keys.Left)
                {
                    // If an image is currently selected.
                    IHTMLElement imgElement = (IHTMLElement)Selection.SelectedImage;
                    if (imgElement == null)
                        return;

                    // And it's parent is an anchor.
                    IHTMLElement imgParentElement = imgElement.parentElement;
                    if (!(imgParentElement is IHTMLAnchorElement))
                        return;

                    // And there is no other HTML besides the anchor and the image.
                    IHTMLElementCollection anchorChildren = (IHTMLElementCollection)imgParentElement.children;
                    if (anchorChildren.length > 1 || !String.IsNullOrEmpty(imgParentElement.innerText))
                        return;

                    // Move the caret outside the hyperlink.
                    selection.Start.MoveAdjacentToElement(imgParentElement, _ELEMENT_ADJACENCY.ELEM_ADJ_BeforeBegin);
                    selection.Collapse(true);
                    selection.ToTextRange().select();
                    e.Cancel();
                }

                return;
            }
        }
        protected override void HandleBackspaceKey(HtmlEventArgs e)
        {
            // This is a fix for an issue where hitting the backspace key deletes just an anchor tag around an image,
            // but does not delete the image as well. The repro for this issue is to insert an image in Writer (which
            // by default adds an anchor around the image), click on the empty space to the right of the image (or hit
            // End) and then hit backspace.
            if (SelectedMarkupRange != null && SelectedMarkupRange.IsEmpty())
            {
                MarkupContext context = SelectedMarkupRange.Start.Left(false);

                // If we're backspacing over an anchor element.
                if (context.Element == null ||
                    context.Context != _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_EnterScope ||
                    !(context.Element is IHTMLAnchorElement))
                {
                    return;
                }

                // And the anchor contains just a single child element.
                IHTMLElementCollection anchorChildren = (IHTMLElementCollection)context.Element.children;
                if (anchorChildren.length > 1 || !String.IsNullOrEmpty(context.Element.innerText))
                {
                    return;
                }

                // And that single child element is an image.
                IHTMLElementCollection childImgs = (IHTMLElementCollection)anchorChildren.tags("img");
                if (childImgs != null && childImgs.length == 1)
                {
                    using (IUndoUnit undoUnit = CreateUndoUnit())
                    {
                        HTMLElementHelper.RemoveElement(context.Element);
                        e.Cancel();

                        undoUnit.Commit();
                    }
                }

                return;
            }
        }
 public override void OnKeyPress(HtmlEventArgs e)
 {
     CurrentCommitStrategy.OnKeyPress(e);
     char ch = (char)e.htmlEvt.keyCode;
     if (CurrentCommitStrategy == _realtimeCommitStrategy)
     {
         if (!Char.IsLetterOrDigit(ch) || !ShouldUseRealtimeDamageCommitStrategy())
         {
             //the caret position moved onto a new word, so revoke realtime spelling strategy
             CurrentCommitStrategy = _wordBasedCommitStrategy;
         }
     }
 }
 public override void OnKeyDown(HtmlEventArgs e)
 {
     CurrentCommitStrategy.OnKeyDown(e);
 }
 protected abstract void HandleKeyboardNavigationKey(HtmlEventArgs e);
 private void EditorContext_KeyUp(object o, HtmlEventArgs e)
 {
     if (Selected)
     {
         OnKeyUp(o, e);
     }
 }
        private void DocumentEvents_MouseUp(object o, HtmlEventArgs e)
        {
            OnMouseUp(e);

            if (e.WasCancelled)
                return;

            // global processing for Mouse Up (none for the time being )
        }
        protected virtual void OnKeyUp(object o, HtmlEventArgs e)
        {

        }
        protected virtual void OnMouseUp(HtmlEventArgs evt)
        {
            if (MouseUp != null)
            {
                foreach (HtmlEventHandler handler in MouseUp.GetInvocationList())
                {
                    handler(this, evt);

                    if (evt.WasCancelled)
                        break;
                }
            }
        }
        private void EditorContext_KeyDown(object o, HtmlEventArgs e)
        {
            if (Selected)
            {
                // Enter key
                if ((e.htmlEvt.keyCode == (int)Keys.Enter) &&
                    !e.htmlEvt.shiftKey && !e.htmlEvt.ctrlKey && !e.htmlEvt.altKey)
                {

                    // insert a linebreak if we are not parented by a block element
                    IHTMLElement blockScope = EditorContext.Selection.SelectedMarkupRange.Start.GetParentElement(ElementFilters.BLOCK_OR_TABLE_CELL_ELEMENTS);
                    if (blockScope is IHTMLTableCell)
                    {
                        LastChanceKeyboardHook.OnBeforeKeyHandled(this, GetKeyEventArgs(e.htmlEvt));
                        TableEditor.InsertLineBreak(EditorContext);
                        e.Cancel();
                    }
                }

                // tab key
                if ((e.htmlEvt.keyCode == (int)Keys.Tab) &&
                    !e.htmlEvt.ctrlKey && !e.htmlEvt.altKey)
                {
                    // only hijack tab and shift-tab if we are not in a list
                    IHTMLElement listItemScope = EditorContext.Selection.SelectedMarkupRange.Start.GetParentElement(ElementFilters.LIST_ITEM_ELEMENTS);
                    if (listItemScope == null)
                    {
                        if (e.htmlEvt.shiftKey)
                        {
                            LastChanceKeyboardHook.OnBeforeKeyHandled(this, GetKeyEventArgs(e.htmlEvt));
                            TableEditor.SelectPreviousCell(EditorContext);
                            e.Cancel();
                        }
                        else
                        {
                            LastChanceKeyboardHook.OnBeforeKeyHandled(this, GetKeyEventArgs(e.htmlEvt));
                            TableEditor.SelectNextCell(EditorContext);
                            e.Cancel();
                        }
                    }
                }
            }
        }
 public abstract void OnKeyDown(HtmlEventArgs e);
 private void EditorContext_DoubleClick(object sender, HtmlEventArgs e)
 {
     if (Selected)
         EditorContext.CommandManager.Execute(CommandId.ActivateContextualTab);
 }
 public override void OnKeyDown(HtmlEventArgs e)
 {
 }
 private void DocumentEvents_Click(object o, HtmlEventArgs e)
 {
     if (!e.htmlEvt.cancelBubble)
     {
         MoveSelectionToPoint(new Point(e.htmlEvt.screenX, e.htmlEvt.screenY));
     }
 }
 public override void OnKeyPress(HtmlEventArgs e)
 {
     OnCommitDamage(EventArgs.Empty);
 }
        void DocumentEvents_KeyPress(object o, HtmlEventArgs e)
        {
            OnKeyPress(e);

            if (e.WasCancelled)
                return;
        }
        public void OnKeyPress(HtmlEventArgs e)
        {
            OnDamage();

            if (CharIsWordSeparator(Convert.ToChar(e.htmlEvt.keyCode)))
                ExpandDamageToAdjacentWords(_currentSelectionDamage);
        }
        private void DocumentEvents_KeyDown(object o, HtmlEventArgs e)
        {
            OnKeyDown(e);

            // return if someone else cancelled processing
            if (e.WasCancelled)
                return;

            // global processing for special keys
            switch (e.htmlEvt.keyCode)
            {
                // tab key
                case (int)Keys.Tab:
                    HandleTabKey(e);
                    break;
                case (int)Keys.Left:
                case (int)Keys.Right:
                case (int)Keys.Up:
                case (int)Keys.Down:
                    HandleKeyboardNavigationKey(e);
                    break;
                case (int)Keys.Back:
                    HandleBackspaceKey(e);
                    break;
            }
        }
 protected override void OnKeyDown(HtmlEventArgs e)
 {
     base.OnKeyDown(e);
     if (((Keys)e.htmlEvt.keyCode) == Keys.Back)
     {
         using (IUndoUnit undo = EditorContext.CreateUndoUnit())
         {
             (HTMLElement as IHTMLDOMNode).removeNode(true);
             undo.Commit();
         }
         e.Cancel();
     }
 }
 protected abstract void HandleTabKey(HtmlEventArgs e);