Bug 1421382: Make <input type="file"> use a <span> with a text node instead of a <xul:label>.
MozReview-Commit-ID: 27uVAsSXF3B
--- 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;