Bug 1343037 part 6. Simplify the setup around the editor state's GetSelectionRange function. r=ehsan
Really, there are only two cases we need to worry about. Either IsSelectionCached(), and then our SelectionProperties has the data we want, or not and then we have a non-null mSelCon which has the data we want. Since we are now using cached selection state a lot more (instead of initializing the editor whenever someone asks for selection state), we need to actually update it more correctly when .value is set. And since we now update the cached selection state for the case when .value has been set (to point to the end of the text), we need to change HTMLInputElement::HasCachedSelection to return false for that case. Otherwise we will always do eager editor init on value set. We handle that by not doing eager init if the cached selection is collapsed. The web platform test changes test the "update on .value set" behavior. They fail without this patch, pass with it. MozReview-Commit-ID: DDU8U4MGb23
This commit is contained in:
@@ -923,8 +923,11 @@ nsTextControlFrame::SetSelectionStart(int32_t aSelectionStart)
|
||||
|
||||
nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent());
|
||||
MOZ_ASSERT(txtCtrl, "Content not a text control element");
|
||||
rv = txtCtrl->GetSelectionRange(&selStart, &selEnd);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
ErrorResult controlResult;
|
||||
txtCtrl->GetSelectionRange(&selStart, &selEnd, controlResult);
|
||||
if (NS_WARN_IF(controlResult.Failed())) {
|
||||
return controlResult.StealNSResult();
|
||||
}
|
||||
|
||||
if (aSelectionStart > selEnd) {
|
||||
// Collapse to the new start point.
|
||||
@@ -946,8 +949,11 @@ nsTextControlFrame::SetSelectionEnd(int32_t aSelectionEnd)
|
||||
|
||||
nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent());
|
||||
MOZ_ASSERT(txtCtrl, "Content not a text control element");
|
||||
rv = txtCtrl->GetSelectionRange(&selStart, &selEnd);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
ErrorResult controlResult;
|
||||
txtCtrl->GetSelectionRange(&selStart, &selEnd, controlResult);
|
||||
if (NS_WARN_IF(controlResult.Failed())) {
|
||||
return controlResult.StealNSResult();
|
||||
}
|
||||
|
||||
if (aSelectionEnd < selStart) {
|
||||
// Collapse to the new end point.
|
||||
|
||||
Reference in New Issue
Block a user