Bug 1680548 - Cache the max length in TextControlState::SelectionProperties r=masayuki

GetValue() is not a cheap operation, and this allows to skip it in SetSelectionRange.

Differential Revision: https://phabricator.services.mozilla.com/D98659
This commit is contained in:
Kagami Sascha Rosylight
2020-12-05 09:34:59 +00:00
parent 1ddd56ea7e
commit f8cb249c67
3 changed files with 41 additions and 24 deletions

View File

@@ -2069,17 +2069,6 @@ void TextControlState::SetSelectionRange(
bool changed = false;
nsresult rv = NS_OK; // For the ScrollSelectionIntoView() return value.
if (IsSelectionCached()) {
nsAutoString value;
// XXXbz is "false" the right thing to pass here? Hard to tell, given the
// various mismatches between our impl and the spec.
GetValue(value, false);
uint32_t length = value.Length();
if (aStart > length) {
aStart = length;
}
if (aEnd > length) {
aEnd = length;
}
SelectionProperties& props = GetSelectionProperties();
changed = props.GetStart() != aStart || props.GetEnd() != aEnd ||
props.GetDirection() != aDirection;
@@ -2402,6 +2391,7 @@ void TextControlState::UnbindFromFrame(nsTextControlFrame* aFrame) {
GetSelectionDirection(IgnoreErrors());
SelectionProperties& props = GetSelectionProperties();
props.SetMaxLength(value.Length());
props.SetStart(start);
props.SetEnd(end);
props.SetDirection(direction);
@@ -2902,6 +2892,7 @@ bool TextControlState::SetValueWithoutTextEditor(
aHandlingSetValue.GetSetValueFlags()));
SelectionProperties& props = GetSelectionProperties();
props.SetMaxLength(aHandlingSetValue.GetSettingValue().Length());
if (aHandlingSetValue.GetSetValueFlags() &
eSetValue_MoveCursorToEndIfValueChanged) {
props.SetStart(aHandlingSetValue.GetSettingValue().Length());
@@ -2912,13 +2903,6 @@ bool TextControlState::SetValueWithoutTextEditor(
props.SetStart(0);
props.SetEnd(0);
props.SetDirection(nsITextControlFrame::eForward);
} else {
// Make sure our cached selection position is not outside the new
// value.
props.SetStart(std::min(
props.GetStart(), aHandlingSetValue.GetSettingValue().Length()));
props.SetEnd(std::min(props.GetEnd(),
aHandlingSetValue.GetSettingValue().Length()));
}
}