Bug 1415416 - Part 1. Collapse selection on focus when value is empty. r?masayuki draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Thu, 11 Jan 2018 18:39:12 +0900
changeset 718986 407879b9d6bd2c5e082bc4f96b12635e6ea05b23
parent 718845 4db166f0442dddc5b9011c722d7499501fedf283
child 718987 afa8e1fe4806cecebba380bd9fb32743fdd52909
push id95130
push userbmo:m_kato@ga2.so-net.ne.jp
push dateThu, 11 Jan 2018 09:49:28 +0000
reviewersmasayuki
bugs1415416, 1375910
milestone59.0a1
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
layout/forms/nsTextControlFrame.cpp
--- 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;