2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-09-23 21:16:51 +04:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1998-09-23 21:16:51 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-09-23 21:16:51 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
2007-02-24 07:42:53 +03:00
|
|
|
* Mats Palmgren <mats.palmgren@bredband.net>
|
2010-02-11 11:35:49 +03:00
|
|
|
* Geoff Lankow <geoff@darktrojan.net>
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:30:37 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-09-23 21:16:51 +04:00
|
|
|
|
|
|
|
#include "nsFileControlFrame.h"
|
2000-05-02 07:40:44 +04:00
|
|
|
|
1998-09-23 21:16:51 +04:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "prtypes.h"
|
|
|
|
#include "nsIAtom.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
1998-09-23 21:16:51 +04:00
|
|
|
#include "nsWidgetsCID.h"
|
1999-03-09 12:44:27 +03:00
|
|
|
#include "nsIComponentManager.h"
|
1998-09-23 21:16:51 +04:00
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsIDOMHTMLInputElement.h"
|
|
|
|
#include "nsIFormControl.h"
|
1998-12-20 04:21:23 +03:00
|
|
|
#include "nsINameSpaceManager.h"
|
1999-02-18 03:13:39 +03:00
|
|
|
#include "nsCOMPtr.h"
|
1999-07-01 02:17:43 +04:00
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
2000-12-30 22:22:22 +03:00
|
|
|
#include "nsIDocument.h"
|
1999-07-01 02:17:43 +04:00
|
|
|
#include "nsIDOMMouseListener.h"
|
1999-08-21 04:09:24 +04:00
|
|
|
#include "nsIPresShell.h"
|
2002-09-04 03:36:13 +04:00
|
|
|
#include "nsXPCOM.h"
|
1999-09-15 09:31:31 +04:00
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsIComponentManager.h"
|
2005-11-29 02:56:44 +03:00
|
|
|
#include "nsPIDOMWindow.h"
|
2000-08-18 22:16:12 +04:00
|
|
|
#include "nsIFilePicker.h"
|
2000-08-25 17:25:50 +04:00
|
|
|
#include "nsIDOMMouseEvent.h"
|
2000-12-30 22:22:22 +03:00
|
|
|
#include "nsINodeInfo.h"
|
2007-05-14 13:11:38 +04:00
|
|
|
#include "nsIDOMEventTarget.h"
|
2002-06-04 04:44:04 +04:00
|
|
|
#include "nsILocalFile.h"
|
2006-04-25 13:18:42 +04:00
|
|
|
#include "nsIFileControlElement.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"
|
2006-01-26 05:29:17 +03:00
|
|
|
#include "nsDisplayList.h"
|
2008-01-11 00:55:38 +03:00
|
|
|
#include "nsIDOMNSUIEvent.h"
|
|
|
|
#include "nsIDOMEventGroup.h"
|
|
|
|
#include "nsIDOM3EventTarget.h"
|
2010-08-05 06:40:18 +04:00
|
|
|
#include "nsIDOMHTMLInputElement.h"
|
2007-09-28 05:09:14 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
#include "nsIAccessibilityService.h"
|
|
|
|
#endif
|
2010-02-11 11:35:49 +03:00
|
|
|
|
|
|
|
#include "nsInterfaceHashtable.h"
|
|
|
|
#include "nsURIHashKey.h"
|
|
|
|
#include "nsILocalFile.h"
|
|
|
|
#include "nsIPrivateBrowsingService.h"
|
|
|
|
#include "nsNetCID.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsWeakReference.h"
|
2009-12-23 04:05:26 +03:00
|
|
|
#include "nsIVariant.h"
|
|
|
|
#include "nsIContentPrefService.h"
|
2010-02-11 11:35:49 +03:00
|
|
|
#include "nsIContentURIGrouper.h"
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 20:59:13 +04:00
|
|
|
#include "mozilla/Services.h"
|
2010-05-31 02:54:34 +04:00
|
|
|
#include "nsDirectoryServiceDefs.h"
|
2010-07-21 20:07:55 +04:00
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
2010-07-24 01:35:51 +04:00
|
|
|
#include "nsICapturePicker.h"
|
|
|
|
#include "nsIFileURL.h"
|
1998-09-23 21:16:51 +04:00
|
|
|
|
2002-06-12 11:58:26 +04:00
|
|
|
#define SYNC_TEXT 0x1
|
|
|
|
#define SYNC_BUTTON 0x2
|
|
|
|
#define SYNC_BOTH 0x3
|
|
|
|
|
2010-02-11 11:35:49 +03:00
|
|
|
#define CPS_PREF_NAME NS_LITERAL_STRING("browser.upload.lastDir")
|
|
|
|
|
|
|
|
class UploadLastDir : public nsIObserver, public nsSupportsWeakReference {
|
|
|
|
public:
|
2010-02-11 20:34:01 +03:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
|
|
|
UploadLastDir();
|
2010-02-11 11:35:49 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch the last used directory for this location from the content
|
|
|
|
* pref service, if it is available.
|
|
|
|
*
|
|
|
|
* @param aURI URI of the current page
|
|
|
|
* @param aFile path to the last used directory
|
|
|
|
*/
|
|
|
|
nsresult FetchLastUsedDirectory(nsIURI* aURI, nsILocalFile** aFile);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store the last used directory for this location using the
|
|
|
|
* content pref service, if it is available
|
|
|
|
* @param aURI URI of the current page
|
|
|
|
* @param aFile file chosen by the user - the path to the parent of this
|
|
|
|
* file will be stored
|
|
|
|
*/
|
|
|
|
nsresult StoreLastUsedDirectory(nsIURI* aURI, nsILocalFile* aFile);
|
|
|
|
private:
|
|
|
|
// Directories are stored here during private browsing mode
|
|
|
|
nsInterfaceHashtable<nsStringHashKey, nsILocalFile> mUploadLastDirStore;
|
|
|
|
PRBool mInPrivateBrowsing;
|
|
|
|
};
|
|
|
|
|
2010-02-11 20:34:01 +03:00
|
|
|
NS_IMPL_ISUPPORTS2(UploadLastDir, nsIObserver, nsISupportsWeakReference)
|
2010-02-11 11:35:49 +03:00
|
|
|
UploadLastDir* gUploadLastDir = nsnull;
|
|
|
|
|
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)
|
|
|
|
|
2006-03-27 01:30:36 +04:00
|
|
|
nsFileControlFrame::nsFileControlFrame(nsStyleContext* aContext):
|
2008-12-29 18:07:38 +03:00
|
|
|
nsBlockFrame(aContext),
|
2010-04-22 00:17:41 +04:00
|
|
|
mTextFrame(nsnull)
|
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
|
|
|
|
2006-11-14 01:05:25 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileControlFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
2008-12-29 18:07:38 +03:00
|
|
|
nsresult rv = nsBlockFrame::Init(aContent, aParent, aPrevInFlow);
|
2006-11-14 01:05:25 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-07-24 01:35:51 +04:00
|
|
|
mMouseListener = new BrowseMouseListener(this);
|
2010-07-24 00:16:39 +04:00
|
|
|
NS_ENSURE_TRUE(mMouseListener, NS_ERROR_OUT_OF_MEMORY);
|
2010-07-24 01:35:51 +04:00
|
|
|
mCaptureMouseListener = new CaptureMouseListener(this);
|
|
|
|
NS_ENSURE_TRUE(mCaptureMouseListener, NS_ERROR_OUT_OF_MEMORY);
|
2006-11-14 01:05:25 +03:00
|
|
|
|
2010-02-21 17:52:51 +03:00
|
|
|
if (!gUploadLastDir)
|
|
|
|
nsFileControlFrame::InitUploadLastDir();
|
|
|
|
|
2006-11-14 01:05:25 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2006-04-10 04:16:29 +04:00
|
|
|
void
|
2009-12-24 08:21:15 +03:00
|
|
|
nsFileControlFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2004-05-22 05:17:00 +04:00
|
|
|
{
|
2004-01-18 07:35:54 +03:00
|
|
|
mTextFrame = nsnull;
|
2008-01-11 00:55:38 +03:00
|
|
|
ENSURE_TRUE(mContent);
|
|
|
|
|
2006-11-14 01:05:25 +03:00
|
|
|
// remove mMouseListener as a mouse event listener (bug 40533, bug 355931)
|
2008-01-11 00:55:38 +03:00
|
|
|
NS_NAMED_LITERAL_STRING(click, "click");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMEventGroup> systemGroup;
|
|
|
|
mContent->GetSystemEventGroup(getter_AddRefs(systemGroup));
|
|
|
|
|
2010-07-24 01:35:51 +04:00
|
|
|
nsCOMPtr<nsIDOM3EventTarget> dom3Capture = do_QueryInterface(mCapture);
|
|
|
|
if (dom3Capture) {
|
|
|
|
nsContentUtils::DestroyAnonymousContent(&mCapture);
|
|
|
|
}
|
|
|
|
|
2008-01-11 00:55:38 +03:00
|
|
|
nsCOMPtr<nsIDOM3EventTarget> dom3Browse = do_QueryInterface(mBrowse);
|
|
|
|
if (dom3Browse) {
|
|
|
|
dom3Browse->RemoveGroupedEventListener(click, mMouseListener, PR_FALSE,
|
|
|
|
systemGroup);
|
2007-02-18 20:34:09 +03:00
|
|
|
nsContentUtils::DestroyAnonymousContent(&mBrowse);
|
2006-11-14 01:05:25 +03:00
|
|
|
}
|
2008-01-11 00:55:38 +03:00
|
|
|
nsCOMPtr<nsIDOM3EventTarget> dom3TextContent =
|
|
|
|
do_QueryInterface(mTextContent);
|
|
|
|
if (dom3TextContent) {
|
|
|
|
dom3TextContent->RemoveGroupedEventListener(click, mMouseListener, PR_FALSE,
|
|
|
|
systemGroup);
|
2007-02-18 20:34:09 +03:00
|
|
|
nsContentUtils::DestroyAnonymousContent(&mTextContent);
|
2006-11-14 01:05:25 +03:00
|
|
|
}
|
|
|
|
|
2010-07-24 01:35:51 +04:00
|
|
|
mCaptureMouseListener->ForgetFrame();
|
2006-11-14 01:05:25 +03:00
|
|
|
mMouseListener->ForgetFrame();
|
2009-12-24 08:21:15 +03:00
|
|
|
nsBlockFrame::DestroyFrom(aDestructRoot);
|
2002-12-20 08:40:37 +03:00
|
|
|
}
|
|
|
|
|
2010-07-24 01:35:51 +04:00
|
|
|
struct CaptureCallbackData {
|
|
|
|
nsICapturePicker* picker;
|
|
|
|
PRUint32* mode;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct CaptureCallbackData CaptureCallbackData;
|
|
|
|
|
|
|
|
PRBool CapturePickerAcceptCallback(const nsAString& aAccept, void* aClosure)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
PRBool captureEnabled;
|
|
|
|
CaptureCallbackData* closure = (CaptureCallbackData*)aClosure;
|
|
|
|
|
|
|
|
if (StringBeginsWith(aAccept,
|
|
|
|
NS_LITERAL_STRING("image/"))) {
|
|
|
|
rv = closure->picker->ModeMayBeAvailable(nsICapturePicker::MODE_STILL,
|
|
|
|
&captureEnabled);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (captureEnabled) {
|
|
|
|
*closure->mode = nsICapturePicker::MODE_STILL;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
} else if (StringBeginsWith(aAccept,
|
|
|
|
NS_LITERAL_STRING("audio/"))) {
|
|
|
|
rv = closure->picker->ModeMayBeAvailable(nsICapturePicker::MODE_AUDIO_CLIP,
|
|
|
|
&captureEnabled);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (captureEnabled) {
|
|
|
|
*closure->mode = nsICapturePicker::MODE_AUDIO_CLIP;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
} else if (StringBeginsWith(aAccept,
|
|
|
|
NS_LITERAL_STRING("video/"))) {
|
|
|
|
rv = closure->picker->ModeMayBeAvailable(nsICapturePicker::MODE_VIDEO_CLIP,
|
|
|
|
&captureEnabled);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (captureEnabled) {
|
|
|
|
*closure->mode = nsICapturePicker::MODE_VIDEO_CLIP;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
rv = closure->picker->ModeMayBeAvailable(nsICapturePicker::MODE_VIDEO_NO_SOUND_CLIP,
|
|
|
|
&captureEnabled);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (captureEnabled) {
|
|
|
|
*closure->mode = nsICapturePicker::MODE_VIDEO_NO_SOUND_CLIP;
|
|
|
|
return PR_FALSE;;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-02-18 20:34:09 +03:00
|
|
|
nsresult
|
|
|
|
nsFileControlFrame::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
|
1999-07-01 02:17:43 +04:00
|
|
|
{
|
2002-06-12 11:58:26 +04:00
|
|
|
// Get the NodeInfoManager and tag necessary to create input elements
|
2003-07-29 01:25:13 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = mContent->GetDocument();
|
2000-05-10 17:13:39 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
2008-09-13 02:32:18 +04:00
|
|
|
nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::input, nsnull,
|
2009-06-09 11:41:19 +04:00
|
|
|
kNameSpaceID_XHTML);
|
2001-02-20 00:50:04 +03:00
|
|
|
|
2002-06-12 11:58:26 +04:00
|
|
|
// Create the text content
|
2010-07-23 13:49:57 +04:00
|
|
|
NS_NewHTMLElement(getter_AddRefs(mTextContent), nodeInfo.forget(), PR_FALSE);
|
2007-02-18 20:34:09 +03:00
|
|
|
if (!mTextContent)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2009-01-31 15:34:01 +03:00
|
|
|
// Mark the element to be native anonymous before setting any attributes.
|
|
|
|
mTextContent->SetNativeAnonymous();
|
|
|
|
|
2007-02-18 20:34:09 +03:00
|
|
|
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;
|
2009-10-25 07:13:30 +03:00
|
|
|
fileControl->GetDisplayFileName(value);
|
2007-02-18 20:34:09 +03:00
|
|
|
textControl->SetValue(value);
|
1999-08-19 18:03:53 +04:00
|
|
|
}
|
2005-10-01 02:01:54 +04:00
|
|
|
|
2007-02-18 20:34:09 +03:00
|
|
|
textControl->SetTabIndex(-1);
|
|
|
|
textControl->SetReadOnly(PR_TRUE);
|
1999-08-19 18:03:53 +04:00
|
|
|
}
|
1999-07-01 02:17:43 +04:00
|
|
|
|
2007-02-18 20:34:09 +03:00
|
|
|
if (!aElements.AppendElement(mTextContent))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-07-01 02:17:43 +04:00
|
|
|
|
2008-01-11 00:55:38 +03:00
|
|
|
NS_NAMED_LITERAL_STRING(click, "click");
|
|
|
|
nsCOMPtr<nsIDOMEventGroup> systemGroup;
|
|
|
|
mContent->GetSystemEventGroup(getter_AddRefs(systemGroup));
|
|
|
|
nsCOMPtr<nsIDOM3EventTarget> dom3TextContent =
|
|
|
|
do_QueryInterface(mTextContent);
|
|
|
|
NS_ENSURE_STATE(dom3TextContent);
|
|
|
|
// Register as an event listener of the textbox
|
|
|
|
// to open file dialog on mouse click
|
|
|
|
dom3TextContent->AddGroupedEventListener(click, mMouseListener, PR_FALSE,
|
|
|
|
systemGroup);
|
1999-08-19 18:03:53 +04:00
|
|
|
|
2007-02-18 20:34:09 +03:00
|
|
|
// Create the browse button
|
2010-07-23 13:49:57 +04:00
|
|
|
nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::input, nsnull,
|
|
|
|
kNameSpaceID_XHTML);
|
|
|
|
NS_NewHTMLElement(getter_AddRefs(mBrowse), nodeInfo.forget(), PR_FALSE);
|
2007-02-18 20:34:09 +03:00
|
|
|
if (!mBrowse)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2009-01-31 15:34:01 +03:00
|
|
|
// Mark the element to be native anonymous before setting any attributes.
|
|
|
|
mBrowse->SetNativeAnonymous();
|
|
|
|
|
2007-02-18 20:34:09 +03:00
|
|
|
mBrowse->SetAttr(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
NS_LITERAL_STRING("button"), PR_FALSE);
|
2010-07-24 01:35:51 +04:00
|
|
|
|
|
|
|
// Create the capture button
|
|
|
|
nsCOMPtr<nsICapturePicker> capturePicker;
|
|
|
|
capturePicker = do_GetService("@mozilla.org/capturepicker;1");
|
|
|
|
if (capturePicker) {
|
|
|
|
PRUint32 mode = 0;
|
|
|
|
|
|
|
|
CaptureCallbackData data;
|
|
|
|
data.picker = capturePicker;
|
|
|
|
data.mode = &mode;
|
|
|
|
ParseAcceptAttribute(&CapturePickerAcceptCallback, (void*)&data);
|
|
|
|
|
|
|
|
if (mode != 0) {
|
|
|
|
mCaptureMouseListener->mMode = mode;
|
|
|
|
nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::input, nsnull,
|
|
|
|
kNameSpaceID_XHTML);
|
|
|
|
NS_NewHTMLElement(getter_AddRefs(mCapture), nodeInfo.forget(), PR_FALSE);
|
|
|
|
if (!mCapture)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
// Mark the element to be native anonymous before setting any attributes.
|
|
|
|
mCapture->SetNativeAnonymous();
|
|
|
|
|
|
|
|
mCapture->SetAttr(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
NS_LITERAL_STRING("button"), PR_FALSE);
|
|
|
|
|
|
|
|
mCapture->SetAttr(kNameSpaceID_None, nsGkAtoms::value,
|
|
|
|
NS_LITERAL_STRING("capture"), PR_FALSE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> captureEventTarget =
|
|
|
|
do_QueryInterface(mCapture);
|
|
|
|
captureEventTarget->AddEventListener(click, mCaptureMouseListener, PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
2007-02-18 20:34:09 +03:00
|
|
|
nsCOMPtr<nsIDOMHTMLInputElement> fileContent = do_QueryInterface(mContent);
|
|
|
|
nsCOMPtr<nsIDOMHTMLInputElement> browseControl = do_QueryInterface(mBrowse);
|
|
|
|
if (fileContent && browseControl) {
|
|
|
|
PRInt32 tabIndex;
|
|
|
|
nsAutoString accessKey;
|
|
|
|
|
|
|
|
fileContent->GetAccessKey(accessKey);
|
|
|
|
browseControl->SetAccessKey(accessKey);
|
|
|
|
fileContent->GetTabIndex(&tabIndex);
|
|
|
|
browseControl->SetTabIndex(tabIndex);
|
1999-08-19 18:03:53 +04:00
|
|
|
}
|
1999-07-01 02:17:43 +04:00
|
|
|
|
2007-02-18 20:34:09 +03:00
|
|
|
if (!aElements.AppendElement(mBrowse))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2010-07-24 01:35:51 +04:00
|
|
|
if (mCapture && !aElements.AppendElement(mCapture))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2008-01-11 00:55:38 +03:00
|
|
|
nsCOMPtr<nsIDOM3EventTarget> dom3Browse = do_QueryInterface(mBrowse);
|
|
|
|
NS_ENSURE_STATE(dom3Browse);
|
|
|
|
// Register as an event listener of the button
|
|
|
|
// to open file dialog on mouse click
|
|
|
|
dom3Browse->AddGroupedEventListener(click, mMouseListener, PR_FALSE,
|
|
|
|
systemGroup);
|
2007-02-18 20:34:09 +03:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
SyncAttr(kNameSpaceID_None, nsGkAtoms::size, SYNC_TEXT);
|
|
|
|
SyncAttr(kNameSpaceID_None, nsGkAtoms::disabled, SYNC_BOTH);
|
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
|
2010-02-21 03:52:50 +03:00
|
|
|
nsFileControlFrame::AppendAnonymousContentTo(nsBaseContentList& aElements)
|
2010-02-11 20:34:01 +03:00
|
|
|
{
|
|
|
|
aElements.MaybeAppendElement(mTextContent);
|
|
|
|
aElements.MaybeAppendElement(mBrowse);
|
2010-07-24 01:35:51 +04:00
|
|
|
aElements.MaybeAppendElement(mCapture);
|
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
|
|
|
|
1998-10-23 03:00:37 +04:00
|
|
|
void
|
|
|
|
nsFileControlFrame::SetFocus(PRBool aOn, PRBool aRepaint)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-07-24 01:35:51 +04:00
|
|
|
PRBool ShouldProcessMouseClick(nsIDOMEvent* aMouseEvent)
|
1998-09-23 21:16:51 +04:00
|
|
|
{
|
2000-08-25 17:25:50 +04:00
|
|
|
// only allow the left button
|
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aMouseEvent);
|
2008-01-11 00:55:38 +03:00
|
|
|
nsCOMPtr<nsIDOMNSUIEvent> uiEvent = do_QueryInterface(aMouseEvent);
|
|
|
|
NS_ENSURE_STATE(uiEvent);
|
|
|
|
PRBool defaultPrevented = PR_FALSE;
|
|
|
|
uiEvent->GetPreventDefault(&defaultPrevented);
|
|
|
|
if (defaultPrevented) {
|
2010-07-24 01:35:51 +04:00
|
|
|
return PR_FALSE;
|
2000-08-25 17:25:50 +04:00
|
|
|
}
|
|
|
|
|
2008-01-11 00:55:38 +03:00
|
|
|
PRUint16 whichButton;
|
|
|
|
if (NS_FAILED(mouseEvent->GetButton(&whichButton)) || whichButton != 0) {
|
2010-07-24 01:35:51 +04:00
|
|
|
return PR_FALSE;
|
2008-01-11 00:55:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 clickCount;
|
|
|
|
if (NS_FAILED(mouseEvent->GetDetail(&clickCount)) || clickCount > 1) {
|
2010-07-24 01:35:51 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is called when our capture button is clicked
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileControlFrame::CaptureMouseListener::MouseClick(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
NS_ASSERTION(mFrame, "We should have been unregistered");
|
|
|
|
if (!ShouldProcessMouseClick(aMouseEvent))
|
2008-01-11 00:55:38 +03:00
|
|
|
return NS_OK;
|
2010-07-24 01:35:51 +04:00
|
|
|
|
|
|
|
// Get parent nsIDOMWindowInternal object.
|
|
|
|
nsIContent* content = mFrame->GetContent();
|
2010-08-05 06:40:18 +04:00
|
|
|
nsCOMPtr<nsIDOMHTMLInputElement> inputElem = do_QueryInterface(content);
|
2010-07-24 01:35:51 +04:00
|
|
|
nsCOMPtr<nsIFileControlElement> fileControl = do_QueryInterface(content);
|
|
|
|
if (!content || !inputElem || !fileControl)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc = content->GetDocument();
|
|
|
|
if (!doc)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// Get Loc title
|
|
|
|
nsXPIDLString title;
|
|
|
|
nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
|
|
|
|
"FileUpload", title);
|
|
|
|
|
|
|
|
nsPIDOMWindow* win = doc->GetWindow();
|
|
|
|
if (!win) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsICapturePicker> capturePicker;
|
|
|
|
capturePicker = do_CreateInstance("@mozilla.org/capturepicker;1");
|
|
|
|
if (!capturePicker)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
rv = capturePicker->Init(win, title, mMode);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Tell our textframe to remember the currently focused value
|
|
|
|
mFrame->mTextFrame->InitFocusedValue();
|
|
|
|
|
|
|
|
// Show dialog
|
|
|
|
PRUint32 result;
|
|
|
|
rv = capturePicker->Show(&result);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (result == nsICapturePicker::RETURN_CANCEL)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (!mFrame) {
|
|
|
|
// The frame got destroyed while the filepicker was up. Don't do
|
|
|
|
// anything here.
|
|
|
|
// (This listener itself can't be destroyed because the event listener
|
|
|
|
// manager holds a strong reference to us while it fires the event.)
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = capturePicker->GetUri(getter_AddRefs(uri));
|
|
|
|
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));
|
|
|
|
} else {
|
|
|
|
return NS_ERROR_FAILURE;
|
2008-01-11 00:55:38 +03:00
|
|
|
}
|
2000-08-25 17:25:50 +04:00
|
|
|
|
2010-07-24 01:35:51 +04:00
|
|
|
// 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()) {
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
mFrame->mTextFrame->SetFireChangeEventState(oldState);
|
|
|
|
// May need to fire an onchange here
|
|
|
|
mFrame->mTextFrame->CheckFireOnChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is called when our browse button is clicked
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileControlFrame::BrowseMouseListener::MouseClick(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
NS_ASSERTION(mFrame, "We should have been unregistered");
|
|
|
|
if (!ShouldProcessMouseClick(aMouseEvent))
|
|
|
|
return NS_OK;
|
2000-06-07 05:21:20 +04:00
|
|
|
|
2000-09-01 05:54:35 +04:00
|
|
|
// Get parent nsIDOMWindowInternal object.
|
2008-08-15 14:21:31 +04:00
|
|
|
nsIContent* content = mFrame->GetContent();
|
2010-08-05 06:40:18 +04:00
|
|
|
nsCOMPtr<nsIDOMHTMLInputElement> inputElem = do_QueryInterface(content);
|
2009-10-25 07:13:30 +03:00
|
|
|
nsCOMPtr<nsIFileControlElement> fileControl = do_QueryInterface(content);
|
|
|
|
if (!content || !inputElem || !fileControl)
|
2003-07-04 16:50:32 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-08-18 22:16:12 +04:00
|
|
|
|
2003-07-29 01:25:13 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = content->GetDocument();
|
2000-08-18 22:16:12 +04:00
|
|
|
if (!doc)
|
2003-07-29 01:25:13 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-08-18 22:16:12 +04:00
|
|
|
|
|
|
|
// Get Loc title
|
2005-01-19 02:46:59 +03:00
|
|
|
nsXPIDLString title;
|
2004-12-17 23:40:48 +03:00
|
|
|
nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
|
|
|
|
"FileUpload", title);
|
2000-05-27 17:03:18 +04:00
|
|
|
|
2000-09-14 03:57:52 +04:00
|
|
|
nsCOMPtr<nsIFilePicker> filePicker = do_CreateInstance("@mozilla.org/filepicker;1");
|
2000-08-18 22:16:12 +04:00
|
|
|
if (!filePicker)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2008-09-28 23:14:28 +04:00
|
|
|
nsPIDOMWindow* win = doc->GetWindow();
|
|
|
|
if (!win) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2009-10-25 07:13:30 +03:00
|
|
|
PRBool multi;
|
2010-07-24 01:35:51 +04:00
|
|
|
rv = inputElem->GetMultiple(&multi);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-10-25 07:13:30 +03:00
|
|
|
|
2010-07-24 01:35:51 +04:00
|
|
|
rv = filePicker->Init(win, title, multi ?
|
|
|
|
(PRInt16)nsIFilePicker::modeOpenMultiple :
|
|
|
|
(PRInt16)nsIFilePicker::modeOpen);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2000-08-18 22:16:12 +04:00
|
|
|
|
2010-05-20 06:28:01 +04:00
|
|
|
// We want to get the file filter from the accept attribute and we add the
|
|
|
|
// |filterAll| filter to be sure the user has a valid fallback.
|
|
|
|
PRUint32 filter = mFrame->GetFileFilterFromAccept();
|
|
|
|
filePicker->AppendFilters(filter | nsIFilePicker::filterAll);
|
|
|
|
|
|
|
|
// If the accept attribute asks for a filter, it has to be the default one.
|
|
|
|
if (filter) {
|
|
|
|
// We have two filters: |filterAll| and another one. |filterAll| is
|
|
|
|
// always the first one (index=0) so we can assume the one we want to be
|
|
|
|
// the default is at index 1.
|
|
|
|
filePicker->SetFilterIndex(1);
|
|
|
|
}
|
2000-08-18 22:16:12 +04:00
|
|
|
|
|
|
|
// Set default directry and filename
|
|
|
|
nsAutoString defaultName;
|
|
|
|
|
2009-10-25 07:13:30 +03:00
|
|
|
nsCOMArray<nsIFile> oldFiles;
|
|
|
|
fileControl->GetFileArray(oldFiles);
|
|
|
|
|
|
|
|
if (oldFiles.Count()) {
|
|
|
|
// set directory
|
|
|
|
nsCOMPtr<nsIFile> parentFile;
|
|
|
|
oldFiles[0]->GetParent(getter_AddRefs(parentFile));
|
|
|
|
if (parentFile) {
|
2010-07-24 01:35:51 +04:00
|
|
|
nsCOMPtr<nsILocalFile> parentLocalFile = do_QueryInterface(parentFile, &rv);
|
2009-10-25 07:13:30 +03:00
|
|
|
if (parentLocalFile) {
|
|
|
|
filePicker->SetDisplayDirectory(parentLocalFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unfortunately nsIFilePicker doesn't allow multiple files to be
|
|
|
|
// default-selected, so only select something by default if exactly
|
|
|
|
// one file was selected before.
|
|
|
|
if (oldFiles.Count() == 1) {
|
2002-05-08 03:07:19 +04:00
|
|
|
nsAutoString leafName;
|
2009-10-25 07:13:30 +03:00
|
|
|
oldFiles[0]->GetLeafName(leafName);
|
2002-04-27 09:33:09 +04:00
|
|
|
if (!leafName.IsEmpty()) {
|
2004-04-22 03:38:22 +04:00
|
|
|
filePicker->SetDefaultString(leafName);
|
2000-08-18 22:16:12 +04:00
|
|
|
}
|
|
|
|
}
|
2009-12-23 04:05:26 +03:00
|
|
|
} else {
|
|
|
|
// Attempt to retrieve the last used directory from the content pref service
|
2010-02-11 11:35:49 +03:00
|
|
|
nsCOMPtr<nsILocalFile> localFile;
|
2010-05-31 02:54:34 +04:00
|
|
|
gUploadLastDir->FetchLastUsedDirectory(doc->GetDocumentURI(),
|
|
|
|
getter_AddRefs(localFile));
|
|
|
|
if (!localFile) {
|
2010-05-31 17:55:06 +04:00
|
|
|
// Default to "desktop" directory for each platform
|
2010-05-31 02:54:34 +04:00
|
|
|
nsCOMPtr<nsIFile> homeDir;
|
2010-05-31 17:55:06 +04:00
|
|
|
NS_GetSpecialDirectory(NS_OS_DESKTOP_DIR, getter_AddRefs(homeDir));
|
2010-05-31 02:54:34 +04:00
|
|
|
localFile = do_QueryInterface(homeDir);
|
|
|
|
}
|
|
|
|
filePicker->SetDisplayDirectory(localFile);
|
2000-08-18 22:16:12 +04:00
|
|
|
}
|
|
|
|
|
2004-02-20 01:13:47 +03:00
|
|
|
// Tell our textframe to remember the currently focused value
|
2008-08-15 14:21:31 +04:00
|
|
|
mFrame->mTextFrame->InitFocusedValue();
|
2004-02-20 01:13:47 +03:00
|
|
|
|
2000-08-18 22:16:12 +04:00
|
|
|
// Open dialog
|
|
|
|
PRInt16 mode;
|
2010-07-24 01:35:51 +04:00
|
|
|
rv = filePicker->Show(&mode);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-08-11 03:40:29 +04:00
|
|
|
if (mode == nsIFilePicker::returnCancel)
|
|
|
|
return NS_OK;
|
2000-08-18 22:16:12 +04:00
|
|
|
|
2008-08-15 14:21:31 +04:00
|
|
|
if (!mFrame) {
|
|
|
|
// The frame got destroyed while the filepicker was up. Don't do
|
|
|
|
// anything here.
|
|
|
|
// (This listener itself can't be destroyed because the event listener
|
|
|
|
// manager holds a strong reference to us while it fires the event.)
|
2004-01-18 07:35:54 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-10-25 07:13:30 +03:00
|
|
|
// Collect new selected filenames
|
|
|
|
nsTArray<nsString> newFileNames;
|
|
|
|
if (multi) {
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> iter;
|
2010-07-24 01:35:51 +04:00
|
|
|
rv = filePicker->GetFiles(getter_AddRefs(iter));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-10-25 07:13:30 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> tmp;
|
2009-12-23 04:05:26 +03:00
|
|
|
PRBool prefSaved = PR_FALSE;
|
2009-10-25 07:13:30 +03:00
|
|
|
while (NS_SUCCEEDED(iter->GetNext(getter_AddRefs(tmp)))) {
|
2010-02-11 11:35:49 +03:00
|
|
|
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(tmp);
|
|
|
|
if (localFile) {
|
2009-10-25 07:13:30 +03:00
|
|
|
nsString unicodePath;
|
2010-07-24 01:35:51 +04:00
|
|
|
rv = localFile->GetPath(unicodePath);
|
2009-10-25 07:13:30 +03:00
|
|
|
if (!unicodePath.IsEmpty()) {
|
|
|
|
newFileNames.AppendElement(unicodePath);
|
|
|
|
}
|
2009-12-23 04:05:26 +03:00
|
|
|
if (!prefSaved) {
|
|
|
|
// Store the last used directory using the content pref service
|
2010-07-24 01:35:51 +04:00
|
|
|
rv = gUploadLastDir->StoreLastUsedDirectory(doc->GetDocumentURI(),
|
|
|
|
localFile);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-23 04:05:26 +03:00
|
|
|
prefSaved = PR_TRUE;
|
|
|
|
}
|
2009-10-25 07:13:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsILocalFile> localFile;
|
2010-07-24 01:35:51 +04:00
|
|
|
rv = filePicker->GetFile(getter_AddRefs(localFile));
|
2009-10-25 07:13:30 +03:00
|
|
|
if (localFile) {
|
|
|
|
nsString unicodePath;
|
2010-07-24 01:35:51 +04:00
|
|
|
rv = localFile->GetPath(unicodePath);
|
2009-10-25 07:13:30 +03:00
|
|
|
if (!unicodePath.IsEmpty()) {
|
|
|
|
newFileNames.AppendElement(unicodePath);
|
2009-08-11 03:40:29 +04:00
|
|
|
}
|
2009-12-23 04:05:26 +03:00
|
|
|
// Store the last used directory using the content pref service
|
2010-07-24 01:35:51 +04:00
|
|
|
rv = gUploadLastDir->StoreLastUsedDirectory(doc->GetDocumentURI(),
|
|
|
|
localFile);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-08-11 03:40:29 +04:00
|
|
|
}
|
2009-03-10 09:14:57 +03:00
|
|
|
}
|
|
|
|
|
2009-10-25 07:13:30 +03:00
|
|
|
// Set new selected files
|
|
|
|
if (!newFileNames.IsEmpty()) {
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
mFrame->mTextFrame->SetFireChangeEventState(oldState);
|
|
|
|
// May need to fire an onchange here
|
|
|
|
mFrame->mTextFrame->CheckFireOnChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
1998-09-23 21:16:51 +04:00
|
|
|
}
|
|
|
|
|
2010-02-11 11:35:49 +03:00
|
|
|
void nsFileControlFrame::InitUploadLastDir() {
|
|
|
|
gUploadLastDir = new UploadLastDir();
|
|
|
|
NS_IF_ADDREF(gUploadLastDir);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 20:59:13 +04:00
|
|
|
mozilla::services::GetObserverService();
|
2010-02-11 11:35:49 +03:00
|
|
|
if (observerService && gUploadLastDir) {
|
|
|
|
observerService->AddObserver(gUploadLastDir, NS_PRIVATE_BROWSING_SWITCH_TOPIC, PR_TRUE);
|
|
|
|
observerService->AddObserver(gUploadLastDir, "browser:purge-session-history", PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsFileControlFrame::DestroyUploadLastDir() {
|
2010-02-21 17:52:51 +03:00
|
|
|
if (gUploadLastDir)
|
|
|
|
NS_RELEASE(gUploadLastDir);
|
2010-02-11 11:35:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
UploadLastDir::UploadLastDir():
|
|
|
|
mInPrivateBrowsing(PR_FALSE)
|
|
|
|
{
|
2010-02-11 20:34:01 +03:00
|
|
|
nsCOMPtr<nsIPrivateBrowsingService> pbService =
|
|
|
|
do_GetService(NS_PRIVATE_BROWSING_SERVICE_CONTRACTID);
|
|
|
|
if (pbService) {
|
|
|
|
pbService->GetPrivateBrowsingEnabled(&mInPrivateBrowsing);
|
|
|
|
}
|
2010-02-11 11:35:49 +03:00
|
|
|
|
|
|
|
mUploadLastDirStore.Init();
|
|
|
|
}
|
|
|
|
|
2009-12-23 04:05:26 +03:00
|
|
|
nsresult
|
2010-02-11 11:35:49 +03:00
|
|
|
UploadLastDir::FetchLastUsedDirectory(nsIURI* aURI, nsILocalFile** aFile)
|
2009-12-23 04:05:26 +03:00
|
|
|
{
|
2010-02-11 11:35:49 +03:00
|
|
|
NS_PRECONDITION(aURI, "aURI is null");
|
|
|
|
NS_PRECONDITION(aFile, "aFile is null");
|
|
|
|
// Retrieve the data from memory if it's present during private browsing mode,
|
|
|
|
// otherwise fall through to check the CPS
|
|
|
|
if (mInPrivateBrowsing) {
|
|
|
|
nsCOMPtr<nsIContentURIGrouper> hostnameGrouperService =
|
|
|
|
do_GetService(NS_HOSTNAME_GROUPER_SERVICE_CONTRACTID);
|
|
|
|
if (!hostnameGrouperService)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
nsString group;
|
|
|
|
hostnameGrouperService->Group(aURI, group);
|
|
|
|
|
|
|
|
if (mUploadLastDirStore.Get(group, aFile)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-23 04:05:26 +03:00
|
|
|
// Attempt to get the CPS, if it's not present we'll just return
|
|
|
|
nsCOMPtr<nsIContentPrefService> contentPrefService =
|
|
|
|
do_GetService(NS_CONTENT_PREF_SERVICE_CONTRACTID);
|
|
|
|
if (!contentPrefService)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
nsCOMPtr<nsIWritableVariant> uri = do_CreateInstance(NS_VARIANT_CONTRACTID);
|
|
|
|
if (!uri)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
uri->SetAsISupports(aURI);
|
|
|
|
|
|
|
|
// Get the last used directory, if it is stored
|
|
|
|
PRBool hasPref;
|
2010-02-11 11:35:49 +03:00
|
|
|
if (NS_SUCCEEDED(contentPrefService->HasPref(uri, CPS_PREF_NAME, &hasPref)) && hasPref) {
|
2009-12-23 04:05:26 +03:00
|
|
|
nsCOMPtr<nsIVariant> pref;
|
2010-02-11 11:35:49 +03:00
|
|
|
contentPrefService->GetPref(uri, CPS_PREF_NAME, nsnull, getter_AddRefs(pref));
|
2009-12-23 04:05:26 +03:00
|
|
|
nsString prefStr;
|
|
|
|
pref->GetAsAString(prefStr);
|
2010-02-11 11:35:49 +03:00
|
|
|
|
2010-02-11 20:34:01 +03:00
|
|
|
nsCOMPtr<nsILocalFile> localFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
|
|
|
|
if (!localFile)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
localFile->InitWithPath(prefStr);
|
|
|
|
|
2010-02-11 11:35:49 +03:00
|
|
|
*aFile = localFile;
|
2010-02-11 20:34:01 +03:00
|
|
|
NS_ADDREF(*aFile);
|
2009-12-23 04:05:26 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-02-11 11:35:49 +03:00
|
|
|
nsresult
|
|
|
|
UploadLastDir::StoreLastUsedDirectory(nsIURI* aURI, nsILocalFile* aFile)
|
2009-12-23 04:05:26 +03:00
|
|
|
{
|
2010-02-11 11:35:49 +03:00
|
|
|
NS_PRECONDITION(aURI, "aURI is null");
|
|
|
|
NS_PRECONDITION(aFile, "aFile is null");
|
|
|
|
nsCOMPtr<nsIFile> parentFile;
|
|
|
|
aFile->GetParent(getter_AddRefs(parentFile));
|
|
|
|
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(parentFile);
|
|
|
|
|
|
|
|
// Store the data in memory instead of the CPS during private browsing mode
|
|
|
|
if (mInPrivateBrowsing) {
|
|
|
|
nsCOMPtr<nsIContentURIGrouper> hostnameGrouperService =
|
|
|
|
do_GetService(NS_HOSTNAME_GROUPER_SERVICE_CONTRACTID);
|
|
|
|
if (!hostnameGrouperService)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
nsString group;
|
|
|
|
hostnameGrouperService->Group(aURI, group);
|
|
|
|
|
|
|
|
return mUploadLastDirStore.Put(group, localFile);
|
|
|
|
}
|
|
|
|
|
2009-12-23 04:05:26 +03:00
|
|
|
// Attempt to get the CPS, if it's not present we'll just return
|
|
|
|
nsCOMPtr<nsIContentPrefService> contentPrefService =
|
|
|
|
do_GetService(NS_CONTENT_PREF_SERVICE_CONTRACTID);
|
|
|
|
if (!contentPrefService)
|
2010-02-11 11:35:49 +03:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2009-12-23 04:05:26 +03:00
|
|
|
nsCOMPtr<nsIWritableVariant> uri = do_CreateInstance(NS_VARIANT_CONTRACTID);
|
|
|
|
if (!uri)
|
2010-02-11 11:35:49 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2009-12-23 04:05:26 +03:00
|
|
|
uri->SetAsISupports(aURI);
|
2010-02-11 11:35:49 +03:00
|
|
|
|
2009-12-23 04:05:26 +03:00
|
|
|
// Find the parent of aFile, and store it
|
|
|
|
nsString unicodePath;
|
|
|
|
parentFile->GetPath(unicodePath);
|
2010-02-11 11:35:49 +03:00
|
|
|
if (unicodePath.IsEmpty()) // nothing to do
|
|
|
|
return NS_OK;
|
|
|
|
nsCOMPtr<nsIWritableVariant> prefValue = do_CreateInstance(NS_VARIANT_CONTRACTID);
|
|
|
|
if (!prefValue)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
prefValue->SetAsAString(unicodePath);
|
|
|
|
return contentPrefService->SetPref(uri, CPS_PREF_NAME, prefValue);
|
|
|
|
}
|
|
|
|
|
2010-02-11 20:34:01 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
UploadLastDir::Observe(nsISupports *aSubject, char const *aTopic, PRUnichar const *aData)
|
|
|
|
{
|
2010-02-11 11:35:49 +03:00
|
|
|
if (strcmp(aTopic, NS_PRIVATE_BROWSING_SWITCH_TOPIC) == 0) {
|
|
|
|
if (NS_LITERAL_STRING(NS_PRIVATE_BROWSING_ENTER).Equals(aData)) {
|
|
|
|
mInPrivateBrowsing = PR_TRUE;
|
|
|
|
} else if (NS_LITERAL_STRING(NS_PRIVATE_BROWSING_LEAVE).Equals(aData)) {
|
|
|
|
mInPrivateBrowsing = PR_FALSE;
|
|
|
|
if (mUploadLastDirStore.IsInitialized()) {
|
|
|
|
mUploadLastDirStore.Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (strcmp(aTopic, "browser:purge-session-history") == 0) {
|
|
|
|
if (mUploadLastDirStore.IsInitialized()) {
|
|
|
|
mUploadLastDirStore.Clear();
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIContentPrefService> contentPrefService =
|
|
|
|
do_GetService(NS_CONTENT_PREF_SERVICE_CONTRACTID);
|
|
|
|
if (contentPrefService)
|
|
|
|
contentPrefService->RemovePrefsByName(CPS_PREF_NAME);
|
2009-12-23 04:05:26 +03:00
|
|
|
}
|
2010-02-11 11:35:49 +03:00
|
|
|
return NS_OK;
|
2009-12-23 04:05:26 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
nsFileControlFrame::GetMinWidth(nsIRenderingContext *aRenderingContext)
|
|
|
|
{
|
|
|
|
nscoord result;
|
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
|
|
|
|
|
|
|
// Our min width is our pref width
|
|
|
|
result = GetPrefWidth(aRenderingContext);
|
|
|
|
return result;
|
|
|
|
}
|
1998-09-23 21:16:51 +04:00
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
NS_IMETHODIMP nsFileControlFrame::Reflow(nsPresContext* aPresContext,
|
1998-10-02 08:10:00 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
1998-09-23 21:16:51 +04:00
|
|
|
{
|
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
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsFileControlFrame");
|
2001-11-14 16:40:03 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
2000-04-22 01:51:35 +04:00
|
|
|
|
2000-09-10 02:13:12 +04:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
|
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
|
|
|
if (mState & NS_FRAME_FIRST_REFLOW) {
|
2000-01-22 04:16:50 +03:00
|
|
|
mTextFrame = GetTextControlFrame(aPresContext, this);
|
2005-12-13 02:53:06 +03:00
|
|
|
NS_ENSURE_TRUE(mTextFrame, NS_ERROR_UNEXPECTED);
|
1999-05-08 00:30:16 +04:00
|
|
|
}
|
|
|
|
|
2009-01-04 22:52:38 +03:00
|
|
|
// nsBlockFrame takes care of all our reflow
|
2008-12-29 18:07:38 +03:00
|
|
|
return nsBlockFrame::Reflow(aPresContext, aDesiredSize, aReflowState,
|
2007-11-27 06:35:50 +03:00
|
|
|
aStatus);
|
1999-07-01 02:17:43 +04:00
|
|
|
}
|
1998-09-23 21:16:51 +04:00
|
|
|
|
2000-05-17 03:29:35 +04:00
|
|
|
nsNewFrame*
|
2004-08-01 03:15:21 +04:00
|
|
|
nsFileControlFrame::GetTextControlFrame(nsPresContext* aPresContext, nsIFrame* aStart)
|
1999-07-01 02:17:43 +04:00
|
|
|
{
|
2000-05-17 03:29:35 +04:00
|
|
|
nsNewFrame* result = nsnull;
|
2000-08-18 22:16:12 +04:00
|
|
|
#ifndef DEBUG_NEWFRAME
|
1999-07-01 02:17:43 +04:00
|
|
|
// find the text control frame.
|
2004-01-09 17:20:53 +03:00
|
|
|
nsIFrame* childFrame = aStart->GetFirstChild(nsnull);
|
1999-07-01 02:17:43 +04:00
|
|
|
|
1999-09-15 09:31:31 +04:00
|
|
|
while (childFrame) {
|
1999-07-01 02:17:43 +04:00
|
|
|
// see if the child is a text control
|
2003-11-19 04:20:56 +03:00
|
|
|
nsCOMPtr<nsIFormControl> formCtrl =
|
|
|
|
do_QueryInterface(childFrame->GetContent());
|
|
|
|
|
|
|
|
if (formCtrl && formCtrl->GetType() == NS_FORM_INPUT_TEXT) {
|
|
|
|
result = (nsNewFrame*)childFrame;
|
1998-10-01 08:46:11 +04:00
|
|
|
}
|
1998-09-23 21:16:51 +04:00
|
|
|
|
1999-07-01 02:17:43 +04:00
|
|
|
// if not continue looking
|
2000-05-17 03:29:35 +04:00
|
|
|
nsNewFrame* frame = GetTextControlFrame(aPresContext, childFrame);
|
1999-09-15 09:31:31 +04:00
|
|
|
if (frame)
|
2000-02-23 23:58:42 +03:00
|
|
|
result = frame;
|
1999-07-01 02:17:43 +04:00
|
|
|
|
2003-07-04 16:50:32 +04:00
|
|
|
childFrame = childFrame->GetNextSibling();
|
1998-09-23 21:16:51 +04:00
|
|
|
}
|
|
|
|
|
2000-02-23 23:58:42 +03:00
|
|
|
return result;
|
2000-08-18 22:16:12 +04:00
|
|
|
#else
|
|
|
|
return nsnull;
|
|
|
|
#endif
|
1998-09-23 21:16:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PRIntn
|
|
|
|
nsFileControlFrame::GetSkipSides() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-06-12 11:58:26 +04:00
|
|
|
void
|
|
|
|
nsFileControlFrame::SyncAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
|
|
|
|
PRInt32 aWhichControls)
|
|
|
|
{
|
|
|
|
nsAutoString value;
|
2005-10-28 15:25:24 +04:00
|
|
|
if (mContent->GetAttr(aNameSpaceID, aAttribute, value)) {
|
2002-06-12 11:58:26 +04:00
|
|
|
if (aWhichControls & SYNC_TEXT && mTextContent) {
|
|
|
|
mTextContent->SetAttr(aNameSpaceID, aAttribute, value, PR_TRUE);
|
|
|
|
}
|
|
|
|
if (aWhichControls & SYNC_BUTTON && mBrowse) {
|
|
|
|
mBrowse->SetAttr(aNameSpaceID, aAttribute, value, PR_TRUE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (aWhichControls & SYNC_TEXT && mTextContent) {
|
|
|
|
mTextContent->UnsetAttr(aNameSpaceID, aAttribute, PR_TRUE);
|
|
|
|
}
|
|
|
|
if (aWhichControls & SYNC_BUTTON && mBrowse) {
|
|
|
|
mBrowse->UnsetAttr(aNameSpaceID, aAttribute, PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-02-11 04:13:28 +03:00
|
|
|
|
1999-08-19 18:03:53 +04:00
|
|
|
NS_IMETHODIMP
|
2005-09-07 20:49:21 +04:00
|
|
|
nsFileControlFrame::AttributeChanged(PRInt32 aNameSpaceID,
|
2004-12-31 04:13:27 +03:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aModType)
|
1999-08-19 18:03:53 +04:00
|
|
|
{
|
2002-06-12 11:58:26 +04:00
|
|
|
// propagate disabled to text / button inputs
|
2008-12-17 10:33:33 +03:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::disabled) {
|
|
|
|
SyncAttr(aNameSpaceID, aAttribute, SYNC_BOTH);
|
|
|
|
// propagate size to text
|
|
|
|
} else if (aAttribute == nsGkAtoms::size) {
|
|
|
|
SyncAttr(aNameSpaceID, aAttribute, SYNC_TEXT);
|
|
|
|
} else if (aAttribute == nsGkAtoms::tabindex) {
|
|
|
|
SyncAttr(aNameSpaceID, aAttribute, SYNC_BUTTON);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2005-08-17 02:52:48 +04:00
|
|
|
PRBool
|
|
|
|
nsFileControlFrame::IsLeaf() const
|
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1999-11-02 01:12:45 +03:00
|
|
|
#ifdef NS_DEBUG
|
1998-11-19 20:22:29 +03:00
|
|
|
NS_IMETHODIMP
|
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
|
|
|
|
2005-12-13 03:57:56 +03:00
|
|
|
nsresult
|
|
|
|
nsFileControlFrame::SetFormProperty(nsIAtom* aName,
|
|
|
|
const nsAString& aValue)
|
1999-01-26 01:16:27 +03:00
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
if (nsGkAtoms::value == aName) {
|
2010-04-22 00:17:41 +04:00
|
|
|
nsCOMPtr<nsIDOMHTMLInputElement> textControl =
|
|
|
|
do_QueryInterface(mTextContent);
|
|
|
|
NS_ASSERTION(textControl,
|
|
|
|
"The text control should exist and be an input element");
|
|
|
|
textControl->SetValue(aValue);
|
1999-02-11 04:13:28 +03:00
|
|
|
}
|
2005-12-13 02:53:06 +03:00
|
|
|
return NS_OK;
|
1999-02-11 04:13:28 +03:00
|
|
|
}
|
1999-01-26 01:16:27 +03:00
|
|
|
|
2005-12-13 02:53:06 +03:00
|
|
|
nsresult
|
|
|
|
nsFileControlFrame::GetFormProperty(nsIAtom* aName, nsAString& aValue) const
|
1999-01-26 01:16:27 +03:00
|
|
|
{
|
2001-04-24 12:33:57 +04:00
|
|
|
aValue.Truncate(); // initialize out param
|
1999-02-11 04:13:28 +03:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (nsGkAtoms::value == aName) {
|
2009-10-25 07:13:30 +03:00
|
|
|
nsCOMPtr<nsIFileControlElement> fileControl =
|
|
|
|
do_QueryInterface(mContent);
|
|
|
|
if (fileControl) {
|
|
|
|
fileControl->GetDisplayFileName(aValue);
|
2001-04-24 12:33:57 +04:00
|
|
|
}
|
1999-02-11 04:13:28 +03:00
|
|
|
}
|
1999-01-26 01:16:27 +03:00
|
|
|
return NS_OK;
|
1999-02-18 03:13:39 +03:00
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
1999-02-11 04:13:28 +03:00
|
|
|
{
|
2009-01-30 10:10:25 +03:00
|
|
|
// box-shadow
|
|
|
|
if (GetStyleBorder()->mBoxShadow) {
|
|
|
|
nsresult rv = aLists.BorderBackground()->AppendNewToTop(new (aBuilder)
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayBoxShadowOuter(aBuilder, this));
|
2009-01-30 10:10:25 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2006-02-07 01:27:58 +03:00
|
|
|
// Our background is inherited to the text input, and we don't really want to
|
|
|
|
// paint it or out padding and borders (which we never have anyway, per
|
|
|
|
// styles in forms.css) -- doing it just makes us look ugly in some cases and
|
|
|
|
// has no effect in others.
|
2006-02-07 01:08:10 +03:00
|
|
|
nsDisplayListCollection tempList;
|
2008-12-29 18:07:38 +03:00
|
|
|
nsresult rv = nsBlockFrame::BuildDisplayList(aBuilder, aDirtyRect, tempList);
|
2006-01-26 05:29:17 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2006-02-07 01:08:10 +03:00
|
|
|
|
|
|
|
tempList.BorderBackground()->DeleteAll();
|
2007-11-27 06:35:50 +03:00
|
|
|
|
2008-01-08 01:18:06 +03:00
|
|
|
// Clip height only
|
|
|
|
nsRect clipRect(aBuilder->ToReferenceFrame(this), GetSize());
|
|
|
|
clipRect.width = GetOverflowRect().XMost();
|
|
|
|
rv = OverflowClip(aBuilder, tempList, aLists, clipRect);
|
2007-11-27 06:35:50 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
// Disabled file controls don't pass mouse events to their children, so we
|
|
|
|
// put an invisible item in the display list above the children
|
|
|
|
// just to catch events
|
2006-12-26 20:47:52 +03:00
|
|
|
if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::disabled) &&
|
2006-01-26 05:29:17 +03:00
|
|
|
IsVisibleForPainting(aBuilder)) {
|
2010-08-13 14:01:13 +04:00
|
|
|
rv = aLists.Content()->AppendNewToTop(
|
|
|
|
new (aBuilder) nsDisplayEventReceiver(aBuilder, this));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
1999-09-15 09:31:31 +04:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
return DisplaySelectionOverlay(aBuilder, aLists);
|
|
|
|
}
|
2006-11-14 01:05:25 +03:00
|
|
|
|
2007-09-28 05:09:14 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
2010-06-28 16:02:03 +04:00
|
|
|
already_AddRefed<nsAccessible>
|
|
|
|
nsFileControlFrame::CreateAccessible()
|
2007-09-28 05:09:14 +04:00
|
|
|
{
|
2007-11-20 23:39:36 +03:00
|
|
|
// Accessible object exists just to hold onto its children, for later shutdown
|
|
|
|
nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 20:59:13 +04:00
|
|
|
if (!accService)
|
2010-06-28 16:02:03 +04:00
|
|
|
return nsnull;
|
2007-11-20 23:39:36 +03:00
|
|
|
|
2010-06-28 16:02:03 +04:00
|
|
|
return accService->CreateHyperTextAccessible(mContent,
|
|
|
|
PresContext()->PresShell());
|
2007-09-28 05:09:14 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-07-21 20:07:55 +04:00
|
|
|
void
|
|
|
|
nsFileControlFrame::ParseAcceptAttribute(AcceptAttrCallback aCallback,
|
|
|
|
void* aClosure) const
|
2010-05-20 06:28:01 +04:00
|
|
|
{
|
|
|
|
nsAutoString accept;
|
2010-07-21 20:12:19 +04:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::accept, accept);
|
2010-05-20 06:28:01 +04:00
|
|
|
|
2010-07-21 20:07:55 +04:00
|
|
|
nsCharSeparatedTokenizerTemplate<nsContentUtils::IsHTMLWhitespace>
|
|
|
|
tokenizer(accept, ',');
|
|
|
|
// Empty loop body because aCallback is doing the work
|
|
|
|
while (tokenizer.hasMoreTokens() &&
|
|
|
|
(*aCallback)(tokenizer.nextToken(), aClosure));
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool FileFilterCallback(const nsAString& aVal, void* aClosure)
|
|
|
|
{
|
|
|
|
PRInt32* filter = (PRInt32*)aClosure;
|
|
|
|
|
|
|
|
if (aVal.EqualsLiteral("image/*")) {
|
|
|
|
*filter |= nsIFilePicker::filterImages;
|
|
|
|
} else if (aVal.EqualsLiteral("audio/*")) {
|
|
|
|
*filter |= nsIFilePicker::filterAudio;
|
|
|
|
} else if (aVal.EqualsLiteral("video/*")) {
|
|
|
|
*filter |= nsIFilePicker::filterVideo;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsFileControlFrame::GetFileFilterFromAccept() const
|
|
|
|
{
|
|
|
|
PRInt32 filterVal = 0;
|
|
|
|
this->ParseAcceptAttribute(&FileFilterCallback, (void*)&filterVal);
|
|
|
|
return filterVal;
|
2010-05-20 06:28:01 +04:00
|
|
|
}
|
2006-11-14 01:05:25 +03:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Mouse listener implementation
|
|
|
|
|
2008-04-06 16:28:34 +04:00
|
|
|
NS_IMPL_ISUPPORTS2(nsFileControlFrame::MouseListener,
|
|
|
|
nsIDOMMouseListener,
|
|
|
|
nsIDOMEventListener)
|