/// <summary>
        /// Inserts the extended entry break into the editor.
        /// </summary>
        internal void InsertExtendedEntryBreak()
        {
            IHTMLDocument3 doc3       = (IHTMLDocument3)HTMLElement.document;
            IHTMLElement2  entryBreak = (IHTMLElement2)doc3.getElementById(EXTENDED_ENTRY_ID);

            if (entryBreak == null)
            {
                using (IUndoUnit undo = EditorContext.CreateUndoUnit())
                {
                    using (EditorContext.DamageServices.CreateDamageTracker(ElementRange.Clone(), true))
                    {
                        MarkupPointer insertionPoint =
                            EditorContext.MarkupServices.CreateMarkupPointer(EditorContext.Selection.SelectedMarkupRange.Start);

                        //delete the parent block element of the insertion point if it is empty (bug 421500)
                        DeleteInsertionTargetBlockIfEmpty(insertionPoint);

                        IHTMLElement extendedEntryBreak = InsertExtendedEntryBreak(insertionPoint);

                        //reselect the insertion point
                        MarkupRange selection = EditorContext.MarkupServices.CreateMarkupRange();
                        insertionPoint.MoveAdjacentToElement(extendedEntryBreak, _ELEMENT_ADJACENCY.ELEM_ADJ_AfterEnd);
                        MarkupPointerMoveHelper.MoveUnitBounded(
                            insertionPoint, MarkupPointerMoveHelper.MoveDirection.RIGHT,
                            MarkupPointerAdjacency.AfterEnterBlock | MarkupPointerAdjacency.BeforeText
                            , HTMLElement);
                        selection.Start.MoveToPointer(insertionPoint);
                        selection.End.MoveToPointer(insertionPoint);
                        selection.ToTextRange().select();
                    }
                    undo.Commit();
                }
            }
        }
Example #2
0
        public void ExecuteSelectionOperation(HtmlEditorSelectionOperation op)
        {
            //suspend selection change events while the real HTML selection is temporarily adjusted
            //to include the smart content element while the selection operation executes.
            _editorComponentContext.BeginSelectionChange();
            try
            {
                IHTMLDocument2 document       = (IHTMLDocument2)HTMLElement.document;
                MarkupRange    elementRange   = CreateElementClingMarkupRange();
                MarkupRange    insertionRange = CreateSelectionBoundaryMarkupRange();
                elementRange.ToTextRange().select();
                op(this);

                //reset the selection
                if (elementRange.Start.Positioned && elementRange.End.Positioned)
                {
                    document.selection.empty();
                    _editorComponentContext.Selection = this;
                }
                else
                {
                    insertionRange.ToTextRange().select();
                }
            }
            finally
            {
                _editorComponentContext.EndSelectionChange();
            }
        }
Example #3
0
        /// <summary>
        /// Select all of the text in the region.
        /// </summary>
        protected void SelectAll()
        {
            MarkupRange selectRange = ElementRange.Clone();

            selectRange.MoveToElement(HTMLElement, false);
            selectRange.ToTextRange().select();
        }
        protected virtual void Deselect()
        {
            MarkupRange range = EditorContext.MarkupServices.CreateMarkupRange(HTMLElement);

            range.Start.MoveAdjacentToElement(HTMLElement, _ELEMENT_ADJACENCY.ELEM_ADJ_BeforeBegin);
            range.Collapse(true);
            range.ToTextRange().select();
        }
Example #5
0
 /// <summary>
 /// Switches focus to the previous editable region.
 /// </summary>
 protected void SelectPreviousRegion()
 {
     if (_previousEditableRegion != null)
     {
         MarkupRange range = EditorContext.MarkupServices.CreateMarkupRange(_previousEditableRegion, false);
         range.End.MoveToPointer(range.Start);
         range.ToTextRange().select();
     }
 }
Example #6
0
        protected void SelectRange()
        {
            MarkupRange range = GetMarkupRange();

            if (range != null && range.Positioned)
            {
                range.ToTextRange().select();
            }
        }
Example #7
0
 /// <summary>
 /// Switches focus to the next editable region.
 /// </summary>
 protected void SelectNextRegion()
 {
     if (_nextEditableRegion != null)
     {
         MarkupRange range = EditorContext.MarkupServices.CreateMarkupRange(_nextEditableRegion, false);
         range.End.MoveToPointer(range.Start);
         range.ToTextRange().select();
     }
     //Note: this could work if we have to use Focus (which causes scroll) but there is a flicker
     //HTMLElement.scrollIntoView(false);
 }
Example #8
0
        private void SelectElement(IHTMLElement element)
        {
            PersistEditFieldValues();

            InlineEditField field = new InlineEditField(element, SmartContent, EditorContext, HTMLElement, this);

            field.ClearDefaultText();

            MarkupRange range = EditorContext.MarkupServices.CreateMarkupRange(element, false);

            range.ToTextRange().select();
        }
Example #9
0
 private void SelectEntireTable()
 {
     try
     {
         MarkupRange tableMarkupRange = EditorContext.MarkupServices.CreateMarkupRange(HTMLElement, true);
         tableMarkupRange.ToTextRange().select();
         DrawSelectionBorder = true;
     }
     catch (Exception ex)
     {
         Trace.Fail("Unexpected error attempting to select entire table: " + ex.ToString());
     }
 }
Example #10
0
        /// <summary>
        /// Notify the data format handler that data was dropped and should be inserted into
        /// the document at whatever insert location the handler has internally tracked.
        /// </summary>
        /// <param name="action"></param>
        public override bool DataDropped(DataAction action)
        {
            if (currentCaretLocation == null)
            {
                return(false);
            }

            // create two markup pointers that map to the location of the caret
            MarkupPointer begin = EditorContext.MarkupServices.CreateMarkupPointer();
            MarkupPointer end   = EditorContext.MarkupServices.CreateMarkupPointer();

            EditorContext.MarkupServices.MoveMarkupPointerToCaret(currentCaretLocation, begin);
            MarkupPointerMoveHelper.PerformImageBreakout(begin);

            //optimize the drop location to keep it from being in an unexpected location (fixes bug 395224)
            if (EditorContext.ShouldMoveDropLocationRight(begin))
            {
                begin.Right(true);
            }

            //synchronize the end pointer with the being pointer
            end.MoveToPointer(begin);

            MarkupRange selectedRange = EditorContext.SelectedMarkupRange;

            // WinLive 91888 Photomail image drag drop loses images
            //if (!selectedRange.IsEmpty() && selectedRange.InRange(end))
            if (!selectedRange.IsEmpty() && selectedRange.InRange(end, false))
            {
                //the drop location is over the drag source location, so don't so anything.
                return(false);
            }

            // Forces a SelectionChanged event so that the correct behaviors around the drop location are activated.
            // For example, one side effect of this call is that the OnEditableRegionFocusChanged event is fired, which
            // sets whether the current drop location in the canvas supports images, html and/or text.
            MarkupRange dropRange = EditorContext.MarkupServices.CreateMarkupRange(begin, end);

            dropRange.ToTextRange().select();

            try
            {
                // insert the data at the current insertion point
                return(InsertData(action, begin, end));
            }
            catch (Exception e)
            {
                Trace.Fail(e.Message, e.StackTrace);
                return(false);
            }
        }
Example #11
0
        private void ApplyBlockStyle(_ELEMENT_TAG_ID styleTagId, MarkupRange selection, MarkupRange maximumBounds, MarkupRange postOpSelection)
        {
            Debug.Assert(selection != maximumBounds, "selection and maximumBounds must be distinct objects");
            SelectionPositionPreservationCookie selectionPreservationCookie = null;

            //update the range cling and gravity so it will stick with the re-arranged block content
            selection.Start.PushCling(false);
            selection.Start.PushGravity(_POINTER_GRAVITY.POINTER_GRAVITY_Left);
            selection.End.PushCling(false);
            selection.End.PushGravity(_POINTER_GRAVITY.POINTER_GRAVITY_Right);

            try
            {
                if (selection.IsEmpty())
                {
                    //nothing is selected, so expand the selection to cover the entire parent block element
                    IHTMLElementFilter stopFilter =
                        ElementFilters.CreateCompoundElementFilter(ElementFilters.BLOCK_ELEMENTS,
                                                                   new IHTMLElementFilter(IsSplitStopElement));
                    MovePointerLeftUntilRegionBreak(selection.Start, stopFilter, maximumBounds.Start);
                    MovePointerRightUntilRegionBreak(selection.End, stopFilter, maximumBounds.End);
                }

                using (IUndoUnit undo = _editor.CreateSelectionUndoUnit(selection))
                {
                    selectionPreservationCookie = SelectionPositionPreservationHelper.Save(_markupServices, postOpSelection, selection);
                    if (selection.IsEmptyOfContent())
                    {
                        ApplyBlockFormatToEmptySelection(selection, styleTagId, maximumBounds);
                    }
                    else
                    {
                        ApplyBlockFormatToContentSelection(selection, styleTagId, maximumBounds);
                    }
                    undo.Commit();
                }
            }
            finally
            {
                selection.Start.PopCling();
                selection.Start.PopGravity();
                selection.End.PopCling();
                selection.End.PopGravity();
            }

            if (!SelectionPositionPreservationHelper.Restore(selectionPreservationCookie, selection, selection.Clone()))
            {
                selection.ToTextRange().select();
            }
        }
        private MarkupRange AdjustSelection()
        {
            MarkupRange selection = CreateMaxSafeRange(SelectedMarkupRange);

            if (selection.IsEmpty())
            {
                MarkupRange editableRange = MarkupHelpers.GetEditableRange(selection.Start.CurrentScope, MarkupServices);
                MarkupPointerMoveHelper.MoveUnitBounded(selection.Start,
                                                        MarkupPointerMoveHelper.MoveDirection.LEFT,
                                                        MarkupPointerAdjacency.BeforeVisible | MarkupPointerAdjacency.BeforeEnterScope,
                                                        editableRange.Start);
                selection.Collapse(true);
            }
            selection.ToTextRange().select();
            return(selection);
        }
Example #13
0
        internal bool Restore(MarkupRange selection, MarkupRange bounds)
        {
            if (initialMarkup == null)
            {
                return(false);
            }

            NormalizeBounds(ref bounds);

            /*
             *          if (initialMarkup != bounds.HtmlText)
             *          {
             *              Trace.Fail("Unexpected markup");
             *              Trace.WriteLine(initialMarkup);
             *              Trace.WriteLine(bounds.HtmlText);
             *              return false;
             *          }
             */

            selection.Start.MoveToPointer(bounds.Start);

            if (movesRight == int.MaxValue)
            {
                selection.Start.MoveToPointer(bounds.End);
            }
            else
            {
                for (int i = 0; i < movesRight; i++)
                {
                    selection.Start.Right(true);
                }
            }

            for (int i = 0; i < charsLeft; i++)
            {
                selection.Start.MoveUnit(_MOVEUNIT_ACTION.MOVEUNIT_PREVCHAR);
            }

            selection.Collapse(true);
            selection.ToTextRange().select();

            Debug.Assert(bounds.InRange(selection, true), "Selection was out of bounds");

            return(true);
        }
        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();
                }
            }
        }
Example #15
0
        /// <summary>
        /// Highlight the current word
        /// </summary>
        public void Highlight(int offset, int length)
        {
            // select word
            MarkupRange highlightRange = currentWordRange.Clone();

            MarkupHelpers.AdjustMarkupRange(highlightRange, offset, length);

            try
            {
                highlightRange.ToTextRange().select();
            }
            catch (COMException ce)
            {
                // Fix bug 772709: This error happens when we try to select un-selectable objects.
                if (ce.ErrorCode != unchecked ((int)0x800A025E))
                {
                    throw;
                }
            }
        }