Bug 583863: Refactor <input> implementation to deal with files that are not on the disk. r=sicking a=blocking-fennec
This commit is contained in:
@@ -65,7 +65,7 @@
|
||||
#include "nsINodeInfo.h"
|
||||
#include "nsIDOMEventTarget.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsIFileControlElement.h"
|
||||
#include "nsHTMLInputElement.h"
|
||||
#include "nsNodeInfoManager.h"
|
||||
#include "nsContentCreatorFunctions.h"
|
||||
#include "nsContentUtils.h"
|
||||
@@ -90,6 +90,7 @@
|
||||
#include "nsHTMLInputElement.h"
|
||||
#include "nsICapturePicker.h"
|
||||
#include "nsIFileURL.h"
|
||||
#include "nsDOMFile.h"
|
||||
|
||||
#define SYNC_TEXT 0x1
|
||||
#define SYNC_BUTTON 0x2
|
||||
@@ -235,20 +236,21 @@ nsFileControlFrame::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
|
||||
mTextContent->SetAttr(kNameSpaceID_None, nsGkAtoms::type,
|
||||
NS_LITERAL_STRING("text"), PR_FALSE);
|
||||
|
||||
nsCOMPtr<nsIDOMHTMLInputElement> textControl = do_QueryInterface(mTextContent);
|
||||
if (textControl) {
|
||||
nsCOMPtr<nsIFileControlElement> fileControl = do_QueryInterface(mContent);
|
||||
if (fileControl) {
|
||||
// Initialize value when we create the content in case the value was set
|
||||
// before we got here
|
||||
nsAutoString value;
|
||||
fileControl->GetDisplayFileName(value);
|
||||
textControl->SetValue(value);
|
||||
}
|
||||
nsHTMLInputElement* inputElement =
|
||||
nsHTMLInputElement::FromContent(mContent);
|
||||
NS_ASSERTION(inputElement, "Why is our content not a <input>?");
|
||||
|
||||
textControl->SetTabIndex(-1);
|
||||
textControl->SetReadOnly(PR_TRUE);
|
||||
}
|
||||
// Initialize value when we create the content in case the value was set
|
||||
// before we got here
|
||||
nsAutoString value;
|
||||
inputElement->GetDisplayFileName(value);
|
||||
|
||||
nsCOMPtr<nsIDOMHTMLInputElement> textControl = do_QueryInterface(mTextContent);
|
||||
NS_ASSERTION(textControl, "Why is the <input> we created not a <input>?");
|
||||
textControl->SetValue(value);
|
||||
|
||||
textControl->SetTabIndex(-1);
|
||||
textControl->SetReadOnly(PR_TRUE);
|
||||
|
||||
if (!aElements.AppendElement(mTextContent))
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
@@ -398,9 +400,11 @@ nsFileControlFrame::CaptureMouseListener::MouseClick(nsIDOMEvent* aMouseEvent)
|
||||
|
||||
// Get parent nsIDOMWindowInternal object.
|
||||
nsIContent* content = mFrame->GetContent();
|
||||
nsCOMPtr<nsIDOMHTMLInputElement> inputElem = do_QueryInterface(content);
|
||||
nsCOMPtr<nsIFileControlElement> fileControl = do_QueryInterface(content);
|
||||
if (!content || !inputElem || !fileControl)
|
||||
if (!content)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsHTMLInputElement* inputElement = nsHTMLInputElement::FromContent(content);
|
||||
if (!inputElement)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDocument> doc = content->GetDocument();
|
||||
@@ -443,21 +447,13 @@ nsFileControlFrame::CaptureMouseListener::MouseClick(nsIDOMEvent* aMouseEvent)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = capturePicker->GetUri(getter_AddRefs(uri));
|
||||
nsCOMPtr<nsIDOMFile> domFile;
|
||||
rv = capturePicker->GetFile(getter_AddRefs(domFile));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsTArray<nsString> newFileNames;
|
||||
if (uri) {
|
||||
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(uri);
|
||||
if (!fileURL)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsCAutoString spec;
|
||||
rv = uri->GetSpec(spec);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
newFileNames.AppendElement(NS_ConvertUTF8toUTF16(spec));
|
||||
nsCOMArray<nsIDOMFile> newFiles;
|
||||
if (domFile) {
|
||||
newFiles.AppendObject(domFile);
|
||||
} else {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
@@ -465,13 +461,13 @@ nsFileControlFrame::CaptureMouseListener::MouseClick(nsIDOMEvent* aMouseEvent)
|
||||
// XXXkhuey we really should have a better UI story than the tired old
|
||||
// uneditable text box with the file name inside.
|
||||
// Set new selected files
|
||||
if (!newFileNames.IsEmpty()) {
|
||||
if (newFiles.Count()) {
|
||||
// Tell mTextFrame that this update of the value is a user initiated
|
||||
// change. Otherwise it'll think that the value is being set by a script
|
||||
// and not fire onchange when it should.
|
||||
PRBool oldState = mFrame->mTextFrame->GetFireChangeEventState();
|
||||
mFrame->mTextFrame->SetFireChangeEventState(PR_TRUE);
|
||||
fileControl->SetFileNames(newFileNames);
|
||||
inputElement->SetFiles(newFiles);
|
||||
|
||||
mFrame->mTextFrame->SetFireChangeEventState(oldState);
|
||||
// May need to fire an onchange here
|
||||
@@ -491,12 +487,9 @@ nsFileControlFrame::BrowseMouseListener::MouseClick(nsIDOMEvent* aMouseEvent)
|
||||
if (!ShouldProcessMouseClick(aMouseEvent))
|
||||
return NS_OK;
|
||||
|
||||
nsIContent* content = mFrame->GetContent();
|
||||
if (content->IsHTML() && content->Tag() == nsGkAtoms::input) {
|
||||
nsHTMLInputElement* input = static_cast<nsHTMLInputElement*>(content);
|
||||
return input->FireAsyncClickHandler();
|
||||
}
|
||||
return NS_OK;
|
||||
nsHTMLInputElement* input =
|
||||
nsHTMLInputElement::FromContent(mFrame->GetContent());
|
||||
return input ? input->FireAsyncClickHandler() : NS_OK;
|
||||
}
|
||||
|
||||
nscoord
|
||||
@@ -643,10 +636,11 @@ nsFileControlFrame::GetFormProperty(nsIAtom* aName, nsAString& aValue) const
|
||||
aValue.Truncate(); // initialize out param
|
||||
|
||||
if (nsGkAtoms::value == aName) {
|
||||
nsCOMPtr<nsIFileControlElement> fileControl =
|
||||
do_QueryInterface(mContent);
|
||||
if (fileControl) {
|
||||
fileControl->GetDisplayFileName(aValue);
|
||||
nsHTMLInputElement* inputElement =
|
||||
nsHTMLInputElement::FromContent(mContent);
|
||||
|
||||
if (inputElement) {
|
||||
inputElement->GetDisplayFileName(aValue);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
|
||||
Reference in New Issue
Block a user