Bug 1343037 part 12. Implement nsTextEditorState::SetSelectionStart. r=ehsan
This introduces three behavior changes:
1) Before this change, in cached mode, we did not enforce the "start <= end"
invariant.
2) Before this change, in cached mode, we did not fire "select" events on
selectionStart changes.
3) Changes the IDL type of HTMLInputElement's selectionStart attribute to
"unsigned long" to match the spec and HTMLTextareaElement.
MozReview-Commit-ID: JM9XXMMPUHM
This commit is contained in:
@@ -6422,22 +6422,22 @@ HTMLInputElement::SetRangeText(const nsAString& aReplacement, uint32_t aStart,
|
||||
SetSelectionRange(aSelectionStart, aSelectionEnd, direction, aRv);
|
||||
}
|
||||
|
||||
Nullable<int32_t>
|
||||
Nullable<uint32_t>
|
||||
HTMLInputElement::GetSelectionStart(ErrorResult& aRv)
|
||||
{
|
||||
if (!SupportsTextSelection()) {
|
||||
return Nullable<int32_t>();
|
||||
return Nullable<uint32_t>();
|
||||
}
|
||||
|
||||
int32_t selStart = GetSelectionStartIgnoringType(aRv);
|
||||
uint32_t selStart = GetSelectionStartIgnoringType(aRv);
|
||||
if (aRv.Failed()) {
|
||||
return Nullable<int32_t>();
|
||||
return Nullable<uint32_t>();
|
||||
}
|
||||
|
||||
return Nullable<int32_t>(selStart);
|
||||
return Nullable<uint32_t>(selStart);
|
||||
}
|
||||
|
||||
int32_t
|
||||
uint32_t
|
||||
HTMLInputElement::GetSelectionStartIgnoringType(ErrorResult& aRv)
|
||||
{
|
||||
int32_t selEnd, selStart;
|
||||
@@ -6446,7 +6446,7 @@ HTMLInputElement::GetSelectionStartIgnoringType(ErrorResult& aRv)
|
||||
}
|
||||
|
||||
void
|
||||
HTMLInputElement::SetSelectionStart(const Nullable<int32_t>& aSelectionStart,
|
||||
HTMLInputElement::SetSelectionStart(const Nullable<uint32_t>& aSelectionStart,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
if (!SupportsTextSelection()) {
|
||||
@@ -6454,35 +6454,9 @@ HTMLInputElement::SetSelectionStart(const Nullable<int32_t>& aSelectionStart,
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t selStart = 0;
|
||||
if (!aSelectionStart.IsNull()) {
|
||||
selStart = aSelectionStart.Value();
|
||||
}
|
||||
|
||||
nsTextEditorState* state = GetEditorState();
|
||||
if (state && state->IsSelectionCached()) {
|
||||
state->GetSelectionProperties().SetStart(selStart);
|
||||
return;
|
||||
}
|
||||
|
||||
nsAutoString direction;
|
||||
GetSelectionDirection(direction, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t start, end;
|
||||
GetSelectionRange(&start, &end, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
start = selStart;
|
||||
if (end < start) {
|
||||
end = start;
|
||||
}
|
||||
|
||||
aRv = SetSelectionRange(start, end, direction);
|
||||
MOZ_ASSERT(state, "SupportsTextSelection() returned true!");
|
||||
state->SetSelectionStart(aSelectionStart, aRv);
|
||||
}
|
||||
|
||||
Nullable<int32_t>
|
||||
|
||||
Reference in New Issue
Block a user