public bool FilterAppliesRanged(int offset, int length) { MarkupRange adjustedRange = currentWordRange.Clone(); MarkupHelpers.AdjustMarkupRange(ref stagingTextRange, adjustedRange, offset, length); return(filter != null && filter(adjustedRange)); }
/// <summary> /// Expands a range to the safest outter tags that can be contained without encompassing /// text that is not currently in this range. /// </summary> /// <param name="range"></param> private void SelectOuter(MarkupRange range) { IHTMLElement parent = range.ParentElement(); MarkupRange editableRange = MarkupHelpers.GetEditableRange(parent, MarkupServices); if (editableRange == null) { return; } while (parent != null && range.MoveOutwardIfNoContent()) { parent = range.Start.CurrentScope; } if (range.Start.IsLeftOf(editableRange.Start)) { range.Start.MoveToPointer(editableRange.Start); } if (range.End.IsRightOf(editableRange.End)) { range.End.MoveToPointer(editableRange.End); } return; }
private void HighlightWordRange(MarkupRange word) { try { IHighlightSegmentRaw segment; IDisplayPointerRaw start; IDisplayPointerRaw end; _displayServices.CreateDisplayPointer(out start); _displayServices.CreateDisplayPointer(out end); DisplayServices.TraceMoveToMarkupPointer(start, word.Start); DisplayServices.TraceMoveToMarkupPointer(end, word.End); _highlightRenderingServices.AddSegment(start, end, HighlightWordStyle, out segment); _tracker.AddSegment(segment, MarkupHelpers.UseStagingTextRange(ref stagingTextRange, word, rng => rng.text), _markupServicesRaw); } catch (COMException ce) { if (ce.ErrorCode == unchecked ((int)0x800A025E)) { return; } throw; } }
private string GetHtmlText(out MarkupPointer blockBoundary) { MarkupRange blockRange = _blogPostHtmlEditorControl.SelectedMarkupRange.Clone(); MarkupRange textRange = blockRange.Clone(); IHTMLElement ele = blockRange.ParentElement(ElementFilters.IsBlockOrTableCellOrBodyElement); if (ele == null) { blockBoundary = null; return(String.Empty); } blockRange.MoveToElement(ele, false); blockBoundary = blockRange.Start; // Fix Bug 616152 - We want the start and end pointer to match so // we can look back from the start of the insertion point (not the end, // which would include the selection that is going to be overwritten) textRange.Collapse(true); // Fix bug WinLive 59172: Specific characters of mixed characters are broken in mail body after press the 'Enter' key // Caused by using MOVEUNIT_PREVCHAR to navigate into Unicode surrogate (32-bit) characters. We work around this by moving // only at word or block boundaries. string html = null; do { int startPos = textRange.Start.MarkupPosition; textRange.Start.MoveUnitBounded(_MOVEUNIT_ACTION.MOVEUNIT_PREVWORDBEGIN, blockBoundary); if (textRange.Start.MarkupPosition == startPos) { // PREVWORDBEGIN didn't actually move us, due to no word being available. // To avoid an infinite loop, just move the text range to include the whole // block and move on. textRange.Start.MoveToPointer(blockRange.Start); break; } if (textRange.Positioned && textRange.Start.IsLeftOfOrEqualTo(textRange.End)) { html = MarkupHelpers.GetRangeTextFast(textRange); } html = html ?? string.Empty; } while (html.Length < MinLookBack && textRange.Start.IsRightOf(blockRange.Start)); if (html == null && textRange.Positioned && textRange.Start.IsLeftOfOrEqualTo(textRange.End)) { html = MarkupHelpers.GetRangeTextFast(textRange); } return(html ?? string.Empty); }
private bool IsEditableSelection() { MarkupRange selectedRange = SelectedMarkupRange; if (MarkupHelpers.GetEditableRange(selectedRange.Start.CurrentScope, MarkupServices) != null) { if (selectedRange.IsEmpty() || MarkupHelpers.GetEditableRange(selectedRange.Start.CurrentScope, MarkupServices) != null) { return(true); } } return(false); }
public void FindAndCrawlForLinksInResponse(ResponseModel responseModel) { var linksFoundInMarkup = MarkupHelpers.GetValidUrlListFromMarkup(responseModel.Markup, ValidUrlParser, CheckImages); foreach (var url in linksFoundInMarkup) { if (VisitedUrlList.Contains(url)) { continue; } VisitedUrlList.Add(url); SendRequest(url, responseModel.RequestedUrl); } }
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); }
private IHTMLElement CreateNodeForCentering() { // Create markup services using the element's document that we are analyzing MshtmlMarkupServices MarkupServices = new MshtmlMarkupServices(_element.document as IMarkupServicesRaw); MarkupPointer end = MarkupServices.CreateMarkupPointer(); MarkupPointer start = MarkupServices.CreateMarkupPointer(); // Find the element that we will want to wrap. IHTMLElement elementToEncapsulate = _element; // If the elements parent is an A, we will also want to // wrap the A and not just the image inside if (_element.parentElement.tagName == "A") { elementToEncapsulate = _element.parentElement; } // Move the starting pointer to before the begining of the element we want to wrap start.MoveAdjacentToElement(elementToEncapsulate, _ELEMENT_ADJACENCY.ELEM_ADJ_BeforeBegin); // Find this elements parent IHTMLElement3 currentBlockScope = start.CurrentBlockScope() as IHTMLElement3; // If its parent is also the div that is around the post // we need to actually create a new div and just put it around the element // If it is splittable block, split it // e.g "<DIV>Blah<IMG/>Blah</DIV>" => "<DIV>Blah</DIV><DIV><IMG/></DIV><DIV>Blah</DIV>" if (!IsBodyElement(currentBlockScope)) { // We are in a block that can be split so split it at the begining and end MarkupHelpers.SplitBlockForInsertionOrBreakout(MarkupServices, null, start); end.MoveAdjacentToElement(elementToEncapsulate, _ELEMENT_ADJACENCY.ELEM_ADJ_AfterEnd); MarkupHelpers.SplitBlockForInsertionOrBreakout(MarkupServices, null, end); // Position start back to the beginning of our element start.MoveAdjacentToElement(elementToEncapsulate, _ELEMENT_ADJACENCY.ELEM_ADJ_BeforeBegin); } // Now we can wrap it in an P tag (centering node) end.MoveAdjacentToElement(elementToEncapsulate, _ELEMENT_ADJACENCY.ELEM_ADJ_AfterEnd); IHTMLElement centeringElement = MarkupServices.CreateElement(_ELEMENT_TAG_ID.TAGID_P, string.Empty); MarkupServices.InsertElement(centeringElement, start, end); return(centeringElement); }
public void CrawlForLinksInResponse(IResponseModel responseModel) { var linksFoundInMarkup = MarkupHelpers.GetValidUrlListFromMarkup(responseModel.Markup, ValidUrlParser, CheckImages); foreach (var url in linksFoundInMarkup) { lock (UrlList) { if (UrlList.Where(l => l.Address == url).Count() > 0) { continue; } UrlList.Add(new LinkModel(url)); } SendRequest(url, responseModel.RequestedUrl); } }
//iterates through a word range checking for spelling errors //return: whether the word range is finished (true) or not private bool ProcessWordRange(MshtmlWordRange wordRange) { if (wordRange.CurrentWordRange.Positioned) { //track where we will need to clear; MarkupPointer start = _markupServices.CreateMarkupPointer(); start.MoveToPointer(wordRange.CurrentWordRange.End); ArrayList highlightwords = new ArrayList(NUMBER_OF_WORDS_TO_CHECK); int i = 0; //to do....the word range is losing its place when it stays in the queue while (wordRange.HasNext() && i < NUMBER_OF_WORDS_TO_CHECK) { // advance to the next word wordRange.Next(); // check the spelling int offset, length; if (ProcessWord(wordRange, out offset, out length)) { MarkupRange highlightRange = wordRange.CurrentWordRange.Clone(); MarkupHelpers.AdjustMarkupRange(ref stagingTextRange, highlightRange, offset, length); //note: cannot just push the current word range here, as it moves before we get to the highlighting step highlightwords.Add(highlightRange); } i++; } MarkupPointer end = wordRange.CurrentWordRange.End; //got our words, clear the checked range and then add the misspellings ClearRange(start, end); foreach (MarkupRange word in highlightwords) { HighlightWordRange(word); } return(!wordRange.HasNext()); } else { return(true); } }
/// <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; } } }
private void SplitBlockForApplyingBlockStyles(MarkupPointer splitPoint, MarkupRange maximumBounds) { //find the split stop parent IHTMLElement splitStop = splitPoint.GetParentElement(new IHTMLElementFilter(IsSplitStopElement)); if (splitStop != null) { MarkupPointer stopLocation = _markupServices.CreateMarkupPointer(splitStop, _ELEMENT_ADJACENCY.ELEM_ADJ_AfterBegin); if (maximumBounds.InRange(stopLocation)) { stopLocation.MoveAdjacentToElement(splitStop, _ELEMENT_ADJACENCY.ELEM_ADJ_BeforeEnd); if (maximumBounds.InRange(stopLocation)) { maximumBounds = maximumBounds.Clone(); maximumBounds.MoveToElement(splitStop, false); } } } MarkupHelpers.SplitBlockForInsertionOrBreakout(_markupServices, maximumBounds, splitPoint); }
public void CrawlForLinksInResponse(IResponseModel responseModel) { var linksFoundInMarkup = MarkupHelpers.GetValidUrlListFromMarkup(responseModel.Markup, ValidUrlParser, _settings.CheckImages); lock (wordCounts) { AddWordsToCount(responseModel.Markup); ; } foreach (var url in linksFoundInMarkup) { lock (UrlList) { if (UrlList.Any(l => l.Address == url)) { continue; } UrlList.Add(new LinkModel(url, responseModel.RequestedUrl)); } } }
/// <summary> /// Advance to next word /// </summary> public void Next() { currentWordRange.End.MoveToPointer(currentVirtualPosition); do { //advance the start pointer to the beginning of next word if (!currentWordRange.End.IsEqualTo(selectionRange.Start)) //avoids skipping over the first word { //fix bug 1848 - move the start to the end pointer before advancing to the next word //this ensures that the "next begin" is after the current selection. currentWordRange.Start.MoveToPointer(currentWordRange.End); currentWordRange.Start.MoveUnit(_MOVEUNIT_ACTION.MOVEUNIT_PREVWORDBEGIN); currentWordRange.Start.MoveUnit(_MOVEUNIT_ACTION.MOVEUNIT_NEXTWORDBEGIN); } else { //Special case for putting the start pointer at the beginning of the //correct word when the selection may or may not be already adjacent //to the the beginning of the word. //Note: theoretically, the selection adjustment in the constructor //guarantees that we will be flush against the first word, so we could //probably do nothing, but it works, so we'll keep it. currentWordRange.Start.MoveUnit(_MOVEUNIT_ACTION.MOVEUNIT_NEXTWORDEND); currentWordRange.Start.MoveUnit(_MOVEUNIT_ACTION.MOVEUNIT_PREVWORDBEGIN); } //advance the end pointer to the end of next word currentWordRange.End.MoveUnit(_MOVEUNIT_ACTION.MOVEUNIT_NEXTWORDEND); if (currentWordRange.Start.IsRightOf(currentWordRange.End)) { //Note: this was a condition that caused several bugs that caused us to stop //spell-checking correctly, so this logic is here in case we still have edge //cases that trigger it. //This should not occur anymore since we fixed several causes of this //condition by setting the currentWordRange gravity, and detecting case where //the selection may or may-not start at the beginning of a word. Debug.Fail("word start jumped past word end"); //if this occurred, it was probably because start was already at the beginning //of the correct word before it was moved. To resolve this situation, we //move the start pointer back to the beginning of the word that the end pointer //is at. Since the End pointer always advances on each iteration, this should not //cause an infinite loop. The worst case scenario is that we check the same word //more than once. currentWordRange.Start.MoveToPointer(currentWordRange.End); currentWordRange.Start.MoveUnit(_MOVEUNIT_ACTION.MOVEUNIT_PREVWORDBEGIN); } } while(MarkupHelpers.GetRangeTextFast(currentWordRange) == null && currentWordRange.End.IsLeftOf(selectionRange.End)); currentVirtualPosition.MoveToPointer(currentWordRange.End); if (currentWordRange.End.IsRightOf(selectionRange.End)) { //then collapse the range so that CurrentWord returns Empty; currentWordRange.Start.MoveToPointer(currentWordRange.End); } else { MarkupRange testRange = currentWordRange.Clone(); testRange.Collapse(false); testRange.End.MoveUnitBounded(_MOVEUNIT_ACTION.MOVEUNIT_NEXTCHAR, selectionRange.End); if (MarkupHelpers.GetRangeHtmlFast(testRange) == ".") { currentWordRange.End.MoveToPointer(testRange.End); } } }