diff --git a/layout/forms/nsTextControlFrame.cpp b/layout/forms/nsTextControlFrame.cpp index 2a480fb7079c..ce9da0765873 100644 --- a/layout/forms/nsTextControlFrame.cpp +++ b/layout/forms/nsTextControlFrame.cpp @@ -793,6 +793,25 @@ already_AddRefed nsTextControlFrame::GetTextEditor() { nsresult nsTextControlFrame::SetSelectionInternal( nsINode* aStartNode, uint32_t aStartOffset, nsINode* aEndNode, uint32_t aEndOffset, nsITextControlFrame::SelectionDirection aDirection) { + // Create a new range to represent the new selection. + // Note that we use a new range to avoid having to do + // isIncreasing checks to avoid possible errors. + + // Be careful to use internal nsRange methods which do not check to make sure + // we have access to the node. + // XXXbz nsRange::SetStartAndEnd takes int32_t (and ranges generally work on + // int32_t), but we're passing uint32_t. The good news is that at this point + // our endpoints should really be within our length, so not really that big. + // And if they _are_ that big, SetStartAndEnd() will simply error out, which + // is not too bad for a case we don't expect to happen. + ErrorResult error; + RefPtr range = + nsRange::Create(aStartNode, aStartOffset, aEndNode, aEndOffset, error); + if (NS_WARN_IF(error.Failed())) { + return error.StealNSResult(); + } + MOZ_ASSERT(range); + // Get the selection, clear it and add the new range to it! TextControlElement* textControlElement = TextControlElement::FromNode(GetContent()); @@ -812,10 +831,16 @@ nsresult nsTextControlFrame::SetSelectionInternal( direction = (aDirection == eBackward) ? eDirPrevious : eDirNext; } - ErrorResult error; - selection->SetStartAndEndInLimiter(*aStartNode, aStartOffset, *aEndNode, - aEndOffset, error); - MOZ_TRY(error.StealNSResult()); + selection->RemoveAllRanges(error); + if (NS_WARN_IF(error.Failed())) { + return error.StealNSResult(); + } + + selection->AddRangeAndSelectFramesAndNotifyListeners( + *range, error); // NOTE: can destroy the world + if (NS_WARN_IF(error.Failed())) { + return error.StealNSResult(); + } selection->SetDirection(direction); return NS_OK; diff --git a/testing/web-platform/tests/selection/textcontrols/selectionchange.tentative.html b/testing/web-platform/tests/selection/textcontrols/selectionchange.tentative.html deleted file mode 100644 index ebb5d2bfd4a4..000000000000 --- a/testing/web-platform/tests/selection/textcontrols/selectionchange.tentative.html +++ /dev/null @@ -1,149 +0,0 @@ - - -Test selectionchange events from text controls - - - - - -
- - -