diff --git a/dom/base/Selection.cpp b/dom/base/Selection.cpp index 2bbc3ab60a21..473ae5cbbaed 100644 --- a/dom/base/Selection.cpp +++ b/dom/base/Selection.cpp @@ -410,6 +410,63 @@ void Selection::SetCaretBidiLevel(const Nullable& aCaretBidiLevel, } } +/** + * Test whether the supplied range points to a single table element. + * Result is one of the TableSelection constants. "None" means + * a table element isn't selected. + */ +// TODO: Figure out TableSelection::Column and TableSelection::AllCells +static nsresult GetTableSelectionType(nsRange* aRange, + TableSelection* aTableSelectionType) { + if (!aRange || !aTableSelectionType) { + return NS_ERROR_NULL_POINTER; + } + + *aTableSelectionType = TableSelection::None; + + nsINode* startNode = aRange->GetStartContainer(); + if (!startNode) { + return NS_ERROR_FAILURE; + } + + nsINode* endNode = aRange->GetEndContainer(); + if (!endNode) { + return NS_ERROR_FAILURE; + } + + // Not a single selected node + if (startNode != endNode) { + return NS_OK; + } + + nsIContent* child = aRange->GetChildAtStartOffset(); + + // Not a single selected node + if (!child || child->GetNextSibling() != aRange->GetChildAtEndOffset()) { + return NS_OK; + } + + nsIContent* startContent = static_cast(startNode); + if (!(startNode->IsElement() && startContent->IsHTMLElement())) { + // Implies a check for being an element; if we ever make this work + // for non-HTML, need to keep checking for elements. + return NS_OK; + } + + if (startContent->IsHTMLElement(nsGkAtoms::tr)) { + *aTableSelectionType = TableSelection::Cell; + } else // check to see if we are selecting a table or row (column and all + // cells not done yet) + { + if (child->IsHTMLElement(nsGkAtoms::table)) + *aTableSelectionType = TableSelection::Table; + else if (child->IsHTMLElement(nsGkAtoms::tr)) + *aTableSelectionType = TableSelection::Row; + } + + return NS_OK; +} + nsresult Selection::GetTableCellLocationFromRange( nsRange* aRange, TableSelection* aSelectionType, int32_t* aRow, int32_t* aCol) { @@ -493,53 +550,6 @@ nsresult Selection::MaybeAddTableCellRange(nsRange* aRange, bool* aDidAddRange, return AddRangesForSelectableNodes(aRange, aOutIndex); } -// TODO: Figure out TableSelection::Column and TableSelection::AllCells -nsresult Selection::GetTableSelectionType(nsRange* aRange, - TableSelection* aTableSelectionType) { - if (!aRange || !aTableSelectionType) return NS_ERROR_NULL_POINTER; - - *aTableSelectionType = TableSelection::None; - - // Must have access to frame selection to get cell info - if (!mFrameSelection) return NS_OK; - - nsINode* startNode = aRange->GetStartContainer(); - if (!startNode) return NS_ERROR_FAILURE; - - nsINode* endNode = aRange->GetEndContainer(); - if (!endNode) return NS_ERROR_FAILURE; - - // Not a single selected node - if (startNode != endNode) return NS_OK; - - nsIContent* child = aRange->GetChildAtStartOffset(); - - // Not a single selected node - if (!child || child->GetNextSibling() != aRange->GetChildAtEndOffset()) { - return NS_OK; - } - - nsIContent* startContent = static_cast(startNode); - if (!(startNode->IsElement() && startContent->IsHTMLElement())) { - // Implies a check for being an element; if we ever make this work - // for non-HTML, need to keep checking for elements. - return NS_OK; - } - - if (startContent->IsHTMLElement(nsGkAtoms::tr)) { - *aTableSelectionType = TableSelection::Cell; - } else // check to see if we are selecting a table or row (column and all - // cells not done yet) - { - if (child->IsHTMLElement(nsGkAtoms::table)) - *aTableSelectionType = TableSelection::Table; - else if (child->IsHTMLElement(nsGkAtoms::tr)) - *aTableSelectionType = TableSelection::Row; - } - - return NS_OK; -} - Selection::Selection() : mCachedOffsetForFrame(nullptr), mDirection(eDirNext), diff --git a/dom/base/Selection.h b/dom/base/Selection.h index e4db62acfc2b..4df8eb0866af 100644 --- a/dom/base/Selection.h +++ b/dom/base/Selection.h @@ -712,13 +712,6 @@ class Selection final : public nsSupportsWeakReference, */ void SelectFramesInAllRanges(nsPresContext* aPresContext); - /** - * Test whether the supplied range points to a single table element. - * Result is one of the TableSelection constants. "None" means - * a table element isn't selected. - */ - nsresult GetTableSelectionType(nsRange* aRange, - TableSelection* aTableSelectionType); MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult GetTableCellLocationFromRange(nsRange* aRange, TableSelection* aSelectionType,