Bug 741216 - Allow dropping files into the file picker control; r=bzbarsky

This commit is contained in:
Ehsan Akhgari 2012-04-02 16:25:09 -04:00
Родитель 054e3c8f89
Коммит ef2894de82
2 изменённых файлов: 25 добавлений и 5 удалений

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

@ -37,6 +37,8 @@
#include "nsIDOMWindow.h"
#include "nsContentUtils.h"
#include "nsIBidiKeyboard.h"
#include "mozilla/dom/Element.h"
#include "nsIFormControl.h"
using namespace mozilla;
@ -646,9 +648,11 @@ nsEditorEventListener::DragOver(nsIDOMDragEvent* aDragEvent)
}
else
{
// This is needed when dropping on an input, to prevent the editor for
// the editable parent from receiving the event.
aDragEvent->StopPropagation();
if (!IsFileControlTextBox()) {
// This is needed when dropping on an input, to prevent the editor for
// the editable parent from receiving the event.
aDragEvent->StopPropagation();
}
if (mCaret)
{
@ -704,8 +708,8 @@ nsEditorEventListener::Drop(nsIDOMDragEvent* aMouseEvent)
if (!dropParent->IsEditable() || !CanDrop(aMouseEvent)) {
// was it because we're read-only?
if (mEditor->IsReadonly() || mEditor->IsDisabled())
{
if ((mEditor->IsReadonly() || mEditor->IsDisabled()) &&
!IsFileControlTextBox()) {
// it was decided to "eat" the event as this is the "least surprise"
// since someone else handling it might be unintentional and the
// user could probably re-drag to be not over the disabled/readonly
@ -956,3 +960,18 @@ nsEditorEventListener::SpellCheckIfNeeded() {
}
}
bool
nsEditorEventListener::IsFileControlTextBox()
{
dom::Element* root = mEditor->GetRoot();
if (root && root->IsInNativeAnonymousSubtree()) {
nsIContent* parent = root->FindFirstNonNativeAnonymous();
if (parent && parent->IsHTML(nsGkAtoms::input)) {
nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(parent);
MOZ_ASSERT(formControl);
return formControl->GetType() == NS_FORM_INPUT_FILE;
}
}
return false;
}

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

@ -67,6 +67,7 @@ protected:
nsresult DragGesture(nsIDOMDragEvent* aDragEvent);
void CleanupDragDropCaret();
already_AddRefed<nsIPresShell> GetPresShell();
bool IsFileControlTextBox();
protected:
nsEditor* mEditor; // weak