/// <summary> /// Fixes up all the headers in the entire markupRange. /// </summary> /// <param name="turnBold">Whether or not the text should be turning bold.</param> private void FixupHeaders(bool turnBold) { IHTMLElement elementStartHeader = markupRange.Start.GetParentElement(ElementFilters.HEADER_ELEMENTS); IHTMLElement elementEndHeader = markupRange.End.GetParentElement(ElementFilters.HEADER_ELEMENTS); MarkupRange currentRange = markupRange.Clone(); if (elementStartHeader != null) { // Takes care of the following cases: // <h1>...|blah|...</h1> // <h1>...|blah...</h1>...|... MarkupRange startRange = markupServices.CreateMarkupRange(elementStartHeader, false); startRange.Start.MoveToPointer(markupRange.Start); if (startRange.End.IsRightOf(markupRange.End)) { startRange.End.MoveToPointer(markupRange.End); } FixupHeaderRange(startRange, turnBold); currentRange.Start.MoveAdjacentToElement(elementStartHeader, _ELEMENT_ADJACENCY.ELEM_ADJ_AfterEnd); if (currentRange.End.IsLeftOf(currentRange.Start)) { currentRange.End.MoveToPointer(currentRange.Start); } } if (elementEndHeader != null && !HTMLElementHelper.ElementsAreEqual(elementStartHeader, elementEndHeader)) { // Takes care of the following case: // ...|...<h1>...blah|...</h1> MarkupRange endRange = markupServices.CreateMarkupRange(elementEndHeader, false); endRange.End.MoveToPointer(markupRange.End); FixupHeaderRange(endRange, turnBold); currentRange.End.MoveAdjacentToElement(elementEndHeader, _ELEMENT_ADJACENCY.ELEM_ADJ_BeforeBegin); if (currentRange.Start.IsRightOf(currentRange.End)) { currentRange.Start.MoveToPointer(currentRange.End); } } if (!markupRange.InRange(currentRange)) { return; } IHTMLElement[] headerElements = currentRange.GetElements(ElementFilters.HEADER_ELEMENTS, true); if (headerElements != null && headerElements.Length > 0) { foreach (IHTMLElement element in headerElements) { MarkupRange headerRange = markupServices.CreateMarkupRange(element, false); FixupHeaderRange(headerRange, turnBold); } } }
public TableCellEditingElementBehavior GetCellBehavior(IHTMLElement cellElement) { foreach (TableCellEditingElementBehavior cellBehavior in _cellElementBehaviors) { if (cellBehavior.Attached && HTMLElementHelper.ElementsAreEqual(cellElement, cellBehavior.HTMLElement)) { return(cellBehavior); } } // didn't find the behavior return(null); }
/// <summary> /// Wraps the range from startPointer to endPointer with the given element (as long as the range is non-empty) /// and then moves the pointers past the inserted element. /// </summary> /// <param name="element">The element to wrap the range in.</param> /// <param name="markupServices">The MarkupServices for the start and end pointers.</param> /// <param name="startPointer">Pointer to place the beginning of the element.</param> /// <param name="endPointer">Pointer to place the end of the element.</param> private void InsertElement(IHTMLElement element, MshtmlMarkupServices markupServices, MarkupPointer startPointer, MarkupPointer endPointer) { Debug.Assert(startPointer.IsLeftOfOrEqualTo(endPointer), "Expected start to be left of or equal to end!"); Debug.Assert(HTMLElementHelper.ElementsAreEqual(startPointer.CurrentScope, endPointer.CurrentScope), "Expected start and end to be in the same scope, otherwise resulting HTML will be invalid!"); if (startPointer.IsLeftOf(endPointer)) { markupServices.InsertElement(element, startPointer, endPointer); } endPointer.Right(true); startPointer.MoveToPointer(endPointer); }
private IHTMLElement GetTargetCell(Point clientPoint) { // maximum amount of scanning buffer is based on cell spacing int maxScanningRange = Math.Max(TableHelper.GetAttributeAsInteger(_table.cellSpacing), 2); // copy client point so we can modify the x-coordinate while scanning Point targetPoint = new Point(clientPoint.X, clientPoint.Y); // if we go past the end of the table allow the cell closest to the cursor // to become the target cell (necessary for sizing the table larger) Point xTargetPoint = new Point(targetPoint.X, targetPoint.Y); IHTMLTableCell targetCell = null; while (targetCell == null && xTargetPoint.X >= (targetPoint.X - maxScanningRange)) // 0 ) { // determine the cell we are over targetCell = _editorContext.ElementFromClientPoint(xTargetPoint) as IHTMLTableCell; // screen cells that don't belong to us if (!HTMLElementHelper.ElementsAreEqual(_table as IHTMLElement, TableHelper.GetContainingTableElement(targetCell as IHTMLElement) as IHTMLElement)) { targetCell = null; } xTargetPoint.X--; } // if we got a target cell then ensure that the point is over the document area if (targetCell != null) { if (_editorContext.PointIsOverDocumentArea(clientPoint)) { return(targetCell as IHTMLElement); } else { return(null); } } else { return(null); } }
public TableSelection(MarkupRange markupRange) { // calculate the begin and end cells IHTMLTableCell beginCell; IHTMLTableCell endCell; ArrayList selectedCells; FindCellRange(markupRange, out selectedCells, out beginCell, out endCell); // see if the two cells have a single containing table IHTMLTable table = GetSelectedTable(beginCell, endCell, markupRange) as IHTMLTable; // if we have a table then calculate the rest of our states if (table != null) { // validate the table selection if (ValidateTableSelection(table, markupRange, out _entireTableSelected)) { _table = table; _beginCell = beginCell; _endCell = endCell; // filter selected cells to only include direct descendents of this table (no // cells from nested tables) _selectedCells = new ArrayList(); foreach (IHTMLElement cell in selectedCells) { if (HTMLElementHelper.ElementsAreEqual(TableHelper.GetContainingTableElement(cell) as IHTMLElement, _table as IHTMLElement)) { _selectedCells.Add(cell); } } _hasContiguousSelection = !HTMLElementHelper.ElementsAreEqual(_beginCell as IHTMLElement, _endCell as IHTMLElement); _beginRow = GetContainingRowForCell(beginCell); _endRow = GetContainingRowForCell(endCell); _beginColumn = new HTMLTableColumn(_table, beginCell); _endColumn = new HTMLTableColumn(_table, endCell); } } }
protected override bool QueryElementSelected() { if (_tableIsEditable) { TableSelection tableSelection = new TableSelection(EditorContext.Selection.SelectedMarkupRange); if ((tableSelection.Table != null) && HTMLElementHelper.ElementsAreEqual(HTMLElement, tableSelection.Table as IHTMLElement)) { _currentTableSelection = tableSelection; return(true); } else { _currentTableSelection = null; return(false); } } else { return(false); } }
private IHTMLElement GetSelectedTable(IHTMLTableCell beginCell, IHTMLTableCell endCell, MarkupRange selectionMarkupRange) { // screen null cases if (beginCell == null || endCell == null) { return(null); } // get containing tables IHTMLTable beginTable = TableHelper.GetContainingTableElement(beginCell as IHTMLElement); IHTMLTable endTable = TableHelper.GetContainingTableElement(endCell as IHTMLElement); // see if they are from the same table if (HTMLElementHelper.ElementsAreEqual(beginTable as IHTMLElement, endTable as IHTMLElement)) { return(beginTable as IHTMLElement); } else { return(null); } }
private void PasteCellsIntoTable(IHTMLTable sourceTable, TableSelection tableSelection) { // collect up the top level cells we are pasting ArrayList cellsToPaste = new ArrayList(); foreach (IHTMLTableRow row in sourceTable.rows) { foreach (IHTMLElement cell in row.cells) { cellsToPaste.Add(cell); } } // get the list of cells we are pasting into int appendRows = 0; int cellsPerRow = 0; ArrayList targetCells; if (tableSelection.SelectedCells.Count > 1) { targetCells = tableSelection.SelectedCells; } else { targetCells = new ArrayList(); bool accumulatingCells = false; foreach (IHTMLTableRow row in tableSelection.Table.rows) { cellsPerRow = row.cells.length; foreach (IHTMLElement cell in row.cells) { if (!accumulatingCells && HTMLElementHelper.ElementsAreEqual(cell, tableSelection.BeginCell as IHTMLElement)) { accumulatingCells = true; } if (accumulatingCells) { targetCells.Add(cell); } } } // if the target cells aren't enough to paste all of the cells, then // calculate the number of rows we need to append to fit all of the // cells being pasted int cellGap = cellsToPaste.Count - targetCells.Count; if (cellGap > 0 && cellsPerRow > 0) { appendRows = cellGap / cellsPerRow + (cellGap % cellsPerRow == 0 ? 0 : 1); } } // perform the paste using (IUndoUnit undoUnit = EditorContext.CreateUndoUnit()) { // append rows if needed if (appendRows > 0) { // see if we can cast our editor context to the one required // by the table editor IHtmlEditorComponentContext editorContext = EditorContext as IHtmlEditorComponentContext; if (editorContext != null) { // markup range based on last target cell IHTMLElement lastCell = targetCells[targetCells.Count - 1] as IHTMLElement; MarkupRange lastCellRange = EditorContext.MarkupServices.CreateMarkupRange(lastCell); for (int i = 0; i < appendRows; i++) { IHTMLTableRow row = TableEditor.InsertRowBelow(editorContext, lastCellRange); foreach (IHTMLElement cell in row.cells) { targetCells.Add(cell); } lastCellRange = EditorContext.MarkupServices.CreateMarkupRange(row as IHTMLElement); } } else { Debug.Fail("Couldn't cast EditorContext!"); } } // do the paste for (int i = 0; i < cellsToPaste.Count && i < targetCells.Count; i++) { (targetCells[i] as IHTMLElement).innerHTML = (cellsToPaste[i] as IHTMLElement).innerHTML; } undoUnit.Commit(); } }
public bool Filter(IHTMLElement e) { return(HTMLElementHelper.ElementsAreEqual(e, _element)); }