2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1998-09-23 21:16:51 +04:00
|
|
|
|
|
|
|
#include "nsFileControlFrame.h"
|
2000-05-02 07:40:44 +04:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
1999-02-18 03:13:39 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2000-12-30 22:22:22 +03:00
|
|
|
#include "nsIDocument.h"
|
2014-06-20 06:01:40 +04:00
|
|
|
#include "mozilla/dom/NodeInfo.h"
|
2013-12-03 18:40:10 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2018-01-08 16:05:05 +03:00
|
|
|
#include "mozilla/dom/DOMPrefs.h"
|
2018-03-13 23:23:59 +03:00
|
|
|
#include "mozilla/dom/DOMStringList.h"
|
|
|
|
#include "mozilla/dom/DataTransfer.h"
|
|
|
|
#include "mozilla/dom/Directory.h"
|
|
|
|
#include "mozilla/dom/DragEvent.h"
|
|
|
|
#include "mozilla/dom/FileList.h"
|
2013-08-08 00:23:08 +04:00
|
|
|
#include "mozilla/dom/HTMLButtonElement.h"
|
2013-03-28 23:41:32 +04:00
|
|
|
#include "mozilla/dom/HTMLInputElement.h"
|
2018-02-09 19:17:10 +03:00
|
|
|
#include "mozilla/dom/MutationEventBinding.h"
|
2015-07-10 20:56:36 +03:00
|
|
|
#include "mozilla/Preferences.h"
|
2004-06-25 16:26:02 +04:00
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsContentCreatorFunctions.h"
|
2004-12-17 23:40:48 +03:00
|
|
|
#include "nsContentUtils.h"
|
2014-04-03 08:18:36 +04:00
|
|
|
#include "mozilla/EventStates.h"
|
2013-09-06 10:40:45 +04:00
|
|
|
#include "nsIDOMFileList.h"
|
2013-04-04 16:01:08 +04:00
|
|
|
#include "nsTextNode.h"
|
2011-06-01 10:06:38 +04:00
|
|
|
|
2012-10-16 02:44:34 +04:00
|
|
|
using namespace mozilla;
|
2013-03-28 23:41:32 +04:00
|
|
|
using namespace mozilla::dom;
|
2010-10-25 16:17:38 +04:00
|
|
|
|
2005-11-04 05:38:33 +03:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewFileControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1998-09-23 21:16:51 +04:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) nsFileControlFrame(aContext);
|
1998-09-23 21:16:51 +04:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsFileControlFrame)
|
|
|
|
|
2013-03-22 21:15:13 +04:00
|
|
|
nsFileControlFrame::nsFileControlFrame(nsStyleContext* aContext)
|
2017-05-26 13:11:11 +03:00
|
|
|
: nsBlockFrame(aContext, kClassID)
|
1998-09-23 21:16:51 +04:00
|
|
|
{
|
2009-01-19 21:31:32 +03:00
|
|
|
AddStateBits(NS_BLOCK_FLOAT_MGR);
|
1999-07-01 02:17:43 +04:00
|
|
|
}
|
|
|
|
|
1999-08-19 18:03:53 +04:00
|
|
|
|
2013-03-20 05:47:48 +04:00
|
|
|
void
|
2014-05-25 02:20:40 +04:00
|
|
|
nsFileControlFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2006-11-14 01:05:25 +03:00
|
|
|
{
|
2013-03-20 05:47:48 +04:00
|
|
|
nsBlockFrame::Init(aContent, aParent, aPrevInFlow);
|
2006-11-14 01:05:25 +03:00
|
|
|
|
2013-03-27 15:32:00 +04:00
|
|
|
mMouseListener = new DnDListener(this);
|
2006-11-14 01:05:25 +03:00
|
|
|
}
|
|
|
|
|
2006-04-10 04:16:29 +04:00
|
|
|
void
|
2017-11-07 03:20:33 +03:00
|
|
|
nsFileControlFrame::DestroyFrom(nsIFrame* aDestructRoot, PostDestroyData& aPostDestroyData)
|
2004-05-22 05:17:00 +04:00
|
|
|
{
|
2008-01-11 00:55:38 +03:00
|
|
|
ENSURE_TRUE(mContent);
|
|
|
|
|
2013-03-22 21:15:13 +04:00
|
|
|
// Remove the events.
|
2011-11-29 08:39:21 +04:00
|
|
|
if (mContent) {
|
|
|
|
mContent->RemoveSystemEventListener(NS_LITERAL_STRING("drop"),
|
|
|
|
mMouseListener, false);
|
|
|
|
mContent->RemoveSystemEventListener(NS_LITERAL_STRING("dragover"),
|
|
|
|
mMouseListener, false);
|
2011-06-01 10:06:38 +04:00
|
|
|
}
|
|
|
|
|
2017-11-07 03:20:33 +03:00
|
|
|
aPostDestroyData.AddAnonymousContent(mTextContent.forget());
|
|
|
|
aPostDestroyData.AddAnonymousContent(mBrowseFilesOrDirs.forget());
|
2006-11-14 01:05:25 +03:00
|
|
|
|
|
|
|
mMouseListener->ForgetFrame();
|
2017-11-07 03:20:33 +03:00
|
|
|
nsBlockFrame::DestroyFrom(aDestructRoot, aPostDestroyData);
|
2002-12-20 08:40:37 +03:00
|
|
|
}
|
|
|
|
|
2015-07-10 20:56:36 +03:00
|
|
|
static already_AddRefed<Element>
|
|
|
|
MakeAnonButton(nsIDocument* aDoc, const char* labelKey,
|
|
|
|
HTMLInputElement* aInputElement,
|
|
|
|
const nsAString& aAccessKey)
|
1999-07-01 02:17:43 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Element> button = aDoc->CreateHTMLElement(nsGkAtoms::button);
|
2013-09-25 00:29:27 +04:00
|
|
|
// NOTE: SetIsNativeAnonymousRoot() has to be called before setting any
|
|
|
|
// attribute.
|
2015-07-10 20:56:36 +03:00
|
|
|
button->SetIsNativeAnonymousRoot();
|
|
|
|
button->SetAttr(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
NS_LITERAL_STRING("button"), false);
|
2001-02-20 00:50:04 +03:00
|
|
|
|
2013-02-09 14:48:20 +04:00
|
|
|
// Set the file picking button text depending on the current locale.
|
2017-08-04 07:40:52 +03:00
|
|
|
nsAutoString buttonTxt;
|
2013-02-09 14:48:20 +04:00
|
|
|
nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
|
2015-07-10 20:56:36 +03:00
|
|
|
labelKey, buttonTxt);
|
2013-03-29 16:32:47 +04:00
|
|
|
|
|
|
|
// Set the browse button text. It's a bit of a pain to do because we want to
|
|
|
|
// make sure we are not notifying.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsTextNode> textContent =
|
2015-07-10 20:56:36 +03:00
|
|
|
new nsTextNode(button->NodeInfo()->NodeInfoManager());
|
2013-03-29 16:32:47 +04:00
|
|
|
|
|
|
|
textContent->SetText(buttonTxt, false);
|
|
|
|
|
2015-07-10 20:56:36 +03:00
|
|
|
nsresult rv = button->AppendChildTo(textContent, false);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-02-09 14:48:20 +04:00
|
|
|
|
2013-02-09 19:09:14 +04:00
|
|
|
// Make sure access key and tab order for the element actually redirect to the
|
|
|
|
// file picking button.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<HTMLButtonElement> buttonElement =
|
2015-07-10 20:56:36 +03:00
|
|
|
HTMLButtonElement::FromContentOrNull(button);
|
|
|
|
|
|
|
|
if (!aAccessKey.IsEmpty()) {
|
2018-02-01 22:21:14 +03:00
|
|
|
buttonElement->SetAccessKey(aAccessKey, IgnoreErrors());
|
2015-07-10 20:56:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Both elements are given the same tab index so that the user can tab
|
|
|
|
// to the file control at the correct index, and then between the two
|
|
|
|
// buttons.
|
2018-02-01 22:21:14 +03:00
|
|
|
buttonElement->SetTabIndex(aInputElement->TabIndex(), IgnoreErrors());
|
2015-07-10 20:56:36 +03:00
|
|
|
|
|
|
|
return button.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsFileControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocument> doc = mContent->GetComposedDoc();
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<HTMLInputElement> fileContent = HTMLInputElement::FromContentOrNull(mContent);
|
2013-02-09 19:09:14 +04:00
|
|
|
|
2015-07-10 20:56:36 +03:00
|
|
|
// The access key is transferred to the "Choose files..." button only. In
|
|
|
|
// effect that access key allows access to the control via that button, then
|
|
|
|
// the user can tab between the two buttons.
|
2013-02-09 19:09:14 +04:00
|
|
|
nsAutoString accessKey;
|
|
|
|
fileContent->GetAccessKey(accessKey);
|
|
|
|
|
2016-06-29 19:18:42 +03:00
|
|
|
mBrowseFilesOrDirs = MakeAnonButton(doc, "Browse", fileContent, accessKey);
|
|
|
|
if (!mBrowseFilesOrDirs || !aElements.AppendElement(mBrowseFilesOrDirs)) {
|
2007-02-18 20:34:09 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2013-02-09 19:09:14 +04:00
|
|
|
}
|
2007-02-18 20:34:09 +03:00
|
|
|
|
2013-02-09 19:09:14 +04:00
|
|
|
// Create and setup the text showing the selected files.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<NodeInfo> nodeInfo;
|
2013-02-09 19:09:14 +04:00
|
|
|
nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::label, nullptr,
|
|
|
|
kNameSpaceID_XUL,
|
2018-01-30 07:10:53 +03:00
|
|
|
nsINode::ELEMENT_NODE);
|
2013-02-09 19:09:14 +04:00
|
|
|
NS_TrustedNewXULElement(getter_AddRefs(mTextContent), nodeInfo.forget());
|
2013-09-25 00:29:27 +04:00
|
|
|
// NOTE: SetIsNativeAnonymousRoot() has to be called before setting any
|
|
|
|
// attribute.
|
|
|
|
mTextContent->SetIsNativeAnonymousRoot();
|
2013-02-09 18:57:30 +04:00
|
|
|
mTextContent->SetAttr(kNameSpaceID_None, nsGkAtoms::crop,
|
|
|
|
NS_LITERAL_STRING("center"), false);
|
2007-02-18 20:34:09 +03:00
|
|
|
|
2013-02-09 19:09:14 +04:00
|
|
|
// Update the displayed text to reflect the current element's value.
|
2010-09-05 22:00:05 +04:00
|
|
|
nsAutoString value;
|
2013-03-28 23:41:32 +04:00
|
|
|
HTMLInputElement::FromContent(mContent)->GetDisplayFileName(value);
|
2013-02-09 18:57:30 +04:00
|
|
|
UpdateDisplayedValue(value, false);
|
1999-07-01 02:17:43 +04:00
|
|
|
|
2013-02-09 19:09:14 +04:00
|
|
|
if (!aElements.AppendElement(mTextContent)) {
|
2007-02-18 20:34:09 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2013-02-09 19:09:14 +04:00
|
|
|
}
|
1999-07-01 02:17:43 +04:00
|
|
|
|
2013-03-27 15:32:00 +04:00
|
|
|
// We should be able to interact with the element by doing drag and drop.
|
2011-11-29 08:39:21 +04:00
|
|
|
mContent->AddSystemEventListener(NS_LITERAL_STRING("drop"),
|
|
|
|
mMouseListener, false);
|
|
|
|
mContent->AddSystemEventListener(NS_LITERAL_STRING("dragover"),
|
|
|
|
mMouseListener, false);
|
2007-02-18 20:34:09 +03:00
|
|
|
|
2010-12-14 21:00:57 +03:00
|
|
|
SyncDisabledState();
|
2000-01-14 02:34:01 +03:00
|
|
|
|
1999-07-01 02:17:43 +04:00
|
|
|
return NS_OK;
|
1998-09-23 21:16:51 +04:00
|
|
|
}
|
|
|
|
|
2010-02-11 20:34:01 +03:00
|
|
|
void
|
2014-07-16 22:41:57 +04:00
|
|
|
nsFileControlFrame::AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aFilter)
|
2010-02-11 20:34:01 +03:00
|
|
|
{
|
2016-06-29 19:18:42 +03:00
|
|
|
if (mBrowseFilesOrDirs) {
|
|
|
|
aElements.AppendElement(mBrowseFilesOrDirs);
|
2014-07-16 22:41:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mTextContent) {
|
|
|
|
aElements.AppendElement(mTextContent);
|
|
|
|
}
|
2010-02-11 20:34:01 +03:00
|
|
|
}
|
|
|
|
|
2009-01-12 22:20:59 +03:00
|
|
|
NS_QUERYFRAME_HEAD(nsFileControlFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsBlockFrame)
|
1998-09-23 21:16:51 +04:00
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFileControlFrame::SetFocus(bool aOn, bool aRepaint)
|
1998-10-23 03:00:37 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-07-29 14:41:38 +03:00
|
|
|
static void
|
|
|
|
AppendBlobImplAsDirectory(nsTArray<OwningFileOrDirectory>& aArray,
|
|
|
|
BlobImpl* aBlobImpl,
|
|
|
|
nsIContent* aContent)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aBlobImpl);
|
|
|
|
MOZ_ASSERT(aBlobImpl->IsDirectory());
|
|
|
|
|
|
|
|
nsAutoString fullpath;
|
|
|
|
ErrorResult err;
|
2017-02-01 23:43:37 +03:00
|
|
|
aBlobImpl->GetMozFullPath(fullpath, SystemCallerGuarantee(), err);
|
2016-07-29 14:41:38 +03:00
|
|
|
if (err.Failed()) {
|
|
|
|
err.SuppressException();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> file;
|
2017-01-21 09:36:10 +03:00
|
|
|
nsresult rv = NS_NewLocalFile(fullpath, true, getter_AddRefs(file));
|
2016-07-29 14:41:38 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPIDOMWindowInner* inner = aContent->OwnerDoc()->GetInnerWindow();
|
|
|
|
if (!inner || !inner->IsCurrentInnerWindow()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<Directory> directory =
|
|
|
|
Directory::Create(inner, file);
|
|
|
|
MOZ_ASSERT(directory);
|
|
|
|
|
|
|
|
OwningFileOrDirectory* element = aArray.AppendElement();
|
|
|
|
element->SetAsDirectory() = directory;
|
|
|
|
}
|
|
|
|
|
2011-06-01 10:06:38 +04:00
|
|
|
/**
|
2013-03-27 15:32:00 +04:00
|
|
|
* This is called when we receive a drop or a dragover.
|
2011-06-01 10:06:38 +04:00
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
2013-03-27 15:32:00 +04:00
|
|
|
nsFileControlFrame::DnDListener::HandleEvent(nsIDOMEvent* aEvent)
|
2011-06-01 10:06:38 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mFrame, "We should have been unregistered");
|
2011-06-29 22:07:57 +04:00
|
|
|
|
2018-03-13 23:23:59 +03:00
|
|
|
Event* event = aEvent->InternalDOMEvent();
|
|
|
|
if (event->DefaultPrevented()) {
|
2011-06-01 10:06:38 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-03-27 15:32:00 +04:00
|
|
|
|
2018-03-13 23:23:59 +03:00
|
|
|
DragEvent* dragEvent = event->AsDragEvent();
|
2014-11-18 18:58:08 +03:00
|
|
|
if (!dragEvent) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-03-13 23:23:59 +03:00
|
|
|
RefPtr<DataTransfer> dataTransfer = dragEvent->GetDataTransfer();
|
2014-11-18 18:58:08 +03:00
|
|
|
if (!IsValidDropData(dataTransfer)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-07 21:13:50 +03:00
|
|
|
RefPtr<HTMLInputElement> inputElement =
|
|
|
|
HTMLInputElement::FromContent(mFrame->GetContent());
|
|
|
|
bool supportsMultiple =
|
|
|
|
inputElement->HasAttr(kNameSpaceID_None, nsGkAtoms::multiple);
|
2014-11-18 18:58:08 +03:00
|
|
|
if (!CanDropTheseFiles(dataTransfer, supportsMultiple)) {
|
|
|
|
dataTransfer->SetDropEffect(NS_LITERAL_STRING("none"));
|
|
|
|
aEvent->StopPropagation();
|
2011-06-01 10:06:38 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-03-27 15:32:00 +04:00
|
|
|
nsAutoString eventType;
|
|
|
|
aEvent->GetType(eventType);
|
2011-06-01 10:06:38 +04:00
|
|
|
if (eventType.EqualsLiteral("dragover")) {
|
|
|
|
// Prevent default if we can accept this drag data
|
|
|
|
aEvent->PreventDefault();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eventType.EqualsLiteral("drop")) {
|
|
|
|
aEvent->StopPropagation();
|
|
|
|
aEvent->PreventDefault();
|
|
|
|
|
2018-03-13 23:24:00 +03:00
|
|
|
RefPtr<FileList> fileList =
|
|
|
|
dataTransfer->GetFiles(*nsContentUtils::GetSystemPrincipal());
|
2011-06-10 16:44:53 +04:00
|
|
|
|
2016-07-29 14:41:38 +03:00
|
|
|
RefPtr<BlobImpl> webkitDir;
|
|
|
|
nsresult rv =
|
|
|
|
GetBlobImplForWebkitDirectory(fileList, getter_AddRefs(webkitDir));
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_OK);
|
|
|
|
|
|
|
|
nsTArray<OwningFileOrDirectory> array;
|
|
|
|
if (webkitDir) {
|
2017-12-07 21:13:50 +03:00
|
|
|
AppendBlobImplAsDirectory(array, webkitDir, inputElement);
|
2016-07-29 14:41:38 +03:00
|
|
|
inputElement->MozSetDndFilesAndDirectories(array);
|
|
|
|
} else {
|
|
|
|
bool blinkFileSystemEnabled =
|
|
|
|
Preferences::GetBool("dom.webkitBlink.filesystem.enabled", false);
|
2017-02-16 20:23:33 +03:00
|
|
|
bool dirPickerEnabled =
|
|
|
|
Preferences::GetBool("dom.input.dirpicker", false);
|
|
|
|
if (blinkFileSystemEnabled || dirPickerEnabled) {
|
2016-07-29 14:41:38 +03:00
|
|
|
FileList* files = static_cast<FileList*>(fileList.get());
|
|
|
|
if (files) {
|
|
|
|
for (uint32_t i = 0; i < files->Length(); ++i) {
|
|
|
|
File* file = files->Item(i);
|
|
|
|
if (file) {
|
|
|
|
if (file->Impl() && file->Impl()->IsDirectory()) {
|
2017-12-07 21:13:50 +03:00
|
|
|
AppendBlobImplAsDirectory(array, file->Impl(), inputElement);
|
2016-07-29 14:41:38 +03:00
|
|
|
} else {
|
|
|
|
OwningFileOrDirectory* element = array.AppendElement();
|
|
|
|
element->SetAsFile() = file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-16 20:23:33 +03:00
|
|
|
// Entries API.
|
2016-07-29 14:41:38 +03:00
|
|
|
if (blinkFileSystemEnabled) {
|
2017-02-16 20:23:33 +03:00
|
|
|
// This is rather ugly. Pass the directories as Files using SetFiles,
|
|
|
|
// but then if blink filesystem API is enabled, it wants
|
|
|
|
// FileOrDirectory array.
|
|
|
|
inputElement->SetFiles(fileList, true);
|
2016-07-29 14:41:38 +03:00
|
|
|
inputElement->UpdateEntries(array);
|
|
|
|
}
|
2017-02-16 20:23:33 +03:00
|
|
|
// Directory Upload API
|
|
|
|
else if (dirPickerEnabled) {
|
|
|
|
inputElement->SetFilesOrDirectories(array, true);
|
|
|
|
}
|
|
|
|
// Normal DnD
|
|
|
|
else {
|
|
|
|
inputElement->SetFiles(fileList, true);
|
|
|
|
}
|
|
|
|
|
2017-12-07 21:13:50 +03:00
|
|
|
nsContentUtils::DispatchTrustedEvent(inputElement->OwnerDoc(),
|
|
|
|
static_cast<nsINode*>(inputElement),
|
2016-07-29 14:41:38 +03:00
|
|
|
NS_LITERAL_STRING("input"), true,
|
|
|
|
false);
|
2017-12-07 21:13:50 +03:00
|
|
|
nsContentUtils::DispatchTrustedEvent(inputElement->OwnerDoc(),
|
|
|
|
static_cast<nsINode*>(inputElement),
|
2016-07-29 14:41:38 +03:00
|
|
|
NS_LITERAL_STRING("change"), true,
|
|
|
|
false);
|
|
|
|
}
|
2011-06-01 10:06:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-07-29 14:41:38 +03:00
|
|
|
nsresult
|
|
|
|
nsFileControlFrame::DnDListener::GetBlobImplForWebkitDirectory(nsIDOMFileList* aFileList,
|
|
|
|
BlobImpl** aBlobImpl)
|
|
|
|
{
|
|
|
|
*aBlobImpl = nullptr;
|
|
|
|
|
|
|
|
HTMLInputElement* inputElement =
|
|
|
|
HTMLInputElement::FromContent(mFrame->GetContent());
|
|
|
|
bool webkitDirPicker =
|
2018-01-08 16:05:05 +03:00
|
|
|
DOMPrefs::WebkitBlinkDirectoryPickerEnabled() &&
|
2016-07-29 14:41:38 +03:00
|
|
|
inputElement->HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory);
|
|
|
|
if (!webkitDirPicker) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aFileList) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileList* files = static_cast<FileList*>(aFileList);
|
|
|
|
// webkitdirectory doesn't care about the length of the file list but
|
|
|
|
// only about the first item on it.
|
|
|
|
uint32_t len = files->Length();
|
|
|
|
if (len) {
|
|
|
|
File* file = files->Item(0);
|
|
|
|
if (file) {
|
|
|
|
BlobImpl* impl = file->Impl();
|
|
|
|
if (impl && impl->IsDirectory()) {
|
|
|
|
RefPtr<BlobImpl> retVal = impl;
|
|
|
|
retVal.swap(*aBlobImpl);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-03-13 23:24:00 +03:00
|
|
|
nsFileControlFrame::DnDListener::IsValidDropData(DataTransfer* aDataTransfer)
|
2011-06-01 10:06:38 +04:00
|
|
|
{
|
|
|
|
// We only support dropping files onto a file upload control
|
2016-10-11 04:07:47 +03:00
|
|
|
nsTArray<nsString> types;
|
2018-03-13 23:24:00 +03:00
|
|
|
aDataTransfer->GetTypes(types, CallerType::System);
|
2015-08-28 22:21:08 +03:00
|
|
|
|
2016-10-11 04:07:47 +03:00
|
|
|
return types.Contains(NS_LITERAL_STRING("Files"));
|
2011-06-01 10:06:38 +04:00
|
|
|
}
|
|
|
|
|
2016-07-29 14:41:38 +03:00
|
|
|
bool
|
2018-03-13 23:24:00 +03:00
|
|
|
nsFileControlFrame::DnDListener::CanDropTheseFiles(DataTransfer* aDataTransfer,
|
2014-11-18 18:58:08 +03:00
|
|
|
bool aSupportsMultiple)
|
|
|
|
{
|
2018-03-13 23:24:00 +03:00
|
|
|
RefPtr<FileList> fileList =
|
2018-03-13 23:24:00 +03:00
|
|
|
aDataTransfer->GetFiles(*nsContentUtils::GetSystemPrincipal());
|
2014-11-18 18:58:08 +03:00
|
|
|
|
2016-07-29 14:41:38 +03:00
|
|
|
RefPtr<BlobImpl> webkitDir;
|
|
|
|
nsresult rv =
|
|
|
|
GetBlobImplForWebkitDirectory(fileList, getter_AddRefs(webkitDir));
|
|
|
|
// Just check if either there isn't webkitdirectory attribute, or
|
|
|
|
// fileList has a directory which can be dropped to the element.
|
|
|
|
// No need to use webkitDir for anything here.
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
2014-11-18 18:58:08 +03:00
|
|
|
uint32_t listLength = 0;
|
|
|
|
if (fileList) {
|
|
|
|
fileList->GetLength(&listLength);
|
|
|
|
}
|
|
|
|
return listLength <= 1 || aSupportsMultiple;
|
|
|
|
}
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nscoord
|
2017-06-09 22:14:53 +03:00
|
|
|
nsFileControlFrame::GetMinISize(gfxContext *aRenderingContext)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
{
|
|
|
|
nscoord result;
|
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
|
|
|
|
|
|
|
// Our min width is our pref width
|
2014-07-24 21:03:25 +04:00
|
|
|
result = GetPrefISize(aRenderingContext);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
return result;
|
|
|
|
}
|
1998-09-23 21:16:51 +04:00
|
|
|
|
2010-12-14 21:00:57 +03:00
|
|
|
void
|
|
|
|
nsFileControlFrame::SyncDisabledState()
|
|
|
|
{
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates eventStates = mContent->AsElement()->State();
|
2010-12-14 21:00:57 +03:00
|
|
|
if (eventStates.HasState(NS_EVENT_STATE_DISABLED)) {
|
2016-06-29 19:18:42 +03:00
|
|
|
mBrowseFilesOrDirs->SetAttr(kNameSpaceID_None, nsGkAtoms::disabled,
|
|
|
|
EmptyString(), true);
|
2010-12-14 21:00:57 +03:00
|
|
|
} else {
|
2016-06-29 19:18:42 +03:00
|
|
|
mBrowseFilesOrDirs->UnsetAttr(kNameSpaceID_None, nsGkAtoms::disabled, true);
|
2010-12-14 21:00:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2013-02-09 18:57:30 +04:00
|
|
|
nsFileControlFrame::AttributeChanged(int32_t aNameSpaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute,
|
2013-02-09 18:57:30 +04:00
|
|
|
int32_t aModType)
|
1999-08-19 18:03:53 +04:00
|
|
|
{
|
2013-02-09 18:57:30 +04:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None && aAttribute == nsGkAtoms::tabindex) {
|
2018-02-09 19:17:10 +03:00
|
|
|
if (aModType == MutationEventBinding::REMOVAL) {
|
2016-06-29 19:18:42 +03:00
|
|
|
mBrowseFilesOrDirs->UnsetAttr(aNameSpaceID, aAttribute, true);
|
2013-02-09 18:57:30 +04:00
|
|
|
} else {
|
|
|
|
nsAutoString value;
|
2017-12-07 21:13:50 +03:00
|
|
|
mContent->AsElement()->GetAttr(aNameSpaceID, aAttribute, value);
|
2016-06-29 19:18:42 +03:00
|
|
|
mBrowseFilesOrDirs->SetAttr(aNameSpaceID, aAttribute, value, true);
|
2008-12-17 10:33:33 +03:00
|
|
|
}
|
1999-08-19 18:03:53 +04:00
|
|
|
}
|
|
|
|
|
2008-12-29 18:07:38 +03:00
|
|
|
return nsBlockFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
|
1999-08-19 18:03:53 +04:00
|
|
|
}
|
|
|
|
|
2010-12-14 21:00:57 +03:00
|
|
|
void
|
2014-04-03 08:18:36 +04:00
|
|
|
nsFileControlFrame::ContentStatesChanged(EventStates aStates)
|
2010-12-14 21:00:57 +03:00
|
|
|
{
|
|
|
|
if (aStates.HasState(NS_EVENT_STATE_DISABLED)) {
|
|
|
|
nsContentUtils::AddScriptRunner(new SyncDisabledStateEvent(this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-06 03:31:14 +04:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2001-11-14 04:33:42 +03:00
|
|
|
nsFileControlFrame::GetFrameName(nsAString& aResult) const
|
1998-11-19 20:22:29 +03:00
|
|
|
{
|
2001-11-14 04:33:42 +03:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("FileControl"), aResult);
|
1998-11-19 20:22:29 +03:00
|
|
|
}
|
1999-11-02 01:12:45 +03:00
|
|
|
#endif
|
1999-01-22 18:32:57 +03:00
|
|
|
|
2013-02-09 18:57:30 +04:00
|
|
|
void
|
|
|
|
nsFileControlFrame::UpdateDisplayedValue(const nsAString& aValue, bool aNotify)
|
|
|
|
{
|
2013-02-07 17:58:05 +04:00
|
|
|
mTextContent->SetAttr(kNameSpaceID_None, nsGkAtoms::value, aValue, aNotify);
|
2013-02-09 18:57:30 +04:00
|
|
|
}
|
|
|
|
|
2005-12-13 03:57:56 +03:00
|
|
|
nsresult
|
2017-10-03 01:05:19 +03:00
|
|
|
nsFileControlFrame::SetFormProperty(nsAtom* aName,
|
2005-12-13 03:57:56 +03:00
|
|
|
const nsAString& aValue)
|
1999-01-26 01:16:27 +03:00
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
if (nsGkAtoms::value == aName) {
|
2013-02-09 18:57:30 +04:00
|
|
|
UpdateDisplayedValue(aValue, true);
|
1999-02-11 04:13:28 +03:00
|
|
|
}
|
2005-12-13 02:53:06 +03:00
|
|
|
return NS_OK;
|
2013-02-09 18:57:30 +04:00
|
|
|
}
|
1999-01-26 01:16:27 +03:00
|
|
|
|
2013-02-14 15:12:27 +04:00
|
|
|
void
|
2006-01-26 05:29:17 +03:00
|
|
|
nsFileControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayListSet& aLists)
|
1999-02-11 04:13:28 +03:00
|
|
|
{
|
2017-08-07 05:23:35 +03:00
|
|
|
BuildDisplayListForInline(aBuilder, aLists);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
2006-11-14 01:05:25 +03:00
|
|
|
|
2007-09-28 05:09:14 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
2012-09-29 01:53:44 +04:00
|
|
|
a11y::AccType
|
|
|
|
nsFileControlFrame::AccessibleType()
|
2007-09-28 05:09:14 +04:00
|
|
|
{
|
2012-12-18 05:25:52 +04:00
|
|
|
return a11y::eHTMLFileInputType;
|
2007-09-28 05:09:14 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-11-14 01:05:25 +03:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Mouse listener implementation
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsFileControlFrame::MouseListener,
|
|
|
|
nsIDOMEventListener)
|