Backed out changeset 651187869807 (bug 1680548) for causing valgrid bustages in nsTextControlFrame.

This commit is contained in:
Mihai Alexandru Michis
2020-12-05 03:15:59 +02:00
parent 7174b9cce5
commit fcd894ffe5
3 changed files with 21 additions and 36 deletions

View File

@@ -2069,6 +2069,17 @@ void TextControlState::SetSelectionRange(
bool changed = false; bool changed = false;
nsresult rv = NS_OK; // For the ScrollSelectionIntoView() return value. nsresult rv = NS_OK; // For the ScrollSelectionIntoView() return value.
if (IsSelectionCached()) { 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(); SelectionProperties& props = GetSelectionProperties();
changed = props.GetStart() != aStart || props.GetEnd() != aEnd || changed = props.GetStart() != aStart || props.GetEnd() != aEnd ||
props.GetDirection() != aDirection; props.GetDirection() != aDirection;
@@ -2882,7 +2893,6 @@ bool TextControlState::SetValueWithoutTextEditor(
aHandlingSetValue.GetSetValueFlags())); aHandlingSetValue.GetSetValueFlags()));
SelectionProperties& props = GetSelectionProperties(); SelectionProperties& props = GetSelectionProperties();
props.SetMaxLength(aHandlingSetValue.GetSettingValue().Length());
if (aHandlingSetValue.GetSetValueFlags() & if (aHandlingSetValue.GetSetValueFlags() &
eSetValue_MoveCursorToEndIfValueChanged) { eSetValue_MoveCursorToEndIfValueChanged) {
props.SetStart(aHandlingSetValue.GetSettingValue().Length()); props.SetStart(aHandlingSetValue.GetSettingValue().Length());
@@ -2893,6 +2903,13 @@ bool TextControlState::SetValueWithoutTextEditor(
props.SetStart(0); props.SetStart(0);
props.SetEnd(0); props.SetEnd(0);
props.SetDirection(nsITextControlFrame::eForward); 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()));
} }
} }

View File

@@ -284,12 +284,12 @@ class TextControlState final : public SupportsWeakPtr {
uint32_t GetStart() const { return mStart; } uint32_t GetStart() const { return mStart; }
void SetStart(uint32_t value) { void SetStart(uint32_t value) {
mIsDirty = true; mIsDirty = true;
mStart = std::min(value, mMaxLength); mStart = value;
} }
uint32_t GetEnd() const { return mEnd; } uint32_t GetEnd() const { return mEnd; }
void SetEnd(uint32_t value) { void SetEnd(uint32_t value) {
mIsDirty = true; mIsDirty = true;
mEnd = std::min(value, mMaxLength); mEnd = value;
} }
nsITextControlFrame::SelectionDirection GetDirection() const { nsITextControlFrame::SelectionDirection GetDirection() const {
return mDirection; return mDirection;
@@ -298,20 +298,13 @@ class TextControlState final : public SupportsWeakPtr {
mIsDirty = true; mIsDirty = true;
mDirection = value; mDirection = value;
} }
void SetMaxLength(uint32_t aMax) {
mMaxLength = aMax;
// recompute against the new max length
SetStart(GetStart());
SetEnd(GetEnd());
}
// return true only if mStart, mEnd, or mDirection have been modified, // return true only if mStart, mEnd, or mDirection have been modified,
// or if SetIsDirty() was explicitly called. // or if SetIsDirty() was explicitly called.
bool IsDirty() const { return mIsDirty; } bool IsDirty() const { return mIsDirty; }
void SetIsDirty() { mIsDirty = true; } void SetIsDirty() { mIsDirty = true; }
private: private:
uint32_t mStart, mEnd, mMaxLength; uint32_t mStart, mEnd;
bool mIsDirty = false; bool mIsDirty = false;
nsITextControlFrame::SelectionDirection mDirection; nsITextControlFrame::SelectionDirection mDirection;
}; };

View File

@@ -144,31 +144,6 @@
} }
}, "selectionEnd edge-case values"); }, "selectionEnd edge-case values");
test(() => {
for (const el of createTestElements(testValue)) {
el.selectionStart = 200;
assert_equals(el.selectionStart, testValue.length);
el.remove();
}
}, "selectionStart should be clamped by the current value length");
test(() => {
for (const el of createTestElements(testValue)) {
el.selectionStart = 300;
assert_equals(el.selectionEnd, testValue.length);
el.remove();
}
}, "selectionEnd should be clamped by the current value length");
test(() => {
for (const el of createTestElements(testValue)) {
el.setSelectionRange(200, 300);
assert_equals(el.selectionStart, testValue.length);
assert_equals(el.selectionEnd, testValue.length);
el.remove();
}
}, "setSelectionRange should be clamped by the current value length");
test(() => { test(() => {
for (let el of createTestElements(testValue)) { for (let el of createTestElements(testValue)) {
const start = 1; const start = 1;