Bug 1451576 - Demo of using [dir] in NAC
STR:
./mach run --devtools --setpref devtools.inspector.showAllAnonymousContent=true --setpref devtools.inspector.showUserAgentStyles=true 'data:text/html,<input type="file" />'
Then select a file with RTL text.
MozReview-Commit-ID: HMQNu2qQm4B
--- a/layout/forms/nsFileControlFrame.cpp
+++ b/layout/forms/nsFileControlFrame.cpp
@@ -81,16 +81,18 @@ MakeAnonButton(nsIDocument* aDoc, const
const nsAString& aAccessKey)
{
RefPtr<Element> button = aDoc->CreateHTMLElement(nsGkAtoms::button);
// NOTE: SetIsNativeAnonymousRoot() has to be called before setting any
// attribute.
button->SetIsNativeAnonymousRoot();
button->SetAttr(kNameSpaceID_None, nsGkAtoms::type,
NS_LITERAL_STRING("button"), false);
+ button->SetAttr(kNameSpaceID_None, nsGkAtoms::dir,
+ NS_LITERAL_STRING("auto"), false);
// Set the file picking button text depending on the current locale.
nsAutoString buttonTxt;
nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
labelKey, buttonTxt);
// Set the browse button text. It's a bit of a pain to do because we want to
// make sure we are not notifying.
@@ -135,26 +137,23 @@ 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);
+ mTextContent->SetAttr(kNameSpaceID_None, nsGkAtoms::dir,
+ NS_LITERAL_STRING("auto"), false);
+ mTextContent->AppendChildTo(new nsTextNode(doc->NodeInfoManager()), 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;
@@ -464,17 +463,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
@@ -496,30 +496,24 @@ input[type="file"] {
-moz-binding: none;
cursor: default;
border: none;
background-color: transparent;
padding: 0;
}
-input[type="file"] > xul|label {
+input[type="file"] > label {
min-inline-size: 12em;
padding-inline-start: 5px;
text-align: match-parent;
color: inherit;
font-size: inherit;
letter-spacing: inherit;
-
- /*
- * Force the text to have LTR directionality. Otherwise filenames containing
- * RTL characters will be reordered with chaotic results.
- */
- direction: ltr !important;
}
/* button part of file selector */
input[type="file"] > button[type="button"] {
block-size: inherit;
font-size: inherit;
letter-spacing: inherit;
cursor: inherit;
@@ -533,24 +527,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;