author | Mirko Brodesser <mbrodesser@mozilla.com> |
Fri, 07 Feb 2020 09:24:34 +0000 | |
changeset 512859 | 5a1c680c8740e07ff1a252019512b2f551f3ef93 |
parent 512858 | 37865176d8d00b40c5ab0ecea4c244cd6a62c8ba |
child 512860 | 11d012aeef35ad362eb77dff4df0a14ce5bcf478 |
push id | 37100 |
push user | apavel@mozilla.com |
push date | Fri, 07 Feb 2020 21:53:54 +0000 |
treeherder | mozilla-central@882200a11bcf [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | smaug |
bugs | 1613378 |
milestone | 74.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
dom/base/Selection.cpp | file | annotate | diff | comparison | revisions | |
dom/base/Selection.h | file | annotate | diff | comparison | revisions |
--- a/dom/base/Selection.cpp +++ b/dom/base/Selection.cpp @@ -405,16 +405,73 @@ void Selection::SetCaretBidiLevel(const } if (aCaretBidiLevel.IsNull()) { mFrameSelection->UndefineCaretBidiLevel(); } else { mFrameSelection->SetCaretBidiLevel(aCaretBidiLevel.Value()); } } +/** + * 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<nsIContent*>(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) { if (!aRange || !aSelectionType || !aRow || !aCol) return NS_ERROR_NULL_POINTER; *aSelectionType = TableSelection::None; *aRow = 0; @@ -488,63 +545,16 @@ nsresult Selection::MaybeAddTableCellRan // getTableCellLocation) if (mFrameSelection->mSelectingTableCellMode == TableSelection::None) mFrameSelection->mSelectingTableCellMode = tableMode; *aDidAddRange = true; 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<nsIContent*>(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), mSelectionType(SelectionType::eNormal), mCustomColors(nullptr), mSelectionChangeBlockerCount(0), mUserInitiated(false), mCalledByJS(false),
--- a/dom/base/Selection.h +++ b/dom/base/Selection.h @@ -707,23 +707,16 @@ class Selection final : public nsSupport bool aSelect); /** * SelectFramesInAllRanges() calls SelectFrames() for all current * ranges. */ 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, int32_t* aRow, int32_t* aCol); /** * @param aOutIndex points to the index of the range in mRanges. If * aDidAddRange is true, it is in [0, mRanges.Length()).