Bug 1421382: Make <input type="file"> use a <span> with a text node instead of a <xul:label>. draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Wed, 29 Nov 2017 20:49:18 +0100
changeset 705251 f367ef51f23bf62ba86b640e51aa1232c80a87dc
parent 705249 8484caf2a054360682a2701e7afbd8bf25291666
child 742321 c2ad210f3262da89a44aac9ad094527bc930a48b
push id91427
push userbmo:emilio@crisal.io
push dateWed, 29 Nov 2017 19:52:11 +0000
bugs1421382
milestone59.0a1
Bug 1421382: Make <input type="file"> use a <span> with a text node instead of a <xul:label>. MozReview-Commit-ID: 27uVAsSXF3B
layout/forms/nsFileControlFrame.cpp
layout/style/res/forms.css
--- a/layout/forms/nsFileControlFrame.cpp
+++ b/layout/forms/nsFileControlFrame.cpp
@@ -137,26 +137,29 @@ nsFileControlFrame::CreateAnonymousConte
   fileContent->GetAccessKey(accessKey);
 
   mBrowseFilesOrDirs = MakeAnonButton(doc, "Browse", fileContent, accessKey);
   if (!mBrowseFilesOrDirs || !aElements.AppendElement(mBrowseFilesOrDirs)) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   // Create and setup the text showing the selected files.
-  RefPtr<NodeInfo> nodeInfo;
-  nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::label, nullptr,
-                                                 kNameSpaceID_XUL,
-                                                 nsIDOMNode::ELEMENT_NODE);
-  NS_TrustedNewXULElement(getter_AddRefs(mTextContent), nodeInfo.forget());
+  RefPtr<NodeInfo> nodeInfo =
+    doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::span, nullptr,
+                                        kNameSpaceID_XHTML,
+                                        nsIDOMNode::ELEMENT_NODE);
+
+  mTextContent = NS_NewHTMLSpanElement(nodeInfo.forget());
+
+  RefPtr<nsTextNode> textNode = new nsTextNode(doc->NodeInfoManager());
+  mTextContent->AppendChildTo(textNode, false);
+
   // NOTE: SetIsNativeAnonymousRoot() has to be called before setting any
   // attribute.
   mTextContent->SetIsNativeAnonymousRoot();
-  mTextContent->SetAttr(kNameSpaceID_None, nsGkAtoms::crop,
-                        NS_LITERAL_STRING("center"), false);
 
   // Update the displayed text to reflect the current element's value.
   nsAutoString value;
   HTMLInputElement::FromContent(mContent)->GetDisplayFileName(value);
   UpdateDisplayedValue(value, false);
 
   if (!aElements.AppendElement(mTextContent)) {
     return NS_ERROR_OUT_OF_MEMORY;
@@ -476,17 +479,17 @@ nsFileControlFrame::GetFrameName(nsAStri
 {
   return MakeFrameName(NS_LITERAL_STRING("FileControl"), aResult);
 }
 #endif
 
 void
 nsFileControlFrame::UpdateDisplayedValue(const nsAString& aValue, bool aNotify)
 {
-  mTextContent->SetAttr(kNameSpaceID_None, nsGkAtoms::value, aValue, aNotify);
+  mTextContent->GetFirstChild()->SetText(aValue, aNotify);
 }
 
 nsresult
 nsFileControlFrame::SetFormProperty(nsAtom* aName,
                                     const nsAString& aValue)
 {
   if (nsGkAtoms::value == aName) {
     UpdateDisplayedValue(aValue, true);
--- a/layout/style/res/forms.css
+++ b/layout/style/res/forms.css
@@ -489,17 +489,17 @@ input[type="file"] {
   -moz-binding: none;
   cursor: default;
 
   border: none;
   background-color: transparent;
   padding: 0;
 }
 
-input[type="file"] > xul|label {
+input[type="file"] > span {
   min-inline-size: 12em;
   padding-inline-start: 5px;
   text-align: match-parent;
 
   color: inherit;
   font-size: inherit;
   letter-spacing: inherit;