Bug 1415416 - Part 1. Collapse selection on focus when value is empty. r?masayuki
After landing
bug 1375910, input.value = "" doesn't remove inter text node.
When value is empty, SelectAllOrCollapseToEndOfText will set selection to
end of text. But since empty text node is still exist, it select all nodes,
instead of collapsed. So if text node is empty, we should collapse selection.
MozReview-Commit-ID: Gm0AP6YSJIg
--- a/layout/forms/nsTextControlFrame.cpp
+++ b/layout/forms/nsTextControlFrame.cpp
@@ -947,16 +947,19 @@ nsTextControlFrame::SelectAllOrCollapseT
if (numChildren > 0) {
// We never want to place the selection after the last
// br under the root node!
nsIContent *child = rootContent->GetLastChild();
if (child) {
if (child->IsHTMLElement(nsGkAtoms::br)) {
child = child->GetPreviousSibling();
--numChildren;
+ } else if (child->IsNodeOfType(nsINode::eTEXT) && !child->Length()) {
+ // Editor won't remove text node when empty value.
+ --numChildren;
}
}
if (!aSelect && numChildren) {
child = child->GetPreviousSibling();
if (child && child->IsNodeOfType(nsINode::eTEXT)) {
rootNode = do_QueryInterface(child);
const nsTextFragment* fragment = child->GetText();
numChildren = fragment ? fragment->GetLength() : 0;