tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 455c0b0a8dc097948b9bd8cbb72bb62c683ce334
parent df2fae2a76c1635475ac8b69bd1144d3205a0d13
Author: Emilio Cobos Álvarez <emilio@crisal.io>
Date:   Fri,  3 Oct 2025 21:39:09 +0000

Bug 1992452 - Remove UpdateValueDisplay calls on PrepareEditor. r=smaug

PrepareEditor initializes and sets up the DOM as well so there's no need
for doing it twice.

This causes a behavior change in test_bug1785739, but I think it's a
progression, as before there were two calls to find() that ended up with
the same range.

Differential Revision: https://phabricator.services.mozilla.com/D267437

Diffstat:
Mdom/html/TextControlState.cpp | 17-----------------
Mdom/html/test/test_bug1785739.html | 18+++++-------------
Mlayout/forms/nsTextControlFrame.cpp | 10++--------
Mlayout/forms/nsTextControlFrame.h | 2+-
4 files changed, 8 insertions(+), 39 deletions(-)

diff --git a/dom/html/TextControlState.cpp b/dom/html/TextControlState.cpp @@ -1720,24 +1720,7 @@ nsresult TextControlState::PrepareEditor(const nsAString* aValue) { // Create an editor newTextEditor = new TextEditor(); preDestroyer.Init(newTextEditor); - - // Make sure we clear out the non-breaking space before we initialize the - // editor - nsresult rv = mBoundFrame->UpdateValueDisplay(true); - if (NS_FAILED(rv)) { - NS_WARNING("nsTextControlFrame::UpdateValueDisplay() failed"); - return rv; - } } else { - if (aValue || !mEditorInitialized) { - // Set the correct value in the root node - nsresult rv = mBoundFrame->UpdateValueDisplay(true, aValue); - if (NS_FAILED(rv)) { - NS_WARNING("nsTextControlFrame::UpdateValueDisplay() failed"); - return rv; - } - } - newTextEditor = mTextEditor; // just pretend that we have a new editor! // Don't lose application flags in the process. diff --git a/dom/html/test/test_bug1785739.html b/dom/html/test/test_bug1785739.html @@ -23,21 +23,13 @@ finder.init(SpecialPowers.wrap(window).docShell); - function find() { - return finder.find( - "abc", - false, - SpecialPowers.Ci.nsITypeAheadFind.FIND_NEXT, - true); - } - async function runTests() { - finder.find("abc", false, SpecialPowers.Ci.nsITypeAheadFind.FIND_FIRST, true); - // Wait until layout flush as the bug repro needs it - await new Promise(requestAnimationFrame); - for (let i = 0; i < 9; i++) { - find(); + let which = i == 0 + ? SpecialPowers.Ci.nsITypeAheadFind.FIND_FIRST + : SpecialPowers.Ci.nsITypeAheadFind.FIND_NEXT; + finder.find("abc", false, which, true); + // Wait until layout flush as the bug repro needs it await new Promise(requestAnimationFrame); is(input.selectionStart, (i * 19) + 1); } diff --git a/layout/forms/nsTextControlFrame.cpp b/layout/forms/nsTextControlFrame.cpp @@ -1034,8 +1034,7 @@ void nsTextControlFrame::SetInitialChildList(ChildListID aListID, } } -nsresult nsTextControlFrame::UpdateValueDisplay(bool aNotify, - const nsAString* aValue) { +nsresult nsTextControlFrame::UpdateValueDisplay(bool aNotify) { MOZ_ASSERT(mRootNode, "Must have a div content\n"); MOZ_ASSERT(!mEditorHasBeenInitialized, "Do not call this after editor has been initialized"); @@ -1060,12 +1059,7 @@ nsresult nsTextControlFrame::UpdateValueDisplay(bool aNotify, // Get the current value of the textfield from the content. nsAutoString value; - if (aValue) { - value = *aValue; - } else { - ControlElement()->GetTextEditorValue(value); - } - + ControlElement()->GetTextEditorValue(value); return textContent->SetText(value, aNotify); } diff --git a/layout/forms/nsTextControlFrame.h b/layout/forms/nsTextControlFrame.h @@ -248,7 +248,7 @@ class nsTextControlFrame : public nsContainerFrame, * value. This should only be called when we have no editor yet. * @throws NS_ERROR_UNEXPECTED if the div has no text content */ - nsresult UpdateValueDisplay(bool aNotify, const nsAString* aValue = nullptr); + nsresult UpdateValueDisplay(bool aNotify); /** * Find out whether an attribute exists on the content or not.