Bug 1495153 part 1 - Replace the XUL label in <input type=file> with an HTML label. r=emilio
☠☠ backed out by 90853a59691e ☠ ☠
authorMats Palmgren <mats@mozilla.com>
Sat, 06 Oct 2018 19:31:51 +0200
changeset 495651 6800eb348ebe37c9beb67fe76da7ec86be0f7f1f
parent 495649 ce95adbcf2e4cd8462964ab6b748d2978cb9d607
child 495652 6d95f0e0cc76d43171e8c16ee04f56204da38462
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1495153
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1495153 part 1 - Replace the XUL label in <input type=file> with an HTML label. r=emilio
layout/forms/nsFileControlFrame.cpp
layout/style/res/forms.css
--- a/layout/forms/nsFileControlFrame.cpp
+++ b/layout/forms/nsFileControlFrame.cpp
@@ -136,35 +136,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,
-                                                 nsINode::ELEMENT_NODE);
-  NS_TrustedNewXULElement(getter_AddRefs(mTextContent), nodeInfo.forget());
+  mTextContent = doc->CreateHTMLElement(nsGkAtoms::label);
   // NOTE: SetIsNativeAnonymousRoot() has to be called before setting any
   // attribute.
   mTextContent->SetIsNativeAnonymousRoot();
-  mTextContent->SetAttr(kNameSpaceID_None, nsGkAtoms::crop,
-                        NS_LITERAL_STRING("center"), false);
+  RefPtr<nsTextNode> text = new nsTextNode(doc->NodeInfoManager());
+  mTextContent->AppendChildTo(text, false);
 
   // Update the displayed text to reflect the current element's value.
   nsAutoString value;
   HTMLInputElement::FromNode(mContent)->GetDisplayFileName(value);
   UpdateDisplayedValue(value, false);
 
-  if (!aElements.AppendElement(mTextContent)) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
+  aElements.AppendElement(mTextContent);
 
   // We should be able to interact with the element by doing drag and drop.
   mContent->AddSystemEventListener(NS_LITERAL_STRING("drop"),
                                    mMouseListener, false);
   mContent->AddSystemEventListener(NS_LITERAL_STRING("dragover"),
                                    mMouseListener, false);
 
   SyncDisabledState();
@@ -470,17 +464,18 @@ 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);
+  auto* text = Text::FromNode(mTextContent->GetFirstChild());
+  text->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
@@ -3,17 +3,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /**
   Styles for old GFX form widgets
  **/
 
 
 @namespace url(http://www.w3.org/1999/xhtml); /* set default namespace to HTML */
-@namespace xul url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);
 
 *|*::-moz-fieldset-content {
   display: block; /* StyleAdjuster::adjust_for_fieldset_content overrides this in some cases */
   unicode-bidi: inherit;
   text-overflow: inherit;
   overflow: inherit;
   overflow-clip-box: inherit;
   /* Need to inherit border-radius too, so when the fieldset has rounded
@@ -475,45 +474,42 @@ input[type="image"]:disabled {
 input[type="image"]:-moz-focusring {
   /* Don't specify the outline-color, we should always use initial value. */
   outline: 1px dotted;
 }
 
 /* file selector */
 input[type="file"] {
   display: inline-block;
-  white-space: nowrap;
+  white-space: nowrap !important;
   overflow: hidden;
   overflow-clip-box: padding-box;
   color: unset;
 
   /* Revert rules which apply on all inputs. */
   -moz-appearance: none;
   -moz-binding: none;
   cursor: default;
 
   border: none;
   background-color: transparent;
   padding: unset;
 }
 
-input[type="file"] > xul|label {
+input[type="file"] > label {
   min-inline-size: 12em;
   padding-inline-start: 5px;
   text-align: match-parent;
 
   color: unset;
   font-size: unset;
   letter-spacing: unset;
 
-  /*
-   * Force the text to have LTR directionality. Otherwise filenames containing
-   * RTL characters will be reordered with chaotic results.
-   */
-  direction: ltr !important;
+  -moz-user-select: none;
+  unicode-bidi: plaintext;
 }
 
 /* button part of file selector */
 input[type="file"] > button[type="button"] {
   block-size: inherit;
   font-size: unset;
   letter-spacing: unset;
   cursor: unset;
@@ -527,24 +523,16 @@ input[type="color"]::-moz-color-swatch {
   min-height: 3px;
   margin-inline-start: auto;
   margin-inline-end: auto;
   box-sizing: border-box;
   border: 1px solid grey;
   display: block;
 }
 
-/* Try to make RTL <input type='file'> look nicer. */
-/* TODO: find a better solution than forcing direction: ltr on all file
-   input labels and remove this override -- bug 1161482 */
-input[type="file"]:dir(rtl) > xul|label {
-  padding-inline-start: 0px;
-  padding-inline-end: 5px;
-}
-
 /* radio buttons */
 input[type="radio"] {
   display: inline-block;
   -moz-appearance: radio;
   margin-block-start: 3px;
   margin-block-end: 0px;
   margin-inline-start: 5px;
   margin-inline-end: 3px;