mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 838694 - Move the text showing the file name to the right of the browse button. r=bz
This commit is contained in:
parent
01c5c4a59d
commit
3473000c3d
@ -114,83 +114,66 @@ nsFileControlFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
||||
nsresult
|
||||
nsFileControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
|
||||
{
|
||||
// Get the NodeInfoManager and tag necessary to create input elements
|
||||
nsCOMPtr<nsIDocument> doc = mContent->GetDocument();
|
||||
|
||||
nsCOMPtr<nsINodeInfo> nodeInfo;
|
||||
nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::label, nullptr,
|
||||
kNameSpaceID_XUL,
|
||||
nsIDOMNode::ELEMENT_NODE);
|
||||
|
||||
// Create the text content
|
||||
NS_TrustedNewXULElement(getter_AddRefs(mTextContent), nodeInfo.forget());
|
||||
if (!mTextContent)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
// Mark the element to be native anonymous before setting any attributes.
|
||||
mTextContent->SetNativeAnonymous();
|
||||
|
||||
mTextContent->SetAttr(kNameSpaceID_None, nsGkAtoms::crop,
|
||||
NS_LITERAL_STRING("center"), false);
|
||||
|
||||
nsHTMLInputElement* inputElement =
|
||||
nsHTMLInputElement::FromContent(mContent);
|
||||
NS_ASSERTION(inputElement, "Why is our content not a <input>?");
|
||||
|
||||
// Initialize value when we create the content in case the value was set
|
||||
// before we got here
|
||||
nsAutoString value;
|
||||
inputElement->GetDisplayFileName(value);
|
||||
UpdateDisplayedValue(value, false);
|
||||
|
||||
if (!aElements.AppendElement(mTextContent))
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
// Register the whole frame as an event listener of drag events
|
||||
mContent->AddSystemEventListener(NS_LITERAL_STRING("drop"),
|
||||
mMouseListener, false);
|
||||
mContent->AddSystemEventListener(NS_LITERAL_STRING("dragover"),
|
||||
mMouseListener, false);
|
||||
|
||||
// Register as an event listener of the textbox
|
||||
// to open file dialog on mouse click
|
||||
mTextContent->AddSystemEventListener(NS_LITERAL_STRING("click"),
|
||||
mMouseListener, false);
|
||||
|
||||
// Create the browse button
|
||||
// Create and setup the file picking button.
|
||||
nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::input, nullptr,
|
||||
kNameSpaceID_XHTML,
|
||||
nsIDOMNode::ELEMENT_NODE);
|
||||
NS_NewHTMLElement(getter_AddRefs(mBrowse), nodeInfo.forget(),
|
||||
dom::NOT_FROM_PARSER);
|
||||
if (!mBrowse)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
// Mark the element to be native anonymous before setting any attributes.
|
||||
// NOTE: SetNativeAnonymous() has to be called before setting any attribute.
|
||||
mBrowse->SetNativeAnonymous();
|
||||
|
||||
mBrowse->SetAttr(kNameSpaceID_None, nsGkAtoms::type,
|
||||
NS_LITERAL_STRING("button"), false);
|
||||
|
||||
// Make sure access key and tab order for the element actually redirect to the
|
||||
// file picking button.
|
||||
nsCOMPtr<nsIDOMHTMLInputElement> fileContent = do_QueryInterface(mContent);
|
||||
nsCOMPtr<nsIDOMHTMLInputElement> browseControl = do_QueryInterface(mBrowse);
|
||||
if (fileContent && browseControl) {
|
||||
int32_t tabIndex;
|
||||
nsAutoString accessKey;
|
||||
|
||||
fileContent->GetAccessKey(accessKey);
|
||||
browseControl->SetAccessKey(accessKey);
|
||||
fileContent->GetTabIndex(&tabIndex);
|
||||
browseControl->SetTabIndex(tabIndex);
|
||||
nsAutoString accessKey;
|
||||
fileContent->GetAccessKey(accessKey);
|
||||
browseControl->SetAccessKey(accessKey);
|
||||
|
||||
int32_t tabIndex;
|
||||
fileContent->GetTabIndex(&tabIndex);
|
||||
browseControl->SetTabIndex(tabIndex);
|
||||
|
||||
if (!aElements.AppendElement(mBrowse)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
if (!aElements.AppendElement(mBrowse))
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
// Create and setup the text showing the selected files.
|
||||
nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::label, nullptr,
|
||||
kNameSpaceID_XUL,
|
||||
nsIDOMNode::ELEMENT_NODE);
|
||||
NS_TrustedNewXULElement(getter_AddRefs(mTextContent), nodeInfo.forget());
|
||||
// NOTE: SetNativeAnonymous() has to be called before setting any attribute.
|
||||
mTextContent->SetNativeAnonymous();
|
||||
mTextContent->SetAttr(kNameSpaceID_None, nsGkAtoms::crop,
|
||||
NS_LITERAL_STRING("center"), false);
|
||||
|
||||
// Register as an event listener of the button
|
||||
// to open file dialog on mouse click
|
||||
// Update the displayed text to reflect the current element's value.
|
||||
nsAutoString value;
|
||||
nsHTMLInputElement::FromContent(mContent)->GetDisplayFileName(value);
|
||||
UpdateDisplayedValue(value, false);
|
||||
|
||||
if (!aElements.AppendElement(mTextContent)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// We should be able to interact with the element by doing drag and drop or
|
||||
// clicking.
|
||||
mContent->AddSystemEventListener(NS_LITERAL_STRING("drop"),
|
||||
mMouseListener, false);
|
||||
mContent->AddSystemEventListener(NS_LITERAL_STRING("dragover"),
|
||||
mMouseListener, false);
|
||||
mBrowse->AddSystemEventListener(NS_LITERAL_STRING("click"),
|
||||
mMouseListener, false);
|
||||
mTextContent->AddSystemEventListener(NS_LITERAL_STRING("click"),
|
||||
mMouseListener, false);
|
||||
|
||||
SyncDisabledState();
|
||||
|
||||
|
@ -423,6 +423,7 @@ input[type="file"] {
|
||||
|
||||
input[type="file"] > xul|label {
|
||||
width: 12em;
|
||||
-moz-padding-start: 5px;
|
||||
|
||||
border-color: inherit;
|
||||
background-color: inherit;
|
||||
|
Loading…
Reference in New Issue
Block a user