Bug 838354 - Remove all capture button references from nsFileControlFrame. r=bz

This commit is contained in:
Mounir Lamouri 2013-03-22 17:10:13 +00:00
Родитель bb3c171c25
Коммит 68c0f2cae5
8 изменённых файлов: 7 добавлений и 274 удалений

Просмотреть файл

@ -243,7 +243,6 @@
@BINPATH@/components/jsdservice.xpt
@BINPATH@/components/jsinspector.xpt
@BINPATH@/components/layout_base.xpt
@BINPATH@/components/layout_forms.xpt
#ifdef NS_PRINTING
@BINPATH@/components/layout_printing.xpt
#endif

Просмотреть файл

@ -245,7 +245,6 @@
@BINPATH@/components/jsdebugger.xpt
@BINPATH@/components/jsinspector.xpt
@BINPATH@/components/layout_base.xpt
@BINPATH@/components/layout_forms.xpt
#ifdef NS_PRINTING
@BINPATH@/components/layout_printing.xpt
#endif

Просмотреть файл

@ -6,7 +6,6 @@ Reset=Reset
Submit=Submit Query
Browse=Browse…
FileUpload=File Upload
MediaUpload=Media Upload
# LOCALIZATION NOTE (IsIndexPromptWithSpace): The last character of the string
# should be a space (U+0020) in most locales. The prompt is followed by an
# input field. The space needs be escaped in the property file to avoid

Просмотреть файл

@ -5,11 +5,5 @@
TEST_DIRS += ['test']
XPIDL_SOURCES += [
'nsICapturePicker.idl',
]
XPIDL_MODULE = 'layout_forms'
MODULE = 'layout'

Просмотреть файл

@ -41,8 +41,6 @@
#include "nsIVariant.h"
#include "mozilla/Services.h"
#include "nsDirectoryServiceDefs.h"
#include "nsICapturePicker.h"
#include "nsIFileURL.h"
#include "nsDOMFile.h"
#include "nsEventStates.h"
#include "nsTextControlFrame.h"
@ -79,7 +77,6 @@ nsFileControlFrame::Init(nsIContent* aContent,
nsBlockFrame::Init(aContent, aParent, aPrevInFlow);
mMouseListener = new BrowseMouseListener(this);
mCaptureMouseListener = new CaptureMouseListener(this);
}
void
@ -96,7 +93,6 @@ nsFileControlFrame::DestroyFrom(nsIFrame* aDestructRoot)
}
// remove mMouseListener as a mouse event listener (bug 40533, bug 355931)
nsContentUtils::DestroyAnonymousContent(&mCapture);
if (mBrowse) {
mBrowse->RemoveSystemEventListener(NS_LITERAL_STRING("click"),
@ -110,7 +106,6 @@ nsFileControlFrame::DestroyFrom(nsIFrame* aDestructRoot)
}
nsContentUtils::DestroyAnonymousContent(&mTextContent);
mCaptureMouseListener->ForgetFrame();
mMouseListener->ForgetFrame();
nsBlockFrame::DestroyFrom(aDestructRoot);
}
@ -183,37 +178,6 @@ nsFileControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
mBrowse->SetAttr(kNameSpaceID_None, nsGkAtoms::type,
NS_LITERAL_STRING("button"), false);
// Create the capture button
nsCOMPtr<nsICapturePicker> capturePicker;
capturePicker = do_GetService("@mozilla.org/capturepicker;1");
if (capturePicker) {
CaptureCallbackData data;
data.picker = capturePicker;
data.mode = GetCaptureMode(data);
if (data.mode != 0) {
mCaptureMouseListener->mMode = data.mode;
nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::input, nullptr,
kNameSpaceID_XHTML,
nsIDOMNode::ELEMENT_NODE);
NS_NewHTMLElement(getter_AddRefs(mCapture), nodeInfo.forget(),
dom::NOT_FROM_PARSER);
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"), false);
mCapture->SetAttr(kNameSpaceID_None, nsGkAtoms::value,
NS_LITERAL_STRING("capture"), false);
mCapture->AddSystemEventListener(NS_LITERAL_STRING("click"),
mCaptureMouseListener, false);
}
}
nsCOMPtr<nsIDOMHTMLInputElement> fileContent = do_QueryInterface(mContent);
nsCOMPtr<nsIDOMHTMLInputElement> browseControl = do_QueryInterface(mBrowse);
if (fileContent && browseControl) {
@ -229,9 +193,6 @@ nsFileControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
if (!aElements.AppendElement(mBrowse))
return NS_ERROR_OUT_OF_MEMORY;
if (mCapture && !aElements.AppendElement(mCapture))
return NS_ERROR_OUT_OF_MEMORY;
// Register as an event listener of the button
// to open file dialog on mouse click
mBrowse->AddSystemEventListener(NS_LITERAL_STRING("click"),
@ -249,7 +210,6 @@ nsFileControlFrame::AppendAnonymousContentTo(nsBaseContentList& aElements,
{
aElements.MaybeAppendElement(mTextContent);
aElements.MaybeAppendElement(mBrowse);
aElements.MaybeAppendElement(mCapture);
}
NS_QUERYFRAME_HEAD(nsFileControlFrame)
@ -286,90 +246,6 @@ bool ShouldProcessMouseClick(nsIDOMEvent* aMouseEvent)
return true;
}
/**
* This is called when our capture button is clicked
*/
NS_IMETHODIMP
nsFileControlFrame::CaptureMouseListener::HandleEvent(nsIDOMEvent* aMouseEvent)
{
nsresult rv;
NS_ASSERTION(mFrame, "We should have been unregistered");
if (!ShouldProcessMouseClick(aMouseEvent))
return NS_OK;
// Get parent nsPIDOMWindow object.
nsIContent* content = mFrame->GetContent();
nsHTMLInputElement* inputElement =
nsHTMLInputElement::FromContentOrNull(content);
if (!inputElement)
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,
"MediaUpload", 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);
// Show dialog
uint32_t 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<nsIDOMFile> domFile;
rv = capturePicker->GetFile(getter_AddRefs(domFile));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMArray<nsIDOMFile> newFiles;
if (domFile) {
newFiles.AppendObject(domFile);
} else {
return NS_ERROR_FAILURE;
}
// 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 (newFiles.Count()) {
// Tell our input element 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.
inputElement->SetFiles(newFiles, true);
nsContentUtils::DispatchTrustedEvent(content->OwnerDoc(), content,
NS_LITERAL_STRING("change"), true,
false);
}
return NS_OK;
}
/**
* This is called when we receive any registered events on the control.
* We've only registered for drop, dragover and click events.
@ -618,51 +494,6 @@ nsFileControlFrame::AccessibleType()
}
#endif
uint32_t
nsFileControlFrame::GetCaptureMode(const CaptureCallbackData& aData)
{
int32_t filters = nsHTMLInputElement::FromContent(mContent)->GetFilterFromAccept();
nsresult rv;
bool captureEnabled;
if (filters == nsIFilePicker::filterImages) {
rv = aData.picker->ModeMayBeAvailable(nsICapturePicker::MODE_STILL,
&captureEnabled);
NS_ENSURE_SUCCESS(rv, 0);
if (captureEnabled) {
return nsICapturePicker::MODE_STILL;
}
return 0;
}
if (filters == nsIFilePicker::filterAudio) {
rv = aData.picker->ModeMayBeAvailable(nsICapturePicker::MODE_AUDIO_CLIP,
&captureEnabled);
NS_ENSURE_SUCCESS(rv, 0);
if (captureEnabled) {
return nsICapturePicker::MODE_AUDIO_CLIP;
}
return 0;
}
if (filters == nsIFilePicker::filterVideo) {
rv = aData.picker->ModeMayBeAvailable(nsICapturePicker::MODE_VIDEO_CLIP,
&captureEnabled);
NS_ENSURE_SUCCESS(rv, 0);
if (captureEnabled) {
return nsICapturePicker::MODE_VIDEO_CLIP;
}
rv = aData.picker->ModeMayBeAvailable(nsICapturePicker::MODE_VIDEO_NO_SOUND_CLIP,
&captureEnabled);
NS_ENSURE_SUCCESS(rv, 0);
if (captureEnabled) {
return nsICapturePicker::MODE_VIDEO_NO_SOUND_CLIP;
}
return 0;
}
return 0;
}
////////////////////////////////////////////////////////////
// Mouse listener implementation

Просмотреть файл

@ -11,7 +11,6 @@
#include "nsIFormControlFrame.h"
#include "nsIDOMEventListener.h"
#include "nsIAnonymousContentCreator.h"
#include "nsICapturePicker.h"
#include "nsCOMPtr.h"
class nsTextControlFrame;
@ -41,7 +40,7 @@ public:
virtual void SetFocus(bool aOn, bool aRepaint);
virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
#ifdef DEBUG
@ -63,27 +62,20 @@ public:
#ifdef ACCESSIBILITY
virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE;
#endif
#endif
typedef bool (*AcceptAttrCallback)(const nsAString&, void*);
protected:
struct CaptureCallbackData {
nsICapturePicker* picker;
uint32_t mode;
};
uint32_t GetCaptureMode(const CaptureCallbackData& aData);
class MouseListener;
friend class MouseListener;
class MouseListener : public nsIDOMEventListener {
public:
NS_DECL_ISUPPORTS
MouseListener(nsFileControlFrame* aFrame)
: mFrame(aFrame)
: mFrame(aFrame)
{}
virtual ~MouseListener() {}
@ -116,21 +108,10 @@ protected:
nsWeakFrame mFrame;
};
class CaptureMouseListener: public MouseListener {
public:
CaptureMouseListener(nsFileControlFrame* aFrame)
: MouseListener(aFrame)
, mMode(0)
{}
NS_DECL_NSIDOMEVENTLISTENER
uint32_t mMode;
};
class BrowseMouseListener: public MouseListener {
public:
BrowseMouseListener(nsFileControlFrame* aFrame)
: MouseListener(aFrame)
BrowseMouseListener(nsFileControlFrame* aFrame)
: MouseListener(aFrame)
{}
NS_DECL_NSIDOMEVENTLISTENER
@ -155,17 +136,10 @@ protected:
*/
nsCOMPtr<nsIContent> mBrowse;
/**
* The capture button input.
* @see nsFileControlFrame::CreateAnonymousContent
*/
nsCOMPtr<nsIContent> mCapture;
/**
* Our mouse listener. This makes sure we don't get used after destruction.
*/
nsRefPtr<BrowseMouseListener> mMouseListener;
nsRefPtr<CaptureMouseListener> mCaptureMouseListener;
protected:
/**

Просмотреть файл

@ -1,62 +0,0 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* 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/. */
#include "nsISupports.idl"
interface nsIDOMWindow;
interface nsIDOMFile;
[scriptable, uuid(a4e2b2de-5712-4f80-aabb-7de3a747f227)]
interface nsICapturePicker : nsISupports
{
const long MODE_STILL = 1; // Capture a still (image)
const long MODE_AUDIO_CLIP = 2; // Capture a clip of audio
const long MODE_VIDEO_CLIP = 3; // Capture a clip of video
const long MODE_VIDEO_NO_SOUND_CLIP = 4; // Capture a clip of video (no sound)
// Return codes from the dialog
const long RETURN_OK = 0;
const long RETURN_CANCEL = 1;
/**
* Initialize the camera picker widget. The camera picker is not valid until this
* method is called.
*
* @param parent nsIDOMWindow parent. This dialog will be dependent
* on this parent. This must not be null.
* @param title The title for the file widget
* @param flags Mode and type flags for what to capture
*
*/
void init(in nsIDOMWindow parent, in AString title, in unsigned long mode);
/**
* Show file dialog. The dialog is displayed modally.
*
* @return returnOK if the user captures the requested content, returnCancel if
* the user cancels the capture process
*/
unsigned long show();
/**
* Determine if the given mode might be available. Consumers should take a
* true value to be a hint of what might be available, not a guarantee.
*
* @param mode Mode to examine
*
* @return false if the requested mode can definitely not be captured,
* true otherwise.
*/
boolean modeMayBeAvailable(in unsigned long mode);
/**
* Get the captured image/video/audio. This may be a data URI, file URI,
* or a blob reference URI.
*/
readonly attribute nsIDOMFile file;
// The MIME type of the captured content. Cannot be set after calling show()
attribute AString type;
};

Просмотреть файл

@ -169,7 +169,6 @@
@BINPATH@/components/jsdebugger.xpt
@BINPATH@/components/jsinspector.xpt
@BINPATH@/components/layout_base.xpt
@BINPATH@/components/layout_forms.xpt
#ifdef NS_PRINTING
@BINPATH@/components/layout_printing.xpt
#endif